Skip to content

Commit 5e3d83e

Browse files
committed
fix(hooks): Not calling the callbacks
1 parent 6a997be commit 5e3d83e

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

src/memory/hooks/functions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ void FunctionHook::Initialize()
6161
hookFunc->addCallback(m_callbackType, m_handler);
6262
}
6363

64+
dyno::IHook* FunctionHook::GetHookFunction()
65+
{
66+
if (!m_pfn) return nullptr;
67+
68+
dyno::IHookManager& manager = dyno::IHookManager::Get();
69+
return manager.findDetour(m_pfn).get();
70+
}
71+
6472
extern bool shuttingDown;
6573

6674
FunctionHook::~FunctionHook()

src/memory/hooks/functions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class FunctionHook
4444
void Enable();
4545
void Disable();
4646

47+
dyno::IHook* GetHookFunction();
48+
4749
std::any Call(std::vector<std::any> arguments);
4850
};
4951

src/memory/hooks/vfunctions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ void VFunctionHook::Initialize()
5555
hookFunc->addCallback(m_callbackType, m_handler);
5656
}
5757

58+
dyno::IHook* VFunctionHook::GetHookFunction()
59+
{
60+
if (!m_pvtable) return nullptr;
61+
62+
dyno::IHookManager& manager = dyno::IHookManager::Get();
63+
return manager.findVirtual(m_pvtable, m_ioffset).get();
64+
}
65+
5866
void VFunctionHook::Enable()
5967
{
6068
if (enabled) return;

src/memory/hooks/vfunctions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class VFunctionHook
4747
void Enable();
4848
void Disable();
4949

50+
dyno::IHook* GetHookFunction();
51+
5052
std::any Call(std::vector<std::any> arguments);
5153
};
5254

src/scripting/memory/hooks.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ std::map<uint64_t, std::vector<std::string>> outputHooksList;
6868

6969
dyno::ReturnAction HookCallback(dyno::CallbackType type, dyno::IHook& hook) {
7070
dyno::IHook* hptr = &hook;
71+
7172
std::string callbackType = (type == dyno::CallbackType::Pre ? "Pre" : "Post");
7273
if (hooksList.find(hptr) == hooksList.end())
7374
return dyno::ReturnAction::Ignored;
7475

7576
ClassData* ev = new ClassData({ { "plugin_name", std::string("core") }, { "hook_ptr", hptr } }, "Event", nullptr);
7677
for (auto hk : hooksList[hptr])
7778
{
79+
printf("Hook called: %s\n", hk.id.c_str());
7880
if (g_pluginManager.ExecuteEvent("core", "hook:" + callbackType + ":" + hk.id, {}, ev) != EventResult::Continue) {
7981
delete ev;
8082
return dyno::ReturnAction::Supercede;
@@ -202,6 +204,9 @@ LoadScriptingComponent(hooks, [](PluginObject plugin, EContext* ctx) -> void {
202204
false
203205
};
204206

207+
auto foundhook = ((FunctionHook*)(hk.hookPtrPre))->GetHookFunction();
208+
hooksList[foundhook].push_back(hk);
209+
205210
std::vector<Hook> hookArr = data->GetData<std::vector<Hook>>("hooks_arr");
206211
hookArr.push_back(hk);
207212
data->SetData("hooks_arr", hookArr);
@@ -227,6 +232,9 @@ LoadScriptingComponent(hooks, [](PluginObject plugin, EContext* ctx) -> void {
227232
true
228233
};
229234

235+
auto foundhook = ((VFunctionHook*)(hk.hookPtrPre))->GetHookFunction();
236+
hooksList[foundhook].push_back(hk);
237+
230238
std::vector<Hook> hookArr = data->GetData<std::vector<Hook>>("hooks_arr");
231239
hookArr.push_back(hk);
232240
data->SetData("hooks_arr", hookArr);

0 commit comments

Comments
 (0)