ISource2ModApi
Main entry point for Source2Mod API.
This interface provides access to:
- Core engine interfaces
- Source2Mod subsystems (Commands, Events, ConVars, etc.)
- Logging and console output
- Interface querying and factory access
Main API interface for Source2Mod.
Provides access to all source2mod subsystems and engine interfaces.
api->Commands()->RegisterConCommand(...);
api->Events()->HookGameEvent(...);Global g_Source2ModAPI · Header source2mod/ISource2ModApi.h
Types
PluginId
using PluginId = int;CreateInterfaceFn
typedef void* (*CreateInterfaceFn)(const char* pName, int* pReturnCode);Methods
Log
virtual void Log(ISource2ModPlugin* plugin, const char* msg, ...) = 0;Logs a formatted message with plugin context.
| Parameter | Type | Description |
|---|---|---|
plugin | ISource2ModPlugin* | Plugin instance |
msg | const char* | Format string |
— | ... |
ConPrint
virtual void ConPrint(const char* msg) = 0;Prints message to console.
| Parameter | Type |
|---|---|
msg | const char* |
ConPrintf
virtual void ConPrintf(const char* fmt, ...) = 0;Prints formatted message to console.
| Parameter | Type |
|---|---|
fmt | const char* |
— | ... |
AddListener
virtual void AddListener(ISource2ModPlugin* plugin, ISource2ModListener* pListener) = 0;Registers a source2mod listener.
| Parameter | Type | Description |
|---|---|---|
plugin | ISource2ModPlugin* | Owner plugin |
pListener | ISource2ModListener* | Listener instance |
QueryInterface
virtual void* QueryInterface(CreateInterfaceFn fn, const char* iface, int min = -1) = 0;Queries interface from factory.
| Parameter | Type | Default | Description |
|---|---|---|---|
fn | CreateInterfaceFn | Factory function | |
iface | const char* | Interface name | |
min | int | -1 | Minimum version (optional) |
InterfaceSearch
virtual void* InterfaceSearch(CreateInterfaceFn fn, const char* iface, int max, int* ret) = 0;Searches for interface by iterating versions.
| Parameter | Type |
|---|---|
fn | CreateInterfaceFn |
iface | const char* |
max | int |
ret | int* |
FormatIface
virtual int FormatIface(char iface[], size_t maxlength) = 0;Formats interface name with version.
| Parameter | Type |
|---|---|
iface | char [] |
maxlength | size_t |
GetEngineFactory
virtual CreateInterfaceFn GetEngineFactory(bool syn = true) = 0;| Parameter | Type | Default |
|---|---|---|
syn | bool | true |
GetPhysicsFactory
virtual CreateInterfaceFn GetPhysicsFactory(bool syn = true) = 0;| Parameter | Type | Default |
|---|---|---|
syn | bool | true |
GetFileSystemFactory
virtual CreateInterfaceFn GetFileSystemFactory(bool syn = true) = 0;| Parameter | Type | Default |
|---|---|---|
syn | bool | true |
GetServerFactory
virtual CreateInterfaceFn GetServerFactory(bool syn = true) = 0;| Parameter | Type | Default |
|---|---|---|
syn | bool | true |
Source2ModFactory
virtual void* Source2ModFactory(const char* iface, int* ret, PluginId* id) = 0;Source2Mod interface factory.
| Parameter | Type |
|---|---|
iface | const char* |
ret | int* |
id | PluginId* |
MetaFactory
virtual void* MetaFactory(const char* iface, int* ret, PluginId* id) = 0;Metamod interface factory.
| Parameter | Type |
|---|---|
iface | const char* |
ret | int* |
id | PluginId* |
Addresses
virtual ISource2ModAddresses* Addresses() = 0;Access address/pattern system.
Commands
virtual ISource2ModCommands* Commands() = 0;Access command system.
ConVars
virtual ISource2ModConVars* ConVars() = 0;Access ConVar system.
CustomHud
virtual ISource2ModCustomHud* CustomHud() = 0;Access custom HUD layout system.
Entities
virtual ISource2ModEntities* Entities() = 0;Access entities and Entity I/O system.
Events
virtual ISource2ModEvents* Events() = 0;Access event system.
GameConfig
virtual ISource2ModGameConfig* GameConfig() = 0;Access game configuration system.
GameSystems
virtual ISource2ModGameSystems* GameSystems() = 0;Access game system registry.
HTTP
virtual ISource2ModHTTP* HTTP() = 0;Access HTTP system.
Menus
virtual ISource2ModMenus* Menus() = 0;Access menu system.
SQL
virtual ISource2ModSQL* SQL() = 0;Access the SQL system (MySQL and SQLite).
NetworkMessages
virtual ISource2ModNetworkMessages* NetworkMessages() = 0;Access network messages system.
Paths
virtual ISource2ModPaths* Paths() = 0;Where Source2Mod keeps things on disk.
Scheduler
virtual ISource2ModScheduler* Scheduler() = 0;Access scheduler system.
Sounds
virtual ISource2ModSounds* Sounds() = 0;Access sound system.
Trace
virtual ISource2ModTrace* Trace() = 0;Access tracing system.
Transmit
virtual ISource2ModTransmit* Transmit() = 0;Access transmit system (per-viewer entity visibility).
LoadModule
virtual ISource2ModModule* LoadModule(const char* name) = 0;Creates and initialises a module wrapper by name.
The returned object must be released with FreeModule().
| Parameter | Type | Description |
|---|---|---|
name | const char* | Module name without extension (e.g. "server"). |
Returns ISource2ModModule* — Heap-allocated ISource2ModModule, or nullptr on failure.
LoadModuleFromMemory
virtual ISource2ModModule* LoadModuleFromMemory(uintptr_t ptr) = 0;Creates and initialises a module wrapper from an address inside it.
The returned object must be released with FreeModule().
| Parameter | Type | Description |
|---|---|---|
ptr | uintptr_t | Any address that belongs to the target module. |
Returns ISource2ModModule* — Heap-allocated ISource2ModModule, or nullptr on failure.
FreeModule
virtual void FreeModule(ISource2ModModule* module) = 0;Releases a module previously obtained from LoadModule() / LoadModuleFromMemory().
| Parameter | Type |
|---|---|
module | ISource2ModModule* |
GetSource2Server
virtual ISource2Server* GetSource2Server() = 0;GetSource2ServerConfig
virtual ISource2ServerConfig* GetSource2ServerConfig() = 0;GetSource2GameClients
virtual ISource2GameClients* GetSource2GameClients() = 0;GetSource2GameEntities
virtual ISource2GameEntities* GetSource2GameEntities() = 0;GetEngineServer
virtual IVEngineServer2* GetEngineServer() = 0;GetCVar
virtual ICvar* GetCVar() = 0;GetSchemaSystem
virtual CSchemaSystem* GetSchemaSystem() = 0;GetGameResourceService
virtual IGameResourceService* GetGameResourceService() = 0;GetNetworkServerService
virtual INetworkServerService* GetNetworkServerService() = 0;GetNetworkSystem
virtual INetworkSystem* GetNetworkSystem() = 0;GetNetworkMessages
virtual INetworkMessages* GetNetworkMessages() = 0;GetNetworkStringTableServer
virtual INetworkStringTableContainer* GetNetworkStringTableServer() = 0;GetEngineServiceMgr
virtual IEngineServiceMgr* GetEngineServiceMgr() = 0;GetHostStateMgr
virtual IHostStateMgr* GetHostStateMgr() = 0;GetLocalize
virtual ILocalize* GetLocalize() = 0;GetFileSystem
virtual IFileSystem* GetFileSystem() = 0;GetGameEventSystem
virtual IGameEventSystem* GetGameEventSystem() = 0;GetGameEventManager
virtual IGameEventManager2* GetGameEventManager() = 0;GetEntitySystem
virtual CGameEntitySystem* GetEntitySystem() = 0;GetGlobalVars
virtual CGlobalVars* GetGlobalVars() = 0;GetBaseDir
virtual const char* GetBaseDir() = 0;Returns base directory of the server.
Format
virtual size_t Format(char* buffer, size_t maxlength, const char* format, ...) = 0;Formats string into buffer.
| Parameter | Type |
|---|---|
buffer | char* |
maxlength | size_t |
format | const char* |
— | ... |
FormatArgs
virtual size_t FormatArgs(char* buffer, size_t maxlength, const char* format, va_list ap) = 0;Formats string using va_list.
| Parameter | Type |
|---|---|
buffer | char* |
maxlength | size_t |
format | const char* |
ap | va_list |
GameHooks
virtual ISource2ModGameHooks* GameHooks() = 0;Access the core's hooks on common game functions.