Fix CS_TerminateRound calls & detour (#893)

This commit is contained in:
Michael Flaherty 2018-10-03 19:50:31 -07:00 committed by Nicholas Hastings
parent 7ed329c11f
commit fc14e37d0f
2 changed files with 66 additions and 9 deletions

View File

@ -126,7 +126,7 @@ DETOUR_DECL_MEMBER0(DetourWeaponPrice, int)
} }
#endif #endif
#if SOURCE_ENGINE != SE_CSGO || !defined(WIN32) #if SOURCE_ENGINE != SE_CSGO
DETOUR_DECL_MEMBER2(DetourTerminateRound, void, float, delay, int, reason) DETOUR_DECL_MEMBER2(DetourTerminateRound, void, float, delay, int, reason)
{ {
if (g_pIgnoreTerminateDetour) if (g_pIgnoreTerminateDetour)
@ -135,20 +135,31 @@ DETOUR_DECL_MEMBER2(DetourTerminateRound, void, float, delay, int, reason)
DETOUR_MEMBER_CALL(DetourTerminateRound)(delay, reason); DETOUR_MEMBER_CALL(DetourTerminateRound)(delay, reason);
return; return;
} }
#elif !defined(WIN32)
DETOUR_DECL_MEMBER4(DetourTerminateRound, void, float, delay, int, reason, int, unknown, int, unknown2)
{
if (g_pIgnoreTerminateDetour)
{
g_pIgnoreTerminateDetour = false;
DETOUR_MEMBER_CALL(DetourTerminateRound)(delay, reason, unknown, unknown2);
return;
}
#else #else
//Windows CSGO //Windows CSGO
//char __userpurge TerminateRound(int a1@<ecx>, float a2@<xmm1>, int *a3) //char __userpurge TerminateRound(int a1@<ecx>, float a2@<xmm1>, int *a3)
// a1 - this // a1 - this
// a2 - delay // a2 - delay
// a3 - reason // a3 - reason
DETOUR_DECL_MEMBER1(DetourTerminateRound, void, int, reason) // a4 - unknown
// a5 - unknown
DETOUR_DECL_MEMBER3(DetourTerminateRound, void, int, reason, int, unknown, int, unknown2)
{ {
float delay; float delay;
if (g_pIgnoreTerminateDetour) if (g_pIgnoreTerminateDetour)
{ {
g_pIgnoreTerminateDetour = false; g_pIgnoreTerminateDetour = false;
return DETOUR_MEMBER_CALL(DetourTerminateRound)(reason); return DETOUR_MEMBER_CALL(DetourTerminateRound)(reason, unknown, unknown2);
} }
//Save the delay //Save the delay
@ -178,11 +189,16 @@ DETOUR_DECL_MEMBER1(DetourTerminateRound, void, int, reason)
reason++; reason++;
#endif #endif
#if SOURCE_ENGINE != SE_CSGO || !defined(WIN32) #if SOURCE_ENGINE != SE_CSGO
if (result == Pl_Changed) if (result == Pl_Changed)
return DETOUR_MEMBER_CALL(DetourTerminateRound)(delay, reason); return DETOUR_MEMBER_CALL(DetourTerminateRound)(delay, reason);
return DETOUR_MEMBER_CALL(DetourTerminateRound)(orgdelay, orgreason); return DETOUR_MEMBER_CALL(DetourTerminateRound)(orgdelay, orgreason);
#elif !defined(WIN32)
if (result == Pl_Changed)
return DETOUR_MEMBER_CALL(DetourTerminateRound)(delay, reason, unknown, unknown2);
return DETOUR_MEMBER_CALL(DetourTerminateRound)(orgdelay, orgreason, unknown, unknown2);
#else #else
if (result == Pl_Changed) if (result == Pl_Changed)
{ {
@ -190,13 +206,13 @@ DETOUR_DECL_MEMBER1(DetourTerminateRound, void, int, reason)
{ {
movss xmm1, delay movss xmm1, delay
} }
return DETOUR_MEMBER_CALL(DetourTerminateRound)(reason); return DETOUR_MEMBER_CALL(DetourTerminateRound)(reason, unknown, unknown2);
} }
__asm __asm
{ {
movss xmm1, orgdelay movss xmm1, orgdelay
} }
return DETOUR_MEMBER_CALL(DetourTerminateRound)(orgreason); return DETOUR_MEMBER_CALL(DetourTerminateRound)(orgreason, unknown, unknown2);
#endif #endif
} }

View File

@ -314,17 +314,17 @@ static cell_t CS_TerminateRound(IPluginContext *pContext, const cell_t *params)
reason++; reason++;
#endif #endif
#if SOURCE_ENGINE != SE_CSGO || !defined(WIN32) #if SOURCE_ENGINE != SE_CSGO
static ICallWrapper *pWrapper = NULL; static ICallWrapper *pWrapper = NULL;
if (!pWrapper) if (!pWrapper)
{ {
REGISTER_NATIVE_ADDR("TerminateRound", REGISTER_NATIVE_ADDR("TerminateRound",
PassInfo pass[2]; \ PassInfo pass[2]; \
pass[0].flags = PASSFLAG_BYVAL; \ pass[0].flags = PASSFLAG_BYVAL; \ // delay
pass[0].type = PassType_Basic; \ pass[0].type = PassType_Basic; \
pass[0].size = sizeof(float); \ pass[0].size = sizeof(float); \
pass[1].flags = PASSFLAG_BYVAL; \ pass[1].flags = PASSFLAG_BYVAL; \ // reason
pass[1].type = PassType_Basic; \ pass[1].type = PassType_Basic; \
pass[1].size = sizeof(int); \ pass[1].size = sizeof(int); \
pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 2)) pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 2))
@ -342,6 +342,45 @@ static cell_t CS_TerminateRound(IPluginContext *pContext, const cell_t *params)
vptr += sizeof(float); vptr += sizeof(float);
*(int*)vptr = reason; *(int*)vptr = reason;
pWrapper->Execute(vstk, NULL);
#elif !defined(WIN32)
static ICallWrapper *pWrapper = NULL;
if (!pWrapper)
{
REGISTER_NATIVE_ADDR("TerminateRound",
PassInfo pass[4]; \
pass[0].flags = PASSFLAG_BYVAL; \ // delay
pass[0].type = PassType_Basic; \
pass[0].size = sizeof(float); \
pass[1].flags = PASSFLAG_BYVAL; \ // reason
pass[1].type = PassType_Basic; \
pass[1].size = sizeof(int); \
pass[2].flags = PASSFLAG_BYVAL; \ // unknown
pass[2].type = PassType_Basic; \
pass[2].size = sizeof(int); \
pass[3].flags = PASSFLAG_BYVAL; \ // unknown2
pass[3].type = PassType_Basic; \
pass[3].size = sizeof(int); \
pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 4))
}
if (params[3] == 1 && g_pTerminateRoundDetoured)
g_pIgnoreTerminateDetour = true;
unsigned char vstk[sizeof(void *) + sizeof(float)+ sizeof(int)];
unsigned char *vptr = vstk;
*(void **)vptr = gamerules;
vptr += sizeof(void *);
*(float *)vptr = sp_ctof(params[1]);
vptr += sizeof(float);
*(int*)vptr = reason;
vptr += sizeof(int);
*(int*)vptr = 0;
vptr += sizeof(int);
*(int*)vptr = 0;
pWrapper->Execute(vstk, NULL); pWrapper->Execute(vstk, NULL);
#else #else
static void *addr = NULL; static void *addr = NULL;
@ -358,6 +397,8 @@ static cell_t CS_TerminateRound(IPluginContext *pContext, const cell_t *params)
__asm __asm
{ {
push 0
push 0
push reason push reason
movss xmm1, delay movss xmm1, delay
mov ecx, gamerules mov ecx, gamerules