diff options
author | Haru <haru@dotalux.com> | 2014-10-28 21:13:21 +0100 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2014-10-28 21:43:39 +0100 |
commit | 60becfc70e65ba7920079f990bfaa11851369f0c (patch) | |
tree | fd53b78cefae7fae6b01784f8ce3fbd58b31f302 | |
parent | d18235cae43500d68210b09514b76506fc831014 (diff) | |
download | hercules-60becfc70e65ba7920079f990bfaa11851369f0c.tar.gz hercules-60becfc70e65ba7920079f990bfaa11851369f0c.tar.bz2 hercules-60becfc70e65ba7920079f990bfaa11851369f0c.tar.xz hercules-60becfc70e65ba7920079f990bfaa11851369f0c.zip |
Added preliminary support for char and login server to HPMHooking
- Special thanks to Ind
Signed-off-by: Haru <haru@dotalux.com>
19 files changed, 570 insertions, 105 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c index 641d84c68..7a875d1c4 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -318,27 +318,40 @@ void hplugins_config_read(const char * const *extra_plugins, int extra_plugins_c if (plist != NULL) { int length = libconfig->setting_length(plist); char filename[60]; - for(i = 0; i < length; i++) { - if( !strcmpi(libconfig->setting_get_string_elem(plist,i),"HPMHooking") ) {//must load it first + char hooking_plugin_name[32]; + const char *plugin_name_suffix = ""; + if (SERVER_TYPE == SERVER_TYPE_LOGIN) + plugin_name_suffix = "_login"; + else if (SERVER_TYPE == SERVER_TYPE_CHAR) + plugin_name_suffix = "_char"; + else if (SERVER_TYPE == SERVER_TYPE_MAP) + plugin_name_suffix = "_map"; + snprintf(hooking_plugin_name, sizeof(hooking_plugin_name), "HPMHooking%s", plugin_name_suffix); + + for (i = 0; i < length; i++) { + const char *plugin_name = libconfig->setting_get_string_elem(plist,i); + if (strcmpi(plugin_name, "HPMHooking") == 0 || strcmpi(plugin_name, hooking_plugin_name) == 0) { //must load it first struct hplugin *plugin; - snprintf(filename, 60, "plugins/%s%s", libconfig->setting_get_string_elem(plist,i), DLL_EXT); - if( ( plugin = HPM->load(filename) ) ) { + snprintf(filename, 60, "plugins/%s%s", hooking_plugin_name, DLL_EXT); + if ((plugin = HPM->load(filename))) { bool (*func)(bool *fr); bool (*addhook_sub) (enum HPluginHookType type, const char *target, void *hook, unsigned int pID); - if( ( func = plugin_import(plugin->dll, "Hooked",bool (*)(bool *)) ) && ( addhook_sub = plugin_import(plugin->dll, "HPM_Plugin_AddHook",bool (*)(enum HPluginHookType, const char *, void *, unsigned int)) ) ) { - if( func(&HPM->force_return) ) { + if ((func = plugin_import(plugin->dll, "Hooked",bool (*)(bool *))) + && (addhook_sub = plugin_import(plugin->dll, "HPM_Plugin_AddHook",bool (*)(enum HPluginHookType, const char *, void *, unsigned int)))) { + if (func(&HPM->force_return)) { HPM->hooking = true; HPM->addhook_sub = addhook_sub; } } } + break; } } - for(i = 0; i < length; i++) { - if( strcmpi(libconfig->setting_get_string_elem(plist,i),"HPMHooking") ) {//now all others - snprintf(filename, 60, "plugins/%s%s", libconfig->setting_get_string_elem(plist,i), DLL_EXT); - HPM->load(filename); - } + for (i = 0; i < length; i++) { + if (strncmpi(libconfig->setting_get_string_elem(plist,i),"HPMHooking", 10) == 0) // Already loaded, skip + continue; + snprintf(filename, 60, "plugins/%s%s", libconfig->setting_get_string_elem(plist,i), DLL_EXT); + HPM->load(filename); } libconfig->destroy(&plugins_conf); } diff --git a/src/plugins/HPMHooking.c b/src/plugins/HPMHooking.c index 46792b268..3f3ecc4ec 100644 --- a/src/plugins/HPMHooking.c +++ b/src/plugins/HPMHooking.c @@ -11,6 +11,29 @@ #include "../common/malloc.h" #include "../common/mmo.h" #include "../common/socket.h" + +#if defined (HPMHOOKING_LOGIN) +#define HPM_SERVER_TYPE SERVER_TYPE_LOGIN +#define HPM_CORE_INCLUDE "../plugins/HPMHooking/HPMHooking_login.HPMHooksCore.inc" +#define HPM_SYMBOL_INCLUDE "../plugins/HPMHooking/HPMHooking_login.GetSymbol.inc" +#define HPM_HOOKS_INCLUDE "../plugins/HPMHooking/HPMHooking_login.Hooks.inc" +#define HPM_POINTS_INCLUDE "../plugins/HPMHooking/HPMHooking_login.HookingPoints.inc" +#define HPM_SOURCES_INCLUDE "../plugins/HPMHooking/HPMHooking_login.sources.inc" +#elif defined (HPMHOOKING_CHAR) +#define HPM_SERVER_TYPE SERVER_TYPE_CHAR +#define HPM_CORE_INCLUDE "../plugins/HPMHooking/HPMHooking_char.HPMHooksCore.inc" +#define HPM_SYMBOL_INCLUDE "../plugins/HPMHooking/HPMHooking_char.GetSymbol.inc" +#define HPM_HOOKS_INCLUDE "../plugins/HPMHooking/HPMHooking_char.Hooks.inc" +#define HPM_POINTS_INCLUDE "../plugins/HPMHooking/HPMHooking_char.HookingPoints.inc" +#define HPM_SOURCES_INCLUDE "../plugins/HPMHooking/HPMHooking_char.sources.inc" +#include "../char/pincode.h" +#elif defined (HPMHOOKING_MAP) +#define HPM_SERVER_TYPE SERVER_TYPE_MAP +#define HPM_CORE_INCLUDE "../plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc" +#define HPM_SYMBOL_INCLUDE "../plugins/HPMHooking/HPMHooking_map.GetSymbol.inc" +#define HPM_HOOKS_INCLUDE "../plugins/HPMHooking/HPMHooking_map.Hooks.inc" +#define HPM_POINTS_INCLUDE "../plugins/HPMHooking/HPMHooking_map.HookingPoints.inc" +#define HPM_SOURCES_INCLUDE "../plugins/HPMHooking/HPMHooking_map.sources.inc" #include "../map/atcommand.h" #include "../map/battle.h" #include "../map/battleground.h" @@ -44,13 +67,22 @@ #include "../map/storage.h" #include "../map/trade.h" #include "../map/unit.h" +#else +#define HPM_SERVER_TYPE SERVER_TYPE_UNKNOWN +#define HPM_CORE_INCLUDE "../plugins/HPMHooking/HPMHooking.HPMHooksCore.inc" +#define HPM_SYMBOL_INCLUDE "../plugins/HPMHooking/HPMHooking.GetSymbol.inc" +#define HPM_HOOKS_INCLUDE "../plugins/HPMHooking/HPMHooking.Hooks.inc" +#define HPM_POINTS_INCLUDE "../plugins/HPMHooking/HPMHooking.HookingPoints.inc" +#define HPM_SOURCES_INCLUDE "../plugins/HPMHooking/HPMHooking.sources.inc" +#error HPMHooking plugin needs to be compiled for a specific server type. Please make sure your Makefiles are up to date. +#endif #include "../common/HPMDataCheck.h" HPExport struct hplugin_info pinfo = { "HPMHooking", // Plugin name - SERVER_TYPE_MAP,// Which server types this plugin works with? - "0.1", // Plugin version + HPM_SERVER_TYPE,// Which server types this plugin works with? + "0.2", // Plugin version HPM_VERSION, // HPM Version (don't change, macro is automatically updated) }; @@ -70,7 +102,7 @@ struct HPMHookPoint { }; struct HPMHooksCore { - #include "../plugins/HPMHooking/HPMHooking.HPMHooksCore.inc" + #include HPM_CORE_INCLUDE struct { int total; } data; @@ -89,7 +121,7 @@ HPExport bool Hooked (bool *fr) { HPMforce_return = fr; DB = GET_SYMBOL("DB"); iMalloc = GET_SYMBOL("iMalloc"); -#include "../plugins/HPMHooking/HPMHooking.GetSymbol.inc" +#include HPM_SYMBOL_INCLUDE HPM_HP_load(); return true; } @@ -127,7 +159,7 @@ HPExport bool HPM_Plugin_AddHook(enum HPluginHookType type, const char *target, return false; } -#include "../plugins/HPMHooking/HPMHooking.Hooks.inc" +#include HPM_HOOKS_INCLUDE void HPM_HP_final(void) { int i, len = HPMHooks.data.total * 2; @@ -149,7 +181,7 @@ void HPM_HP_final(void) { } void HPM_HP_load(void) { - #include "../plugins/HPMHooking/HPMHooking.HookingPoints.inc" + #include HPM_POINTS_INCLUDE int i, len = ARRAYLENGTH(HookingPoints), idx = 0; memset(&HPMHooks,0,sizeof(struct HPMHooksCore)); @@ -171,6 +203,6 @@ void HPM_HP_load(void) { HPMHooks.data.total++; } - #include "../plugins/HPMHooking/HPMHooking.sources.inc" + #include HPM_SOURCES_INCLUDE } diff --git a/src/plugins/HPMHooking/HPMHooking_char.GetSymbol.inc b/src/plugins/HPMHooking/HPMHooking_char.GetSymbol.inc new file mode 100644 index 000000000..84800ca49 --- /dev/null +++ b/src/plugins/HPMHooking/HPMHooking_char.GetSymbol.inc @@ -0,0 +1,7 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// +// NOTE: This file was auto-generated and should never be manually edited, +// as it will get overwritten. + +if( !(pincode = GET_SYMBOL("pincode") ) ) return false; diff --git a/src/plugins/HPMHooking/HPMHooking_char.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_char.HPMHooksCore.inc new file mode 100644 index 000000000..4a940739f --- /dev/null +++ b/src/plugins/HPMHooking/HPMHooking_char.HPMHooksCore.inc @@ -0,0 +1,55 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// +// NOTE: This file was auto-generated and should never be manually edited, +// as it will get overwritten. + +struct { + struct HPMHookPoint *HP_pincode_handle_pre; + struct HPMHookPoint *HP_pincode_handle_post; + struct HPMHookPoint *HP_pincode_decrypt_pre; + struct HPMHookPoint *HP_pincode_decrypt_post; + struct HPMHookPoint *HP_pincode_error_pre; + struct HPMHookPoint *HP_pincode_error_post; + struct HPMHookPoint *HP_pincode_update_pre; + struct HPMHookPoint *HP_pincode_update_post; + struct HPMHookPoint *HP_pincode_sendstate_pre; + struct HPMHookPoint *HP_pincode_sendstate_post; + struct HPMHookPoint *HP_pincode_setnew_pre; + struct HPMHookPoint *HP_pincode_setnew_post; + struct HPMHookPoint *HP_pincode_change_pre; + struct HPMHookPoint *HP_pincode_change_post; + struct HPMHookPoint *HP_pincode_compare_pre; + struct HPMHookPoint *HP_pincode_compare_post; + struct HPMHookPoint *HP_pincode_check_pre; + struct HPMHookPoint *HP_pincode_check_post; + struct HPMHookPoint *HP_pincode_config_read_pre; + struct HPMHookPoint *HP_pincode_config_read_post; +} list; + +struct { + int HP_pincode_handle_pre; + int HP_pincode_handle_post; + int HP_pincode_decrypt_pre; + int HP_pincode_decrypt_post; + int HP_pincode_error_pre; + int HP_pincode_error_post; + int HP_pincode_update_pre; + int HP_pincode_update_post; + int HP_pincode_sendstate_pre; + int HP_pincode_sendstate_post; + int HP_pincode_setnew_pre; + int HP_pincode_setnew_post; + int HP_pincode_change_pre; + int HP_pincode_change_post; + int HP_pincode_compare_pre; + int HP_pincode_compare_post; + int HP_pincode_check_pre; + int HP_pincode_check_post; + int HP_pincode_config_read_pre; + int HP_pincode_config_read_post; +} count; + +struct { + struct pincode_interface pincode; +} source; diff --git a/src/plugins/HPMHooking/HPMHooking_char.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_char.HookingPoints.inc new file mode 100644 index 000000000..11c3b86a7 --- /dev/null +++ b/src/plugins/HPMHooking/HPMHooking_char.HookingPoints.inc @@ -0,0 +1,21 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// +// NOTE: This file was auto-generated and should never be manually edited, +// as it will get overwritten. + +struct HookingPointData HookingPoints[] = { +/* pincode */ + { HP_POP(pincode->handle, HP_pincode_handle) }, + { HP_POP(pincode->decrypt, HP_pincode_decrypt) }, + { HP_POP(pincode->error, HP_pincode_error) }, + { HP_POP(pincode->update, HP_pincode_update) }, + { HP_POP(pincode->sendstate, HP_pincode_sendstate) }, + { HP_POP(pincode->setnew, HP_pincode_setnew) }, + { HP_POP(pincode->change, HP_pincode_change) }, + { HP_POP(pincode->compare, HP_pincode_compare) }, + { HP_POP(pincode->check, HP_pincode_check) }, + { HP_POP(pincode->config_read, HP_pincode_config_read) }, +}; + +int HookingPointsLenMax = 20; diff --git a/src/plugins/HPMHooking/HPMHooking_char.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_char.Hooks.inc new file mode 100644 index 000000000..d795ebb4a --- /dev/null +++ b/src/plugins/HPMHooking/HPMHooking_char.Hooks.inc @@ -0,0 +1,269 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// +// NOTE: This file was auto-generated and should never be manually edited, +// as it will get overwritten. + +/* pincode */ +void HP_pincode_handle(int fd, struct char_session_data *sd) { + int hIndex = 0; + if( HPMHooks.count.HP_pincode_handle_pre ) { + void (*preHookFunc) (int *fd, struct char_session_data *sd); + *HPMforce_return = false; + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_handle_pre; hIndex++ ) { + preHookFunc = HPMHooks.list.HP_pincode_handle_pre[hIndex].func; + preHookFunc(&fd, sd); + } + if( *HPMforce_return ) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.pincode.handle(fd, sd); + } + if( HPMHooks.count.HP_pincode_handle_post ) { + void (*postHookFunc) (int *fd, struct char_session_data *sd); + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_handle_post; hIndex++ ) { + postHookFunc = HPMHooks.list.HP_pincode_handle_post[hIndex].func; + postHookFunc(&fd, sd); + } + } + return; +} +void HP_pincode_decrypt(unsigned int userSeed, char *pin) { + int hIndex = 0; + if( HPMHooks.count.HP_pincode_decrypt_pre ) { + void (*preHookFunc) (unsigned int *userSeed, char *pin); + *HPMforce_return = false; + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_decrypt_pre; hIndex++ ) { + preHookFunc = HPMHooks.list.HP_pincode_decrypt_pre[hIndex].func; + preHookFunc(&userSeed, pin); + } + if( *HPMforce_return ) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.pincode.decrypt(userSeed, pin); + } + if( HPMHooks.count.HP_pincode_decrypt_post ) { + void (*postHookFunc) (unsigned int *userSeed, char *pin); + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_decrypt_post; hIndex++ ) { + postHookFunc = HPMHooks.list.HP_pincode_decrypt_post[hIndex].func; + postHookFunc(&userSeed, pin); + } + } + return; +} +void HP_pincode_error(int account_id) { + int hIndex = 0; + if( HPMHooks.count.HP_pincode_error_pre ) { + void (*preHookFunc) (int *account_id); + *HPMforce_return = false; + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_error_pre; hIndex++ ) { + preHookFunc = HPMHooks.list.HP_pincode_error_pre[hIndex].func; + preHookFunc(&account_id); + } + if( *HPMforce_return ) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.pincode.error(account_id); + } + if( HPMHooks.count.HP_pincode_error_post ) { + void (*postHookFunc) (int *account_id); + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_error_post; hIndex++ ) { + postHookFunc = HPMHooks.list.HP_pincode_error_post[hIndex].func; + postHookFunc(&account_id); + } + } + return; +} +void HP_pincode_update(int account_id, char *pin) { + int hIndex = 0; + if( HPMHooks.count.HP_pincode_update_pre ) { + void (*preHookFunc) (int *account_id, char *pin); + *HPMforce_return = false; + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_update_pre; hIndex++ ) { + preHookFunc = HPMHooks.list.HP_pincode_update_pre[hIndex].func; + preHookFunc(&account_id, pin); + } + if( *HPMforce_return ) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.pincode.update(account_id, pin); + } + if( HPMHooks.count.HP_pincode_update_post ) { + void (*postHookFunc) (int *account_id, char *pin); + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_update_post; hIndex++ ) { + postHookFunc = HPMHooks.list.HP_pincode_update_post[hIndex].func; + postHookFunc(&account_id, pin); + } + } + return; +} +void HP_pincode_sendstate(int fd, struct char_session_data *sd, uint16 state) { + int hIndex = 0; + if( HPMHooks.count.HP_pincode_sendstate_pre ) { + void (*preHookFunc) (int *fd, struct char_session_data *sd, uint16 *state); + *HPMforce_return = false; + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_sendstate_pre; hIndex++ ) { + preHookFunc = HPMHooks.list.HP_pincode_sendstate_pre[hIndex].func; + preHookFunc(&fd, sd, &state); + } + if( *HPMforce_return ) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.pincode.sendstate(fd, sd, state); + } + if( HPMHooks.count.HP_pincode_sendstate_post ) { + void (*postHookFunc) (int *fd, struct char_session_data *sd, uint16 *state); + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_sendstate_post; hIndex++ ) { + postHookFunc = HPMHooks.list.HP_pincode_sendstate_post[hIndex].func; + postHookFunc(&fd, sd, &state); + } + } + return; +} +void HP_pincode_setnew(int fd, struct char_session_data *sd) { + int hIndex = 0; + if( HPMHooks.count.HP_pincode_setnew_pre ) { + void (*preHookFunc) (int *fd, struct char_session_data *sd); + *HPMforce_return = false; + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_setnew_pre; hIndex++ ) { + preHookFunc = HPMHooks.list.HP_pincode_setnew_pre[hIndex].func; + preHookFunc(&fd, sd); + } + if( *HPMforce_return ) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.pincode.setnew(fd, sd); + } + if( HPMHooks.count.HP_pincode_setnew_post ) { + void (*postHookFunc) (int *fd, struct char_session_data *sd); + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_setnew_post; hIndex++ ) { + postHookFunc = HPMHooks.list.HP_pincode_setnew_post[hIndex].func; + postHookFunc(&fd, sd); + } + } + return; +} +void HP_pincode_change(int fd, struct char_session_data *sd) { + int hIndex = 0; + if( HPMHooks.count.HP_pincode_change_pre ) { + void (*preHookFunc) (int *fd, struct char_session_data *sd); + *HPMforce_return = false; + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_change_pre; hIndex++ ) { + preHookFunc = HPMHooks.list.HP_pincode_change_pre[hIndex].func; + preHookFunc(&fd, sd); + } + if( *HPMforce_return ) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.pincode.change(fd, sd); + } + if( HPMHooks.count.HP_pincode_change_post ) { + void (*postHookFunc) (int *fd, struct char_session_data *sd); + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_change_post; hIndex++ ) { + postHookFunc = HPMHooks.list.HP_pincode_change_post[hIndex].func; + postHookFunc(&fd, sd); + } + } + return; +} +int HP_pincode_compare(int fd, struct char_session_data *sd, char *pin) { + int hIndex = 0; + int retVal___ = 0; + if( HPMHooks.count.HP_pincode_compare_pre ) { + int (*preHookFunc) (int *fd, struct char_session_data *sd, char *pin); + *HPMforce_return = false; + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_compare_pre; hIndex++ ) { + preHookFunc = HPMHooks.list.HP_pincode_compare_pre[hIndex].func; + retVal___ = preHookFunc(&fd, sd, pin); + } + if( *HPMforce_return ) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.pincode.compare(fd, sd, pin); + } + if( HPMHooks.count.HP_pincode_compare_post ) { + int (*postHookFunc) (int retVal___, int *fd, struct char_session_data *sd, char *pin); + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_compare_post; hIndex++ ) { + postHookFunc = HPMHooks.list.HP_pincode_compare_post[hIndex].func; + retVal___ = postHookFunc(retVal___, &fd, sd, pin); + } + } + return retVal___; +} +void HP_pincode_check(int fd, struct char_session_data *sd) { + int hIndex = 0; + if( HPMHooks.count.HP_pincode_check_pre ) { + void (*preHookFunc) (int *fd, struct char_session_data *sd); + *HPMforce_return = false; + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_check_pre; hIndex++ ) { + preHookFunc = HPMHooks.list.HP_pincode_check_pre[hIndex].func; + preHookFunc(&fd, sd); + } + if( *HPMforce_return ) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.pincode.check(fd, sd); + } + if( HPMHooks.count.HP_pincode_check_post ) { + void (*postHookFunc) (int *fd, struct char_session_data *sd); + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_check_post; hIndex++ ) { + postHookFunc = HPMHooks.list.HP_pincode_check_post[hIndex].func; + postHookFunc(&fd, sd); + } + } + return; +} +bool HP_pincode_config_read(char *w1, char *w2) { + int hIndex = 0; + bool retVal___ = false; + if( HPMHooks.count.HP_pincode_config_read_pre ) { + bool (*preHookFunc) (char *w1, char *w2); + *HPMforce_return = false; + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_config_read_pre; hIndex++ ) { + preHookFunc = HPMHooks.list.HP_pincode_config_read_pre[hIndex].func; + retVal___ = preHookFunc(w1, w2); + } + if( *HPMforce_return ) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.pincode.config_read(w1, w2); + } + if( HPMHooks.count.HP_pincode_config_read_post ) { + bool (*postHookFunc) (bool retVal___, char *w1, char *w2); + for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_config_read_post; hIndex++ ) { + postHookFunc = HPMHooks.list.HP_pincode_config_read_post[hIndex].func; + retVal___ = postHookFunc(retVal___, w1, w2); + } + } + return retVal___; +} diff --git a/src/plugins/HPMHooking/HPMHooking_char.sources.inc b/src/plugins/HPMHooking/HPMHooking_char.sources.inc new file mode 100644 index 000000000..fd5d2d2bf --- /dev/null +++ b/src/plugins/HPMHooking/HPMHooking_char.sources.inc @@ -0,0 +1,7 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// +// NOTE: This file was auto-generated and should never be manually edited, +// as it will get overwritten. + +memcpy(&HPMHooks.source.pincode, pincode, sizeof(struct pincode_interface)); diff --git a/src/plugins/HPMHooking/HPMHooking_login.GetSymbol.inc b/src/plugins/HPMHooking/HPMHooking_login.GetSymbol.inc new file mode 100644 index 000000000..6dcfae29d --- /dev/null +++ b/src/plugins/HPMHooking/HPMHooking_login.GetSymbol.inc @@ -0,0 +1,6 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// +// NOTE: This file was auto-generated and should never be manually edited, +// as it will get overwritten. + diff --git a/src/plugins/HPMHooking/HPMHooking_login.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_login.HPMHooksCore.inc new file mode 100644 index 000000000..4c380b367 --- /dev/null +++ b/src/plugins/HPMHooking/HPMHooking_login.HPMHooksCore.inc @@ -0,0 +1,14 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// +// NOTE: This file was auto-generated and should never be manually edited, +// as it will get overwritten. + +struct { +} list; + +struct { +} count; + +struct { +} source; diff --git a/src/plugins/HPMHooking/HPMHooking_login.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_login.HookingPoints.inc new file mode 100644 index 000000000..6752a4324 --- /dev/null +++ b/src/plugins/HPMHooking/HPMHooking_login.HookingPoints.inc @@ -0,0 +1,10 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// +// NOTE: This file was auto-generated and should never be manually edited, +// as it will get overwritten. + +struct HookingPointData HookingPoints[] = { +}; + +int HookingPointsLenMax = 0; diff --git a/src/plugins/HPMHooking/HPMHooking_login.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_login.Hooks.inc new file mode 100644 index 000000000..6dcfae29d --- /dev/null +++ b/src/plugins/HPMHooking/HPMHooking_login.Hooks.inc @@ -0,0 +1,6 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// +// NOTE: This file was auto-generated and should never be manually edited, +// as it will get overwritten. + diff --git a/src/plugins/HPMHooking/HPMHooking_login.sources.inc b/src/plugins/HPMHooking/HPMHooking_login.sources.inc new file mode 100644 index 000000000..6dcfae29d --- /dev/null +++ b/src/plugins/HPMHooking/HPMHooking_login.sources.inc @@ -0,0 +1,6 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// +// NOTE: This file was auto-generated and should never be manually edited, +// as it will get overwritten. + diff --git a/src/plugins/HPMHooking/HPMHooking.GetSymbol.inc b/src/plugins/HPMHooking/HPMHooking_map.GetSymbol.inc index 8482b9f80..8482b9f80 100644 --- a/src/plugins/HPMHooking/HPMHooking.GetSymbol.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.GetSymbol.inc diff --git a/src/plugins/HPMHooking/HPMHooking.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc index 6054e9d9a..6054e9d9a 100644 --- a/src/plugins/HPMHooking/HPMHooking.HPMHooksCore.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc diff --git a/src/plugins/HPMHooking/HPMHooking.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc index e2f946f7e..e2f946f7e 100644 --- a/src/plugins/HPMHooking/HPMHooking.HookingPoints.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc diff --git a/src/plugins/HPMHooking/HPMHooking.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc index f47cf27f0..f47cf27f0 100644 --- a/src/plugins/HPMHooking/HPMHooking.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc diff --git a/src/plugins/HPMHooking/HPMHooking.sources.inc b/src/plugins/HPMHooking/HPMHooking_map.sources.inc index 53bb6bcad..53bb6bcad 100644 --- a/src/plugins/HPMHooking/HPMHooking.sources.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.sources.inc diff --git a/src/plugins/Makefile.in b/src/plugins/Makefile.in index 39f445319..7f94e6b67 100644 --- a/src/plugins/Makefile.in +++ b/src/plugins/Makefile.in @@ -24,10 +24,11 @@ MYPLUGINS = ######### DO NOT EDIT ANYTHING BELOW THIS LINE!!! ################## # All plugins in the src/plugins directory -ALLPLUGINS = $(basename $(wildcard *.c)) +HPMHOOKING = $(addprefix HPMHooking_, login char map) +ALLPLUGINS = $(filter-out HPMHooking, $(basename $(wildcard *.c))) $(HPMHOOKING) # Plugins that will be built through 'make plugins' or 'make all' -PLUGINS = sample db2sql HPMHooking $(MYPLUGINS) +PLUGINS = sample db2sql HPMHooking_map $(MYPLUGINS) COMMON_D = ../common COMMON_H = $(wildcard $(COMMON_D)/*.h) @@ -46,11 +47,14 @@ CC = @CC@ export CC ##################################################################### -.PHONY: all $(ALLPLUGINS) clean buildclean help +.PHONY: all $(ALLPLUGINS) HPMHooking clean buildclean help all: $(PLUGINS) Makefile $(ALLPLUGINS): %: ../../plugins/%@DLLEXT@ + @echo " PLUGIN $@" + +HPMHooking: $(HPMHOOKING) buildclean: @echo " CLEAN plugins (build temp files)" @@ -81,3 +85,11 @@ Makefile: Makefile.in ../../plugins/%@DLLEXT@: %.c $(ALL_H) $$(shell ls %/* 2>/dev/null) @echo " CC $<" @$(CC) @PLUGINSTATIC@ @DEFS@ @CFLAGS@ @CPPFLAGS@ @LDFLAGS@ @SOFLAGS@ -o $@ $< + +../../plugins/HPMHooking_login@DLLEXT@: HPMHOOKINGTYPE = LOGIN +../../plugins/HPMHooking_char@DLLEXT@: HPMHOOKINGTYPE = CHAR +../../plugins/HPMHooking_map@DLLEXT@: HPMHOOKINGTYPE = MAP + +../../plugins/HPMHooking_%@DLLEXT@: HPMHooking.c $(ALL_H) $$(shell ls HPMHooking/*_%* HPMHooking/*_common* 2>/dev/null) + @echo " CC $< ($(HPMHOOKINGTYPE))" + @$(CC) -DHPMHOOKING_$(HPMHOOKINGTYPE) @PLUGINSTATIC@ @DEFS@ @CFLAGS@ @CPPFLAGS@ @LDFLAGS@ @SOFLAGS@ -o $@ $< diff --git a/tools/HPMHookGen/HPMHookGen.pl b/tools/HPMHookGen/HPMHookGen.pl index 3e2a11e5d..fa5bd1150 100755 --- a/tools/HPMHookGen/HPMHookGen.pl +++ b/tools/HPMHookGen/HPMHookGen.pl @@ -250,14 +250,19 @@ sub parse($$) { my %key2original; my @files = grep { -f } glob 'doxyoutput/xml/*interface*.xml'; my %ifs; -my @keys; +my %keys = ( + login => [ ], + char => [ ], + map => [ ], +); foreach my $file (@files) { # Loop through the xml files my $xml = new XML::Simple; my $data = $xml->XMLin($file); my $loc = $data->{compounddef}->{location}; - next unless $loc->{file} =~ /src\/map\//; # We only handle mapserver for the time being + next unless $loc->{file} =~ /src\/(map|char|login)\//; + my $servertype = $1; my $key = $data->{compounddef}->{compoundname}; my $original = $key; @@ -370,25 +375,27 @@ foreach my $file (@files) { # Loop through the xml files push(@{ $ifs{$key} }, $if); } } - push(@keys, $key) if $key2original{$key}; + push($keys{$servertype}, $key) if $key2original{$key}; } -# Some interfaces use different names -my %exportsymbols = map { - $_ => &{ sub ($) { - return 'battlegrounds' if $_ =~ /^bg$/; - return 'pc_groups' if $_ =~ /^pcg$/; - return $_; - }}($_); -} @keys; - -my ($maxlen, $idx) = (0, 0); -my $fname; -$fname = "../../src/plugins/HPMHooking/HPMHooking.HookingPoints.inc"; -open(FH, ">", $fname) - or die "cannot open > $fname: $!"; - -print FH <<"EOF"; +foreach my $servertype (keys %keys) { + my $keysref = $keys{$servertype}; + # Some interfaces use different names + my %exportsymbols = map { + $_ => &{ sub ($) { + return 'battlegrounds' if $servertype eq 'map' and $_ =~ /^bg$/; + return 'pc_groups' if $servertype eq 'map' and $_ =~ /^pcg$/; + return $_; + }}($_); + } @$keysref; + + my ($maxlen, $idx) = (0, 0); + my $fname; + $fname = "../../src/plugins/HPMHooking/HPMHooking_${servertype}.HookingPoints.inc"; + open(FH, ">", $fname) + or die "cannot open > $fname: $!"; + + print FH <<"EOF"; // Copyright (c) Hercules Dev Team, licensed under GNU GPL. // See the LICENSE file // @@ -398,30 +405,30 @@ print FH <<"EOF"; struct HookingPointData HookingPoints[] = { EOF -foreach my $key (@keys) { - print FH "/* ".$key." */\n"; - foreach my $if (@{ $ifs{$key} }) { + foreach my $key (@$keysref) { + print FH "/* ".$key." */\n"; + foreach my $if (@{ $ifs{$key} }) { - print FH <<"EOF"; + print FH <<"EOF"; { HP_POP($key\->$if->{name}, $if->{hname}) }, EOF - $idx += 2; - $maxlen = length($key."->".$if->{name}) if( length($key."->".$if->{name}) > $maxlen ) + $idx += 2; + $maxlen = length($key."->".$if->{name}) if( length($key."->".$if->{name}) > $maxlen ) + } } -} -print FH <<"EOF"; + print FH <<"EOF"; }; int HookingPointsLenMax = $maxlen; EOF -close FH; + close FH; -$fname = "../../src/plugins/HPMHooking/HPMHooking.sources.inc"; -open(FH, ">", $fname) - or die "cannot open > $fname: $!"; + $fname = "../../src/plugins/HPMHooking/HPMHooking_${servertype}.sources.inc"; + open(FH, ">", $fname) + or die "cannot open > $fname: $!"; -print FH <<"EOF"; + print FH <<"EOF"; // Copyright (c) Hercules Dev Team, licensed under GNU GPL. // See the LICENSE file // @@ -429,19 +436,19 @@ print FH <<"EOF"; // as it will get overwritten. EOF -foreach my $key (@keys) { + foreach my $key (@$keysref) { - print FH <<"EOF"; + print FH <<"EOF"; memcpy(&HPMHooks.source.$key, $key, sizeof(struct $key2original{$key})); EOF -} -close FH; + } + close FH; -$fname = "../../src/plugins/HPMHooking/HPMHooking.GetSymbol.inc"; -open(FH, ">", $fname) - or die "cannot open > $fname: $!"; + $fname = "../../src/plugins/HPMHooking/HPMHooking_${servertype}.GetSymbol.inc"; + open(FH, ">", $fname) + or die "cannot open > $fname: $!"; -print FH <<"EOF"; + print FH <<"EOF"; // Copyright (c) Hercules Dev Team, licensed under GNU GPL. // See the LICENSE file // @@ -449,19 +456,19 @@ print FH <<"EOF"; // as it will get overwritten. EOF -foreach my $key (@keys) { + foreach my $key (@$keysref) { - print FH <<"EOF"; + print FH <<"EOF"; if( !($key = GET_SYMBOL("$exportsymbols{$key}") ) ) return false; EOF -} -close FH; + } + close FH; -$fname = "../../src/plugins/HPMHooking/HPMHooking.HPMHooksCore.inc"; -open(FH, ">", $fname) - or die "cannot open > $fname: $!"; + $fname = "../../src/plugins/HPMHooking/HPMHooking_${servertype}.HPMHooksCore.inc"; + open(FH, ">", $fname) + or die "cannot open > $fname: $!"; -print FH <<"EOF"; + print FH <<"EOF"; // Copyright (c) Hercules Dev Team, licensed under GNU GPL. // See the LICENSE file // @@ -471,53 +478,53 @@ print FH <<"EOF"; struct { EOF -foreach my $key (@keys) { - foreach my $if (@{ $ifs{$key} }) { + foreach my $key (@$keysref) { + foreach my $if (@{ $ifs{$key} }) { - print FH <<"EOF"; + print FH <<"EOF"; struct HPMHookPoint *$if->{hname}_pre; struct HPMHookPoint *$if->{hname}_post; EOF + } } -} -print FH <<"EOF"; + print FH <<"EOF"; } list; struct { EOF -foreach my $key (@keys) { - foreach my $if (@{ $ifs{$key} }) { + foreach my $key (@$keysref) { + foreach my $if (@{ $ifs{$key} }) { - print FH <<"EOF"; + print FH <<"EOF"; int $if->{hname}_pre; int $if->{hname}_post; EOF + } } -} -print FH <<"EOF"; + print FH <<"EOF"; } count; struct { EOF -foreach my $key (@keys) { + foreach my $key (@$keysref) { - print FH <<"EOF"; + print FH <<"EOF"; struct $key2original{$key} $key; EOF -} + } -print FH <<"EOF"; + print FH <<"EOF"; } source; EOF -close FH; + close FH; -$fname = "../../src/plugins/HPMHooking/HPMHooking.Hooks.inc"; -open(FH, ">", $fname) - or die "cannot open > $fname: $!"; + $fname = "../../src/plugins/HPMHooking/HPMHooking_${servertype}.Hooks.inc"; + open(FH, ">", $fname) + or die "cannot open > $fname: $!"; -print FH <<"EOF"; + print FH <<"EOF"; // Copyright (c) Hercules Dev Team, licensed under GNU GPL. // See the LICENSE file // @@ -525,27 +532,27 @@ print FH <<"EOF"; // as it will get overwritten. EOF -foreach my $key (@keys) { + foreach my $key (@$keysref) { - print FH <<"EOF"; + print FH <<"EOF"; /* $key */ EOF - foreach my $if (@{ $ifs{$key} }) { - my ($initialization, $beforeblock3, $beforeblock2, $afterblock3, $afterblock2, $retval) = ('', '', '', '', '', ''); + foreach my $if (@{ $ifs{$key} }) { + my ($initialization, $beforeblock3, $beforeblock2, $afterblock3, $afterblock2, $retval) = ('', '', '', '', '', ''); - unless ($if->{type} eq 'void') { - $initialization = "\n\t$if->{type} retVal___$if->{typeinit};"; - $initialization .= "\n\tmemset(&retVal___, '\\0', sizeof($if->{type}));" if $if->{memset}; - } + unless ($if->{type} eq 'void') { + $initialization = "\n\t$if->{type} retVal___$if->{typeinit};"; + $initialization .= "\n\tmemset(&retVal___, '\\0', sizeof($if->{type}));" if $if->{memset}; + } - $beforeblock3 .= "\n\t\t\t$_" foreach (@{ $if->{before} }); - $afterblock3 .= "\n\t\t\t$_" foreach (@{ $if->{after} }); - $beforeblock2 .= "\n\t\t$_" foreach (@{ $if->{before} }); - $afterblock2 .= "\n\t\t$_" foreach (@{ $if->{after} }); - $retval = ' retVal___' unless $if->{type} eq 'void'; + $beforeblock3 .= "\n\t\t\t$_" foreach (@{ $if->{before} }); + $afterblock3 .= "\n\t\t\t$_" foreach (@{ $if->{after} }); + $beforeblock2 .= "\n\t\t$_" foreach (@{ $if->{before} }); + $afterblock2 .= "\n\t\t$_" foreach (@{ $if->{after} }); + $retval = ' retVal___' unless $if->{type} eq 'void'; - print FH <<"EOF"; + print FH <<"EOF"; $if->{handlerdef} {$if->{notes} int hIndex = 0;${initialization} if( HPMHooks.count.$if->{hname}_pre ) { @@ -573,8 +580,8 @@ $if->{handlerdef} {$if->{notes} return$retval; } EOF + } } -} - -close FH; + close FH; +} |