fix logger

This commit is contained in:
FutureRave 2022-10-13 22:38:06 +01:00
parent 924b5859d6
commit cbe4cd3557
No known key found for this signature in database
GPG Key ID: 22F9079C86CFAB31

View File

@ -1,12 +1,11 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "party.hpp"
#include "console.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include <utils/hook.hpp>
namespace logger
@ -15,48 +14,42 @@ namespace logger
{
utils::hook::detour com_error_hook;
const game::dvar_t* logger_dev = nullptr;
void print_error(const char* msg, ...)
{
char buffer[2048];
char buffer[2048]{};
va_list ap;
va_start(ap, msg);
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
vsnprintf_s(buffer, _TRUNCATE, msg, ap);
va_end(ap);
console::error(buffer);
console::error("%s", buffer);
}
void print_com_error(int, const char* msg, ...)
{
char buffer[2048];
char buffer[2048]{};
va_list ap;
va_start(ap, msg);
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
vsnprintf_s(buffer, _TRUNCATE, msg, ap);
va_end(ap);
console::error(buffer);
console::error("%s", buffer);
}
void com_error_stub(const int error, const char* msg, ...)
{
char buffer[2048];
char buffer[2048]{};
va_list ap;
{
va_list ap;
va_start(ap, msg);
va_start(ap, msg);
vsnprintf_s(buffer, _TRUNCATE, msg, ap);
va_end(ap);
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
va_end(ap);
console::error("Error: %s\n", buffer);
}
console::error("Error: %s\n", buffer);
party::clear_sv_motd(); // clear sv_motd on error if it exists
@ -65,50 +58,43 @@ namespace logger
void print_warning(const char* msg, ...)
{
char buffer[2048];
char buffer[2048]{};
va_list ap;
va_start(ap, msg);
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
vsnprintf_s(buffer, _TRUNCATE, msg, ap);
va_end(ap);
console::warn(buffer);
console::warn("%s", buffer);
}
void print(const char* msg, ...)
{
char buffer[2048];
char buffer[2048]{};
va_list ap;
va_start(ap, msg);
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
vsnprintf_s(buffer, _TRUNCATE, msg, ap);
va_end(ap);
console::info(buffer);
console::info("%s", buffer);
}
void print_dev(const char* msg, ...)
{
static auto* enabled = dvars::register_bool("logger_dev", false, game::DVAR_FLAG_SAVED, "Print dev stuff");
if (!enabled->current.enabled)
if (!logger_dev->current.enabled)
{
return;
}
char buffer[2048];
char buffer[2048]{};
va_list ap;
va_start(ap, msg);
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
vsnprintf_s(buffer, _TRUNCATE, msg, ap);
va_end(ap);
console::info(buffer);
console::info("%s", buffer);
}
}
@ -126,6 +112,8 @@ namespace logger
}
com_error_hook.create(game::Com_Error, com_error_stub);
logger_dev = dvars::register_bool("logger_dev", false, game::DVAR_FLAG_SAVED, "Print dev stuff");
}
};
}