From 552f5f750cb480709d96c3dad07172627a6a78ad Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Mon, 15 May 2023 17:19:18 +0200 Subject: [PATCH] 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. --- r5dev/common/opcodes.cpp | 5 +--- r5dev/core/init.cpp | 2 -- r5dev/engine/client/client.cpp | 35 ++++++++++++++++++++++ r5dev/engine/client/client.h | 18 ++++++++--- r5dev/engine/server/vengineserver_impl.cpp | 15 ---------- r5dev/game/CMakeLists.txt | 1 - r5dev/game/server/fairfight_impl.h | 28 ----------------- 7 files changed, 50 insertions(+), 54 deletions(-) delete mode 100644 r5dev/game/server/fairfight_impl.h diff --git a/r5dev/common/opcodes.cpp b/r5dev/common/opcodes.cpp index fc822a50..95452066 100644 --- a/r5dev/common/opcodes.cpp +++ b/r5dev/common/opcodes.cpp @@ -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 diff --git a/r5dev/core/init.cpp b/r5dev/core/init.cpp index 6c134d1a..6cf97064 100644 --- a/r5dev/core/init.cpp +++ b/r5dev/core/init.cpp @@ -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 diff --git a/r5dev/engine/client/client.cpp b/r5dev/engine/client/client.cpp index a9af2893..1fa308ae 100644 --- a/r5dev/engine/client/client.cpp +++ b/r5dev/engine/client/client.cpp @@ -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); diff --git a/r5dev/engine/client/client.h b/r5dev/engine/client/client.h index 9aabb31d..0b29f431 100644 --- a/r5dev/engine/client/client.h +++ b/r5dev/engine/client/client.h @@ -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(); +inline CMemory p_CClient_ActivatePlayer; +inline auto v_CClient_ActivatePlayer = p_CClient_ActivatePlayer.RCast(); + inline CMemory p_CClient_ProcessStringCmd; inline auto v_CClient_ProcessStringCmd = p_CClient_ProcessStringCmd.RCast(); @@ -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(); /*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(); /*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(); /*40 53 41 56 41 57 48 83 EC 20 48 8B D9 48 89 74*/ - v_CClient_ProcessStringCmd = p_CClient_ProcessStringCmd.RCast(); /*48 89 6C 24 ?? 57 48 81 EC ?? ?? ?? ?? 48 8B 7A 20*/ + v_CClient_Connect = p_CClient_Connect.RCast(); + v_CClient_Disconnect = p_CClient_Disconnect.RCast(); + v_CClient_Clear = p_CClient_Clear.RCast(); + v_CClient_ActivatePlayer = p_CClient_ActivatePlayer.RCast(); + v_CClient_ProcessStringCmd = p_CClient_ProcessStringCmd.RCast(); v_CClient_SetSignonState = p_CClient_SetSignonState.RCast(); v_CClient_SendNetMsg = p_CClient_SendNetMsg.RCast(); v_CClient_SendSnapshot = p_CClient_SendSnapshot.RCast(); @@ -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); } diff --git a/r5dev/engine/server/vengineserver_impl.cpp b/r5dev/engine/server/vengineserver_impl.cpp index 8c4e768f..2865686e 100644 --- a/r5dev/engine/server/vengineserver_impl.cpp +++ b/r5dev/engine/server/vengineserver_impl.cpp @@ -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); } diff --git a/r5dev/game/CMakeLists.txt b/r5dev/game/CMakeLists.txt index 4998a7ff..1a669114 100644 --- a/r5dev/game/CMakeLists.txt +++ b/r5dev/game/CMakeLists.txt @@ -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" diff --git a/r5dev/game/server/fairfight_impl.h b/r5dev/game/server/fairfight_impl.h deleted file mode 100644 index 2498aaaf..00000000 --- a/r5dev/game/server/fairfight_impl.h +++ /dev/null @@ -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 { } -}; -///////////////////////////////////////////////////////////////////////////////