Skip to content

Commit

Permalink
ChaosMod/EffectDispatcher: Fix broken effect timer logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Jan 19, 2025
1 parent a72e71a commit f1bd901
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
14 changes: 7 additions & 7 deletions ChaosMod/Components/EffectDispatchTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ void EffectDispatchTimer::UpdateTimer(int deltaTime)
return;

m_TimerPercentage += deltaTime
* (ComponentExists<MetaModifiers>() ? GetComponent<MetaModifiers>()->TimerSpeedModifier : 1.f)
/ m_EffectSpawnTime / 1000;
* (!ComponentExists<MetaModifiers>() ? 1.f : GetComponent<MetaModifiers>()->TimerSpeedModifier)
/ m_EffectSpawnTime / 1000.f;

if (m_TimerPercentage >= 1.f && m_DispatchEffectsOnTimer && ComponentExists<EffectDispatcher>())
{
Expand Down Expand Up @@ -135,8 +135,8 @@ void EffectDispatchTimer::ResetTimer()
int EffectDispatchTimer::GetRemainingTimerTime() const
{
return std::ceil(m_EffectSpawnTime
/ (ComponentExists<MetaModifiers>() ? GetComponent<MetaModifiers>()->TimerSpeedModifier : 1.f)
* (1 - m_TimerPercentage));
/ (!ComponentExists<MetaModifiers>() ? 1.f : GetComponent<MetaModifiers>()->TimerSpeedModifier)
* (1.f - m_TimerPercentage));
}

bool EffectDispatchTimer::ShouldDispatchEffectNow() const
Expand All @@ -161,7 +161,7 @@ void EffectDispatchTimer::ResetFakeTimerPercentage()

void EffectDispatchTimer::OnRun()
{
auto currentUpdateTime = GetTickCount64();
auto curTime = GetTickCount64();

if (m_EnableTimer && m_DrawTimerBar
&& (!ComponentExists<MetaModifiers>() || !GetComponent<MetaModifiers>()->HideChaosUI)
Expand All @@ -180,7 +180,7 @@ void EffectDispatchTimer::OnRun()
false);
}

int deltaTime = currentUpdateTime - m_Timer;
int deltaTime = curTime - m_Timer;

// The game was paused
if (deltaTime > 1000)
Expand All @@ -194,5 +194,5 @@ void EffectDispatchTimer::OnRun()
UpdateTimer(deltaTime);
}

m_Timer = currentUpdateTime;
m_Timer = curTime;
}
12 changes: 10 additions & 2 deletions ChaosMod/Components/EffectDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,22 @@ static void _DispatchEffect(EffectDispatcher *effectDispatcher, const EffectDisp
static void _OnRunEffects(LPVOID data)
{
auto effectDispatcher = reinterpret_cast<EffectDispatcher *>(data);
auto lastTime = GetTickCount64();
while (true)
{
int deltaTime = GetTickCount64()
- (!ComponentExists<EffectDispatchTimer>() ? 0 : GetComponent<EffectDispatchTimer>()->GetTimer());
auto curTime = GetTickCount64();
int deltaTime =
!ComponentExists<EffectDispatchTimer>()
? 0
: (curTime - lastTime)
* (ComponentExists<MetaModifiers>() ? GetComponent<MetaModifiers>()->EffectDurationModifier
: 1.f);
// The game was paused
if (deltaTime > 1000)
deltaTime = 0;

lastTime = curTime;

while (!effectDispatcher->EffectDispatchQueue.empty())
{
_DispatchEffect(effectDispatcher, effectDispatcher->EffectDispatchQueue.front());
Expand Down

0 comments on commit f1bd901

Please sign in to comment.