From 77c2be57ec0c1180d8557cbc98d5ddac67174fc3 Mon Sep 17 00:00:00 2001 From: Amos <48657826+Mauler125@users.noreply.github.com> Date: Mon, 27 Dec 2021 02:06:03 +0100 Subject: [PATCH] Fix crash when setting persistence var in CClient struct --- r5dev/client/client.cpp | 2 +- r5dev/client/client.h | 3 ++- r5dev/server/IVEngineServer.cpp | 5 ++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/r5dev/client/client.cpp b/r5dev/client/client.cpp index 49d3d39e..2a0bc684 100644 --- a/r5dev/client/client.cpp +++ b/r5dev/client/client.cpp @@ -2,4 +2,4 @@ #include "client/client.h" /////////////////////////////////////////////////////////////////////////////// -CClient* g_pClient = reinterpret_cast(p_IVEngineServer_PersistenceAvailable.FindPatternSelf("48 8D 0D", ADDRESS::Direction::DOWN, 150).ResolveRelativeAddressSelf(0x3, 0x7).GetPtr()); +CClient* g_pClient = reinterpret_cast(g_pClientBuffer.GetPtr()); diff --git a/r5dev/client/client.h b/r5dev/client/client.h index 9fb97ec2..ac907890 100644 --- a/r5dev/client/client.h +++ b/r5dev/client/client.h @@ -21,6 +21,7 @@ namespace const std::uintptr_t g_dwPersistenceVar = 0x5BC; const std::uintptr_t g_dwCClientPadding = 303360; #endif + static ADDRESS g_pClientBuffer = p_IVEngineServer_PersistenceAvailable.FindPatternSelf("48 8D 0D", ADDRESS::Direction::DOWN, 150).ResolveRelativeAddressSelf(0x3, 0x7); } class CClient @@ -28,7 +29,7 @@ class CClient public: inline CClient* GetClientInstance(int nIndex) { - return (CClient*)(std::uintptr_t)(g_pClient + (nIndex * g_dwCClientSize)); + return (CClient*)(std::uintptr_t)(g_pClientBuffer.GetPtr() + (nIndex * g_dwCClientSize)); } void*& GetNetChan() diff --git a/r5dev/server/IVEngineServer.cpp b/r5dev/server/IVEngineServer.cpp index a46279bb..6cb816f9 100644 --- a/r5dev/server/IVEngineServer.cpp +++ b/r5dev/server/IVEngineServer.cpp @@ -15,9 +15,8 @@ //----------------------------------------------------------------------------- bool HIVEngineServer_PersistenceAvailable(void* entidx, int clientidx) { - CClient* pClient = g_pClient->GetClientInstance(clientidx); // Get client instance. - std::uintptr_t targetInstance = (std::uintptr_t)pClient; - *(char*)(targetInstance + g_dwPersistenceVar) = (char)0x5; // Set the client instance to 'ready'. + CClient* pClient = g_pClient->GetClientInstance(clientidx); // Get client instance. + *(char*)((std::uintptr_t)pClient + g_dwPersistenceVar) = (char)0x5; // Set the client instance to 'ready'. if (!g_bIsPersistenceVarSet[clientidx] && sv_showconnecting->m_pParent->m_iValue > 0) {