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

Types

Source2ModConVarHookId

using Source2ModConVarHookId = Source2ModHookId;

A ConVar change hook (HookConVarChange).

ConVarChangeHandler

using ConVarChangeHandler = Source2ModCallback<void(ConVarRefAbstract* ref, CSplitScreenSlot slot, const char* pszNewValue, const char* pszOldValue)>;

Callback type for ConVar value changes.

Methods

GetConvarAccessIndexByName

virtual uint16 GetConvarAccessIndexByName(const char* name) = 0;

Retrieves access index of a ConVar by name.

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

GetConvarRef

virtual ConVarRefAbstract GetConvarRef(uint16 accessIndex) = 0;

Gets a ConVar reference wrapper.

ParameterType
accessIndexuint16

GetName

virtual const char* GetName(uint16 accessIndex) = 0;

Gets ConVar name.

ParameterType
accessIndexuint16

GetHelpText

virtual const char* GetHelpText(uint16 accessIndex) = 0;

Gets help/description text.

ParameterType
accessIndexuint16

GetType

virtual EConVarType GetType(uint16 accessIndex) = 0;

Gets ConVar type.

ParameterType
accessIndexuint16

GetFlags

virtual uint64 GetFlags(uint16 accessIndex) = 0;

Gets flags (FCVAR_*).

ParameterType
accessIndexuint16

SetFlags

virtual void SetFlags(uint16 accessIndex, uint64 flags) = 0;

Sets flags (FCVAR_*).

ParameterType
accessIndexuint16
flagsuint64

GetValueAddress

virtual void* GetValueAddress(uint16 accessIndex, CSplitScreenSlot slot = -1) = 0;

Gets pointer to underlying value.

Type depends on ConVar type.
ParameterTypeDefault
accessIndexuint16
slotCSplitScreenSlot-1

GetString

virtual const char* GetString(uint16 accessIndex, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
slotCSplitScreenSlot-1

GetBool

virtual bool GetBool(uint16 accessIndex, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
slotCSplitScreenSlot-1

GetInt

virtual int32 GetInt(uint16 accessIndex, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
slotCSplitScreenSlot-1

GetFloat

virtual float GetFloat(uint16 accessIndex, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
slotCSplitScreenSlot-1

GetDouble

virtual double GetDouble(uint16 accessIndex, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
slotCSplitScreenSlot-1

SetString

virtual void SetString(uint16 accessIndex, const char* value, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
valueconst char*
slotCSplitScreenSlot-1

SetBool

virtual void SetBool(uint16 accessIndex, bool value, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
valuebool
slotCSplitScreenSlot-1

SetInt

virtual void SetInt(uint16 accessIndex, int32 value, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
valueint32
slotCSplitScreenSlot-1

SetFloat

virtual void SetFloat(uint16 accessIndex, float value, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
valuefloat
slotCSplitScreenSlot-1

SetDouble

virtual void SetDouble(uint16 accessIndex, double value, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
valuedouble
slotCSplitScreenSlot-1

GetVector2

virtual Vector2D GetVector2(uint16 accessIndex, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
slotCSplitScreenSlot-1

GetVector3

virtual Vector GetVector3(uint16 accessIndex, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
slotCSplitScreenSlot-1

GetVector4

virtual Vector4D GetVector4(uint16 accessIndex, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
slotCSplitScreenSlot-1

GetQAngle

virtual QAngle GetQAngle(uint16 accessIndex, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
slotCSplitScreenSlot-1

GetColor

virtual Color GetColor(uint16 accessIndex, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
slotCSplitScreenSlot-1

SetVector2

virtual void SetVector2(uint16 accessIndex, const Vector2D& value, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
valueconst Vector2D&
slotCSplitScreenSlot-1

SetVector3

virtual void SetVector3(uint16 accessIndex, const Vector& value, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
valueconst Vector&
slotCSplitScreenSlot-1

SetVector4

virtual void SetVector4(uint16 accessIndex, const Vector4D& value, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
valueconst Vector4D&
slotCSplitScreenSlot-1

SetQAngle

virtual void SetQAngle(uint16 accessIndex, const QAngle& value, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
valueconst QAngle&
slotCSplitScreenSlot-1

SetColor

virtual void SetColor(uint16 accessIndex, const Color& value, CSplitScreenSlot slot = -1) = 0;
ParameterTypeDefault
accessIndexuint16
valueconst Color&
slotCSplitScreenSlot-1

GetValue

virtual void GetValue(uint16 accessIndex, void* outValue, CSplitScreenSlot slot = -1) = 0;

Gets value into user-provided buffer.

ParameterTypeDefault
accessIndexuint16
outValuevoid*
slotCSplitScreenSlot-1

HookConVarChange

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.

ParameterTypeDescription
handlerConVarChangeHandlerA function, an object and a method, or a lambda

Returns Source2ModConVarHookId — The id UnhookConVarChange(id) takes

UnhookConVarChange

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

SetValue

virtual void SetValue(uint16 accessIndex, const void* value, CSplitScreenSlot slot = -1) = 0;

Sets value from user-provided buffer.

ParameterTypeDefault
accessIndexuint16
valueconst void*
slotCSplitScreenSlot-1

CreateConVar

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

DeleteConVar

virtual void DeleteConVar(uint16 accessIndex) = 0;

Deletes a ConVar.

ParameterType
accessIndexuint16

Functions

UTIL_RemoveConVarFlags

inline bool UTIL_RemoveConVarFlags(const char* pszName, uint64 nFlags);

Clears flags on a ConVar found by name, e.g. FCVAR_CHEAT.

ParameterType
pszNameconst char*
nFlagsuint64

Returns bool — false when there is no such ConVar, or its data is not available.

UTIL_AddConVarFlags

inline bool UTIL_AddConVarFlags(const char* pszName, uint64 nFlags);

Sets flags on a ConVar found by name.

ParameterType
pszNameconst char*
nFlagsuint64

UTIL_SetConVar

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.

ParameterTypeDefault
pszNameconst char*
valueconst T&
slotCSplitScreenSlot-1
vdouble
vfloat
vint
—unsigned v

Returns bool — false when there is no such ConVar, or its data is not available.

Macros

HOOK_CONVAR_CHANGE

#define HOOK_CONVAR_CHANGE(passfunc) g_pSource2ModConVars->HookConVarChange(passfunc)

Macro for listening to ConVar value changes.

UNHOOK_CONVAR_CHANGE

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

Other macros

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

On this page