ISource2ModFunctions

Interface id ISource2ModFunctions002 (SOURCE2MOD_FUNCTIONS_INTERFACE) · Global g_pSource2ModFunctions · Header source2mod/ISource2ModFunctions.h

Methods

Find

virtual ISource2ModFunction* Find(const char* name) = 0;

The function a gamedata entry with a "function" object describes.

ParameterType
nameconst char*

Returns ISource2ModFunction* — nullptr when there is no such entry, it has no "function", or its signature does not match the running game (the reason is on the console).

Create

virtual ISource2ModFunction* Create(PluginId owner, void* address, void** vtable, int vtableIndex, bool isMember, Source2ModType returnType, const Source2ModType* params, int count) = 0;

A function described here instead of in gamedata.

ParameterTypeDescription
ownerPluginIdThe plugin it belongs to (g_PluginID); freed when it unloads.
addressvoid*The function; nullptr for a virtual.
vtablevoid**For a virtual called through one class's vtable whatever the object's class; nullptr to use the object's own.
vtableIndexintThe slot of a virtual; -1 for a function at @p address.
isMemberboolWhether the first parameter is this (a virtual always is).
returnTypeSource2ModType
paramsconst Source2ModType*The parameter types, this included.
countint

Destroy

virtual void Destroy(ISource2ModFunction* function) = 0;

Frees one from Create() / From*(). One from Find() is left alone.

ParameterType
functionISource2ModFunction*

FromGameConfig

virtual ISource2ModFunction* FromGameConfig(PluginId owner, const char* name, const FunctionTypes& types) = 0;

A gamedata entry (its signature, symbol or -- a virtual -- offset), with the types given here instead of in a "function" object.

ParameterType
ownerPluginId
nameconst char*
typesconst FunctionTypes&

FromSignature

virtual ISource2ModFunction* FromSignature(PluginId owner, const char* module, const char* signature, const FunctionTypes& types, const char* section = "") = 0;

A signature of the plugin's own in a module ("server"), optionally only in one section (".text").

ParameterTypeDefault
ownerPluginId
moduleconst char*
signatureconst char*
typesconst FunctionTypes&
sectionconst char*""

FromSignatureRelative

virtual ISource2ModFunction* FromSignatureRelative(PluginId owner, const char* module, const char* signature, int offset, int nextInstructionOffset, const FunctionTypes& types, const char* section = "") = 0;

The function a matched call / jmp / lea refers to: the rel32 at @p offset from the match, relative to the next instruction at @p nextInstructionOffset (a call or jmp at the start: 1, 5).

ParameterTypeDefault
ownerPluginId
moduleconst char*
signatureconst char*
offsetint
nextInstructionOffsetint
typesconst FunctionTypes&
sectionconst char*""

FromSymbol

virtual ISource2ModFunction* FromSymbol(PluginId owner, const char* module, const char* symbol, const FunctionTypes& types) = 0;

An exported or debug symbol in a module.

ParameterType
ownerPluginId
moduleconst char*
symbolconst char*
typesconst FunctionTypes&

FromVirtualTable

virtual ISource2ModFunction* FromVirtualTable(PluginId owner, const char* module, const char* className, int index, const FunctionTypes& types, const char* baseName = "") = 0;

Slot @p index of one class's vtable (an RTTI name in a module; @p baseName picks a secondary base's vtable): called on any object, hooked on that class.

ParameterTypeDefault
ownerPluginId
moduleconst char*
classNameconst char*
indexint
typesconst FunctionTypes&
baseNameconst char*""

FromVirtual

virtual ISource2ModFunction* FromVirtual(PluginId owner, int index, const FunctionTypes& types) = 0;

Slot @p index of whatever object it is called / hooked on (an engine interface: FromVirtual(g_PluginID, KHook::GetVtableIndex(&ISource2Server::GameFrame), ...) with HookTarget::Instance(g_pSource2Server)).

ParameterType
ownerPluginId
indexint
typesconst FunctionTypes&

ISource2ModFunction

A game function: where it is and what it takes. From Find() (owned by the core, valid until the server shuts down) or Create() (the plugin's, freed with Destroy() or when the plugin unloads).

GetName

virtual const char* GetName() const = 0;

The gamedata name, "" for one from Create().

GetReturnType

virtual Source2ModType GetReturnType() const = 0;

GetParamCount

virtual int GetParamCount() const = 0;

Parameters, this of a member function included (it is the first).

GetParamType

virtual Source2ModType GetParamType(int index) const = 0;
ParameterType
indexint

IsVirtual

virtual bool IsVirtual() const = 0;

A virtual: the address comes from the vtable of the object it is called on.

GetAddress

virtual void* GetAddress(void* pThis = nullptr, bool bypassHooks = false) const = 0;

Where a call goes. A virtual reads it off @p pThis's vtable (or off the fixed vtable it was created with). @p bypassHooks: past every hook on the function (KHook::FindOriginal), as HookChain::Bypass.

ParameterTypeDefault
pThisvoid*nullptr
bypassHooksboolfalse

Returns void* — nullptr when there is no address (a virtual without an object).

CheckCall

virtual bool CheckCall(Source2ModType returnType, const Source2ModType* params, int count) const = 0;

Whether a call of this shape matches the gamedata; a mismatch is reported on the console (once per function and shape).

ParameterType
returnTypeSource2ModType
paramsconst Source2ModType*
countint

Call

template <typename Sig, typename... A> typename source2mod_functions_detail::Signature<Sig>::Return Call(A&&... args) const;

Calls it. @p Sig is the function's C++ type with this as the first parameter of a member function: Call<void(CBaseEntity*, bool)>(ent, true). Nothing is called when it does not match the gamedata; the result is then value-initialised.

ParameterType
argsA&&...

CallOriginal

template <typename Sig, typename... A> typename source2mod_functions_detail::Signature<Sig>::Return CallOriginal(A&&... args) const;

Call past every hook on the function (all plugins', raw and game hooks).

ParameterType
argsA&&...

IsMember

virtual bool IsMember() const = 0;

A member function ("this" in the gamedata, or a virtual).

FunctionTypes

What a function takes and returns, for one found without a gamedata "function" object (ISource2ModFunctions::From*).

const Source2ModType params[] = { Source2ModType::Entity, Source2ModType::Bool };
FunctionTypes types{ Source2ModType::Void, params, 2, true };   // void (CBaseEntity* this, bool)

Fields

FieldTypeDescription
returnTypeSource2ModType
paramsconst Source2ModType*this included for a member function
countint
isMemberboolthe first parameter is this

Enums

Source2ModType

enum class Source2ModType : int32_t

How a value crosses into a game function and back. The numbers are SourcePawn's Source2ModType_*.

NameValue
Void0
Bool
Int8
Int16
Int32
Int64
Float
Double
Entity
Object
String
Vector
VectorValue
Pointer
BufferString
Command
IntRef
BoolRef
FloatRef

Functions

TypeOf

template <typename T> constexpr Source2ModType TypeOf();

AsThis

template <typename A> void* AsThis(A&& arg);
ParameterType
argA&&

Source2ModCallFunction

template <typename Sig, typename... A> inline typename source2mod_functions_detail::Signature<Sig>::Return Source2ModCallFunction(ISource2ModFunctions* functions, ISource2ModFunction*& cache, const char* name, HookChain chain, A&&... args);

A gamedata function by name (its "function" object), called through the hooks (HookChain::Run) or straight to the original (HookChain::Bypass) -- how the SDK's schema helpers (Teleport, SwitchTeam, GiveNamedItem, ...) make their calls. Found once per call site. When the entry is missing or does not match @p Sig nothing is called and the result is value-initialised.

ParameterType
functionsISource2ModFunctions*
cacheISource2ModFunction*&
nameconst char*
chainHookChain
argsA&&...

Macros

SOURCE2MOD_CALL_FUNCTION

#define SOURCE2MOD_CALL_FUNCTION(SIG, NAME, CHAIN, ...) \
    ([&]() -> typename source2mod_functions_detail::Signature<SIG>::Return {                        
        static ISource2ModFunction* s_function = nullptr;                                          
        return Source2ModCallFunction<SIG>(g_pSource2ModFunctions, s_function, NAME, CHAIN, __VA_ARGS__); 
    }())

SOURCE2MOD_CALL_FUNCTION(void(CCSPlayerController*, int), "CCSPlayerController::SwitchTeam", eChain, this, nTeam)

On this page