-
Notifications
You must be signed in to change notification settings - Fork 0
ConfigManager
QinShenYu edited this page Jun 10, 2026
·
2 revisions
Namespace: ScavLib.config
A lightweight wrapper around BepInEx's ConfigFile that reduces boilerplate
when declaring and binding configuration entries.
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);
}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.");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)
);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)
)
);ConfigEntry<T> works the same as in standard BepInEx:
// Read
float amount = healAmount.Value;
// Write (persisted to disk automatically)
healAmount.Value = 75f;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.