diff --git a/CHANGELOG-III.md b/CHANGELOG-III.md index 956a6ef..1d651bf 100644 --- a/CHANGELOG-III.md +++ b/CHANGELOG-III.md @@ -48,6 +48,7 @@ All the remaining, non-critical fixes. * The radar's horizontal position and its disc texture now scale to resolution correctly, resolving color bleed issues at high resolutions. * Credits now scale to resolution correctly, and they don't cut to an empty screen at the very end anymore. * Mission title and 'Mission Passed' texts now stay on screen for the same duration, regardless of screen resolution. +* The inner padding of the text boxes with a background now scales to resolution correctly. * `FILE_FLAG_NO_BUFFERING` flag has been removed from IMG reading functions - speeding up streaming. * Free resprays will not carry on a New Game now. * Fixed ambulance and firetruck dispatch timers - they reset on New Game now. diff --git a/CHANGELOG-VC.md b/CHANGELOG-VC.md index 446ce80..247dc1c 100644 --- a/CHANGELOG-VC.md +++ b/CHANGELOG-VC.md @@ -44,6 +44,7 @@ All the remaining, non-critical fixes. * The radar's horizontal position, the disc texture, and the shadow now scale to resolution correctly. The radar disc was also shrunk slightly to fix gaps and make the icons sit better on the edge. * Credits now scale to resolution correctly. * Mission title and 'Mission Passed' texts now stay on screen for the same duration, regardless of screen resolution. +* The inner padding of the text boxes with a background now scales to resolution correctly. * `FILE_FLAG_NO_BUFFERING` flag has been removed from IMG reading functions - speeding up streaming. * Free resprays will not carry on a New Game now. * Fixed ambulance and firetruck dispatch timers - they reset on New Game now. diff --git a/README.md b/README.md index 4cdc8f9..d2d551d 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ for both first-time players and the old guard returning for yet another playthro SilentPatch includes code contributions from: * aap +* B1ack_Wh1te * DK22Pac * Fire_Head * Nick007J diff --git a/SilentPatchIII/SilentPatchIII.cpp b/SilentPatchIII/SilentPatchIII.cpp index f9d5df4..11b1263 100644 --- a/SilentPatchIII/SilentPatchIII.cpp +++ b/SilentPatchIII/SilentPatchIII.cpp @@ -1099,6 +1099,72 @@ namespace BrakelightsDummy } } + +// ============= Fix text background padding not scaling to resolution ============= +namespace TextRectPaddingScalingFixes +{ + template + static const float* orgPaddingXSize; + + template + static float PaddingXSize_Recalculated; + + template + static void RecalculateXSize(std::index_sequence) + { + const float multiplier = GetWidthMult() * RsGlobal->MaximumWidth; + ((PaddingXSize_Recalculated = *orgPaddingXSize * multiplier), ...); + } + + template + static const float* orgPaddingYSize; + + template + static float PaddingYSize_Recalculated; + + template + static void RecalculateYSize(std::index_sequence) + { + const float multiplier = GetHeightMult() * RsGlobal->MaximumHeight; + ((PaddingYSize_Recalculated = *orgPaddingYSize * multiplier), ...); + } + + static void (*orgGetTextRect)(CRect*, float, float, void*); + template + static void GetTextRect_Recalculate(CRect* a1, float a2, float a3, void* a4) + { + RecalculateXSize(std::make_index_sequence{}); + RecalculateYSize(std::make_index_sequence{}); + orgGetTextRect(a1, a2, a3, a4); + } + + HOOK_EACH_INIT(PaddingXSize, orgPaddingXSize, PaddingXSize_Recalculated); + HOOK_EACH_INIT(PaddingYSize, orgPaddingYSize, PaddingYSize_Recalculated); + + template + static const float* orgWrapX; + + template + static float WrapX_Recalculated; + + template + static void RecalculateWrapX(std::index_sequence) + { + const float multiplier = GetWidthMult() * RsGlobal->MaximumWidth; + ((WrapX_Recalculated = *orgWrapX * multiplier), ...); + } + + static void (*orgSetJustifyOff)(); + template + static void SetJustifyOff_Recalculate() + { + RecalculateWrapX(std::make_index_sequence{}); + orgSetJustifyOff(); + } + + HOOK_EACH_INIT(WrapX, orgWrapX, WrapX_Recalculated); +} + namespace ModelIndicesReadyHook { static void (*orgInitialiseObjectData)(const char*); @@ -1493,6 +1559,54 @@ void InjectDelayedPatches_III_Common( bool bHasDebugMenu, const wchar_t* wcModul } TXN_CATCH(); + + // Fix text background padding not scaling to resolution + try + { + using namespace TextRectPaddingScalingFixes; + + auto getTextRect = get_pattern("FF 74 24 54 FF 74 24 54 50 E8 ? ? ? ? 83 C4 10", 9); + auto rectWidth1 = pattern("D8 25 ? ? ? ? D9 18 89 54 24 18 8B 44 24 34 DB 44 24 18 D8 44 24 38 D8 05").get_one(); + auto rectWidth2 = pattern("D8 25 ? ? ? ? D9 18 D9 05 ? ? ? ? D8 0D ? ? ? ? 8B 44 24 34 D8 44 24 38 D8 05").get_one(); + auto rectWidth3 = get_pattern("D8 25 ? ? ? ? 8B 44 24 34 D9 18", 2); + + auto rectHeight1 = pattern("D8 05 ? ? ? ? D9 58 04 D9 44 24 3C D8 25").count(2); + auto rectHeight2 = pattern("D9 05 ? ? ? ? D8 44 24 3C DE C1 D8 05").get_one(); + + // SetWrapx on the help boxes includes an unscaled -4.0f probably to work together with this padding, + // so treat it as part of the same fix + auto setJustifyOff_helpBox = get_pattern("59 E8 ? ? ? ? D9 EE", 1); + + std::array paddingXSizes = { + rectWidth1.get(2), + rectWidth1.get(0x18 + 2), + rectWidth2.get(2), + rectWidth2.get(0x1C + 2), + rectWidth3 + }; + + std::array paddingYSizes = { + rectHeight1.get(0).get(2), + rectHeight1.get(0).get(0xD + 2), + rectHeight1.get(1).get(2), + rectHeight1.get(1).get(0xD + 2), + rectHeight2.get(2), + rectHeight2.get(0xC + 2), + }; + + std::array wrapxWidth = { + get_pattern("D8 25 ? ? ? ? D9 1C 24 DD D8", 2), + }; + + HookEach_PaddingXSize(paddingXSizes, PatchFloat); + HookEach_PaddingYSize(paddingYSizes, PatchFloat); + InterceptCall(getTextRect, orgGetTextRect, GetTextRect_Recalculate); + + HookEach_WrapX(wrapxWidth, PatchFloat); + InterceptCall(setJustifyOff_helpBox, orgSetJustifyOff, SetJustifyOff_Recalculate); + } + TXN_CATCH(); + FLAUtils::Init(moduleList); } diff --git a/SilentPatchIII/versionmeta.props b/SilentPatchIII/versionmeta.props index 37929c4..c7bb85a 100644 --- a/SilentPatchIII/versionmeta.props +++ b/SilentPatchIII/versionmeta.props @@ -6,7 +6,7 @@ .asi SilentPatch for GTA III 9 - 0 + 1 2013-2024 diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index 4e83de3..7cd1b9b 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -553,6 +553,72 @@ namespace MinimalHUD } +// ============= Fix text background padding not scaling to resolution ============= +namespace TextRectPaddingScalingFixes +{ + template + static const float* orgPaddingXSize; + + template + static float PaddingXSize_Recalculated; + + template + static void RecalculateXSize(std::index_sequence) + { + const float multiplier = GetWidthMult() * RsGlobal->MaximumWidth; + ((PaddingXSize_Recalculated = *orgPaddingXSize * multiplier), ...); + } + + template + static const float* orgPaddingYSize; + + template + static float PaddingYSize_Recalculated; + + template + static void RecalculateYSize(std::index_sequence) + { + const float multiplier = GetHeightMult() * RsGlobal->MaximumHeight; + ((PaddingYSize_Recalculated = *orgPaddingYSize * multiplier), ...); + } + + static void (*orgGetTextRect)(CRect*, float, float, void*); + template + static void GetTextRect_Recalculate(CRect* a1, float a2, float a3, void* a4) + { + RecalculateXSize(std::make_index_sequence{}); + RecalculateYSize(std::make_index_sequence{}); + orgGetTextRect(a1, a2, a3, a4); + } + + HOOK_EACH_INIT(PaddingXSize, orgPaddingXSize, PaddingXSize_Recalculated); + HOOK_EACH_INIT(PaddingYSize, orgPaddingYSize, PaddingYSize_Recalculated); + + template + static const float* orgWrapX; + + template + static float WrapX_Recalculated; + + template + static void RecalculateWrapX(std::index_sequence) + { + const float multiplier = GetWidthMult() * RsGlobal->MaximumWidth; + ((WrapX_Recalculated = *orgWrapX * multiplier), ...); + } + + static void (*orgSetJustifyOff)(); + template + static void SetJustifyOff_Recalculate() + { + RecalculateWrapX(std::make_index_sequence{}); + orgSetJustifyOff(); + } + + HOOK_EACH_INIT(WrapX, orgWrapX, WrapX_Recalculated); +} + + float FixedRefValue() { return 1.0f; @@ -1908,6 +1974,54 @@ void InjectDelayedPatches_VC_Common( bool bHasDebugMenu, const wchar_t* wcModule } TXN_CATCH(); + + // Fix text background padding not scaling to resolution + try + { + using namespace TextRectPaddingScalingFixes; + + auto getTextRect = get_pattern("FF 74 24 54 FF 74 24 54 50 E8 ? ? ? ? 83 C4 10", 9); + auto rectWidth1 = pattern("D8 25 ? ? ? ? D9 1E D9 44 24 38 D8 05 ? ? ? ? D8 05").get_one(); + auto rectWidth2 = pattern("D8 25 ? ? ? ? D9 1E D9 05 ? ? ? ? D8 0D ? ? ? ? D8 44 24 38 D8 05").get_one(); + auto rectWidth3 = get_pattern("D8 25 ? ? ? ? 0F BF C5 D9 1E", 2); + + auto rectHeight1 = pattern("D8 05 ? ? ? ? D9 5E 04 D9 44 24 3C D8 25").count(2); + auto rectHeight2 = pattern("D9 05 ? ? ? ? D8 44 24 3C DE C1 D8 05").get_one(); + + // SetWrapx on the help boxes includes an unscaled -4.0f probably to work together with this padding, + // so treat it as part of the same fix + auto setJustifyOff_helpBox = get_pattern("59 E8 ? ? ? ? D9 EE", 1); + + std::array paddingXSizes = { + rectWidth1.get(2), + rectWidth1.get(0x12 + 2), + rectWidth2.get(2), + rectWidth2.get(0x18 + 2), + rectWidth3 + }; + + std::array paddingYSizes = { + rectHeight1.get(0).get(2), + rectHeight1.get(0).get(0xD + 2), + rectHeight1.get(1).get(2), + rectHeight1.get(1).get(0xD + 2), + rectHeight2.get(2), + rectHeight2.get(0xC + 2), + }; + + std::array wrapxWidth = { + get_pattern("D8 25 ? ? ? ? D9 1C 24 DD D8", 2), + }; + + HookEach_PaddingXSize(paddingXSizes, PatchFloat); + HookEach_PaddingYSize(paddingYSizes, PatchFloat); + InterceptCall(getTextRect, orgGetTextRect, GetTextRect_Recalculate); + + HookEach_WrapX(wrapxWidth, PatchFloat); + InterceptCall(setJustifyOff_helpBox, orgSetJustifyOff, SetJustifyOff_Recalculate); + } + TXN_CATCH(); + FLAUtils::Init(moduleList); } diff --git a/SilentPatchVC/versionmeta.props b/SilentPatchVC/versionmeta.props index a48a814..66afbb3 100644 --- a/SilentPatchVC/versionmeta.props +++ b/SilentPatchVC/versionmeta.props @@ -6,7 +6,7 @@ .asi SilentPatch for Vice City 11 - 0 + 1 2013-2024