Requirements: BepInEx
Also on Nexus Mods.
ModSettingsLib is a small mod to help create and unify settings menus for other mods in Casualties Unknown.
Note for players: This is a core dependency library. It does not add any content on its own, but is required by other mods to function.
- Ensure you have BepInEx 5 installed for Casualties Unknown.
- Download the latest release here.
- Extract the folder within the the zip file into the game directory under
BepInEx/plugins/. - Launch the game. Within the games settings menu, you should be able to find a new tab called "Mod Settings".
Implement a settings page for your mod as follows.
Within in your plugins Awake() function, define the default entries for your mods setting pages:
using CU_ModSettings;
public void Awake()
{
ModSettingsPlugin.AddModSettingsPageDefaults("Dani.ExampleModName", new SettingBool
{
name = "Dani.ExampleConsume",
value = true
},
new SettingBool
{
name = "Dani.ExampleSure",
value = true
},
new SettingInt
{
name = "Dani.ExampleHowMuch",
value = 1,
min = 0,
max = 255
});
}This mod uses the games translation system in order to determine the display strings for settings pages.
The Setting.name field is therefor a translation key. You will have to register translation keys in the Locale class.
// Example for adding translation keys for the mod settings page entry above
internal class LocalePatches
{
public static void LoadLanguagePatch()
{
// Include this check to avoid overwriting modded translations for your mod
if (Locale.currentLangName is not "EN") return;
Dictionary<string, string> other = Locale.currentLang.other;
other["Dani.ExampleModName"] = "Example Mod";
// The game prefixes settings translationkeys with "gameset" and
// postfixes the description keys with "dsc"
other["gamesetDani.ExampleConsume"] = "Consume example";
other["gamesetDani.ExampleConsumedsc"] = "Determines if you want to be able to consume.";
other["gamesetDani.ExampleSure"] = "Are you sure?";
other["gamesetDani.ExampleSuredsc"] = "Checks to see if you are really sure to consume it.";
other["gamesetDani.ExampleHowMuch"] = "How much do you want to consume?";
other["gamesetDani.ExampleHowMuchdsc"] = "Asks how much you want to consume.";
}
}
public static class HarmonyPatcher
{
// Call this function in your plugins Awake() function.
public static void ApplyPatches()
{
Harmony harmony = new("Example Mod");
harmony.Patch(Method(typeof(Locale), nameof(Locale.LoadLanguage)),
postfix: new(typeof(LocalePatches), nameof(LocalePatches.LoadLanguagePatch)));
}
}Use Settings.Get<T>(string name); to retrieve your set values.
nameis a translation keyvalueholds the saved or the default valueapplycan be given a lambda, that runs immediately when the setting was changed in the settings menu
Note: Some
Settingclasses likeSettingInthave fields likeminandmaxwhich default to 0. If you don't assign them, players can never set the value to anything other than 0.