r5sdk/r5dev/engine/sys_utils.h
Kawe Mazidjatari f120354e96 Initial port to CMake
* All libraries have been isolated from each other, and build into separate artifacts.
* Project has been restructured to support isolating libraries.
* CCrashHandler now calls a callback on crash (setup from core/dllmain.cpp, this can be setup in any way for any project. This callback is getting called when the apllication crashes. Useful for flushing buffers before closing handles to logging files for example).
* Tier0 'CoreMsgV' function now calls a callback sink, which could be set by the user (currently setup to the SDK's internal logger in core/dllmain.cpp).

TODO:
* Add a batch file to autogenerate all projects.
* Add support for dedicated server.
* Add support for client dll.

Bugs:
* Game crashes on the title screen after the UI script compiler has finished (root cause unknown).
* Curl error messages are getting logged twice for the dedicated server due to the removal of all "DEDICATED" preprocessor directives to support isolating projects. This has to be fixed properly!
2023-05-10 00:05:38 +02:00

54 lines
2.6 KiB
C++

#pragma once
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inline CMemory p_Error;
inline auto v_Error = p_Error.RCast<void (*)(const char* fmt, ...)>();
inline CMemory p_Warning;
inline auto v_Warning = p_Warning.RCast<void (*)(int, const char* fmt, ...)>();
inline CMemory p_Sys_GetProcessUpTime;
inline auto v_Sys_GetProcessUpTime = p_Sys_GetProcessUpTime.RCast<int (*)(char* szBuffer)>();
#ifndef DEDICATED
inline CMemory p_Con_NPrintf;
inline auto v_Con_NPrintf = p_Con_NPrintf.RCast<void (*)(int pos, const char* fmt, ...)>();
#endif // !DEDICATED
/* ==== ------- ========================================================================================================================================================= */
///////////////////////////////////////////////////////////////////////////////
int Sys_GetProcessUpTime(char* szBuffer);
///////////////////////////////////////////////////////////////////////////////
class VSys_Utils : public IDetour
{
virtual void GetAdr(void) const
{
LogFunAdr("Error", p_Error.GetPtr());
LogFunAdr("Warning", p_Warning.GetPtr());
LogFunAdr("Sys_GetProcessUpTime", p_Sys_GetProcessUpTime.GetPtr());
#ifndef DEDICATED
LogFunAdr("Con_NPrintf", p_Con_NPrintf.GetPtr());
#endif // !DEDICATED
}
virtual void GetFun(void) const
{
p_Error = g_GameDll.FindPatternSIMD("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 ?? ?? E8");
p_Warning = g_GameDll.FindPatternSIMD("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 ?? ?? ?? ??");
p_Sys_GetProcessUpTime = g_GameDll.FindPatternSIMD("40 57 48 83 EC 30 48 8B F9 8B 0D ?? ?? ?? ??");
#ifndef DEDICATED
p_Con_NPrintf = g_GameDll.FindPatternSIMD("48 89 4C 24 ?? 48 89 54 24 ?? 4C 89 44 24 ?? 4C 89 4C 24 ?? C3");
#endif // !DEDICATED
v_Error = p_Error.RCast<void (*)(const char*, ...)>();
v_Warning = p_Warning.RCast<void (*)(int, const char*, ...)>();
v_Sys_GetProcessUpTime = p_Sys_GetProcessUpTime.RCast<int (*)(char*)>();
#ifndef DEDICATED
v_Con_NPrintf = p_Con_NPrintf.RCast<void (*)(int, const char*, ...)>();
#endif // !DEDICATED
}
virtual void GetVar(void) const { }
virtual void GetCon(void) const { }
virtual void Attach(void) const;
virtual void Detach(void) const;
};
///////////////////////////////////////////////////////////////////////////////