Skip to content

ConfigManager

Kanisuko edited this page May 23, 2026 · 2 revisions

ConfigManager

Namespace:​ ScavLib.config

A lightweight wrapper around BepInEx's ConfigFile that reduces boilerplate when declaring and binding configuration entries.


Setup

Instantiate ConfigManager in your plugin's Awake(), passing BepInEx's built-in Config object:

using ScavLib.config;

private ConfigManager _cfg;

private void Awake()
{
    _cfg = new ConfigManager(Config);
}

Binding Entries

Basic Bind

ConfigEntry<bool>  enableFeature = _cfg.Bind("General", "EnableFeature", true,
    "Enables my feature.");

ConfigEntry<float> healAmount    = _cfg.Bind("Healing", "HealAmount", 50f,
    "Amount to restore on heal.");

ConfigEntry<int>   maxItems      = _cfg.Bind("Items", "MaxItems", 10,
    "Maximum number of items to spawn.");

ConfigEntry<string> welcomeMsg   = _cfg.Bind("UI", "WelcomeMessage", "Hello!",
    "Message shown on world load.");

Bind with Acceptable Value Range

Constrain numeric entries to a valid range. BepInEx will enforce this both in the config file and in the r2modman config editor:

ConfigEntry<float> speed = _cfg.Bind(
    section:        "Movement",
    key:            "SpeedMultiplier",
    defaultValue:   1.0f,
    description:    "Player speed multiplier.",
    acceptableValues: new AcceptableValueRange<float>(0.1f, 5.0f)
);

Bind with Full ConfigDescription

For complete control over metadata:

ConfigEntry<int> level = _cfg.Bind(
    section:      "Skills",
    key:          "StartingSTR",
    defaultValue: 10,
    configDescription: new ConfigDescription(
        "Starting Strength level.",
        new AcceptableValueRange<int>(1, 30)
    )
);

Reading and Writing Values

ConfigEntry<T> works the same as in standard BepInEx:

// Read
float amount = healAmount.Value;

// Write (persisted to disk automatically)
healAmount.Value = 75f;

Integration with MenuBuilder

Config entries bind directly to MenuBuilder controls without extra glue code:

protected override void DrawContent()
{
    MenuBuilder.SliderConfig("Heal Amount", _healAmount, 0f, 100f);
    MenuBuilder.ToggleConfig("Enable Feature", _enableFeature);
}

Changes made in the menu are written to the config entry immediately and persisted to disk by BepInEx.

Clone this wiki locally