From 3a374deec7af1b257c0da67d422a271763eefe42 Mon Sep 17 00:00:00 2001 From: Silent Date: Sat, 5 Oct 2024 15:10:10 +0200 Subject: [PATCH] III: Fix the onscreen counter bar X placement not scaling to resolution --- SilentPatchIII/SilentPatchIII.cpp | 65 +++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/SilentPatchIII/SilentPatchIII.cpp b/SilentPatchIII/SilentPatchIII.cpp index e2e9228..0a98211 100644 --- a/SilentPatchIII/SilentPatchIII.cpp +++ b/SilentPatchIII/SilentPatchIII.cpp @@ -943,6 +943,50 @@ namespace RadardiscFixes HOOK_EACH_INIT(CalculateRadarYPos, orgRadarYPos, RadarYPos_Recalculated); } +// ============= Fix the onscreen counter bar X placement not scaling to resolution ============= +namespace OnscreenCounterBarFixes +{ + template + static const float* orgXPos; + + template + static float XPos_Recalculated; + + template + static const float* orgYPos; + + template + static float YPos_Recalculated; + + template + static void RecalculateXPositions(std::index_sequence) + { + const float multiplier = GetWidthMult() * RsGlobal->MaximumWidth; + ((XPos_Recalculated = *orgXPos * multiplier), ...); + } + + template + static void RecalculateYPositions(std::index_sequence) + { + const float multiplier = GetHeightMult() * RsGlobal->MaximumHeight; + ((YPos_Recalculated = *orgYPos * multiplier), ...); + } + + static int (*orgAtoi)(const char* str); + + template + static int atoi_RecalculatePositions(const char* str) + { + RecalculateXPositions(std::make_index_sequence{}); + RecalculateYPositions(std::make_index_sequence{}); + + return orgAtoi(str); + } + + HOOK_EACH_INIT(XPos, orgXPos, XPos_Recalculated); + HOOK_EACH_INIT(YPos, orgYPos, YPos_Recalculated); +} + namespace ModelIndicesReadyHook { static void (*orgInitialiseObjectData)(const char*); @@ -1187,6 +1231,27 @@ void InjectDelayedPatches_III_Common( bool bHasDebugMenu, const wchar_t* wcModul } TXN_CATCH(); + + // Fix the onscreen counter bar X placement not scaling to resolution + try + { + using namespace OnscreenCounterBarFixes; + + auto atoiWrap = get_pattern("E8 ? ? ? ? 59 8D 8C 24 ? ? ? ? 6A 50"); + + std::array XPositions = { + get_pattern("D9 05 ? ? ? ? D8 C1 D9 1C 24", 2), + get_pattern("D8 E9 D8 05 ? ? ? ? D9 1C 24", 2 + 2), + get_pattern("D8 C2 D8 05 ? ? ? ? D9 1C 24", 2 + 2), + get_pattern("D9 05 ? ? ? ? D8 C2 D9 1C 24", 2), + }; + + HookEach_XPos(XPositions, PatchFloat); + + InterceptCall(atoiWrap, orgAtoi, atoi_RecalculatePositions); + } + TXN_CATCH(); + FLAUtils::Init(moduleList); }