Skip to content

Commit

Permalink
ChaosMod/Components: Make positioning of overriden functions consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Feb 14, 2025
1 parent b31566e commit f020502
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 245 deletions.
1 change: 0 additions & 1 deletion ChaosMod/Components/DebugMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class DebugMenu : public Component
DebugMenu();

virtual void OnRun() override;

virtual void OnKeyInput(DWORD key, bool repeated, bool isUpNow, bool isCtrlPressed, bool isShiftPressed,
bool isAltPressed) override;

Expand Down
36 changes: 18 additions & 18 deletions ChaosMod/Components/DebugSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,24 @@ DebugSocket::DebugSocket()
}
}

void DebugSocket::OnModPauseCleanup(PauseCleanupFlags cleanupFlags)
{
Close();
}

void DebugSocket::OnRun()
{
if (!m_DelegateQueue.empty())
{
std::lock_guard lock(m_DelegateQueueMutex);
while (!m_DelegateQueue.empty())
{
m_DelegateQueue.front()();
m_DelegateQueue.pop();
}
}
}

void DebugSocket::Close()
{
m_Server->stop();
Expand All @@ -288,22 +306,4 @@ void DebugSocket::ScriptLog(std::string_view scriptName, std::string_view text)
client->send(json.dump());
}

void DebugSocket::OnModPauseCleanup(PauseCleanupFlags cleanupFlags)
{
Close();
}

void DebugSocket::OnRun()
{
if (!m_DelegateQueue.empty())
{
std::lock_guard lock(m_DelegateQueueMutex);
while (!m_DelegateQueue.empty())
{
m_DelegateQueue.front()();
m_DelegateQueue.pop();
}
}
}

#endif
6 changes: 3 additions & 3 deletions ChaosMod/Components/DebugSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ class DebugSocket : public Component
public:
DebugSocket();

virtual void OnModPauseCleanup(PauseCleanupFlags cleanupFlags = {}) override;
virtual void OnRun() override;

private:
void Connect();

public:
void Close();

void ScriptLog(std::string_view scriptName, std::string_view text);

virtual void OnModPauseCleanup(PauseCleanupFlags cleanupFlags = {}) override;
virtual void OnRun() override;
};

#endif
76 changes: 38 additions & 38 deletions ChaosMod/Components/EffectDispatchTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,44 @@ EffectDispatchTimer::EffectDispatchTimer(const std::array<BYTE, 3> &timerColor)
g_OptionsManager.GetConfigValue({ "DistanceType" }, OPTION_DEFAULT_DISTANCE_TYPE));
}

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

if (m_EnableTimer && m_DrawTimerBar
&& (!ComponentExists<MetaModifiers>() || !GetComponent<MetaModifiers>()->HideChaosUI)
&& (!ComponentExists<MetaModifiers>() || !GetComponent<MetaModifiers>()->DisableChaos))
{
float percentage = m_FakeTimerPercentage != 0.f ? m_FakeTimerPercentage : m_TimerPercentage;

// Timer bar at the top
DRAW_RECT(.5f, .01f, 1.f, .021f, 0, 0, 0, 127, false);

if (ComponentExists<MetaModifiers>() && GetComponent<MetaModifiers>()->FlipChaosUI)
DRAW_RECT(1.f - percentage * .5f, .01f, percentage, .018f, m_TimerColor[0], m_TimerColor[1],
m_TimerColor[2], 255, false);
else
DRAW_RECT(percentage * .5f, .01f, percentage, .018f, m_TimerColor[0], m_TimerColor[1], m_TimerColor[2], 255,
false);
}

int deltaTime = curTime - m_Timer;

// The game was paused
if (deltaTime > 1000)
deltaTime = 0;

if (!m_PauseTimer)
{
if (m_DistanceChaosState.EnableDistanceBasedEffectDispatch)
UpdateTravelledDistance();
else
UpdateTimer(deltaTime);
}

m_Timer = curTime;
}

void EffectDispatchTimer::UpdateTimer(int deltaTime)
{
if (!m_EnableTimer || (ComponentExists<MetaModifiers>() && GetComponent<MetaModifiers>()->DisableChaos))
Expand Down Expand Up @@ -174,42 +212,4 @@ void EffectDispatchTimer::SetTimerPaused(bool pause)
bool EffectDispatchTimer::IsUsingDistanceBasedDispatch() const
{
return m_DistanceChaosState.EnableDistanceBasedEffectDispatch;
}

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

if (m_EnableTimer && m_DrawTimerBar
&& (!ComponentExists<MetaModifiers>() || !GetComponent<MetaModifiers>()->HideChaosUI)
&& (!ComponentExists<MetaModifiers>() || !GetComponent<MetaModifiers>()->DisableChaos))
{
float percentage = m_FakeTimerPercentage != 0.f ? m_FakeTimerPercentage : m_TimerPercentage;

// Timer bar at the top
DRAW_RECT(.5f, .01f, 1.f, .021f, 0, 0, 0, 127, false);

if (ComponentExists<MetaModifiers>() && GetComponent<MetaModifiers>()->FlipChaosUI)
DRAW_RECT(1.f - percentage * .5f, .01f, percentage, .018f, m_TimerColor[0], m_TimerColor[1],
m_TimerColor[2], 255, false);
else
DRAW_RECT(percentage * .5f, .01f, percentage, .018f, m_TimerColor[0], m_TimerColor[1], m_TimerColor[2], 255,
false);
}

int deltaTime = curTime - m_Timer;

// The game was paused
if (deltaTime > 1000)
deltaTime = 0;

if (!m_PauseTimer)
{
if (m_DistanceChaosState.EnableDistanceBasedEffectDispatch)
UpdateTravelledDistance();
else
UpdateTimer(deltaTime);
}

m_Timer = curTime;
}
4 changes: 2 additions & 2 deletions ChaosMod/Components/EffectDispatchTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class EffectDispatchTimer : public Component
public:
EffectDispatchTimer(const std::array<BYTE, 3> &timerColor);

virtual void OnRun() override;

private:
void UpdateTimer(int deltaTime);
void UpdateTravelledDistance();
Expand All @@ -53,6 +55,4 @@ class EffectDispatchTimer : public Component
void SetTimerPaused(bool pause);

bool IsUsingDistanceBasedDispatch() const;

virtual void OnRun() override;
};
6 changes: 3 additions & 3 deletions ChaosMod/Components/EffectDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ class EffectDispatcher : public Component

EffectDispatcher(const std::array<std::uint8_t, 3> &textColor, const std::array<std::uint8_t, 3> &effectTimerColor);

virtual void OnModPauseCleanup(PauseCleanupFlags cleanupFlags = {}) override;
virtual void OnRun() override;

private:
float GetEffectTopSpace();

void RegisterPermanentEffects();

public:
virtual void OnModPauseCleanup(PauseCleanupFlags cleanupFlags = {}) override;
virtual void OnRun() override;

void DrawEffectTexts();

void DispatchEffect(const EffectIdentifier &effectId,
Expand Down
1 change: 0 additions & 1 deletion ChaosMod/Components/EffectShortcuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class EffectShortcuts : public Component
EffectShortcuts();

virtual void OnRun() override;

virtual void OnKeyInput(DWORD key, bool repeated, bool isUpNow, bool isCtrlPressed, bool isShiftPressed,
bool isAltPressed) override;
};
16 changes: 8 additions & 8 deletions ChaosMod/Components/HelpTextQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@

#include "Memory/Hooks/GetLabelTextHook.h"

void HelpTextQueue::DisplayLabel(std::string_view label, std::uint8_t durationSecs)
{
if (durationSecs == 0)
return;

m_HelpTextQueue.emplace(label, durationSecs / 1000.f);
}

void HelpTextQueue::OnModPauseCleanup(PauseCleanupFlags cleanupFlags)
{
Hooks::ClearCustomLabels();
Expand All @@ -29,4 +21,12 @@ void HelpTextQueue::OnRun()

if ((helpText.TimerSecs -= GET_FRAME_TIME()) < 0.f)
m_HelpTextQueue.pop();
}

void HelpTextQueue::DisplayLabel(std::string_view label, std::uint8_t durationSecs)
{
if (durationSecs == 0)
return;

m_HelpTextQueue.emplace(label, durationSecs / 1000.f);
}
4 changes: 2 additions & 2 deletions ChaosMod/Components/HelpTextQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class HelpTextQueue : public Component
std::queue<HelpText> m_HelpTextQueue;

public:
void DisplayLabel(std::string_view label, std::uint8_t durationSecs);

virtual void OnModPauseCleanup(PauseCleanupFlags cleanupFlags = {}) override;
virtual void OnRun() override;

void DisplayLabel(std::string_view label, std::uint8_t durationSecs);
};
Loading

0 comments on commit f020502

Please sign in to comment.