From 107a516f9e1916517fe970b65ba77167a96523de Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 15 May 2022 00:29:25 +0200 Subject: [PATCH] Implement CBaseClientState structure --- r5dev/engine/baseclientstate.h | 159 +++++++++++++++++++++++++- r5dev/engine/clockdriftmgr.cpp | 34 ++++++ r5dev/engine/clockdriftmgr.h | 28 +++++ r5dev/engine/datablock.h | 23 ++++ r5dev/engine/framesnapshot.h | 42 +++++++ r5dev/engine/packed_entity.h | 10 ++ r5dev/public/include/inetchannel.h | 7 +- r5dev/public/include/inetmsghandler.h | 21 ++++ r5dev/tier1/mempool.h | 36 ++++++ r5dev/vproj/clientsdk.vcxproj | 7 ++ r5dev/vproj/clientsdk.vcxproj.filters | 21 ++++ r5dev/vproj/dedicated.vcxproj | 7 ++ r5dev/vproj/dedicated.vcxproj.filters | 21 ++++ r5dev/vproj/gamesdk.vcxproj | 7 ++ r5dev/vproj/gamesdk.vcxproj.filters | 21 ++++ 15 files changed, 442 insertions(+), 2 deletions(-) create mode 100644 r5dev/engine/clockdriftmgr.cpp create mode 100644 r5dev/engine/clockdriftmgr.h create mode 100644 r5dev/engine/datablock.h create mode 100644 r5dev/engine/framesnapshot.h create mode 100644 r5dev/engine/packed_entity.h create mode 100644 r5dev/public/include/inetmsghandler.h create mode 100644 r5dev/tier1/mempool.h diff --git a/r5dev/engine/baseclientstate.h b/r5dev/engine/baseclientstate.h index dd7ff4fe..29b2aab1 100644 --- a/r5dev/engine/baseclientstate.h +++ b/r5dev/engine/baseclientstate.h @@ -1,17 +1,174 @@ #pragma once +#include "tier1/NetAdr2.h" +#include "tier1/mempool.h" +#include "common/protocol.h" +#include "public/include/inetmsghandler.h" +#include "engine/datablock.h" +#include "engine/net_chan.h" #include "engine/debugoverlay.h" +#include "engine/clockdriftmgr.h" +#include "engine/framesnapshot.h" +#include "engine/packed_entity.h" inline bool* cl_m_bPaused = nullptr; inline int* cl_host_tickcount = nullptr; +struct __declspec(align(8)) CClientSnapshotManager +{ + void* __vftable /*VFT*/; + void* m_Frames; + CUtlMemoryPool m_ClientFramePool; +}; + +struct IServerMessageHandler : INetMessageHandler +{}; +struct CS_INetChannelHandler : INetChannelHandler +{}; + + /////////////////////////////////////////////////////////////////////////////// -class CBaseClientState +class CBaseClientState : CS_INetChannelHandler, IConnectionlessPacketHandler, IServerMessageHandler, CClientSnapshotManager { public: bool IsPaused(); float GetClientTime(); int GetClientTickCount() const; // Get the client tick count. void SetClientTickCount(int tick); // Set the client tick count. + + int m_Socket; + int _padding_maybe; + CNetChan* m_NetChannel; + double m_flConnectTime; + _DWORD m_nRetryNumber; + _DWORD m_nChallengeRetryLimit; + _BYTE encrypted_connection_MAYBE; + _BYTE gap79[3]; + v_netadr_t addr; + bool m_bUnk_used_during_auth; + char m_bSendChallengeRequest; + _BYTE m_bDoNetParamsReconnect_MAYBE; + _BYTE field_97; + SIGNONSTATE m_nSignonState; + _BYTE gap9C[4]; + double m_flNextCmdTime; + int m_nServerCount; + int field_AC; + float m_flClockDriftUnknown_TIME; + CClockDriftMgr m_ClockDriftMgr; + _BYTE field_148; + _BYTE field_149; + int m_nDeltaTick; + int m_nStringTableAckTick; + int m_nProcesseedDeltaTick; + int m_nProcessedStringTableAckTick; + bool m_bPendingTicksAvailable; + __declspec(align(4)) _BYTE m_bPaused; + char field_161; + char field_162; + _DWORD dword164; + int m_nViewEntity_MAYBE_ClientSlot_Plus_One; + int m_nPlayerSlot; + char m_szLevelFileName[64]; + char m_szLevelBaseName[64]; + char field_1F0[64]; + char field_230[64]; + _BYTE m_szServerAddresString[128]; + char buffer[16]; + int m_bInMpLobbyMenu; + int m_nTeam; + _DWORD m_nMaxClients; + _BYTE m_bSignonChallengeReceived; + _DWORD challenge; + v_netadr_t challengeAddr; + _BYTE byte33C; + _QWORD m_pServerClasses; + int m_nServerClasses; + int m_nServerClassBits; + __int64 m_StringTableContainer; + char m_PersistenceData[98304]; +#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) + char pads0[8]; +#endif + _BYTE m_bPersistenceBaselineRecvd; + __unaligned __declspec(align(4)) _QWORD m_nPersistenceBaselineEntries; + char field_18364; + char field_18365; + char buffer_0x400[1024]; + NetDataBlockReceiver blockReceiver; + char client_requested_disconnect; + char error_message[512]; + _BYTE gap18CA1[3]; + _DWORD last_usercmd_time_from_server_maybe; + CFrameSnapshot* prev_frame_maybe; + _QWORD qword18CB0; + CFrameSnapshot* current_frame_maybe; + _BYTE gap18CC0[8]; + char IsClockCorrectionEnabled_MAYBE; + char m_b_unknown; + bool m_bLocalPredictionInitialized_MAYBE; + int field_18CCC; + int dword18CD0; + int field_18CD4; + float GetFrameTime; + int outgoing_command; + int current_movement_sequence_number; + char gap18CE4[4]; + __int64 qword18CE8; + int field_18CF0; + int hit_prespawn; + int field_18CF8; + int dword18CFC; + float m_flClockDriftUnknown_rounded; + char something_with_prediction; + char field_18D05; + char gap18D06[2]; + int dword18D08; + char gap18D0C[13]; + char do_local_prediction_update; + char gap18D1A[2]; + int dword18D1C; + __int64 qword18D20; + int dword18D28; + int dword18D2C; + float field_18D30; + float m_flUnk1; + float m_flUnk2; + int dword18D3C; + int dword18D40; + char gap18D44[4]; + __int64 qword18D48; + __int64 qword18D50; + __int64 qword18D58; + int dword18D60; + char gap18D64[4]; + __int64 qword18D68; + char gap18D70[8]; + char buffer_47128[47128]; + char entitlements_bitfield[16]; + __int64 maybe_some_ll_stuff; + __int64 qword245A8; + __int64 qword245B0; + __int64 qword245B8; + __int64 qword245C0; + __int64 qword245C8; + __int64 qword245D0; + __int64 qword245D8; + __int64 qword245E0; + __int64 qword245E8; + __int64 qword245F0; + int dword245F8; + char gap245FC[1024]; + __unaligned __declspec(align(1)) __int64 qword249FC; + char gap24A04[4]; + __int64 m_pModelPrecacheTable; + __int64 qword24A10; + __int64 m_pInstanceBaselineTable; + __int64 m_pLightStyleTable; + __int64 m_pUserInfoTable; + __int64 m_pServerStartupTable; + PackedEntity m_pEntityBaselines_maybe[4096]; + char byte34A38; + char field_34A39[7]; }; extern CBaseClientState* g_pBaseClientState; diff --git a/r5dev/engine/clockdriftmgr.cpp b/r5dev/engine/clockdriftmgr.cpp new file mode 100644 index 00000000..4d924373 --- /dev/null +++ b/r5dev/engine/clockdriftmgr.cpp @@ -0,0 +1,34 @@ +//===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======// +// +// Purpose: +// +// $Workfile: $ +// $Date: $ +// +//------------------------------------------------------------------------------ +// $Log: $ +// +// $NoKeywords: $ +//=============================================================================// + +#include "core/stdafx.h" +#include "engine/clockdriftmgr.h" + +void CClockDriftMgr::Clear() +{ + m_nClientTick = 0; + m_nServerTick = 0; + m_iCurClockOffset = 0; + memset(m_ClockOffsets, 0, sizeof(m_ClockOffsets)); +} + +float CClockDriftMgr::GetCurrentClockDifference() const +{ + // Note: this could be optimized a little by updating it each time we add + // a sample (subtract the old value from the total and add the new one in). + float total = 0; + for (int i = 0; i < NUM_CLOCKDRIFT_SAMPLES; i++) + total += m_ClockOffsets[i]; + + return total / NUM_CLOCKDRIFT_SAMPLES; +} diff --git a/r5dev/engine/clockdriftmgr.h b/r5dev/engine/clockdriftmgr.h new file mode 100644 index 00000000..610a4ae1 --- /dev/null +++ b/r5dev/engine/clockdriftmgr.h @@ -0,0 +1,28 @@ +#ifndef CLOCKDRIFTMGR_H +#define CLOCKDRIFTMGR_H + +struct __declspec(align(4)) CClockDriftMgr +{ + void Clear(); + float GetCurrentClockDifference() const; + + enum + { + // This controls how much it smoothes out the samples from the server. + NUM_CLOCKDRIFT_SAMPLES = 24 + }; + + float field_0[4]; + int field_10; + float m_ClockOffsets[NUM_CLOCKDRIFT_SAMPLES]; + int m_iCurClockOffset; + float field_78; + float field_7C; + float m_flClientTickTime; + int m_nClientTick; + float m_flServerTickTime; + int m_nServerTick; + int tickcount_MAYBE; +}; + +#endif // CLOCKDRIFTMGR_H \ No newline at end of file diff --git a/r5dev/engine/datablock.h b/r5dev/engine/datablock.h new file mode 100644 index 00000000..7a34d2fb --- /dev/null +++ b/r5dev/engine/datablock.h @@ -0,0 +1,23 @@ +#ifndef DATABLOCK_H +#define DATABLOCK_H + +struct __declspec(align(8)) NetDataBlockReceiver +{ + void* __vftable /*VFT*/; + void* client; /*CClientState*/ + char m_bStartedRecv; + char m_bCompletedRecv; + _BYTE byte12; + __int16 transfer_id; + __int16 counter; + _BYTE m_bInitialized; + int transfer_size; + int total_blocks; + _DWORD blocks_ackd; + double start_time; + bool block_status[768]; + char* m_pBigBuffer; +}; + + +#endif // DATABLOCK_H \ No newline at end of file diff --git a/r5dev/engine/framesnapshot.h b/r5dev/engine/framesnapshot.h new file mode 100644 index 00000000..9250cf1c --- /dev/null +++ b/r5dev/engine/framesnapshot.h @@ -0,0 +1,42 @@ +#if !defined( FRAMESNAPSHOT_H ) +#define FRAMESNAPSHOT_H + +struct TickUpdate +{ + int m_nTickUnused; + int m_nTick; + float m_flHostFrameTime; + float m_flHostFrameTimeStdDeviation; + bool m_bStruggling; + char m_nUnkStat_maybe_load; + int command_number; +}; + +struct __declspec(align(1)) CFrameSnapshot +{ + char field_0; + _DWORD last_entity; + _DWORD snap_dword8; + _DWORD snap_dwordC; + _BYTE snap_byte10; + _BYTE gap11[3]; + _DWORD snap_dword14; + _DWORD snap_dword18; + _BYTE snap_byte1C; + _BYTE gap1D[3]; + _DWORD snap_dword20; + _BYTE snap_byte24; + _BYTE snap_byte25; + _BYTE snap_byte26; + __unaligned __declspec(align(1)) _WORD word27; + _BYTE gap29[3]; + TickUpdate snap_tick_update; + _BYTE gap44[4]; + _QWORD qword48; + _QWORD qword50; + char buffer_0x20000[131072]; + char buffer_0x800[2048]; + char transmit_entity[4096]; +}; + +#endif // FRAMESNAPSHOT_H \ No newline at end of file diff --git a/r5dev/engine/packed_entity.h b/r5dev/engine/packed_entity.h new file mode 100644 index 00000000..bec8249f --- /dev/null +++ b/r5dev/engine/packed_entity.h @@ -0,0 +1,10 @@ +#if !defined( PACKED_ENTITY_H ) +#define PACKED_ENTITY_H + +struct PackedEntity +{ + _DWORD field_0; + _QWORD field_8; +}; + +#endif // PACKED_ENTITY_H \ No newline at end of file diff --git a/r5dev/public/include/inetchannel.h b/r5dev/public/include/inetchannel.h index d2e49400..24046499 100644 --- a/r5dev/public/include/inetchannel.h +++ b/r5dev/public/include/inetchannel.h @@ -8,7 +8,12 @@ struct INetChannelHandler { - void* iNetMessageHandlerVTable /*VFT*/; + void* __vftable /*VFT*/; +}; + +struct INetMessageHandler +{ + void* __vftable /*VFT*/; }; typedef struct netpacket_s netpacket_t; diff --git a/r5dev/public/include/inetmsghandler.h b/r5dev/public/include/inetmsghandler.h new file mode 100644 index 00000000..8e1900f9 --- /dev/null +++ b/r5dev/public/include/inetmsghandler.h @@ -0,0 +1,21 @@ +//===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======// +// +// Purpose: +// +// $Workfile: $ +// $Date: $ +// +//------------------------------------------------------------------------------ +// $Log: $ +// +// $NoKeywords: $ +//=============================================================================// +#if !defined( INETMSGHANDLER_H ) +#define INETMSGHANDLER_H + +struct IConnectionlessPacketHandler +{ + void* __vftable /*VFT*/; +}; + +#endif // INETMSGHANDLER_H \ No newline at end of file diff --git a/r5dev/tier1/mempool.h b/r5dev/tier1/mempool.h new file mode 100644 index 00000000..d67eba61 --- /dev/null +++ b/r5dev/tier1/mempool.h @@ -0,0 +1,36 @@ +//===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======// +// +// Purpose: +// +// $Workfile: $ +// $Date: $ +// +//------------------------------------------------------------------------------ +// $Log: $ +// +// $NoKeywords: $ +//=============================================================================// + +#ifndef MEMPOOL_H +#define MEMPOOL_H + +struct CUtlMemoryPool +{ + class CBlob + { + public: + short m_nAlignment; // to int align the struct. + short m_NumBlobs; // Number of blobs. + const char* m_pszAllocOwner; + CBlob* m_pPrev, * m_pNext; + }; + + int m_BlockSize; + int m_BlocksPerBlob; + int m_GrowMode; + int m_BlocksAllocated; + int unk; + CBlob m_BlobHead; +}; + +#endif // MEMPOOL_H \ No newline at end of file diff --git a/r5dev/vproj/clientsdk.vcxproj b/r5dev/vproj/clientsdk.vcxproj index d1387522..8fbc7982 100644 --- a/r5dev/vproj/clientsdk.vcxproj +++ b/r5dev/vproj/clientsdk.vcxproj @@ -28,6 +28,7 @@ + @@ -139,11 +140,14 @@ + + + @@ -154,6 +158,7 @@ + @@ -196,6 +201,7 @@ + @@ -408,6 +414,7 @@ + diff --git a/r5dev/vproj/clientsdk.vcxproj.filters b/r5dev/vproj/clientsdk.vcxproj.filters index 755fbfb2..51a6d9b6 100644 --- a/r5dev/vproj/clientsdk.vcxproj.filters +++ b/r5dev/vproj/clientsdk.vcxproj.filters @@ -483,6 +483,9 @@ sdk\squirrel + + sdk\engine + @@ -1439,6 +1442,24 @@ sdk\squirrel + + sdk\engine + + + sdk\engine + + + sdk\engine + + + sdk\engine + + + sdk\public\include + + + sdk\tier1 + diff --git a/r5dev/vproj/dedicated.vcxproj b/r5dev/vproj/dedicated.vcxproj index 95aeec09..d51f858a 100644 --- a/r5dev/vproj/dedicated.vcxproj +++ b/r5dev/vproj/dedicated.vcxproj @@ -147,9 +147,12 @@ + + + @@ -158,6 +161,7 @@ + @@ -199,6 +203,7 @@ + @@ -400,6 +405,7 @@ + @@ -432,6 +438,7 @@ + diff --git a/r5dev/vproj/dedicated.vcxproj.filters b/r5dev/vproj/dedicated.vcxproj.filters index 543fb17a..6e35170b 100644 --- a/r5dev/vproj/dedicated.vcxproj.filters +++ b/r5dev/vproj/dedicated.vcxproj.filters @@ -1065,6 +1065,24 @@ sdk\squirrel + + sdk\engine + + + sdk\engine + + + sdk\engine + + + sdk\engine + + + sdk\public\include + + + sdk\tier1 + @@ -1304,6 +1322,9 @@ sdk\squirrel + + sdk\engine + diff --git a/r5dev/vproj/gamesdk.vcxproj b/r5dev/vproj/gamesdk.vcxproj index 6e595317..e42dbfd6 100644 --- a/r5dev/vproj/gamesdk.vcxproj +++ b/r5dev/vproj/gamesdk.vcxproj @@ -29,6 +29,7 @@ + @@ -148,11 +149,14 @@ + + + @@ -163,6 +167,7 @@ + @@ -214,6 +219,7 @@ + @@ -427,6 +433,7 @@ + diff --git a/r5dev/vproj/gamesdk.vcxproj.filters b/r5dev/vproj/gamesdk.vcxproj.filters index 08d536e1..779d1e00 100644 --- a/r5dev/vproj/gamesdk.vcxproj.filters +++ b/r5dev/vproj/gamesdk.vcxproj.filters @@ -513,6 +513,9 @@ sdk\squirrel + + sdk\engine + @@ -1502,6 +1505,24 @@ sdk\squirrel + + sdk\engine + + + sdk\engine + + + sdk\engine + + + sdk\engine + + + sdk\tier1 + + + sdk\public\include +