From b1e1765124b4505e23ebb558d5c025b0568b1993 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 9 Sep 2022 20:16:55 +0200 Subject: [PATCH] Set the correct datatype for what was originally 'm_bSplitScreenConnect' Bool is a char on this platform, and UINT8_MAX is 0xff (255), yet we set this char to 256 causing arithmetic overflow. Looking at the assembly of the game, this really is a uint16_t, and gets set to 256 in CHostState::Init, parsed to State_NewGame as 256 before the lowbyte is being reset to 0. --- r5dev/engine/host_state.cpp | 8 ++++---- r5dev/engine/host_state.h | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/r5dev/engine/host_state.cpp b/r5dev/engine/host_state.cpp index f238142a..82b8a7b6 100644 --- a/r5dev/engine/host_state.cpp +++ b/r5dev/engine/host_state.cpp @@ -172,7 +172,7 @@ FORCEINLINE void CHostState::Init(void) m_levelName[0] = 0; m_landMarkName[0] = 0; m_mapGroupName[0] = 0; - m_bSplitScreenConnect = 256; // Is this actually 'm_bSplitScreenConnect'? (assembly sets this value, other 3 bytes are padded which makes this operation valid still). + m_nSplitScreenPlayers = 256; m_vecLocation.Init(); m_angLocation.Init(); m_iCurrentState = HostStates_t::HS_NEW_GAME; @@ -321,8 +321,8 @@ FORCEINLINE void CHostState::GameShutDown(void) FORCEINLINE void CHostState::State_NewGame(void) { LARGE_INTEGER time{}; - - m_bSplitScreenConnect = false; + uint16_t nSplitScreenPlayers = m_nSplitScreenPlayers; + m_nSplitScreenPlayers = 0; #ifndef CLIENT_DLL if (!g_pServerGameClients) // Init Game if it ain't valid. { @@ -332,7 +332,7 @@ FORCEINLINE void CHostState::State_NewGame(void) #ifndef CLIENT_DLL if (!CModelLoader__Map_IsValid(g_pModelLoader, m_levelName) // Check if map is valid and if we can start a new game. - || !Host_NewGame(m_levelName, nullptr, m_bBackgroundLevel, m_bSplitScreenConnect, time) || !g_pServerGameClients) + || !Host_NewGame(m_levelName, nullptr, m_bBackgroundLevel, nSplitScreenPlayers, time) || !g_pServerGameClients) { Error(eDLL_T::ENGINE, false, "%s - Error: Map not valid\n", "CHostState::State_NewGame"); #ifndef DEDICATED diff --git a/r5dev/engine/host_state.h b/r5dev/engine/host_state.h index 24835d9c..5a4a0f15 100644 --- a/r5dev/engine/host_state.h +++ b/r5dev/engine/host_state.h @@ -45,9 +45,7 @@ public: bool m_bRememberLocation; //0x0265 bool m_bBackgroundLevel; //0x0266 bool m_bWaitingForConnection; //0x0267 - bool m_bSplitScreenConnect; //0x0268 - bool m_bGameHasShutDownAndFlushedMemory; //0x0269 - bool m_bWorkshopMapDownloadPending; //0x026A + uint16_t m_nSplitScreenPlayers; //0x0268 }; /* ==== CHOSTSTATE ====================================================================================================================================================== */