Skip to main content

Overview

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.

Usage

Access console variables using the global instance:
#include "utils/convars/convars.h"

// Access a console variable
auto* sv_cheats = g_convars["sv_cheats"];

Global Instance

g_convars
convars::impl
Global singleton instance of the console variable utility

Class: convars::impl

Operators

operator[]

Retrieves a pointer to a console variable by name.
convar_name
const char*
required
The name of the console variable to retrieve
return
sdk::con_var*
Pointer to the console variable, or nullptr if not found
auto* cvar = g_convars["sensitivity"];
if (cvar) {
    // Console variable was found
}

Common Usage Patterns

Reading Console Variable Values

// Get a console variable
auto* 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();
}

Setting Console Variable Values

// Get sv_cheats console variable
auto* 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");
}

Checking Console Variable Flags

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);
}

Complete Example

#include "utils/convars/convars.h"

void adjust_game_settings()
{
    // Access sensitivity setting
    auto* sensitivity = g_convars["sensitivity"];
    if (sensitivity) {
        float current = sensitivity->get_float();
        sensitivity->set_value(current * 1.5f);
    }
    
    // Enable developer mode
    auto* developer = g_convars["developer"];
    if (developer) {
        developer->set_value(1);
    }
    
    // Set viewmodel FOV
    auto* viewmodel_fov = g_convars["viewmodel_fov"];
    if (viewmodel_fov) {
        viewmodel_fov->set_value(90);
    }
}

Common Console Variables

Here are some commonly accessed console variables:
VariableTypeDescription
sv_cheatsintEnables cheat commands
sensitivityfloatMouse sensitivity
viewmodel_fovintField of view for viewmodel
r_drawothermodelsintDraw mode for player models
mat_wireframeintWireframe rendering mode
developerintDeveloper mode
con_filter_enableintConsole 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.

Build docs developers (and LLMs) love