From 554be014121697f764de3afd191f11c7a0630410 Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:36:10 +0100 Subject: [PATCH] Implemented CSD aspect ratio hooks This only includes the centred mode, as the intention is to map out CSD classes in the API and handle the rest manually. Co-Authored-By: Michael <15317421+ActualMandM@users.noreply.github.com> --- UnleashedRecomp/game.cpp | 28 ++++++++++++++++++++++++++++ UnleashedRecompLib/config/SWA.toml | 13 ++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/UnleashedRecomp/game.cpp b/UnleashedRecomp/game.cpp index 1ae3d0f..acdd2f0 100644 --- a/UnleashedRecomp/game.cpp +++ b/UnleashedRecomp/game.cpp @@ -43,3 +43,31 @@ void CameraBoostAspectRatioMidAsmHook(PPCRegister& r31, PPCRegister& f0) f0.f32 = pCamera->m_VertFieldOfView; } } + +void CSDAspectRatioMidAsmHook(PPCRegister& f1, PPCRegister& f2) +{ + auto newAspectRatio = (float)Window::s_width / (float)Window::s_height; + + if (newAspectRatio > m_baseAspectRatio) + { + f1.f64 = 1280.0f / ((newAspectRatio * 720.0f) / 1280.0f); + } + else if (newAspectRatio < m_baseAspectRatio) + { + f2.f64 = 720.0f / ((1280.0f / newAspectRatio) / 720.0f); + } +} + +void CSDOffsetMidAsmHook(PPCRegister& f1, PPCRegister& f2) +{ + auto newAspectRatio = (float)Window::s_width / (float)Window::s_height; + + if (newAspectRatio > m_baseAspectRatio) + { + *(be*)g_memory.Translate(0x8339C5D0) = ((newAspectRatio * 720.0f) - 1280.0f) / 2.0f / 1280.0f; + } + else + { + *(be*)g_memory.Translate(0x8339C5D4) = ((1280.0f / newAspectRatio) - 720.0f) / 2.0f / 720.0f; + } +} diff --git a/UnleashedRecompLib/config/SWA.toml b/UnleashedRecompLib/config/SWA.toml index 820dd50..8646af7 100644 --- a/UnleashedRecompLib/config/SWA.toml +++ b/UnleashedRecompLib/config/SWA.toml @@ -119,4 +119,15 @@ jump_address_on_false = 0x82468EE0 [[midasm_hook]] name = "CameraBoostAspectRatioMidAsmHook" address = 0x8246BDA8 -registers = ["r31", "f0"] \ No newline at end of file +registers = ["r31", "f0"] + +[[midasm_hook]] +name = "CSDAspectRatioMidAsmHook" +address = 0x830C0A28 +registers = ["f1", "f2"] + +[[midasm_hook]] +name = "CSDOffsetMidAsmHook" +address = 0x830C0A78 +registers = ["f1", "f2"] +return = true \ No newline at end of file