From 1c4a08ea9258330463fc06cace8c06bbd595cc08 Mon Sep 17 00:00:00 2001 From: Silent Date: Wed, 23 Oct 2024 23:59:29 +0200 Subject: [PATCH] SA: Fix text background padding not scaling to resolution Debugged by Wesser --- SilentPatchSA/SilentPatchSA.cpp | 105 ++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index f60281c..03ae770 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -3079,6 +3079,69 @@ namespace MapScreenScalingFixes } +// ============= Fix text background padding not scaling to resolution ============= +// Debugged by Wesser +namespace TextRectPaddingScalingFixes +{ + template + static const float* orgPaddingXSize; + + template + static float PaddingXSize_Recalculated; + + template + static void RecalculateXSize(std::index_sequence) + { + ((PaddingXSize_Recalculated = ScaleX(*orgPaddingXSize)), ...); + } + + template + static const float* orgPaddingYSize; + + template + static float PaddingYSize_Recalculated; + + template + static void RecalculateYSize(std::index_sequence) + { + ((PaddingYSize_Recalculated = ScaleY(*orgPaddingYSize)), ...); + } + + template + static const double* orgPaddingYSize_Double; + + template + static double PaddingYSize_Double_Recalculated; + + template + static void RecalculateYSize_Double(std::index_sequence) + { + ((PaddingYSize_Double_Recalculated = ScaleY(static_cast(*orgPaddingYSize_Double))), ...); + } + + static short (*orgProcessCurrentString)(uint8_t, float, float, void*); + + template + static short ProcessCurrentString_Scale(uint8_t a1, float a2, float a3, void* a4) + { + RecalculateXSize(std::make_index_sequence{}); + RecalculateYSize(std::make_index_sequence{}); + return orgProcessCurrentString(a1, a2, a3, a4); + } + + template + static short ProcessCurrentString_Scale_NewBinaries(uint8_t a1, float a2, float a3, void* a4) + { + RecalculateYSize_Double(std::make_index_sequence{}); + return orgProcessCurrentString(a1, a2, a3, a4); + } + + HOOK_EACH_INIT(PaddingXSize, orgPaddingXSize, PaddingXSize_Recalculated); + HOOK_EACH_INIT(PaddingYSize, orgPaddingYSize, PaddingYSize_Recalculated); + HOOK_EACH_INIT(PaddingYSize_Double, orgPaddingYSize_Double, PaddingYSize_Double_Recalculated); +} + + // ============= LS-RP Mode stuff ============= namespace LSRPMode { @@ -6153,6 +6216,25 @@ void Patch_SA_10(HINSTANCE hInstance) } + // Fix text background padding not scaling to resolution + // Debugged by Wesser + { + using namespace TextRectPaddingScalingFixes; + + std::array paddingXSizes = { + (float**)(0x71A653 + 2), (float**)(0x71A66B + 2), + (float**)(0x71A69D + 2), (float**)(0x71A6AB + 2), + }; + std::array paddingYSizes = { + (float**)(0x71A6BF + 2), (float**)(0x71A6EC + 2), + }; + + HookEach_PaddingXSize(paddingXSizes, PatchFloat); + HookEach_PaddingYSize(paddingYSizes, PatchFloat); + InterceptCall(0x71A631, orgProcessCurrentString, ProcessCurrentString_Scale); + } + + #if FULL_PRECISION_D3D // Test - full precision D3D device Patch( 0x7F672B+1, *(uint8_t*)(0x7F672B+1) | D3DCREATE_FPU_PRESERVE ); @@ -8338,6 +8420,29 @@ void Patch_SA_NewBinaries_Common(HINSTANCE hInstance) InjectHook(scaleY.get(1), ScaleY_NewBinaries, HookType::Call); } TXN_CATCH(); + + + // Fix text background padding not scaling to resolution + // Debugged by Wesser + try + { + using namespace TextRectPaddingScalingFixes; + + auto processCurrentString = get_pattern("E8 ? ? ? ? DD 05 ? ? ? ? 8B 4D 08"); + + // In new binaries, 4.0f is shared for width and height. + // Make height determine the scale, so it works nicer in widescreen. + auto paddingSize = pattern("DD 05 ? ? ? ? DC E9 D9 C9 D9 19").count(2); + std::array paddingYSizes = { + get_pattern("D8 CA DD 05 ? ? ? ? DC C1", 2 + 2), + paddingSize.get(0).get(2), + paddingSize.get(1).get(2), + }; + + HookEach_PaddingYSize_Double(paddingYSizes, PatchDouble); + InterceptCall(processCurrentString, orgProcessCurrentString, ProcessCurrentString_Scale_NewBinaries); + } + TXN_CATCH(); }