diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/char/HPMchar.c | 17 | ||||
-rw-r--r-- | src/char/HPMchar.h | 2 | ||||
-rw-r--r-- | src/common/HPM.c | 168 | ||||
-rw-r--r-- | src/common/HPM.h | 20 | ||||
-rw-r--r-- | src/common/HPMi.h | 79 | ||||
-rw-r--r-- | src/common/mmo.h | 5 | ||||
-rw-r--r-- | src/common/socket.c | 13 | ||||
-rw-r--r-- | src/common/socket.h | 5 | ||||
-rw-r--r-- | src/login/HPMlogin.c | 17 | ||||
-rw-r--r-- | src/login/HPMlogin.h | 2 | ||||
-rw-r--r-- | src/map/HPMmap.c | 54 | ||||
-rw-r--r-- | src/map/HPMmap.h | 2 | ||||
-rw-r--r-- | src/map/battleground.c | 15 | ||||
-rw-r--r-- | src/map/battleground.h | 5 | ||||
-rw-r--r-- | src/map/guild.c | 25 | ||||
-rw-r--r-- | src/map/instance.c | 13 | ||||
-rw-r--r-- | src/map/instance.h | 5 | ||||
-rw-r--r-- | src/map/itemdb.c | 13 | ||||
-rw-r--r-- | src/map/itemdb.h | 4 | ||||
-rw-r--r-- | src/map/map.c | 12 | ||||
-rw-r--r-- | src/map/map.h | 4 | ||||
-rw-r--r-- | src/map/mob.c | 12 | ||||
-rw-r--r-- | src/map/mob.h | 9 | ||||
-rw-r--r-- | src/map/npc.c | 12 | ||||
-rw-r--r-- | src/map/npc.h | 5 | ||||
-rw-r--r-- | src/map/party.c | 25 | ||||
-rw-r--r-- | src/map/party.h | 5 | ||||
-rw-r--r-- | src/map/pc.c | 22 | ||||
-rw-r--r-- | src/map/pc.h | 6 | ||||
-rw-r--r-- | src/map/unit.c | 27 |
30 files changed, 246 insertions, 357 deletions
diff --git a/src/char/HPMchar.c b/src/char/HPMchar.c index a67f017c1..14d7be1a3 100644 --- a/src/char/HPMchar.c +++ b/src/char/HPMchar.c @@ -47,13 +47,18 @@ // HPMDataCheck comes after all the other includes #include "common/HPMDataCheck.h" -bool HPM_char_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) { - /* record address */ - switch( type ) { +/** + * HPM plugin data store validator sub-handler (char-server) + * + * @see HPM_interface::data_store_validate + */ +bool HPM_char_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store) +{ + switch (type) { default: - return false; + break; } - return true; + return false; } void HPM_char_plugin_load_sub(struct hplugin *plugin) { @@ -61,6 +66,8 @@ void HPM_char_plugin_load_sub(struct hplugin *plugin) { } void HPM_char_do_init(void) { + HPM->load_sub = HPM_char_plugin_load_sub; + HPM->data_store_validate_sub = HPM_char_data_store_validate; HPM->datacheck_init(HPMDataCheck, HPMDataCheckLen, HPMDataCheckVer); HPM_shared_symbols(SERVER_TYPE_CHAR); } diff --git a/src/char/HPMchar.h b/src/char/HPMchar.h index e3e000ef3..fd07f45ed 100644 --- a/src/char/HPMchar.h +++ b/src/char/HPMchar.h @@ -13,7 +13,7 @@ struct hplugin; -bool HPM_char_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr); +bool HPM_char_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store); void HPM_char_plugin_load_sub(struct hplugin *plugin); diff --git a/src/common/HPM.c b/src/common/HPM.c index 77c7e3fa2..ce3d769ca 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -168,57 +168,54 @@ bool hplugins_addpacket(unsigned short cmd, unsigned short length, void (*receiv return true; } -void hplugins_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) +bool hplugin_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store) { - /* record address */ + nullpo_retr(false, store); + switch (type) { /* core-handled */ case HPDT_SESSION: - ret->HPDataSRCPtr = (void**)(&((struct socket_data *)ptr)->hdata); - ret->hdatac = &((struct socket_data *)ptr)->hdatac; - break; + if (!*store) { + *store = HPM->data_store_create(); + } + return true; /* goes to sub */ default: - if (HPM->grabHPDataSub) { - if (HPM->grabHPDataSub(ret,type,ptr)) - return; - ShowError("HPM:HPM:grabHPData failed, unknown type %d!\n",type); - } else { - ShowError("HPM:grabHPData failed, type %d needs sub-handler!\n",type); - } - ret->HPDataSRCPtr = NULL; - ret->hdatac = NULL; - return; + break; } + if (HPM->data_store_validate_sub) { + if (HPM->data_store_validate_sub(type, store)) + return true; + ShowError("HPM:HPM:validateHPData failed, unknown type %d!\n",type); + } else { + ShowError("HPM:validateHPData failed, type %d needs sub-handler!\n",type); + } + return false; } -void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, void *data, unsigned int index, bool autofree) +void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, void *data, unsigned int index, bool autofree) { - struct HPluginData *HPData, **HPDataSRC; - struct HPDataOperationStorage action; - unsigned int i, max; - - HPM->grabHPData(&action,type,ptr); + struct hplugin_data_entry *HPData; + unsigned int i; + struct hplugin_data_store *store; - if (action.hdatac == NULL) { /* woo it failed! */ + if (!HPM->data_store_validate(type, storeptr)) { + /* woo it failed! */ ShowError("HPM:addToHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); return; } - - /* flag */ - HPDataSRC = *(action.HPDataSRCPtr); - max = *(action.hdatac); + store = *storeptr; /* duplicate check */ - for (i = 0; i < max; i++) { - if (HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index) { + for (i = 0; i < store->count; i++) { + if (store->array[i]->pluginID == pluginID && store->array[i]->type == index) { ShowError("HPM:addToHPData:%s: error! attempting to insert duplicate struct of id %u and index %u\n",HPM->pid2name(pluginID),pluginID,index); return; } } - /* HPluginData is always same size, probably better to use the ERS (with reasonable chunk size e.g. 10/25/50) */ - CREATE(HPData, struct HPluginData, 1); + /* hplugin_data_entry is always same size, probably better to use the ERS (with reasonable chunk size e.g. 10/25/50) */ + CREATE(HPData, struct hplugin_data_entry, 1); /* input */ HPData->pluginID = pluginID; @@ -227,76 +224,63 @@ void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, voi HPData->data = data; /* resize */ - *(action.hdatac) += 1; - RECREATE(*(action.HPDataSRCPtr),struct HPluginData *,*(action.hdatac)); + RECREATE(store->array, struct hplugin_data_entry *, ++store->count); - /* RECREATE modified the address */ - HPDataSRC = *(action.HPDataSRCPtr); - HPDataSRC[*(action.hdatac) - 1] = HPData; + store->array[store->count - 1] = HPData; } -void *hplugins_getFromHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index) +void *hplugins_getFromHPData(enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, unsigned int index) { - struct HPDataOperationStorage action; - struct HPluginData **HPDataSRC; - unsigned int i, max; - - HPM->grabHPData(&action,type,ptr); + unsigned int i; + struct hplugin_data_store *store; - if (action.hdatac == NULL) { /* woo it failed! */ + if (!HPM->data_store_validate(type, storeptr)) { + /* woo it failed! */ ShowError("HPM:getFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); return NULL; } + store = *storeptr; - /* flag */ - HPDataSRC = *(action.HPDataSRCPtr); - max = *(action.hdatac); - - for (i = 0; i < max; i++) { - if (HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index) - return HPDataSRC[i]->data; + for (i = 0; i < store->count; i++) { + if (store->array[i]->pluginID == pluginID && store->array[i]->type == index) + return store->array[i]->data; } return NULL; } -void hplugins_removeFromHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index) +void hplugins_removeFromHPData(enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, unsigned int index) { - struct HPDataOperationStorage action; - struct HPluginData **HPDataSRC; - unsigned int i, max; - - HPM->grabHPData(&action,type,ptr); + unsigned int i; + struct hplugin_data_store *store; - if (action.hdatac == NULL) { /* woo it failed! */ + if (!HPM->data_store_validate(type, storeptr)) { + /* woo it failed! */ ShowError("HPM:removeFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); return; } + store = *storeptr; - /* flag */ - HPDataSRC = *(action.HPDataSRCPtr); - max = *(action.hdatac); - - for (i = 0; i < max; i++) { - if (HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index) + for (i = 0; i < store->count; i++) { + if (store->array[i]->pluginID == pluginID && store->array[i]->type == index) break; } - if (i != max) { + if (i != store->count) { unsigned int cursor; - aFree(HPDataSRC[i]->data);/* when its removed we delete it regardless of autofree */ - aFree(HPDataSRC[i]); - HPDataSRC[i] = NULL; + aFree(store->array[i]->data);/* when its removed we delete it regardless of autofree */ + aFree(store->array[i]); + store->array[i] = NULL; - for (i = 0, cursor = 0; i < max; i++) { - if (HPDataSRC[i] == NULL) + for (i = 0, cursor = 0; i < store->count; i++) { + if (store->array[i] == NULL) continue; if (i != cursor) - HPDataSRC[cursor] = HPDataSRC[i]; + store->array[cursor] = store->array[i]; cursor++; } - *(action.hdatac) = cursor; + store->count = cursor; } } @@ -781,6 +765,43 @@ bool hplugins_parse_conf(const char *w1, const char *w2, enum HPluginConfType po } /** + * Helper to destroy and release an interface's hplugin_data store. + * + * @param hdata The hplugin_data store. The pointer will be freed. + */ +void hplugin_data_store_destroy(struct hplugin_data_store *store) +{ + unsigned int i; + + if (!store) + return; + + for (i = 0; i < store->count; i++) { + if (store->array[i]->flag.free) { + aFree(store->array[i]->data); + } + aFree(store->array[i]); + } + aFree(store->array); + aFree(store); +} + +/** + * Helper to create and initialize an interface's hplugin_data store. + * + * The store is owned by the caller, and it should be eventually destroyed by + * \c hdata_destroy. + * + * @return An initialized hplugin_data store. + */ +struct hplugin_data_store *hplugin_data_store_create(void) +{ + struct hplugin_data_store *store; + CREATE(store, struct hplugin_data_store, 1); + return store; +} + +/** * Called by HPM->DataCheck on a plugins incoming data, ensures data structs in use are matching! **/ bool HPM_DataCheck(struct s_HPMDataCheck *src, unsigned int size, int version, char *name) { @@ -947,10 +968,13 @@ void hpm_defaults(void) HPM->parse_packets = hplugins_parse_packets; HPM->load_sub = NULL; HPM->addhook_sub = NULL; - HPM->grabHPData = hplugins_grabHPData; - HPM->grabHPDataSub = NULL; HPM->parseConf = hplugins_parse_conf; HPM->DataCheck = HPM_DataCheck; HPM->datacheck_init = HPM_datacheck_init; HPM->datacheck_final = HPM_datacheck_final; + + HPM->data_store_destroy = hplugin_data_store_destroy; + HPM->data_store_create = hplugin_data_store_create; + HPM->data_store_validate = hplugin_data_store_validate; + HPM->data_store_validate_sub = NULL; } diff --git a/src/common/HPM.h b/src/common/HPM.h index 444829419..1d13a178f 100644 --- a/src/common/HPM.h +++ b/src/common/HPM.h @@ -65,7 +65,7 @@ struct hpm_symbol { void *ptr; ///< The symbol value }; -struct HPluginData { +struct hplugin_data_entry { unsigned int pluginID; unsigned int type; struct { @@ -74,6 +74,11 @@ struct HPluginData { void *data; }; +struct hplugin_data_store { + struct hplugin_data_entry **array; + unsigned int count; +}; + struct HPluginPacket { unsigned int pluginID; unsigned short cmd; @@ -86,10 +91,6 @@ struct HPMFileNameCache { char *name; }; -struct HPDataOperationStorage { - void **HPDataSRCPtr; - unsigned int *hdatac; -}; /* */ struct HPConfListenStorage { unsigned int pluginID; @@ -136,15 +137,18 @@ struct HPM_interface { unsigned char (*parse_packets) (int fd, enum HPluginPacketHookingPoints point); void (*load_sub) (struct hplugin *plugin); bool (*addhook_sub) (enum HPluginHookType type, const char *target, void *hook, unsigned int pID); - void (*grabHPData) (struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr); - /* for server-specific HPData e.g. map_session_data */ - bool (*grabHPDataSub) (struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr); /* for custom config parsing */ bool (*parseConf) (const char *w1, const char *w2, enum HPluginConfType point); /* validates plugin data */ bool (*DataCheck) (struct s_HPMDataCheck *src, unsigned int size, int version, char *name); void (*datacheck_init) (const struct s_HPMDataCheck *src, unsigned int length, int version); void (*datacheck_final) (void); + + struct hplugin_data_store *(*data_store_create) (void); + void (*data_store_destroy) (struct hplugin_data_store *store); + bool (*data_store_validate) (enum HPluginDataTypes type, struct hplugin_data_store **store); + /* for server-specific HPData e.g. map_session_data */ + bool (*data_store_validate_sub) (enum HPluginDataTypes type, struct hplugin_data_store **store); }; CMDLINEARG(loadplugin); diff --git a/src/common/HPMi.h b/src/common/HPMi.h index eee713fd9..d92503a91 100644 --- a/src/common/HPMi.h +++ b/src/common/HPMi.h @@ -14,6 +14,7 @@ struct script_state; struct AtCommandInfo; struct socket_data; struct map_session_data; +struct hplugin_data_store; #define HPM_VERSION "1.1" #define HPM_ADDCONF_LENGTH 40 @@ -96,53 +97,53 @@ enum HPluginConfType { #define addArg(name, param,func,help) (HPMi->addArg(HPMi->pid,(name),(param),(cmdline_arg_ ## func),(help))) /* HPData handy redirects */ /* session[] */ -#define addToSession(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_SESSION,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromSession(ptr,index) (HPMi->getFromHPData(HPDT_SESSION,HPMi->pid,(ptr),(index))) -#define removeFromSession(ptr,index) (HPMi->removeFromHPData(HPDT_SESSION,HPMi->pid,(ptr),(index))) +#define addToSession(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_SESSION,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromSession(ptr,index) (HPMi->getFromHPData(HPDT_SESSION,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromSession(ptr,index) (HPMi->removeFromHPData(HPDT_SESSION,HPMi->pid,&(ptr)->hdata,(index))) /* map_session_data */ -#define addToMSD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MSD,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromMSD(ptr,index) (HPMi->getFromHPData(HPDT_MSD,HPMi->pid,(ptr),(index))) -#define removeFromMSD(ptr,index) (HPMi->removeFromHPData(HPDT_MSD,HPMi->pid,(ptr),(index))) +#define addToMSD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MSD,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromMSD(ptr,index) (HPMi->getFromHPData(HPDT_MSD,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromMSD(ptr,index) (HPMi->removeFromHPData(HPDT_MSD,HPMi->pid,&(ptr)->hdata,(index))) /* npc_data */ -#define addToNPCD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_NPCD,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromNPCD(ptr,index) (HPMi->getFromHPData(HPDT_NPCD,HPMi->pid,(ptr),(index))) -#define removeFromNPCD(ptr,index) (HPMi->removeFromHPData(HPDT_NPCD,HPMi->pid,(ptr),(index))) +#define addToNPCD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_NPCD,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromNPCD(ptr,index) (HPMi->getFromHPData(HPDT_NPCD,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromNPCD(ptr,index) (HPMi->removeFromHPData(HPDT_NPCD,HPMi->pid,&(ptr)->hdata,(index))) /* map_data */ -#define addToMAPD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MAP,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromMAPD(ptr,index) (HPMi->getFromHPData(HPDT_MAP,HPMi->pid,(ptr),(index))) -#define removeFromMAPD(ptr,index) (HPMi->removeFromHPData(HPDT_MAP,HPMi->pid,(ptr),(index))) +#define addToMAPD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MAP,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromMAPD(ptr,index) (HPMi->getFromHPData(HPDT_MAP,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromMAPD(ptr,index) (HPMi->removeFromHPData(HPDT_MAP,HPMi->pid,&(ptr)->hdata,(index))) /* party_data */ -#define addToPAD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_PARTY,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromPAD(ptr,index) (HPMi->getFromHPData(HPDT_PARTY,HPMi->pid,(ptr),(index))) -#define removeFromPAD(ptr,index) (HPMi->removeFromHPData(HPDT_PARTY,HPMi->pid,(ptr),(index))) +#define addToPAD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_PARTY,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromPAD(ptr,index) (HPMi->getFromHPData(HPDT_PARTY,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromPAD(ptr,index) (HPMi->removeFromHPData(HPDT_PARTY,HPMi->pid,&(ptr)->hdata,(index))) /* guild */ -#define addToGLD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_GUILD,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromGLD(ptr,index) (HPMi->getFromHPData(HPDT_GUILD,HPMi->pid,(ptr),(index))) -#define removeFromGLD(ptr,index) (HPMi->removeFromHPData(HPDT_GUILD,HPMi->pid,(ptr),(index))) +#define addToGLD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_GUILD,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromGLD(ptr,index) (HPMi->getFromHPData(HPDT_GUILD,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromGLD(ptr,index) (HPMi->removeFromHPData(HPDT_GUILD,HPMi->pid,&(ptr)->hdata,(index))) /* instance_data */ -#define addToINSTD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_INSTANCE,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromINSTD(ptr,index) (HPMi->getFromHPData(HPDT_INSTANCE,HPMi->pid,(ptr),(index))) -#define removeFromINSTD(ptr,index) (HPMi->removeFromHPData(HPDT_INSTANCE,HPMi->pid,(ptr),(index))) +#define addToINSTD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_INSTANCE,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromINSTD(ptr,index) (HPMi->getFromHPData(HPDT_INSTANCE,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromINSTD(ptr,index) (HPMi->removeFromHPData(HPDT_INSTANCE,HPMi->pid,&(ptr)->hdata,(index))) /* mob_db */ -#define addToMOBDB(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MOBDB,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromMOBDB(ptr,index) (HPMi->getFromHPData(HPDT_MOBDB,HPMi->pid,(ptr),(index))) -#define removeFromMOBDB(ptr,index) (HPMi->removeFromHPData(HPDT_MOBDB,HPMi->pid,(ptr),(index))) +#define addToMOBDB(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MOBDB,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromMOBDB(ptr,index) (HPMi->getFromHPData(HPDT_MOBDB,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromMOBDB(ptr,index) (HPMi->removeFromHPData(HPDT_MOBDB,HPMi->pid,&(ptr)->hdata,(index))) /* mob_data */ -#define addToMOBDATA(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MOBDATA,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromMOBDATA(ptr,index) (HPMi->getFromHPData(HPDT_MOBDATA,HPMi->pid,(ptr),(index))) -#define removeFromMOBDATA(ptr,index) (HPMi->removeFromHPData(HPDT_MOBDATA,HPMi->pid,(ptr),(index))) +#define addToMOBDATA(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MOBDATA,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromMOBDATA(ptr,index) (HPMi->getFromHPData(HPDT_MOBDATA,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromMOBDATA(ptr,index) (HPMi->removeFromHPData(HPDT_MOBDATA,HPMi->pid,&(ptr)->hdata,(index))) /* item_data */ -#define addToITEMDATA(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_ITEMDATA,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromITEMDATA(ptr,index) (HPMi->getFromHPData(HPDT_ITEMDATA,HPMi->pid,(ptr),(index))) -#define removeFromITEMDATA(ptr,index) (HPMi->removeFromHPData(HPDT_ITEMDATA,HPMi->pid,(ptr),(index))) +#define addToITEMDATA(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_ITEMDATA,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromITEMDATA(ptr,index) (HPMi->getFromHPData(HPDT_ITEMDATA,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromITEMDATA(ptr,index) (HPMi->removeFromHPData(HPDT_ITEMDATA,HPMi->pid,&(ptr)->hdata,(index))) /* battleground_data */ -#define addToBGDATA(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_BGDATA,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromBGDATA(ptr,index) (HPMi->getFromHPData(HPDT_BGDATA,HPMi->pid,(ptr),(index))) -#define removeFromBGDATA(ptr,index) (HPMi->removeFromHPData(HPDT_BGDATA,HPMi->pid,(ptr),(index))) +#define addToBGDATA(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_BGDATA,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromBGDATA(ptr,index) (HPMi->getFromHPData(HPDT_BGDATA,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromBGDATA(ptr,index) (HPMi->removeFromHPData(HPDT_BGDATA,HPMi->pid,&(ptr)->hdata,(index))) /* autotrade_vending */ -#define addToATVEND(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromATVEND(ptr,index) (HPMi->getFromHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,(ptr),(index))) -#define removeFromATVEND(ptr,index) (HPMi->removeFromHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,(ptr),(index))) +#define addToATVEND(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromATVEND(ptr,index) (HPMi->getFromHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromATVEND(ptr,index) (HPMi->removeFromHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,&(ptr)->hdata,(index))) /// HPMi->addCommand #define addAtcommand(cname,funcname) do { \ @@ -205,9 +206,9 @@ struct HPMi_interface { bool (*addScript) (char *name, char *args, bool (*func)(struct script_state *st), bool isDeprecated); void (*addCPCommand) (char *name, CParseFunc func); /* HPM Custom Data */ - void (*addToHPData) (enum HPluginDataTypes type, unsigned int pluginID, void *ptr, void *data, unsigned int index, bool autofree); - void *(*getFromHPData) (enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index); - void (*removeFromHPData) (enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index); + void (*addToHPData) (enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, void *data, unsigned int index, bool autofree); + void *(*getFromHPData) (enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, unsigned int index); + void (*removeFromHPData) (enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, unsigned int index); /* packet */ bool (*addPacket) (unsigned short cmd, unsigned short length, void (*receive)(int fd), unsigned int point, unsigned int pluginID); /* Hooking */ diff --git a/src/common/mmo.h b/src/common/mmo.h index 012eec935..cbda0e91b 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -198,7 +198,7 @@ #define JOBL_BABY 0x2000 //8192 #define JOBL_THIRD 0x4000 //16384 -struct HPluginData; +struct hplugin_data_store; enum item_types { IT_HEALING = 0, @@ -663,8 +663,7 @@ struct guild { struct channel_data *channel; /* HPM Custom Struct */ - struct HPluginData **hdata; - unsigned int hdatac; + struct hplugin_data_store *hdata; }; struct guild_castle { diff --git a/src/common/socket.c b/src/common/socket.c index de8ca4682..842f9ba87 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -623,7 +623,6 @@ static int create_session(int fd, RecvFunc func_recv, SendFunc func_send, ParseF sockt->session[fd]->rdata_tick = sockt->last_tick; sockt->session[fd]->session_data = NULL; sockt->session[fd]->hdata = NULL; - sockt->session[fd]->hdatac = 0; return 0; } @@ -638,16 +637,8 @@ static void delete_session(int fd) aFree(sockt->session[fd]->wdata); if( sockt->session[fd]->session_data ) aFree(sockt->session[fd]->session_data); - if (sockt->session[fd]->hdata) { - unsigned int i; - for(i = 0; i < sockt->session[fd]->hdatac; i++) { - if( sockt->session[fd]->hdata[i]->flag.free ) { - aFree(sockt->session[fd]->hdata[i]->data); - } - aFree(sockt->session[fd]->hdata[i]); - } - aFree(sockt->session[fd]->hdata); - } + HPM->data_store_destroy(sockt->session[fd]->hdata); + sockt->session[fd]->hdata = NULL; aFree(sockt->session[fd]); sockt->session[fd] = NULL; } diff --git a/src/common/socket.h b/src/common/socket.h index a995bffc8..510eac575 100644 --- a/src/common/socket.h +++ b/src/common/socket.h @@ -17,7 +17,7 @@ # include <sys/types.h> #endif -struct HPluginData; +struct hplugin_data_store; #define FIFOSIZE_SERVERLINK 256*1024 @@ -105,8 +105,7 @@ struct socket_data { void* session_data; // stores application-specific data related to the session - struct HPluginData **hdata; - unsigned int hdatac; + struct hplugin_data_store *hdata; }; struct hSockOpt { diff --git a/src/login/HPMlogin.c b/src/login/HPMlogin.c index 895cbad16..ce88728fe 100644 --- a/src/login/HPMlogin.c +++ b/src/login/HPMlogin.c @@ -32,13 +32,18 @@ // HPMDataCheck comes after all the other includes #include "common/HPMDataCheck.h" -bool HPM_login_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) { - /* record address */ - switch( type ) { +/** + * HPM plugin data store validator sub-handler (login-server) + * + * @see HPM_interface::data_store_validate + */ +bool HPM_login_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store) +{ + switch (type) { default: - return false; + break; } - return true; + return false; } void HPM_login_plugin_load_sub(struct hplugin *plugin) { @@ -46,6 +51,8 @@ void HPM_login_plugin_load_sub(struct hplugin *plugin) { } void HPM_login_do_init(void) { + HPM->load_sub = HPM_login_plugin_load_sub; + HPM->data_store_validate_sub = HPM_login_data_store_validate; HPM->datacheck_init(HPMDataCheck, HPMDataCheckLen, HPMDataCheckVer); HPM_shared_symbols(SERVER_TYPE_LOGIN); } diff --git a/src/login/HPMlogin.h b/src/login/HPMlogin.h index 2a4d5c538..1f08a8666 100644 --- a/src/login/HPMlogin.h +++ b/src/login/HPMlogin.h @@ -13,7 +13,7 @@ struct hplugin; -bool HPM_login_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr); +bool HPM_login_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store); void HPM_login_plugin_load_sub(struct hplugin *plugin); diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c index ac78e8c84..ddffb5519 100644 --- a/src/map/HPMmap.c +++ b/src/map/HPMmap.c @@ -85,57 +85,33 @@ struct HPM_atcommand_list { struct HPM_atcommand_list *atcommand_list = NULL; unsigned int atcommand_list_items = 0; -bool HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) { - /* record address */ - switch( type ) { +/** + * HPM plugin data store validator sub-handler (map-server) + * + * @see HPM_interface::data_store_validate + */ +bool HPM_map_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store) +{ + switch (type) { case HPDT_MSD: - ret->HPDataSRCPtr = (void**)(&((struct map_session_data *)ptr)->hdata); - ret->hdatac = &((struct map_session_data *)ptr)->hdatac; - break; case HPDT_NPCD: - ret->HPDataSRCPtr = (void**)(&((struct npc_data *)ptr)->hdata); - ret->hdatac = &((struct npc_data *)ptr)->hdatac; - break; case HPDT_MAP: - ret->HPDataSRCPtr = (void**)(&((struct map_data *)ptr)->hdata); - ret->hdatac = &((struct map_data *)ptr)->hdatac; - break; case HPDT_PARTY: - ret->HPDataSRCPtr = (void**)(&((struct party_data *)ptr)->hdata); - ret->hdatac = &((struct party_data *)ptr)->hdatac; - break; case HPDT_GUILD: - ret->HPDataSRCPtr = (void**)(&((struct guild *)ptr)->hdata); - ret->hdatac = &((struct guild *)ptr)->hdatac; - break; case HPDT_INSTANCE: - ret->HPDataSRCPtr = (void**)(&((struct instance_data *)ptr)->hdata); - ret->hdatac = &((struct instance_data *)ptr)->hdatac; - break; case HPDT_MOBDB: - ret->HPDataSRCPtr = (void**)(&((struct mob_db *)ptr)->hdata); - ret->hdatac = &((struct mob_db *)ptr)->hdatac; - break; case HPDT_MOBDATA: - ret->HPDataSRCPtr = (void**)(&((struct mob_data *)ptr)->hdata); - ret->hdatac = &((struct mob_data *)ptr)->hdatac; - break; case HPDT_ITEMDATA: - ret->HPDataSRCPtr = (void**)(&((struct item_data *)ptr)->hdata); - ret->hdatac = &((struct item_data *)ptr)->hdatac; - break; case HPDT_BGDATA: - ret->HPDataSRCPtr = (void**)(&((struct battleground_data *)ptr)->hdata); - ret->hdatac = &((struct battleground_data *)ptr)->hdatac; - break; case HPDT_AUTOTRADE_VEND: - ret->HPDataSRCPtr = (void**)(&((struct autotrade_vending *)ptr)->hdata); - ret->hdatac = &((struct autotrade_vending *)ptr)->hdatac; - break; + if (!*store) { + *store = HPM->data_store_create(); + } + return true; default: - return false; + break; } - return true; + return false; } void HPM_map_plugin_load_sub(struct hplugin *plugin) { @@ -188,7 +164,7 @@ void HPM_map_add_group_permission(unsigned int pluginID, char *name, unsigned in void HPM_map_do_init(void) { HPM->load_sub = HPM_map_plugin_load_sub; - HPM->grabHPDataSub = HPM_map_grabHPData; + HPM->data_store_validate_sub = HPM_map_data_store_validate; HPM->datacheck_init(HPMDataCheck, HPMDataCheckLen, HPMDataCheckVer); HPM_shared_symbols(SERVER_TYPE_MAP); } diff --git a/src/map/HPMmap.h b/src/map/HPMmap.h index 00a8f43c3..10bdf0ba7 100644 --- a/src/map/HPMmap.h +++ b/src/map/HPMmap.h @@ -15,7 +15,7 @@ struct hplugin; struct map_session_data; -bool HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr); +bool HPM_map_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store); bool HPM_map_add_atcommand(char *name, AtCommandFunc func); void HPM_map_atcommands(void); diff --git a/src/map/battleground.c b/src/map/battleground.c index 5df05d301..46d695272 100644 --- a/src/map/battleground.c +++ b/src/map/battleground.c @@ -880,17 +880,10 @@ void do_init_battleground(bool minimal) { */ int bg_team_db_final(DBKey key, DBData *data, va_list ap) { struct battleground_data* bgd = DB->data2ptr(data); - int i; - nullpo_ret(bgd); - for(i = 0; i < bgd->hdatac; i++ ) { - if( bgd->hdata[i]->flag.free ) { - aFree(bgd->hdata[i]->data); - } - aFree(bgd->hdata[i]); - } - if( bgd->hdata ) - aFree(bgd->hdata); - + + HPM->data_store_destroy(bgd->hdata); + bgd->hdata = NULL; + return 0; } diff --git a/src/map/battleground.h b/src/map/battleground.h index 094037f43..0280407a2 100644 --- a/src/map/battleground.h +++ b/src/map/battleground.h @@ -10,7 +10,7 @@ #include "common/db.h" #include "common/mmo.h" // struct party -struct HPluginData; +struct hplugin_data_store; struct block_list; struct map_session_data; @@ -54,8 +54,7 @@ struct battleground_data { char logout_event[EVENT_NAME_LENGTH]; char die_event[EVENT_NAME_LENGTH]; /* HPM Custom Struct */ - struct HPluginData **hdata; - unsigned int hdatac; + struct hplugin_data_store *hdata; }; struct bg_arena { diff --git a/src/map/guild.c b/src/map/guild.c index 7a187b625..2dca97502 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -1763,16 +1763,8 @@ int guild_broken(int guild_id,int flag) if( g->instance ) aFree(g->instance); - if( g->hdata ) - { - for( i = 0; i < g->hdatac; i++ ) { - if( g->hdata[i]->flag.free ) { - aFree(g->hdata[i]->data); - } - aFree(g->hdata[i]); - } - aFree(g->hdata); - } + HPM->data_store_destroy(g->hdata); + g->hdata = NULL; idb_remove(guild->db,guild_id); return 0; @@ -2250,7 +2242,6 @@ void do_init_guild(bool minimal) { void do_final_guild(void) { DBIterator *iter = db_iterator(guild->db); struct guild *g; - int i; for( g = dbi_first(iter); dbi_exists(iter); g = dbi_next(iter) ) { if( g->channel != NULL ) @@ -2259,16 +2250,8 @@ void do_final_guild(void) { aFree(g->instance); g->instance = NULL; } - if( g->hdata ) - { - for( i = 0; i < g->hdatac; i++ ) { - if( g->hdata[i]->flag.free ) { - aFree(g->hdata[i]->data); - } - aFree(g->hdata[i]); - } - aFree(g->hdata); - } + HPM->data_store_destroy(g->hdata); + g->hdata = NULL; } dbi_destroy(iter); diff --git a/src/map/instance.c b/src/map/instance.c index 300247fe7..7213c43a1 100644 --- a/src/map/instance.c +++ b/src/map/instance.c @@ -588,19 +588,8 @@ void instance_destroy(int instance_id) { instance->list[instance_id].state = INSTANCE_FREE; instance->list[instance_id].num_map = 0; - if (instance->list[instance_id].hdata) - { - for( j = 0; j < instance->list[instance_id].hdatac; j++ ) { - if( instance->list[instance_id].hdata[j]->flag.free ) { - aFree(instance->list[instance_id].hdata[j]->data); - } - aFree(instance->list[instance_id].hdata[j]); - } - aFree(instance->list[instance_id].hdata); - } - + HPM->data_store_destroy(instance->list[instance_id].hdata); instance->list[instance_id].hdata = NULL; - instance->list[instance_id].hdatac = 0; } /*-------------------------------------- diff --git a/src/map/instance.h b/src/map/instance.h index 589e1a511..f879195ef 100644 --- a/src/map/instance.h +++ b/src/map/instance.h @@ -9,7 +9,7 @@ #include "common/hercules.h" #include "common/mmo.h" // struct point -struct HPluginData; +struct hplugin_data_store; struct block_list; struct map_session_data; @@ -54,8 +54,7 @@ struct instance_data { struct point respawn; ///< reload spawn /** HPM Custom Struct */ - struct HPluginData **hdata; - unsigned int hdatac; + struct hplugin_data_store *hdata; }; struct instance_interface { diff --git a/src/map/itemdb.c b/src/map/itemdb.c index ccedee72a..c531a4d7a 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -2100,17 +2100,8 @@ void destroy_item_data(struct item_data* self, int free_self) script->free_code(self->unequip_script); if( self->combos ) aFree(self->combos); - if (self->hdata) - { - int i; - for (i = 0; i < self->hdatac; i++ ) { - if (self->hdata[i]->flag.free ) { - aFree(self->hdata[i]->data); - } - aFree(self->hdata[i]); - } - aFree(self->hdata); - } + HPM->data_store_destroy(self->hdata); + self->hdata = NULL; #if defined(DEBUG) // trash item memset(self, 0xDD, sizeof(struct item_data)); diff --git a/src/map/itemdb.h b/src/map/itemdb.h index a3edd451e..de9770aab 100644 --- a/src/map/itemdb.h +++ b/src/map/itemdb.h @@ -13,6 +13,7 @@ #include "common/sql.h" struct script_code; +struct hplugin_data_store; /** * Defines @@ -490,8 +491,7 @@ struct item_data { struct item_package *package; /* HPM Custom Struct */ - struct HPluginData **hdata; - unsigned int hdatac; + struct hplugin_data_store *hdata; }; #define itemdb_name(n) (itemdb->search(n)->name) diff --git a/src/map/map.c b/src/map/map.c index e01a25366..0ed7072d2 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -3239,16 +3239,8 @@ void do_final_maps(void) { if( map->list[i].qi_data ) aFree(map->list[i].qi_data); - if( map->list[i].hdata ) - { - for( v = 0; v < map->list[i].hdatac; v++ ) { - if( map->list[i].hdata[v]->flag.free ) { - aFree(map->list[i].hdata[v]->data); - } - aFree(map->list[i].hdata[v]); - } - aFree(map->list[i].hdata); - } + HPM->data_store_destroy(map->list[i].hdata); + map->list[i].hdata = NULL; } map->zone_db_clear(); diff --git a/src/map/map.h b/src/map/map.h index 3ac39e54f..c3e426bb6 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -19,6 +19,7 @@ struct mob_data; struct npc_data; struct channel_data; +struct hplugin_data_store; enum E_MAPSERVER_ST { MAPSERVER_ST_RUNNING = CORE_ST_LAST, @@ -738,8 +739,7 @@ struct map_data { unsigned short hpmeter_visible; /* HPM Custom Struct */ - struct HPluginData **hdata; - unsigned int hdatac; + struct hplugin_data_store *hdata; }; /// Stores information about a remote map (for multi-mapserver setups). diff --git a/src/map/mob.c b/src/map/mob.c index 2fe9fe8fb..174d2e49f 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -4708,16 +4708,8 @@ int do_init_mob(bool minimal) { void mob_destroy_mob_db(int index) { struct mob_db *data = mob->db_data[index]; - if (data->hdata) { - int i; - for (i = 0; i < data->hdatac; i++) { - if (data->hdata[i]->flag.free ) { - aFree(data->hdata[i]->data); - } - aFree(data->hdata[i]); - } - aFree(data->hdata); - } + HPM->data_store_destroy(data->hdata); + data->hdata = NULL; aFree(data); mob->db_data[index] = NULL; } diff --git a/src/map/mob.h b/src/map/mob.h index 4b8a054b5..1142502f4 100644 --- a/src/map/mob.h +++ b/src/map/mob.h @@ -11,6 +11,8 @@ #include "common/hercules.h" #include "common/mmo.h" // struct item +struct hplugin_data_store; + #define MAX_RANDOMMONSTER 5 // Change this to increase the table size in your mob_db to accommodate a larger mob database. @@ -140,8 +142,7 @@ struct mob_db { struct spawn_info spawn[10]; /* HPM Custom Struct */ - struct HPluginData **hdata; - unsigned int hdatac; + struct hplugin_data_store *hdata; }; struct mob_data { @@ -210,12 +211,10 @@ struct mob_data { int tomb_nid; /* HPM Custom Struct */ - struct HPluginData **hdata; - unsigned int hdatac; + struct hplugin_data_store *hdata; }; - enum { MST_TARGET = 0, MST_RANDOM, //Random Target! diff --git a/src/map/npc.c b/src/map/npc.c index a0c14a058..85de5301b 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -2321,16 +2321,8 @@ int npc_unload(struct npc_data* nd, bool single) nd->ud = NULL; } - if (nd->hdata) { - unsigned int i; - for (i = 0; i < nd->hdatac; i++) { - if (nd->hdata[i]->flag.free) { - aFree(nd->hdata[i]->data); - } - aFree(nd->hdata[i]); - } - aFree(nd->hdata); - } + HPM->data_store_destroy(nd->hdata); + nd->hdata = NULL; aFree(nd); diff --git a/src/map/npc.h b/src/map/npc.h index 14b89d128..06aee3f93 100644 --- a/src/map/npc.h +++ b/src/map/npc.h @@ -11,7 +11,7 @@ #include "common/hercules.h" #include "common/db.h" -struct HPluginData; +struct hplugin_data_store; struct view_data; enum npc_parse_options { @@ -103,8 +103,7 @@ struct npc_data { } tomb; } u; /* HPData Support for npc_data */ - struct HPluginData **hdata; - unsigned int hdatac; + struct hplugin_data_store *hdata; }; diff --git a/src/map/party.c b/src/map/party.c index db285a4b4..4735dfc42 100644 --- a/src/map/party.c +++ b/src/map/party.c @@ -103,16 +103,8 @@ int party_db_final(DBKey key, DBData *data, va_list ap) { if (p->instance) aFree(p->instance); - if (p->hdata) { - int i; - for (i = 0; i < p->hdatac; i++) { - if (p->hdata[i]->flag.free) { - aFree(p->hdata[i]->data); - } - aFree(p->hdata[i]); - } - aFree(p->hdata); - } + HPM->data_store_destroy(p->hdata); + p->hdata = NULL; } return 0; } @@ -608,16 +600,9 @@ int party_broken(int party_id) if( p->instance ) aFree(p->instance); - if( p->hdata ) - { - for( j = 0; j < p->hdatac; j++ ) { - if( p->hdata[j]->flag.free ) { - aFree(p->hdata[j]->data); - } - aFree(p->hdata[j]); - } - aFree(p->hdata); - } + HPM->data_store_destroy(p->hdata); + p->hdata = NULL; + idb_remove(party->db,party_id); return 0; } diff --git a/src/map/party.h b/src/map/party.h index c7893add2..960e6da08 100644 --- a/src/map/party.h +++ b/src/map/party.h @@ -15,7 +15,7 @@ #define PARTY_BOOKING_JOBS 6 #define PARTY_BOOKING_RESULTS 10 -struct HPluginData; +struct hplugin_data_store; struct party_member_data { struct map_session_data *sd; @@ -37,8 +37,7 @@ struct party_data { } state; /* HPM Custom Struct */ - struct HPluginData **hdata; - unsigned int hdatac; + struct hplugin_data_store *hdata; }; #define PB_NOTICE_LENGTH (36 + 1) diff --git a/src/map/pc.c b/src/map/pc.c index dc7014701..fee41deff 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -11332,14 +11332,8 @@ void pc_autotrade_populate(struct map_session_data *sd) { pc->autotrade_update(sd,PAUC_START); - for(i = 0; i < data->hdatac; i++ ) { - if( data->hdata[i]->flag.free ) { - aFree(data->hdata[i]->data); - } - aFree(data->hdata[i]); - } - if( data->hdata ) - aFree(data->hdata); + HPM->data_store_destroy(data->hdata); + data->hdata = NULL; idb_remove(pc->at_db, sd->status.char_id); } @@ -11349,16 +11343,8 @@ void pc_autotrade_populate(struct map_session_data *sd) { */ int pc_autotrade_final(DBKey key, DBData *data, va_list ap) { struct autotrade_vending* at_v = DB->data2ptr(data); - int i; - for(i = 0; i < at_v->hdatac; i++ ) { - if( at_v->hdata[i]->flag.free ) { - aFree(at_v->hdata[i]->data); - } - aFree(at_v->hdata[i]); - } - if( at_v->hdata ) - aFree(at_v->hdata); - + HPM->data_store_destroy(at_v->hdata); + at_v->hdata = NULL; return 0; } diff --git a/src/map/pc.h b/src/map/pc.h index e6e95978d..a74bc6c80 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -541,8 +541,7 @@ END_ZEROED_BLOCK; unsigned char delayed_damage;//ref. counter bugreport:7307 [Ind/Hercules] /* HPM Custom Struct */ - struct HPluginData **hdata; - unsigned int hdatac; + struct hplugin_data_store *hdata; /* expiration_time timer id */ int expiration_tid; @@ -758,8 +757,7 @@ struct autotrade_vending { struct s_vending vending[MAX_VENDING]; unsigned char vend_num; /* HPM Custom Struct */ - struct HPluginData **hdata; - unsigned int hdatac; + struct hplugin_data_store *hdata; }; /*===================================== diff --git a/src/map/unit.c b/src/map/unit.c index 04a8befc2..0f8a9d7e6 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -2655,16 +2655,9 @@ int unit_free(struct block_list *bl, clr_type clrtype) { sd->num_quests = sd->avail_quests = 0; } - if (sd->hdata) { - unsigned int k; - for( k = 0; k < sd->hdatac; k++ ) { - if( sd->hdata[k]->flag.free ) { - aFree(sd->hdata[k]->data); - } - aFree(sd->hdata[k]); - } - aFree(sd->hdata); - } + HPM->data_store_destroy(sd->hdata); + sd->hdata = NULL; + break; } case BL_PET: @@ -2775,17 +2768,9 @@ int unit_free(struct block_list *bl, clr_type clrtype) { if( md->tomb_nid ) mob->mvptomb_destroy(md); - if (md->hdata) - { - unsigned int k; - for (k = 0; k < md->hdatac; k++) { - if( md->hdata[k]->flag.free ) { - aFree(md->hdata[k]->data); - } - aFree(md->hdata[k]); - } - aFree(md->hdata); - } + HPM->data_store_destroy(md->hdata); + md->hdata = NULL; + break; } case BL_HOM: |