Cleanup code a bit

This commit is contained in:
Diavolo 2022-04-16 17:11:08 +02:00
parent 790b75e186
commit b99ad565bb
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
2 changed files with 24 additions and 7 deletions

View File

@ -43,13 +43,12 @@ namespace Components
static char buf[128]; // Length the game uses
const auto* data = "latest " __DATE__ " " __TIME__;
sprintf_s(buf, sizeof(buf), "%s %s", SHORTVERSION, data);
sprintf_s(buf, "%s %s", SHORTVERSION, data);
return buf;
}
// Use IW4x Branding
void Branding::Dvar_SetVersionString(const Game::dvar_t* dvar, const char* /*value*/)
const char* Branding::GetVersionString()
{
#ifdef _DEBUG
const auto* buildType = "IW4x_DEV MP";
@ -61,9 +60,22 @@ namespace Components
const auto* result = Utils::String::VA("%s %s build %s %s",
buildType, "(Beta)", Branding::GetBuildNumber(), reinterpret_cast<const char*>(0x7170A0));
return result;
}
void Branding::Dvar_SetVersionString(const Game::dvar_t* dvar, const char* /*value*/)
{
const auto* result = Branding::GetVersionString();
Utils::Hook::Call<void(const Game::dvar_t*, const char*)>(0x4A9580)(dvar, result);
}
// Branding this might be a good idea in case this LSP logging ever gets turned on for some reason
void Branding::MSG_WriteVersionStringHeader(Game::msg_t* msg, const char* /*string*/)
{
const auto* result = Branding::GetVersionString();
Utils::Hook::Call<void(Game::msg_t*, const char*)>(0x463820)(msg, result);
}
Game::dvar_t* Branding::Dvar_RegisterUIBuildLocation(const char* dvarName,
float /*x*/, float /*y*/, float min, float max, int /*flags*/, const char* description)
{
@ -100,18 +112,19 @@ namespace Components
// Short version dvar
Utils::Hook::Set<const char*>(0x60BD91, SHORTVERSION);
// Console version string
Utils::Hook::Set<const char*>(0x4B12BB, "IW4x " VERSION " (built " __DATE__ " " __TIME__ ")");
Utils::Hook(0x4B12B0, Branding::GetBuildNumber, HOOK_JUMP).install()->quick();
// Version string color
static Game::vec4_t buildLocColor = {1.0f, 1.0f, 1.0f, 0.8f};
Utils::Hook::Set<float*>(0x43F710, buildLocColor);
// Shift ui version string to the left (ui_buildlocation)
// Place ui version string to bottom right corner (ui_buildlocation)
Utils::Hook(0x6310A0, Branding::Dvar_RegisterUIBuildLocation, HOOK_CALL).install()->quick(); // Dvar_RegisterVec2
Utils::Hook(0x60BD81, Branding::Dvar_SetVersionString, HOOK_CALL).install()->quick();
Utils::Hook(0x4DA842, Branding::MSG_WriteVersionStringHeader, HOOK_CALL).install()->quick();
// Hook CG_DrawFullScreenDebugOverlays so we may render the version when it's appropriate
Utils::Hook(0x5AC975, Branding::CG_DrawVersion_Hk, HOOK_CALL).install()->quick();
}

View File

@ -7,6 +7,9 @@ namespace Components
public:
Branding();
static const char* GetBuildNumber();
static const char* GetVersionString();
private:
static Dvar::Var CGDrawVersion;
static Dvar::Var CGDrawVersionX;
@ -16,8 +19,9 @@ namespace Components
static void CG_DrawVersion();
static void CG_DrawVersion_Hk(int localClientNum);
static const char* GetBuildNumber();
// Use IW4x Branding
static void Dvar_SetVersionString(const Game::dvar_t* dvar, const char* value);
static void MSG_WriteVersionStringHeader(Game::msg_t* msg, const char* string);
static Game::dvar_t* Dvar_RegisterUIBuildLocation(const char* dvarName, float x, float y, float min, float max, int flags, const char* description);