BepInExExtensions
Helper library for making writing ConfigFiles and profile support easy
模組介紹 作者原文
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);
}
}
安裝與使用 安裝:BepInEx 外掛
- 本站下載的壓縮包就是模組本體,通常是 BepInEx 外掛(解壓後得到 .dll 或外掛資料夾)。
- 建議流程:用社群模組管理器(如 r2modman)選中本遊戲後匯入該模組,管理器會自動裝好 BepInEx 前置並處理依賴。
- 手動流程:先在遊戲目錄裝好 BepInEx 載入器,再把解壓出的 .dll 或外掛資料夾放進 BepInEx/plugins/。
- 啟動遊戲,BepInEx 控制台會列印載入日誌;確認這個模組出現在日誌裡即為安裝成功。
帶「前置依賴」的模組需要一併安裝,否則不會載入。功能開關通常在遊戲內或外掛自帶的設定檔裡調整。
下面這些內容需要先安裝,否則該模組不會生效: