From 8cde3246c14fd6f1da44f5610c9359a23d3739e8 Mon Sep 17 00:00:00 2001 From: Silent Date: Fri, 4 Oct 2024 20:19:33 +0200 Subject: [PATCH] VC: Scale onscreen counter bar position and shadow to resolution --- SilentPatchVC/SilentPatchVC.cpp | 98 +++++++++++++++++++++++++++++---- 1 file changed, 87 insertions(+), 11 deletions(-) diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index 01b00f9..0b69b96 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -190,9 +190,11 @@ namespace PrintStringShadows Memory::DynBase::InterceptCall(addr, orgPrintString, PrintString); } }; +} - // Radar position and radardisc shadow - +// ============= Radar position and radardisc shadow ============= +namespace RadardiscFixes +{ static const float RADARDISC_SHRINK = 2.0f; // We are shrinking the radardisc by that template @@ -282,6 +284,50 @@ namespace PrintStringShadows HOOK_EACH_INIT(DrawRadarDisc, orgDrawSprite, DrawSprite_Scale); } +// ============= Fix the onscreen counter bar placement and shadow 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); +} + float FixedRefValue() { return 1.0f; @@ -1049,6 +1095,12 @@ void InjectDelayedPatches_VC_Common( bool bHasDebugMenu, const wchar_t* wcModule } } + auto PatchFloat = [](float** address, const float*& org, float& replaced) + { + org = *address; + Patch(address, &replaced); + }; + // Locale based metric/imperial system INI/debug menu { using namespace Localization; @@ -1225,8 +1277,7 @@ void InjectDelayedPatches_VC_Common( bool bHasDebugMenu, const wchar_t* wcModule // Fix the radar disc shadow scaling and radar X position try { - // Legacy namespace name, it's OK - using namespace PrintStringShadows; + using namespace RadardiscFixes; auto draw_entity_coord_blip = pattern("D8 0D ? ? ? ? D8 05 ? ? ? ? DE C1 D9 5C 24 18").count(2); auto draw_radar_disc1 = pattern("D8 25 ? ? ? ? DD DB D9 C2 D9 9C 24 ? ? ? ? DB 05 ? ? ? ? D8 0D ? ? ? ? D8 0D ? ? ? ? D8 05 ? ? ? ? D8 05").count(2); @@ -1294,13 +1345,6 @@ void InjectDelayedPatches_VC_Common( bool bHasDebugMenu, const wchar_t* wcModule } TXN_CATCH(); - - auto PatchFloat = [](float** address, const float*& org, float& replaced) - { - org = *address; - Patch(address, &replaced); - }; - HookEach_CalculateRadarXPos(radarXPos, PatchFloat); HookEach_CalculateRadarXPos_RadardiscShrink(radarXPos_RadardiscShrink, PatchFloat); HookEach_CalculateRadarYPos_RadardiscShrink(radarYPos_RadardiscShrink, PatchFloat); @@ -1309,6 +1353,38 @@ void InjectDelayedPatches_VC_Common( bool bHasDebugMenu, const wchar_t* wcModule } TXN_CATCH(); + + // Fix the onscreen counter bar placement and shadow not scaling to resolution + try + { + using namespace OnscreenCounterBarFixes; + + auto atoiWrap = get_pattern("E8 ? ? ? ? D9 EE DB 05 ? ? ? ? 89 C7"); + auto shadow1 = pattern("D8 05 ? ? ? ? D9 9C 24 ? ? ? ? D9 05 ? ? ? ? D8 44 24 50").get_one(); + auto shadow2 = pattern("D9 05 ? ? ? ? D8 C1 D9 9C 24 ? ? ? ? D9 05").get_one(); + auto fill1 = pattern("D8 05 ? ? ? ? D9 9C 24 ? ? ? ? D9 05 ? ? ? ? 8D 84 24").get_one(); + + std::array XPositions = { + shadow1.get(2), + shadow2.get(2), + fill1.get(2), + fill1.get(13 + 2), + get_pattern("D9 05 ? ? ? ? D8 C1 D9 9C 24 ? ? ? ? DB 44 24 6C", 2), + get_pattern("D8 05 ? ? ? ? D9 9C 24 ? ? ? ? DE D9 E8 ? ? ? ? 59", 2), + }; + + std::array YPositions = { + shadow1.get(13 + 2), + shadow2.get(15 + 2), + }; + + HookEach_XPos(XPositions, PatchFloat); + HookEach_YPos(YPositions, PatchFloat); + + InterceptCall(atoiWrap, orgAtoi, atoi_RecalculatePositions); + } + TXN_CATCH(); + FLAUtils::Init(moduleList); }