ISource2ModGameHooks

Hooks on the game functions plugins reach for most often, held by the core.

One detour per function, placed by the core from its gamedata the first time a plugin asks for it and taken out again once the last listener is gone -- a function nobody listens to is not hooked at all. A plugin registers a handler and never touches KHook, a signature or a prototype. When Valve changes one -- an argument added, the order swapped between platforms, as GroundAccelerate's is -- the core's gamedata and its one call site change, and the plugins keep running. Anything not in this set is still a KHOOK_MEMBER / KHOOK_VIRTUAL of the plugin's own.

Every hook hands its handler a context: the hooked object, the arguments, and result where the function returns something. What the handler returns is the usual Action:

  • Ignore -- nothing changed.
  • Override -- pre: the original still runs but the function returns ctx.result; post: the function returns ctx.result instead of what the original produced.
  • Supersede -- pre only: the original does not run, the function returns ctx.result. Stops the remaining pre handlers.

Arguments passed by pointer (the damage info, the move data, the weapon) can be changed in place and the original sees the change; arguments passed by value (a speed, a flag) cannot -- a handler that needs that keeps a raw KHOOK_MEMBER of its own. Handlers run in registration order, pre before the original and post after it; in post, result holds what the original returned.

HookX() returns a Source2ModGameHookId for UnhookX(); a plugin may have several handlers on one function. The handlers are the plugin's until it unhooks them or unloads, whichever comes first; nothing to undo in Unload().

Whose a handler is, the core reads off the handler (see Source2ModCallback): no call takes a plugin id. What a plugin still holds at unload the core drops for it.

Global g_pSource2ModGameHooks · Header source2mod/ISource2ModGameHooks.h

Types

GameHookHandler

template <typename CONTEXT> using GameHookHandler = Source2ModCallback<GameHookReturn<typename CONTEXT::Return>(CONTEXT& ctx, bool post)>;

A handler: the context, and whether this is the post pass. A function, an object and a method, or a lambda (Source2ModCallback).

Source2ModGameHookId

using Source2ModGameHookId = Source2ModHookId;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

Methods

HookTakeDamage

virtual Source2ModGameHookId HookTakeDamage(GameHookHandler<TakeDamageContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<TakeDamageContext>
postbool

HookCanAcquire

virtual Source2ModGameHookId HookCanAcquire(GameHookHandler<CanAcquireContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<CanAcquireContext>
postbool

HookCanMove

virtual Source2ModGameHookId HookCanMove(GameHookHandler<CanMoveContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<CanMoveContext>
postbool

HookCanUse

virtual Source2ModGameHookId HookCanUse(GameHookHandler<CanUseContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<CanUseContext>
postbool

HookPostThink

virtual Source2ModGameHookId HookPostThink(GameHookHandler<PostThinkContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<PostThinkContext>
postbool

HookProcessUsercmds

virtual Source2ModGameHookId HookProcessUsercmds(GameHookHandler<ProcessUsercmdsContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<ProcessUsercmdsContext>
postbool

HookSimulateUserCommands

virtual Source2ModGameHookId HookSimulateUserCommands(GameHookHandler<SimulateUserCommandsContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

HookRunCommand

virtual Source2ModGameHookId HookRunCommand(GameHookHandler<RunCommandContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<RunCommandContext>
postbool

HookAcceptInput

virtual Source2ModGameHookId HookAcceptInput(GameHookHandler<AcceptInputContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<AcceptInputContext>
postbool

HookTouch

virtual Source2ModGameHookId HookTouch(GameHookHandler<TouchContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<TouchContext>
postbool

HookDropWeapon

virtual Source2ModGameHookId HookDropWeapon(GameHookHandler<DropWeaponContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<DropWeaponContext>
postbool

HookAirAccelerate

virtual Source2ModGameHookId HookAirAccelerate(GameHookHandler<AirAccelerateContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<AirAccelerateContext>
postbool

HookAirMove

virtual Source2ModGameHookId HookAirMove(GameHookHandler<MovementContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<MovementContext>
postbool

HookCanUnduck

virtual Source2ModGameHookId HookCanUnduck(GameHookHandler<MovementContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<MovementContext>
postbool

HookCategorizePosition

virtual Source2ModGameHookId HookCategorizePosition(GameHookHandler<CategorizePositionContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<CategorizePositionContext>
postbool

HookCheckFalling

virtual Source2ModGameHookId HookCheckFalling(GameHookHandler<MovementContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<MovementContext>
postbool

HookCheckParameters

virtual Source2ModGameHookId HookCheckParameters(GameHookHandler<MovementContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<MovementContext>
postbool

HookCheckVelocity

virtual Source2ModGameHookId HookCheckVelocity(GameHookHandler<CheckVelocityContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<CheckVelocityContext>
postbool

HookCheckWater

virtual Source2ModGameHookId HookCheckWater(GameHookHandler<MovementContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<MovementContext>
postbool

HookDuck

virtual Source2ModGameHookId HookDuck(GameHookHandler<MovementContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<MovementContext>
postbool

HookFriction

virtual Source2ModGameHookId HookFriction(GameHookHandler<MovementContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<MovementContext>
postbool

HookFullWalkMove

virtual Source2ModGameHookId HookFullWalkMove(GameHookHandler<FullWalkMoveContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<FullWalkMoveContext>
postbool

HookGroundAccelerate

virtual Source2ModGameHookId HookGroundAccelerate(GameHookHandler<GroundAccelerateContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<GroundAccelerateContext>
postbool

HookLadderMove

virtual Source2ModGameHookId HookLadderMove(GameHookHandler<MovementContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<MovementContext>
postbool

HookMoveInit

virtual Source2ModGameHookId HookMoveInit(GameHookHandler<MovementContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<MovementContext>
postbool

HookPlayerMove

virtual Source2ModGameHookId HookPlayerMove(GameHookHandler<MovementContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<MovementContext>
postbool

HookProcessMovement

virtual Source2ModGameHookId HookProcessMovement(GameHookHandler<MovementContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<MovementContext>
postbool

HookSetupMove

virtual Source2ModGameHookId HookSetupMove(GameHookHandler<SetupMoveContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<SetupMoveContext>
postbool

HookTryPlayerMove

virtual Source2ModGameHookId HookTryPlayerMove(GameHookHandler<TryPlayerMoveContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<TryPlayerMoveContext>
postbool

HookWalkMove

virtual Source2ModGameHookId HookWalkMove(GameHookHandler<MovementContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<MovementContext>
postbool

HookWaterMove

virtual Source2ModGameHookId HookWaterMove(GameHookHandler<MovementContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<MovementContext>
postbool

HookOnJumpLegacy

virtual Source2ModGameHookId HookOnJumpLegacy(GameHookHandler<LegacyJumpContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<LegacyJumpContext>
postbool

HookOnJumpModern

virtual Source2ModGameHookId HookOnJumpModern(GameHookHandler<ModernJumpContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<ModernJumpContext>
postbool

HookCheckJumpButtonLegacy

virtual Source2ModGameHookId HookCheckJumpButtonLegacy(GameHookHandler<LegacyJumpContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<LegacyJumpContext>
postbool

HookCheckJumpButtonModern

virtual Source2ModGameHookId HookCheckJumpButtonModern(GameHookHandler<ModernJumpContext> handler, bool post) = 0;

What HookX() returns and UnhookX() takes: one registered handler. A plugin may register several handlers on the same function and drop any one of them; whatever it still holds at unload the core drops for it.

ParameterType
handlerGameHookHandler<ModernJumpContext>
postbool

UnhookTakeDamage

virtual bool UnhookTakeDamage(Source2ModGameHookId id) = 0;
virtual bool UnhookTakeDamage(const GameHookHandler<TakeDamageContext>& handler, bool post) = 0;

Drops a handler: the one HookX() returned the id for, or the one that is this function or object and method (a lambda goes by its id). True when it was found.

UnhookCanAcquire

virtual bool UnhookCanAcquire(Source2ModGameHookId id) = 0;
virtual bool UnhookCanAcquire(const GameHookHandler<CanAcquireContext>& handler, bool post) = 0;

UnhookCanMove

virtual bool UnhookCanMove(Source2ModGameHookId id) = 0;
virtual bool UnhookCanMove(const GameHookHandler<CanMoveContext>& handler, bool post) = 0;

UnhookCanUse

virtual bool UnhookCanUse(Source2ModGameHookId id) = 0;
virtual bool UnhookCanUse(const GameHookHandler<CanUseContext>& handler, bool post) = 0;

UnhookPostThink

virtual bool UnhookPostThink(Source2ModGameHookId id) = 0;
virtual bool UnhookPostThink(const GameHookHandler<PostThinkContext>& handler, bool post) = 0;

UnhookProcessUsercmds

virtual bool UnhookProcessUsercmds(Source2ModGameHookId id) = 0;
virtual bool UnhookProcessUsercmds(const GameHookHandler<ProcessUsercmdsContext>& handler, bool post) = 0;

UnhookSimulateUserCommands

virtual bool UnhookSimulateUserCommands(Source2ModGameHookId id) = 0;
virtual bool UnhookSimulateUserCommands(const GameHookHandler<SimulateUserCommandsContext>& handler, bool post) = 0;

UnhookRunCommand

virtual bool UnhookRunCommand(Source2ModGameHookId id) = 0;
virtual bool UnhookRunCommand(const GameHookHandler<RunCommandContext>& handler, bool post) = 0;

UnhookAcceptInput

virtual bool UnhookAcceptInput(Source2ModGameHookId id) = 0;
virtual bool UnhookAcceptInput(const GameHookHandler<AcceptInputContext>& handler, bool post) = 0;

UnhookTouch

virtual bool UnhookTouch(Source2ModGameHookId id) = 0;
virtual bool UnhookTouch(const GameHookHandler<TouchContext>& handler, bool post) = 0;

UnhookDropWeapon

virtual bool UnhookDropWeapon(Source2ModGameHookId id) = 0;
virtual bool UnhookDropWeapon(const GameHookHandler<DropWeaponContext>& handler, bool post) = 0;

UnhookAirAccelerate

virtual bool UnhookAirAccelerate(Source2ModGameHookId id) = 0;
virtual bool UnhookAirAccelerate(const GameHookHandler<AirAccelerateContext>& handler, bool post) = 0;

UnhookAirMove

virtual bool UnhookAirMove(Source2ModGameHookId id) = 0;
virtual bool UnhookAirMove(const GameHookHandler<MovementContext>& handler, bool post) = 0;

UnhookCanUnduck

virtual bool UnhookCanUnduck(Source2ModGameHookId id) = 0;
virtual bool UnhookCanUnduck(const GameHookHandler<MovementContext>& handler, bool post) = 0;

UnhookCategorizePosition

virtual bool UnhookCategorizePosition(Source2ModGameHookId id) = 0;
virtual bool UnhookCategorizePosition(const GameHookHandler<CategorizePositionContext>& handler, bool post) = 0;

UnhookCheckFalling

virtual bool UnhookCheckFalling(Source2ModGameHookId id) = 0;
virtual bool UnhookCheckFalling(const GameHookHandler<MovementContext>& handler, bool post) = 0;

UnhookCheckParameters

virtual bool UnhookCheckParameters(Source2ModGameHookId id) = 0;
virtual bool UnhookCheckParameters(const GameHookHandler<MovementContext>& handler, bool post) = 0;

UnhookCheckVelocity

virtual bool UnhookCheckVelocity(Source2ModGameHookId id) = 0;
virtual bool UnhookCheckVelocity(const GameHookHandler<CheckVelocityContext>& handler, bool post) = 0;

UnhookCheckWater

virtual bool UnhookCheckWater(Source2ModGameHookId id) = 0;
virtual bool UnhookCheckWater(const GameHookHandler<MovementContext>& handler, bool post) = 0;

UnhookDuck

virtual bool UnhookDuck(Source2ModGameHookId id) = 0;
virtual bool UnhookDuck(const GameHookHandler<MovementContext>& handler, bool post) = 0;

UnhookFriction

virtual bool UnhookFriction(Source2ModGameHookId id) = 0;
virtual bool UnhookFriction(const GameHookHandler<MovementContext>& handler, bool post) = 0;

UnhookFullWalkMove

virtual bool UnhookFullWalkMove(Source2ModGameHookId id) = 0;
virtual bool UnhookFullWalkMove(const GameHookHandler<FullWalkMoveContext>& handler, bool post) = 0;

UnhookGroundAccelerate

virtual bool UnhookGroundAccelerate(Source2ModGameHookId id) = 0;
virtual bool UnhookGroundAccelerate(const GameHookHandler<GroundAccelerateContext>& handler, bool post) = 0;

UnhookLadderMove

virtual bool UnhookLadderMove(Source2ModGameHookId id) = 0;
virtual bool UnhookLadderMove(const GameHookHandler<MovementContext>& handler, bool post) = 0;

UnhookMoveInit

virtual bool UnhookMoveInit(Source2ModGameHookId id) = 0;
virtual bool UnhookMoveInit(const GameHookHandler<MovementContext>& handler, bool post) = 0;

UnhookPlayerMove

virtual bool UnhookPlayerMove(Source2ModGameHookId id) = 0;
virtual bool UnhookPlayerMove(const GameHookHandler<MovementContext>& handler, bool post) = 0;

UnhookProcessMovement

virtual bool UnhookProcessMovement(Source2ModGameHookId id) = 0;
virtual bool UnhookProcessMovement(const GameHookHandler<MovementContext>& handler, bool post) = 0;

UnhookSetupMove

virtual bool UnhookSetupMove(Source2ModGameHookId id) = 0;
virtual bool UnhookSetupMove(const GameHookHandler<SetupMoveContext>& handler, bool post) = 0;

UnhookTryPlayerMove

virtual bool UnhookTryPlayerMove(Source2ModGameHookId id) = 0;
virtual bool UnhookTryPlayerMove(const GameHookHandler<TryPlayerMoveContext>& handler, bool post) = 0;

UnhookWalkMove

virtual bool UnhookWalkMove(Source2ModGameHookId id) = 0;
virtual bool UnhookWalkMove(const GameHookHandler<MovementContext>& handler, bool post) = 0;

UnhookWaterMove

virtual bool UnhookWaterMove(Source2ModGameHookId id) = 0;
virtual bool UnhookWaterMove(const GameHookHandler<MovementContext>& handler, bool post) = 0;

UnhookOnJumpLegacy

virtual bool UnhookOnJumpLegacy(Source2ModGameHookId id) = 0;
virtual bool UnhookOnJumpLegacy(const GameHookHandler<LegacyJumpContext>& handler, bool post) = 0;

UnhookOnJumpModern

virtual bool UnhookOnJumpModern(Source2ModGameHookId id) = 0;
virtual bool UnhookOnJumpModern(const GameHookHandler<ModernJumpContext>& handler, bool post) = 0;

UnhookCheckJumpButtonLegacy

virtual bool UnhookCheckJumpButtonLegacy(Source2ModGameHookId id) = 0;
virtual bool UnhookCheckJumpButtonLegacy(const GameHookHandler<LegacyJumpContext>& handler, bool post) = 0;

UnhookCheckJumpButtonModern

virtual bool UnhookCheckJumpButtonModern(Source2ModGameHookId id) = 0;
virtual bool UnhookCheckJumpButtonModern(const GameHookHandler<ModernJumpContext>& handler, bool post) = 0;

IsAvailable

virtual bool IsAvailable(GameHook hook) = 0;

False when the core's gamedata has no entry for the function on this platform -- handlers can still be registered, they just never run.

ParameterType
hookGameHook

TakeDamageContext

CBaseEntity::TakeDamageOld(info, result) -> int64

Fields

FieldType
entityCBaseEntity*
infoCTakeDamageInfo*
damageResultCTakeDamageResult*
resultstd::int64_t

CanAcquireContext

CCSPlayer_ItemServices::CanAcquire(item, method, unk) -> AcquireResult

Fields

CanMoveContext

CCSPlayerPawnBase::CanMove() -> bool; false while frozen, defusing, ...

Fields

FieldType
pawnCCSPlayerPawnBase*
resultbool

CanUseContext

CCSPlayer_WeaponServices::CanUse(weapon) -> bool

Fields

FieldType
servicesCCSPlayer_WeaponServices*
weaponCBasePlayerWeapon*
resultbool

PostThinkContext

CCSPlayerPawn::PostThink()

Fields

FieldType
pawnCCSPlayerPawnBase*

ProcessUsercmdsContext

CCSPlayerController::ProcessUserCmd(cmds, count, paused, margin) -> void*. The commands are CUserCmd (a protobuf-backed type), left untyped here.

Fields

FieldType
controllerCCSPlayerController*
cmdsvoid*
countint
pausedbool
marginfloat
resultvoid*

SimulateUserCommandsContext

CBasePlayerController::OnSimulateUserCommands()

Fields

FieldType
controllerCBasePlayerController*

RunCommandContext

CPlayer_MovementServices::RunCommand(cmd), on CCSPlayer_MovementServices' vtable; the command is a CUserCmd.

Fields

FieldType
servicesCCSPlayer_MovementServices*
cmdvoid*

AcceptInputContext

CEntityIdentity::AcceptInput(name, activator, caller, value, ...) -> bool

Fields

FieldType
identityCEntityIdentity*
inputNameCUtlSymbolLarge*
activatorCEntityInstance*
callerCEntityInstance*
valuevariant_t*
resultbool

TouchContext

CBaseEntity::Touch(other), on CBaseEntity's own vtable -- an entity class that overrides Touch is not seen here.

Fields

FieldType
entityCBaseEntity*
otherCBaseEntity*

DropWeaponContext

CCSPlayer_WeaponServices::DropWeapon(weapon, target, velocity)

Fields

FieldType
servicesCCSPlayer_WeaponServices*
weaponCBasePlayerWeapon*
targetVector*
velocityVector*

MovementContext

The CCSPlayer_MovementServices functions that take the move data alone: AirMove, CheckFalling, CheckParameters, Duck, Friction, PlayerMove, ProcessMovement, WalkMove, WaterMove (void), and CanUnduck, CheckWater, LadderMove, MoveInit (bool, in result).

Fields

FieldType
servicesCCSPlayer_MovementServices*
moveDataCMoveData*
resultbool

AirAccelerateContext

CCSPlayer_MovementServices::AirAccelerate(move, wishDirection, wishSpeed, acceleration)

Fields

FieldType
servicesCCSPlayer_MovementServices*
moveDataCMoveData*
wishDirectionVector*
wishSpeedfloat
accelerationfloat

GroundAccelerateContext

CCSPlayer_MovementServices::GroundAccelerate(move, wishDirection, frameTime, wishSpeed, acceleration). The engine's argument order differs between Linux and Windows; here it is always this one.

Fields

FieldType
servicesCCSPlayer_MovementServices*
moveDataCMoveData*
wishDirectionVector*
frameTimefloat
wishSpeedfloat
accelerationfloat

CategorizePositionContext

CCSPlayer_MovementServices::CategorizePosition(move, stayOnGround)

Fields

FieldType
servicesCCSPlayer_MovementServices*
moveDataCMoveData*
stayOnGroundbool

CheckVelocityContext

CCSPlayer_MovementServices::CheckVelocity(move, unk)

Fields

FieldType
servicesCCSPlayer_MovementServices*
moveDataCMoveData*
unkvoid*

FullWalkMoveContext

CCSPlayer_MovementServices::FullWalkMove(move, onGround)

Fields

FieldType
servicesCCSPlayer_MovementServices*
moveDataCMoveData*
onGroundbool

SetupMoveContext

CCSPlayer_MovementServices::SetupMove(cmd, move); the command is a CUserCmd.

Fields

FieldType
servicesCCSPlayer_MovementServices*
cmdCUserCmd*
moveDataCMoveData*

TryPlayerMoveContext

CCSPlayer_MovementServices::TryPlayerMove(move, firstDest, firstTrace, isSurfing)

Fields

FieldType
servicesCCSPlayer_MovementServices*
moveDataCMoveData*
firstDestVector*
firstTraceCGameTrace*
isSurfingbool*

LegacyJumpContext

CCSPlayerLegacyJump::OnJump / CheckJumpButton(move)

Fields

FieldType
jumpCCSPlayerLegacyJump*
moveDataCMoveData*

ModernJumpContext

CCSPlayerModernJump::OnJump / CheckJumpButton(move)

Fields

FieldType
jumpCCSPlayerModernJump*
moveDataCMoveData*

GameHookReturn

What a game hook handler answers -- KHook's { action, value }.

return { Action::Supersede, 0 };              // skip the original, it returns 0
return { Action::Override, AcquireResult::NotAllowedByMode };
return { Action::Supersede, ctx.CallOriginal() };
return Action::Ignore;                         // an action alone

An action alone takes its value from ctx.result, so a handler that sets the field and returns Override / Supersede keeps working. For a function without a return value there is only the action.

Several handlers on one function: Supersede stops the chain, otherwise the strongest action wins; each value a handler returns lands in ctx.result right away, so the last one to return a value decides it and the next handler sees it there.

Fields

FieldType
actionAction
hasValuebool

Constructors

GameHookReturn(Action a);
GameHookReturn(Action a, RETURN v);

Enums

AcquireResult

enum AcquireResult : std::uint32_t

What CCSPlayer_ItemServices::CanAcquire answers.

NameValue
Allowed0
InvalidItem
AlreadyOwned
AlreadyPurchased
ReachedGrenadeTypeLimit
ReachedGrenadeTotalLimit
NotAllowedByTeam
NotAllowedByMap
NotAllowedByMode
NotAllowedForPurchase
NotAllowedByProhibition

AcquireMethod

enum AcquireMethod : std::uint32_t

How an item is being acquired in CCSPlayer_ItemServices::CanAcquire.

NameValue
PickUp0
Buy
BuyWithCtrl

GameHook

enum class GameHook : int

The hooks, for IsAvailable().

Name
TakeDamage
CanAcquire
CanMove
CanUse
PostThink
ProcessUsercmds
SimulateUserCommands
RunCommand
AcceptInput
Touch
DropWeapon
AirAccelerate
AirMove
CanUnduck
CategorizePosition
CheckFalling
CheckParameters
CheckVelocity
CheckWater
Duck
Friction
FullWalkMove
GroundAccelerate
LadderMove
MoveInit
PlayerMove
ProcessMovement
SetupMove
TryPlayerMove
WalkMove
WaterMove
OnJumpLegacy
OnJumpModern
CheckJumpButtonLegacy
CheckJumpButtonModern
Count

Macros

SOURCE2MOD_GAMEHOOK_CALL_ORIGINAL

#define SOURCE2MOD_GAMEHOOK_CALL_ORIGINAL(RET) \
    using Return = RET;                                                   
    RET CallOriginal() const { return callOriginal_(callOriginalData_); } 
    RET (*callOriginal_)(const void*) = nullptr;                          
    const void* callOriginalData_ = nullptr;

Every context ends with CallOriginal(): the game's function, run now with the arguments the game passed, past every hook on it -- SourceHook's SH_CALL. What it returns is what the game would have answered.

In a pre handler the function really runs (with all its side effects), so a handler that calls it should answer Supersede with ctx.result set to the value, or the game runs it a second time after the handlers:

const AcquireResult game = ctx.CallOriginal(); ctx.result = game == AcquireResult::Allowed && Blocked(ctx) ? AcquireResult::NotAllowedByMode : game; return Action::Supersede;

A changed pointed-to object (the damage info, the move data) counts; a scalar field changed in the context does not, the call takes what the game passed. In a post handler ctx.result already holds the game's answer.

The two members after it belong to the core; the movement contexts shared by void and bool functions answer false for the void ones.

On this page

TypesGameHookHandlerSource2ModGameHookIdMethodsHookTakeDamageHookCanAcquireHookCanMoveHookCanUseHookPostThinkHookProcessUsercmdsHookSimulateUserCommandsHookRunCommandHookAcceptInputHookTouchHookDropWeaponHookAirAccelerateHookAirMoveHookCanUnduckHookCategorizePositionHookCheckFallingHookCheckParametersHookCheckVelocityHookCheckWaterHookDuckHookFrictionHookFullWalkMoveHookGroundAccelerateHookLadderMoveHookMoveInitHookPlayerMoveHookProcessMovementHookSetupMoveHookTryPlayerMoveHookWalkMoveHookWaterMoveHookOnJumpLegacyHookOnJumpModernHookCheckJumpButtonLegacyHookCheckJumpButtonModernUnhookTakeDamageUnhookCanAcquireUnhookCanMoveUnhookCanUseUnhookPostThinkUnhookProcessUsercmdsUnhookSimulateUserCommandsUnhookRunCommandUnhookAcceptInputUnhookTouchUnhookDropWeaponUnhookAirAccelerateUnhookAirMoveUnhookCanUnduckUnhookCategorizePositionUnhookCheckFallingUnhookCheckParametersUnhookCheckVelocityUnhookCheckWaterUnhookDuckUnhookFrictionUnhookFullWalkMoveUnhookGroundAccelerateUnhookLadderMoveUnhookMoveInitUnhookPlayerMoveUnhookProcessMovementUnhookSetupMoveUnhookTryPlayerMoveUnhookWalkMoveUnhookWaterMoveUnhookOnJumpLegacyUnhookOnJumpModernUnhookCheckJumpButtonLegacyUnhookCheckJumpButtonModernIsAvailableTakeDamageContextFieldsCanAcquireContextFieldsCanMoveContextFieldsCanUseContextFieldsPostThinkContextFieldsProcessUsercmdsContextFieldsSimulateUserCommandsContextFieldsRunCommandContextFieldsAcceptInputContextFieldsTouchContextFieldsDropWeaponContextFieldsMovementContextFieldsAirAccelerateContextFieldsGroundAccelerateContextFieldsCategorizePositionContextFieldsCheckVelocityContextFieldsFullWalkMoveContextFieldsSetupMoveContextFieldsTryPlayerMoveContextFieldsLegacyJumpContextFieldsModernJumpContextFieldsGameHookReturnFieldsConstructorsEnumsAcquireResultAcquireMethodGameHookMacrosSOURCE2MOD_GAMEHOOK_CALL_ORIGINAL