iw7-mod/src/client/component/logger.cpp

105 lines
2.0 KiB
C++
Raw Normal View History

2022-05-20 14:59:24 -04:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "console.hpp"
#include <utils/hook.hpp>
namespace logger
{
namespace
{
2022-05-25 07:48:49 -04:00
void sys_print_stub(const char* msg)
2022-05-20 14:59:24 -04:00
{
2022-05-25 07:48:49 -04:00
console::info(msg);
2022-05-20 14:59:24 -04:00
}
2022-06-08 20:53:48 -04:00
void print_info(const char* msg, ...)
2022-06-01 09:55:00 -04:00
{
2022-06-08 20:53:48 -04:00
char buffer[0x1000]{ 0 };
2022-06-01 09:55:00 -04:00
va_list ap;
va_start(ap, msg);
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
va_end(ap);
console::info(buffer);
}
2022-06-08 20:53:48 -04:00
void print_warn(const char* msg, ...)
2022-05-20 14:59:24 -04:00
{
2022-06-08 20:53:48 -04:00
char buffer[0x1000]{ 0 };
va_list ap;
va_start(ap, msg);
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
va_end(ap);
console::warn(buffer);
}
void print_error(const char* msg, ...)
{
char buffer[0x1000]{ 0 };
va_list ap;
va_start(ap, msg);
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
va_end(ap);
console::error(buffer);
}
void print_debug(const char* msg, ...)
{
char buffer[0x1000]{ 0 };
va_list ap;
va_start(ap, msg);
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
va_end(ap);
console::debug(buffer);
2022-05-20 14:59:24 -04:00
}
2022-06-08 20:53:48 -04:00
void r_warn_once_per_frame_vsnprintf_stub(char* buffer, size_t buffer_length, char* msg, va_list va)
2022-05-20 14:59:24 -04:00
{
vsnprintf(buffer, buffer_length, msg, va);
console::warn(buffer);
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
2022-06-08 20:53:48 -04:00
// Sys_Print
utils::hook::call(0xC6E57A_b, sys_print_stub); // SV_SpawnServer: completed\n
utils::hook::call(0xC13641_b, sys_print_stub); // SV_CmdsSP_MapRestart: completed\n
utils::hook::jump(0x519772_b, sys_print_stub); // OnlineAutoTest:: Map load success. Server is listen.\n
utils::hook::call(0xB712BA_b, sys_print_stub); // G_SaveError
2022-05-20 14:59:24 -04:00
2022-06-08 20:53:48 -04:00
// Com_Printf
utils::hook::jump(0x343080_b, print_info);
2022-06-01 09:55:00 -04:00
2022-05-20 14:59:24 -04:00
if (!game::environment::is_dedi())
{
2022-06-08 20:53:48 -04:00
// R_WarnOncePerFrame
utils::hook::call(0xE4B121_b, r_warn_once_per_frame_vsnprintf_stub);
2022-05-20 14:59:24 -04:00
}
}
};
}
2022-06-08 20:53:48 -04:00
REGISTER_COMPONENT(logger::component)