### GenericButtonConfigItem Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Creates a button item in the config UI that runs a callback when clicked. This item is not tied to a ConfigEntry, so you must provide section, name, description, and button text. ```APIDOC ## GenericButtonConfigItem ### Description Creates a button item in the config UI that runs a callback when clicked. This item is not tied to a ConfigEntry, so you must provide section, name, description, and button text. ### Constructor `GenericButtonConfigItem(string section, string name, string description, string buttonText, Action onClick)` ### Parameters - `section` (string) - The section under which the button will be displayed. - `name` (string) - The display name of the button. - `description` (string) - The description shown when hovering over the button. - `buttonText` (string) - The text displayed on the button. - `onClick` (Action) - The callback to run when the button is clicked. ### Example ```csharp LethalConfigManager.AddConfigItem(new GenericButtonConfigItem("Section", "ItemName", "Description", "ButtonText", () => { // Code you want to run when the button is clicked goes here. })); ``` ``` -------------------------------- ### Import LethalConfig namespace Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Add this using directive to access the LethalConfig API in your mod source file. ```csharp using LethalConfig; ``` -------------------------------- ### GenericButtonConfigItem creation Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Create a button item not tied to a ConfigEntry; pass section, name, description, and button text, with a callback for click logic. ```csharp LethalConfigManager.AddConfigItem(new GenericButtonConfigItem("Section", "ItemName", "Description", "ButtonText", () => { // Code you want to run when the button is clicked goes here. })); ``` -------------------------------- ### Listening to setting changes via SettingChanged Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Subscribe to ConfigEntry.SettingChanged to react to value changes, e.g., logging the new value. Players expect immediate effect unless prompted to restart. ```csharp configEntry.SettingChanged += (obj, args) => { logSource.LogInfo($"Slider value changed to {configEntry.Value}"); }; ``` -------------------------------- ### Create a BepInEx ConfigEntry Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Standard BepInEx config binding used as the basis for LethalConfig items. ```csharp var configEntry = Config.Bind("General", "Example", 0, "This is an example component!"); ``` -------------------------------- ### Add BepInDependency attribute for LethalConfig Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Recommended to hint BepInEx that your mod depends on LethalConfig. Replace the plugin attributes with your own. ```csharp [BepInPlugin(PluginInfo.Guid, PluginInfo.Name, PluginInfo.Version)] [BepInDependency("ainavt.lc.lethalconfig")] public class MyVeryCoolPlugin: BaseUnityPlugin { ... } ``` -------------------------------- ### Register an IntSliderConfigItem Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Creates and registers a slider component with min and max options. The section is automatically derived from the ConfigEntry's section. ```csharp var exampleSlider = new IntSliderConfigItem(configEntry, new IntSliderOptions { Min = 0, Max = 100 }); LethalConfigManager.AddConfigItem(exampleSlider); ``` -------------------------------- ### SetModDescription override Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Override the mod's description shown in LethalConfig by passing a string. ```csharp LethalConfigManager.SetModDescription("Very cool mod description!"); ``` -------------------------------- ### ConfigEntry.SettingChanged Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Event that fires when the value of a ConfigEntry changes. This allows mods to react to setting changes immediately. ```APIDOC ## ConfigEntry.SettingChanged ### Description Event that fires when the value of a ConfigEntry changes. This allows mods to react to setting changes immediately. ### Event Handler Signature `void SettingChanged(object sender, EventArgs e)` ### Example ```csharp configEntry.SettingChanged += (obj, args) => { logSource.LogInfo($"Slider value changed to {configEntry.Value}"); }; ``` ``` -------------------------------- ### LethalConfigManager.SetModDescription Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Overrides the mod's description displayed in the LethalConfig UI. ```APIDOC ## LethalConfigManager.SetModDescription ### Description Overrides the mod's description displayed in the LethalConfig UI. ### Parameters - `description` (string) - The new description for the mod. ### Example ```csharp LethalConfigManager.SetModDescription("Very cool mod description!"); ``` ``` -------------------------------- ### LethalConfigManager.SkipAutoGenFor Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Skips automatic generation of config UI for a specific ConfigEntry, a config section, or the entire mod. This is useful for manually managing config items. ```APIDOC ## LethalConfigManager.SkipAutoGenFor ### Description Skips automatic generation of config UI for a specific ConfigEntry, a config section, or the entire mod. This is useful for manually managing config items. ### Overloads - `SkipAutoGenFor(ConfigEntry configEntry)` - Skips automatic generation for the given ConfigEntry. - `SkipAutoGenFor(string section)` - Skips automatic generation for the config section with the given name. - `SkipAutoGen()` - Skips automatic generation for the calling mod. ### Example ```csharp var configEntry = Config.Bind("General", "Example", 0, "This is an example component!"); var skippedConfigEntry = Config.Bind("Skip This Section", "Example 2", 0, "This is an example component!"); LethalConfigManager.SkipAutoGenFor(configEntry); LethalConfigManager.SkipAutoGenFor("Skip This Section"); LethalConfigManager.SkipAutoGen(); ``` ``` -------------------------------- ### SkipAutoGenFor and SkipAutoGen usage Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Skip automatic generation for a specific ConfigEntry, a config section, or the entire calling mod using LethalConfigManager methods. ```csharp var configEntry = Config.Bind("General", "Example", 0, "This is an example component!"); var skippedConfigEntry = Config.Bind("Skip This Section", "Example 2", 0, "This is an example component!"); // skips automatic generation for the ConfigEntry. LethalConfigManager.SkipAutoGenFor(configEntry); // skips automatic generation for the Config section "Skip This Section". LethalConfigManager.SkipAutoGenFor("Skip This Section"); // skips automatic generation for the calling mod. LethalConfigManager.SkipAutoGen(); ``` -------------------------------- ### SetModIcon with Sprite from AssetBundle Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Override the mod's icon by passing a UnityEngine.Sprite, typically loaded from an AssetBundle. ```csharp var aVeryCoolIconAsset = assetBundle.LoadAsset("path/to/asset.png") LethalConfigManager.SetModIcon(aVeryCoolIconAsset); ``` -------------------------------- ### Overriding display properties with BoolCheckBoxOptions Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Visually override the section, name, and description of a config item without changing the underlying ConfigEntry. The underlying entry remains unaffected, avoiding new BepInEx config entries. ```csharp var boolCheckBox = Config.Bind("Example", "Bool Checkbox", false, "This is a bool checkbox."); var configItem = new BoolCheckBoxConfigItem(boolCheckBox, new BoolCheckBoxOptions { Section = "General", Name = "Enable something", Description = "Does something interesting" }); ``` -------------------------------- ### Overriding display properties Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Allows mods to change the visual display properties (section, name, description) of a config item without altering the underlying ConfigEntry. This is useful for reorganizing or renaming items without affecting the config file. ```APIDOC ## Overriding display properties ### Description Allows mods to change the visual display properties (section, name, description) of a config item without altering the underlying ConfigEntry. This is useful for reorganizing or renaming items without affecting the config file. ### Usage Pass `Section`, `Name`, and `Description` properties in the options object when creating a config item. ### Example ```csharp var boolCheckBox = Config.Bind("Example", "Bool Checkbox", false, "This is a bool checkbox."); var configItem = new BoolCheckBoxConfigItem(boolCheckBox, new BoolCheckBoxOptions { Section = "General", Name = "Enable something", Description = "Does something interesting" }); ``` ``` -------------------------------- ### CanModifyCallback for BoolCheckBoxConfigItem Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Use the CanModifyCallback constructor option to conditionally disallow runtime modifications. The callback is invoked every time the config entry is displayed in the UI; return a bool or CanModifyResult with an optional reason message. ```csharp var exampleCheckbox = new BoolCheckBoxConfigItem(configEntry, new BaseOptions { CanModifyCallback = CheckboxCanModifyCallback }); // This gets called everytime the config entry gets displayed in the UI. private static CanModifyResult CheckboxCanModifyCallback() { // Return true if the entry can be modified. // Return false if it should be modified. // When returning false You should also include a message for the reason // that the config entry cannot be modified. return (false, "Example reason"); // you can also return only a bool, or CanModifyResult.True()/CanModifyResult.False(reason) } ``` -------------------------------- ### LethalConfigManager.SetModIcon Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Overrides the mod's icon displayed in the LethalConfig UI. The icon is loaded from an AssetBundle as a Sprite. ```APIDOC ## LethalConfigManager.SetModIcon ### Description Overrides the mod's icon displayed in the LethalConfig UI. The icon is loaded from an AssetBundle as a Sprite. ### Parameters - `icon` (UnityEngine.Sprite) - The sprite to use as the mod's icon. ### Example ```csharp var aVeryCoolIconAsset = assetBundle.LoadAsset("path/to/asset.png"); LethalConfigManager.SetModIcon(aVeryCoolIconAsset); ``` ``` -------------------------------- ### CanModifyCallback Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Allows mods to conditionally disallow modifications to config items at runtime. The callback is invoked every time the config entry is displayed in the UI. ```APIDOC ## CanModifyCallback ### Description Allows mods to conditionally disallow modifications to config items at runtime. The callback is invoked every time the config entry is displayed in the UI. ### Usage Pass a callback to the `CanModifyCallback` property in the options of a config item constructor. ### Callback Signature `CanModifyResult CanModifyCallback()` ### Return Value - `CanModifyResult` - A result indicating whether the entry can be modified. Return `true` to allow modification, or `false` with a reason message to disallow. ### Example ```csharp var exampleCheckbox = new BoolCheckBoxConfigItem(configEntry, new BaseOptions { CanModifyCallback = CheckboxCanModifyCallback }); private static CanModifyResult CheckboxCanModifyCallback() { return (false, "Example reason"); // or return true; or CanModifyResult.True()/CanModifyResult.False(reason) } ``` ``` -------------------------------- ### Disable restart requirement for a slider Source: https://github.com/ainavt/lethalconfig/blob/main/README.md Two ways to set RequiresRestart to false: via the options object or the bool constructor overload. By default, items require a restart and warn the player on apply. ```csharp // Using the slider options object var exampleSlider = new IntSliderConfigItem(configEntry, new IntSliderOptions { RequiresRestart = false, Min = 0, Max = 100 }); // Using the bool constructor overload var exampleSlider = new IntSliderConfigItem(configEntry, requiresRestart: false); ```