From a6324c524f34792236900b8338ff2e733c7de230 Mon Sep 17 00:00:00 2001 From: csnv Date: Sun, 11 Aug 2024 18:28:01 +0200 Subject: [PATCH] Fixed buyingstores not being searchable with searchstore --- src/map/buyingstore.c | 18 ++- src/map/buyingstore.h | 4 + src/map/map.c | 2 + src/map/searchstore.c | 23 ++- src/plugins/HPMHooking/HPMHooking.Defs.inc | 10 ++ .../HPMHooking_map.HPMHooksCore.inc | 20 +++ .../HPMHooking_map.HookingPoints.inc | 5 + .../HPMHooking/HPMHooking_map.Hooks.inc | 131 ++++++++++++++++++ tools/validateinterfaces.py | 1 + 9 files changed, 209 insertions(+), 5 deletions(-) diff --git a/src/map/buyingstore.c b/src/map/buyingstore.c index b86e5a334..40ebdca5f 100644 --- a/src/map/buyingstore.c +++ b/src/map/buyingstore.c @@ -79,6 +79,8 @@ static bool buyingstore_setup(struct map_session_data *sd, unsigned char slots) sd->buyingstore.slots = slots; clif->buyingstore_open(sd); + idb_put(buyingstore->db, sd->status.char_id, sd); + return true; } @@ -212,6 +214,7 @@ static void buyingstore_close(struct map_session_data *sd) // notify other players clif->buyingstore_disappear_entry(&sd->bl); + idb_remove(buyingstore->db, sd->status.char_id); } } @@ -489,13 +492,26 @@ static bool buyingstore_searchall(struct map_session_data *sd, const struct s_se return true; } +static void final(void) +{ + db_destroy(buyingstore->db); +} + +static void init(bool minimal) +{ + buyingstore->db = idb_alloc(DB_OPT_BASE); + buyingstore->nextid = 0; +} + void buyingstore_defaults(void) { buyingstore = &buyingstore_s; - buyingstore->nextid = 0; memset(buyingstore->blankslots, 0, sizeof(buyingstore->blankslots)); memset(buyingstore->blankoptions, 0, sizeof(buyingstore->blankoptions)); + + buyingstore->init = init; + buyingstore->final = final; /* */ buyingstore->setup = buyingstore_setup; buyingstore->create = buyingstore_create; diff --git a/src/map/buyingstore.h b/src/map/buyingstore.h index 556980710..4fbb0d161 100644 --- a/src/map/buyingstore.h +++ b/src/map/buyingstore.h @@ -77,9 +77,13 @@ struct s_buyingstore { **/ struct buyingstore_interface { unsigned int nextid; + struct DBMap* db; int blankslots[MAX_SLOTS]; // used when checking whether or not an item's card slots are blank struct item_option blankoptions[MAX_ITEM_OPTIONS]; // used for search result temporary. /* */ + void (*init) (bool minimal); + void (*final) (void); + /* */ bool (*setup) (struct map_session_data* sd, unsigned char slots); void (*create) (struct map_session_data* sd, int zenylimit, unsigned char result, const char* storename, const struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub* itemlist, unsigned int count); void (*close) (struct map_session_data* sd); diff --git a/src/map/map.c b/src/map/map.c index d181fe563..d3c88d1cf 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -6545,6 +6545,7 @@ int do_final(void) elemental->final(); map->list_final(); vending->final(); + buyingstore->final(); rodex->final(); achievement->final(); stylist->final(); @@ -7102,6 +7103,7 @@ int do_init(int argc, char *argv[]) bg->init(minimal); duel->init(minimal); vending->init(minimal); + buyingstore->init(minimal); rodex->init(minimal); mapiif->init(minimal); diff --git a/src/map/searchstore.c b/src/map/searchstore.c index df3d8fa6f..7f36ba1e9 100644 --- a/src/map/searchstore.c +++ b/src/map/searchstore.c @@ -76,6 +76,16 @@ static inline unsigned int searchstore_getstoreid(struct map_session_data *sd, u return 0; } +/// return vender/buyer database by type +static inline struct DBMap* searchstore_getdatabase(unsigned char type) +{ + switch (type) { + case SEARCHTYPE_VENDING: return vending->db; + case SEARCHTYPE_BUYING_STORE: return buyingstore->db; + } + return NULL; +} + static bool searchstore_open(struct map_session_data *sd, unsigned int uses, unsigned short effect) { nullpo_retr(false, sd); @@ -108,6 +118,7 @@ static void searchstore_query(struct map_session_data *sd, struct s_search_store_search s; searchstore_searchall_t store_searchall; time_t querytime; + struct DBMap* db; if( !battle_config.feature_search_stores ) { return; @@ -174,6 +185,10 @@ static void searchstore_query(struct map_session_data *sd, // allocate max. amount of results sd->searchstore.items = (struct s_search_store_info_item*)aMalloc(sizeof(struct s_search_store_info_item)*battle_config.searchstore_maxresults); + // Retrieve required database + db = searchstore_getdatabase(type); + nullpo_retv(db); + // search s.search_sd = sd; s.itemlist = itemlist; @@ -182,14 +197,14 @@ static void searchstore_query(struct map_session_data *sd, s.card_count = card_count; s.min_price = min_price; s.max_price = max_price; - iter = db_iterator(vending->db); + iter = db_iterator(db); - for( pl_sd = dbi_first(iter); dbi_exists(iter); pl_sd = dbi_next(iter) ) { - if( sd == pl_sd ) {// skip own shop, if any + for (pl_sd = dbi_first(iter); dbi_exists(iter); pl_sd = dbi_next(iter)) { + if (sd == pl_sd) { // skip own shop, if any continue; } - if( !store_searchall(pl_sd, &s) ) {// exceeded result size + if (!store_searchall(pl_sd, &s)) { // exceeded result size clif->search_store_info_failed(sd, SSI_FAILED_OVER_MAXCOUNT); break; } diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc index 09c771842..424a793f8 100644 --- a/src/plugins/HPMHooking/HPMHooking.Defs.inc +++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc @@ -638,6 +638,10 @@ typedef void (*HPMHOOK_pre_bg_config_read) (void); typedef void (*HPMHOOK_post_bg_config_read) (void); #endif // MAP_BATTLEGROUND_H #ifdef MAP_BUYINGSTORE_H /* buyingstore */ +typedef void (*HPMHOOK_pre_buyingstore_init) (bool *minimal); +typedef void (*HPMHOOK_post_buyingstore_init) (bool minimal); +typedef void (*HPMHOOK_pre_buyingstore_final) (void); +typedef void (*HPMHOOK_post_buyingstore_final) (void); typedef bool (*HPMHOOK_pre_buyingstore_setup) (struct map_session_data **sd, unsigned char *slots); typedef bool (*HPMHOOK_post_buyingstore_setup) (bool retVal___, struct map_session_data *sd, unsigned char slots); typedef void (*HPMHOOK_pre_buyingstore_create) (struct map_session_data **sd, int *zenylimit, unsigned char *result, const char **storename, const struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub **itemlist, unsigned int *count); @@ -7548,6 +7552,12 @@ typedef bool (*HPMHOOK_pre_pc_auto_exp_insurance) (struct map_session_data **sd) typedef bool (*HPMHOOK_post_pc_auto_exp_insurance) (bool retVal___, struct map_session_data *sd); typedef void (*HPMHOOK_pre_pc_crimson_marker_clear) (struct map_session_data **sd); typedef void (*HPMHOOK_post_pc_crimson_marker_clear) (struct map_session_data *sd); +typedef bool (*HPMHOOK_pre_pc_is_own_skill) (struct map_session_data **sd, uint16 *skill_id); +typedef bool (*HPMHOOK_post_pc_is_own_skill) (bool retVal___, struct map_session_data *sd, uint16 skill_id); +typedef void (*HPMHOOK_pre_pc_clear_existing_cloneskill) (struct map_session_data **sd, bool *clear_vars); +typedef void (*HPMHOOK_post_pc_clear_existing_cloneskill) (struct map_session_data *sd, bool clear_vars); +typedef void (*HPMHOOK_pre_pc_clear_existing_reproduceskill) (struct map_session_data **sd, bool *clear_vars); +typedef void (*HPMHOOK_post_pc_clear_existing_reproduceskill) (struct map_session_data *sd, bool clear_vars); #endif // MAP_PC_H #ifdef MAP_NPC_H /* libpcre */ typedef pcre* (*HPMHOOK_pre_libpcre_compile) (const char **pattern, int *options, const char ***errptr, int **erroffset, const unsigned char **tableptr); diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc index 3b7573540..2e76cffaf 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc @@ -400,6 +400,10 @@ struct { struct HPMHookPoint *HP_bg_str2teamtype_post; struct HPMHookPoint *HP_bg_config_read_pre; struct HPMHookPoint *HP_bg_config_read_post; + struct HPMHookPoint *HP_buyingstore_init_pre; + struct HPMHookPoint *HP_buyingstore_init_post; + struct HPMHookPoint *HP_buyingstore_final_pre; + struct HPMHookPoint *HP_buyingstore_final_post; struct HPMHookPoint *HP_buyingstore_setup_pre; struct HPMHookPoint *HP_buyingstore_setup_post; struct HPMHookPoint *HP_buyingstore_create_pre; @@ -5526,6 +5530,12 @@ struct { struct HPMHookPoint *HP_pc_auto_exp_insurance_post; struct HPMHookPoint *HP_pc_crimson_marker_clear_pre; struct HPMHookPoint *HP_pc_crimson_marker_clear_post; + struct HPMHookPoint *HP_pc_is_own_skill_pre; + struct HPMHookPoint *HP_pc_is_own_skill_post; + struct HPMHookPoint *HP_pc_clear_existing_cloneskill_pre; + struct HPMHookPoint *HP_pc_clear_existing_cloneskill_post; + struct HPMHookPoint *HP_pc_clear_existing_reproduceskill_pre; + struct HPMHookPoint *HP_pc_clear_existing_reproduceskill_post; struct HPMHookPoint *HP_libpcre_compile_pre; struct HPMHookPoint *HP_libpcre_compile_post; struct HPMHookPoint *HP_libpcre_study_pre; @@ -7987,6 +7997,10 @@ struct { int HP_bg_str2teamtype_post; int HP_bg_config_read_pre; int HP_bg_config_read_post; + int HP_buyingstore_init_pre; + int HP_buyingstore_init_post; + int HP_buyingstore_final_pre; + int HP_buyingstore_final_post; int HP_buyingstore_setup_pre; int HP_buyingstore_setup_post; int HP_buyingstore_create_pre; @@ -13113,6 +13127,12 @@ struct { int HP_pc_auto_exp_insurance_post; int HP_pc_crimson_marker_clear_pre; int HP_pc_crimson_marker_clear_post; + int HP_pc_is_own_skill_pre; + int HP_pc_is_own_skill_post; + int HP_pc_clear_existing_cloneskill_pre; + int HP_pc_clear_existing_cloneskill_post; + int HP_pc_clear_existing_reproduceskill_pre; + int HP_pc_clear_existing_reproduceskill_post; int HP_libpcre_compile_pre; int HP_libpcre_compile_post; int HP_libpcre_study_pre; diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc index 6eea16042..b10616bd0 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc @@ -220,6 +220,8 @@ struct HookingPointData HookingPoints[] = { { HP_POP(bg->str2teamtype, HP_bg_str2teamtype) }, { HP_POP(bg->config_read, HP_bg_config_read) }, /* buyingstore_interface */ + { HP_POP(buyingstore->init, HP_buyingstore_init) }, + { HP_POP(buyingstore->final, HP_buyingstore_final) }, { HP_POP(buyingstore->setup, HP_buyingstore_setup) }, { HP_POP(buyingstore->create, HP_buyingstore_create) }, { HP_POP(buyingstore->close, HP_buyingstore_close) }, @@ -2828,6 +2830,9 @@ struct HookingPointData HookingPoints[] = { { HP_POP(pc->expandInventory, HP_pc_expandInventory) }, { HP_POP(pc->auto_exp_insurance, HP_pc_auto_exp_insurance) }, { HP_POP(pc->crimson_marker_clear, HP_pc_crimson_marker_clear) }, + { HP_POP(pc->is_own_skill, HP_pc_is_own_skill) }, + { HP_POP(pc->clear_existing_cloneskill, HP_pc_clear_existing_cloneskill) }, + { HP_POP(pc->clear_existing_reproduceskill, HP_pc_clear_existing_reproduceskill) }, /* pcre_interface */ { HP_POP(libpcre->compile, HP_libpcre_compile) }, { HP_POP(libpcre->study, HP_libpcre_study) }, diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc index 0eb919422..5de3e8247 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc @@ -5091,6 +5091,58 @@ void HP_bg_config_read(void) { return; } /* buyingstore_interface */ +void HP_buyingstore_init(bool minimal) { + int hIndex = 0; + if (HPMHooks.count.HP_buyingstore_init_pre > 0) { + void (*preHookFunc) (bool *minimal); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_buyingstore_init_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_buyingstore_init_pre[hIndex].func; + preHookFunc(&minimal); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.buyingstore.init(minimal); + } + if (HPMHooks.count.HP_buyingstore_init_post > 0) { + void (*postHookFunc) (bool minimal); + for (hIndex = 0; hIndex < HPMHooks.count.HP_buyingstore_init_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_buyingstore_init_post[hIndex].func; + postHookFunc(minimal); + } + } + return; +} +void HP_buyingstore_final(void) { + int hIndex = 0; + if (HPMHooks.count.HP_buyingstore_final_pre > 0) { + void (*preHookFunc) (void); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_buyingstore_final_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_buyingstore_final_pre[hIndex].func; + preHookFunc(); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.buyingstore.final(); + } + if (HPMHooks.count.HP_buyingstore_final_post > 0) { + void (*postHookFunc) (void); + for (hIndex = 0; hIndex < HPMHooks.count.HP_buyingstore_final_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_buyingstore_final_post[hIndex].func; + postHookFunc(); + } + } + return; +} bool HP_buyingstore_setup(struct map_session_data *sd, unsigned char slots) { int hIndex = 0; bool retVal___ = false; @@ -73524,6 +73576,85 @@ void HP_pc_crimson_marker_clear(struct map_session_data *sd) { } return; } +bool HP_pc_is_own_skill(struct map_session_data *sd, uint16 skill_id) { + int hIndex = 0; + bool retVal___ = false; + if (HPMHooks.count.HP_pc_is_own_skill_pre > 0) { + bool (*preHookFunc) (struct map_session_data **sd, uint16 *skill_id); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_pc_is_own_skill_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_pc_is_own_skill_pre[hIndex].func; + retVal___ = preHookFunc(&sd, &skill_id); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.pc.is_own_skill(sd, skill_id); + } + if (HPMHooks.count.HP_pc_is_own_skill_post > 0) { + bool (*postHookFunc) (bool retVal___, struct map_session_data *sd, uint16 skill_id); + for (hIndex = 0; hIndex < HPMHooks.count.HP_pc_is_own_skill_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_pc_is_own_skill_post[hIndex].func; + retVal___ = postHookFunc(retVal___, sd, skill_id); + } + } + return retVal___; +} +void HP_pc_clear_existing_cloneskill(struct map_session_data *sd, bool clear_vars) { + int hIndex = 0; + if (HPMHooks.count.HP_pc_clear_existing_cloneskill_pre > 0) { + void (*preHookFunc) (struct map_session_data **sd, bool *clear_vars); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_pc_clear_existing_cloneskill_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_pc_clear_existing_cloneskill_pre[hIndex].func; + preHookFunc(&sd, &clear_vars); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.pc.clear_existing_cloneskill(sd, clear_vars); + } + if (HPMHooks.count.HP_pc_clear_existing_cloneskill_post > 0) { + void (*postHookFunc) (struct map_session_data *sd, bool clear_vars); + for (hIndex = 0; hIndex < HPMHooks.count.HP_pc_clear_existing_cloneskill_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_pc_clear_existing_cloneskill_post[hIndex].func; + postHookFunc(sd, clear_vars); + } + } + return; +} +void HP_pc_clear_existing_reproduceskill(struct map_session_data *sd, bool clear_vars) { + int hIndex = 0; + if (HPMHooks.count.HP_pc_clear_existing_reproduceskill_pre > 0) { + void (*preHookFunc) (struct map_session_data **sd, bool *clear_vars); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_pc_clear_existing_reproduceskill_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_pc_clear_existing_reproduceskill_pre[hIndex].func; + preHookFunc(&sd, &clear_vars); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.pc.clear_existing_reproduceskill(sd, clear_vars); + } + if (HPMHooks.count.HP_pc_clear_existing_reproduceskill_post > 0) { + void (*postHookFunc) (struct map_session_data *sd, bool clear_vars); + for (hIndex = 0; hIndex < HPMHooks.count.HP_pc_clear_existing_reproduceskill_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_pc_clear_existing_reproduceskill_post[hIndex].func; + postHookFunc(sd, clear_vars); + } + } + return; +} /* pcre_interface */ pcre* HP_libpcre_compile(const char *pattern, int options, const char **errptr, int *erroffset, const unsigned char *tableptr) { int hIndex = 0; diff --git a/tools/validateinterfaces.py b/tools/validateinterfaces.py index 1bee64cbe..8484430a7 100755 --- a/tools/validateinterfaces.py +++ b/tools/validateinterfaces.py @@ -147,6 +147,7 @@ "searchstore_getsearchallfunc", "searchstore_getsearchfunc", "searchstore_getstoreid", + "searchstore_getdatabase", "searchstore_hasstore", "skill_reveal_trap", "skill_validate_unit_id_array",