From e403f961aafd66d071d5f3b3dc797a7c60793930 Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Wed, 20 Nov 2024 10:31:22 +0300 Subject: [PATCH 1/2] Cherry pick of global delta time from 'options-menu' branch. Co-authored-by: Hyper <34012267+hyperbx@users.noreply.github.com> --- UnleashedRecomp/CMakeLists.txt | 1 + UnleashedRecomp/app.cpp | 19 +++++++++++++++++++ UnleashedRecomp/app.h | 3 +++ UnleashedRecomp/ui/window.cpp | 13 ------------- 4 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 UnleashedRecomp/app.cpp create mode 100644 UnleashedRecomp/app.h diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index ff8536d8..43a7956b 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -79,6 +79,7 @@ set(SWA_UI_CXX_SOURCES ) set(SWA_CXX_SOURCES + "app.cpp" "main.cpp" "misc_impl.cpp" "stdafx.cpp" diff --git a/UnleashedRecomp/app.cpp b/UnleashedRecomp/app.cpp new file mode 100644 index 00000000..722429f9 --- /dev/null +++ b/UnleashedRecomp/app.cpp @@ -0,0 +1,19 @@ +#include +#include +#include + +double g_deltaTime; + +// CApplication::Update +PPC_FUNC_IMPL(__imp__sub_822C1130); +PPC_FUNC(sub_822C1130) +{ + g_deltaTime = ctx.f1.f64; + + SDL_PumpEvents(); + SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT); + + Window::Update(); + + __imp__sub_822C1130(ctx, base); +} diff --git a/UnleashedRecomp/app.h b/UnleashedRecomp/app.h new file mode 100644 index 00000000..4e1d379e --- /dev/null +++ b/UnleashedRecomp/app.h @@ -0,0 +1,3 @@ +#pragma once + +extern double g_deltaTime; diff --git a/UnleashedRecomp/ui/window.cpp b/UnleashedRecomp/ui/window.cpp index 7f587044..2df75973 100644 --- a/UnleashedRecomp/ui/window.cpp +++ b/UnleashedRecomp/ui/window.cpp @@ -1,7 +1,6 @@ #include "window.h" #include "sdl_listener.h" #include -#include #include bool m_isFullscreenKeyReleased = true; @@ -175,15 +174,3 @@ void Window::Update() Config::WindowHeight = Window::s_height; } } - -// CApplication::Update -PPC_FUNC_IMPL(__imp__sub_822C1130); -PPC_FUNC(sub_822C1130) -{ - SDL_PumpEvents(); - SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT); - - Window::Update(); - - __imp__sub_822C1130(ctx, base); -} From cffefcdbf3176640fce9857e96bfc6d0c378c19d Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Wed, 20 Nov 2024 10:54:22 +0300 Subject: [PATCH 2/2] Use global instead of function provided delta time in cmaera HFR patches. --- UnleashedRecomp/patches/fps_patches.cpp | 11 +++++++---- UnleashedRecompLib/config/SWA.toml | 26 ++++++++++++------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/UnleashedRecomp/patches/fps_patches.cpp b/UnleashedRecomp/patches/fps_patches.cpp index d55c5e90..1ad63b10 100644 --- a/UnleashedRecomp/patches/fps_patches.cpp +++ b/UnleashedRecomp/patches/fps_patches.cpp @@ -2,6 +2,7 @@ #include #include #include +#include float m_lastLoadingFrameDelta = 0.0f; std::chrono::steady_clock::time_point m_lastLoadingFrameTime; @@ -36,14 +37,16 @@ static double ComputeLerpFactor(double t, double deltaTime) return 1.0 - pow(1.0 - t, (30.0 + bias) / (fps + bias)); } -void CameraLerpFixMidAsmHook(PPCRegister& t, PPCRegister& deltaTime) +// It's important to use global delta time here instead of function provided +// delta time, as it might be time scaled and not match with 30 FPS behavior. +void CameraLerpFixMidAsmHook(PPCRegister& t) { - t.f64 = ComputeLerpFactor(t.f64, deltaTime.f64); + t.f64 = ComputeLerpFactor(t.f64, g_deltaTime); } -void CameraTargetSideOffsetLerpFixMidAsmHook(PPCVRegister& v13, PPCVRegister& v62, PPCRegister& deltaTime) +void CameraTargetSideOffsetLerpFixMidAsmHook(PPCVRegister& v13, PPCVRegister& v62) { - float factor = float(ComputeLerpFactor(double(v13.f32[0] * v62.f32[0]), deltaTime.f64)); + float factor = float(ComputeLerpFactor(double(v13.f32[0] * v62.f32[0]), g_deltaTime)); for (size_t i = 0; i < 4; i++) { diff --git a/UnleashedRecompLib/config/SWA.toml b/UnleashedRecompLib/config/SWA.toml index 8d2fe1a3..e154e37b 100644 --- a/UnleashedRecompLib/config/SWA.toml +++ b/UnleashedRecompLib/config/SWA.toml @@ -213,52 +213,52 @@ jump_address = 0x8247DD3C [[midasm_hook]] name = "CameraLerpFixMidAsmHook" address = 0x8247DD48 # Slope -registers = ["f0", "f21"] +registers = ["f0"] [[midasm_hook]] name = "CameraLerpFixMidAsmHook" address = 0x8247DDFC # Dash path binormal -registers = ["f0", "f21"] +registers = ["f0"] [[midasm_hook]] name = "CameraLerpFixMidAsmHook" address = 0x8247E280 # Target front offset -registers = ["f0", "f21"] +registers = ["f0"] [[midasm_hook]] name = "CameraLerpFixMidAsmHook" address = 0x8247E300 # Target -registers = ["f0", "f21"] +registers = ["f0"] [[midasm_hook]] name = "CameraLerpFixMidAsmHook" address = 0x8247E3C8 # Target -registers = ["f0", "f21"] +registers = ["f0"] [[midasm_hook]] name = "CameraLerpFixMidAsmHook" address = 0x8247E4A0 # Target up positive -registers = ["f0", "f21"] +registers = ["f0"] [[midasm_hook]] name = "CameraLerpFixMidAsmHook" address = 0x8247E4E8 # Target up negative -registers = ["f0", "f21"] +registers = ["f0"] [[midasm_hook]] name = "CameraLerpFixMidAsmHook" address = 0x8247E9FC # Position -registers = ["f0", "f21"] +registers = ["f0"] [[midasm_hook]] name = "CameraLerpFixMidAsmHook" address = 0x8247EA84 # Position up negative -registers = ["f0", "f21"] +registers = ["f0"] [[midasm_hook]] name = "CameraLerpFixMidAsmHook" address = 0x8247EA50 # Position up positive -registers = ["f0", "f21"] +registers = ["f0"] [[midasm_hook]] name = "CameraDeltaTimeFixMidAsmHook" @@ -269,7 +269,7 @@ jump_address = 0x8247ED34 [[midasm_hook]] name = "CameraLerpFixMidAsmHook" address = 0x8247ED40 # Distance offset 1 -registers = ["f0", "f21"] +registers = ["f0"] [[midasm_hook]] name = "CameraDeltaTimeFixMidAsmHook" @@ -280,12 +280,12 @@ jump_address = 0x8247ED58 [[midasm_hook]] name = "CameraLerpFixMidAsmHook" address = 0x8247ED64 # Distance offset 2 -registers = ["f13", "f21"] +registers = ["f13"] [[midasm_hook]] name = "CameraTargetSideOffsetLerpFixMidAsmHook" address = 0x8247F12C # Target side offset -registers = ["v13", "v62", "f21"] +registers = ["v13", "v62"] # 2D camera HFR fixes [[midasm_hook]]