Aptivi - Manual
ProjectsWebsiteBlog
Nitrocid KS - Manual
Nitrocid KS - Manual
  • Welcome!
  • Versions and Compatibility
    • Supported Versions
    • EOL Versions
    • Version Release Notes
      • v0.0.1.x series
      • v0.0.2.x series
      • v0.0.3.x series
      • v0.0.4.x series
      • v0.0.5.x series
        • v0.0.5.0 Beta Versions
      • v0.0.6.x series
        • v0.0.6.0 Beta Versions
      • v0.0.7.x series
        • v0.0.7.0 Beta Versions
      • v0.0.8.x series
      • v0.0.9.x series
      • v0.0.10.x series
      • v0.0.11.x series
      • v0.0.12.x series
      • v0.0.13.x series
      • v0.0.14.x series
      • v0.0.15.x series
      • v0.0.16.x series
      • v0.0.17.x series
      • v0.0.18.x series
      • v0.0.19.x series
      • v0.0.20.x series
      • v0.0.21.x series
      • v0.0.22.x series
      • v0.0.23.x series
      • v0.0.24.x series
      • v0.1.0.x and 0.1.1.x series
      • v0.1.2.x and v0.1.3.x series
    • Compatibility Notes for KS API Revisions
      • Upgrading to API v1.0 series
      • Upgrading to API v1.1 series
      • Upgrading to API v1.2 series
      • Upgrading to API v1.3 series
      • Upgrading to API v2.0 series
      • Upgrading to API v2.1 series
      • Upgrading to API v3.0 series
        • From 0.0.24.x to 0.1.0 Beta 1
        • From 0.1.0 Beta 1 to 0.1.0 Beta 2
        • From 0.1.0 Beta 2 to 0.1.0 Beta 3
        • From 0.1.0 Beta 3 to 0.1.0 RC
        • From 0.1.0 RC to 0.1.0 Final
      • Upgrading to API v3.1 series
  • Installation and Maintenance
    • Installing the Kernel
      • Windows
      • macOS
      • Linux
      • Android
    • Upgrading the Kernel
      • Windows
      • macOS
      • Linux
      • Android
    • Dependency Information
  • Fundamentals
    • What is the Kernel?
    • What is Nitrocid KS?
    • Simulated Kernel Features
      • Extra Features
        • More Networking
          • FTP Client
          • SSH Connection
          • SFTP Client
          • RSS Client
          • HTTP Client
          • Mail Client
        • Games and Amusements
          • Hangman
          • BackRace
          • Meteor
          • Pong
          • Russian Roulette
          • ShipDuet
          • Snaker
          • Solver
          • SpeedPress
          • Wordle
        • More Editors
          • JSON Editor
          • SQL Editor
        • Common Programs
          • Archive
          • Caffeine
          • Calendar
          • Calculator
          • Contacts
          • Dictionary
          • Git Shell
          • Notes
          • Stocks
          • Timers
          • To-do List
          • Unit Converter
          • Weather
        • Docking
        • Language Studio
        • Theme Studio
      • Accounts
        • Groups
        • Permissions
      • Editors
        • Text Editor
        • Hex Editor
      • Shells
        • Commands List
        • Addon Commands List
      • Files and Folders
        • Hashing and Encryption
      • The Nitrocid Homepage
      • Networking
      • Localization
      • Screensavers
      • Lockscreen Widgets
      • Audio Cues
  • Advanced and Power Users
    • Building the Kernel
      • Building on Windows
      • Building on macOS
      • Building on Linux
      • Building on Android
    • Kernel Modifications
      • Building your Mod
      • Analyzing your Mod
        • Text - NKS0001
        • ConsoleBase - NKS0002
        • ConsoleBase - NKS0003
        • ConsoleBase - NKS0004
        • ConsoleBase - NKS0005
        • ConsoleBase - NKS0006
        • ConsoleBase - NKS0007
        • ConsoleBase - NKS0008
        • ConsoleBase - NKS0009
        • Files - NKS0010
        • Files - NKS0011
        • Files - NKS0012
        • Files - NKS0013
        • Files - NKS0014
        • Files - NKS0015
        • Files - NKS0016
        • Files - NKS0017
        • Files - NKS0018
        • Files - NKS0019
        • Files - NKS0020
        • Files - NKS0021
        • Files - NKS0022
        • Files - NKS0023
        • Kernel - NKS0024
        • Kernel - NKS0025
        • Kernel - NKS0026
        • Kernel - NKS0027
        • Kernel - NKS0031
        • Kernel - NKS0032
        • Kernel - NKS0033
        • Kernel - NKS0037
        • Kernel - NKS0038
        • Kernel - NKS0039
        • Kernel - NKS0040
        • Kernel - NKS0041
        • Kernel - NKS0042
        • Kernel - NKS0043
        • Kernel - NKS0052
        • Kernel - NKS0053
        • Languages - NKS0044
        • Languages - NKS0045
        • Languages - NKS0046
        • Network - NKS0051
        • Text - NKS0047
        • Text - NKS0048
        • Text - NKS0049
        • Text - NKS0050
        • Text - NKS0054
        • Text - NKS0055
      • Managing your Mod
        • Inter-Mod Communication
        • Inter-Addon Communication
    • Diagnostics
      • Debugging
        • Local Debugging
        • Remote Debugging
      • Testing
      • Other Diagnostics
    • Bootloader
      • Boot Choices
      • Kernel Environments
      • Custom Boot Styles
    • Inner Workings
      • Kernel Settings
        • Mechanics of Settings App
        • Settings Format
        • Custom Settings
      • Shell Structure
        • Help System
        • Command Parsing
        • Command Information
        • Command Switches
        • Shell History
        • Shell Scripting
        • Shell Presets
        • Extra Shell Features
      • Multilingual Kernel
        • Locale Tools
        • Custom Languages
      • Inner Essentials
        • Kernel Drivers
          • Console Drivers
          • Debug Logger Drivers
          • Encoding Drivers
          • Encryption Drivers
          • Filesystem Drivers
          • Hardware Prober Drivers
          • Input Drivers
          • Network Drivers
          • RNG Drivers
          • Regular Expression Drivers
          • Sorting Drivers
        • Kernel Placeholders
        • The Permissions
        • The Users
        • Kernel Threads
        • Kernel Arguments
        • Kernel Journaling
        • Remote Procedure
        • Nitrocid Filesystem
        • Screensaver Internals
        • Splash Internals
        • Kernel Platform
        • Theme Internals
        • Color Internals
        • Privacy Consents
        • System Notifications
        • MAL and MOTD
        • Progress Handlers
        • Assembly Signing
        • Assembly Reflection
        • Random Number Generation
        • Network Tools
        • Date and Time
        • Mod Manual Pages
      • Miscellaneous APIs
  • Project Dependencies
  • Report an issue
  • Source code
  • API Reference
Powered by GitBook
On this page
  • Defining custom settings
  • Using your own custom settings
  • Testing your own custom settings
  • Fallback configuration
Edit on GitHub
  1. Advanced and Power Users
  2. Inner Workings
  3. Kernel Settings

Custom Settings

You can add your own custom settings, too!

Last updated 2 months ago

Customized settings give you an ability to leverage the built-in settings application provided by the Nitrocid base system to customize your mod's behavior. These settings are saved to your kernel configuration directory as JSON files under the class names for easy recognition.

In your mod, you can register and unregister your custom settings using the following functions from the ConfigTools class:

  • RegisterCustomSetting(BaseKernelConfig kernelConfig)

  • UnregisterCustomSetting(string setting)

Beware that your base kernel configuration class must contain valid entries in your list of entries under the JSON representation.

You can use the below function to convert your JSON settings entries to their usable ones:

public static SettingsEntry[] GetSettingsEntries(string entriesText)

Defining custom settings

Before you continue, you must first understand the settings format and take a quick look at it here:

The first thing that your custom kernel settings requires is that you need to have a class (for example, let's assume that your custom settings class name is OxygenSettings) that is derived from both the BaseKernelConfig class and the IKernelConfig interface.

OxygenSettings.cs
internal class OxygenSettings : BaseKernelConfig, IKernelConfig
{
    // Your custom settings here
}

This class must override the SettingsEntries property from the base class so that it can understand your custom settings entries and how they're defined. The easiest way to override it is to just let this property return an array from SettingsEntries using the GetSettingsEntries function, pointing it at your variable containing your JSON representation of the settings entries, as demonstrated in the below example:

OxygenSettings.cs
internal class OxygenSettings : BaseKernelConfig, IKernelConfig
{
    // Your JSON representation about your settings entries
    private readonly string _entriesJson =
        """
        [
            {
                "Name": "CustomSection",
                "Desc": "This is the custom section.",
                "DisplayAs": "Custom section",
                "Keys": [
                    {
                        "Name": "Custom switch",
                        "Type": "SBoolean",
                        "Variable": "CustomSwitch",
                        "Description": "Specifies the custom switch."
                    },
                    {
                        "Name": "Custom character",
                        "Type": "SChar",
                        "Variable": "CustomChar",
                        "Description": "Specifies the custom character."
                    },
                    {
                        "Name": "Custom color",
                        "Type": "SColor",
                        "Variable": "CustomColor",
                        "Description": "Specifies the custom color."
                    },
                    {
                        "Name": "Custom double",
                        "Type": "SDouble",
                        "Variable": "CustomDouble",
                        "Description": "Specifies the custom double."
                    },
                    {
                        "Name": "Custom figlet font",
                        "Type": "SFiglet",
                        "Variable": "CustomFigletFont",
                        "Description": "Specifies the custom figlet font."
                    },
                    {
                        "Name": "Custom integer",
                        "Type": "SInt",
                        "Variable": "CustomInt",
                        "Description": "Specifies the custom integer."
                    },
                    {
                        "Name": "Custom integer slider",
                        "Type": "SIntSlider",
                        "Variable": "CustomIntSlider",
                        "Description": "Specifies the custom integer slider.",
                        "MinimumValue": 0,
                        "MaximumValue": 255
                    },
                    {
                        "Name": "Custom list",
                        "Type": "SList",
                        "Variable": "CustomList",
                        "SelectionFunctionName": "GetPathList",
                        "SelectionFunctionType": "Filesystem",
                        "DelimiterVariable": "PathLookupDelimiter",
                        "IsValuePath": true,
                        "IsPathCurrentPath": true,
                        "Description": "Specifies the custom list."
                    },
                    {
                        "Name": "Custom preset",
                        "Type": "SPreset",
                        "Variable": "CustomPreset",
                        "ShellType": "Shell",
                        "Description": "Specifies the custom preset."
                    },
                    {
                        "Name": "Custom selection",
                        "Type": "SSelection",
                        "Variable": "CustomSelection",
                        "IsEnumeration": false,
                        "SelectionFunctionName": "ListAllLanguages",
                        "SelectionFunctionType": "LanguageManager",
                        "IsSelectionFunctionDict": true,
                        "SelectionFallback": [ "en-US" ],
                        "Description": "Specifies the custom selection."
                    },
                    {
                        "Name": "Custom string",
                        "Type": "SString",
                        "Variable": "CustomString",
                        "Description": "Specifies the custom string."
                    }
                ]
            }
        ]
        """;

    // You must override this
    public override SettingsEntry[] SettingsEntries =>
        ConfigTools.GetSettingsEntries(_entriesJson);

    // Your variables. Your JSON representation of the entries must contain information about these
    public char CustomChar { get; set; } = 'A';
    public string CustomColor { get; set; } = Color.Empty.PlainSequence;
    public double CustomDouble { get; set; } = 0.5d;
    public bool CustomSwitch { get; set; } = true;
    public string CustomFigletFont { get; set; } = "small";
    public int CustomInt { get; set; } = 1;
    public int CustomIntSlider { get; set; } = 4;
    public string CustomList { get; set; } = "";
    public string CustomPreset { get; set; } = "Default";
    public string CustomString { get; set; } = "Default";
    public string CustomSelection { get; set; } = "en-US";
}

After that, you must register your configuration class by just two lines somewhere in your mod initialization code:

MyModInit.cs
var customSettings = new OxygenSettings();
ConfigTools.RegisterCustomSetting(customSettings);

You don't have to save a copy of your customSettings variable, since it gets added to the custom settings list that the kernel configuration tool supervises.

You can also unregister your custom settings by putting the UnregisterCustomSetting() function somewhere in your mod stop function like this:

MyModStop.cs
ConfigTools.UnregisterCustomSetting(nameof(OxygenSettings));

You don't have to do all the guesswork to figure out how to get your custom configuration name. All you have to do is to point the above function to the name of your configuration class using the nameof function.

Using your own custom settings

To use your own custom settings, you'll have to get a settings instance from GetKernelConfig() before being able to get the updated settings instance containing your configured settings, even if you have a new instance of your custom settings. You can easily wrap it to a property like this:

Mod.cs
internal static BaseKernelConfig Configuration =>
    Config.GetKernelConfig(nameof(OxygenSettings));

You can then get a value from your desired settings key. For example, if you want to get a value of a string configuration defined earlier, called CustomString, you can get the value of this key like this:

Mod.cs
var key = ConfigTools.GetSettingsKey(Configuration, nameof(OxygenSettings.CustomString));
string value = (string)ConfigTools.GetValueFromEntry(key, Configuration);

If you used this method against your newly-created instance of your custom settings (the customSettings variable) instead of the above property, calls to GetValueFromEntry() would not return the configured results changed by the settings command.

Testing your own custom settings

To test your own custom settings to check to see if it works or not, make sure that you've registered your custom settings upon starting your mod. Invoking the help usage of the settings command (help settings) is enough to list all of your kernel settings (built-in and custom).

Use the settings command to specify your kernel settings type with the -type switch, pointing it to your custom kernel settings name, which is usually your settings class name, for example, settings -type=OxygenSettings.

If everything goes well, you should be able to change your settings there.

When registering custom settings, the kernel runs a validation test to ensure that your custom settings are formed well before adding it to the list. If it fails, the kernel will give you a list of the configuration entries that you'll have to fix before being able to use them.

If any of the kernel configuration entries is invalid, the configuration tools will report a failure. Make sure that all of the entries are valid and that you've specified the variable names correctly. Use nameof to help you assign them.

The variable names are case-sensitive.

Fallback configuration

You can generate a configuration instance that contains all fallback values that are determined by the constructor of all settings properties. You can provide either a configuration class as a generic type argument, or a config type name, using the GetFallbackKernelConfig() function.

To demonstrate that, you can use either of the following:

  • F8: Reset all configuration entries

  • SHIFT + R: Reset selected configuration entry

Some of the kernel settings may store the current settings, even if the fallback instances are generated. Settings for your mods should not rely on external variables when possible.

You can also embed your settings JSON content if it became too big using the Resources feature, which you can learn more about how to add a file to your project resources and use it .

Settings Format
here