2022-01-30 18:23:42 -05:00
|
|
|
#include <std_include.hpp>
|
|
|
|
#include "loader/component_loader.hpp"
|
|
|
|
|
|
|
|
#include "game/game.hpp"
|
|
|
|
#include "game_console.hpp"
|
|
|
|
#include "game/dvars.hpp"
|
|
|
|
|
|
|
|
#include <utils/hook.hpp>
|
|
|
|
|
|
|
|
namespace logger
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
utils::hook::detour com_error_hook;
|
|
|
|
utils::hook::detour nullsub_48_hook;
|
|
|
|
utils::hook::detour sub_32AEF0;
|
|
|
|
|
2022-06-17 14:00:39 -04:00
|
|
|
game::dvar_t* logger_dev = nullptr;
|
|
|
|
|
2022-01-30 18:23:42 -05:00
|
|
|
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);
|
|
|
|
|
|
|
|
game_console::print(game_console::con_type_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);
|
|
|
|
|
|
|
|
game_console::print(game_console::con_type_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);
|
|
|
|
|
|
|
|
game_console::print(game_console::con_type_error, "Error: %s\n", buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
game_console::print(game_console::con_type_warning, 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);
|
|
|
|
|
|
|
|
game_console::print(game_console::con_type_info, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_dev(const char* msg, ...)
|
|
|
|
{
|
2022-06-17 14:00:39 -04:00
|
|
|
if (!logger_dev->current.enabled)
|
2022-01-30 18:23:42 -05:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char buffer[2048];
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, msg);
|
|
|
|
|
|
|
|
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
game_console::print(game_console::con_type_info, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lui_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);
|
|
|
|
|
|
|
|
if (strstr(msg, "LUI WARNING:"))
|
|
|
|
{
|
|
|
|
game_console::print(game_console::con_type_warning, buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-17 14:00:39 -04:00
|
|
|
if (!logger_dev->current.enabled)
|
2022-01-30 18:23:42 -05:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
game_console::print(game_console::con_type_info, buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class component final : public component_interface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void post_unpack() override
|
|
|
|
{
|
2022-03-18 17:02:44 -04:00
|
|
|
utils::hook::jump(0x14032C620, print_warning, true);
|
|
|
|
utils::hook::jump(0x14032C630, print_warning, true);
|
|
|
|
utils::hook::jump(0x14032AEF0, lui_print, true);
|
|
|
|
com_error_hook.create(0x1405A2D80, com_error_stub);
|
2022-04-29 15:51:25 -04:00
|
|
|
utils::hook::jump(0x14013A98C, print);
|
2022-06-17 14:00:39 -04:00
|
|
|
|
|
|
|
logger_dev = dvars::register_bool("logger_dev", false, game::DVAR_FLAG_SAVED, "Print dev stuff");
|
2022-01-30 18:23:42 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_COMPONENT(logger::component)
|