From edbe66e718bca90f1da015a6db3284d840ba19cb Mon Sep 17 00:00:00 2001 From: AnnieRuru Date: Sat, 20 Sep 2014 03:49:45 +0800 Subject: Add struct item_data, mob_db and mob_data for plugins http://hercules.ws/board/topic/7161-plugin-missing-hook-to-struct-item-data-and-mob-data/ --- src/common/HPMi.h | 15 +++++++++++++++ src/map/HPMmap.c | 12 ++++++++++++ src/map/itemdb.h | 4 ++++ src/map/mob.h | 8 ++++++++ 4 files changed, 39 insertions(+) (limited to 'src') diff --git a/src/common/HPMi.h b/src/common/HPMi.h index 1022a1ec2..47f4e6b8b 100644 --- a/src/common/HPMi.h +++ b/src/common/HPMi.h @@ -80,6 +80,9 @@ enum HPluginDataTypes { HPDT_INSTANCE, HPDT_GUILD, HPDT_PARTY, + HPDT_MOBDB, + HPDT_MOBDATA, + HPDT_ITEMDATA, }; /* used in macros and conf storage */ @@ -131,6 +134,18 @@ enum HPluginConfType { #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))) +/* 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))) +/* 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))) +/* 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))) /* HPMi->addCommand */ #define addAtcommand(cname,funcname) \ diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c index a0701ae45..f1cdec538 100644 --- a/src/map/HPMmap.c +++ b/src/map/HPMmap.c @@ -101,6 +101,18 @@ bool HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataType 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; default: return false; } diff --git a/src/map/itemdb.h b/src/map/itemdb.h index 23339790e..f65345cb9 100644 --- a/src/map/itemdb.h +++ b/src/map/itemdb.h @@ -434,6 +434,10 @@ 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 HPluginData **hdata; + unsigned int hdatac; }; struct item_combo { diff --git a/src/map/mob.h b/src/map/mob.h index f79b33804..133107143 100644 --- a/src/map/mob.h +++ b/src/map/mob.h @@ -126,6 +126,10 @@ struct mob_db { int maxskill; struct mob_skill skill[MAX_MOBSKILL]; struct spawn_info spawn[10]; + + /* HPM Custom Struct */ + struct HPluginData **hdata; + unsigned int hdatac; }; struct mob_data { @@ -197,6 +201,10 @@ struct mob_data { * MvP Tombstone NPC ID **/ int tomb_nid; + + /* HPM Custom Struct */ + struct HPluginData **hdata; + unsigned int hdatac; }; -- cgit v1.2.3-70-g09d2 From 2e76de4a5c6f51dab67b8ee41604d714e3cddd39 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 17 Dec 2014 17:35:10 +0300 Subject: Remove plugin data in item_data destruction. --- src/map/itemdb.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/map/itemdb.c b/src/map/itemdb.c index 545ce9ba0..9bb34f024 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -16,6 +16,7 @@ #include "mob.h" // MAX_MOB_DB #include "pc.h" // W_MUSICAL, W_WHIP #include "script.h" // item script processing +#include "../common/HPM.h" #include "../common/conf.h" #include "../common/malloc.h" #include "../common/nullpo.h" @@ -2069,6 +2070,7 @@ bool itemdb_is_item_usable(struct item_data *item) /// Destroys the item_data. void destroy_item_data(struct item_data* self, int free_self) { + int v; if( self == NULL ) return; // free scripts @@ -2080,6 +2082,14 @@ void destroy_item_data(struct item_data* self, int free_self) script->free_code(self->unequip_script); if( self->combos ) aFree(self->combos); + for (v = 0; v < self->hdatac; v++ ) { + if (self->hdata[v]->flag.free ) { + aFree(self->hdata[v]->data); + } + aFree(self->hdata[v]); + } + if (self->hdata) + aFree(self->hdata); #if defined(DEBUG) // trash item memset(self, 0xDD, sizeof(struct item_data)); -- cgit v1.2.3-70-g09d2 From 6986718327b15180bed128037addbd6fcd558005 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 17 Dec 2014 18:41:42 +0300 Subject: Move mob_db deletion into separate function. --- src/map/mob.c | 16 ++++++++++------ src/map/mob.h | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/map/mob.c b/src/map/mob.c index 6171ddb75..ad8615678 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -3550,8 +3550,7 @@ int mob_clone_delete(struct mob_data *md) const int class_ = md->class_; if (class_ >= MOB_CLONE_START && class_ < MOB_CLONE_END && mob->db_data[class_]!=NULL) { - aFree(mob->db_data[class_]); - mob->db_data[class_]=NULL; + mob->destroy_mob_db(class_); //Clear references to the db md->db = mob->dummy; md->vd = NULL; @@ -3574,8 +3573,7 @@ int mob_makedummymobdb(int class_) return 1; //Using the mob->dummy data already. [Skotlex] if (class_ > 0 && class_ <= MAX_MOB_DB) { //Remove the mob data so that it uses the dummy data instead. - aFree(mob->db_data[class_]); - mob->db_data[class_] = NULL; + mob->destroy_mob_db(class_); } return 0; } @@ -4701,6 +4699,12 @@ int do_init_mob(bool minimal) { return 0; } +void mob_destroy_mob_db(int index) +{ + aFree(mob->db_data[index]); + mob->db_data[index] = NULL; +} + /*========================================== * Clean memory usage. *------------------------------------------*/ @@ -4716,8 +4720,7 @@ int do_final_mob(void) { if (mob->db_data[i] != NULL) { - aFree(mob->db_data[i]); - mob->db_data[i] = NULL; + mob->destroy_mob_db(i); } } for (i = 0; i <= MAX_MOB_CHAT; i++) @@ -4852,4 +4855,5 @@ void mob_defaults(void) { mob->readdb_itemratio = mob_readdb_itemratio; mob->load = mob_load; mob->clear_spawninfo = mob_clear_spawninfo; + mob->destroy_mob_db = mob_destroy_mob_db; } diff --git a/src/map/mob.h b/src/map/mob.h index 133107143..9aac2c664 100644 --- a/src/map/mob.h +++ b/src/map/mob.h @@ -377,6 +377,7 @@ struct mob_interface { bool (*readdb_itemratio) (char *str[], int columns, int current); void (*load) (bool minimal); void (*clear_spawninfo) (); + void (*destroy_mob_db) (int index); }; struct mob_interface *mob; -- cgit v1.2.3-70-g09d2 From 220d882bc33baad69db55ade4ea41b845b0e9611 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 17 Dec 2014 18:50:37 +0300 Subject: Remove plugin data in mob_db destruction. --- src/map/mob.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/map/mob.c b/src/map/mob.c index ad8615678..8fe3e3cef 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -34,6 +34,7 @@ #include "script.h" #include "skill.h" #include "status.h" +#include "../common/HPM.h" #include "../common/cbasetypes.h" #include "../common/db.h" #include "../common/ers.h" @@ -4701,7 +4702,17 @@ int do_init_mob(bool minimal) { void mob_destroy_mob_db(int index) { - aFree(mob->db_data[index]); + struct mob_db *data = mob->db_data[index]; + int v; + for (v = 0; v < data->hdatac; v++ ) { + if (data->hdata[v]->flag.free ) { + aFree(data->hdata[v]->data); + } + aFree(data->hdata[v]); + } + if (data->hdata) + aFree(data->hdata); + aFree(data); mob->db_data[index] = NULL; } -- cgit v1.2.3-70-g09d2 From 575b83e553b1b02a05a6cf9732d6b761b522cd74 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 17 Dec 2014 20:24:43 +0300 Subject: Remove plugin data in mob_data destruction. --- src/map/unit.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 0924e6cf2..e23eb42ac 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -2720,6 +2720,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { } case BL_MOB: { + unsigned int k; struct mob_data *md = (struct mob_data*)bl; if( md->spawn_timer != INVALID_TIMER ) { @@ -2774,6 +2775,15 @@ int unit_free(struct block_list *bl, clr_type clrtype) { mob->clone_delete(md); if( md->tomb_nid ) mob->mvptomb_destroy(md); + + for (k = 0; k < md->hdatac; k++) { + if( md->hdata[k]->flag.free ) { + aFree(md->hdata[k]->data); + } + aFree(md->hdata[k]); + } + if (md->hdata) + aFree(md->hdata); break; } case BL_HOM: -- cgit v1.2.3-70-g09d2 From a75f608ed23e2d6ac06582abb833c2a874cd7815 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 18 Dec 2014 00:29:24 +0300 Subject: Add function for reading custom itemdb fields. This functions called after reading normal fields and after adding item to itemdb. --- src/map/itemdb.c | 7 +++++++ src/map/itemdb.h | 1 + 2 files changed, 8 insertions(+) (limited to 'src') diff --git a/src/map/itemdb.c b/src/map/itemdb.c index 9bb34f024..cd4465468 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -1502,6 +1502,11 @@ int itemdb_validate_entry(struct item_data *entry, int n, const char *source) { return item->nameid; } +void itemdb_readdb_additional_fields(int itemid, config_setting_t *it, int n, const char *source) +{ + // do nothing. plugins can do own work +} + /** * Processes one itemdb entry from the sql backend, loading and inserting it * into the item database. @@ -1937,6 +1942,7 @@ int itemdb_readdb_libconfig(const char *filename) { if( !nameid ) continue; + itemdb->readdb_additional_fields(nameid, it, i - 1, filename); count++; if( duplicate[nameid] ) { @@ -2345,6 +2351,7 @@ void itemdb_defaults(void) { itemdb->read_combos = itemdb_read_combos; itemdb->gendercheck = itemdb_gendercheck; itemdb->validate_entry = itemdb_validate_entry; + itemdb->readdb_additional_fields = itemdb_readdb_additional_fields; itemdb->readdb_sql_sub = itemdb_readdb_sql_sub; itemdb->readdb_libconfig_sub = itemdb_readdb_libconfig_sub; itemdb->readdb_libconfig = itemdb_readdb_libconfig; diff --git a/src/map/itemdb.h b/src/map/itemdb.h index f65345cb9..9a72c64ac 100644 --- a/src/map/itemdb.h +++ b/src/map/itemdb.h @@ -604,6 +604,7 @@ struct itemdb_interface { void (*read_combos) (); int (*gendercheck) (struct item_data *id); int (*validate_entry) (struct item_data *entry, int n, const char *source); + void (*readdb_additional_fields) (int itemid, config_setting_t *it, int n, const char *source); int (*readdb_sql_sub) (Sql *handle, int n, const char *source); int (*readdb_libconfig_sub) (config_setting_t *it, int n, const char *source); int (*readdb_libconfig) (const char *filename); -- cgit v1.2.3-70-g09d2 From 2c6fd58d633e4139a6f0f3b4bb0262e64fc957e2 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 18 Dec 2014 00:34:35 +0300 Subject: Update HPM hooks. --- .../HPMHooking/HPMHooking_map.HPMHooksCore.inc | 8 ++++ .../HPMHooking/HPMHooking_map.HookingPoints.inc | 2 + src/plugins/HPMHooking/HPMHooking_map.Hooks.inc | 52 ++++++++++++++++++++++ 3 files changed, 62 insertions(+) (limited to 'src') diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc index 7b9eadb91..b4c98894e 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc @@ -2567,6 +2567,8 @@ struct { struct HPMHookPoint *HP_itemdb_gendercheck_post; struct HPMHookPoint *HP_itemdb_validate_entry_pre; struct HPMHookPoint *HP_itemdb_validate_entry_post; + struct HPMHookPoint *HP_itemdb_readdb_additional_fields_pre; + struct HPMHookPoint *HP_itemdb_readdb_additional_fields_post; struct HPMHookPoint *HP_itemdb_readdb_sql_sub_pre; struct HPMHookPoint *HP_itemdb_readdb_sql_sub_post; struct HPMHookPoint *HP_itemdb_readdb_libconfig_sub_pre; @@ -3191,6 +3193,8 @@ struct { struct HPMHookPoint *HP_mob_load_post; struct HPMHookPoint *HP_mob_clear_spawninfo_pre; struct HPMHookPoint *HP_mob_clear_spawninfo_post; + struct HPMHookPoint *HP_mob_destroy_mob_db_pre; + struct HPMHookPoint *HP_mob_destroy_mob_db_post; struct HPMHookPoint *HP_npc_init_pre; struct HPMHookPoint *HP_npc_init_post; struct HPMHookPoint *HP_npc_final_pre; @@ -7644,6 +7648,8 @@ struct { int HP_itemdb_gendercheck_post; int HP_itemdb_validate_entry_pre; int HP_itemdb_validate_entry_post; + int HP_itemdb_readdb_additional_fields_pre; + int HP_itemdb_readdb_additional_fields_post; int HP_itemdb_readdb_sql_sub_pre; int HP_itemdb_readdb_sql_sub_post; int HP_itemdb_readdb_libconfig_sub_pre; @@ -8268,6 +8274,8 @@ struct { int HP_mob_load_post; int HP_mob_clear_spawninfo_pre; int HP_mob_clear_spawninfo_post; + int HP_mob_destroy_mob_db_pre; + int HP_mob_destroy_mob_db_post; int HP_npc_init_pre; int HP_npc_init_post; int HP_npc_final_pre; diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc index 58af99107..a92bf59f5 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc @@ -1302,6 +1302,7 @@ struct HookingPointData HookingPoints[] = { { HP_POP(itemdb->read_combos, HP_itemdb_read_combos) }, { HP_POP(itemdb->gendercheck, HP_itemdb_gendercheck) }, { HP_POP(itemdb->validate_entry, HP_itemdb_validate_entry) }, + { HP_POP(itemdb->readdb_additional_fields, HP_itemdb_readdb_additional_fields) }, { HP_POP(itemdb->readdb_sql_sub, HP_itemdb_readdb_sql_sub) }, { HP_POP(itemdb->readdb_libconfig_sub, HP_itemdb_readdb_libconfig_sub) }, { HP_POP(itemdb->readdb_libconfig, HP_itemdb_readdb_libconfig) }, @@ -1621,6 +1622,7 @@ struct HookingPointData HookingPoints[] = { { HP_POP(mob->readdb_itemratio, HP_mob_readdb_itemratio) }, { HP_POP(mob->load, HP_mob_load) }, { HP_POP(mob->clear_spawninfo, HP_mob_clear_spawninfo) }, + { HP_POP(mob->destroy_mob_db, HP_mob_destroy_mob_db) }, /* npc */ { HP_POP(npc->init, HP_npc_init) }, { HP_POP(npc->final, HP_npc_final) }, diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc index 62b1be620..cc8f95353 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc @@ -33991,6 +33991,32 @@ int HP_itemdb_validate_entry(struct item_data *entry, int n, const char *source) } return retVal___; } +void HP_itemdb_readdb_additional_fields(int itemid, config_setting_t *it, int n, const char *source) { + int hIndex = 0; + if( HPMHooks.count.HP_itemdb_readdb_additional_fields_pre ) { + void (*preHookFunc) (int *itemid, config_setting_t *it, int *n, const char *source); + *HPMforce_return = false; + for(hIndex = 0; hIndex < HPMHooks.count.HP_itemdb_readdb_additional_fields_pre; hIndex++ ) { + preHookFunc = HPMHooks.list.HP_itemdb_readdb_additional_fields_pre[hIndex].func; + preHookFunc(&itemid, it, &n, source); + } + if( *HPMforce_return ) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.itemdb.readdb_additional_fields(itemid, it, n, source); + } + if( HPMHooks.count.HP_itemdb_readdb_additional_fields_post ) { + void (*postHookFunc) (int *itemid, config_setting_t *it, int *n, const char *source); + for(hIndex = 0; hIndex < HPMHooks.count.HP_itemdb_readdb_additional_fields_post; hIndex++ ) { + postHookFunc = HPMHooks.list.HP_itemdb_readdb_additional_fields_post[hIndex].func; + postHookFunc(&itemid, it, &n, source); + } + } + return; +} int HP_itemdb_readdb_sql_sub(Sql *handle, int n, const char *source) { int hIndex = 0; int retVal___ = 0; @@ -42588,6 +42614,32 @@ void HP_mob_clear_spawninfo(void) { } return; } +void HP_mob_destroy_mob_db(int index) { + int hIndex = 0; + if( HPMHooks.count.HP_mob_destroy_mob_db_pre ) { + void (*preHookFunc) (int *index); + *HPMforce_return = false; + for(hIndex = 0; hIndex < HPMHooks.count.HP_mob_destroy_mob_db_pre; hIndex++ ) { + preHookFunc = HPMHooks.list.HP_mob_destroy_mob_db_pre[hIndex].func; + preHookFunc(&index); + } + if( *HPMforce_return ) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.mob.destroy_mob_db(index); + } + if( HPMHooks.count.HP_mob_destroy_mob_db_post ) { + void (*postHookFunc) (int *index); + for(hIndex = 0; hIndex < HPMHooks.count.HP_mob_destroy_mob_db_post; hIndex++ ) { + postHookFunc = HPMHooks.list.HP_mob_destroy_mob_db_post[hIndex].func; + postHookFunc(&index); + } + } + return; +} /* npc */ int HP_npc_init(bool minimal) { int hIndex = 0; -- cgit v1.2.3-70-g09d2