Skip to content

Commit

Permalink
Fix function hooking on windows (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yarukon authored Jul 24, 2024
1 parent f8451c2 commit 1806919
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/core/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@
#include "pch.h"
#include "dynohook/core.h"
#include "dynohook/manager.h"

#ifdef _WIN32
#include "dynohook/conventions/x64/x64MsFastcall.h"
#else
#include "dynohook/conventions/x64/x64SystemVcall.h"
#endif

namespace counterstrikesharp {

Expand Down Expand Up @@ -275,8 +280,11 @@ void ValveFunction::AddHook(CallbackT callable, bool post)
{
dyno::HookManager& manager = dyno::HookManager::Get();
dyno::Hook* hook = manager.hook((void*)m_ulAddr, [this] {
return new dyno::x64SystemVcall(ConvertArgsToDynoHook(m_Args),
static_cast<dyno::DataType>(this->m_eReturnType));
#ifdef _WIN32
return new dyno::x64MsFastcall(ConvertArgsToDynoHook(m_Args), static_cast<dyno::DataType>(this->m_eReturnType));
#else
return new dyno::x64SystemVcall(ConvertArgsToDynoHook(m_Args), static_cast<dyno::DataType>(this->m_eReturnType));
#endif
});
g_HookMap[hook] = this;
hook->addCallback(dyno::HookType::Post, (dyno::HookHandler*)&HookHandler);
Expand All @@ -297,8 +305,11 @@ void ValveFunction::AddHook(CallbackT callable, bool post)
void ValveFunction::RemoveHook(CallbackT callable, bool post) {
dyno::HookManager& manager = dyno::HookManager::Get();
dyno::Hook* hook = manager.hook((void*)m_ulAddr, [this] {
return new dyno::x64SystemVcall(ConvertArgsToDynoHook(m_Args),
static_cast<dyno::DataType>(this->m_eReturnType));
#ifdef _WIN32
return new dyno::x64MsFastcall(ConvertArgsToDynoHook(m_Args), static_cast<dyno::DataType>(this->m_eReturnType));
#else
return new dyno::x64SystemVcall(ConvertArgsToDynoHook(m_Args), static_cast<dyno::DataType>(this->m_eReturnType));
#endif
});
g_HookMap[hook] = this;

Expand All @@ -313,4 +324,4 @@ void ValveFunction::RemoveHook(CallbackT callable, bool post) {
}
}

} // namespace counterstrikesharp
} // namespace counterstrikesharp

0 comments on commit 1806919

Please sign in to comment.