diff options
author | Haru <haru@dotalux.com> | 2015-09-26 04:11:41 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2015-10-11 00:24:22 +0200 |
commit | 657e7f9c07bc1445ce785cd11772664a1848ea5a (patch) | |
tree | b0b6ce19dfd5946fe6a0cf6c33eac78e357d4832 | |
parent | 70265291d62280c525adc317158e9f531e0147ff (diff) | |
download | hercules-657e7f9c07bc1445ce785cd11772664a1848ea5a.tar.gz hercules-657e7f9c07bc1445ce785cd11772664a1848ea5a.tar.bz2 hercules-657e7f9c07bc1445ce785cd11772664a1848ea5a.tar.xz hercules-657e7f9c07bc1445ce785cd11772664a1848ea5a.zip |
Cleanup of the HPluginData implementation (second part)
- Changed the hplugin_data_store's array into a VECTOR.
Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r-- | src/char/HPMchar.c | 3 | ||||
-rw-r--r-- | src/char/HPMchar.h | 2 | ||||
-rw-r--r-- | src/common/HPM.c | 219 | ||||
-rw-r--r-- | src/common/HPM.h | 26 | ||||
-rw-r--r-- | src/common/HPMi.h | 106 | ||||
-rw-r--r-- | src/common/mmo.h | 4 | ||||
-rw-r--r-- | src/common/socket.c | 3 | ||||
-rw-r--r-- | src/common/socket.h | 3 | ||||
-rw-r--r-- | src/login/HPMlogin.c | 3 | ||||
-rw-r--r-- | src/login/HPMlogin.h | 2 | ||||
-rw-r--r-- | src/map/HPMmap.c | 6 | ||||
-rw-r--r-- | src/map/HPMmap.h | 2 | ||||
-rw-r--r-- | src/map/battleground.c | 3 | ||||
-rw-r--r-- | src/map/battleground.h | 3 | ||||
-rw-r--r-- | src/map/guild.c | 6 | ||||
-rw-r--r-- | src/map/instance.c | 3 | ||||
-rw-r--r-- | src/map/instance.h | 4 | ||||
-rw-r--r-- | src/map/itemdb.c | 3 | ||||
-rw-r--r-- | src/map/itemdb.h | 4 | ||||
-rw-r--r-- | src/map/map.c | 3 | ||||
-rw-r--r-- | src/map/map.h | 4 | ||||
-rw-r--r-- | src/map/mob.c | 3 | ||||
-rw-r--r-- | src/map/mob.h | 8 | ||||
-rw-r--r-- | src/map/npc.c | 3 | ||||
-rw-r--r-- | src/map/npc.h | 3 | ||||
-rw-r--r-- | src/map/party.c | 6 | ||||
-rw-r--r-- | src/map/party.h | 4 | ||||
-rw-r--r-- | src/map/pc.c | 6 | ||||
-rw-r--r-- | src/map/pc.h | 7 | ||||
-rw-r--r-- | src/map/unit.c | 9 |
30 files changed, 242 insertions, 219 deletions
diff --git a/src/char/HPMchar.c b/src/char/HPMchar.c index 14d7be1a3..d3150bc11 100644 --- a/src/char/HPMchar.c +++ b/src/char/HPMchar.c @@ -52,9 +52,10 @@ * * @see HPM_interface::data_store_validate */ -bool HPM_char_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store) +bool HPM_char_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize) { switch (type) { + // No supported types at the moment. default: break; } diff --git a/src/char/HPMchar.h b/src/char/HPMchar.h index fd07f45ed..431017b7a 100644 --- a/src/char/HPMchar.h +++ b/src/char/HPMchar.h @@ -13,7 +13,7 @@ struct hplugin; -bool HPM_char_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store); +bool HPM_char_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize); void HPM_char_plugin_load_sub(struct hplugin *plugin); diff --git a/src/common/HPM.c b/src/common/HPM.c index ce3d769ca..578e90bbc 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -168,120 +168,158 @@ bool hplugins_addpacket(unsigned short cmd, unsigned short length, void (*receiv return true; } -bool hplugin_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store) +/** + * Validates and if necessary initializes a plugin data store. + * + * @param type[in] The data store type. + * @param storeptr[in,out] A pointer to the store. + * @param initialize Whether the store should be initialized in case it isn't. + * @retval false if the store is an invalid or mismatching type. + * @retval true if the store is a valid type. + * + * @remark + * If \c storeptr is a pointer to a NULL pointer (\c storeptr itself can't + * be NULL), two things may happen, depending on the \c initialize value: + * if false, then \c storeptr isn't changed; if true, then \c storeptr is + * initialized through \c HPM->data_store_create() and ownership is passed + * to the caller. + */ +bool hplugin_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize) { - nullpo_retr(false, store); + struct hplugin_data_store *store; + nullpo_retr(false, storeptr); + store = *storeptr; + if (!initialize && store == NULL) + return true; switch (type) { /* core-handled */ case HPDT_SESSION: - if (!*store) { - *store = HPM->data_store_create(); - } - return true; - /* goes to sub */ + break; default: + if (HPM->data_store_validate_sub == NULL) { + ShowError("HPM:validateHPData failed, type %d needs sub-handler!\n",type); + return false; + } + if (!HPM->data_store_validate_sub(type, storeptr, initialize)) { + ShowError("HPM:HPM:validateHPData failed, unknown type %d!\n",type); + return false; + } 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); + if (initialize && (!store || store->type == HPDT_UNKNOWN)) { + HPM->data_store_create(storeptr, type); + store = *storeptr; } - return false; + if (store->type != type) { + ShowError("HPM:HPM:validateHPData failed, store type mismatch %d != %d.\n",store->type, type); + return false; + } + return true; } -void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, void *data, unsigned int index, bool autofree) +/** + * Adds an entry to a plugin data store. + * + * @param type[in] The store type. + * @param pluginID[in] The plugin identifier. + * @param storeptr[in,out] A pointer to the store. The store will be initialized if necessary. + * @param data[in] The data entry to add. + * @param classid[in] The entry class identifier. + * @param autofree[in] Whether the entry should be automatically freed when removed. + */ +void hplugins_addToHPData(enum HPluginDataTypes type, uint32 pluginID, struct hplugin_data_store **storeptr, void *data, uint32 classid, bool autofree) { - struct hplugin_data_entry *HPData; - unsigned int i; struct hplugin_data_store *store; + struct hplugin_data_entry *entry; + int i; + nullpo_retv(storeptr); - if (!HPM->data_store_validate(type, storeptr)) { + if (!HPM->data_store_validate(type, storeptr, true)) { /* woo it failed! */ - ShowError("HPM:addToHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); + ShowError("HPM:addToHPData:%s: failed, type %d (%u|%u)\n", HPM->pid2name(pluginID), type, pluginID, classid); return; } store = *storeptr; /* duplicate check */ - 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; - } + ARR_FIND(0, VECTOR_LENGTH(store->entries), i, VECTOR_INDEX(store->entries, i)->pluginID == pluginID && VECTOR_INDEX(store->entries, i)->classid == classid); + if (i != VECTOR_LENGTH(store->entries)) { + ShowError("HPM:addToHPData:%s: error! attempting to insert duplicate struct of id %u and classid %u\n", HPM->pid2name(pluginID), pluginID, classid); + return; } /* 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); + CREATE(entry, struct hplugin_data_entry, 1); /* input */ - HPData->pluginID = pluginID; - HPData->type = index; - HPData->flag.free = autofree ? 1 : 0; - HPData->data = data; - - /* resize */ - RECREATE(store->array, struct hplugin_data_entry *, ++store->count); + entry->pluginID = pluginID; + entry->classid = classid; + entry->flag.free = autofree ? 1 : 0; + entry->data = data; - store->array[store->count - 1] = HPData; + VECTOR_ENSURE(store->entries, 1, 1); + VECTOR_PUSH(store->entries, entry); } -void *hplugins_getFromHPData(enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, unsigned int index) +/** + * Retrieves an entry from a plugin data store. + * + * @param type[in] The store type. + * @param pluginID[in] The plugin identifier. + * @param store[in] The store. + * @param classid[in] The entry class identifier. + * + * @return The retrieved entry, or NULL. + */ +void *hplugins_getFromHPData(enum HPluginDataTypes type, uint32 pluginID, struct hplugin_data_store *store, uint32 classid) { - unsigned int i; - struct hplugin_data_store *store; + int i; - if (!HPM->data_store_validate(type, storeptr)) { + if (!HPM->data_store_validate(type, &store, false)) { /* woo it failed! */ - ShowError("HPM:getFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); + ShowError("HPM:getFromHPData:%s: failed, type %d (%u|%u)\n", HPM->pid2name(pluginID), type, pluginID, classid); return NULL; } - store = *storeptr; + if (!store) + return NULL; - for (i = 0; i < store->count; i++) { - if (store->array[i]->pluginID == pluginID && store->array[i]->type == index) - return store->array[i]->data; - } + ARR_FIND(0, VECTOR_LENGTH(store->entries), i, VECTOR_INDEX(store->entries, i)->pluginID == pluginID && VECTOR_INDEX(store->entries, i)->classid == classid); + if (i != VECTOR_LENGTH(store->entries)) + return VECTOR_INDEX(store->entries, i)->data; return NULL; } -void hplugins_removeFromHPData(enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, unsigned int index) +/** + * Removes an entry from a plugin data store. + * + * @param type[in] The store type. + * @param pluginID[in] The plugin identifier. + * @param store[in] The store. + * @param classid[in] The entry class identifier. + */ +void hplugins_removeFromHPData(enum HPluginDataTypes type, uint32 pluginID, struct hplugin_data_store *store, uint32 classid) { - unsigned int i; - struct hplugin_data_store *store; + struct hplugin_data_entry *entry; + int i; - if (!HPM->data_store_validate(type, storeptr)) { + if (!HPM->data_store_validate(type, &store, false)) { /* woo it failed! */ - ShowError("HPM:removeFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); + ShowError("HPM:removeFromHPData:%s: failed, type %d (%u|%u)\n", HPM->pid2name(pluginID), type, pluginID, classid); return; } - store = *storeptr; - - for (i = 0; i < store->count; i++) { - if (store->array[i]->pluginID == pluginID && store->array[i]->type == index) - break; - } - - if (i != store->count) { - unsigned int cursor; + if (!store) + return; - aFree(store->array[i]->data);/* when its removed we delete it regardless of autofree */ - aFree(store->array[i]); - store->array[i] = NULL; + ARR_FIND(0, VECTOR_LENGTH(store->entries), i, VECTOR_INDEX(store->entries, i)->pluginID == pluginID && VECTOR_INDEX(store->entries, i)->classid == classid); + if (i == VECTOR_LENGTH(store->entries)) + return; - for (i = 0, cursor = 0; i < store->count; i++) { - if (store->array[i] == NULL) - continue; - if (i != cursor) - store->array[cursor] = store->array[i]; - cursor++; - } - store->count = cursor; - } + entry = VECTOR_INDEX(store->entries, i); + VECTOR_ERASE(store->entries, i); // Erase and compact + aFree(entry->data); // when it's removed we delete it regardless of autofree + aFree(entry); } /* TODO: add ability for tracking using pID for the upcoming runtime load/unload support. */ @@ -765,25 +803,30 @@ bool hplugins_parse_conf(const char *w1, const char *w2, enum HPluginConfType po } /** - * Helper to destroy and release an interface's hplugin_data store. + * Helper to destroy an interface's hplugin_data store and release any owned memory. * - * @param hdata The hplugin_data store. The pointer will be freed. + * The pointer will be cleared. + * + * @param storeptr[in,out] A pointer to the plugin data store. */ -void hplugin_data_store_destroy(struct hplugin_data_store *store) +void hplugin_data_store_destroy(struct hplugin_data_store **storeptr) { - unsigned int i; - - if (!store) + struct hplugin_data_store *store; + nullpo_retv(storeptr); + store = *storeptr; + if (store == NULL) return; - for (i = 0; i < store->count; i++) { - if (store->array[i]->flag.free) { - aFree(store->array[i]->data); + while (VECTOR_LENGTH(store->entries) > 0) { + struct hplugin_data_entry *entry = VECTOR_POP(store->entries); + if (entry->flag.free) { + aFree(entry->data); } - aFree(store->array[i]); + aFree(entry); } - aFree(store->array); + VECTOR_CLEAR(store->entries); aFree(store); + *storeptr = NULL; } /** @@ -792,13 +835,21 @@ void hplugin_data_store_destroy(struct hplugin_data_store *store) * The store is owned by the caller, and it should be eventually destroyed by * \c hdata_destroy. * - * @return An initialized hplugin_data store. + * @param storeptr[in,out] A pointer to the data store to initialize. + * @param type[in] The store type. */ -struct hplugin_data_store *hplugin_data_store_create(void) +void hplugin_data_store_create(struct hplugin_data_store **storeptr, enum HPluginDataTypes type) { struct hplugin_data_store *store; - CREATE(store, struct hplugin_data_store, 1); - return store; + nullpo_retv(storeptr); + + if (*storeptr == NULL) { + CREATE(*storeptr, struct hplugin_data_store, 1); + } + store = *storeptr; + + store->type = type; + VECTOR_INIT(store->entries); } /** diff --git a/src/common/HPM.h b/src/common/HPM.h index 1d13a178f..5420e5300 100644 --- a/src/common/HPM.h +++ b/src/common/HPM.h @@ -65,18 +65,24 @@ struct hpm_symbol { void *ptr; ///< The symbol value }; +/** + * A plugin custom data, to be injected in various interfaces and objects. + */ struct hplugin_data_entry { - unsigned int pluginID; - unsigned int type; + uint32 pluginID; ///< The owner plugin identifier. + uint32 classid; ///< The entry's object type, managed by the plugin (for plugins that need more than one entry). struct { - unsigned int free : 1; + unsigned int free : 1; ///< Whether the entry data should be automatically cleared by the HPM. } flag; - void *data; + void *data; ///< The entry data. }; +/** + * A store for plugin custom data entries. + */ struct hplugin_data_store { - struct hplugin_data_entry **array; - unsigned int count; + enum HPluginDataTypes type; ///< The store type. + VECTOR_DECL(struct hplugin_data_entry *) entries; ///< The store entries. }; struct HPluginPacket { @@ -144,11 +150,11 @@ struct HPM_interface { 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); + void (*data_store_create) (struct hplugin_data_store **storeptr, enum HPluginDataTypes type); + void (*data_store_destroy) (struct hplugin_data_store **storeptr); + bool (*data_store_validate) (enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize); /* for server-specific HPData e.g. map_session_data */ - bool (*data_store_validate_sub) (enum HPluginDataTypes type, struct hplugin_data_store **store); + bool (*data_store_validate_sub) (enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize); }; CMDLINEARG(loadplugin); diff --git a/src/common/HPMi.h b/src/common/HPMi.h index d92503a91..9a61dd256 100644 --- a/src/common/HPMi.h +++ b/src/common/HPMi.h @@ -60,19 +60,23 @@ enum HPluginHookType { HOOK_TYPE_POST, }; +/** + * Data types for plugin custom data. + */ enum HPluginDataTypes { - HPDT_SESSION, - HPDT_MSD, - HPDT_NPCD, - HPDT_MAP, - HPDT_INSTANCE, - HPDT_GUILD, - HPDT_PARTY, - HPDT_MOBDB, - HPDT_MOBDATA, - HPDT_ITEMDATA, - HPDT_BGDATA, - HPDT_AUTOTRADE_VEND, + HPDT_UNKNOWN, ///< Unknown type (such as an uninitialized store). + HPDT_SESSION, ///< For struct socket_data. + HPDT_MSD, ///< For struct map_session_data. + HPDT_NPCD, ///< For struct npc_data. + HPDT_MAP, ///< For struct map_data. + HPDT_INSTANCE, ///< For struct instance_data. + HPDT_GUILD, ///< For struct guild. + HPDT_PARTY, ///< For struct party_data. + HPDT_MOBDB, ///< For struct mob_db. + HPDT_MOBDATA, ///< For struct mob_data. + HPDT_ITEMDATA, ///< For struct item_data. + HPDT_BGDATA, ///< For struct battleground_data. + HPDT_AUTOTRADE_VEND, ///< For struct autotrade_vending. }; /* used in macros and conf storage */ @@ -97,53 +101,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)->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))) +#define addToSession(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_SESSION,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree))) +#define getFromSession(ptr,classid) (HPMi->getFromHPData(HPDT_SESSION,HPMi->pid,(ptr)->hdata,(classid))) +#define removeFromSession(ptr,classid) (HPMi->removeFromHPData(HPDT_SESSION,HPMi->pid,(ptr)->hdata,(classid))) /* map_session_data */ -#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))) +#define addToMSD(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_MSD,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree))) +#define getFromMSD(ptr,classid) (HPMi->getFromHPData(HPDT_MSD,HPMi->pid,(ptr)->hdata,(classid))) +#define removeFromMSD(ptr,classid) (HPMi->removeFromHPData(HPDT_MSD,HPMi->pid,(ptr)->hdata,(classid))) /* npc_data */ -#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))) +#define addToNPCD(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_NPCD,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree))) +#define getFromNPCD(ptr,classid) (HPMi->getFromHPData(HPDT_NPCD,HPMi->pid,(ptr)->hdata,(classid))) +#define removeFromNPCD(ptr,classid) (HPMi->removeFromHPData(HPDT_NPCD,HPMi->pid,(ptr)->hdata,(classid))) /* map_data */ -#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))) +#define addToMAPD(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_MAP,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree))) +#define getFromMAPD(ptr,classid) (HPMi->getFromHPData(HPDT_MAP,HPMi->pid,(ptr)->hdata,(classid))) +#define removeFromMAPD(ptr,classid) (HPMi->removeFromHPData(HPDT_MAP,HPMi->pid,(ptr)->hdata,(classid))) /* party_data */ -#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))) +#define addToPAD(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_PARTY,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree))) +#define getFromPAD(ptr,classid) (HPMi->getFromHPData(HPDT_PARTY,HPMi->pid,(ptr)->hdata,(classid))) +#define removeFromPAD(ptr,classid) (HPMi->removeFromHPData(HPDT_PARTY,HPMi->pid,(ptr)->hdata,(classid))) /* guild */ -#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))) +#define addToGLD(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_GUILD,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree))) +#define getFromGLD(ptr,classid) (HPMi->getFromHPData(HPDT_GUILD,HPMi->pid,(ptr)->hdata,(classid))) +#define removeFromGLD(ptr,classid) (HPMi->removeFromHPData(HPDT_GUILD,HPMi->pid,(ptr)->hdata,(classid))) /* instance_data */ -#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))) +#define addToINSTD(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_INSTANCE,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree))) +#define getFromINSTD(ptr,classid) (HPMi->getFromHPData(HPDT_INSTANCE,HPMi->pid,(ptr)->hdata,(classid))) +#define removeFromINSTD(ptr,classid) (HPMi->removeFromHPData(HPDT_INSTANCE,HPMi->pid,(ptr)->hdata,(classid))) /* mob_db */ -#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))) +#define addToMOBDB(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_MOBDB,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree))) +#define getFromMOBDB(ptr,classid) (HPMi->getFromHPData(HPDT_MOBDB,HPMi->pid,(ptr)->hdata,(classid))) +#define removeFromMOBDB(ptr,classid) (HPMi->removeFromHPData(HPDT_MOBDB,HPMi->pid,(ptr)->hdata,(classid))) /* mob_data */ -#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))) +#define addToMOBDATA(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_MOBDATA,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree))) +#define getFromMOBDATA(ptr,classid) (HPMi->getFromHPData(HPDT_MOBDATA,HPMi->pid,(ptr)->hdata,(classid))) +#define removeFromMOBDATA(ptr,classid) (HPMi->removeFromHPData(HPDT_MOBDATA,HPMi->pid,(ptr)->hdata,(classid))) /* item_data */ -#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))) +#define addToITEMDATA(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_ITEMDATA,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree))) +#define getFromITEMDATA(ptr,classid) (HPMi->getFromHPData(HPDT_ITEMDATA,HPMi->pid,(ptr)->hdata,(classid))) +#define removeFromITEMDATA(ptr,classid) (HPMi->removeFromHPData(HPDT_ITEMDATA,HPMi->pid,(ptr)->hdata,(classid))) /* battleground_data */ -#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))) +#define addToBGDATA(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_BGDATA,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree))) +#define getFromBGDATA(ptr,classid) (HPMi->getFromHPData(HPDT_BGDATA,HPMi->pid,(ptr)->hdata,(classid))) +#define removeFromBGDATA(ptr,classid) (HPMi->removeFromHPData(HPDT_BGDATA,HPMi->pid,(ptr)->hdata,(classid))) /* autotrade_vending */ -#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))) +#define addToATVEND(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree))) +#define getFromATVEND(ptr,classid) (HPMi->getFromHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,(ptr)->hdata,(classid))) +#define removeFromATVEND(ptr,classid) (HPMi->removeFromHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,(ptr)->hdata,(classid))) /// HPMi->addCommand #define addAtcommand(cname,funcname) do { \ @@ -206,9 +210,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, 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); + void (*addToHPData) (enum HPluginDataTypes type, uint32 pluginID, struct hplugin_data_store **storeptr, void *data, uint32 classid, bool autofree); + void *(*getFromHPData) (enum HPluginDataTypes type, uint32 pluginID, struct hplugin_data_store *store, uint32 classid); + void (*removeFromHPData) (enum HPluginDataTypes type, uint32 pluginID, struct hplugin_data_store *store, uint32 classid); /* 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 cbda0e91b..73d4510a1 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -661,9 +661,7 @@ struct guild { unsigned short instances; struct channel_data *channel; - - /* HPM Custom Struct */ - struct hplugin_data_store *hdata; + struct hplugin_data_store *hdata; ///< HPM Plugin Data Store }; struct guild_castle { diff --git a/src/common/socket.c b/src/common/socket.c index 842f9ba87..a26873b67 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -637,8 +637,7 @@ static void delete_session(int fd) aFree(sockt->session[fd]->wdata); if( sockt->session[fd]->session_data ) aFree(sockt->session[fd]->session_data); - HPM->data_store_destroy(sockt->session[fd]->hdata); - sockt->session[fd]->hdata = NULL; + HPM->data_store_destroy(&sockt->session[fd]->hdata); aFree(sockt->session[fd]); sockt->session[fd] = NULL; } diff --git a/src/common/socket.h b/src/common/socket.h index 510eac575..a2dea8b74 100644 --- a/src/common/socket.h +++ b/src/common/socket.h @@ -104,8 +104,7 @@ struct socket_data { ParseFunc func_parse; void* session_data; // stores application-specific data related to the session - - struct hplugin_data_store *hdata; + struct hplugin_data_store *hdata; ///< HPM Plugin Data Store. }; struct hSockOpt { diff --git a/src/login/HPMlogin.c b/src/login/HPMlogin.c index ce88728fe..b900f28fe 100644 --- a/src/login/HPMlogin.c +++ b/src/login/HPMlogin.c @@ -37,9 +37,10 @@ * * @see HPM_interface::data_store_validate */ -bool HPM_login_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store) +bool HPM_login_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize) { switch (type) { + // No supported types at the moment default: break; } diff --git a/src/login/HPMlogin.h b/src/login/HPMlogin.h index 1f08a8666..35d4bd01c 100644 --- a/src/login/HPMlogin.h +++ b/src/login/HPMlogin.h @@ -13,7 +13,7 @@ struct hplugin; -bool HPM_login_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store); +bool HPM_login_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize); void HPM_login_plugin_load_sub(struct hplugin *plugin); diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c index ddffb5519..edbe74039 100644 --- a/src/map/HPMmap.c +++ b/src/map/HPMmap.c @@ -90,7 +90,7 @@ unsigned int atcommand_list_items = 0; * * @see HPM_interface::data_store_validate */ -bool HPM_map_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store) +bool HPM_map_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize) { switch (type) { case HPDT_MSD: @@ -104,9 +104,7 @@ bool HPM_map_data_store_validate(enum HPluginDataTypes type, struct hplugin_data case HPDT_ITEMDATA: case HPDT_BGDATA: case HPDT_AUTOTRADE_VEND: - if (!*store) { - *store = HPM->data_store_create(); - } + // Initialized by the caller. return true; default: break; diff --git a/src/map/HPMmap.h b/src/map/HPMmap.h index 10bdf0ba7..b1957b139 100644 --- a/src/map/HPMmap.h +++ b/src/map/HPMmap.h @@ -15,7 +15,7 @@ struct hplugin; struct map_session_data; -bool HPM_map_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store); +bool HPM_map_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize); 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 46d695272..be6b7a863 100644 --- a/src/map/battleground.c +++ b/src/map/battleground.c @@ -881,8 +881,7 @@ 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); - HPM->data_store_destroy(bgd->hdata); - bgd->hdata = NULL; + HPM->data_store_destroy(&bgd->hdata); return 0; } diff --git a/src/map/battleground.h b/src/map/battleground.h index 0280407a2..dcf92d6d8 100644 --- a/src/map/battleground.h +++ b/src/map/battleground.h @@ -53,8 +53,7 @@ struct battleground_data { // Logout Event char logout_event[EVENT_NAME_LENGTH]; char die_event[EVENT_NAME_LENGTH]; - /* HPM Custom Struct */ - struct hplugin_data_store *hdata; + struct hplugin_data_store *hdata; ///< HPM Plugin Data Store }; struct bg_arena { diff --git a/src/map/guild.c b/src/map/guild.c index 2dca97502..f8798f821 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -1763,8 +1763,7 @@ int guild_broken(int guild_id,int flag) if( g->instance ) aFree(g->instance); - HPM->data_store_destroy(g->hdata); - g->hdata = NULL; + HPM->data_store_destroy(&g->hdata); idb_remove(guild->db,guild_id); return 0; @@ -2250,8 +2249,7 @@ void do_final_guild(void) { aFree(g->instance); g->instance = NULL; } - HPM->data_store_destroy(g->hdata); - g->hdata = NULL; + HPM->data_store_destroy(&g->hdata); } dbi_destroy(iter); diff --git a/src/map/instance.c b/src/map/instance.c index 7213c43a1..0936a5ace 100644 --- a/src/map/instance.c +++ b/src/map/instance.c @@ -588,8 +588,7 @@ void instance_destroy(int instance_id) { instance->list[instance_id].state = INSTANCE_FREE; instance->list[instance_id].num_map = 0; - HPM->data_store_destroy(instance->list[instance_id].hdata); - instance->list[instance_id].hdata = NULL; + HPM->data_store_destroy(&instance->list[instance_id].hdata); } /*-------------------------------------- diff --git a/src/map/instance.h b/src/map/instance.h index f879195ef..058cd2c3d 100644 --- a/src/map/instance.h +++ b/src/map/instance.h @@ -52,9 +52,7 @@ struct instance_data { unsigned int original_progress_timeout; struct point respawn; ///< reload spawn - - /** HPM Custom Struct */ - struct hplugin_data_store *hdata; + struct hplugin_data_store *hdata; ///< HPM Plugin Data Store }; struct instance_interface { diff --git a/src/map/itemdb.c b/src/map/itemdb.c index c531a4d7a..ccfff2246 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -2100,8 +2100,7 @@ void destroy_item_data(struct item_data* self, int free_self) script->free_code(self->unequip_script); if( self->combos ) aFree(self->combos); - HPM->data_store_destroy(self->hdata); - self->hdata = NULL; + HPM->data_store_destroy(&self->hdata); #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 de9770aab..64b800b87 100644 --- a/src/map/itemdb.h +++ b/src/map/itemdb.h @@ -489,9 +489,7 @@ struct item_data { /* TODO add a pointer to some sort of (struct extra) and gather all the not-common vals into it to save memory */ struct item_group *group; struct item_package *package; - - /* HPM Custom Struct */ - struct hplugin_data_store *hdata; + struct hplugin_data_store *hdata; ///< HPM Plugin Data Store }; #define itemdb_name(n) (itemdb->search(n)->name) diff --git a/src/map/map.c b/src/map/map.c index 0ed7072d2..b142ed1f3 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -3239,8 +3239,7 @@ void do_final_maps(void) { if( map->list[i].qi_data ) aFree(map->list[i].qi_data); - HPM->data_store_destroy(map->list[i].hdata); - map->list[i].hdata = NULL; + HPM->data_store_destroy(&map->list[i].hdata); } map->zone_db_clear(); diff --git a/src/map/map.h b/src/map/map.h index c3e426bb6..961a45793 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -737,9 +737,7 @@ struct map_data { /* speeds up clif_updatestatus processing by causing hpmeter to run only when someone with the permission can view it */ unsigned short hpmeter_visible; - - /* HPM Custom Struct */ - struct hplugin_data_store *hdata; + struct hplugin_data_store *hdata; ///< HPM Plugin Data Store }; /// Stores information about a remote map (for multi-mapserver setups). diff --git a/src/map/mob.c b/src/map/mob.c index 174d2e49f..01f585b6f 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -4708,8 +4708,7 @@ int do_init_mob(bool minimal) { void mob_destroy_mob_db(int index) { struct mob_db *data = mob->db_data[index]; - HPM->data_store_destroy(data->hdata); - data->hdata = NULL; + HPM->data_store_destroy(&data->hdata); aFree(data); mob->db_data[index] = NULL; } diff --git a/src/map/mob.h b/src/map/mob.h index 1142502f4..bb26258c6 100644 --- a/src/map/mob.h +++ b/src/map/mob.h @@ -140,9 +140,7 @@ struct mob_db { int maxskill; struct mob_skill skill[MAX_MOBSKILL]; struct spawn_info spawn[10]; - - /* HPM Custom Struct */ - struct hplugin_data_store *hdata; + struct hplugin_data_store *hdata; ///< HPM Plugin Data Store }; struct mob_data { @@ -209,9 +207,7 @@ struct mob_data { * MvP Tombstone NPC ID **/ int tomb_nid; - - /* HPM Custom Struct */ - struct hplugin_data_store *hdata; + struct hplugin_data_store *hdata; ///< HPM Plugin Data Store }; diff --git a/src/map/npc.c b/src/map/npc.c index 85de5301b..24b22beb3 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -2321,8 +2321,7 @@ int npc_unload(struct npc_data* nd, bool single) nd->ud = NULL; } - HPM->data_store_destroy(nd->hdata); - nd->hdata = NULL; + HPM->data_store_destroy(&nd->hdata); aFree(nd); diff --git a/src/map/npc.h b/src/map/npc.h index 06aee3f93..bf3d1494d 100644 --- a/src/map/npc.h +++ b/src/map/npc.h @@ -102,8 +102,7 @@ struct npc_data { char killer_name[NAME_LENGTH]; } tomb; } u; - /* HPData Support for npc_data */ - struct hplugin_data_store *hdata; + struct hplugin_data_store *hdata; ///< HPM Plugin Data Store }; diff --git a/src/map/party.c b/src/map/party.c index 4735dfc42..f7e7d431c 100644 --- a/src/map/party.c +++ b/src/map/party.c @@ -103,8 +103,7 @@ int party_db_final(DBKey key, DBData *data, va_list ap) { if (p->instance) aFree(p->instance); - HPM->data_store_destroy(p->hdata); - p->hdata = NULL; + HPM->data_store_destroy(&p->hdata); } return 0; } @@ -600,8 +599,7 @@ int party_broken(int party_id) if( p->instance ) aFree(p->instance); - HPM->data_store_destroy(p->hdata); - p->hdata = NULL; + HPM->data_store_destroy(&p->hdata); idb_remove(party->db,party_id); return 0; diff --git a/src/map/party.h b/src/map/party.h index 960e6da08..df7c03f05 100644 --- a/src/map/party.h +++ b/src/map/party.h @@ -35,9 +35,7 @@ struct party_data { unsigned snovice :1; ///< There's a Super Novice unsigned tk : 1; ///< There's a taekwon } state; - - /* HPM Custom Struct */ - struct hplugin_data_store *hdata; + struct hplugin_data_store *hdata; ///< HPM Plugin Data Store }; #define PB_NOTICE_LENGTH (36 + 1) diff --git a/src/map/pc.c b/src/map/pc.c index fee41deff..99f5b867e 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -11332,8 +11332,7 @@ void pc_autotrade_populate(struct map_session_data *sd) { pc->autotrade_update(sd,PAUC_START); - HPM->data_store_destroy(data->hdata); - data->hdata = NULL; + HPM->data_store_destroy(&data->hdata); idb_remove(pc->at_db, sd->status.char_id); } @@ -11343,8 +11342,7 @@ 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); - HPM->data_store_destroy(at_v->hdata); - at_v->hdata = NULL; + HPM->data_store_destroy(&at_v->hdata); return 0; } diff --git a/src/map/pc.h b/src/map/pc.h index a74bc6c80..2c8b24acf 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -539,9 +539,7 @@ END_ZEROED_BLOCK; unsigned short (*parse_cmd_func)(int fd, struct map_session_data *sd); ///< parse_cmd_func used by this player unsigned char delayed_damage;//ref. counter bugreport:7307 [Ind/Hercules] - - /* HPM Custom Struct */ - struct hplugin_data_store *hdata; + struct hplugin_data_store *hdata; ///< HPM Plugin Data Store /* expiration_time timer id */ int expiration_tid; @@ -756,8 +754,7 @@ struct autotrade_vending { struct item list[MAX_VENDING]; struct s_vending vending[MAX_VENDING]; unsigned char vend_num; - /* HPM Custom Struct */ - struct hplugin_data_store *hdata; + struct hplugin_data_store *hdata; ///< HPM Plugin Data Store }; /*===================================== diff --git a/src/map/unit.c b/src/map/unit.c index 0f8a9d7e6..dcb5ec900 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -2654,10 +2654,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { sd->quest_log = NULL; sd->num_quests = sd->avail_quests = 0; } - - HPM->data_store_destroy(sd->hdata); - sd->hdata = NULL; - + HPM->data_store_destroy(&sd->hdata); break; } case BL_PET: @@ -2768,9 +2765,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { if( md->tomb_nid ) mob->mvptomb_destroy(md); - HPM->data_store_destroy(md->hdata); - md->hdata = NULL; - + HPM->data_store_destroy(&md->hdata); break; } case BL_HOM: |