From 180691955935ed02b48efd93410c7742c5b194fa Mon Sep 17 00:00:00 2001 From: Yarukon <61296195+Yarukon@users.noreply.github.com> Date: Wed, 24 Jul 2024 14:26:41 +0800 Subject: [PATCH] Fix function hooking on windows (#529) --- src/core/function.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/core/function.cpp b/src/core/function.cpp index 235621184..58c990f25 100644 --- a/src/core/function.cpp +++ b/src/core/function.cpp @@ -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 { @@ -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(this->m_eReturnType)); +#ifdef _WIN32 + return new dyno::x64MsFastcall(ConvertArgsToDynoHook(m_Args), static_cast(this->m_eReturnType)); +#else + return new dyno::x64SystemVcall(ConvertArgsToDynoHook(m_Args), static_cast(this->m_eReturnType)); +#endif }); g_HookMap[hook] = this; hook->addCallback(dyno::HookType::Post, (dyno::HookHandler*)&HookHandler); @@ -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(this->m_eReturnType)); +#ifdef _WIN32 + return new dyno::x64MsFastcall(ConvertArgsToDynoHook(m_Args), static_cast(this->m_eReturnType)); +#else + return new dyno::x64SystemVcall(ConvertArgsToDynoHook(m_Args), static_cast(this->m_eReturnType)); +#endif }); g_HookMap[hook] = this; @@ -313,4 +324,4 @@ void ValveFunction::RemoveHook(CallbackT callable, bool post) { } } -} // namespace counterstrikesharp \ No newline at end of file +} // namespace counterstrikesharp