Start here

↑ ↓ to move, Enter to openKeyword search
Guides

Mod Settings API (Launcher UI, Lua, and Native C)

Goal
give any code mod a native configuration UI inside the MJOLNIR Launcher's My Mods page — color pickers, dropdowns, toggles, sliders, and text fields — with zero custom React code, and read those values from UE4SS Lua or a native C DLL
Reference implementation
mods/MJOLNIRHudColor

Goal: give any code mod a native configuration UI inside the MJOLNIR Launcher's My Mods page — color pickers, dropdowns, toggles, sliders, and text fields — with zero custom React code, and read those values from UE4SS Lua or a native C DLL Reference implementation: mods/MJOLNIRHudColor

Instead of asking players to edit Lua files or remember console commands, any code mod can declare a "settings" array in its mod.json. The launcher automatically adds a Settings button to that mod's card in My Mods, renders all controls dynamically, validates every value, and writes a flat JSON file that both Lua mods and native C DLLs can read with zero external dependencies.

MJOLNIRHudColor settings panel open inside the MJOLNIR Launcher's My Mods view, showing the Theme preset dropdown, conditional Custom HUD color picker, toggle switches, and signed badge


Architecture and storage layout

User settings are stored outside ue4ss/Mods/<ModId>/:

<game_binaries>/ue4ss/mjolnir-settings/<ModId>.json

Where <game_binaries> is Meteorite/Binaries/Win64 on Steam and Meteorite/Binaries/WinGDK on Xbox Game Pass.

Keeping user settings outside the mod's install directory enforces two invariants:

  1. Signed mod integrity stays intact. The launcher verifies every installed code mod's tree_digest against its Ed25519-signed release manifest. Writing user config inside ue4ss/Mods/<ModId>/ would immediately mark the mod red (modified). Notice in the screenshot above that MJOLNIRHudColor keeps its blue signed shield even after customizing its settings.
  2. Mod updates never wipe player choices. Updating or reinstalling <ModId> replaces ue4ss/Mods/<ModId>/ while leaving ue4ss/mjolnir-settings/<ModId>.json untouched.

On-disk JSON format

Every settings file uses a flat, primitive-only JSON object:

{
  "schema_version": 1,
  "values": {
    "preset": "custom",
    "custom_color": "#00FF88",
    "recolor_menus": true,
    "enable_hotkey": true
  }
}
  • schema_version is currently 1.
  • values maps each setting key to a JSON primitive (string, boolean, or number — never nested objects or arrays).
  • The launcher writes atomically via a .tmp file and rename (apps/launcher/src-tauri/src/mod_settings.rs).

1. Building your mod's UI inside the Launcher (mod.json)

You do not need to write any React, TypeScript, or Rust code to give your mod a native settings panel in the launcher. Add a top-level "settings" array to mods/<YourMod>/mod.json and the launcher renders the full UI automatically.

All five built-in Mod Settings API control types rendered inside a launcher mod card: select dropdown, conditional color picker, boolean toggle, numeric sliders with units, and text input

What the launcher renders for you automatically

As soon as a mod's mod.json declares at least one entry in "settings":

  • Settings toggle button: The launcher sets has_settings: true on the mod's row in My Mods and shows a Settings / Close button (Library.tsx).
  • Section grouping: Contiguous fields sharing a "section" string are grouped automatically under uppercase section headers (APPEARANCE, CAMERA & MOVEMENT, LABELS).
  • Conditional fields (visible_when): Fields with "visible_when": { "key": "<other_key>", "equals": <value> } appear or hide dynamically as the player interacts with the panel — ideal for revealing a custom color picker or advanced sliders only when relevant.
  • Per-field reset: Any field whose value differs from its "default" shows a gold reset link right beside its label.
  • Footer actions: Every panel displays the exact storage path (ue4ss/mjolnir-settings/<ModId>.json), Reset defaults, Save settings (enabled whenever changes are pending), and a Saved confirmation.

Supported field types

typeJSON valueLauncher controlType-specific properties & Rust validation
"color""#RRGGBB" stringColor swatch picker + monospace hex inputAccepts #RGB or #RRGGBB (with or without #), normalized to uppercase #RRGGBB
"select"stringObsidian-and-gold dropdown (Select)options: array of { "value": string, "label": string }; saved value must match a declared option
"boolean"booleanPill toggle switchStrict boolean
"number"numberRange slider (when both min & max are set) + numeric input + optional unit suffixOptional min, max, step, unit (e.g. "u/s", "°", "%"); rejects NaN/infinity and clamps to [min, max]
"string"stringText inputOptional placeholder, max_length (defaults to 256 characters)

Common field properties

Every object in "settings" accepts these properties (mirrored in mod_settings.rs and types.ts):

PropertyRequiredDescription
"key"YesSetting identifier (1–64 chars: ASCII alphanumeric, _, -, .) — the exact key your Lua or C mod reads from values. Must be unique within the mod.
"type"YesOne of "color", "select", "boolean", "number", "string".
"label"YesHuman-readable label shown beside the control.
"default"YesDefault primitive value matching "type".
"description"NoHelper text displayed underneath the label.
"section"NoOptional group heading (e.g. "Appearance", "Scope & Controls"). Contiguous fields with the same "section" render under one header.
"visible_when"No{ "key": "<other_key>", "equals": <primitive> } — shows the field in the launcher only when <other_key> currently equals that value.

UI Cookbook: Recipe 1 — Preset dropdown + conditional color picker

This is the exact mods/MJOLNIRHudColor/mod.json schema that powers the first screenshot above. Notice how "custom_color" stays hidden while the player picks a built-in preset, and reveals the color swatch + hex input the instant they choose "custom":

{
  "version": "0.1.0",
  "summary": "Recolor Halo Campaign Evolved's Unreal Engine 5 HUD and menu theme at runtime with built-in presets or any hex color, without tag edits or recooking.",
  "category": "tools",
  "slug": "mjolnir-hud-color",
  "settings": [
    {
      "key": "preset",
      "type": "select",
      "label": "Theme preset",
      "description": "Built-in palette, or pick Custom Color to choose any hex color below.",
      "section": "Appearance",
      "default": "amber",
      "options": [
        { "value": "amber", "label": "Amber (Halo 3 / ODST)" },
        { "value": "emerald", "label": "Emerald (Classic CE)" },
        { "value": "crimson", "label": "Crimson (Banished)" },
        { "value": "violet", "label": "Violet (Covenant)" },
        { "value": "white", "label": "Tactical Monochrome" },
        { "value": "default", "label": "Shipped Cyan (Default)" },
        { "value": "custom", "label": "Custom Color…" }
      ]
    },
    {
      "key": "custom_color",
      "type": "color",
      "label": "Custom HUD color",
      "description": "Derives a matching 6-shade HUD and menu theme from one sRGB hex color.",
      "section": "Appearance",
      "default": "#F5A623",
      "visible_when": { "key": "preset", "equals": "custom" }
    },
    {
      "key": "recolor_menus",
      "type": "boolean",
      "label": "Recolor frontend & pause menus",
      "description": "Turn off to keep the main menu cyan and only recolor the in-game HUD.",
      "section": "Scope & Controls",
      "default": true
    },
    {
      "key": "enable_hotkey",
      "type": "boolean",
      "label": "F5 preset cycle hotkey",
      "description": "Press F5 in game to cycle through built-in presets.",
      "section": "Scope & Controls",
      "default": true
    }
  ]
}

UI Cookbook: Recipe 2 — Sliders with units, toggles, and text inputs

This schema produces the five-control card in the second screenshot above, demonstrating "number" sliders with "unit", "string" with "placeholder" / "max_length", "boolean", "select", and "color":

{
  "version": "1.0.0",
  "summary": "Example code mod declaring all five Mod Settings API field types.",
  "category": "tools",
  "settings": [
    {
      "key": "profile",
      "type": "select",
      "label": "Display style",
      "description": "Preset layout style, or choose Custom to unlock accent color customization.",
      "section": "Appearance",
      "default": "tactical",
      "options": [
        { "value": "tactical", "label": "Tactical (Compact)" },
        { "value": "classic", "label": "Classic CE" },
        { "value": "custom", "label": "Custom…" }
      ]
    },
    {
      "key": "accent_color",
      "type": "color",
      "label": "Accent color",
      "description": "Primary highlight color in sRGB hex (#RRGGBB). Shown when Display style is Custom.",
      "section": "Appearance",
      "default": "#52C5D8",
      "visible_when": { "key": "profile", "equals": "custom" }
    },
    {
      "key": "show_telemetry",
      "type": "boolean",
      "label": "Show live telemetry overlay",
      "description": "Render speed, coordinates, and camera pitch in the upper-left corner.",
      "section": "Camera & Movement",
      "default": true
    },
    {
      "key": "move_speed",
      "type": "number",
      "label": "Base flight speed",
      "description": "Movement velocity in Unreal units per second before Shift/Ctrl modifiers.",
      "section": "Camera & Movement",
      "default": 1800,
      "min": 200,
      "max": 5000,
      "step": 100,
      "unit": "u/s"
    },
    {
      "key": "fov_scale",
      "type": "number",
      "label": "Camera FOV",
      "description": "Horizontal field of view while free-cam is active.",
      "section": "Camera & Movement",
      "default": 90,
      "min": 60,
      "max": 120,
      "step": 1,
      "unit": "°"
    },
    {
      "key": "watermark",
      "type": "string",
      "label": "Custom screenshot tag",
      "description": "Optional short label stamped onto captured overlays (up to 32 characters).",
      "section": "Labels",
      "default": "",
      "placeholder": "e.g. B30 Cinema Pass",
      "max_length": 32
    }
  ]
}

Launcher implementation files

For reference (or when contributing a new generic control type):

Most mods never need to edit the launcher at all. If a future mod genuinely requires a reusable control type that the five built-in types cannot express (for example, a keybind capture input), extend SettingType / SettingField in mod_settings.rs and types.ts and add a single case branch in SettingControl.tsx so every mod can reuse it.


2. Reading settings in UE4SS Lua mods

The canonical zero-dependency Lua helper lives at mods/MJOLNIRCore/Scripts/ModSettings.lua.

Because UE4SS's require() searches a mod's own Scripts/ folder (and ue4ss/Mods/shared/), not sibling mod folders, each Lua mod that uses settings ships a byte-identical copy of ModSettings.lua in its own Scripts/ directory. tools/tests/test_mod_settings.lua verifies parity in CI so copies never drift.

Basic usage

local ModSettings = require("ModSettings")

local SETTING_DEFAULTS = {
    preset        = "amber",
    custom_color  = "#F5A623",
    recolor_menus = true,
    enable_hotkey = true,
}

local lastRaw = nil
local settings = ModSettings.merge(SETTING_DEFAULTS, nil)

local function syncSettings()
    local loaded, raw = ModSettings.load("MyModName", SETTING_DEFAULTS)
    if raw == lastRaw and next(settings) ~= nil then
        return false -- unchanged on disk; preserve any in-game runtime override
    end
    lastRaw = raw
    settings = loaded
    return true
end

API summary (ModSettings.lua)

  • ModSettings.load(modId, defaults, opts) → values, rawText, resolvedPath
    • Resolves <game_binaries>\ue4ss\mjolnir-settings\<modId>.json automatically on both Steam (Win64) and Xbox Game Pass (WinGDK) using the caller's source path via debug.getinfo.
    • Parses the JSON without external dependencies, merges only keys present in defaults whose runtime type matches (type(v) == type(default)), and falls back cleanly to defaults if the file is missing, empty, or corrupt.
    • Returns the raw file string as rawText (or "" if no file exists) so mods can detect on-disk edits cheaply without clobbering runtime overrides.
  • ModSettings.configPath(modId, scriptPath) → resolved path string (or nil).
  • ModSettings.ue4ssRoot(scriptPath) → <game_binaries>\ue4ss root string (or nil).
  • ModSettings.parseJson(text) → decoded Lua value (or nil, err).
  • ModSettings.merge(defaults, parsed) → new table with defaults merged.

Keep it event-driven (no polling loops)

Do not poll the settings file on a tick or timer loop. Re-check ModSettings.load only at natural lifecycle boundaries — startup, PlayerController:ClientRestart, menu/HUD open hooks, and an optional console reload command (e.g. mjolnir_hud_color reload). That way, players can even change a setting in the launcher while the game is running and pick it up on the next screen transition or console reload with zero per-frame overhead.

PR capability checklist: Because ModSettings.lua reads <ue4ss>\mjolnir-settings\<ModId>.json via io.open, remember to check the File I/O capability box and note read-only settings loading in your code-mod pull request (contributing_code_mods.md).


3. Reading settings in native C DLL mods

Native C mods can include the header-only C99/C11 library native/include/mjolnir_mod_settings.h. It has zero external dependencies (standard C library + optional Windows.h for GetModuleFileNameA) and compiles cleanly under MSVC /W4 /WX.

Usage in a native DLL

#include <windows.h>
#include "../include/mjolnir_mod_settings.h"

static void load_my_mod_settings(void) {
    char path[MAX_PATH];
    if (!mjolnir_settings_path_from_address(
            (const void *)&load_my_mod_settings,
            "MJOLNIRHudColor",
            path,
            sizeof(path))) {
        return;
    }

    MjolnirModSettings cfg;
    if (mjolnir_settings_load_file(&cfg, path)) {
        const char *preset = mjolnir_settings_get_string(&cfg, "preset", "amber");
        int recolor_menus = mjolnir_settings_get_bool(&cfg, "recolor_menus", 1);

        float r = 1.0f, g = 0.55f, b = 0.10f;
        if (mjolnir_settings_get_color_linear(&cfg, "custom_color", &r, &g, &b)) {
            /* r, g, b are UE5 linear-light RGB ready for FLinearColor */
        }
        (void)preset;
        (void)recolor_menus;
    }
    mjolnir_settings_free(&cfg);
}

C API overview

FunctionPurpose
mjolnir_settings_path_from_address(addr, mod_id, out, cap)Resolves <ue4ss>\mjolnir-settings\<mod_id>.json from any function/static address inside your DLL (handles ue4ss/Mods/<Mod>/native/*.dll and ue4ss/Mods/<Mod>/*.dll)
mjolnir_settings_path_from_dll_path(dll_path, mod_id, out, cap)Pure path-string version of the resolver (testable without Windows module lookup)
mjolnir_settings_path_from_exe(mod_id, out, cap)Resolves via the host game executable's directory (<game_binaries>\ue4ss\mjolnir-settings\<mod_id>.json)
mjolnir_settings_load_file(&cfg, path) / mjolnir_settings_parse(&cfg, json)Initializes cfg and loads/parses { "schema_version": 1, "values": { ... } }
mjolnir_settings_get_string / get_bool / get_numberType-safe value getters with caller-supplied defaults
mjolnir_settings_get_color_rgb(&cfg, key, &r, &g, &b)Parses #RRGGBB / #RGB into 8-bit sRGB channels (0..255)
mjolnir_settings_get_color_linear(&cfg, key, &r, &g, &b)Parses #RRGGBB / #RGB and converts directly to linear-light RGB (0.0..1.0) for UE5 FLinearColor
mjolnir_settings_free(&cfg)Releases all memory allocated by the parsed settings table

Unit tests live in native/include/test_mod_settings.c and run in CI via native/include/test-mod-settings.ps1.


4. Testing your mod's settings locally

  1. Add your "settings" array to mods/<YourMod>/mod.json.
  2. If your mod is Lua, copy mods/MJOLNIRCore/Scripts/ModSettings.lua into mods/<YourMod>/Scripts/ModSettings.lua and add <YourMod> to tools/tests/test_mod_settings.lua, then run:
    lua tools/tests/test_mod_settings.lua
    
  3. If your mod has a native C DLL, test the header with:
    .\native\include\test-mod-settings.ps1
    
  4. Preview your UI live in the launcher (cd apps/launcher && pnpm tauri dev), open My Mods, click Settings on your mod's card, tweak each control, click Save settings, and verify <game_binaries>\ue4ss\mjolnir-settings\<YourMod>.json updates and loads cleanly in-game.
  5. Run the launcher Rust settings tests if you touched the schema backend:
    cd apps/launcher/src-tauri
    cargo test --lib mod_settings