From f7c823eeaf723d1bc3e3b6cc90b404a2716bdd72 Mon Sep 17 00:00:00 2001 From: "Skyth (Asilkan)" <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Sun, 30 Mar 2025 18:42:37 +0300 Subject: [PATCH] Fix staffroll text getting cropped at narrow aspect ratios. (#1489) --- .../patches/aspect_ratio_patches.cpp | 36 +++++++++++++++++++ UnleashedRecompLib/config/SWA.toml | 35 ++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/UnleashedRecomp/patches/aspect_ratio_patches.cpp b/UnleashedRecomp/patches/aspect_ratio_patches.cpp index d1780b16..02f49ee0 100644 --- a/UnleashedRecomp/patches/aspect_ratio_patches.cpp +++ b/UnleashedRecomp/patches/aspect_ratio_patches.cpp @@ -1650,3 +1650,39 @@ PPC_FUNC(sub_82E54950) __imp__sub_82E54950(ctx, base); } } + +// Credits while Sonic is running are offseted by 133 pixels at 16:9. +// We can make this dynamic by remembering the anchoring and shifting accordingly. +void EndingTextAllocMidAsmHook(PPCRegister& r3) +{ + r3.u32 += sizeof(uint32_t); +} + +static constexpr uint32_t ENDING_TEXT_SIZE = 0x164; + +void EndingTextCtorRightMidAsmHook(PPCRegister& r3) +{ + *reinterpret_cast(g_memory.base + r3.u32 + ENDING_TEXT_SIZE) = ALIGN_RIGHT; +} + +void EndingTextCtorLeftMidAsmHook(PPCRegister& r3) +{ + *reinterpret_cast(g_memory.base + r3.u32 + ENDING_TEXT_SIZE) = ALIGN_LEFT; +} + +void EndingTextCtorCenterMidAsmHook(PPCRegister& r3) +{ + *reinterpret_cast(g_memory.base + r3.u32 + ENDING_TEXT_SIZE) = ALIGN_CENTER; +} + +void EndingTextPositionMidAsmHook(PPCRegister& r31, PPCRegister& f13) +{ + uint32_t align = *reinterpret_cast(g_memory.base + r31.u32 + ENDING_TEXT_SIZE); + + // Since widescreen is always forced, 133 offset will always be part of the position. + if (align == ALIGN_RIGHT) + f13.f64 += -133.0 * (1.0 - g_aspectRatioNarrowScale); + + else if (align == ALIGN_LEFT) + f13.f64 += 133.0 * (1.0 - g_aspectRatioNarrowScale); +} diff --git a/UnleashedRecompLib/config/SWA.toml b/UnleashedRecompLib/config/SWA.toml index db5bf2d7..eb871b8a 100644 --- a/UnleashedRecompLib/config/SWA.toml +++ b/UnleashedRecompLib/config/SWA.toml @@ -1106,3 +1106,38 @@ name = "UseAlternateTitleMidAsmHook" address = 0x82580F44 jump_address_on_true = 0x82580F48 jump_address_on_false = 0x82580FA0 + +[[midasm_hook]] +name = "EndingTextAllocMidAsmHook" +address = 0x8257E284 +registers = ["r3"] + +[[midasm_hook]] +name = "EndingTextAllocMidAsmHook" +address = 0x8257E45C +registers = ["r3"] + +[[midasm_hook]] +name = "EndingTextAllocMidAsmHook" +address = 0x8257EDD8 +registers = ["r3"] + +[[midasm_hook]] +name = "EndingTextCtorRightMidAsmHook" +address = 0x8257E304 +registers = ["r3"] + +[[midasm_hook]] +name = "EndingTextCtorLeftMidAsmHook" +address = 0x8257E4DC +registers = ["r3"] + +[[midasm_hook]] +name = "EndingTextCtorCenterMidAsmHook" +address = 0x8257EE40 +registers = ["r3"] + +[[midasm_hook]] +name = "EndingTextPositionMidAsmHook" +address = 0x82580168 +registers = ["r31", "f13"]