From 8b6b2eb2c762af0c965538ff077e70d0a4953d66 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 6 Jul 2018 20:44:03 +0300 Subject: Update packet ZC_ADD_EXCHANGE_ITEM. --- src/map/clif.c | 66 +++++++++++++++--------------------------------- src/map/packets_struct.h | 23 +++++++++++++++++ 2 files changed, 43 insertions(+), 46 deletions(-) diff --git a/src/map/clif.c b/src/map/clif.c index 0e5765cfc..15560dd00 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -4142,63 +4142,37 @@ static void clif_tradestart(struct map_session_data *sd, uint8 type) static void clif_tradeadditem(struct map_session_data *sd, struct map_session_data *tsd, int index, int amount) { int fd; - unsigned char *buf; + struct PACKET_ZC_ADD_EXCHANGE_ITEM p; + nullpo_retv(sd); nullpo_retv(tsd); fd = tsd->fd; - buf = WFIFOP(fd,0); - WFIFOHEAD(fd,packet_len(tradeaddType)); - WBUFW(buf,0) = tradeaddType; - if( index == 0 ) - { -#if PACKETVER < 20100223 - WBUFL(buf,2) = amount; //amount - WBUFW(buf,6) = 0; // type id -#else - WBUFW(buf,2) = 0; // type id - WBUFB(buf,4) = 0; // item type - WBUFL(buf,5) = amount; // amount - buf = WBUFP(buf,1); //Advance 1B -#endif - WBUFB(buf,8) = 0; //identify flag - WBUFB(buf,9) = 0; // attribute - WBUFB(buf,10)= 0; //refine - WBUFW(buf,11)= 0; //card (4w) - WBUFW(buf,13)= 0; //card (4w) - WBUFW(buf,15)= 0; //card (4w) - WBUFW(buf,17)= 0; //card (4w) -#if PACKETVER >= 20150226 - clif->add_item_options(WBUFP(buf, 19), &sd->status.inventory[index]); -#endif - } - else + WFIFOHEAD(fd, sizeof(p)); + memset(&p, 0, sizeof(p)); + p.packetType = tradeaddType; + p.amount = amount; + if (index != 0) { index -= 2; //index fix -#if PACKETVER < 20100223 - WBUFL(buf,2) = amount; //amount - if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0) - WBUFW(buf,6) = sd->inventory_data[index]->view_id; - else - WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id -#else + Assert_retv(index >= 0 && index < MAX_INVENTORY); if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0) - WBUFW(buf,2) = sd->inventory_data[index]->view_id; + p.itemId = sd->inventory_data[index]->view_id; else - WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id - WBUFB(buf,4) = sd->inventory_data[index]->type; // item type - WBUFL(buf,5) = amount; // amount - buf = WBUFP(buf,1); //Advance 1B -#endif - WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag - WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute - WBUFB(buf,10)= sd->status.inventory[index].refine; //refine - clif->addcards((struct EQUIPSLOTINFO*)WBUFP(buf, 11), &sd->status.inventory[index]); + p.itemId = sd->status.inventory[index].nameid; +#if PACKETVER >= 20100223 + p.itemType = sd->inventory_data[index]->type; +#endif + p.identified = sd->status.inventory[index].identify; + p.damaged = sd->status.inventory[index].attribute; + p.refine = sd->status.inventory[index].refine; + clif->addcards(&p.slot, &sd->status.inventory[index]); #if PACKETVER >= 20150226 - clif->add_item_options(WBUFP(buf, 19), &sd->status.inventory[index]); + clif->add_item_options(&p.option_data[0], &sd->status.inventory[index]); #endif } - WFIFOSET(fd,packet_len(tradeaddType)); + memcpy(WFIFOP(fd, 0), &p, sizeof(p)); + WFIFOSET(fd, sizeof(p)); } /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM). diff --git a/src/map/packets_struct.h b/src/map/packets_struct.h index 573215530..e0010e530 100644 --- a/src/map/packets_struct.h +++ b/src/map/packets_struct.h @@ -1988,6 +1988,29 @@ struct PACKET_ZC_SPRITE_CHANGE { #endif } __attribute__((packed)); +struct PACKET_ZC_ADD_EXCHANGE_ITEM { + int16 packetType; +#if PACKETVER_RE_NUM >= 20180704 + uint32 itemId; + uint8 itemType; + int32 amount; +#elif PACKETVER >= 20100223 + uint16 itemId; + uint8 itemType; + int32 amount; +#else + int32 amount; + uint16 itemId; +#endif + uint8 identified; + uint8 damaged; + uint8 refine; + struct EQUIPSLOTINFO slot; +#if PACKETVER >= 20150226 + struct ItemOptions option_data[MAX_ITEM_OPTIONS]; +#endif +} __attribute__((packed)); + #if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute #pragma pack(pop) #endif // not NetBSD < 6 / Solaris -- cgit v1.2.3-70-g09d2