BepInExConfig
Serialize and deserialize the BepInEx configration file into class.
模組介紹 作者原文
BepInExConfig
What's this? これは何?
This isn't Mod. BepInEx Tools.
This tool is BepInEx ConfigFile Class Serializer/Deserializer.
You need to do is to create a class for the configuration with the specified attributes.
Then, when you call the extension methods added by the tool, the settings will be saved and loaded according to the attributes set in the class.
これは Mod ではなく、BepInEx のツールです。
このツールは BepInEx の設定ファイルとクラスをシリアライズ/デシリアライズします。
このツールを使うには、指定された屬性を持つ設定用のクラスを作成する必要があります。
あとは、ツールによって追加された拡張メソッドを呼び出すと、クラスに設定された屬性に応じて設定の保存・読み込みが行われます。
INSTALL インストール
If r2modman
- Install BepInEx
- Install BepInExConfig
- Add BeinExConfig.dll to the project reference. (for Visual Stuio)
r2modmanの場合
- BepInEx をインストールします。
- BepInExConfig をインストールします。
- BepInExConfig.dll をプロジェクトの參照に追加します(Visual Stuio の場合)
If Manual
- Install BepInEx
- Then copy BeinExConfig.dll into ~~~/steamapps/common/Dyson Sphere Program/BepInEx/plugins
- Add BeinExConfig.dll to the project reference. (for Visual Stuio)
手動の場合
- BepInEx をインストールします。
- ダウンロードした BepInExConfig.dll を ~~~/steamapps/common/Dyson Sphere Program/BepInEx/plugins にコピーします
- BepInExConfig.dll をプロジェクトの參照に追加します(Visual Stuio の場合)
Usage 使い方
A simple sample is provided here.
ここには簡単なサンプルを記載します。
There is a plugin for testing in BepInExCoinfgTest, so please refer to it.
BepInExCoinfgTest にテスト用のプラグインがあるので參考にしてください。
Sample Code サンプルコード
Create config class.
設定用クラスを作る。
TestConfig.cs
[BepInExConfig] // 設定用クラスには必須
public class TestConfig
{
// Work - Public Property
[BepInExConfigMember("Base", "TestProp", 10, order: 99)]
public int TestProp { get; set; }
// Work - Public Field
[BepInExConfigMember("Base", "TestField", "hogehoge", "Descripton", order: 0)]
public string TestField;
// Work - Enum
[BepInExConfigMember("Base", "TestKey", KeyCode.Tab, "Sample Key Code Config", order: 1)]
public KeyCode TestKey;
// Not Work - Only public properties or field will work.
[BepInExConfigMember("Base", "TestProp", 10)]
private int PrivateProp { get; set; }
// Not Work - If you don't add the attribute, it won't work.
public int NoAttributeProp { get; set; }
}
Load config.
設定をロード.cs
public static TestConfig PluginConfig { get; set; }
public static void PluginConfigLoad()
{
this.PluginConfig = Config.LoadConfig();
Logger.LogInfo($"TestField: {hoge.TestField}");
Logger.LogInfo($"TestKey: {hoge.TestKey}");
Logger.LogInfo($"TestProp: {hoge.TestProp}");
Logger.LogInfo("Loaded config.");
}
Save config.
設定を保存.cs
public static TestConfig PluginConfig { get; set; }
public static void PluginConfigSave()
{
this.PluginConfig = new TestConfig()
{
TestField = "hugahuga",
TestKey = KeyCode.KeypadEnter,
TestProp = 999,
}
var orphanedEntries = typeof(ConfigFile).GetProperty("OrphanedEntries", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Config, null) as Dictionary;
orphanedEntries?.Clear();
Config.SaveConfig(PluginConfig);
Logger.LogInfo("Saved config.");
}
Saved Config Sample
保存されたコンフィグのサンプル.cfg
Settings file was created by plugin BepInExCoinfgTest v0.0.1
Plugin GUID: Fuhduki.DSP.BepInExCoinfgTest
[Base]
Descripton
Setting type: String
Default value: hogehoge
TestField = hugahuga
Sample Key Code Config
Setting type: KeyCode
Default value: Tab
Acceptable values: None,...
TestKey = KeypadEnter
Setting type: Int32
Default value: 10
TestProp = 999
Simply API Document
Attributes
- BepInExConfig
- Can only be given to classes.
- The configuration class must have a no-argument constructor. (It's OK if you don't write a constructor)
- BepInExConfigMember(string section, string key, string defaultValue, string description = "", int order = 0)
- Can only be given to field or property.
- Only Work to public field or property.
- DefaultValue Typse are string, bool, byte, short, ushort, int, uint, long, ulong, float, double, decimal or object(for Enum).
- The order parameter allows you to determine the order of the configuration items.
- If nothing is set, the settings
安裝與使用 安裝:BepInEx 外掛
- 本站下載的壓縮包就是模組本體,通常是 BepInEx 外掛(解壓後得到 .dll 或外掛資料夾)。
- 建議流程:用社群模組管理器(如 r2modman)選中本遊戲後匯入該模組,管理器會自動裝好 BepInEx 前置並處理依賴。
- 手動流程:先在遊戲目錄裝好 BepInEx 載入器,再把解壓出的 .dll 或外掛資料夾放進 BepInEx/plugins/。
- 啟動遊戲,BepInEx 控制台會列印載入日誌;確認這個模組出現在日誌裡即為安裝成功。
帶「前置依賴」的模組需要一併安裝,否則不會載入。功能開關通常在遊戲內或外掛自帶的設定檔裡調整。
下面這些內容需要先安裝,否則該模組不會生效: