From 14fb7f7756ce942ffb72218eb79a5e49c843bc13 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Thu, 22 Dec 2016 04:17:57 +0700 Subject: [PATCH] Fix crash on hook(detour) ClientCommand from the cstrike module amxx --- regamedll/dlls/player.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 7586a94f..0c0462e8 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -8465,7 +8465,29 @@ void CBasePlayer::ClientCommand(const char *cmd, const char *arg1, const char *a BotArgs[3] = arg3; UseBotArgs = true; - ::ClientCommand(ENT(pev)); + + auto pEntity = ENT(pev); + auto addr = &::ClientCommand; + + // NOTE: force __cdecl to allow cstrike amxx module to hook ClientCommand +#if defined _MSC_VER || defined __INTEL_COMPILER + __asm + { + push pEntity; + call addr; + add esp, 4; + } +#else + asm volatile ( + "pushl %0\n\t" + "call %1\n\t" + "addl %%esp, $4\n\t" + :: + "g" (pEntity), + "g" (addr), + ); +#endif // _MSC_VER || defined __INTEL_COMPILER + UseBotArgs = false; }