diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index 752c6cce..1e494e20 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -68,6 +68,7 @@ set(SWA_PATCHES_CXX_SOURCES "patches/ui/CHudPause_patches.cpp" "patches/ui/CTitleMenu_patches.cpp" "patches/ui/frontend_listener.cpp" + "patches/camera_patches.cpp" "patches/fps_patches.cpp" "patches/misc_patches.cpp" "patches/object_patches.cpp" diff --git a/UnleashedRecomp/patches/camera_patches.cpp b/UnleashedRecomp/patches/camera_patches.cpp new file mode 100644 index 00000000..d158cb8e --- /dev/null +++ b/UnleashedRecomp/patches/camera_patches.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include + +constexpr float m_baseAspectRatio = 16.0f / 9.0f; + +bool CameraAspectRatioMidAsmHook(PPCRegister& r31) +{ + auto pCamera = (SWA::CCamera*)g_memory.Translate(r31.u32); + auto newAspectRatio = (float)Window::s_width / (float)Window::s_height; + + // Dynamically adjust horizontal aspect ratio to window dimensions. + pCamera->m_HorzAspectRatio = newAspectRatio; + + if (auto s_pVertAspectRatio = (be*)g_memory.Translate(0x82028FE0)) + { + // Dynamically adjust vertical aspect ratio for VERT+. + *s_pVertAspectRatio = 2.0f * atan(tan(45.0f / 2.0f) * (m_baseAspectRatio / newAspectRatio)); + } + + // Jump to 4:3 code for VERT+ adjustments if using a narrow aspect ratio. + return newAspectRatio < m_baseAspectRatio; +} + +void CameraBoostAspectRatioMidAsmHook(PPCRegister& r31, PPCRegister& f0) +{ + auto pCamera = (SWA::CCamera*)g_memory.Translate(r31.u32); + + if (Window::s_width < Window::s_height) + { + // Use horizontal FOV for narrow aspect ratios. + f0.f32 = pCamera->m_HorzFieldOfView; + } + else + { + // Use vertical FOV for wide aspect ratios. + f0.f32 = pCamera->m_VertFieldOfView; + } +} + +PPC_FUNC_IMPL(__imp__sub_824697B0); +PPC_FUNC(sub_824697B0) +{ + auto pCamera = (SWA::CCamera*)g_memory.Translate(ctx.r3.u32); + + pCamera->m_InvertX = Config::CameraXInvert; + pCamera->m_InvertY = Config::CameraYInvert; + + __imp__sub_824697B0(ctx, base); +} diff --git a/UnleashedRecomp/patches/video_patches.cpp b/UnleashedRecomp/patches/video_patches.cpp index d3e1f0d2..e4b9aacc 100644 --- a/UnleashedRecomp/patches/video_patches.cpp +++ b/UnleashedRecomp/patches/video_patches.cpp @@ -3,42 +3,10 @@ #include #include +// TODO: to be removed. constexpr float m_baseAspectRatio = 16.0f / 9.0f; -bool CameraAspectRatioMidAsmHook(PPCRegister& r31) -{ - auto pCamera = (SWA::CCamera*)g_memory.Translate(r31.u32); - auto newAspectRatio = (float)Window::s_width / (float)Window::s_height; - - // Dynamically adjust horizontal aspect ratio to window dimensions. - pCamera->m_HorzAspectRatio = newAspectRatio; - - if (auto s_pVertAspectRatio = (be*)g_memory.Translate(0x82028FE0)) - { - // Dynamically adjust vertical aspect ratio for VERT+. - *s_pVertAspectRatio = 2.0f * atan(tan(45.0f / 2.0f) * (m_baseAspectRatio / newAspectRatio)); - } - - // Jump to 4:3 code for VERT+ adjustments if using a narrow aspect ratio. - return newAspectRatio < m_baseAspectRatio; -} - -void CameraBoostAspectRatioMidAsmHook(PPCRegister& r31, PPCRegister& f0) -{ - auto pCamera = (SWA::CCamera*)g_memory.Translate(r31.u32); - - if (Window::s_width < Window::s_height) - { - // Use horizontal FOV for narrow aspect ratios. - f0.f32 = pCamera->m_HorzFieldOfView; - } - else - { - // Use vertical FOV for wide aspect ratios. - f0.f32 = pCamera->m_VertFieldOfView; - } -} - +// TODO: to be removed. void CSDAspectRatioMidAsmHook(PPCRegister& f1, PPCRegister& f2) { if (Config::UIScaleMode == EUIScaleMode::Stretch) diff --git a/UnleashedRecomp/ui/options_menu.cpp b/UnleashedRecomp/ui/options_menu.cpp index 19734973..7dd5b43c 100644 --- a/UnleashedRecomp/ui/options_menu.cpp +++ b/UnleashedRecomp/ui/options_menu.cpp @@ -793,6 +793,7 @@ void DrawInfoPanel() auto size = Scale(26.0f); auto textSize = g_seuratFont->CalcTextSizeA(size, FLT_MAX, 0.0f, desc.c_str()); + // TODO: fix word wrap width not scaling to resolution. drawList->AddText( g_seuratFont, size,