diff --git a/UnleashedRecomp/game.cpp b/UnleashedRecomp/game.cpp index e285eff..07e8d38 100644 --- a/UnleashedRecomp/game.cpp +++ b/UnleashedRecomp/game.cpp @@ -246,16 +246,6 @@ PPC_FUNC(sub_825197C0) __imp__sub_825197C0(ctx, base); } -void HighFrameRateDeltaTimeFixMidAsmHook(PPCRegister& f1) -{ - // Having 60 FPS threshold ensures we still retain - // the original game behavior when locked to 30/60 FPS. - constexpr double threshold = 1.0 / 60.0; - - if (f1.f64 < threshold) - f1.f64 = threshold; -} - void GetStageIDMidAsmHook(PPCRegister& r5) { m_pStageID = *(xpointer*)g_memory.Translate(r5.u32); @@ -331,3 +321,53 @@ PPC_FUNC(sub_82608E60) } #pragma endregion + +#pragma region HFR Patches + +void HighFrameRateDeltaTimeFixMidAsmHook(PPCRegister& f1) +{ + // Having 60 FPS threshold ensures we still retain + // the original game behavior when locked to 30/60 FPS. + constexpr double threshold = 1.0 / 60.0; + + if (f1.f64 < threshold) + f1.f64 = threshold; +} + +void CameraDeltaTimeFixMidAsmHook(PPCRegister& dest, PPCRegister& src) +{ + dest.f64 = src.f64 / 30.0; +} + +void CameraDeltaTimeFixMidAsmHook(PPCRegister& dest) +{ + dest.f64 /= 30.0; +} + +static double ComputeLerpFactor(double t, double deltaTime) +{ + // This type of lerp still falls behind when + // playing catch with a constantly moving position. + // The bias helps with approximately bringing it closer. + double fps = 1.0 / deltaTime; + double bias = t * 60.0; + return 1.0 - pow(1.0 - t, (30.0 + bias) / (fps + bias)); +} + +void CameraLerpFixMidAsmHook(PPCRegister& t, PPCRegister& deltaTime) +{ + t.f64 = ComputeLerpFactor(t.f64, deltaTime.f64); +} + +void CameraTargetSideOffsetLerpFixMidAsmHook(PPCVRegister& v13, PPCVRegister& v62, PPCRegister& deltaTime) +{ + float factor = float(ComputeLerpFactor(double(v13.f32[0] * v62.f32[0]), deltaTime.f64)); + + for (size_t i = 0; i < 4; i++) + { + v62.f32[i] = factor; + v13.f32[i] = 1.0f; + } +} + +#pragma endregion diff --git a/UnleashedRecompLib/config/SWA.toml b/UnleashedRecompLib/config/SWA.toml index 452bbd5..330efa2 100644 --- a/UnleashedRecompLib/config/SWA.toml +++ b/UnleashedRecompLib/config/SWA.toml @@ -203,6 +203,90 @@ name = "HighFrameRateDeltaTimeFixMidAsmHook" address = 0x82419408 registers = ["f1"] +# 3D camera HFR fixes +[[midasm_hook]] +name = "CameraDeltaTimeFixMidAsmHook" +address = 0x8247DD38 # Slope +registers = ["f0", "f31"] +jump_address = 0x8247DD3C + +[[midasm_hook]] +name = "CameraLerpFixMidAsmHook" +address = 0x8247DD48 # Slope +registers = ["f0", "f21"] + +[[midasm_hook]] +name = "CameraLerpFixMidAsmHook" +address = 0x8247DDFC # Dash path binormal +registers = ["f0", "f21"] + +[[midasm_hook]] +name = "CameraLerpFixMidAsmHook" +address = 0x8247E280 # Target front offset +registers = ["f0", "f21"] + +[[midasm_hook]] +name = "CameraLerpFixMidAsmHook" +address = 0x8247E300 # Target +registers = ["f0", "f21"] + +[[midasm_hook]] +name = "CameraLerpFixMidAsmHook" +address = 0x8247E3C8 # Target +registers = ["f0", "f21"] + +[[midasm_hook]] +name = "CameraLerpFixMidAsmHook" +address = 0x8247E4A0 # Target up positive +registers = ["f0", "f21"] + +[[midasm_hook]] +name = "CameraLerpFixMidAsmHook" +address = 0x8247E4E8 # Target up negative +registers = ["f0", "f21"] + +[[midasm_hook]] +name = "CameraLerpFixMidAsmHook" +address = 0x8247E9FC # Position +registers = ["f0", "f21"] + +[[midasm_hook]] +name = "CameraLerpFixMidAsmHook" +address = 0x8247EA84 # Position up negative +registers = ["f0", "f21"] + +[[midasm_hook]] +name = "CameraLerpFixMidAsmHook" +address = 0x8247EA50 # Position up positive +registers = ["f0", "f21"] + +[[midasm_hook]] +name = "CameraDeltaTimeFixMidAsmHook" +address = 0x8247ED30 # Distance offset 1 +registers = ["f0", "f12"] +jump_address = 0x8247ED34 + +[[midasm_hook]] +name = "CameraLerpFixMidAsmHook" +address = 0x8247ED40 # Distance offset 1 +registers = ["f0", "f21"] + +[[midasm_hook]] +name = "CameraDeltaTimeFixMidAsmHook" +address = 0x8247ED54 # Distance offset 2 +registers = ["f13"] +jump_address = 0x8247ED58 + +[[midasm_hook]] +name = "CameraLerpFixMidAsmHook" +address = 0x8247ED64 # Distance offset 2 +registers = ["f13", "f21"] + +[[midasm_hook]] +name = "CameraTargetSideOffsetLerpFixMidAsmHook" +address = 0x8247F12C # Target side offset +registers = ["v13", "v62", "f21"] + [[midasm_hook]] name = "GetStageIDMidAsmHook" address = 0x82528198 @@ -226,4 +310,4 @@ registers = ["r3", "r11"] [[midasm_hook]] name = "WerehogBattleMusicMidAsmHook" address = 0x82B47728 -registers = ["r3", "r11"] \ No newline at end of file +registers = ["r3", "r11"]