Fix logic for the grind booster HFR fix. (#431)

This commit is contained in:
Skyth (Asilkan) 2025-02-19 01:54:38 +03:00 committed by GitHub
parent b8ae355915
commit f123ec7083
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 10 deletions

View file

@ -60,6 +60,7 @@ PPC_FUNC(sub_822C1130)
}
App::s_deltaTime = ctx.f1.f64;
App::s_time += App::s_deltaTime;
// This function can also be called by the loading thread,
// which SDL does not like. To prevent the OS from thinking

View file

@ -14,6 +14,7 @@ public:
static inline ELanguage s_language;
static inline double s_deltaTime;
static inline double s_time = 0.0; // How much time elapsed since the game started.
static void Restart(std::vector<std::string> restartArgs = {});
static void Exit();

View file

@ -106,14 +106,14 @@ static constexpr size_t OBJ_GRIND_DASH_PANEL_SIZE = 0x160;
void ObjGrindDashPanelAllocMidAsmHook(PPCRegister& r3)
{
r3.u32 += sizeof(std::chrono::steady_clock::time_point);
r3.u32 += sizeof(double);
}
// SWA::CObjGrindDashPanel::CObjGrindDashPanel
PPC_FUNC_IMPL(__imp__sub_82614228);
PPC_FUNC(sub_82614228)
{
new (base + ctx.r3.u32 + OBJ_GRIND_DASH_PANEL_SIZE) std::chrono::steady_clock::time_point();
*reinterpret_cast<double*>(base + ctx.r3.u32 + OBJ_GRIND_DASH_PANEL_SIZE) = 0.0;
__imp__sub_82614228(ctx, base);
}
@ -121,14 +121,15 @@ PPC_FUNC(sub_82614228)
PPC_FUNC_IMPL(__imp__sub_826145D8);
PPC_FUNC(sub_826145D8)
{
auto pLastHitTime = (std::chrono::steady_clock::time_point*)g_memory.Translate(ctx.r3.u32 + OBJ_GRIND_DASH_PANEL_SIZE);
auto now = std::chrono::steady_clock::now();
auto deltaTime = std::min(std::chrono::duration<double>(now - *pLastHitTime).count(), 1.0 / 15.0);
constexpr double REFERENCE_DELTA_TIME = 1.0 / 30.0;
constexpr double DELTA_TIME_TOLERANCE = 0.0001;
*pLastHitTime = now;
auto lastHitTime = reinterpret_cast<double*>(base + ctx.r3.u32 + OBJ_GRIND_DASH_PANEL_SIZE);
auto deltaTime = App::s_time - *lastHitTime;
if (deltaTime < 1.0 / 30.0)
return;
__imp__sub_826145D8(ctx, base);
if ((deltaTime + DELTA_TIME_TOLERANCE) > REFERENCE_DELTA_TIME)
{
__imp__sub_826145D8(ctx, base);
*lastHitTime = App::s_time;
}
}