iw4x-client/src/Components/Modules/Branding.cpp

123 lines
4.4 KiB
C++
Raw Normal View History

2022-04-15 08:50:22 -04:00
#include <STDInclude.hpp>
namespace Components
{
Dvar::Var Branding::CGDrawVersion;
Dvar::Var Branding::CGDrawVersionX;
Dvar::Var Branding::CGDrawVersionY;
Game::dvar_t** Branding::Version = reinterpret_cast<Game::dvar_t**>(0x1AD7930);
void Branding::CG_DrawVersion()
{
// Default values
constexpr auto fontScale = 0.25f;
constexpr auto maxChars = std::numeric_limits<int>::max();
// Default colours
2022-04-21 14:37:14 -04:00
constexpr Game::vec4_t shadowColor = {0.0f, 0.0f, 0.0f, 0.69f};
constexpr Game::vec4_t color = {0.4f, 0.69f, 1.0f, 0.69f};
2022-04-15 08:50:22 -04:00
auto* const placement = Game::ScrPlace_GetUnsafeFullPlacement();
2022-05-07 11:02:28 -04:00
auto* const font = Game::UI_GetFontHandle(placement, 0, 0.583f);
2022-04-15 08:50:22 -04:00
const auto width = Game::UI_TextWidth((*Version)->current.string, 0, font, fontScale);
const auto height = Game::UI_TextHeight(font, fontScale);
2022-05-07 09:59:15 -04:00
Game::UI_DrawText(placement, (*Version)->current.string, maxChars, font, 1.0f - (CGDrawVersionX.get<float>() + static_cast<float>(width)),
1.0f - (CGDrawVersionY.get<float>() + static_cast<float>(height)), 3, 3, fontScale, shadowColor, 0);
Game::UI_DrawText(placement, (*Version)->current.string, maxChars, font, (0.0f - static_cast<float>(width)) - CGDrawVersionX.get<float>(),
(0.0f - static_cast<float>(height)) - CGDrawVersionY.get<float>(), 3, 3, fontScale, color, 0);
2022-04-15 08:50:22 -04:00
}
void Branding::CG_DrawVersion_Hk(int localClientNum)
{
Utils::Hook::Call<void(int)>(0x4EFF80)(localClientNum);
if (Branding::CGDrawVersion.get<bool>())
{
Branding::CG_DrawVersion();
}
}
const char* Branding::GetBuildNumber()
{
2022-05-07 09:59:15 -04:00
return SHORTVERSION " latest " __DATE__ " " __TIME__;
2022-04-15 08:50:22 -04:00
}
2022-04-16 11:11:08 -04:00
const char* Branding::GetVersionString()
2022-04-15 08:50:22 -04:00
{
#ifdef _DEBUG
const auto* buildType = "IW4x_DEV MP";
#else
const auto* buildType = "IW4x MP";
#endif
// IW4x is technically a beta
const auto* result = Utils::String::VA("%s %s build %s %s",
buildType, "(Beta)", Branding::GetBuildNumber(), reinterpret_cast<const char*>(0x7170A0));
2022-04-16 11:11:08 -04:00
return result;
}
2022-05-07 09:59:15 -04:00
void Branding::Dvar_SetVersionString(const Game::dvar_t* dvar, [[maybe_unused]] const char* value)
2022-04-16 11:11:08 -04:00
{
const auto* result = Branding::GetVersionString();
2022-04-15 08:50:22 -04:00
Utils::Hook::Call<void(const Game::dvar_t*, const char*)>(0x4A9580)(dvar, result);
}
2022-04-16 11:11:08 -04:00
// Branding this might be a good idea in case this LSP logging ever gets turned on for some reason
2022-05-07 09:59:15 -04:00
void Branding::MSG_WriteVersionStringHeader(Game::msg_t* msg, [[maybe_unused]] const char* string)
2022-04-16 11:11:08 -04:00
{
const auto* result = Branding::GetVersionString();
Utils::Hook::Call<void(Game::msg_t*, const char*)>(0x463820)(msg, result);
}
2022-05-07 09:59:15 -04:00
Game::dvar_t* Branding::Dvar_RegisterUIBuildLocation(const char* dvarName, [[maybe_unused]] float x,
[[maybe_unused]] float y, float min, float max, [[maybe_unused]] int flags, const char* description)
2022-04-15 08:50:22 -04:00
{
2022-05-07 09:59:15 -04:00
return Game::Dvar_RegisterVec2(dvarName, -60.0f,
474.0f, min, max, Game::dvar_flag::DVAR_READONLY, description);
2022-04-15 08:50:22 -04:00
}
void Branding::RegisterBrandingDvars()
{
#ifdef _DEBUG
constexpr auto value = true;
#else
constexpr auto value = false;
#endif
Branding::CGDrawVersion = Dvar::Register<bool>("cg_drawVersion", value,
Game::dvar_flag::DVAR_NONE, "Draw the game version");
2022-05-07 09:59:15 -04:00
Branding::CGDrawVersionX = Dvar::Register<float>("cg_drawVersionX", 10.0f,
2022-04-15 08:50:22 -04:00
0.0f, 512.0f, Game::dvar_flag::DVAR_NONE, "X offset for the version string");
2022-05-07 09:59:15 -04:00
Branding::CGDrawVersionY = Dvar::Register<float>("cg_drawVersionY", 455.0f,
2022-04-15 08:50:22 -04:00
0.0f, 512.0f, Game::dvar_flag::DVAR_NONE, "Y offset for the version string");
}
Branding::Branding()
{
Branding::RegisterBrandingDvars();
2022-04-15 08:50:22 -04:00
// UI version string
Utils::Hook::Set<const char*>(0x43F73B, "IW4x: " VERSION);
// Short version dvar
Utils::Hook::Set<const char*>(0x60BD91, SHORTVERSION);
2022-04-16 11:11:08 -04:00
Utils::Hook(0x4B12B0, Branding::GetBuildNumber, HOOK_JUMP).install()->quick();
2022-04-15 08:50:22 -04:00
// Version string color
static Game::vec4_t buildLocColor = {1.0f, 1.0f, 1.0f, 0.8f};
Utils::Hook::Set<float*>(0x43F710, buildLocColor);
2022-04-16 11:11:08 -04:00
// Place ui version string to bottom right corner (ui_buildlocation)
2022-04-15 08:50:22 -04:00
Utils::Hook(0x6310A0, Branding::Dvar_RegisterUIBuildLocation, HOOK_CALL).install()->quick(); // Dvar_RegisterVec2
Utils::Hook(0x60BD81, Branding::Dvar_SetVersionString, HOOK_CALL).install()->quick();
2022-04-16 11:11:08 -04:00
Utils::Hook(0x4DA842, Branding::MSG_WriteVersionStringHeader, HOOK_CALL).install()->quick();
2022-04-15 08:50:22 -04:00
// Hook CG_DrawFullScreenDebugOverlays so we may render the version when it's appropriate
Utils::Hook(0x5AC975, Branding::CG_DrawVersion_Hk, HOOK_CALL).install()->quick();
}
}