From c9b6a6913fc2a91fdfbd1d7bf6afa1b236e018d3 Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Tue, 12 Nov 2024 19:55:00 +0000 Subject: [PATCH] Fix loading screen speed at high frame rates --- UnleashedRecomp/patches/fps_patches.cpp | 15 +++++++++++++++ UnleashedRecomp/stdafx.h | 1 + UnleashedRecompLib/config/SWA.toml | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/UnleashedRecomp/patches/fps_patches.cpp b/UnleashedRecomp/patches/fps_patches.cpp index 5de2f40..0542c20 100644 --- a/UnleashedRecomp/patches/fps_patches.cpp +++ b/UnleashedRecomp/patches/fps_patches.cpp @@ -3,6 +3,9 @@ #include "ui/window.h" #include "config.h" +float m_lastLoadingFrameDelta = 0.0f; +std::chrono::steady_clock::time_point m_lastLoadingFrameTime; + void HighFrameRateDeltaTimeFixMidAsmHook(PPCRegister& f1) { // Having 60 FPS threshold ensures we still retain @@ -58,3 +61,15 @@ void Camera2DSlopeLerpFixMidAsmHook(PPCRegister& t, PPCRegister& deltaTime) { t.f64 = ComputeLerpFactor(t.f64, deltaTime.f64 / 60.0); } + +void LoadingScreenSpeedFixMidAsmHook(PPCRegister& r4) +{ + auto now = std::chrono::high_resolution_clock::now(); + + m_lastLoadingFrameDelta = std::min(std::chrono::duration(now - m_lastLoadingFrameTime).count(), 1.0f / 15.0f); + m_lastLoadingFrameTime = now; + + auto pDeltaTime = (be*)g_memory.Translate(r4.u32); + + *pDeltaTime = m_lastLoadingFrameDelta; +} diff --git a/UnleashedRecomp/stdafx.h b/UnleashedRecomp/stdafx.h index b0075c4..96152f7 100644 --- a/UnleashedRecomp/stdafx.h +++ b/UnleashedRecomp/stdafx.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/UnleashedRecompLib/config/SWA.toml b/UnleashedRecompLib/config/SWA.toml index 2d44cb3..8d2fe1a 100644 --- a/UnleashedRecompLib/config/SWA.toml +++ b/UnleashedRecompLib/config/SWA.toml @@ -417,3 +417,8 @@ jump_address_on_true = 0x827D20EC name = "ParticleTestDrawIndexedPrimitiveMidAsmHook" address = 0x827D25AC registers = ["r7"] + +[[midasm_hook]] +name = "LoadingScreenSpeedFixMidAsmHook" +address = 0x824DAB60 +registers = ["r4"]