2022-02-28 01:01:40 +01:00
|
|
|
//=============================================================================//
|
|
|
|
//
|
|
|
|
// Purpose: General system utilities.
|
|
|
|
//
|
|
|
|
//=============================================================================//
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
#include "core/stdafx.h"
|
|
|
|
#include "core/logdef.h"
|
2022-01-14 20:45:36 +01:00
|
|
|
#include "tier0/commandline.h"
|
2022-04-09 16:16:40 +02:00
|
|
|
#include "tier1/cvar.h"
|
2021-12-25 22:36:38 +01:00
|
|
|
#include "engine/sys_utils.h"
|
2022-02-08 16:32:00 +01:00
|
|
|
#ifdef DEDICATED
|
2022-05-20 11:52:19 +02:00
|
|
|
#include "engine/server/sv_rcon.h"
|
2022-02-08 16:32:00 +01:00
|
|
|
#else
|
2022-02-19 02:31:16 +01:00
|
|
|
#include "vgui/vgui_debugpanel.h"
|
2022-01-14 20:45:36 +01:00
|
|
|
#endif // !DEDICATED
|
2022-05-09 02:20:07 +02:00
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-01-14 20:45:36 +01:00
|
|
|
// Purpose: Exit engine with error
|
|
|
|
// Input : *error -
|
|
|
|
// ... -
|
|
|
|
// Output : void Sys_Error
|
2021-12-25 22:36:38 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void HSys_Error(char* fmt, ...)
|
|
|
|
{
|
2022-01-14 20:45:36 +01:00
|
|
|
static char buf[1024] = {};
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-01-14 20:45:36 +01:00
|
|
|
va_list args{};
|
2021-12-25 22:36:38 +01:00
|
|
|
va_start(args, fmt);
|
|
|
|
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, args);
|
|
|
|
|
|
|
|
buf[sizeof(buf) -1] = 0;
|
|
|
|
va_end(args);
|
|
|
|
|
2022-09-14 01:14:51 +02:00
|
|
|
Error(eDLL_T::ENGINE, NO_ERROR, "%s", buf);
|
2022-06-20 15:04:27 +02:00
|
|
|
return v_Sys_Error(buf);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-01-14 20:45:36 +01:00
|
|
|
// Purpose: Show warning in the console, exit engine with error when level 5
|
|
|
|
// Input : level -
|
|
|
|
// *error - ... -
|
|
|
|
// Output : void* Sys_Warning
|
2021-12-25 22:36:38 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-01-14 20:45:36 +01:00
|
|
|
void* HSys_Warning(int level, char* fmt, ...)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-01-14 20:45:36 +01:00
|
|
|
static char buf[1024] = {};
|
2022-02-28 01:01:40 +01:00
|
|
|
{/////////////////////////////
|
|
|
|
va_list args{};
|
|
|
|
va_start(args, fmt);
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-02-28 01:01:40 +01:00
|
|
|
vsnprintf(buf, sizeof(buf), fmt, args);
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-08-09 15:19:12 +02:00
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
2022-02-28 01:01:40 +01:00
|
|
|
va_end(args);
|
|
|
|
}/////////////////////////////
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-08-09 15:19:12 +02:00
|
|
|
Warning(eDLL_T::COMMON, "Warning(%d):%s", level, buf);
|
2022-06-20 15:04:27 +02:00
|
|
|
return v_Sys_Warning(level, buf);
|
|
|
|
}
|
|
|
|
|
2022-02-28 01:01:40 +01:00
|
|
|
#ifndef DEDICATED
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Builds log to be displayed on the screen
|
|
|
|
// Input : pos -
|
|
|
|
// *fmt - ... -
|
|
|
|
// Output : void NPrintf
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void HCon_NPrintf(int pos, const char* fmt, ...)
|
|
|
|
{
|
|
|
|
if (cl_showhoststats->GetBool())
|
|
|
|
{
|
|
|
|
static char buf[1024] = {};
|
|
|
|
{/////////////////////////////
|
|
|
|
va_list args{};
|
|
|
|
va_start(args, fmt);
|
|
|
|
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, args);
|
|
|
|
|
2022-08-09 15:19:12 +02:00
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
2022-02-28 01:01:40 +01:00
|
|
|
va_end(args);
|
|
|
|
}/////////////////////////////
|
|
|
|
|
2022-10-26 01:55:36 +02:00
|
|
|
snprintf(g_pOverlay->m_pszCon_NPrintf_Buf,
|
|
|
|
sizeof(g_pOverlay->m_pszCon_NPrintf_Buf), buf);
|
2022-02-28 01:01:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // !DEDICATED
|
|
|
|
|
2022-06-20 14:58:53 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
void SysUtils_Attach()
|
|
|
|
{
|
2022-04-16 23:53:03 +02:00
|
|
|
//DetourAttach((LPVOID*)&Sys_Error, &HSys_Error);
|
2022-06-20 15:04:27 +02:00
|
|
|
DetourAttach((LPVOID*)&v_Sys_Warning, &HSys_Warning);
|
2022-02-28 01:01:40 +01:00
|
|
|
#ifndef DEDICATED
|
2022-06-20 15:04:27 +02:00
|
|
|
DetourAttach((LPVOID*)&v_Con_NPrintf, &HCon_NPrintf);
|
2022-02-28 01:01:40 +01:00
|
|
|
#endif // !DEDICATED
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SysUtils_Detach()
|
|
|
|
{
|
2022-04-16 23:53:03 +02:00
|
|
|
//DetourDetach((LPVOID*)&Sys_Error, &HSys_Error);
|
2022-06-20 15:04:27 +02:00
|
|
|
DetourDetach((LPVOID*)&v_Sys_Warning, &HSys_Warning);
|
2022-02-28 01:01:40 +01:00
|
|
|
#ifndef DEDICATED
|
2022-06-20 15:04:27 +02:00
|
|
|
DetourDetach((LPVOID*)&v_Con_NPrintf, &HCon_NPrintf);
|
2022-02-28 01:01:40 +01:00
|
|
|
#endif // !DEDICATED
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|