h2-mod/src/client/component/branding.cpp

64 lines
1.3 KiB
C++
Raw Normal View History

2021-09-07 00:40:37 +02:00
#include <std_include.hpp>
2021-08-29 13:48:38 -05:00
#include "loader/component_loader.hpp"
2023-02-25 01:57:36 +01:00
#include "game/game.hpp"
#include "game/dvars.hpp"
2021-08-29 13:48:38 -05:00
#include "scheduler.hpp"
#include "command.hpp"
2022-02-02 23:58:46 +01:00
2021-08-29 13:48:38 -05:00
#include <utils/hook.hpp>
#include <utils/string.hpp>
2022-02-02 23:58:46 +01:00
#include <version.h>
2021-08-29 13:48:38 -05:00
namespace branding
{
2022-02-02 23:58:46 +01:00
namespace
{
float color[4] = {0.9f, 0.9f, 0.5f, 1.f};
2023-02-25 01:57:36 +01:00
utils::hook::detour ui_get_formatted_build_number_hook;
const char* ui_get_formatted_build_number_stub()
2022-02-02 23:58:46 +01:00
{
2023-02-25 01:57:36 +01:00
const auto* const build_num = ui_get_formatted_build_number_hook.invoke<const char*>();
return utils::string::va("%s (%s)", VERSION, build_num);
2022-02-02 23:58:46 +01:00
}
2021-12-29 02:29:22 +01:00
2022-02-06 21:36:49 +01:00
void draw()
{
2023-02-25 01:57:36 +01:00
const auto font = game::R_RegisterFont("fonts/fira_mono_bold.ttf", 22);
if (!font)
{
return;
}
const auto placement = game::ScrPlace_GetViewPlacement();
game::rectDef_s rect{};
rect.x = 0;
rect.y = 0;
rect.w = 500;
rect.horzAlign = 1;
rect.vertAlign = 0;
game::rectDef_s text_rect{};
game::UI_DrawWrappedText(placement, "h2-mod", &rect, font,
2023-02-28 18:50:11 +01:00
5.f, 12.f, 0.17f, color, 0, 0, &text_rect, 0);
2022-02-06 21:36:49 +01:00
}
}
2021-08-29 13:48:38 -05:00
class component final : public component_interface
{
public:
void post_unpack() override
{
2022-02-06 21:36:49 +01:00
scheduler::loop(draw, scheduler::pipeline::renderer);
2023-02-25 01:57:36 +01:00
ui_get_formatted_build_number_hook.create(0x1406057D0, ui_get_formatted_build_number_stub);
2021-08-29 13:48:38 -05:00
}
};
}
REGISTER_COMPONENT(branding::component)