From e05c9c787d19c79ac91bb3f4317514bbc7607ca3 Mon Sep 17 00:00:00 2001
From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com>
Date: Sun, 3 Jul 2022 11:03:25 +0200
Subject: [PATCH] Draw the actual simulation tick on overlay

---
 r5dev/engine/client/clientstate.cpp | 28 ++++++++++++++++++++++++++--
 r5dev/engine/client/clientstate.h   |  8 +++++++-
 r5dev/engine/clockdriftmgr.h        |  2 +-
 r5dev/tier1/IConVar.cpp             |  2 +-
 r5dev/vgui/vgui_debugpanel.cpp      |  2 +-
 5 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/r5dev/engine/client/clientstate.cpp b/r5dev/engine/client/clientstate.cpp
index f288ec95..1b0fab53 100644
--- a/r5dev/engine/client/clientstate.cpp
+++ b/r5dev/engine/client/clientstate.cpp
@@ -39,7 +39,31 @@ float CClientState::GetClientTime()
 }
 
 //------------------------------------------------------------------------------
-// Purpose: gets the client simulation tick count
+// Purpose: gets the simulation tick count
+//------------------------------------------------------------------------------
+int CClientState::GetTick() const
+{
+    return m_ClockDriftMgr.m_nSimulationTick;
+}
+
+//------------------------------------------------------------------------------
+// Purpose: gets the last-received server tick count
+//------------------------------------------------------------------------------
+int CClientState::GetServerTickCount() const
+{
+    return m_ClockDriftMgr.m_nServerTick;
+}
+
+//------------------------------------------------------------------------------
+// Purpose: sets the server tick count
+//------------------------------------------------------------------------------
+void CClientState::SetServerTickCount(int tick)
+{
+    m_ClockDriftMgr.m_nServerTick = tick;
+}
+
+//------------------------------------------------------------------------------
+// Purpose: gets the client tick count
 //------------------------------------------------------------------------------
 int CClientState::GetClientTickCount() const
 {
@@ -47,7 +71,7 @@ int CClientState::GetClientTickCount() const
 }
 
 //------------------------------------------------------------------------------
-// Purpose: sets the client simulation tick count
+// Purpose: sets the client tick count
 //------------------------------------------------------------------------------
 void CClientState::SetClientTickCount(int tick)
 {
diff --git a/r5dev/engine/client/clientstate.h b/r5dev/engine/client/clientstate.h
index 272fe5f2..6ab1faee 100644
--- a/r5dev/engine/client/clientstate.h
+++ b/r5dev/engine/client/clientstate.h
@@ -23,8 +23,14 @@ class CClientState : CS_INetChannelHandler, IConnectionlessPacketHandler, IServe
 public:
 	bool IsPaused();
 	float GetClientTime();
+
+	int GetTick() const;
+
+	int GetServerTickCount() const;	// Get the server tick count.
+	void SetServerTickCount(int tick);
+
 	int GetClientTickCount() const;	// Get the client tick count.
-	void SetClientTickCount(int tick); // Set the client tick count.
+	void SetClientTickCount(int tick);
 
 	int m_Socket;
 	int _padding_maybe;
diff --git a/r5dev/engine/clockdriftmgr.h b/r5dev/engine/clockdriftmgr.h
index 610a4ae1..4f249e7f 100644
--- a/r5dev/engine/clockdriftmgr.h
+++ b/r5dev/engine/clockdriftmgr.h
@@ -22,7 +22,7 @@ struct __declspec(align(4)) CClockDriftMgr
 	int m_nClientTick;
 	float m_flServerTickTime;
 	int m_nServerTick;
-	int tickcount_MAYBE;
+	int m_nSimulationTick;
 };
 
 #endif // CLOCKDRIFTMGR_H
\ No newline at end of file
diff --git a/r5dev/tier1/IConVar.cpp b/r5dev/tier1/IConVar.cpp
index b0dfd4f1..de311846 100644
--- a/r5dev/tier1/IConVar.cpp
+++ b/r5dev/tier1/IConVar.cpp
@@ -119,7 +119,7 @@ void ConVar::Init(void) const
 	cl_gpustats_offset_x      = new ConVar("cl_gpustats_offset_x"     , "650", FCVAR_DEVELOPMENTONLY, "X offset for texture streaming debug overlay.", false, 0.f, false, 0.f, nullptr, nullptr);
 	cl_gpustats_offset_y      = new ConVar("cl_gpustats_offset_y"     , "105", FCVAR_DEVELOPMENTONLY, "Y offset for texture streaming debug overlay.", false, 0.f, false, 0.f, nullptr, nullptr);
 
-	cl_showmaterialinfo = new ConVar("cl_showmaterialinfo", "0", FCVAR_DEVELOPMENTONLY, "Draw info for the material under the crosshair on screen", false, 0.f, false, 0.f, nullptr, nullptr);
+	cl_showmaterialinfo = new ConVar("cl_showmaterialinfo", "0", FCVAR_DEVELOPMENTONLY, "Draw info for the material under the crosshair on screen.", false, 0.f, false, 0.f, nullptr, nullptr);
 	cl_materialinfo_offset_x = new ConVar("cl_materialinfo_offset_x", "0", FCVAR_DEVELOPMENTONLY, "X offset for material debug info overlay.", false, 0.f, false, 0.f, nullptr, nullptr);
 	cl_materialinfo_offset_y = new ConVar("cl_materialinfo_offset_y", "420", FCVAR_DEVELOPMENTONLY, "Y offset for material debug info overlay.", false, 0.f, false, 0.f, nullptr, nullptr);
 
diff --git a/r5dev/vgui/vgui_debugpanel.cpp b/r5dev/vgui/vgui_debugpanel.cpp
index 5f8f703b..7e90bafa 100644
--- a/r5dev/vgui/vgui_debugpanel.cpp
+++ b/r5dev/vgui/vgui_debugpanel.cpp
@@ -140,7 +140,7 @@ void CLogSystem::DrawSimStats(void) const
 	static Color c = { 255, 255, 255, 255 };
 	static const char* szLogbuf[4096]{};
 	snprintf((char*)szLogbuf, 4096, "Server Frame: (%d) Client Frame: (%d) Render Frame: (%d)\n",
-	g_pServer->GetTick(), g_pClientState->GetClientTickCount(), *render_tickcount);
+	g_pServer->GetTick(), g_pClientState->GetTick(), *render_tickcount);
 
 	if (cl_simstats_invert_rect_x->GetBool())
 	{