Fix crash in 'CClient::ActivatePlayer'

Set the persistence fields to 'ready' in 'CClient::ActivatePlayer', before executing the rest of the function. Previously, it was set in 'CVEngineServer::PersistenceAvailable', but this is too late. The function 'FairFight_Init' was actually 'CClient::ActivatePlayer', and thus it has been moved to the correct file, and the old file defining it previously has been removed.
This commit is contained in:
Kawe Mazidjatari 2023-05-15 17:19:18 +02:00
parent 9a9813512c
commit 552f5f750c
7 changed files with 50 additions and 54 deletions

View File

@ -21,7 +21,6 @@
//#include "engine/sys_dll.h"
#ifndef CLIENT_DLL
#include "game/server/ai_networkmanager.h"
#include "game/server/fairfight_impl.h"
#include "game/server/detour_impl.h"
#endif // !CLIENT_DLL
#include "rtech/rtech_game.h"
@ -345,9 +344,7 @@ void RuntimePtc_Init() /* .TEXT */
{
#ifndef DEDICATED
p_WASAPI_GetAudioDevice.Offset(0x410).FindPatternSelf("FF 15 ?? ?? 01 00", CMemory::Direction::DOWN, 100).Patch({ 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0xEB }); // CAL --> NOP | Disable debugger check when miles searches for audio device to allow attaching the debugger to the game upon launch.
#ifndef CLIENT_DLL
FairFight_Init.Offset(0x0).FindPatternSelf("0F 87", CMemory::Direction::DOWN, 200).Patch({ 0x0F, 0x85 }); // JA --> JNZ | Prevent 'FairFight' anti-cheat from initializing on the server by comparing RAX against 0x0 instead. Init will crash since the plugins aren't shipped.
#endif // !CLIENT_DLL
p_SQVM_CompileError.Offset(0x0).FindPatternSelf("41 B0 01", CMemory::Direction::DOWN, 400).Patch({ 0x41, 0xB0, 0x00 }); // MOV --> MOV | Set script error level to 0 (not severe): 'mov r8b, 0'.
p_SQVM_CompileError.Offset(0xE0).FindPatternSelf("E8", CMemory::Direction::DOWN, 200).Patch({ 0x90, 0x90, 0x90, 0x90, 0x90 }); // CAL --> NOP | TODO: causes errors on client script error. Research required (same function as soft error but that one doesn't crash).
#else

View File

@ -115,7 +115,6 @@
#include "game/server/ai_networkmanager.h"
#include "game/server/ai_utility.h"
#include "game/server/detour_impl.h"
#include "game/server/fairfight_impl.h"
#include "game/server/gameinterface.h"
#include "game/server/movehelper_server.h"
#include "game/server/physics_main.h"
@ -543,7 +542,6 @@ void DetourRegister() // Register detour classes to be searched and hooked.
REGISTER(VAI_Network);
REGISTER(VAI_NetworkManager);
REGISTER(VRecast);
REGISTER(VFairFight);
REGISTER(VServerGameDLL);
REGISTER(VMoveHelperServer);
REGISTER(VPhysics_Main); // REGISTER SERVER ONLY

View File

@ -310,11 +310,46 @@ void CClient::Disconnect(const Reputation_t nRepLvl, const char* szReason, ...)
}
}
//---------------------------------------------------------------------------------
// Purpose: activate player
// Input : *pClient -
//---------------------------------------------------------------------------------
void CClient::VActivatePlayer(CClient* pClient)
{
pClient->SetPersistenceState(PERSISTENCE::PERSISTENCE_READY); // Set the client instance to 'ready'.
int nUserID = pClient->GetUserID();
if (!g_ServerPlayer[nUserID].m_bPersistenceEnabled && sv_showconnecting->GetBool())
{
g_ServerPlayer[nUserID].m_bPersistenceEnabled = true;
CNetChan* pNetChan = pClient->GetNetChan();
DevMsg(eDLL_T::SERVER, "Enabled persistence for client #%d; channel %s(%s) ('%llu')\n",
nUserID, pNetChan->GetName(), pNetChan->GetAddress(), pClient->GetNucleusID());
} ///////////////////////////////////////////////////////////////////////
v_CClient_ActivatePlayer(pClient);
}
//---------------------------------------------------------------------------------
// Purpose: send a net message
// Input : *pMsg -
// bLocal -
// bForceReliable -
// bVoice -
//---------------------------------------------------------------------------------
bool CClient::SendNetMsg(CNetMessage* pMsg, char bLocal, bool bForceReliable, bool bVoice)
{
return v_CClient_SendNetMsg(this, pMsg, bLocal, bForceReliable, bVoice);
}
//---------------------------------------------------------------------------------
// Purpose: send a snapshot
// Input : *pClient -
// *pFrame -
// nTick -
// nTickAck -
//---------------------------------------------------------------------------------
void* CClient::VSendSnapshot(CClient* pClient, CClientFrame* pFrame, int nTick, int nTickAck)
{
return v_CClient_SendSnapshot(pClient, pFrame, nTick, nTickAck);

View File

@ -95,6 +95,7 @@ public:
public: // Hook statics:
static void VClear(CClient* pClient);
static void VActivatePlayer(CClient* pClient);
static bool VProcessStringCmd(CClient* pClient, NET_StringCmd* pMsg);
static void* VSendSnapshot(CClient* pClient, CClientFrame* pFrame, int nTick, int nTickAck);
@ -155,6 +156,9 @@ inline auto v_CClient_Disconnect = p_CClient_Disconnect.RCast<bool (*)(CClient*
inline CMemory p_CClient_Clear;
inline auto v_CClient_Clear = p_CClient_Clear.RCast<void (*)(CClient* pClient)>();
inline CMemory p_CClient_ActivatePlayer;
inline auto v_CClient_ActivatePlayer = p_CClient_ActivatePlayer.RCast<void (*)(CClient* pClient)>();
inline CMemory p_CClient_ProcessStringCmd;
inline auto v_CClient_ProcessStringCmd = p_CClient_ProcessStringCmd.RCast<bool (*)(CClient* pClient, NET_StringCmd* pMsg)>();
@ -175,6 +179,7 @@ class VClient : public IDetour
LogFunAdr("CClient::Connect", p_CClient_Connect.GetPtr());
LogFunAdr("CClient::Disconnect", p_CClient_Disconnect.GetPtr());
LogFunAdr("CClient::Clear", p_CClient_Clear.GetPtr());
LogFunAdr("CClient::ActivatePlayer", p_CClient_ActivatePlayer.GetPtr());
LogFunAdr("CClient::ProcessStringCmd", p_CClient_ProcessStringCmd.GetPtr());
LogFunAdr("CClient::SetSignonState", p_CClient_SetSignonState.GetPtr());
LogFunAdr("CClient::SendNetMsg", p_CClient_SendNetMsg.GetPtr());
@ -191,20 +196,23 @@ class VClient : public IDetour
#endif
p_CClient_Clear = g_GameDll.FindPatternSIMD("40 53 41 56 41 57 48 83 EC 20 48 8B D9 48 89 74");
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
p_CClient_ActivatePlayer = g_GameDll.FindPatternSIMD("40 53 57 41 57 48 83 EC 30 8B 81 ?? ?? ?? ??");
p_CClient_ProcessStringCmd = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 55 48 81 EC ?? ?? ?? ?? 49 8B D8");
p_CClient_SendNetMsg = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 57 41 56 41 57 48 83 EC 30 48 8B 05 ?? ?? ?? ?? 45 0F B6 F1");
p_CClient_SendSnapshot = g_GameDll.FindPatternSIMD("44 89 44 24 ?? 48 89 4C 24 ?? 55 53 56 57 41 55");
#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
p_CClient_ActivatePlayer = g_GameDll.FindPatternSIMD("40 53 48 83 EC 20 8B 81 B0 03 ?? ?? 48 8B D9 C6");
p_CClient_ProcessStringCmd = g_GameDll.FindPatternSIMD("48 89 6C 24 ?? 57 48 81 EC ?? ?? ?? ?? 48 8B 7A 20");
p_CClient_SendNetMsg = g_GameDll.FindPatternSIMD("40 53 55 56 57 41 56 48 83 EC 40 48 8B 05 ?? ?? ?? ??");
p_CClient_SendSnapshot = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 55 56 41 55 41 56 41 57 48 8D 6C 24 ??");
#endif // !GAMEDLL_S0 || !GAMEDLL_S1
p_CClient_SetSignonState = g_GameDll.FindPatternSIMD("48 8B C4 48 89 58 10 48 89 70 18 57 48 81 EC ?? ?? ?? ?? 0F 29 70 E8 8B F2");
v_CClient_Connect = p_CClient_Connect.RCast<bool (*)(CClient*, const char*, void*, bool, void*, char*, int)>(); /*48 89 5C 24 ?? 48 89 6C 24 ?? 56 57 41 56 48 83 EC 20 41 0F B6 E9*/
v_CClient_Disconnect = p_CClient_Disconnect.RCast<bool (*)(CClient*, const Reputation_t, const char*, ...)>(); /*48 8B C4 4C 89 40 18 4C 89 48 20 53 56 57 48 81 EC ?? ?? ?? ?? 83 B9 ?? ?? ?? ?? ?? 49 8B F8 8B F2*/
v_CClient_Clear = p_CClient_Clear.RCast<void (*)(CClient*)>(); /*40 53 41 56 41 57 48 83 EC 20 48 8B D9 48 89 74*/
v_CClient_ProcessStringCmd = p_CClient_ProcessStringCmd.RCast<bool (*)(CClient*, NET_StringCmd*)>(); /*48 89 6C 24 ?? 57 48 81 EC ?? ?? ?? ?? 48 8B 7A 20*/
v_CClient_Connect = p_CClient_Connect.RCast<bool (*)(CClient*, const char*, void*, bool, void*, char*, int)>();
v_CClient_Disconnect = p_CClient_Disconnect.RCast<bool (*)(CClient*, const Reputation_t, const char*, ...)>();
v_CClient_Clear = p_CClient_Clear.RCast<void (*)(CClient*)>();
v_CClient_ActivatePlayer = p_CClient_ActivatePlayer.RCast<void (*)(CClient* pClient)>();
v_CClient_ProcessStringCmd = p_CClient_ProcessStringCmd.RCast<bool (*)(CClient*, NET_StringCmd*)>();
v_CClient_SetSignonState = p_CClient_SetSignonState.RCast<bool (*)(CClient*, SIGNONSTATE)>();
v_CClient_SendNetMsg = p_CClient_SendNetMsg.RCast<bool (*)(CClient*, CNetMessage*, char, bool, bool)>();
v_CClient_SendSnapshot = p_CClient_SendSnapshot.RCast<void* (*)(CClient*, CClientFrame*, int, int)>();
@ -219,6 +227,7 @@ class VClient : public IDetour
{
DetourAttach((LPVOID*)&v_CClient_Clear, &CClient::VClear);
DetourAttach((LPVOID*)&v_CClient_Connect, &CClient::VConnect);
DetourAttach((LPVOID*)&v_CClient_ActivatePlayer, &CClient::VActivatePlayer);
DetourAttach((LPVOID*)&v_CClient_ProcessStringCmd, &CClient::VProcessStringCmd);
//DetourAttach((LPVOID*)&p_CClient_SendSnapshot, &CClient::VSendSnapshot);
}
@ -226,6 +235,7 @@ class VClient : public IDetour
{
DetourDetach((LPVOID*)&v_CClient_Clear, &CClient::VClear);
DetourDetach((LPVOID*)&v_CClient_Connect, &CClient::VConnect);
DetourDetach((LPVOID*)&v_CClient_ActivatePlayer, &CClient::VActivatePlayer);
DetourDetach((LPVOID*)&v_CClient_ProcessStringCmd, &CClient::VProcessStringCmd);
//DetourDetach((LPVOID*)&p_CClient_SendSnapshot, &CClient::VSendSnapshot);
}

View File

@ -4,10 +4,6 @@
//
//=============================================================================//
#include "core/stdafx.h"
#include "tier1/cvar.h"
#include "common/protocol.h"
#include "engine/client/client.h"
#include "vengineserver_impl.h"
//-----------------------------------------------------------------------------
@ -15,17 +11,6 @@
//-----------------------------------------------------------------------------
bool CVEngineServer::PersistenceAvailable(void* entidx, int clientidx)
{
CClient* pClient = g_pClient->GetClient(clientidx); // Get client instance.
pClient->SetPersistenceState(PERSISTENCE::PERSISTENCE_READY); // Set the client instance to 'ready'.
if (!g_ServerPlayer[clientidx].m_bPersistenceEnabled && sv_showconnecting->GetBool())
{
g_ServerPlayer[clientidx].m_bPersistenceEnabled = true;
CNetChan* pNetChan = pClient->GetNetChan();
DevMsg(eDLL_T::SERVER, "Enabled persistence for client #%d; channel %s(%s) ('%llu')\n",
clientidx, pNetChan->GetName(), pNetChan->GetAddress(), pClient->GetNucleusID());
}
///////////////////////////////////////////////////////////////////////////
return IVEngineServer__PersistenceAvailable(entidx, clientidx);
}

View File

@ -43,7 +43,6 @@ add_sources( SOURCE_GROUP "Server"
"server/detour_impl.h"
"server/entitylist.cpp"
"server/entitylist.h"
"server/fairfight_impl.h"
"server/gameinterface.cpp"
"server/gameinterface.h"
"server/movehelper_server.cpp"

View File

@ -1,28 +0,0 @@
#pragma once
//-------------------------------------------------------------------------
// RUNTIME: FAIRFIGHT
//-------------------------------------------------------------------------
inline CMemory FairFight_Init;
///////////////////////////////////////////////////////////////////////////////
class VFairFight : public IDetour
{
virtual void GetAdr(void) const
{
LogFunAdr("FairFight_Init", FairFight_Init.GetPtr());
}
virtual void GetFun(void) const
{
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
FairFight_Init = g_GameDll.FindPatternSIMD("40 53 57 41 57 48 83 EC 30 8B 81 ?? ?? ?? ??");
#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
FairFight_Init = g_GameDll.FindPatternSIMD("40 53 48 83 EC 20 8B 81 B0 03 ?? ?? 48 8B D9 C6");
#endif // 0x140303AE0 // 40 53 48 83 EC 20 8B 81 ? ? ? ? 48 8B D9 C6 81 ? ? ? ? ? //
}
virtual void GetVar(void) const { }
virtual void GetCon(void) const { }
virtual void Attach(void) const { }
virtual void Detach(void) const { }
};
///////////////////////////////////////////////////////////////////////////////