ISource2ModEvents
Interface for registering and handling game events.
Provides functionality for hooking into Source2 game events, allowing plugins to inspect, modify, or block events.
Interface for registering game event listeners.
Allows plugins to:
- Listen to engine events
- Modify event data
- Block event propagation
Interface id ISource2ModEvents002 (SOURCE2MOD_EVENTS_INTERFACE) · Global g_pSource2ModEvents · Header source2mod/ISource2ModEvents.h
Types
Source2ModEventHookId
using Source2ModEventHookId = Source2ModHookId;A game event hook (HookGameEvent).
GameEventHandler
using GameEventHandler = Source2ModCallback<Action(IGameEvent* event, bool post, bool& dontBroadcast)>;Callback type for game events.
Methods
HookGameEvent
virtual Source2ModEventHookId HookGameEvent(const char* pchName, GameEventHandler handler, bool post) = 0;Registers a listener for a game event. The same event may be hooked as often as a plugin likes; each handler runs.
Whose it is, the core reads off the handler (see Source2ModCallback); what a plugin still holds at unload the core drops for it.
| Parameter | Type | Description |
|---|---|---|
pchName | const char* | Event name (e.g. "player_death") |
handler | GameEventHandler | A function, an object and a method, or a lambda |
post | bool | false to be called before the engine processes the event, true to be called after |
Returns Source2ModEventHookId — The id UnhookGameEvent(id) takes; 0 for an event the game does not have
UnhookGameEvent
virtual bool UnhookGameEvent(const char* pchName, const GameEventHandler& handler, bool post) = 0;
virtual bool UnhookGameEvent(Source2ModEventHookId id) = 0;Drops the hook with this handler -- a function or an object and a method; a lambda goes by its id.
Drops the hook HookGameEvent() returned the id for.
| Parameter | Type |
|---|---|
pchName | const char* |
handler | const GameEventHandler& |
post | bool |
id | Source2ModEventHookId |
Returns bool — true when one was found
Macros
HOOK_GAME_EVENT
#define HOOK_GAME_EVENT(passname, passfunc, post) g_pSource2ModEvents->HookGameEvent(passname, passfunc, post)Macro for hooking a game event.
UNHOOK_GAME_EVENT
#define UNHOOK_GAME_EVENT(passname, passfunc, post) g_pSource2ModEvents->UnhookGameEvent(passname, passfunc, post)Macro for dropping a game event hook (a function or an object and a method; a lambda goes by the id HOOK_GAME_EVENT returned).