Add clock/time function patterns

Added:
* Sys_GetProcessUpTime
* Plat_FloatTime
* Plat_MSTime
This commit is contained in:
Kawe Mazidjatari 2022-06-20 14:58:53 +02:00
parent 7d749fc53a
commit 4095424b7c
12 changed files with 101 additions and 8 deletions

View File

@ -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"

View File

@ -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);

View File

@ -10,12 +10,17 @@ inline auto Sys_Warning = p_Warning.RCast<void* (*)(int, char* fmt, ...)>();
inline CMemory p_Sys_LoadAssetHelper;
inline auto Sys_LoadAssetHelper = p_Sys_LoadAssetHelper.RCast<void* (*)(const CHAR* lpFileName, int64_t a2, LARGE_INTEGER* a3)>();
inline CMemory p_Sys_GetProcessUpTime;
inline auto v_Sys_GetProcessUpTime = p_Sys_GetProcessUpTime.RCast<int (*)(char* szBuffer)>();
inline CMemory p_Con_NPrintf;
inline auto Con_NPrintf = p_Con_NPrintf.RCast<void (*)(int pos, const char* fmt, ...)>();
/* ==== ------- ========================================================================================================================================================= */
///////////////////////////////////////////////////////////////////////////////
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<rsig_t>("\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<rsig_t>("\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<rsig_t>("\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<rsig_t>("\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<rsig_t>("\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<rsig_t>("\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<rsig_t>("\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<rsig_t>("\x40\x57\x48\x83\xEC\x30\x48\x8B\xF9\x8B\x0D\x00\x00\x00\x00"), "xxxxxxxxxxx????");
p_Con_NPrintf = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\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<void (*)(char*, ...)>(); /*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<void* (*)(int, char*, ...)>(); /*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<void* (*)(const CHAR*, int64_t, LARGE_INTEGER*)>();/*48 89 74 24 10 48 89 7C 24 18 41 56 48 83 EC 40 33*/
Con_NPrintf = p_Con_NPrintf.RCast<void (*)(int, const char*, ...)>(); /*48 89 4C 24 ?? 48 89 54 24 ?? 4C 89 44 24 ?? 4C 89 4C 24 ?? C3*/
Sys_Error = p_Sys_Error.RCast<void (*)(char*, ...)>(); /*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<void* (*)(int, char*, ...)>(); /*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<void* (*)(const CHAR*, int64_t, LARGE_INTEGER*)>();/*48 89 74 24 10 48 89 7C 24 18 41 56 48 83 EC 40 33*/
v_Sys_GetProcessUpTime = p_Sys_GetProcessUpTime.RCast<int (*)(char*)>(); /*40 57 48 83 EC 30 48 8B F9 8B 0D ?? ?? ?? ??*/
Con_NPrintf = p_Con_NPrintf.RCast<void (*)(int, const char*, ...)>(); /*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 { }

12
r5dev/tier0/platform.cpp Normal file
View File

@ -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();
}

View File

@ -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

View File

@ -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<double(*)(void)>();
inline CMemory p_Plat_MSTime;
inline auto v_Plat_MSTime = p_Plat_MSTime.RCast<uint64_t(*)(void)>();
///////////////////////////////////////////////////////////////////////////////
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<rsig_t>("\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<rsig_t>("\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<double(*)(void)>(); /*48 83 EC 28 80 3D ? ? ? ? ? 75 05 E8 ? ? ? ? 80 3D ? ? ? ? ? 74 1D*/
v_Plat_MSTime = p_Plat_MSTime.RCast<uint64_t(*)(void)>(); /*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 */

View File

@ -94,6 +94,7 @@
<ClCompile Include="..\tier0\dbg.cpp" />
<ClCompile Include="..\tier0\fasttimer.cpp" />
<ClCompile Include="..\tier0\jobthread.cpp" />
<ClCompile Include="..\tier0\platform.cpp" />
<ClCompile Include="..\tier0\tslist.cpp" />
<ClCompile Include="..\tier1\bitbuf.cpp" />
<ClCompile Include="..\tier1\cmd.cpp" />
@ -421,6 +422,7 @@
<ClInclude Include="..\tier0\interface.h" />
<ClInclude Include="..\tier0\jobthread.h" />
<ClInclude Include="..\tier0\platform.h" />
<ClInclude Include="..\tier0\platform_internal.h" />
<ClInclude Include="..\tier0\threadtools.h" />
<ClInclude Include="..\tier0\tslist.h" />
<ClInclude Include="..\tier0\valve_off.h" />

View File

@ -510,6 +510,9 @@
<ClCompile Include="..\engine\debugoverlay.cpp">
<Filter>sdk\engine</Filter>
</ClCompile>
<ClCompile Include="..\tier0\platform.cpp">
<Filter>sdk\tier0</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\client\cdll_engine_int.h">
@ -1517,6 +1520,9 @@
<ClInclude Include="..\mathlib\sha1.h">
<Filter>sdk\mathlib</Filter>
</ClInclude>
<ClInclude Include="..\tier0\platform_internal.h">
<Filter>sdk\tier0</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="..\shared\resource\lockedserver.png">

View File

@ -406,6 +406,7 @@
<ClInclude Include="..\tier0\interface.h" />
<ClInclude Include="..\tier0\jobthread.h" />
<ClInclude Include="..\tier0\platform.h" />
<ClInclude Include="..\tier0\platform_internal.h" />
<ClInclude Include="..\tier0\threadtools.h" />
<ClInclude Include="..\tier0\tslist.h" />
<ClInclude Include="..\tier0\valve_off.h" />
@ -511,6 +512,7 @@
<ClCompile Include="..\tier0\dbg.cpp" />
<ClCompile Include="..\tier0\fasttimer.cpp" />
<ClCompile Include="..\tier0\jobthread.cpp" />
<ClCompile Include="..\tier0\platform.cpp" />
<ClCompile Include="..\tier0\tslist.cpp" />
<ClCompile Include="..\tier1\bitbuf.cpp" />
<ClCompile Include="..\tier1\cmd.cpp" />

View File

@ -1122,6 +1122,9 @@
<ClInclude Include="..\mathlib\sha1.h">
<Filter>sdk\mathlib</Filter>
</ClInclude>
<ClInclude Include="..\tier0\platform_internal.h">
<Filter>sdk\tier0</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\common\opcodes.cpp">
@ -1379,6 +1382,9 @@
<ClCompile Include="..\mathlib\sha1.cpp">
<Filter>sdk\mathlib</Filter>
</ClCompile>
<ClCompile Include="..\tier0\platform.cpp">
<Filter>sdk\tier0</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\Dedicated.def" />

View File

@ -101,6 +101,7 @@
<ClCompile Include="..\tier0\dbg.cpp" />
<ClCompile Include="..\tier0\fasttimer.cpp" />
<ClCompile Include="..\tier0\jobthread.cpp" />
<ClCompile Include="..\tier0\platform.cpp" />
<ClCompile Include="..\tier0\tslist.cpp" />
<ClCompile Include="..\tier1\bitbuf.cpp" />
<ClCompile Include="..\tier1\cmd.cpp" />
@ -439,6 +440,7 @@
<ClInclude Include="..\tier0\fasttimer.h" />
<ClInclude Include="..\tier0\jobthread.h" />
<ClInclude Include="..\tier0\platform.h" />
<ClInclude Include="..\tier0\platform_internal.h" />
<ClInclude Include="..\tier0\threadtools.h" />
<ClInclude Include="..\tier0\tslist.h" />
<ClInclude Include="..\tier0\valve_off.h" />

View File

@ -540,6 +540,9 @@
<ClCompile Include="..\engine\debugoverlay.cpp">
<Filter>sdk\engine</Filter>
</ClCompile>
<ClCompile Include="..\tier0\platform.cpp">
<Filter>sdk\tier0</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\client\cdll_engine_int.h">
@ -1580,6 +1583,9 @@
<ClInclude Include="..\mathlib\sha1.h">
<Filter>sdk\mathlib</Filter>
</ClInclude>
<ClInclude Include="..\tier0\platform_internal.h">
<Filter>sdk\tier0</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="..\shared\resource\lockedserver.png">