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

ParameterTypeDefaultDescription
nameconst char*Module name, e.g. "server" or "engine2".
extensionboolfalseWhen 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.

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

ParameterTypeDefaultDescription
patternconst char*IDA-style pattern string.
startAddressISource2ModMemoryISource2ModMemory()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.

ParameterTypeDefaultDescription
patternconst char*IDA-style pattern string.
sectionconst char*Section name, e.g. ".text" or ".rdata".
startAddressISource2ModMemoryISource2ModMemory()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.

ParameterTypeDefaultDescription
nameconst char*Class name (undecorated unless decorated is true).
decoratedboolfalsePass 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.

ParameterType
nameconst char*

GetSectionByName

virtual SectionInfo GetSectionByName(const char* name) const = 0;

Returns information about a named section.

ParameterType
nameconst 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.

ParameterTypeDefaultDescription
nameconst char*Class name (undecorated unless decorated is true).
offsetstd::ptrdiff_tOffset of the sub-object in bytes.
decoratedboolfalsePass 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.

ParameterTypeDefaultDescription
nameconst char*Class name (undecorated unless decorated is true).
baseNameconst char*Base class name.
decoratedboolfalsePass 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.

ParameterTypeDescription
nameconst char*Module name, e.g. "server" or "tier0".
ptruintptr_tAny address inside the target module.
ptrvoid*Any address inside the target module.
memISource2ModMemory

Macros

WIN_LINUX

#define WIN_LINUX(win, lin) win

The 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

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

On this page