summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaruna <haru@dotalux.com>2014-12-20 23:42:37 +0100
committerHaruna <haru@dotalux.com>2014-12-20 23:42:37 +0100
commit1134e030744e67bca61f52dc97075f33932f7a38 (patch)
tree3c5f077c6537f7e165039d3bf68d8052253b7dc2
parentc4456ddbebccaca51ab040c60e3c586ed2cc0a10 (diff)
parent2c6fd58d633e4139a6f0f3b4bb0262e64fc957e2 (diff)
downloadhercules-1134e030744e67bca61f52dc97075f33932f7a38.tar.gz
hercules-1134e030744e67bca61f52dc97075f33932f7a38.tar.bz2
hercules-1134e030744e67bca61f52dc97075f33932f7a38.tar.xz
hercules-1134e030744e67bca61f52dc97075f33932f7a38.zip
Merge pull request #416 from 4144/plugext
Extend plugins support in item_data, mob_db, mob_data
-rw-r--r--src/common/HPMi.h15
-rw-r--r--src/map/HPMmap.c12
-rw-r--r--src/map/itemdb.c17
-rw-r--r--src/map/itemdb.h5
-rw-r--r--src/map/mob.c27
-rw-r--r--src/map/mob.h9
-rw-r--r--src/map/unit.c10
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc8
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc2
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.Hooks.inc52
10 files changed, 151 insertions, 6 deletions
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.c b/src/map/itemdb.c
index 545ce9ba0..cd4465468 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"
@@ -1501,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.
@@ -1936,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] ) {
@@ -2069,6 +2076,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 +2088,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));
@@ -2335,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 23339790e..9a72c64ac 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 {
@@ -600,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);
diff --git a/src/map/mob.c b/src/map/mob.c
index 6171ddb75..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"
@@ -3550,8 +3551,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 +3574,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 +4700,22 @@ int do_init_mob(bool minimal) {
return 0;
}
+void mob_destroy_mob_db(int 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;
+}
+
/*==========================================
* Clean memory usage.
*------------------------------------------*/
@@ -4716,8 +4731,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 +4866,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 f79b33804..9aac2c664 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;
};
@@ -369,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;
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:
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;