ISource2ModModule
Source2Mod-facing module interface (mirrors DynLibUtils::CModule).
Plugins obtain an ISource2ModModule via ISource2ModAPI::LoadModule() and release it with ISource2ModAPI::FreeModule(). The implementation inside Source2Mod core delegates every call 1:1 to DynLibUtils::CModule so plugins are fully decoupled from the DynLibUtils headers.
Header source2mod/ISource2ModModule.h
Methods
InitFromName
virtual bool InitFromName(const char* name, bool extension = false) = 0;Initialises the module from its name (without extension).
| Parameter | Type | Default | Description |
|---|---|---|---|
name | const char* | Module name, e.g. "server" or "engine2". | |
extension | bool | false | When true the platform extension is appended automatically. |
Returns bool — True on success.
InitFromMemory
virtual bool InitFromMemory(uintptr_t ptr) = 0;Initialises the module from an address inside it.
| Parameter | Type | Description |
|---|---|---|
ptr | uintptr_t | Any address that belongs to the target module. |
Returns bool — True on success.
FindPattern
virtual ISource2ModMemory FindPattern(const char* pattern, ISource2ModMemory startAddress = ISource2ModMemory()) const = 0;Scans the executable section for a byte-string pattern.
Pattern format: "AB CD ?? EF" (space-separated hex bytes, ?? = wildcard).
| Parameter | Type | Default | Description |
|---|---|---|---|
pattern | const char* | IDA-style pattern string. | |
startAddress | ISource2ModMemory | ISource2ModMemory() | Optional address to start scanning from. |
Returns ISource2ModMemory — Address of the first match, or an invalid (null) ISource2ModMemory.
FindPatternInSection
virtual ISource2ModMemory FindPatternInSection(const char* pattern, const char* section, ISource2ModMemory startAddress = ISource2ModMemory()) const = 0;Scans a named section for a byte-string pattern.
| Parameter | Type | Default | Description |
|---|---|---|---|
pattern | const char* | IDA-style pattern string. | |
section | const char* | Section name, e.g. ".text" or ".rdata". | |
startAddress | ISource2ModMemory | ISource2ModMemory() | Optional address to start scanning from. |
Returns ISource2ModMemory — Address of the first match, or an invalid (null) ISource2ModMemory.
GetVirtualTableByName
virtual ISource2ModMemory GetVirtualTableByName(const char* name, bool decorated = false) const = 0;Returns the address of a virtual table by mangled class name.
| Parameter | Type | Default | Description |
|---|---|---|---|
name | const char* | Class name (undecorated unless decorated is true). | |
decorated | bool | false | Pass true when name is already a decorated symbol. |
GetFunctionByName
virtual ISource2ModMemory GetFunctionByName(const char* name) const = 0;Returns the address of an exported symbol by name.
| Parameter | Type |
|---|---|
name | const char* |
GetSectionByName
virtual SectionInfo GetSectionByName(const char* name) const = 0;Returns information about a named section.
| Parameter | Type |
|---|---|
name | const char* |
GetModuleHandle
virtual void* GetModuleHandle() const = 0;Returns the OS-native module handle (HMODULE / void*).
GetModuleBase
virtual ISource2ModMemory GetModuleBase() const = 0;Returns the base load address of the module.
GetModulePath
virtual const char* GetModulePath() const = 0;Returns the absolute filesystem path of the module.
The pointer is valid for the lifetime of this ISource2ModModule.
GetModuleName
virtual const char* GetModuleName() const = 0;Returns the filename component of the module path.
The pointer is valid for the lifetime of this ISource2ModModule.
GetVirtualTableByOffset
virtual ISource2ModMemory GetVirtualTableByOffset(const char* name, std::ptrdiff_t offset, bool decorated = false) const = 0;Returns the virtual table of the sub-object at an offset inside a class.
A class with several bases has one table per base that is not at offset 0; offset 0 is the primary table, the one GetVirtualTableByName returns. The offset moves whenever the class is laid out anew -- prefer GetVirtualTableByBase.
| Parameter | Type | Default | Description |
|---|---|---|---|
name | const char* | Class name (undecorated unless decorated is true). | |
offset | std::ptrdiff_t | Offset of the sub-object in bytes. | |
decorated | bool | false | Pass true when name is already a decorated symbol. |
GetVirtualTableByBase
virtual ISource2ModMemory GetVirtualTableByBase(const char* name, const char* baseName, bool decorated = false) const = 0;Returns the virtual table of a base class sub-object, located through the RTTI.
For an interface that is not a class's first base, whose table GetVirtualTableByName cannot reach. Non-virtual bases only.
| Parameter | Type | Default | Description |
|---|---|---|---|
name | const char* | Class name (undecorated unless decorated is true). | |
baseName | const char* | Base class name. | |
decorated | bool | false | Pass true when both names are already decorated symbols. |
New
static ISource2ModModule* New(const char* name);
static ISource2ModModule* New(uintptr_t ptr);
static ISource2ModModule* New(void* ptr);
static ISource2ModModule* New(ISource2ModMemory mem);Creates a module wrapper by name (without extension).
Equivalent to g_Source2ModAPI->LoadModule(name). Release with delete or g_Source2ModAPI->FreeModule().
Creates a module wrapper from an address that belongs to the module.
Creates a module wrapper from a void pointer inside the module.
Creates a module wrapper from an ISource2ModMemory address inside the module.
| Parameter | Type | Description |
|---|---|---|
name | const char* | Module name, e.g. "server" or "tier0". |
ptr | uintptr_t | Any address inside the target module. |
ptr | void* | Any address inside the target module. |
mem | ISource2ModMemory |
Macros
WIN_LINUX
#define WIN_LINUX(win, lin) winThe Windows or the Linux one of two things -- a pattern, an offset, a library name -- picked at compile time.
pServer->FindPattern(WIN_LINUX("48 89 7C 24 ? 55", "55 48 89 E5 41 57"));Prefer a gamedata entry for anything the game moves: that is updated without a rebuild. This is for a pattern a plugin keeps to itself.
Other macros
| Macro | Expands to |
|---|---|
WIN_LINUX(win, lin) | lin |
LOAD_MODULE(name) | g_Source2ModAPI->LoadModule(name) |
LOAD_MODULE_MEM(ptr) | g_Source2ModAPI->LoadModuleFromMemory(ptr) |
FREE_MODULE(mod) | g_Source2ModAPI->FreeModule(mod) |