ISource2ModConVars Interface for managing and interacting with console variables (ConVars).
Provides functionality for:
Querying ConVars by name
Reading and writing values
Accessing metadata (type, flags, help text)
Creating and deleting ConVars
ConVars are identified by an internal access index.
Interface id ISource2ModConVars002 (SOURCE2MOD_CONVARS_INTERFACE) · Global g_pSource2ModConVars · Header source2mod/ISource2ModConVars.h
using Source2ModConVarHookId = Source2ModHookId ;
A ConVar change hook (HookConVarChange).
using ConVarChangeHandler = Source2ModCallback < void ( ConVarRefAbstract * ref , CSplitScreenSlot slot , const char* pszNewValue , const char* pszOldValue )>;
Callback type for ConVar value changes.
virtual uint16 GetConvarAccessIndexByName ( const char* name ) = 0 ;
Retrieves access index of a ConVar by name.
Parameter Type Description nameconst char*ConVar name
Returns uint16 — Access index, or SOURCE2MOD_INVALID_CONVAR_INDEX if no ConVar has that name. 0 is a valid index, so compare against the sentinel rather than testing for zero.
virtual ConVarRefAbstract GetConvarRef ( uint16 accessIndex ) = 0 ;
Gets a ConVar reference wrapper.
Parameter Type accessIndexuint16
virtual const char* GetName ( uint16 accessIndex ) = 0 ;
Gets ConVar name.
Parameter Type accessIndexuint16
virtual const char* GetHelpText ( uint16 accessIndex ) = 0 ;
Gets help/description text.
Parameter Type accessIndexuint16
virtual EConVarType GetType ( uint16 accessIndex ) = 0 ;
Gets ConVar type.
Parameter Type accessIndexuint16
virtual uint64 GetFlags ( uint16 accessIndex ) = 0 ;
Gets flags (FCVAR_*).
Parameter Type accessIndexuint16
virtual void SetFlags ( uint16 accessIndex , uint64 flags ) = 0 ;
Sets flags (FCVAR_*).
Parameter Type accessIndexuint16flagsuint64
virtual void* GetValueAddress ( uint16 accessIndex , CSplitScreenSlot slot = - 1 ) = 0 ;
Gets pointer to underlying value.
Type depends on ConVar type.
Parameter Type Default accessIndexuint16slotCSplitScreenSlot-1
virtual const char* GetString ( uint16 accessIndex , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16slotCSplitScreenSlot-1
virtual bool GetBool ( uint16 accessIndex , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16slotCSplitScreenSlot-1
virtual int32 GetInt ( uint16 accessIndex , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16slotCSplitScreenSlot-1
virtual float GetFloat ( uint16 accessIndex , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16slotCSplitScreenSlot-1
virtual double GetDouble ( uint16 accessIndex , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16slotCSplitScreenSlot-1
virtual void SetString ( uint16 accessIndex , const char* value , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16valueconst char*slotCSplitScreenSlot-1
virtual void SetBool ( uint16 accessIndex , bool value , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16valueboolslotCSplitScreenSlot-1
virtual void SetInt ( uint16 accessIndex , int32 value , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16valueint32slotCSplitScreenSlot-1
virtual void SetFloat ( uint16 accessIndex , float value , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16valuefloatslotCSplitScreenSlot-1
virtual void SetDouble ( uint16 accessIndex , double value , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16valuedoubleslotCSplitScreenSlot-1
virtual Vector2D GetVector2 ( uint16 accessIndex , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16slotCSplitScreenSlot-1
virtual Vector GetVector3 ( uint16 accessIndex , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16slotCSplitScreenSlot-1
virtual Vector4D GetVector4 ( uint16 accessIndex , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16slotCSplitScreenSlot-1
virtual QAngle GetQAngle ( uint16 accessIndex , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16slotCSplitScreenSlot-1
virtual Color GetColor ( uint16 accessIndex , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16slotCSplitScreenSlot-1
virtual void SetVector2 ( uint16 accessIndex , const Vector2D & value , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16valueconst Vector2D&slotCSplitScreenSlot-1
virtual void SetVector3 ( uint16 accessIndex , const Vector & value , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16valueconst Vector&slotCSplitScreenSlot-1
virtual void SetVector4 ( uint16 accessIndex , const Vector4D & value , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16valueconst Vector4D&slotCSplitScreenSlot-1
virtual void SetQAngle ( uint16 accessIndex , const QAngle & value , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16valueconst QAngle&slotCSplitScreenSlot-1
virtual void SetColor ( uint16 accessIndex , const Color & value , CSplitScreenSlot slot = - 1 ) = 0 ;
Parameter Type Default accessIndexuint16valueconst Color&slotCSplitScreenSlot-1
virtual void GetValue ( uint16 accessIndex , void* outValue , CSplitScreenSlot slot = - 1 ) = 0 ;
Gets value into user-provided buffer.
Parameter Type Default accessIndexuint16outValuevoid*slotCSplitScreenSlot-1
virtual Source2ModConVarHookId HookConVarChange ( ConVarChangeHandler handler ) = 0 ;
Registers a listener for every ConVar value change.
The engine only takes plain function pointers here, and only keeps one list of them for the whole process. Source2Mod installs a single one of those and fans out to the handlers registered through this, so a plugin can use a capturing lambda and does not have to unregister on unload.
A plugin may register as many as it likes.
Whose it is, the core reads off the handler (see Source2ModCallback); what a plugin still holds at unload the core drops for it.
Parameter Type Description handlerConVarChangeHandlerA function, an object and a method, or a lambda
Returns Source2ModConVarHookId — The id UnhookConVarChange(id) takes
virtual bool UnhookConVarChange ( const ConVarChangeHandler & handler ) = 0 ;
virtual bool UnhookConVarChange ( Source2ModConVarHookId id ) = 0 ;
Drops the change listener with this handler -- a function or an object and a method; a lambda goes by its id.
Drops the change listener HookConVarChange() returned the id for.
Returns bool — true when one was found
virtual void SetValue ( uint16 accessIndex , const void* value , CSplitScreenSlot slot = - 1 ) = 0 ;
Sets value from user-provided buffer.
Parameter Type Default accessIndexuint16valueconst void*slotCSplitScreenSlot-1
virtual uint16 CreateConVar ( const char* name , EConVarType type , const char* help , uint64 flags , bool hasMin , bool hasMax , void* defaultValue , const void* minValue , const void* maxValue ) = 0 ;
Creates a new ConVar.
The engine has no way to unregister a ConVar, so one created here outlives the plugin that created it. When the plugin loads again, the same call returns the existing ConVar with its current value.
Parameter Type Description nameconst char*ConVar name typeEConVarTypeVariable type helpconst char*Description text flagsuint64FCVAR flags hasMinboolWhether min value is enforced hasMaxboolWhether max value is enforced defaultValuevoid*Default value pointer (const char* for EConVarType_String) minValueconst void*Minimum value pointer; only read when hasMin is true, may be nullptr otherwise maxValueconst void*Maximum value pointer; only read when hasMax is true, may be nullptr otherwise
Returns uint16 — Access index of the created ConVar. If a ConVar with that name already exists, its index is returned and the arguments are ignored. SOURCE2MOD_INVALID_CONVAR_INDEX on bad arguments or an unsupported type.
virtual void DeleteConVar ( uint16 accessIndex ) = 0 ;
Deletes a ConVar.
Parameter Type accessIndexuint16
inline bool UTIL_RemoveConVarFlags ( const char* pszName , uint64 nFlags );
Clears flags on a ConVar found by name, e.g. FCVAR_CHEAT.
Parameter Type pszNameconst char*nFlagsuint64
Returns bool — false when there is no such ConVar, or its data is not available.
inline bool UTIL_AddConVarFlags ( const char* pszName , uint64 nFlags );
Sets flags on a ConVar found by name.
Parameter Type pszNameconst char*nFlagsuint64
template < typename T > inline bool UTIL_SetConVar ( const char* pszName , const T & value , CSplitScreenSlot slot = - 1 );
inline bool UTIL_SetConVar ( const char* pszName , double v , CSplitScreenSlot slot = - 1 );
inline bool UTIL_SetConVar ( const char* pszName , float v , CSplitScreenSlot slot = - 1 );
inline bool UTIL_SetConVar ( const char* pszName , int v , CSplitScreenSlot slot = - 1 );
inline bool UTIL_SetConVar ( const char* pszName , unsigned v , CSplitScreenSlot slot = - 1 );
Sets a ConVar by name.
The type is what decides how the value is written, so call it as UTIL_SetConVar<int>("mp_freezetime", 5) when the literal would deduce to something else.
Parameter Type Default pszNameconst char*valueconst T&slotCSplitScreenSlot-1vdoublevfloatvint—unsigned v
Returns bool — false when there is no such ConVar, or its data is not available.
#define HOOK_CONVAR_CHANGE ( passfunc ) g_pSource2ModConVars-> HookConVarChange (passfunc)
Macro for listening to ConVar value changes.
#define UNHOOK_CONVAR_CHANGE ( passfunc ) g_pSource2ModConVars-> UnhookConVarChange (passfunc)
Macro for dropping a ConVar change hook (a function or an object and a method; a lambda goes by the id HOOK_CONVAR_CHANGE returned).
Macro Expands to CVAR_IDX(name)g_pSource2ModConVars->GetConvarAccessIndexByName(name)CVAR_REF(idx)g_pSource2ModConVars->GetConvarRef(idx)CVAR_GET_STR(idx, ...)g_pSource2ModConVars->GetString(idx, ##__VA_ARGS__)CVAR_GET_BOOL(idx, ...)g_pSource2ModConVars->GetBool(idx, ##__VA_ARGS__)CVAR_GET_INT(idx, ...)g_pSource2ModConVars->GetInt(idx, ##__VA_ARGS__)CVAR_GET_FLOAT(idx, ...)g_pSource2ModConVars->GetFloat(idx, ##__VA_ARGS__)CVAR_GET_DOUBLE(idx, ...)g_pSource2ModConVars->GetDouble(idx, ##__VA_ARGS__)CVAR_SET_STR(idx, v, ...)g_pSource2ModConVars->SetString(idx, v, ##__VA_ARGS__)CVAR_SET_BOOL(idx, v, ...)g_pSource2ModConVars->SetBool(idx, v, ##__VA_ARGS__)CVAR_SET_INT(idx, v, ...)g_pSource2ModConVars->SetInt(idx, v, ##__VA_ARGS__)CVAR_SET_FLOAT(idx, v, ...)g_pSource2ModConVars->SetFloat(idx, v, ##__VA_ARGS__)CVAR_SET_DOUBLE(idx, v, ...)g_pSource2ModConVars->SetDouble(idx, v, ##__VA_ARGS__)CVAR_CREATE(name, type, help, flags, hasMin, hasMax, def, minVal, maxVal)g_pSource2ModConVars->CreateConVar(name, type, help, flags, hasMin, hasMax, def, minVal, maxVal)CVAR_DELETE(idx)g_pSource2ModConVars->DeleteConVar(idx)