Client: CPU statistics update logic

Implements the client side CPU statistics logic. An additional check has been added which checks if 'SVC_ServerTick::m_NetTick.m_nCommandTick' equals '-1'. This instructs the client to only update the remote statistics; actual tick members won't get updated as this causes simulation problems.
This commit is contained in:
Kawe Mazidjatari 2023-02-18 00:31:57 +01:00
parent 872e33887a
commit 74eb203f2f
2 changed files with 43 additions and 2 deletions

View File

@ -102,6 +102,38 @@ void CClientState::SetClientTickCount(int tick)
m_ClockDriftMgr.m_nClientTick = tick;
}
//------------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------------
bool CClientState::VProcessServerTick(CClientState* pClientState, SVC_ServerTick* pServerTick)
{
if (pServerTick->m_NetTick.m_nCommandTick != -1)
{
return CClientState__ProcessServerTick(pClientState, pServerTick);
}
else // Statistics only.
{
char* pShifted = reinterpret_cast<char*>(pClientState) - 0x10; // Shifted due to compiled optimizations.
CClientState* pClient_Adj = reinterpret_cast<CClientState*>(pShifted);
CNetChan* pChan = pClient_Adj->m_NetChannel;
pChan->SetRemoteFramerate(pServerTick->m_NetTick.m_flHostFrameTime, pServerTick->m_NetTick.m_flHostFrameTimeStdDeviation);
pChan->SetRemoteCPUStatistics(pServerTick->m_NetTick.m_nServerCPU);
return true;
}
}
void VClientState::Attach() const
{
DetourAttach(&CClientState__ProcessServerTick, &CClientState::VProcessServerTick);
}
void VClientState::Detach() const
{
DetourDetach(&CClientState__ProcessServerTick, &CClientState::VProcessServerTick);
}
/////////////////////////////////////////////////////////////////////////////////
CClientState* g_pClientState = nullptr;
CClientState** g_pClientState_Shifted = nullptr;

View File

@ -23,6 +23,9 @@ public:
///////////////////////////////////////////////////////////////////////////////
class CClientState : CS_INetChannelHandler, IConnectionlessPacketHandler, IServerMessageHandler, CClientSnapshotManager
{
public: // Hook statics.
static bool VProcessServerTick(CClientState* thisptr, SVC_ServerTick* msg);
public:
bool IsPaused() const;
bool IsActive(void) const;
@ -189,6 +192,9 @@ inline auto CClientState__RunFrame = p_CClientState__RunFrame.RCast<void(*)(CCli
inline CMemory p_CClientState__Disconnect; /*48 89 5C 24 ?? 55 57 41 56 48 83 EC 30 0F B6 EA*/
inline auto CClientState__Disconnect = p_CClientState__Disconnect.RCast<void(*)(CClientState* thisptr, bool bSendTrackingContext)>();
inline CMemory p_CClientState__ProcessServerTick;
inline auto CClientState__ProcessServerTick = p_CClientState__ProcessServerTick.RCast<bool(*)(CClientState* thisptr, SVC_ServerTick* msg)>();
///////////////////////////////////////////////////////////////////////////////
class VClientState : public IDetour
@ -197,6 +203,7 @@ class VClientState : public IDetour
{
LogFunAdr("CClientState::RunFrame", p_CClientState__RunFrame.GetPtr());
LogFunAdr("CClientState::Disconnect", p_CClientState__Disconnect.GetPtr());
LogFunAdr("CClientState::ProcessServerTick", p_CClientState__ProcessServerTick.GetPtr());
LogVarAdr("g_pClientState", reinterpret_cast<uintptr_t>(g_pClientState));
LogVarAdr("g_pClientState_Shifted", reinterpret_cast<uintptr_t>(g_pClientState_Shifted));
}
@ -215,6 +222,8 @@ class VClientState : public IDetour
p_CClientState__Disconnect = g_GameDll.FindPatternSIMD("40 56 57 41 54 41 55 41 57 48 83 EC 30 44 0F B6 FA");
CClientState__Disconnect = p_CClientState__Disconnect.RCast<void(*)(CClientState* thisptr, bool bSendTrackingContext)>(); /*40 56 57 41 54 41 55 41 57 48 83 EC 30 44 0F B6 FA*/
#endif
p_CClientState__ProcessServerTick = g_GameDll.FindPatternSIMD("40 57 48 83 EC 20 83 B9 ?? ?? ?? ?? ?? 48 8B F9 7C 66");
CClientState__ProcessServerTick = p_CClientState__ProcessServerTick.RCast<bool(*)(CClientState*, SVC_ServerTick*)>();
}
virtual void GetVar(void) const
{
@ -222,7 +231,7 @@ class VClientState : public IDetour
g_pClientState_Shifted = reinterpret_cast<CClientState**>(reinterpret_cast<int64_t*>(g_pClientState)+1); // Shift by 8 bytes.
}
virtual void GetCon(void) const { }
virtual void Attach(void) const { }
virtual void Detach(void) const { }
virtual void Attach(void) const;
virtual void Detach(void) const;
};
///////////////////////////////////////////////////////////////////////////////