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

87 lines
2.8 KiB
C++
Raw Normal View History

2022-05-20 21:59:24 +03:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "localized_strings.hpp"
#include "scheduler.hpp"
#include "version.hpp"
#include "game/game.hpp"
2022-09-17 20:19:30 +03:00
#include "game/dvars.hpp"
2023-02-10 19:44:53 +00:00
#include "utils/hook.hpp"
#include <utils/string.hpp>
2022-05-20 21:59:24 +03:00
namespace branding
{
namespace
{
2023-02-10 19:44:53 +00:00
utils::hook::detour ui_get_formatted_build_number_hook;
const char* ui_get_formatted_build_number_stub()
{
2024-03-07 22:34:03 -06:00
const auto build_num = ui_get_formatted_build_number_hook.invoke<const char*>();
2023-02-10 19:44:53 +00:00
return utils::string::va("%s (%s)", VERSION, build_num);
}
2022-05-20 21:59:24 +03:00
}
class component final : public component_interface
{
public:
void post_unpack() override
{
2022-06-01 16:55:00 +03:00
if (game::environment::is_dedi())
{
return;
}
2022-05-25 14:48:49 +03:00
localized_strings::override("LUA_MENU_LEGAL_COPYRIGHT", "IW7-MOD");
2022-06-01 16:55:00 +03:00
//localized_strings::override("MENU_SP_CAMPAIGN", "IW7-MOD: CAMPAIGN");
//localized_strings::override("LUA_MENU_MULTIPLAYER_CAPS", "IW7-MOD: MULTIPLAYER");
//localized_strings::override("LUA_MENU_ALIENS_CAPS", "IW7-MOD: ZOMBIES");
2022-05-20 21:59:24 +03:00
2022-06-01 16:55:00 +03:00
scheduler::once([]()
{
2024-07-13 22:46:07 +03:00
dvars::branding = game::Dvar_RegisterBool("branding", true, game::DvarFlags::DVAR_FLAG_SAVED, "Show branding");
2022-06-01 16:55:00 +03:00
}, scheduler::pipeline::renderer);
2022-05-20 21:59:24 +03:00
2024-07-14 00:01:42 +03:00
#if GIT_DIRTY == 1
2024-07-13 22:46:07 +03:00
static char version_buffer[0x100]{};
sprintf_s(version_buffer, sizeof(version_buffer), "%s %s build %s %s %s", BUILD_NAME, VERSION, __DATE__, __TIME__, TARGET_ARCHITECTURE);
#endif
2022-05-20 21:59:24 +03:00
scheduler::loop([]()
{
2022-09-17 20:19:30 +03:00
if (dvars::branding && dvars::branding->current.enabled)
2022-05-20 21:59:24 +03:00
{
2024-07-14 00:01:42 +03:00
#if GIT_DIRTY == 1
2024-07-14 02:07:15 +03:00
const auto font = game::R_RegisterFont("fonts/blender_pro_medium.ttf", 32);
2024-07-13 22:46:07 +03:00
if (!font) return;
static const auto offset_from_corner = 75.0f;
static float text_color[4] = { 0.4f, 0.69f, 1.0f, 0.69f };
const auto* placement = game::ScrPlace_GetViewPlacement();
const auto x = (placement->realViewportSize[0] - offset_from_corner) - (game::R_TextWidth(version_buffer, std::numeric_limits<int>::max(), font));
const auto height = (placement->realViewportSize[1] - offset_from_corner) + 5.0f; // remove some off the offset
game::R_AddCmdDrawText(version_buffer, std::numeric_limits<int>::max(), font, static_cast<float>(x),
height + static_cast<float>(font->pixelHeight),
1.0f, 1.0f, 0.0f, text_color, game::FONT_STYLE_SHADOW);
#else
const auto font = game::R_RegisterFont("fonts/fira_mono_regular.ttf", 16);
if (!font) return;
static float text_color[4] = { 0.860f, 0.459f, 0.925f, 0.400f };
game::R_AddCmdDrawText("iw7-mod: " VERSION, std::numeric_limits<int>::max(), font, 10.f,
5.f + static_cast<float>(font->pixelHeight), 1.f, 1.f, 0.0f, text_color, 0);
#endif
2022-05-20 21:59:24 +03:00
}
}, scheduler::pipeline::renderer);
2023-02-10 19:44:53 +00:00
2024-07-03 19:34:50 +03:00
ui_get_formatted_build_number_hook.create(0x140CD1170, ui_get_formatted_build_number_stub);
2022-05-20 21:59:24 +03:00
}
};
}
2024-03-07 22:34:03 -06:00
REGISTER_COMPONENT(branding::component)