summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIbrahim Zidan <brahem@aotsw.com>2019-04-18 14:43:03 +0200
committerIbrahim Zidan <brahem@aotsw.com>2019-04-18 17:01:57 +0200
commit4779a6137745f9ccad897b767ecfc9ff3bf5082e (patch)
treed815e24ae32ac7d5892188a91f5c36e7e388135a
parent4fcd9b9a3891f3538ecd8a073c3f0e1c5eb85f55 (diff)
downloadhercules-4779a6137745f9ccad897b767ecfc9ff3bf5082e.tar.gz
hercules-4779a6137745f9ccad897b767ecfc9ff3bf5082e.tar.bz2
hercules-4779a6137745f9ccad897b767ecfc9ff3bf5082e.tar.xz
hercules-4779a6137745f9ccad897b767ecfc9ff3bf5082e.zip
Restore the ability for HPM Hooks to hook to private interfaces
- Starting from 5db7c799055c6ae9c4463f6cf4c88a35597d5d31 the ability to hook to private interfaces was removed, this commit restores this ability by introducing two new macros specifically for this. - addHookPrePriv to add a pre-hook for private interface member - addHookPostPriv to add a post-hook for private interface member Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
-rw-r--r--src/plugins/HPMHooking.h10
-rw-r--r--src/plugins/sample.c23
2 files changed, 33 insertions, 0 deletions
diff --git a/src/plugins/HPMHooking.h b/src/plugins/HPMHooking.h
index 44970863c..f94dccac4 100644
--- a/src/plugins/HPMHooking.h
+++ b/src/plugins/HPMHooking.h
@@ -50,11 +50,21 @@ HPExport struct HPMHooking_interface HPMHooking_s;
HPMi->hooking->AddHook(HOOK_TYPE_PRE, #ifname "->" #funcname, (hook), HPMi->pid) \
)
+#define addHookPrePriv(ifname, funcname, hook) ( \
+ (void)((HPMHOOK_pre_PRIV__ ## ifname ## _ ## funcname)0 == (hook)), \
+ HPMi->hooking->AddHook(HOOK_TYPE_PRE, #ifname "->p->" #funcname, (hook), HPMi->pid) \
+ )
+
#define addHookPost(ifname, funcname, hook) ( \
(void)((HPMHOOK_post_ ## ifname ## _ ## funcname)0 == (hook)), \
HPMi->hooking->AddHook(HOOK_TYPE_POST, #ifname "->" #funcname, (hook), HPMi->pid) \
)
+#define addHookPostPriv(ifname, funcname, hook) ( \
+ (void)((HPMHOOK_post_PRIV__ ## ifname ## _ ## funcname)0 == (hook)), \
+ HPMi->hooking->AddHook(HOOK_TYPE_POST, #ifname "->p->" #funcname, (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->hooking->HookStop(__func__,HPMi->pid))
diff --git a/src/plugins/sample.c b/src/plugins/sample.c
index 7ad6794b3..da29bd837 100644
--- a/src/plugins/sample.c
+++ b/src/plugins/sample.c
@@ -26,6 +26,8 @@
#include "common/random.h"
#include "common/socket.h"
#include "common/strlib.h"
+#include "login/login.h"
+#include "login/lclif.p.h"
#include "map/clif.h"
#include "map/pc.h"
#include "map/script.h"
@@ -136,6 +138,19 @@ int my_pc_dropitem_post(int retVal, struct map_session_data *sd, int n, int amou
}
return 1;
}
+
+ /**
+ * pre-hook for lclif->p->parse_CA_CONNECT_INFO_CHANGED this is a private interface function and while in source it cannot be used
+ * outside of lclif.c since it's private, plugin can use it and hook to private interface functions if needed
+ * the pre-hook takes this currently unused packet and show a notice whenver a player sends it
+ **/
+enum parsefunc_rcode my_lclif_parse_CA_CONNECT_INFO_CHANGED_pre(int *fd, struct login_session_data **sd) __attribute__((nonnull(2)));
+enum parsefunc_rcode my_lclif_parse_CA_CONNECT_INFO_CHANGED_pre(int *fd, struct login_session_data **sd)
+{
+ ShowNotice("Player (AID: %d) has sent CA_CONNECT_INFO_CHANGED packet\n", (*sd)->account_id);
+ return PACKET_VALID;
+}
+
/*
* Key is the setting name in our example it's 'my_setting' while val is the value of it.
* this way you can manage more than one setting in one function instead of define multiable ones
@@ -212,6 +227,14 @@ HPExport void plugin_init (void) {
/* - by checking whether it was successful (retVal value) it allows for the originals conditions to take place */
addHookPost(pc, dropitem, my_pc_dropitem_post);
}
+
+ if (SERVER_TYPE == SERVER_TYPE_LOGIN) {
+ /**
+ * In this example we add a pre-hook to lclif->p->parse_CA_CONNECT_INFO_CHANGED
+ * It's similar to nomral hooks except it have it own hooking macros which ends with Priv
+ **/
+ addHookPrePriv(lclif, parse_CA_CONNECT_INFO_CHANGED, my_lclif_parse_CA_CONNECT_INFO_CHANGED_pre);
+ }
}
/* triggered when server starts loading, before any server-specific data is set */
HPExport void server_preinit(void)