VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::GameEvents Class Reference

Creates, fires and listens to game events. More...

#include <GameEvents.hpp>

+ Inheritance diagram for VoltMod::GameEvents:

Public Member Functions

 GameEvents (Interfaces &interfaces, const Bindings &bindings)
 
 ~GameEvents () override
 
 GameEvents (const GameEvents &)=delete
 
GameEvents & operator= (const GameEvents &)=delete
 
Status Available () const
 
IGameEvent * CreateEvent (std::string_view name)
 
bool FireEvent (IGameEvent *event, bool broadcast=true)
 
void FreeEvent (IGameEvent *event)
 
template<class TEvent >
Subscription On (std::function< void(const TEvent &)> handler)
 
void RemoveAllListeners ()
 
void OnServerStartup ()
 
IGameEventListener2 * GetClientLegacyListener (int slot) const
 
bool ClientListensTo (int slot, std::string_view eventName) const
 
void FireGameEvent (IGameEvent *event) override
 

Detailed Description

Creates, fires and listens to game events.

Definition at line 22 of file GameEvents.hpp.

Constructor & Destructor Documentation

◆ GameEvents() [1/2]

VoltMod::GameEvents::GameEvents ( Interfaces &  interfaces,
const Bindings &  bindings 
)

Reads IGameEventManager2 into interfaces. Both must outlive this service.

Definition at line 14 of file GameEvents.cpp.

References VoltMod::Bindings::GameEventManager, VoltMod::Interfaces::GameEventManager, VoltMod::Bindings::LegacyGameEventListener, VoltMod::Address::Ptr(), VoltMod::ReadFile(), and VoltMod::Log::Warn().

◆ ~GameEvents()

VoltMod::GameEvents::~GameEvents ( )
override

Definition at line 31 of file GameEvents.cpp.

References RemoveAllListeners().

◆ GameEvents() [2/2]

VoltMod::GameEvents::GameEvents ( const GameEvents &  )
delete

Member Function Documentation

◆ Available()

Status VoltMod::GameEvents::Available ( ) const

An error when the event manager did not resolve.

Definition at line 37 of file GameEvents.cpp.

References VoltMod::Error::Engine(), VoltMod::Bindings::GameEventManager, VoltMod::Interfaces::GameEventManager, and VoltMod::Error::Unsupported().

◆ ClientListensTo()

bool VoltMod::GameEvents::ClientListensTo ( int  slot,
std::string_view  eventName 
) const

Whether slot's client listens to eventName; a vanilla client takes only what its HUD needs, so an extra one can mean injected code.

Definition at line 60 of file GameEvents.cpp.

References VoltMod::Interfaces::GameEventManager, GetClientLegacyListener(), and VoltMod::ReadFile().

◆ CreateEvent()

IGameEvent * VoltMod::GameEvents::CreateEvent ( std::string_view  name)

◆ FireEvent()

bool VoltMod::GameEvents::FireEvent ( IGameEvent *  event,
bool  broadcast = true 
)

Definition at line 84 of file GameEvents.cpp.

References VoltMod::Interfaces::GameEventManager, and VoltMod::ReadFile().

◆ FireGameEvent()

void VoltMod::GameEvents::FireGameEvent ( IGameEvent *  event)
override

Definition at line 178 of file GameEvents.cpp.

References VoltMod::ReadFile().

◆ FreeEvent()

void VoltMod::GameEvents::FreeEvent ( IGameEvent *  event)

Definition at line 95 of file GameEvents.cpp.

References VoltMod::Interfaces::GameEventManager, and VoltMod::ReadFile().

◆ GetClientLegacyListener()

IGameEventListener2 * VoltMod::GameEvents::GetClientLegacyListener ( int  slot) const

slot's client listener: an event fired at it reaches that client alone. Null without a client or when the GetLegacyGameEventListener signature did not bind.

Definition at line 50 of file GameEvents.cpp.

References VoltMod::IsValidSlot(), and VoltMod::ReadFile().

Referenced by VoltMod::Messages::Broadcast(), VoltMod::Messages::BroadcastKey(), ClientListensTo(), and VoltMod::Messages::SendCenterHtml().

◆ On()

template<class TEvent >
Subscription VoltMod::GameEvents::On ( std::function< void(const TEvent &)>  handler)
inline

Subscribe to TEvent, a struct from <VoltMod/Events/EventTypes.hpp>, while the returned Subscription lives. An event whose Slot is invalid never reaches handler.

Definition at line 41 of file GameEvents.hpp.

References VoltMod::IsValidSlot(), and VoltMod::ReadFile().

◆ OnServerStartup()

void VoltMod::GameEvents::OnServerStartup ( )

Re-attach every event that still has a handler: map startup resets the engine's listeners.

Definition at line 128 of file GameEvents.cpp.

References VoltMod::Interfaces::GameEventManager, VoltMod::Log::Info(), VoltMod::ReadFile(), and VoltMod::Log::Warn().

◆ operator=()

GameEvents & VoltMod::GameEvents::operator= ( const GameEvents &  )
delete

◆ RemoveAllListeners()

void VoltMod::GameEvents::RemoveAllListeners ( )

Remove every handler and detach from the engine.

Definition at line 163 of file GameEvents.cpp.

References VoltMod::Interfaces::GameEventManager, and VoltMod::ReadFile().

Referenced by ~GameEvents().


The documentation for this class was generated from the following files: