BepInExExtensions
Helper library for making writing ConfigFiles and profile support easy
About this mod Author’s original text
Note: This project is not officially associated with BepInEx.
This BepInEx Extension library is a collection of various helper functionalities. As of now the current ready-to-use functions it includes are:
- Configuration File Model
Simple, central place to make your configuration files and instantiate them. An up to date example can be found here: ExamplePlugin and ExampleModel
Designed to make BepInEx Configuration Files easy to write and instantiate.
Includes virtual methods and event hooks for easy customization of each variable in Pre and Post BepInEx.Configuration.ConfigFile.Bind() and for common ConfigFile events.
Migration/Profile Support: You can now change which ConfigFile a model is using live, including Migration hooks, with a simple, one-line command.
Allows you to create your own types/classes, just implement the interfaces and the rest will work.
Sample Usage:
public class ExampleModel: ConfigDataModel
{
//Notes:
//You do not need to do every single different way here, it's just to show you the different ways it can be used.
//Pick the way that makes sense to you and just use that one.
public ConfigData ConfigOption1 = new ConfigData() //SIMPLE/Minimalist setup, using a field.
{
DefaultValue = 100f,
DescriptionString = "Hello"
};
public ConfigData ConfigOption2 { get; set; } = new ConfigData()
{
Key = "Config_Variable_Name", //OPTIONAL: This will be set to 'Config_Variable_Name' in the config file. If not set by you, the default 'Key' name is the variable's name.
DefaultValue = 10f, //REQUIRED: Default value.
DescriptionString = "I'm running out of flavor text", //OPTIONAL: Description.
AcceptableValues = new AcceptableValueRange(0f, 50f) //OPTIONAL: Acceptable values.
};
public ConfigData ConfigOption3; //Nothing defined. This will be bound with the Type defaults.
public override void SetDefaults()
{
this.SectionName = "Example Section"; //Define your section name here.
}
}
[BepInPlugin("dev.cdmtests", "CDM Tests", "0.0.0")]
public class ExamplePlugin: BaseUnityPlugin
{
//NOTE: Before you read this, please take a look at the ExampleModel.cs file. The below will make a lot more sense if you do.
ExampleModel model;
void Awake()
{
//NOTE: Before you read this, please take a look at the ExampleModel.cs file. The below will make a lot more sense if you do.
model = Config.BindModel(Logger); //Initialized and ready to use.
Logger.LogInfo($"ExamplePlugin: model init completed.");
Logger.LogInfo($"ExamplePlugin: model.ConfigOption1={ model.ConfigOption1.Value }");
model.ConfigOption2.Value = 20f;
Logger.LogInfo($"ExamplePlugin: model.ConfigOption2={ (float) model.ConfigOption2 }"); //Explicit & implicit conversion is supported.
Logger.LogInfo($"ExamplePlugin: model.ConfigOption3={ (int) model.ConfigOption3 }"); //All defaults. Value = 0.
//Want to change config files for profile support?
ConfigFile profile2 = new ConfigFile(System.IO.Path.Combine(Paths.BepInExConfigPath, "ExamplePlugin", "profile2"), true);
model.SetConfigFile(profile2);
}
}
Install & use Install: BepInEx plugin
- The archive from playbuff is the mod itself — usually a BepInEx plugin (a .dll or a plugin folder once unzipped).
- Recommended: use a community mod manager (such as r2modman) — pick this game, import the mod, and the manager sets up BepInEx and its dependencies for you.
- Manual route: install the BepInEx loader in the game folder, then drop the unzipped .dll or plugin folder into BepInEx/plugins/.
- Launch the game — the BepInEx console logs every plugin it loads; seeing this mod in the log means it is installed.
Mods with listed dependencies need those installed too, or they will not load. Options are usually changed in-game or in the plugin's config file.
Install these first, or the mod will not work: