summaryrefslogtreecommitdiff
path: root/src/managers/HookSystemManager.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2026-02-22 23:30:10 +0000
committerGitHub <noreply@github.com>2026-02-22 23:30:10 +0000
commitb88813c7efa4b7b0c5fe01471c5fa5b67a61dc7e (patch)
tree4454e82bc033d7e28a23ee372d0e3f48341d0aaa /src/managers/HookSystemManager.cpp
parentb4ee4674f9a74e3d602c7fb17bc09f79d221583c (diff)
event: refactor HookSystem into a typed event bus (#13333)
Refactors the old HookSystem into a typed event bus with clear separation, discovery and types.
Diffstat (limited to 'src/managers/HookSystemManager.cpp')
-rw-r--r--src/managers/HookSystemManager.cpp83
1 files changed, 0 insertions, 83 deletions
diff --git a/src/managers/HookSystemManager.cpp b/src/managers/HookSystemManager.cpp
deleted file mode 100644
index 0aa2d93e..00000000
--- a/src/managers/HookSystemManager.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-#include "HookSystemManager.hpp"
-
-#include "../plugins/PluginSystem.hpp"
-
-CHookSystemManager::CHookSystemManager() {
- ; //
-}
-
-// returns the pointer to the function
-SP<HOOK_CALLBACK_FN> CHookSystemManager::hookDynamic(const std::string& event, HOOK_CALLBACK_FN fn, HANDLE handle) {
- SP<HOOK_CALLBACK_FN> hookFN = makeShared<HOOK_CALLBACK_FN>(fn);
- m_registeredHooks[event].emplace_back(SCallbackFNPtr{.fn = hookFN, .handle = handle});
- return hookFN;
-}
-
-void CHookSystemManager::unhook(SP<HOOK_CALLBACK_FN> fn) {
- for (auto& [k, v] : m_registeredHooks) {
- std::erase_if(v, [&](const auto& other) {
- SP<HOOK_CALLBACK_FN> fn_ = other.fn.lock();
-
- return fn_.get() == fn.get();
- });
- }
-}
-
-void CHookSystemManager::emit(std::vector<SCallbackFNPtr>* const callbacks, SCallbackInfo& info, std::any data) {
- if (callbacks->empty())
- return;
-
- std::vector<HANDLE> faultyHandles;
- volatile bool needsDeadCleanup = false;
-
- for (auto const& cb : *callbacks) {
-
- m_currentEventPlugin = false;
-
- if (!cb.handle) {
- // we don't guard hl hooks
-
- if (SP<HOOK_CALLBACK_FN> fn = cb.fn.lock())
- (*fn)(fn.get(), info, data);
- else
- needsDeadCleanup = true;
- continue;
- }
-
- m_currentEventPlugin = true;
-
- if (std::ranges::find(faultyHandles, cb.handle) != faultyHandles.end())
- continue;
-
- try {
- if (!setjmp(m_hookFaultJumpBuf)) {
- if (SP<HOOK_CALLBACK_FN> fn = cb.fn.lock())
- (*fn)(fn.get(), info, data);
- else
- needsDeadCleanup = true;
- } else {
- // this module crashed.
- throw std::exception();
- }
- } catch (std::exception& e) {
- // TODO: this works only once...?
- faultyHandles.push_back(cb.handle);
- Log::logger->log(Log::ERR, "[hookSystem] Hook from plugin {:x} caused a SIGSEGV, queueing for unloading.", rc<uintptr_t>(cb.handle));
- }
- }
-
- if (needsDeadCleanup)
- std::erase_if(*callbacks, [](const auto& fn) { return !fn.fn.lock(); });
-
- if (!faultyHandles.empty()) {
- for (auto const& h : faultyHandles)
- g_pPluginSystem->unloadPlugin(g_pPluginSystem->getPluginByHandle(h), true);
- }
-}
-
-std::vector<SCallbackFNPtr>* CHookSystemManager::getVecForEvent(const std::string& event) {
- if (!m_registeredHooks.contains(event))
- Log::logger->log(Log::DEBUG, "[hookSystem] New hook event registered: {}", event);
-
- return &m_registeredHooks[event];
-}