Skip to content

Commit

Permalink
Fixed buyingstores not being searchable with searchstore
Browse files Browse the repository at this point in the history
  • Loading branch information
csnv committed Aug 11, 2024
1 parent dbafe89 commit a6fef38
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 5 deletions.
18 changes: 17 additions & 1 deletion src/map/buyingstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/map/buyingstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/map/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -6545,6 +6545,7 @@ int do_final(void)
elemental->final();
map->list_final();
vending->final();
buyingstore->final();
rodex->final();
achievement->final();
stylist->final();
Expand Down Expand Up @@ -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);

Expand Down
23 changes: 19 additions & 4 deletions src/map/searchstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/HPMHooking/HPMHooking.Defs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down Expand Up @@ -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) },
Expand Down
131 changes: 131 additions & 0 deletions src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a6fef38

Please sign in to comment.