From 8b81f41e52b55835aaaa7e4962af23a00188cbdc Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Mon, 27 Feb 2023 12:32:38 +0000 Subject: Plugin System (#1590) --------- Co-authored-by: Mihai Fufezan --- src/managers/HookSystemManager.hpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/managers/HookSystemManager.hpp') diff --git a/src/managers/HookSystemManager.hpp b/src/managers/HookSystemManager.hpp index 57f1e58b..66edd1c0 100644 --- a/src/managers/HookSystemManager.hpp +++ b/src/managers/HookSystemManager.hpp @@ -4,11 +4,21 @@ #include #include +#include #include +#include + +#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; +struct SCallbackFNPtr { + HOOK_CALLBACK_FN* fn = nullptr; + HANDLE handle = nullptr; +}; + #define EMIT_HOOK_EVENT(name, param) \ { \ static auto* const PEVENTVEC = g_pHookSystem->getVecForEvent(name); \ @@ -20,17 +30,20 @@ class CHookSystemManager { CHookSystemManager(); // returns the pointer to the function - HOOK_CALLBACK_FN* hookDynamic(const std::string& event, HOOK_CALLBACK_FN fn); - void hookStatic(const std::string& event, HOOK_CALLBACK_FN* fn); - void unhook(HOOK_CALLBACK_FN* fn); + HOOK_CALLBACK_FN* hookDynamic(const std::string& event, HOOK_CALLBACK_FN fn, HANDLE handle = nullptr); + 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); + std::vector* getVecForEvent(const std::string& event); - void emit(const std::vector* callbacks, std::any data = 0); - std::vector* getVecForEvent(const std::string& event); + bool m_bCurrentEventPlugin = false; + jmp_buf m_jbHookFaultJumpBuf; private: // todo: this is slow. Maybe static ptrs should be somehow allowed. unique ptr for vec? - std::list>> m_lpRegisteredHooks; - std::list m_lCallbackFunctions; + std::list>> m_lpRegisteredHooks; + std::list m_lCallbackFunctions; }; inline std::unique_ptr g_pHookSystem; \ No newline at end of file -- cgit v1.2.3