2022-03-11 16:28:08 -05:00
|
|
|
#include <std_include.hpp>
|
|
|
|
#include "loader/component_loader.hpp"
|
|
|
|
|
|
|
|
#include "party.hpp"
|
|
|
|
#include "console.hpp"
|
|
|
|
|
|
|
|
#include "game/game.hpp"
|
|
|
|
#include "game/dvars.hpp"
|
|
|
|
|
|
|
|
#include <utils/hook.hpp>
|
|
|
|
|
|
|
|
namespace logger
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
utils::hook::detour com_error_hook;
|
|
|
|
|
|
|
|
void print_error(const char* msg, ...)
|
|
|
|
{
|
|
|
|
char buffer[2048];
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, msg);
|
|
|
|
|
|
|
|
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
console::error(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_com_error(int, const char* msg, ...)
|
|
|
|
{
|
|
|
|
char buffer[2048];
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, msg);
|
|
|
|
|
|
|
|
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
console::error(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void com_error_stub(const int error, const char* msg, ...)
|
|
|
|
{
|
|
|
|
char buffer[2048];
|
|
|
|
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, msg);
|
|
|
|
|
|
|
|
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
console::error("Error: %s\n", buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
party::clear_sv_motd(); // clear sv_motd on error if it exists
|
|
|
|
|
|
|
|
com_error_hook.invoke<void>(error, "%s", buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_warning(const char* msg, ...)
|
|
|
|
{
|
|
|
|
char buffer[2048];
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, msg);
|
|
|
|
|
|
|
|
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
console::warn(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print(const char* msg, ...)
|
|
|
|
{
|
|
|
|
char buffer[2048];
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, msg);
|
|
|
|
|
|
|
|
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
console::info(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_dev(const char* msg, ...)
|
|
|
|
{
|
2022-03-12 18:56:15 -05:00
|
|
|
static auto* enabled = dvars::register_bool("logger_dev", false, game::DVAR_FLAG_SAVED, "Print dev stuff");
|
2022-03-11 16:28:08 -05:00
|
|
|
if (!enabled->current.enabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char buffer[2048];
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, msg);
|
|
|
|
|
|
|
|
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
console::info(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class component final : public component_interface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void post_unpack() override
|
|
|
|
{
|
2022-05-30 11:01:14 -04:00
|
|
|
if (!game::environment::is_dedi())
|
|
|
|
{
|
|
|
|
// lua stuff
|
|
|
|
utils::hook::jump(SELECT_VALUE(0x106010_b, 0x27CBB0_b), print_dev); // debug
|
|
|
|
utils::hook::jump(SELECT_VALUE(0x107680_b, 0x27E210_b), print_error); // error
|
|
|
|
utils::hook::jump(SELECT_VALUE(0x0E6E30_b, 0x1F6140_b), printf); // print
|
|
|
|
}
|
2022-05-29 10:44:18 -04:00
|
|
|
|
2022-03-11 16:28:08 -05:00
|
|
|
com_error_hook.create(game::Com_Error, com_error_stub);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-24 16:40:10 -04:00
|
|
|
REGISTER_COMPONENT(logger::component)
|