2022-02-28 01:01:40 +01:00
|
|
|
//=============================================================================//
|
|
|
|
//
|
|
|
|
// Purpose: General system utilities.
|
|
|
|
//
|
|
|
|
//=============================================================================//
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
#include "core/stdafx.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
|
|
|
|
2023-02-19 09:51:46 +01:00
|
|
|
#if !defined( _X360 )
|
|
|
|
#define MAXPRINTMSG 4096
|
|
|
|
#else
|
|
|
|
#define MAXPRINTMSG 1024
|
|
|
|
#endif
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-02-19 09:51:46 +01:00
|
|
|
// Purpose: Show error in the console
|
2022-01-14 20:45:36 +01:00
|
|
|
// Input : *error -
|
|
|
|
// ... -
|
2023-02-19 09:51:46 +01:00
|
|
|
// Output : void _Error
|
2021-12-25 22:36:38 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2023-02-19 09:51:46 +01:00
|
|
|
void _Error(char* fmt, ...)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-02-19 09:51:46 +01:00
|
|
|
char buf[4096];
|
2023-05-22 23:17:50 +02:00
|
|
|
bool shouldNewline = true;
|
2023-03-26 16:09:05 +02:00
|
|
|
{/////////////////////////////
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2023-05-22 23:17:50 +02:00
|
|
|
int len = vsnprintf(buf, sizeof(buf), fmt, args);
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2023-03-26 16:09:05 +02:00
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
|
|
|
va_end(args);
|
2023-05-22 23:17:50 +02:00
|
|
|
|
|
|
|
if (len > 0)
|
|
|
|
shouldNewline = buf[len-1] != '\n';
|
2023-03-26 16:09:05 +02:00
|
|
|
}/////////////////////////////
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2023-05-22 23:17:50 +02:00
|
|
|
Error(eDLL_T::ENGINE, NO_ERROR, shouldNewline ? "%s\n" : "%s", buf);
|
2023-04-08 20:13:06 +02:00
|
|
|
v_Error("%s", 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 - ... -
|
2023-02-19 09:51:46 +01:00
|
|
|
// Output : void* _Warning
|
2021-12-25 22:36:38 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2023-02-26 19:34:42 +01:00
|
|
|
void _Warning(int level, char* fmt, ...)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-02-19 09:51:46 +01:00
|
|
|
char buf[10000];
|
2023-05-22 23:17:50 +02:00
|
|
|
bool shouldNewline = true;
|
2022-02-28 01:01:40 +01:00
|
|
|
{/////////////////////////////
|
2023-03-26 16:09:05 +02:00
|
|
|
va_list args;
|
2022-02-28 01:01:40 +01:00
|
|
|
va_start(args, fmt);
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2023-05-22 23:17:50 +02:00
|
|
|
int len = 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);
|
2023-05-22 23:17:50 +02:00
|
|
|
|
|
|
|
if (len > 0)
|
|
|
|
shouldNewline = buf[len - 1] != '\n';
|
2022-02-28 01:01:40 +01:00
|
|
|
}/////////////////////////////
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2023-02-19 09:51:46 +01:00
|
|
|
if (level < 5)
|
|
|
|
{
|
2023-07-22 21:14:04 +02:00
|
|
|
Warning(eDLL_T::ENGINE, shouldNewline ? "Warning(%d):%s\n" : "Warning(%d):%s", level, buf);
|
2023-02-19 09:51:46 +01:00
|
|
|
}
|
|
|
|
|
2023-04-08 20:13:06 +02:00
|
|
|
v_Warning(level, "%s", buf);
|
2022-06-20 15:04:27 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-02-19 09:51:46 +01:00
|
|
|
void _Con_NPrintf(int pos, const char* fmt, ...)
|
2022-02-28 01:01:40 +01:00
|
|
|
{
|
2023-02-19 09:51:46 +01:00
|
|
|
char buf[MAXPRINTMSG];
|
|
|
|
{/////////////////////////////
|
2023-03-26 16:09:05 +02:00
|
|
|
va_list args;
|
2023-02-19 09:51:46 +01:00
|
|
|
va_start(args, fmt);
|
2022-02-28 01:01:40 +01:00
|
|
|
|
2023-02-19 09:51:46 +01:00
|
|
|
vsnprintf(buf, sizeof(buf), fmt, args);
|
2022-02-28 01:01:40 +01:00
|
|
|
|
2023-02-19 09:51:46 +01:00
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
|
|
|
va_end(args);
|
|
|
|
}/////////////////////////////
|
2022-02-28 01:01:40 +01:00
|
|
|
|
2023-02-19 09:51:46 +01:00
|
|
|
g_pOverlay->m_nCon_NPrintf_Idx = pos;
|
|
|
|
snprintf(g_pOverlay->m_szCon_NPrintf_Buf,
|
2023-04-08 19:10:59 +02:00
|
|
|
sizeof(g_pOverlay->m_szCon_NPrintf_Buf), "%s", 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);
|
|
|
|
}
|
|
|
|
|
2023-01-25 02:26:52 +01:00
|
|
|
void VSys_Utils::Attach() const
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-02-19 09:51:46 +01:00
|
|
|
DetourAttach((LPVOID*)&v_Error, &_Error);
|
|
|
|
DetourAttach((LPVOID*)&v_Warning, &_Warning);
|
2022-02-28 01:01:40 +01:00
|
|
|
#ifndef DEDICATED
|
2023-02-19 09:51:46 +01:00
|
|
|
DetourAttach((LPVOID*)&v_Con_NPrintf, &_Con_NPrintf);
|
2022-02-28 01:01:40 +01:00
|
|
|
#endif // !DEDICATED
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
2023-01-25 02:26:52 +01:00
|
|
|
void VSys_Utils::Detach() const
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-02-19 09:51:46 +01:00
|
|
|
DetourDetach((LPVOID*)&v_Error, &_Error);
|
|
|
|
DetourDetach((LPVOID*)&v_Warning, &_Warning);
|
2022-02-28 01:01:40 +01:00
|
|
|
#ifndef DEDICATED
|
2023-02-19 09:51:46 +01:00
|
|
|
DetourDetach((LPVOID*)&v_Con_NPrintf, &_Con_NPrintf);
|
2022-02-28 01:01:40 +01:00
|
|
|
#endif // !DEDICATED
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|