From 4095424b7cc02c98c1b211bc8dad78619cf0e72f Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Mon, 20 Jun 2022 14:58:53 +0200 Subject: [PATCH] Add clock/time function patterns Added: * Sys_GetProcessUpTime * Plat_FloatTime * Plat_MSTime --- r5dev/core/init.cpp | 1 + r5dev/engine/sys_utils.cpp | 10 ++++++++ r5dev/engine/sys_utils.h | 24 ++++++++++++------ r5dev/tier0/platform.cpp | 12 +++++++++ r5dev/tier0/platform.h | 2 ++ r5dev/tier0/platform_internal.h | 36 +++++++++++++++++++++++++++ r5dev/vproj/clientsdk.vcxproj | 2 ++ r5dev/vproj/clientsdk.vcxproj.filters | 6 +++++ r5dev/vproj/dedicated.vcxproj | 2 ++ r5dev/vproj/dedicated.vcxproj.filters | 6 +++++ r5dev/vproj/gamesdk.vcxproj | 2 ++ r5dev/vproj/gamesdk.vcxproj.filters | 6 +++++ 12 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 r5dev/tier0/platform.cpp create mode 100644 r5dev/tier0/platform_internal.h diff --git a/r5dev/core/init.cpp b/r5dev/core/init.cpp index b311a3fe..a6bfcfd0 100644 --- a/r5dev/core/init.cpp +++ b/r5dev/core/init.cpp @@ -12,6 +12,7 @@ #include "tier0/fasttimer.h" #include "tier0/cpu.h" #include "tier0/commandline.h" +#include "tier0/platform_internal.h" #include "tier1/cmd.h" #include "tier1/IConVar.h" #include "tier1/cvar.h" diff --git a/r5dev/engine/sys_utils.cpp b/r5dev/engine/sys_utils.cpp index 77d73414..b286f372 100644 --- a/r5dev/engine/sys_utils.cpp +++ b/r5dev/engine/sys_utils.cpp @@ -116,6 +116,16 @@ void* HSys_LoadAssetHelper(const CHAR* lpFileName, std::int64_t a2, LARGE_INTEGE return Sys_LoadAssetHelper(lpFileName, a2, a3); } +//----------------------------------------------------------------------------- +// Purpose: Gets the process up time (input buffer should be at least 4096 bytes in size) +// Input : *szBuffer - +// Output : snprintf_s ret val +//----------------------------------------------------------------------------- +int Sys_GetProcessUpTime(char* szBuffer) +{ + return v_Sys_GetProcessUpTime(szBuffer); +} + void SysUtils_Attach() { //DetourAttach((LPVOID*)&Sys_Error, &HSys_Error); diff --git a/r5dev/engine/sys_utils.h b/r5dev/engine/sys_utils.h index 49a858dc..dec74247 100644 --- a/r5dev/engine/sys_utils.h +++ b/r5dev/engine/sys_utils.h @@ -10,12 +10,17 @@ inline auto Sys_Warning = p_Warning.RCast(); inline CMemory p_Sys_LoadAssetHelper; inline auto Sys_LoadAssetHelper = p_Sys_LoadAssetHelper.RCast(); +inline CMemory p_Sys_GetProcessUpTime; +inline auto v_Sys_GetProcessUpTime = p_Sys_GetProcessUpTime.RCast(); + inline CMemory p_Con_NPrintf; inline auto Con_NPrintf = p_Con_NPrintf.RCast(); /* ==== ------- ========================================================================================================================================================= */ /////////////////////////////////////////////////////////////////////////////// void HSys_Error(char* fmt, ...); +int Sys_GetProcessUpTime(char* szBuffer); + void SysUtils_Attach(); void SysUtils_Detach(); @@ -27,20 +32,23 @@ class VSys_Utils : public IDetour spdlog::debug("| FUN: Sys_Error : {:#18x} |\n", p_Sys_Error.GetPtr()); spdlog::debug("| FUN: Sys_Warning : {:#18x} |\n", p_Warning.GetPtr()); spdlog::debug("| FUN: Sys_LoadAssetHelper : {:#18x} |\n", p_Sys_LoadAssetHelper.GetPtr()); + spdlog::debug("| FUN: Sys_GetProcessUpTime : {:#18x} |\n", p_Sys_LoadAssetHelper.GetPtr()); spdlog::debug("| FUN: Con_NPrintf : {:#18x} |\n", p_Con_NPrintf.GetPtr()); spdlog::debug("+----------------------------------------------------------------+\n"); } virtual void GetFun(void) const { - p_Sys_Error = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x4C\x24\x08\x48\x89\x54\x24\x10\x4C\x89\x44\x24\x18\x4C\x89\x4C\x24\x20\x53\x55\x41\x54\x41\x56\xB8\x58\x10\x00\x00\xE8"), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - p_Warning = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x54\x24\x00\x4C\x89\x44\x24\x00\x4C\x89\x4C\x24\x00\x48\x83\xEC\x28\x4C\x8D\x44\x24\x00\xE8\x00\x00\x00\x00\x48\x83\xC4\x28\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x48\x89\x7C\x24\x00\x8B\x05\x00\x00\x00\x00"), "xxxx?xxxx?xxxx?xxxxxxxx?x????xxxxxxxxxxxxxxxxxxxxxxx?xxxx?xxxx?xx????"); - p_Sys_LoadAssetHelper = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x74\x24\x10\x48\x89\x7C\x24\x18\x41\x56\x48\x83\xEC\x40\x33"), "xxxxxxxxxxxxxxxxx"); - p_Con_NPrintf = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x4C\x24\x00\x48\x89\x54\x24\x00\x4C\x89\x44\x24\x00\x4C\x89\x4C\x24\x00\xC3"), "xxxx?xxxx?xxxx?xxxx?x"); + p_Sys_Error = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x4C\x24\x08\x48\x89\x54\x24\x10\x4C\x89\x44\x24\x18\x4C\x89\x4C\x24\x20\x53\x55\x41\x54\x41\x56\xB8\x58\x10\x00\x00\xE8"), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + p_Warning = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x54\x24\x00\x4C\x89\x44\x24\x00\x4C\x89\x4C\x24\x00\x48\x83\xEC\x28\x4C\x8D\x44\x24\x00\xE8\x00\x00\x00\x00\x48\x83\xC4\x28\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x48\x89\x7C\x24\x00\x8B\x05\x00\x00\x00\x00"), "xxxx?xxxx?xxxx?xxxxxxxx?x????xxxxxxxxxxxxxxxxxxxxxxx?xxxx?xxxx?xx????"); + p_Sys_LoadAssetHelper = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x74\x24\x10\x48\x89\x7C\x24\x18\x41\x56\x48\x83\xEC\x40\x33"), "xxxxxxxxxxxxxxxxx"); + p_Sys_GetProcessUpTime = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x40\x57\x48\x83\xEC\x30\x48\x8B\xF9\x8B\x0D\x00\x00\x00\x00"), "xxxxxxxxxxx????"); + p_Con_NPrintf = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x4C\x24\x00\x48\x89\x54\x24\x00\x4C\x89\x44\x24\x00\x4C\x89\x4C\x24\x00\xC3"), "xxxx?xxxx?xxxx?xxxx?x"); - Sys_Error = p_Sys_Error.RCast(); /*48 89 4C 24 08 48 89 54 24 10 4C 89 44 24 18 4C 89 4C 24 20 53 55 41 54 41 56 B8 58 10 00 00 E8*/ - Sys_Warning = p_Warning.RCast(); /*48 89 54 24 ?? 4C 89 44 24 ?? 4C 89 4C 24 ?? 48 83 EC 28 4C 8D 44 24 ?? E8 ?? ?? ?? ?? 48 83 C4 28 C3 CC CC CC CC CC CC CC CC CC CC CC CC CC CC 48 89 5C 24 ?? 48 89 74 24 ?? 48 89 7C 24 ?? 8B 05 ?? ?? ?? ??*/ - Sys_LoadAssetHelper = p_Sys_LoadAssetHelper.RCast();/*48 89 74 24 10 48 89 7C 24 18 41 56 48 83 EC 40 33*/ - Con_NPrintf = p_Con_NPrintf.RCast(); /*48 89 4C 24 ?? 48 89 54 24 ?? 4C 89 44 24 ?? 4C 89 4C 24 ?? C3*/ + Sys_Error = p_Sys_Error.RCast(); /*48 89 4C 24 08 48 89 54 24 10 4C 89 44 24 18 4C 89 4C 24 20 53 55 41 54 41 56 B8 58 10 00 00 E8*/ + Sys_Warning = p_Warning.RCast(); /*48 89 54 24 ?? 4C 89 44 24 ?? 4C 89 4C 24 ?? 48 83 EC 28 4C 8D 44 24 ?? E8 ?? ?? ?? ?? 48 83 C4 28 C3 CC CC CC CC CC CC CC CC CC CC CC CC CC CC 48 89 5C 24 ?? 48 89 74 24 ?? 48 89 7C 24 ?? 8B 05 ?? ?? ?? ??*/ + Sys_LoadAssetHelper = p_Sys_LoadAssetHelper.RCast();/*48 89 74 24 10 48 89 7C 24 18 41 56 48 83 EC 40 33*/ + v_Sys_GetProcessUpTime = p_Sys_GetProcessUpTime.RCast(); /*40 57 48 83 EC 30 48 8B F9 8B 0D ?? ?? ?? ??*/ + Con_NPrintf = p_Con_NPrintf.RCast(); /*48 89 4C 24 ?? 48 89 54 24 ?? 4C 89 44 24 ?? 4C 89 4C 24 ?? C3*/ } virtual void GetVar(void) const { } virtual void GetCon(void) const { } diff --git a/r5dev/tier0/platform.cpp b/r5dev/tier0/platform.cpp new file mode 100644 index 00000000..7e8af4a1 --- /dev/null +++ b/r5dev/tier0/platform.cpp @@ -0,0 +1,12 @@ +#include "core/stdafx.h" +#include "tier0/platform_internal.h" + +double Plat_FloatTime() +{ + return v_Plat_FloatTime(); +} + +uint64_t Plat_MSTime() +{ + return v_Plat_MSTime(); +} diff --git a/r5dev/tier0/platform.h b/r5dev/tier0/platform.h index 16ce459f..e359dd6c 100644 --- a/r5dev/tier0/platform.h +++ b/r5dev/tier0/platform.h @@ -169,6 +169,8 @@ inline uint64_t Plat_Rdtsc() #error #endif } +double Plat_FloatTime(); +uint64_t Plat_MSTime(); //----------------------------------------------------------------------------- // Silences a number of warnings on 360 compiles diff --git a/r5dev/tier0/platform_internal.h b/r5dev/tier0/platform_internal.h new file mode 100644 index 00000000..7939b8b1 --- /dev/null +++ b/r5dev/tier0/platform_internal.h @@ -0,0 +1,36 @@ +#ifndef PLATFORM_INTERNAL_H +#define PLATFORM_INTERNAL_H + +inline CMemory p_Plat_FloatTime; +inline auto v_Plat_FloatTime = p_Plat_FloatTime.RCast(); + +inline CMemory p_Plat_MSTime; +inline auto v_Plat_MSTime = p_Plat_MSTime.RCast(); + +/////////////////////////////////////////////////////////////////////////////// +class VPlatform : public IDetour +{ + virtual void GetAdr(void) const + { + spdlog::debug("| FUN: Plat_FloatTime : {:#18x} |\n", p_Plat_FloatTime.GetPtr()); + spdlog::debug("| FUN: Plat_MSTime : {:#18x} |\n", p_Plat_MSTime.GetPtr()); + spdlog::debug("+----------------------------------------------------------------+\n"); + } + virtual void GetFun(void) const + { + p_Plat_FloatTime = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x83\xEC\x28\x80\x3D\x00\x00\x00\x00\x00\x75\x05\xE8\x00\x00\x00\x00\x80\x3D\x00\x00\x00\x00\x00\x74\x1D"), "xxxxxx?????xxx????xx?????xx"); + p_Plat_MSTime = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x83\xEC\x28\x80\x3D\x00\x00\x00\x00\x00\x75\x05\xE8\x00\x00\x00\x00\x80\x3D\x00\x00\x00\x00\x00\x74\x2A"), "xxxxxx?????xxx????xx?????xx"); + + v_Plat_FloatTime = p_Plat_FloatTime.RCast(); /*48 83 EC 28 80 3D ? ? ? ? ? 75 05 E8 ? ? ? ? 80 3D ? ? ? ? ? 74 1D*/ + v_Plat_MSTime = p_Plat_MSTime.RCast(); /*48 83 EC 28 80 3D ? ? ? ? ? 75 05 E8 ? ? ? ? 80 3D ? ? ? ? ? 74 2A*/ + } + virtual void GetVar(void) const { } + virtual void GetCon(void) const { } + virtual void Attach(void) const { } + virtual void Detach(void) const { } +}; +/////////////////////////////////////////////////////////////////////////////// + +REGISTER(VPlatform); + +#endif /* PLATFORM_INTERNAL_H */ \ No newline at end of file diff --git a/r5dev/vproj/clientsdk.vcxproj b/r5dev/vproj/clientsdk.vcxproj index 5044f214..1f1c0f7c 100644 --- a/r5dev/vproj/clientsdk.vcxproj +++ b/r5dev/vproj/clientsdk.vcxproj @@ -94,6 +94,7 @@ + @@ -421,6 +422,7 @@ + diff --git a/r5dev/vproj/clientsdk.vcxproj.filters b/r5dev/vproj/clientsdk.vcxproj.filters index fca17929..a97e98ea 100644 --- a/r5dev/vproj/clientsdk.vcxproj.filters +++ b/r5dev/vproj/clientsdk.vcxproj.filters @@ -510,6 +510,9 @@ sdk\engine + + sdk\tier0 + @@ -1517,6 +1520,9 @@ sdk\mathlib + + sdk\tier0 + diff --git a/r5dev/vproj/dedicated.vcxproj b/r5dev/vproj/dedicated.vcxproj index 4e6e5534..f57ee58f 100644 --- a/r5dev/vproj/dedicated.vcxproj +++ b/r5dev/vproj/dedicated.vcxproj @@ -406,6 +406,7 @@ + @@ -511,6 +512,7 @@ + diff --git a/r5dev/vproj/dedicated.vcxproj.filters b/r5dev/vproj/dedicated.vcxproj.filters index 652a8af2..c5b6c6a4 100644 --- a/r5dev/vproj/dedicated.vcxproj.filters +++ b/r5dev/vproj/dedicated.vcxproj.filters @@ -1122,6 +1122,9 @@ sdk\mathlib + + sdk\tier0 + @@ -1379,6 +1382,9 @@ sdk\mathlib + + sdk\tier0 + diff --git a/r5dev/vproj/gamesdk.vcxproj b/r5dev/vproj/gamesdk.vcxproj index 80060b67..8f18636b 100644 --- a/r5dev/vproj/gamesdk.vcxproj +++ b/r5dev/vproj/gamesdk.vcxproj @@ -101,6 +101,7 @@ + @@ -439,6 +440,7 @@ + diff --git a/r5dev/vproj/gamesdk.vcxproj.filters b/r5dev/vproj/gamesdk.vcxproj.filters index f45143bd..9e31dbb0 100644 --- a/r5dev/vproj/gamesdk.vcxproj.filters +++ b/r5dev/vproj/gamesdk.vcxproj.filters @@ -540,6 +540,9 @@ sdk\engine + + sdk\tier0 + @@ -1580,6 +1583,9 @@ sdk\mathlib + + sdk\tier0 +