Skip to content

Commit f123ec7

Browse files
Fix logic for the grind booster HFR fix. (#431)
1 parent b8ae355 commit f123ec7

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

UnleashedRecomp/app.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ PPC_FUNC(sub_822C1130)
6060
}
6161

6262
App::s_deltaTime = ctx.f1.f64;
63+
App::s_time += App::s_deltaTime;
6364

6465
// This function can also be called by the loading thread,
6566
// which SDL does not like. To prevent the OS from thinking

UnleashedRecomp/app.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class App
1414
static inline ELanguage s_language;
1515

1616
static inline double s_deltaTime;
17+
static inline double s_time = 0.0; // How much time elapsed since the game started.
1718

1819
static void Restart(std::vector<std::string> restartArgs = {});
1920
static void Exit();

UnleashedRecomp/patches/object_patches.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,29 +106,30 @@ static constexpr size_t OBJ_GRIND_DASH_PANEL_SIZE = 0x160;
106106

107107
void ObjGrindDashPanelAllocMidAsmHook(PPCRegister& r3)
108108
{
109-
r3.u32 += sizeof(std::chrono::steady_clock::time_point);
109+
r3.u32 += sizeof(double);
110110
}
111111

112112
// SWA::CObjGrindDashPanel::CObjGrindDashPanel
113113
PPC_FUNC_IMPL(__imp__sub_82614228);
114114
PPC_FUNC(sub_82614228)
115115
{
116-
new (base + ctx.r3.u32 + OBJ_GRIND_DASH_PANEL_SIZE) std::chrono::steady_clock::time_point();
116+
*reinterpret_cast<double*>(base + ctx.r3.u32 + OBJ_GRIND_DASH_PANEL_SIZE) = 0.0;
117117
__imp__sub_82614228(ctx, base);
118118
}
119119

120120
// SWA::CObjGrindDashPanel::MsgHitEventCollision::Impl
121121
PPC_FUNC_IMPL(__imp__sub_826145D8);
122122
PPC_FUNC(sub_826145D8)
123123
{
124-
auto pLastHitTime = (std::chrono::steady_clock::time_point*)g_memory.Translate(ctx.r3.u32 + OBJ_GRIND_DASH_PANEL_SIZE);
125-
auto now = std::chrono::steady_clock::now();
126-
auto deltaTime = std::min(std::chrono::duration<double>(now - *pLastHitTime).count(), 1.0 / 15.0);
124+
constexpr double REFERENCE_DELTA_TIME = 1.0 / 30.0;
125+
constexpr double DELTA_TIME_TOLERANCE = 0.0001;
127126

128-
*pLastHitTime = now;
127+
auto lastHitTime = reinterpret_cast<double*>(base + ctx.r3.u32 + OBJ_GRIND_DASH_PANEL_SIZE);
128+
auto deltaTime = App::s_time - *lastHitTime;
129129

130-
if (deltaTime < 1.0 / 30.0)
131-
return;
132-
133-
__imp__sub_826145D8(ctx, base);
130+
if ((deltaTime + DELTA_TIME_TOLERANCE) > REFERENCE_DELTA_TIME)
131+
{
132+
__imp__sub_826145D8(ctx, base);
133+
*lastHitTime = App::s_time;
134+
}
134135
}

0 commit comments

Comments
 (0)