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"
|
2021-12-25 22:36:38 +01:00
|
|
|
#include "gameui/IConsole.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-05-09 02:20:07 +02:00
|
|
|
Error(eDLL_T::ENGINE, "%s\n", buf);
|
2022-02-06 15:43:05 +01:00
|
|
|
return 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-02-28 01:01:40 +01:00
|
|
|
buf[sizeof(buf) - 1] = 0;
|
|
|
|
va_end(args);
|
|
|
|
}/////////////////////////////
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-05-09 02:20:07 +02:00
|
|
|
Warning(eDLL_T::NONE, "Warning(%d):%s\n", level, buf);
|
2022-01-14 20:45:36 +01:00
|
|
|
return Sys_Warning(level, buf);
|
|
|
|
}
|
2021-12-25 22:36:38 +01: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
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
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);
|
|
|
|
|
|
|
|
buf[sizeof(buf) - 1] = 0;
|
|
|
|
va_end(args);
|
|
|
|
}/////////////////////////////
|
|
|
|
|
|
|
|
snprintf((char*)g_pLogSystem.m_pszCon_NPrintf_Buf, 4096, buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // !DEDICATED
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-01-14 20:45:36 +01:00
|
|
|
// Purpose: Load assets from a custom directory if file exists
|
|
|
|
// Input : *lpFileName -
|
|
|
|
// a2 - *a3 -
|
|
|
|
// Output : void* Sys_LoadAssetHelper
|
2021-12-25 22:36:38 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void* HSys_LoadAssetHelper(const CHAR* lpFileName, std::int64_t a2, LARGE_INTEGER* a3)
|
|
|
|
{
|
|
|
|
std::string mod_file;
|
|
|
|
std::string base_file = lpFileName;
|
2022-04-25 04:05:42 +02:00
|
|
|
static const std::string mod_dir = "paks\\Win32\\";
|
|
|
|
static const std::string base_dir = "paks\\Win64\\";
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
if (strstr(lpFileName, base_dir.c_str()))
|
|
|
|
{
|
|
|
|
base_file.erase(0, 11); // Erase 'base_dir'.
|
|
|
|
mod_file = mod_dir + base_file; // Prepend 'mod_dir'.
|
|
|
|
|
|
|
|
if (FileExists(mod_file.c_str()))
|
|
|
|
{
|
|
|
|
// Load decompressed pak files from 'mod_dir'.
|
|
|
|
return Sys_LoadAssetHelper(mod_file.c_str(), a2, a3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Sys_LoadAssetHelper(lpFileName, a2, a3);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SysUtils_Attach()
|
|
|
|
{
|
2022-04-16 23:53:03 +02:00
|
|
|
//DetourAttach((LPVOID*)&Sys_Error, &HSys_Error);
|
2022-01-14 20:45:36 +01:00
|
|
|
DetourAttach((LPVOID*)&Sys_Warning, &HSys_Warning);
|
2021-12-25 22:36:38 +01:00
|
|
|
DetourAttach((LPVOID*)&Sys_LoadAssetHelper, &HSys_LoadAssetHelper);
|
2022-02-28 01:01:40 +01:00
|
|
|
#ifndef DEDICATED
|
|
|
|
DetourAttach((LPVOID*)&Con_NPrintf, &HCon_NPrintf);
|
|
|
|
#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-01-14 20:45:36 +01:00
|
|
|
DetourDetach((LPVOID*)&Sys_Warning, &HSys_Warning);
|
2021-12-25 22:36:38 +01:00
|
|
|
DetourDetach((LPVOID*)&Sys_LoadAssetHelper, &HSys_LoadAssetHelper);
|
2022-02-28 01:01:40 +01:00
|
|
|
#ifndef DEDICATED
|
|
|
|
DetourDetach((LPVOID*)&Con_NPrintf, &HCon_NPrintf);
|
|
|
|
#endif // !DEDICATED
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|