Merge pull request #473 from diamante0018/develop

Fix logger
This commit is contained in:
Maurice Heumann 2022-10-14 07:40:19 +02:00 committed by GitHub
commit 6b8559609f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,8 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "party.hpp"
#include "game/game.hpp"
#include "console.hpp"
#include <utils/hook.hpp>
@ -13,48 +13,42 @@ namespace logger
{
utils::hook::detour com_error_hook;
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
@ -63,51 +57,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 =
game::Dvar_RegisterBool("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);
}
// nullsub_56
@ -166,6 +152,9 @@ namespace logger
{
nullsub_56();
sub_1400E7420();
// Make havok script's print function actually print
utils::hook::jump(0x140701A1C, print);
}
if (!game::environment::is_sp())
@ -175,8 +164,7 @@ namespace logger
com_error_hook.create(game::Com_Error, com_error_stub);
// Make havok script's print function actually print
utils::hook::jump(0x140701A1C, print);
logger_dev = game::Dvar_RegisterBool("logger_dev", false, game::DVAR_FLAG_SAVED, "Print dev stuff");
}
};
}