From eac811e0389d1fe22c316fc8b27471bab04493e4 Mon Sep 17 00:00:00 2001 From: Asheraf Date: Mon, 7 Mar 2022 20:55:30 +0100 Subject: [PATCH 01/10] Update PACKET_ZC_BUYING_STORE_ENTRY to use struct format --- src/map/buyingstore.c | 2 +- src/map/clif.c | 37 ++++++++++++++++++------------------- src/map/clif.h | 4 ++-- src/map/packets_struct.h | 10 +++++++++- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/map/buyingstore.c b/src/map/buyingstore.c index fcf7e6170d5..930297151dc 100644 --- a/src/map/buyingstore.c +++ b/src/map/buyingstore.c @@ -197,7 +197,7 @@ static void buyingstore_create(struct map_session_data *sd, int zenylimit, unsig sd->buyingstore.slots = i; // store actual amount of items safestrncpy(sd->message, storename, sizeof(sd->message)); clif->buyingstore_myitemlist(sd); - clif->buyingstore_entry(sd); + clif->buyingstore_entry(&sd->bl, sd->message); } static void buyingstore_close(struct map_session_data *sd) diff --git a/src/map/clif.c b/src/map/clif.c index 918489593af..1d7e27092c6 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -4938,7 +4938,7 @@ static void clif_getareachar_pc(struct map_session_data *sd, struct map_session_ } else if( dstsd->state.vending ) clif->showvendingboard(&dstsd->bl,dstsd->message,sd->fd); else if( dstsd->state.buyingstore ) - clif->buyingstore_entry_single(sd, dstsd); + clif->buyingstore_entry_single(&dstsd->bl, dstsd->message, sd->fd); if(dstsd->spiritball > 0) clif->spiritball_single(sd->fd, dstsd); @@ -19958,31 +19958,30 @@ static void clif_buyingstore_myitemlist(struct map_session_data *sd) /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY). /// 0814 .L .80B -static void clif_buyingstore_entry(struct map_session_data *sd) +static void clif_buyingstore_entry(struct block_list *bl, const char *message) { #if PACKETVER >= 20100420 - uint8 buf[86]; - - nullpo_retv(sd); - WBUFW(buf,0) = 0x814; - WBUFL(buf,2) = sd->bl.id; - memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE); + nullpo_retv(bl); - clif->send(buf, packet_len(0x814), &sd->bl, AREA_WOS); + struct PACKET_ZC_BUYING_STORE_ENTRY p = { 0 }; + p.packetType = HEADER_ZC_BUYING_STORE_ENTRY; + p.makerAID = bl->id; + safestrncpy(p.storeName, message, MESSAGE_SIZE); + clif->send(&p, sizeof(struct PACKET_ZC_BUYING_STORE_ENTRY), bl, AREA_WOS); #endif } -static void clif_buyingstore_entry_single(struct map_session_data *sd, struct map_session_data *pl_sd) +static void clif_buyingstore_entry_single(struct block_list *bl, const char *message, int fd) { #if PACKETVER >= 20100420 - int fd; - - nullpo_retv(sd); - fd = sd->fd; - WFIFOHEAD(fd,packet_len(0x814)); - WFIFOW(fd,0) = 0x814; - WFIFOL(fd,2) = pl_sd->bl.id; - memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE); - WFIFOSET(fd,packet_len(0x814)); + nullpo_retv(bl); + nullpo_retv(message); + + WFIFOHEAD(fd, sizeof(struct PACKET_ZC_BUYING_STORE_ENTRY)); + struct PACKET_ZC_BUYING_STORE_ENTRY *p = WFIFOP(fd, 0); + p->packetType = HEADER_ZC_BUYING_STORE_ENTRY; + p->makerAID = bl->id; + safestrncpy(p->storeName, message, MESSAGE_SIZE); + WFIFOSET(fd, sizeof(struct PACKET_ZC_BUYING_STORE_ENTRY)); #endif } diff --git a/src/map/clif.h b/src/map/clif.h index ccf066c72e9..efbf2632ccf 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -1414,8 +1414,8 @@ struct clif_interface { void (*buyingstore_open) (struct map_session_data* sd); void (*buyingstore_open_failed) (struct map_session_data* sd, unsigned short result, unsigned int weight); void (*buyingstore_myitemlist) (struct map_session_data* sd); - void (*buyingstore_entry) (struct map_session_data* sd); - void (*buyingstore_entry_single) (struct map_session_data* sd, struct map_session_data* pl_sd); + void (*buyingstore_entry) (struct block_list *bl, const char *message); + void (*buyingstore_entry_single) (struct block_list *bl, const char *message, int fd); void (*buyingstore_disappear_entry) (struct map_session_data* sd); void (*buyingstore_disappear_entry_single) (struct map_session_data* sd, struct map_session_data* pl_sd); void (*buyingstore_itemlist) (struct map_session_data* sd, struct map_session_data* pl_sd); diff --git a/src/map/packets_struct.h b/src/map/packets_struct.h index 4b8bc2fe0a3..94f16bc815a 100644 --- a/src/map/packets_struct.h +++ b/src/map/packets_struct.h @@ -5502,7 +5502,6 @@ struct PACKET_CZ_APPROXIMATE_ACTOR { DEFINE_PACKET_HEADER(CZ_APPROXIMATE_ACTOR, 0x0bb0) #endif // PACKETVER_MAIN_NUM >= 20220216 - struct PACKET_CZ_CONTACTNPC { int16 PacketType; uint32 AID; @@ -5668,6 +5667,15 @@ struct PACKET_ZC_SOUND { } __attribute__((packed)); DEFINE_PACKET_HEADER(ZC_SOUND, 0x01d3) +#if PACKETVER >= 20100420 +struct PACKET_ZC_BUYING_STORE_ENTRY { + int16 packetType; + uint32 makerAID; + char storeName[MESSAGE_SIZE]; +} __attribute__((packed)); +DEFINE_PACKET_HEADER(ZC_BUYING_STORE_ENTRY, 0x0814); +#endif + #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 From 55a05ab3df258933f4309e80f7b250f95fcec204 Mon Sep 17 00:00:00 2001 From: Asheraf Date: Mon, 7 Mar 2022 21:02:27 +0100 Subject: [PATCH 02/10] Update PACKET_ZC_STORE_ENTRY to use struct format --- src/map/clif.c | 21 ++++++++++----------- src/map/packets_struct.h | 7 +++++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/map/clif.c b/src/map/clif.c index 1d7e27092c6..975d14ac8a8 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -7105,20 +7105,19 @@ static void clif_openvendingreq(struct map_session_data *sd, int num) /// 0131 .L .80B static void clif_showvendingboard(struct block_list *bl, const char *message, int fd) { - unsigned char buf[128]; - nullpo_retv(bl); + nullpo_retv(message); - WBUFW(buf,0) = 0x131; - WBUFL(buf,2) = bl->id; - safestrncpy(WBUFP(buf,6), message, 80); - - if( fd ) { - WFIFOHEAD(fd,packet_len(0x131)); - memcpy(WFIFOP(fd,0),buf,packet_len(0x131)); - WFIFOSET(fd,packet_len(0x131)); + struct PACKET_ZC_STORE_ENTRY p = { 0 }; + p.packetType = HEADER_ZC_STORE_ENTRY; + p.makerAID = bl->id; + safestrncpy(p.storeName, message, MESSAGE_SIZE); + if (fd != 0) { + WFIFOHEAD(fd, sizeof(struct PACKET_ZC_STORE_ENTRY)); + memcpy(WFIFOP(fd, 0), &p, sizeof(struct PACKET_ZC_STORE_ENTRY)); + WFIFOSET(fd, sizeof(struct PACKET_ZC_STORE_ENTRY)); } else { - clif->send(buf,packet_len(0x131),bl,AREA_WOS); + clif->send(&p, sizeof(struct PACKET_ZC_STORE_ENTRY), bl, AREA_WOS); } } diff --git a/src/map/packets_struct.h b/src/map/packets_struct.h index 94f16bc815a..172707b2c1a 100644 --- a/src/map/packets_struct.h +++ b/src/map/packets_struct.h @@ -5676,6 +5676,13 @@ struct PACKET_ZC_BUYING_STORE_ENTRY { DEFINE_PACKET_HEADER(ZC_BUYING_STORE_ENTRY, 0x0814); #endif +struct PACKET_ZC_STORE_ENTRY { + int16 packetType; + uint32 makerAID; + char storeName[MESSAGE_SIZE]; +} __attribute__((packed)); +DEFINE_PACKET_HEADER(ZC_STORE_ENTRY, 0x0131); + #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 From df35db7825183a295610d7614882c764ab1d5f5a Mon Sep 17 00:00:00 2001 From: Asheraf Date: Mon, 7 Mar 2022 21:06:21 +0100 Subject: [PATCH 03/10] Update PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC to use struct format --- src/map/clif.c | 11 ++++------- src/map/packets_struct.h | 13 +++++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/map/clif.c b/src/map/clif.c index 975d14ac8a8..065979624ed 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -15221,17 +15221,14 @@ static void clif_parse_PurchaseReq(int fd, struct map_session_data *sd) if (sd->state.trading || pc_isdead(sd) || pc_isvending(sd)) return; - int len = (int)RFIFOW(fd, 2) - 8; - int id; - const uint8 *data; + const struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC *p = RP2PTR(fd); + const int len = p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC); if (len < 1) return; - id = RFIFOL(fd, 4); - data = RFIFOP(fd, 8); - - vending->purchase(sd, id, sd->vended_id, data, len/4); + int item_count = len / sizeof(struct CZ_PURCHASE_ITEM_FROMMC); + vending->purchase(sd, p->AID, sd->vended_id, (const uint8 *)&p->list, item_count); // whether it fails or not, the buy window is closed sd->vended_id = 0; diff --git a/src/map/packets_struct.h b/src/map/packets_struct.h index 172707b2c1a..f76901fb940 100644 --- a/src/map/packets_struct.h +++ b/src/map/packets_struct.h @@ -5683,6 +5683,19 @@ struct PACKET_ZC_STORE_ENTRY { } __attribute__((packed)); DEFINE_PACKET_HEADER(ZC_STORE_ENTRY, 0x0131); +struct CZ_PURCHASE_ITEM_FROMMC { + int16 count; + int16 index; +} __attribute__((packed)); + +struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC { + int16 packetType; + int16 packetLength; + uint32 AID; + struct CZ_PURCHASE_ITEM_FROMMC list[]; +} __attribute__((packed)); +DEFINE_PACKET_HEADER(CZ_PC_PURCHASE_ITEMLIST_FROMMC, 0x0134); + #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 From fa27d3d177e03cc78296fb5b386a8751401a2a39 Mon Sep 17 00:00:00 2001 From: Asheraf Date: Mon, 7 Mar 2022 21:09:19 +0100 Subject: [PATCH 04/10] Update PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2 to use struct format --- src/map/clif.c | 12 ++++-------- src/map/packets_struct.h | 9 +++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/map/clif.c b/src/map/clif.c index 065979624ed..c06557ccc5f 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -15242,18 +15242,14 @@ static void clif_parse_PurchaseReq2(int fd, struct map_session_data *sd) if (sd->state.trading || pc_isdead(sd) || pc_isvending(sd)) return; - int len = (int)RFIFOW(fd, 2) - 12; - int aid; - int uid; - const uint8 *data; + const struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2 *p = RP2PTR(fd); + const int len = p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2); if (len < 1) return; - aid = RFIFOL(fd, 4); - uid = RFIFOL(fd, 8); - data = RFIFOP(fd, 12); - vending->purchase(sd, aid, uid, data, len/4); + int item_count = len / sizeof(struct CZ_PURCHASE_ITEM_FROMMC); + vending->purchase(sd, p->AID, p->UniqueID, (const uint8 *)&p->list, item_count); // whether it fails or not, the buy window is closed sd->vended_id = 0; diff --git a/src/map/packets_struct.h b/src/map/packets_struct.h index f76901fb940..e80860a29bc 100644 --- a/src/map/packets_struct.h +++ b/src/map/packets_struct.h @@ -5696,6 +5696,15 @@ struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC { } __attribute__((packed)); DEFINE_PACKET_HEADER(CZ_PC_PURCHASE_ITEMLIST_FROMMC, 0x0134); +struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2 { + int16 packetType; + int16 packetLength; + uint32 AID; + uint32 UniqueID; + struct CZ_PURCHASE_ITEM_FROMMC list[]; +} __attribute__((packed)); +DEFINE_PACKET_HEADER(CZ_PC_PURCHASE_ITEMLIST_FROMMC2, 0x0801); + #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 From a0572a5885baa44df63bb4c7cfa45d29d84a698f Mon Sep 17 00:00:00 2001 From: Asheraf Date: Mon, 7 Mar 2022 21:18:16 +0100 Subject: [PATCH 05/10] Update PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY to use struct format --- src/map/buyingstore.c | 2 +- src/map/clif.c | 31 +++++++++++++------------------ src/map/clif.h | 4 ++-- src/map/packets_struct.h | 8 ++++++++ 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/map/buyingstore.c b/src/map/buyingstore.c index 930297151dc..dc0f200a8c6 100644 --- a/src/map/buyingstore.c +++ b/src/map/buyingstore.c @@ -210,7 +210,7 @@ static void buyingstore_close(struct map_session_data *sd) memset(&sd->buyingstore, 0, sizeof(sd->buyingstore)); // notify other players - clif->buyingstore_disappear_entry(sd); + clif->buyingstore_disappear_entry(&sd->bl); } } diff --git a/src/map/clif.c b/src/map/clif.c index c06557ccc5f..88da085b7ed 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -5474,7 +5474,7 @@ static int clif_outsight(struct block_list *bl, va_list ap) if( sd->state.vending ) clif->closevendingboard(bl,tsd->fd); if( sd->state.buyingstore ) - clif->buyingstore_disappear_entry_single(tsd, sd); + clif->buyingstore_disappear_entry_single(bl, tsd->fd); break; case BL_ITEM: clif->clearflooritem(BL_UCAST(BL_ITEM, bl), tsd->fd); @@ -19987,31 +19987,26 @@ static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data *sd) /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY). /// 0816 .L -static void clif_buyingstore_disappear_entry(struct map_session_data *sd) +static void clif_buyingstore_disappear_entry(struct block_list *bl) { #if PACKETVER >= 20100309 - uint8 buf[6]; - - nullpo_retv(sd); - WBUFW(buf,0) = 0x816; - WBUFL(buf,2) = sd->bl.id; + nullpo_retv(bl); - clif->send(buf, packet_len(0x816), &sd->bl, AREA_WOS); + struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY p = { 0 }; + p.packetType = HEADER_ZC_DISAPPEAR_BUYING_STORE_ENTRY; + p.makerAID = bl->id; + clif->send(&p, sizeof(struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY), bl, AREA_WOS); #endif } -static void clif_buyingstore_disappear_entry_single(struct map_session_data *sd, struct map_session_data *pl_sd) +static void clif_buyingstore_disappear_entry_single(struct block_list *bl, int fd) { #if PACKETVER >= 20100309 - int fd; - - nullpo_retv(sd); - nullpo_retv(pl_sd); - fd = sd->fd; - WFIFOHEAD(fd,packet_len(0x816)); - WFIFOW(fd,0) = 0x816; - WFIFOL(fd,2) = pl_sd->bl.id; - WFIFOSET(fd,packet_len(0x816)); + WFIFOHEAD(fd, sizeof(struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY)); + struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY *p = WFIFOP(fd, 0); + p->packetType = HEADER_ZC_DISAPPEAR_BUYING_STORE_ENTRY; + p->makerAID = bl->id; + WFIFOSET(fd, sizeof(struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY)); #endif } diff --git a/src/map/clif.h b/src/map/clif.h index efbf2632ccf..2df803259b8 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -1416,8 +1416,8 @@ struct clif_interface { void (*buyingstore_myitemlist) (struct map_session_data* sd); void (*buyingstore_entry) (struct block_list *bl, const char *message); void (*buyingstore_entry_single) (struct block_list *bl, const char *message, int fd); - void (*buyingstore_disappear_entry) (struct map_session_data* sd); - void (*buyingstore_disappear_entry_single) (struct map_session_data* sd, struct map_session_data* pl_sd); + void (*buyingstore_disappear_entry) (struct block_list *bl); + void (*buyingstore_disappear_entry_single) (struct block_list *bl, int fd); void (*buyingstore_itemlist) (struct map_session_data* sd, struct map_session_data* pl_sd); void (*buyingstore_trade_failed_buyer) (struct map_session_data* sd, short result); void (*buyingstore_update_item) (struct map_session_data* sd, int nameid, unsigned short amount, uint32 char_id, int zeny); diff --git a/src/map/packets_struct.h b/src/map/packets_struct.h index e80860a29bc..5098d034ffd 100644 --- a/src/map/packets_struct.h +++ b/src/map/packets_struct.h @@ -5705,6 +5705,14 @@ struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2 { } __attribute__((packed)); DEFINE_PACKET_HEADER(CZ_PC_PURCHASE_ITEMLIST_FROMMC2, 0x0801); +#if PACKETVER >= 20100309 +struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY { + int16 packetType; + uint32 makerAID; +} __attribute__((packed)); +DEFINE_PACKET_HEADER(ZC_DISAPPEAR_BUYING_STORE_ENTRY, 0x0816); +#endif + #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 From c4db2d358fb9e0a6b9bd281d9ff85fb1d24d2095 Mon Sep 17 00:00:00 2001 From: Asheraf Date: Mon, 7 Mar 2022 21:33:18 +0100 Subject: [PATCH 06/10] HPM Hooks Update --- src/plugins/HPMHooking/HPMHooking.Defs.inc | 16 +++---- .../HPMHooking/HPMHooking_map.Hooks.inc | 48 +++++++++---------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc index 26379820d97..c939360c59f 100644 --- a/src/plugins/HPMHooking/HPMHooking.Defs.inc +++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc @@ -2010,14 +2010,14 @@ typedef void (*HPMHOOK_pre_clif_buyingstore_open_failed) (struct map_session_dat typedef void (*HPMHOOK_post_clif_buyingstore_open_failed) (struct map_session_data *sd, unsigned short result, unsigned int weight); typedef void (*HPMHOOK_pre_clif_buyingstore_myitemlist) (struct map_session_data **sd); typedef void (*HPMHOOK_post_clif_buyingstore_myitemlist) (struct map_session_data *sd); -typedef void (*HPMHOOK_pre_clif_buyingstore_entry) (struct map_session_data **sd); -typedef void (*HPMHOOK_post_clif_buyingstore_entry) (struct map_session_data *sd); -typedef void (*HPMHOOK_pre_clif_buyingstore_entry_single) (struct map_session_data **sd, struct map_session_data **pl_sd); -typedef void (*HPMHOOK_post_clif_buyingstore_entry_single) (struct map_session_data *sd, struct map_session_data *pl_sd); -typedef void (*HPMHOOK_pre_clif_buyingstore_disappear_entry) (struct map_session_data **sd); -typedef void (*HPMHOOK_post_clif_buyingstore_disappear_entry) (struct map_session_data *sd); -typedef void (*HPMHOOK_pre_clif_buyingstore_disappear_entry_single) (struct map_session_data **sd, struct map_session_data **pl_sd); -typedef void (*HPMHOOK_post_clif_buyingstore_disappear_entry_single) (struct map_session_data *sd, struct map_session_data *pl_sd); +typedef void (*HPMHOOK_pre_clif_buyingstore_entry) (struct block_list **bl, const char **message); +typedef void (*HPMHOOK_post_clif_buyingstore_entry) (struct block_list *bl, const char *message); +typedef void (*HPMHOOK_pre_clif_buyingstore_entry_single) (struct block_list **bl, const char **message, int *fd); +typedef void (*HPMHOOK_post_clif_buyingstore_entry_single) (struct block_list *bl, const char *message, int fd); +typedef void (*HPMHOOK_pre_clif_buyingstore_disappear_entry) (struct block_list **bl); +typedef void (*HPMHOOK_post_clif_buyingstore_disappear_entry) (struct block_list *bl); +typedef void (*HPMHOOK_pre_clif_buyingstore_disappear_entry_single) (struct block_list **bl, int *fd); +typedef void (*HPMHOOK_post_clif_buyingstore_disappear_entry_single) (struct block_list *bl, int fd); typedef void (*HPMHOOK_pre_clif_buyingstore_itemlist) (struct map_session_data **sd, struct map_session_data **pl_sd); typedef void (*HPMHOOK_post_clif_buyingstore_itemlist) (struct map_session_data *sd, struct map_session_data *pl_sd); typedef void (*HPMHOOK_pre_clif_buyingstore_trade_failed_buyer) (struct map_session_data **sd, short *result); diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc index d5848d30efd..565945cc82d 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc @@ -20838,14 +20838,14 @@ void HP_clif_buyingstore_myitemlist(struct map_session_data *sd) { } return; } -void HP_clif_buyingstore_entry(struct map_session_data *sd) { +void HP_clif_buyingstore_entry(struct block_list *bl, const char *message) { int hIndex = 0; if (HPMHooks.count.HP_clif_buyingstore_entry_pre > 0) { - void (*preHookFunc) (struct map_session_data **sd); + void (*preHookFunc) (struct block_list **bl, const char **message); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_clif_buyingstore_entry_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_clif_buyingstore_entry_pre[hIndex].func; - preHookFunc(&sd); + preHookFunc(&bl, &message); } if (*HPMforce_return) { *HPMforce_return = false; @@ -20853,25 +20853,25 @@ void HP_clif_buyingstore_entry(struct map_session_data *sd) { } } { - HPMHooks.source.clif.buyingstore_entry(sd); + HPMHooks.source.clif.buyingstore_entry(bl, message); } if (HPMHooks.count.HP_clif_buyingstore_entry_post > 0) { - void (*postHookFunc) (struct map_session_data *sd); + void (*postHookFunc) (struct block_list *bl, const char *message); for (hIndex = 0; hIndex < HPMHooks.count.HP_clif_buyingstore_entry_post; hIndex++) { postHookFunc = HPMHooks.list.HP_clif_buyingstore_entry_post[hIndex].func; - postHookFunc(sd); + postHookFunc(bl, message); } } return; } -void HP_clif_buyingstore_entry_single(struct map_session_data *sd, struct map_session_data *pl_sd) { +void HP_clif_buyingstore_entry_single(struct block_list *bl, const char *message, int fd) { int hIndex = 0; if (HPMHooks.count.HP_clif_buyingstore_entry_single_pre > 0) { - void (*preHookFunc) (struct map_session_data **sd, struct map_session_data **pl_sd); + void (*preHookFunc) (struct block_list **bl, const char **message, int *fd); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_clif_buyingstore_entry_single_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_clif_buyingstore_entry_single_pre[hIndex].func; - preHookFunc(&sd, &pl_sd); + preHookFunc(&bl, &message, &fd); } if (*HPMforce_return) { *HPMforce_return = false; @@ -20879,25 +20879,25 @@ void HP_clif_buyingstore_entry_single(struct map_session_data *sd, struct map_se } } { - HPMHooks.source.clif.buyingstore_entry_single(sd, pl_sd); + HPMHooks.source.clif.buyingstore_entry_single(bl, message, fd); } if (HPMHooks.count.HP_clif_buyingstore_entry_single_post > 0) { - void (*postHookFunc) (struct map_session_data *sd, struct map_session_data *pl_sd); + void (*postHookFunc) (struct block_list *bl, const char *message, int fd); for (hIndex = 0; hIndex < HPMHooks.count.HP_clif_buyingstore_entry_single_post; hIndex++) { postHookFunc = HPMHooks.list.HP_clif_buyingstore_entry_single_post[hIndex].func; - postHookFunc(sd, pl_sd); + postHookFunc(bl, message, fd); } } return; } -void HP_clif_buyingstore_disappear_entry(struct map_session_data *sd) { +void HP_clif_buyingstore_disappear_entry(struct block_list *bl) { int hIndex = 0; if (HPMHooks.count.HP_clif_buyingstore_disappear_entry_pre > 0) { - void (*preHookFunc) (struct map_session_data **sd); + void (*preHookFunc) (struct block_list **bl); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_clif_buyingstore_disappear_entry_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_clif_buyingstore_disappear_entry_pre[hIndex].func; - preHookFunc(&sd); + preHookFunc(&bl); } if (*HPMforce_return) { *HPMforce_return = false; @@ -20905,25 +20905,25 @@ void HP_clif_buyingstore_disappear_entry(struct map_session_data *sd) { } } { - HPMHooks.source.clif.buyingstore_disappear_entry(sd); + HPMHooks.source.clif.buyingstore_disappear_entry(bl); } if (HPMHooks.count.HP_clif_buyingstore_disappear_entry_post > 0) { - void (*postHookFunc) (struct map_session_data *sd); + void (*postHookFunc) (struct block_list *bl); for (hIndex = 0; hIndex < HPMHooks.count.HP_clif_buyingstore_disappear_entry_post; hIndex++) { postHookFunc = HPMHooks.list.HP_clif_buyingstore_disappear_entry_post[hIndex].func; - postHookFunc(sd); + postHookFunc(bl); } } return; } -void HP_clif_buyingstore_disappear_entry_single(struct map_session_data *sd, struct map_session_data *pl_sd) { +void HP_clif_buyingstore_disappear_entry_single(struct block_list *bl, int fd) { int hIndex = 0; if (HPMHooks.count.HP_clif_buyingstore_disappear_entry_single_pre > 0) { - void (*preHookFunc) (struct map_session_data **sd, struct map_session_data **pl_sd); + void (*preHookFunc) (struct block_list **bl, int *fd); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_clif_buyingstore_disappear_entry_single_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_clif_buyingstore_disappear_entry_single_pre[hIndex].func; - preHookFunc(&sd, &pl_sd); + preHookFunc(&bl, &fd); } if (*HPMforce_return) { *HPMforce_return = false; @@ -20931,13 +20931,13 @@ void HP_clif_buyingstore_disappear_entry_single(struct map_session_data *sd, str } } { - HPMHooks.source.clif.buyingstore_disappear_entry_single(sd, pl_sd); + HPMHooks.source.clif.buyingstore_disappear_entry_single(bl, fd); } if (HPMHooks.count.HP_clif_buyingstore_disappear_entry_single_post > 0) { - void (*postHookFunc) (struct map_session_data *sd, struct map_session_data *pl_sd); + void (*postHookFunc) (struct block_list *bl, int fd); for (hIndex = 0; hIndex < HPMHooks.count.HP_clif_buyingstore_disappear_entry_single_post; hIndex++) { postHookFunc = HPMHooks.list.HP_clif_buyingstore_disappear_entry_single_post[hIndex].func; - postHookFunc(sd, pl_sd); + postHookFunc(bl, fd); } } return; From 90af4a26a9231920f41d63e4eaf116494bcd90a6 Mon Sep 17 00:00:00 2001 From: Haru Date: Thu, 2 Jun 2022 05:39:13 +0200 Subject: [PATCH 07/10] Add some missing nullpo checks Signed-off-by: Haru --- src/map/clif.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/map/clif.c b/src/map/clif.c index 88da085b7ed..1b3a2d90707 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -19954,6 +19954,7 @@ static void clif_buyingstore_entry(struct block_list *bl, const char *message) { #if PACKETVER >= 20100420 nullpo_retv(bl); + nullpo_retv(message); struct PACKET_ZC_BUYING_STORE_ENTRY p = { 0 }; p.packetType = HEADER_ZC_BUYING_STORE_ENTRY; @@ -20002,6 +20003,8 @@ static void clif_buyingstore_disappear_entry(struct block_list *bl) static void clif_buyingstore_disappear_entry_single(struct block_list *bl, int fd) { #if PACKETVER >= 20100309 + nullpo_retv(bl); + WFIFOHEAD(fd, sizeof(struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY)); struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY *p = WFIFOP(fd, 0); p->packetType = HEADER_ZC_DISAPPEAR_BUYING_STORE_ENTRY; From 463c81e86657f6de6740339b4b182c1c6b996782 Mon Sep 17 00:00:00 2001 From: Haru Date: Thu, 2 Jun 2022 05:39:54 +0200 Subject: [PATCH 08/10] Improve type safety of vending->purchase() Signed-off-by: Haru --- src/map/clif.c | 4 ++-- src/map/vending.c | 13 ++++++------- src/map/vending.h | 3 ++- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/map/clif.c b/src/map/clif.c index 1b3a2d90707..a2d0c358fcb 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -15228,7 +15228,7 @@ static void clif_parse_PurchaseReq(int fd, struct map_session_data *sd) return; int item_count = len / sizeof(struct CZ_PURCHASE_ITEM_FROMMC); - vending->purchase(sd, p->AID, sd->vended_id, (const uint8 *)&p->list, item_count); + vending->purchase(sd, p->AID, sd->vended_id, p->list, item_count); // whether it fails or not, the buy window is closed sd->vended_id = 0; @@ -15249,7 +15249,7 @@ static void clif_parse_PurchaseReq2(int fd, struct map_session_data *sd) return; int item_count = len / sizeof(struct CZ_PURCHASE_ITEM_FROMMC); - vending->purchase(sd, p->AID, p->UniqueID, (const uint8 *)&p->list, item_count); + vending->purchase(sd, p->AID, p->UniqueID, p->list, item_count); // whether it fails or not, the buy window is closed sd->vended_id = 0; diff --git a/src/map/vending.c b/src/map/vending.c index 3b8ff05a309..4dd920c7345 100644 --- a/src/map/vending.c +++ b/src/map/vending.c @@ -30,6 +30,7 @@ #include "map/log.h" #include "map/map.h" #include "map/npc.h" +#include "map/packets_struct.h" #include "map/path.h" #include "map/pc.h" #include "map/skill.h" @@ -89,7 +90,7 @@ static void vending_vendinglistreq(struct map_session_data *sd, unsigned int id) /*========================================== * Purchase item(s) from a shop *------------------------------------------*/ -static void vending_purchasereq(struct map_session_data *sd, int aid, unsigned int uid, const uint8 *data, int count) +static void vending_purchasereq(struct map_session_data *sd, int aid, unsigned int uid, const struct CZ_PURCHASE_ITEM_FROMMC *data, int count) { int i, j, cursor, w, new_ = 0, blank, vend_list[MAX_VENDING]; int64 z; @@ -123,9 +124,8 @@ static void vending_purchasereq(struct map_session_data *sd, int aid, unsigned i z = 0; // zeny counter w = 0; // weight counter for (i = 0; i < count; i++) { - short amount = *(const uint16*)(data + 4*i + 0); - short idx = *(const uint16*)(data + 4*i + 2); - idx -= 2; + short amount = data[i].count; + short idx = data[i].index - 2; if( amount <= 0 ) return; @@ -189,9 +189,8 @@ static void vending_purchasereq(struct map_session_data *sd, int aid, unsigned i pc->getzeny(vsd, (int)z, LOG_TYPE_VENDING, sd); for (i = 0; i < count; i++) { - short amount = *(const uint16*)(data + 4*i + 0); - short idx = *(const uint16*)(data + 4*i + 2); - idx -= 2; + short amount = data[i].count; + short idx = data[i].index - 2; // vending item pc->additem(sd, &vsd->status.cart[idx], amount, LOG_TYPE_VENDING); diff --git a/src/map/vending.h b/src/map/vending.h index 3c34a5056ba..6a79170d23b 100644 --- a/src/map/vending.h +++ b/src/map/vending.h @@ -27,6 +27,7 @@ struct DBMap; // common/db.h struct map_session_data; struct s_search_store_search; +struct CZ_PURCHASE_ITEM_FROMMC; struct s_vending { short index; //cart index (return item data) @@ -44,7 +45,7 @@ struct vending_interface { void (*close) (struct map_session_data* sd); void (*open) (struct map_session_data* sd, const char* message, const uint8* data, int count); void (*list) (struct map_session_data* sd, unsigned int id); - void (*purchase) (struct map_session_data* sd, int aid, unsigned int uid, const uint8* data, int count); + void (*purchase) (struct map_session_data* sd, int aid, unsigned int uid, const struct CZ_PURCHASE_ITEM_FROMMC *data, int count); bool (*search) (struct map_session_data* sd, int nameid); bool (*searchall) (struct map_session_data* sd, const struct s_search_store_search* s); }; From 8ea7b89693e7552b085c7854a48bdd63aa548767 Mon Sep 17 00:00:00 2001 From: Haru Date: Thu, 2 Jun 2022 05:40:21 +0200 Subject: [PATCH 09/10] Fix a const correctness warning in clif_parse_NpcClicked Signed-off-by: Haru --- src/map/clif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/clif.c b/src/map/clif.c index a2d0c358fcb..2935bc5fa58 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -12641,7 +12641,7 @@ static void clif_parse_NpcClicked(int fd, struct map_session_data *sd) { struct block_list *bl; - struct PACKET_CZ_CONTACTNPC *packet = RFIFOP(fd, 0); + const struct PACKET_CZ_CONTACTNPC *packet = RFIFOP(fd, 0); if( pc_isdead(sd) ) { clif->clearunit_area(&sd->bl,CLR_DEAD); From 603784084cd3ac3ff7a6898c62d05282817405ce Mon Sep 17 00:00:00 2001 From: Haru Date: Thu, 2 Jun 2022 05:46:15 +0200 Subject: [PATCH 10/10] Update HPM Hooks Signed-off-by: Haru --- src/common/HPMDataCheck.h | 4 ++++ src/plugins/HPMHooking/HPMHooking.Defs.inc | 4 ++-- src/plugins/HPMHooking/HPMHooking_map.Hooks.inc | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/common/HPMDataCheck.h b/src/common/HPMDataCheck.h index 15164a79d88..a6ded261218 100644 --- a/src/common/HPMDataCheck.h +++ b/src/common/HPMDataCheck.h @@ -642,6 +642,7 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = { #define MAP_NPC_H #endif // MAP_NPC_H #ifdef MAP_PACKETS_STRUCT_H + { "CZ_PURCHASE_ITEM_FROMMC", sizeof(struct CZ_PURCHASE_ITEM_FROMMC), SERVER_TYPE_MAP }, { "EQUIPITEM_INFO", sizeof(struct EQUIPITEM_INFO), SERVER_TYPE_MAP }, { "EQUIPSLOTINFO", sizeof(struct EQUIPSLOTINFO), SERVER_TYPE_MAP }, { "GUILD_MEMBER_INFO", sizeof(struct GUILD_MEMBER_INFO), SERVER_TYPE_MAP }, @@ -657,6 +658,8 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = { { "PACKET_CZ_PC_BUY_CASH_POINT_ITEM", sizeof(struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM), SERVER_TYPE_MAP }, { "PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub", sizeof(struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub), SERVER_TYPE_MAP }, { "PACKET_CZ_PC_PURCHASE_ITEMLIST", sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST), SERVER_TYPE_MAP }, + { "PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC", sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC), SERVER_TYPE_MAP }, + { "PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2", sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2), SERVER_TYPE_MAP }, { "PACKET_CZ_PC_PURCHASE_ITEMLIST_sub", sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub), SERVER_TYPE_MAP }, { "PACKET_CZ_PET_EVOLUTION", sizeof(struct PACKET_CZ_PET_EVOLUTION), SERVER_TYPE_MAP }, { "PACKET_CZ_PRIVATE_AIRSHIP_REQUEST", sizeof(struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST), SERVER_TYPE_MAP }, @@ -798,6 +801,7 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = { { "PACKET_ZC_STATE_CHANGE", sizeof(struct PACKET_ZC_STATE_CHANGE), SERVER_TYPE_MAP }, { "PACKET_ZC_STATUS_CHANGE", sizeof(struct PACKET_ZC_STATUS_CHANGE), SERVER_TYPE_MAP }, { "PACKET_ZC_STATUS_CHANGE_ACK", sizeof(struct PACKET_ZC_STATUS_CHANGE_ACK), SERVER_TYPE_MAP }, + { "PACKET_ZC_STORE_ENTRY", sizeof(struct PACKET_ZC_STORE_ENTRY), SERVER_TYPE_MAP }, { "PACKET_ZC_STYLE_CHANGE_RES", sizeof(struct PACKET_ZC_STYLE_CHANGE_RES), SERVER_TYPE_MAP }, { "PACKET_ZC_TALKBOX_CHATCONTENTS", sizeof(struct PACKET_ZC_TALKBOX_CHATCONTENTS), SERVER_TYPE_MAP }, { "PACKET_ZC_TRYCAPTURE_MONSTER", sizeof(struct PACKET_ZC_TRYCAPTURE_MONSTER), SERVER_TYPE_MAP }, diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc index c939360c59f..349070d9fc4 100644 --- a/src/plugins/HPMHooking/HPMHooking.Defs.inc +++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc @@ -8856,8 +8856,8 @@ typedef void (*HPMHOOK_pre_vending_open) (struct map_session_data **sd, const ch typedef void (*HPMHOOK_post_vending_open) (struct map_session_data *sd, const char *message, const uint8 *data, int count); typedef void (*HPMHOOK_pre_vending_list) (struct map_session_data **sd, unsigned int *id); typedef void (*HPMHOOK_post_vending_list) (struct map_session_data *sd, unsigned int id); -typedef void (*HPMHOOK_pre_vending_purchase) (struct map_session_data **sd, int *aid, unsigned int *uid, const uint8 **data, int *count); -typedef void (*HPMHOOK_post_vending_purchase) (struct map_session_data *sd, int aid, unsigned int uid, const uint8 *data, int count); +typedef void (*HPMHOOK_pre_vending_purchase) (struct map_session_data **sd, int *aid, unsigned int *uid, const struct CZ_PURCHASE_ITEM_FROMMC **data, int *count); +typedef void (*HPMHOOK_post_vending_purchase) (struct map_session_data *sd, int aid, unsigned int uid, const struct CZ_PURCHASE_ITEM_FROMMC *data, int count); typedef bool (*HPMHOOK_pre_vending_search) (struct map_session_data **sd, int *nameid); typedef bool (*HPMHOOK_post_vending_search) (bool retVal___, struct map_session_data *sd, int nameid); typedef bool (*HPMHOOK_pre_vending_searchall) (struct map_session_data **sd, const struct s_search_store_search **s); diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc index 565945cc82d..db7de0c7810 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc @@ -98219,10 +98219,10 @@ void HP_vending_list(struct map_session_data *sd, unsigned int id) { } return; } -void HP_vending_purchase(struct map_session_data *sd, int aid, unsigned int uid, const uint8 *data, int count) { +void HP_vending_purchase(struct map_session_data *sd, int aid, unsigned int uid, const struct CZ_PURCHASE_ITEM_FROMMC *data, int count) { int hIndex = 0; if (HPMHooks.count.HP_vending_purchase_pre > 0) { - void (*preHookFunc) (struct map_session_data **sd, int *aid, unsigned int *uid, const uint8 **data, int *count); + void (*preHookFunc) (struct map_session_data **sd, int *aid, unsigned int *uid, const struct CZ_PURCHASE_ITEM_FROMMC **data, int *count); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_vending_purchase_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_vending_purchase_pre[hIndex].func; @@ -98237,7 +98237,7 @@ void HP_vending_purchase(struct map_session_data *sd, int aid, unsigned int uid, HPMHooks.source.vending.purchase(sd, aid, uid, data, count); } if (HPMHooks.count.HP_vending_purchase_post > 0) { - void (*postHookFunc) (struct map_session_data *sd, int aid, unsigned int uid, const uint8 *data, int count); + void (*postHookFunc) (struct map_session_data *sd, int aid, unsigned int uid, const struct CZ_PURCHASE_ITEM_FROMMC *data, int count); for (hIndex = 0; hIndex < HPMHooks.count.HP_vending_purchase_post; hIndex++) { postHookFunc = HPMHooks.list.HP_vending_purchase_post[hIndex].func; postHookFunc(sd, aid, uid, data, count);