ISource2ModEvents

Interface for registering and handling game events.

Provides functionality for hooking into Source2 game events, allowing plugins to inspect, modify, or block events.

Events correspond to engine-defined events (e.g. "player_death").

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.

ParameterTypeDescription
pchNameconst char*Event name (e.g. "player_death")
handlerGameEventHandlerA function, an object and a method, or a lambda
postboolfalse 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.

ParameterType
pchNameconst char*
handlerconst GameEventHandler&
postbool
idSource2ModEventHookId

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).

On this page