Skip to content

Config#

Save and load plugin settings between sessions using the xenon::Config namespace.

How It Works#

Config is a key-value store. Each plugin has its own scope — keys like "enabled" won't collide between different plugins.

Supported types:

  • boolGetBool / SetBool
  • int32_tGetInt / SetInt
  • floatGetFloat / SetFloat

The Get/Set/Save Pattern#

The standard pattern: load in on_load, save in on_unload.

static bool g_enabled = true;
static float g_fov = 60.f;
static int32_t g_mode = 0;

extern "C" void on_load()
{
    g_enabled = Config::GetBool("enabled", true);
    g_fov = Config::GetFloat("fov", 60.f);
    g_mode = Config::GetInt("mode", 0);
}

extern "C" void on_unload()
{
    Config::SetBool("enabled", g_enabled);
    Config::SetFloat("fov", g_fov);
    Config::SetInt("mode", g_mode);
    Config::Save();
}

Why This Works#

  1. on_load reads from disk. If a key doesn't exist yet (first run), the default value is used.
  2. The menu modifies the static variables during the session.
  3. on_unload writes the current values back and flushes to disk.

Default Values#

Every Get function takes a default value:

Config::GetBool("enabled", true);   // Default: true
Config::GetFloat("fov", 60.f);      // Default: 60
Config::GetInt("mode", 0);          // Default: 0

On first run (before any Save), these defaults are used.

When to Call Save#

Call Config::Save() once in on_unload(). This writes all pending changes to disk.

You can also save at other times (e.g., after the user changes a setting), but on_unload is the most common pattern.

Note

SetBool, SetInt, and SetFloat only stage the values in memory. Nothing is written to disk until you call Save().

See Also#