The convars utility provides a convenient interface for accessing console variables (cvars) from the game engine. It wraps the engine’s convar interface with an easy-to-use operator[] syntax.
// Get a console variableauto* sensitivity = g_convars["sensitivity"];if (sensitivity) { // Read the float value float value = sensitivity->get_float(); // Read the int value int int_value = sensitivity->get_int(); // Read the string value const char* str_value = sensitivity->get_string();}
// Get sv_cheats console variableauto* sv_cheats = g_convars["sv_cheats"];if (sv_cheats) { // Set to integer value sv_cheats->set_value(1); // Set to float value sv_cheats->set_value(1.0f); // Set to string value sv_cheats->set_value("1");}
auto* cvar = g_convars["r_drawothermodels"];if (cvar) { // Check if the cvar has specific flags if (cvar->get_flags() & FCVAR_CHEAT) { // This is a cheat-protected variable } // Modify flags (use with caution) cvar->set_flags(cvar->get_flags() & ~FCVAR_CHEAT);}
Here are some commonly accessed console variables:
Variable
Type
Description
sv_cheats
int
Enables cheat commands
sensitivity
float
Mouse sensitivity
viewmodel_fov
int
Field of view for viewmodel
r_drawothermodels
int
Draw mode for player models
mat_wireframe
int
Wireframe rendering mode
developer
int
Developer mode
con_filter_enable
int
Console filtering
The console variable pointer returned by operator[] may be nullptr if the variable doesn’t exist. Always check for nullptr before using the returned pointer.
Modifying certain console variables (especially cheat-protected ones) may trigger anti-cheat detection in online games. Use with caution.