From a61eb7694df25a75f45502ed64b1536fda370c1d Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 21 Oct 2023 14:52:43 +0100 Subject: hooksystem: add callbackinfo struct and cancellable events --- src/managers/HookSystemManager.hpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/managers/HookSystemManager.hpp') diff --git a/src/managers/HookSystemManager.hpp b/src/managers/HookSystemManager.hpp index 66edd1c0..ca8e9006 100644 --- a/src/managers/HookSystemManager.hpp +++ b/src/managers/HookSystemManager.hpp @@ -12,7 +12,8 @@ #include "../plugins/PluginAPI.hpp" // global typedef for hooked functions. Passes itself as a ptr when called, and `data` additionally. -typedef std::function HOOK_CALLBACK_FN; + +typedef std::function HOOK_CALLBACK_FN; struct SCallbackFNPtr { HOOK_CALLBACK_FN* fn = nullptr; @@ -22,7 +23,17 @@ struct SCallbackFNPtr { #define EMIT_HOOK_EVENT(name, param) \ { \ static auto* const PEVENTVEC = g_pHookSystem->getVecForEvent(name); \ - g_pHookSystem->emit(PEVENTVEC, param); \ + SCallbackInfo info; \ + g_pHookSystem->emit(PEVENTVEC, info, param); \ + } + +#define EMIT_HOOK_EVENT_CANCELLABLE(name, param) \ + { \ + static auto* const PEVENTVEC = g_pHookSystem->getVecForEvent(name); \ + SCallbackInfo info; \ + g_pHookSystem->emit(PEVENTVEC, info, param); \ + if (info.cancelled) \ + return; \ } class CHookSystemManager { @@ -34,7 +45,7 @@ class CHookSystemManager { void hookStatic(const std::string& event, HOOK_CALLBACK_FN* fn, HANDLE handle = nullptr); void unhook(HOOK_CALLBACK_FN* fn); - void emit(const std::vector* callbacks, std::any data = 0); + void emit(const std::vector* callbacks, SCallbackInfo& info, std::any data = 0); std::vector* getVecForEvent(const std::string& event); bool m_bCurrentEventPlugin = false; -- cgit v1.2.3