ReGameDLL_CS/regamedll/dlls/debug.cpp

203 lines
3.9 KiB
C++
Raw Normal View History

2015-06-30 12:46:07 +03:00
#include "precompiled.h"
2017-10-12 17:50:56 +03:00
DebugOutputLevel outputLevel[] =
2015-06-30 12:46:07 +03:00
{
2017-10-12 17:50:56 +03:00
{ "bot", DEBUG_BOT },
{ "career", DEBUG_CAREER },
{ "tutor", DEBUG_TUTOR },
{ "stats", DEBUG_STATS },
{ "hostage", DEBUG_HOSTAGE },
2017-10-12 17:50:56 +03:00
{ "all", DEBUG_ALL },
2015-06-30 12:46:07 +03:00
};
unsigned int theDebugOutputTypes;
char theDebugBuffer[MAX_DEBUG_BUFF_SIZE];
2015-06-30 12:46:07 +03:00
bool IsDeveloper()
2015-06-30 12:46:07 +03:00
{
return (CVAR_GET_FLOAT("developer") > 0.0);
}
NOXREF void UTIL_DPrintf(DebugOutputType outputType, char *pszMsg, ...)
{
2015-08-20 13:35:01 +03:00
if (!IsDeveloper())
return;
2015-06-30 12:46:07 +03:00
2015-08-20 13:35:01 +03:00
if (theDebugOutputTypes & outputType)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
va_list argptr;
va_start(argptr, pszMsg);
vsprintf(theDebugBuffer, pszMsg, argptr);
va_end(argptr);
SERVER_PRINT(theDebugBuffer);
2015-06-30 12:46:07 +03:00
}
}
void UTIL_DPrintf(char *pszMsg, ...)
{
2015-08-20 13:35:01 +03:00
if (!IsDeveloper())
return;
2015-06-30 12:46:07 +03:00
va_list argptr;
va_start(argptr, pszMsg);
2015-08-20 13:35:01 +03:00
vsprintf(theDebugBuffer, pszMsg, argptr);
va_end(argptr);
2015-06-30 12:46:07 +03:00
2015-08-20 13:35:01 +03:00
SERVER_PRINT(theDebugBuffer);
2015-06-30 12:46:07 +03:00
}
void PrintDebugFlags()
2015-06-30 12:46:07 +03:00
{
char *tmp;
2017-10-12 17:50:56 +03:00
int remainder = MAX_DEBUG_BUFF_SIZE;
2015-06-30 12:46:07 +03:00
2015-08-20 13:35:01 +03:00
theDebugBuffer[0] = '\0';
2015-06-30 12:46:07 +03:00
tmp = BufPrintf(theDebugBuffer, remainder, "mp_debug:\n");
for (auto level : outputLevel) {
2015-08-20 13:35:01 +03:00
tmp = BufPrintf(tmp, remainder, " %s: %s\n", level.name, (theDebugOutputTypes & level.value) ? "on" : "off");
2015-06-30 12:46:07 +03:00
}
2015-06-30 12:46:07 +03:00
SERVER_PRINT(theDebugBuffer);
}
2015-08-20 13:35:01 +03:00
void SetDebugFlag(const char *flagStr, bool state)
2015-06-30 12:46:07 +03:00
{
if (flagStr)
2015-12-09 01:39:54 +03:00
{
for (auto level : outputLevel)
2015-12-09 01:39:54 +03:00
{
if (FStrEq(level.name, flagStr))
{
DebugOutputType flag = level.value;
2015-12-09 01:39:54 +03:00
if (state)
theDebugOutputTypes |= flag;
else
theDebugOutputTypes &= ~flag;
SERVER_PRINT(SharedVarArgs("mp_debug: %s is now %s\n", flagStr, state ? "on" : "off"));
return;
}
}
}
2015-08-20 13:35:01 +03:00
SERVER_PRINT(SharedVarArgs("mp_debug: unknown variable '%s'\n", flagStr));
2015-06-30 12:46:07 +03:00
}
2015-08-20 13:35:01 +03:00
void PrintDebugFlag(const char *flagStr)
2015-06-30 12:46:07 +03:00
{
if (flagStr)
2015-12-09 01:39:54 +03:00
{
for (auto level : outputLevel)
2015-12-09 01:39:54 +03:00
{
if (FStrEq(level.name, flagStr))
{
SERVER_PRINT(SharedVarArgs("mp_debug: %s is %s\n", flagStr, (level.value & theDebugOutputTypes) ? "on" : "off"));
2015-12-09 01:39:54 +03:00
return;
}
}
}
2015-08-20 13:35:01 +03:00
SERVER_PRINT(SharedVarArgs("mp_debug: unknown variable '%s'\n", flagStr));
2015-06-30 12:46:07 +03:00
}
2015-08-20 13:35:01 +03:00
void UTIL_SetDprintfFlags(const char *flagStr)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
if (!IsDeveloper())
return;
if (!flagStr || !flagStr[0]) {
PrintDebugFlags();
return;
2015-08-20 13:35:01 +03:00
}
if (flagStr[0] == '+')
SetDebugFlag(&flagStr[1], true);
else if (flagStr[0] == '-')
SetDebugFlag(&flagStr[1], false);
2015-08-20 13:35:01 +03:00
else
PrintDebugFlag(flagStr);
2015-06-30 12:46:07 +03:00
}
2015-08-20 13:35:01 +03:00
NOXREF void UTIL_BotDPrintf(char *pszMsg, ...)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
if (!IsDeveloper())
return;
if (theDebugOutputTypes & DEBUG_BOT)
{
va_list argptr;
va_start(argptr, pszMsg);
vsprintf(theDebugBuffer, pszMsg, argptr);
va_end(argptr);
SERVER_PRINT(theDebugBuffer);
}
2015-06-30 12:46:07 +03:00
}
2015-08-20 13:35:01 +03:00
void UTIL_CareerDPrintf(char *pszMsg, ...)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
if (!IsDeveloper())
return;
if (theDebugOutputTypes & DEBUG_CAREER)
{
va_list argptr;
va_start(argptr, pszMsg);
vsprintf(theDebugBuffer, pszMsg, argptr);
va_end(argptr);
SERVER_PRINT(theDebugBuffer);
}
2015-06-30 12:46:07 +03:00
}
2015-08-20 13:35:01 +03:00
NOXREF void UTIL_TutorDPrintf(char *pszMsg, ...)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
if (!IsDeveloper())
return;
if (theDebugOutputTypes & DEBUG_TUTOR)
{
va_list argptr;
va_start(argptr, pszMsg);
vsprintf(theDebugBuffer, pszMsg, argptr);
va_end(argptr);
SERVER_PRINT(theDebugBuffer);
}
2015-06-30 12:46:07 +03:00
}
2015-08-20 13:35:01 +03:00
NOXREF void UTIL_StatsDPrintf(char *pszMsg, ...)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
if (!IsDeveloper())
return;
if (theDebugOutputTypes & DEBUG_STATS)
{
va_list argptr;
va_start(argptr, pszMsg);
vsprintf(theDebugBuffer, pszMsg, argptr);
va_end(argptr);
SERVER_PRINT(theDebugBuffer);
}
2015-06-30 12:46:07 +03:00
}
2015-08-20 13:35:01 +03:00
NOXREF void UTIL_HostageDPrintf(char *pszMsg, ...)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
if (!IsDeveloper())
return;
if (theDebugOutputTypes & DEBUG_HOSTAGE)
{
va_list argptr;
va_start(argptr, pszMsg);
vsprintf(theDebugBuffer, pszMsg, argptr);
va_end(argptr);
SERVER_PRINT(theDebugBuffer);
}
2015-06-30 12:46:07 +03:00
}