summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-02-28 02:12:48 +0100
committerHaru <haru@dotalux.com>2016-04-30 15:57:45 +0200
commit1ec93281b66061f7f7cff509450299bdcbf813b4 (patch)
tree737a9b2ea7cf5bc1e64f521d3987ea2997b688f5 /src/common
parent1a2a4f1477ebddcaefd132c141f7bbf64b23f016 (diff)
downloadhercules-1ec93281b66061f7f7cff509450299bdcbf813b4.tar.gz
hercules-1ec93281b66061f7f7cff509450299bdcbf813b4.tar.bz2
hercules-1ec93281b66061f7f7cff509450299bdcbf813b4.tar.xz
hercules-1ec93281b66061f7f7cff509450299bdcbf813b4.zip
Moved HPMHooking-related definitions to plugins/HPMHooking.h
- Plugins that want to make use of the HPMHooking must now include "plugins/HPMHooking.h". Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/HPM.c40
-rw-r--r--src/common/HPM.h9
-rw-r--r--src/common/HPMi.h22
-rw-r--r--src/common/Makefile.in3
4 files changed, 37 insertions, 37 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index d3d050d27..02b675704 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -38,6 +38,7 @@
#include "common/timer.h"
#include "common/utils.h"
#include "common/nullpo.h"
+#include "plugins/HPMHooking.h"
#include <stdio.h>
#include <stdlib.h>
@@ -51,6 +52,7 @@ struct malloc_interface iMalloc_HPM;
struct malloc_interface *HPMiMalloc;
struct HPM_interface HPM_s;
struct HPM_interface *HPM;
+struct HPMHooking_core_interface HPMHooking_core_s;
/**
* (char*) data name -> (unsigned int) HPMDataCheck[] index
@@ -341,13 +343,13 @@ void hplugins_removeFromHPData(enum HPluginDataTypes type, uint32 pluginID, stru
/* TODO: add ability for tracking using pID for the upcoming runtime load/unload support. */
bool HPM_AddHook(enum HPluginHookType type, const char *target, void *hook, unsigned int pID)
{
- if (!HPM->hooking) {
+ if (!HPM->hooking->enabled) {
ShowError("HPM:AddHook Fail! '%s' tried to hook to '%s' but HPMHooking is disabled!\n",HPM->pid2name(pID),target);
return false;
}
/* search if target is a known hook point within 'common' */
/* if not check if a sub-hooking list is available (from the server) and run it by */
- if (HPM->addhook_sub && HPM->addhook_sub(type,target,hook,pID))
+ if (HPM->hooking->addhook_sub != NULL && HPM->hooking->addhook_sub(type,target,hook,pID))
return true;
ShowError("HPM:AddHook: unknown Hooking Point '%s'!\n",target);
@@ -358,12 +360,12 @@ bool HPM_AddHook(enum HPluginHookType type, const char *target, void *hook, unsi
void HPM_HookStop(const char *func, unsigned int pID)
{
/* track? */
- HPM->force_return = true;
+ HPM->hooking->force_return = true;
}
-bool HPM_HookStopped (void)
+bool HPM_HookStopped(void)
{
- return HPM->force_return;
+ return HPM->hooking->force_return;
}
/**
@@ -567,16 +569,20 @@ struct hplugin *hplugin_load(const char* filename) {
plugin->hpi->addToHPData = hplugins_addToHPData;
plugin->hpi->getFromHPData = hplugins_getFromHPData;
plugin->hpi->removeFromHPData = hplugins_removeFromHPData;
- plugin->hpi->AddHook = HPM_AddHook;
- plugin->hpi->HookStop = HPM_HookStop;
- plugin->hpi->HookStopped = HPM_HookStopped;
plugin->hpi->addArg = hpm_add_arg;
plugin->hpi->addConf = hplugins_addconf;
+ if ((plugin->hpi->hooking = plugin_import(plugin->dll, "HPMHooking_s", struct HPMHooking_interface *)) != NULL) {
+ plugin->hpi->hooking->AddHook = HPM_AddHook;
+ plugin->hpi->hooking->HookStop = HPM_HookStop;
+ plugin->hpi->hooking->HookStopped = HPM_HookStopped;
+ }
/* server specific */
if( HPM->load_sub )
HPM->load_sub(plugin);
- ShowStatus("HPM: Loaded plugin '"CL_WHITE"%s"CL_RESET"' (%s).\n", plugin->info->name, plugin->info->version);
+ ShowStatus("HPM: Loaded plugin '"CL_WHITE"%s"CL_RESET"' (%s)%s.\n",
+ plugin->info->name, plugin->info->version,
+ plugin->hpi->hooking != NULL ? " built with HPMHooking support" : "");
return plugin;
}
@@ -660,12 +666,13 @@ void hplugins_config_read(void) {
bool (*addhook_sub) (enum HPluginHookType type, const char *target, void *hook, unsigned int pID);
if ((func = plugin_import(plugin->dll, "Hooked",const char * (*)(bool *))) != NULL
&& (addhook_sub = plugin_import(plugin->dll, "HPM_Plugin_AddHook",bool (*)(enum HPluginHookType, const char *, void *, unsigned int))) != NULL) {
- const char *failed = func(&HPM->force_return);
+ const char *failed = func(&HPM->hooking->force_return);
if (failed) {
ShowError("HPM: failed to retrieve '%s' for '"CL_WHITE"%s"CL_RESET"'!\n", failed, plugin_name);
} else {
- HPM->hooking = true;
- HPM->addhook_sub = addhook_sub;
+ HPM->hooking->enabled = true;
+ HPM->hooking->addhook_sub = addhook_sub;
+ HPM->hooking->Hooked = func; // The purpose of this is type-checking 'func' at compile time.
}
}
}
@@ -1046,11 +1053,10 @@ void hpm_final(void)
void hpm_defaults(void)
{
HPM = &HPM_s;
+ HPM->hooking = &HPMHooking_core_s;
memset(&HPM->filenames, 0, sizeof(HPM->filenames));
VECTOR_INIT(HPM->cmdline_load_plugins);
- HPM->force_return = false;
- HPM->hooking = false;
/* */
HPM->init = hpm_init;
HPM->final = hpm_final;
@@ -1067,7 +1073,6 @@ void hpm_defaults(void)
HPM->pid2name = hplugins_id2name;
HPM->parse_packets = hplugins_parse_packets;
HPM->load_sub = NULL;
- HPM->addhook_sub = NULL;
HPM->parseConf = hplugins_parse_conf;
HPM->getBattleConf = hplugins_get_battle_conf;
HPM->DataCheck = HPM_DataCheck;
@@ -1078,4 +1083,9 @@ void hpm_defaults(void)
HPM->data_store_create = hplugin_data_store_create;
HPM->data_store_validate = hplugin_data_store_validate;
HPM->data_store_validate_sub = NULL;
+
+ HPM->hooking->enabled = false;
+ HPM->hooking->force_return = false;
+ HPM->hooking->addhook_sub = NULL;
+ HPM->hooking->Hooked = NULL;
}
diff --git a/src/common/HPM.h b/src/common/HPM.h
index 109549aad..0b1275fde 100644
--- a/src/common/HPM.h
+++ b/src/common/HPM.h
@@ -65,6 +65,8 @@
#endif // WIN32
+struct HPMHooking_core_interface;
+
struct hplugin {
DLL dll;
unsigned int idx;
@@ -126,9 +128,6 @@ struct HPM_interface {
/* vars */
unsigned int version[2];
bool off;
- bool hooking;
- /* hooking */
- bool force_return;
/* data */
VECTOR_DECL(struct hplugin *) plugins;
VECTOR_DECL(struct hpm_symbol *) symbols;
@@ -159,7 +158,6 @@ struct HPM_interface {
char *(*pid2name) (unsigned int pid);
unsigned char (*parse_packets) (int fd, int packet_id, enum HPluginPacketHookingPoints point);
void (*load_sub) (struct hplugin *plugin);
- bool (*addhook_sub) (enum HPluginHookType type, const char *target, void *hook, unsigned int pID);
/* for custom config parsing */
bool (*parseConf) (const char *w1, const char *w2, enum HPluginConfType point);
bool (*getBattleConf) (const char* w1, int *value);
@@ -173,6 +171,9 @@ struct HPM_interface {
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 **storeptr, bool initialize);
+
+ /* hooking */
+ struct HPMHooking_core_interface *hooking;
};
CMDLINEARG(loadplugin);
diff --git a/src/common/HPMi.h b/src/common/HPMi.h
index 72640b382..e16eb1d75 100644
--- a/src/common/HPMi.h
+++ b/src/common/HPMi.h
@@ -25,6 +25,7 @@
#include "common/core.h"
#include "common/showmsg.h"
+struct HPMHooking_interface;
struct Sql; // common/sql.h
struct script_state;
struct AtCommandInfo;
@@ -32,7 +33,7 @@ struct socket_data;
struct map_session_data;
struct hplugin_data_store;
-#define HPM_VERSION "1.1"
+#define HPM_VERSION "1.2"
#define HPM_ADDCONF_LENGTH 40
struct hplugin_info {
@@ -71,11 +72,6 @@ enum HPluginPacketHookingPoints {
hpPHP_MAX,
};
-enum HPluginHookType {
- HOOK_TYPE_PRE,
- HOOK_TYPE_POST,
-};
-
/**
* Data types for plugin custom data.
*/
@@ -107,13 +103,6 @@ enum HPluginConfType {
HPCT_MAX,
};
-#define addHookPre(tname,hook) (HPMi->AddHook(HOOK_TYPE_PRE,(tname),(hook),HPMi->pid))
-#define addHookPost(tname,hook) (HPMi->AddHook(HOOK_TYPE_POST,(tname),(hook),HPMi->pid))
-/* need better names ;/ */
-/* will not run the original function after pre-hook processing is complete (other hooks will run) */
-#define hookStop() (HPMi->HookStop(__func__,HPMi->pid))
-#define hookStopped() (HPMi->HookStopped())
-
#define addArg(name, param,func,help) (HPMi->addArg(HPMi->pid,(name),(param),(cmdline_arg_ ## func),(help)))
/* HPData handy redirects */
/* session[] */
@@ -231,10 +220,6 @@ struct HPMi_interface {
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 */
- bool (*AddHook) (enum HPluginHookType type, const char *target, void *hook, unsigned int pID);
- void (*HookStop) (const char *func, unsigned int pID);
- bool (*HookStopped) (void);
/* program --arg/-a */
bool (*addArg) (unsigned int pluginID, char *name, bool has_param, CmdlineExecFunc func, const char *help);
/* battle-config recv param */
@@ -243,6 +228,9 @@ struct HPMi_interface {
void (*addPCGPermission) (unsigned int pluginID, char *name, unsigned int *mask);
struct Sql *sql_handle;
+
+ /* Hooking */
+ struct HPMHooking_interface *hooking;
};
#ifdef HERCULES_CORE
#define HPM_SYMBOL(n, s) (HPM->share((s), (n)), true)
diff --git a/src/common/Makefile.in b/src/common/Makefile.in
index 4580f70b8..6e7ffa088 100644
--- a/src/common/Makefile.in
+++ b/src/common/Makefile.in
@@ -50,7 +50,8 @@ COMMON_C += console.c core.c memmgr.c socket.c
COMMON_H = atomic.h cbasetypes.h conf.h console.h core.h db.h des.h ers.h \
grfio.h hercules.h HPM.h HPMi.h memmgr.h mapindex.h md5calc.h \
mmo.h mutex.h nullpo.h random.h showmsg.h socket.h spinlock.h \
- sql.h strlib.h sysinfo.h thread.h timer.h utils.h winapi.h
+ sql.h strlib.h sysinfo.h thread.h timer.h utils.h winapi.h \
+ ../plugins/HPMHooking.h
COMMON_PH =
COMMON_SQL_OBJ = obj_sql/sql.o