From 8a7cd27875d26664b3a2101596e37a043b9510a8 Mon Sep 17 00:00:00 2001 From: slayercio Date: Tue, 18 Nov 2025 22:02:44 +0100 Subject: [PATCH] fix: hook registration fixes --- src/detail/fxn.hpp | 4 ++-- src/impl/fxn.cpp | 24 +++++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/detail/fxn.hpp b/src/detail/fxn.hpp index 12a7e54..50619b3 100644 --- a/src/detail/fxn.hpp +++ b/src/detail/fxn.hpp @@ -30,8 +30,8 @@ namespace fxn void RegisterNativeHandler(const NativeHash hash, const NativeHandler handler); public: - void RegisterNativeHook(const NativeHash hash, const NativeHook& hook); - void UnregisterNativeHook(const NativeHash hash); + size_t RegisterNativeHook(const NativeHash hash, const NativeHook& hook); + void UnregisterNativeHook(const NativeHash hash, size_t index); public: bool Invoke(fxn::NativeContext* context); diff --git a/src/impl/fxn.cpp b/src/impl/fxn.cpp index 2b6d282..c251562 100644 --- a/src/impl/fxn.cpp +++ b/src/impl/fxn.cpp @@ -105,14 +105,24 @@ namespace fxn m_NativeHandlers[hash] = handler; } - void RegisterNativeHook(const NativeHash hash, const NativeHook& hook) + size_t RegisterNativeHook(const NativeHash hash, const NativeHook& hook) { m_NativeHooks[hash].push_back(hook); + + return m_NativeHooks[hash].size() - 1; } - void UnregisterNativeHook(const NativeHash hash) + void UnregisterNativeHook(const NativeHash hash, std::size_t index) { - m_NativeHooks.erase(hash); + auto it = m_NativeHooks.find(hash); + if (it != m_NativeHooks.end()) + { + auto& hooks = it->second; + if (index < hooks.size()) + { + hooks.erase(hooks.begin() + index); + } + } } void DispatchNative(fxn::NativeContext* context, NativeHash hash) @@ -216,14 +226,14 @@ namespace fxn m_Impl->RegisterNativeHandler(hash, handler); } - void FxnManager::RegisterNativeHook(const NativeHash hash, const NativeHook& hook) + size_t FxnManager::RegisterNativeHook(const NativeHash hash, const NativeHook& hook) { - m_Impl->RegisterNativeHook(hash, hook); + return m_Impl->RegisterNativeHook(hash, hook); } - void FxnManager::UnregisterNativeHook(const NativeHash hash) + void FxnManager::UnregisterNativeHook(const NativeHash hash, size_t index) { - m_Impl->UnregisterNativeHook(hash); + m_Impl->UnregisterNativeHook(hash, index); } bool FxnManager::Invoke(fxn::NativeContext* context)