Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
Re-inject modified player_hurt events
Browse files Browse the repository at this point in the history
When the hitevent module fixes up any player_hurt events, we now
re-inject them back into the engine. This enables
`C_TFPlayer::FireGameEvent` to correctly show bonus effects like crit
and mini crit sprites.

To avoid an infinite loop, the `HitEvents` module maintains a list of
re-injected events and ignores any events sent by the module itself.
  • Loading branch information
dalegaard committed Feb 14, 2021
1 parent f01001d commit b61a2b6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CastingEssentials/Modules/HitEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ void HitEvents::UpdateEnabledState()

void HitEvents::FireGameEventOverride(CDamageAccountPanel* pThis, IGameEvent* event)
{

if (auto it = std::find(m_EventsToIgnore.cbegin(), m_EventsToIgnore.cend(), event); it != m_EventsToIgnore.cend()) {
// We injected this event ourselves, ignore it.
m_FireGameEventHook.SetState(Hooking::HookAction::SUPERCEDE);
m_EventsToIgnore.erase(it);
return;
}

auto is_player_hurt = stricmp(event->GetName(), "player_hurt") == 0;

auto crossbow_only = ce_hitevents_healing_crossbow_only.GetBool();
Expand Down Expand Up @@ -251,7 +259,14 @@ void HitEvents::FireGameEventOverride(CDamageAccountPanel* pThis, IGameEvent* ev
}

newEvent->SetInt(is_player_hurt ? "attacker" : "healer", localPlayer->GetUserID());

m_FireGameEventHook.GetOriginal()(pThis, newEvent.get());

if (is_player_hurt) {
// We re-inject player hurt events with the updated info so that stuff like "crit!" sprites will show up.
m_EventsToIgnore.push_back(newEvent.get());
gameeventmanager->FireEventClientSide(newEvent.release()); // We need to release ownership here as FireEventClientSide will free the event!
}
}
else {
m_FireGameEventHook.SetState(Hooking::HookAction::IGNORE);
Expand Down

0 comments on commit b61a2b6

Please sign in to comment.