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.
| Parameter | Type |
|---|---|
name | const 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.
| Parameter | Type | Description |
|---|---|---|
owner | PluginId | The plugin it belongs to (g_PluginID); freed when it unloads. |
address | void* | The function; nullptr for a virtual. |
vtable | void** | For a virtual called through one class's vtable whatever the object's class; nullptr to use the object's own. |
vtableIndex | int | The slot of a virtual; -1 for a function at @p address. |
isMember | bool | Whether the first parameter is this (a virtual always is). |
returnType | Source2ModType | |
params | const Source2ModType* | The parameter types, this included. |
count | int |
Destroy
virtual void Destroy(ISource2ModFunction* function) = 0;Frees one from Create() / From*(). One from Find() is left alone.
| Parameter | Type |
|---|---|
function | ISource2ModFunction* |
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.
| Parameter | Type |
|---|---|
owner | PluginId |
name | const char* |
types | const 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").
| Parameter | Type | Default |
|---|---|---|
owner | PluginId | |
module | const char* | |
signature | const char* | |
types | const FunctionTypes& | |
section | const 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).
| Parameter | Type | Default |
|---|---|---|
owner | PluginId | |
module | const char* | |
signature | const char* | |
offset | int | |
nextInstructionOffset | int | |
types | const FunctionTypes& | |
section | const 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.
| Parameter | Type |
|---|---|
owner | PluginId |
module | const char* |
symbol | const char* |
types | const 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.
| Parameter | Type | Default |
|---|---|---|
owner | PluginId | |
module | const char* | |
className | const char* | |
index | int | |
types | const FunctionTypes& | |
baseName | const 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)).
| Parameter | Type |
|---|---|
owner | PluginId |
index | int |
types | const 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;| Parameter | Type |
|---|---|
index | int |
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.
| Parameter | Type | Default |
|---|---|---|
pThis | void* | nullptr |
bypassHooks | bool | false |
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).
| Parameter | Type |
|---|---|
returnType | Source2ModType |
params | const Source2ModType* |
count | int |
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.
| Parameter | Type |
|---|---|
args | A&&... |
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).
| Parameter | Type |
|---|---|
args | A&&... |
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
| Field | Type | Description |
|---|---|---|
returnType | Source2ModType | |
params | const Source2ModType* | this included for a member function |
count | int | |
isMember | bool | the first parameter is this |
Enums
Source2ModType
enum class Source2ModType : int32_tHow a value crosses into a game function and back. The numbers are SourcePawn's Source2ModType_*.
| Name | Value |
|---|---|
Void | 0 |
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);| Parameter | Type |
|---|---|
arg | A&& |
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.
| Parameter | Type |
|---|---|
functions | ISource2ModFunctions* |
cache | ISource2ModFunction*& |
name | const char* |
chain | HookChain |
args | A&&... |
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)