# 04 · Client GUI Patches & Declarative EXE Patches > **Experimental Notice**: GUI script patches (`gui-patches`) and declarative `exe` patches (`exe-patches`) depend directly on target client code layout and may require maintenance when the game or core offline patches update. --- ## 1. Plain-Language Intro: War Thunder's DaGui UI Triad (`.tpl` + `.css` + `.nut`) War Thunder's hangar and lobby screens are powered by Dagor's native **DaGui** framework (packaged inside `gui.vromfs.bin`). Every screen or modal window combines three plain-text file types: | Extension | Role | Plain-Language Explanation | | --- | --- | --- | | **`.tpl`** | **Handyman Layout Template** | Similar to HTML + Mustache (e.g. `gui/missions/wtomapselectormodal.tpl`); declares UI containers, buttons, element `id`s, and data-binding tags (`<>`, `{{#cards}}...{{/cards}}`). | | **`.css`** | **DaGui Stylesheet** | Controls widths, heights, margins, colors, fonts, and custom attribute state selectors (such as `[wtoSelected=yes]`). | | **`.nut`** | **Quirrel UI Script** | War Thunder's statically-scoped scripting language (derived from Squirrel); subclasses `BaseGuiHandlerWT` to render `.tpl` views, handle button clicks, and call local server RPCs. | ### Best-Practice UI Pattern: "Standalone Files for Logic + Minimal Patch for Entry Hook" Just like the bundled `templates/official-map-selector` mod, the cleanest way to add new UI is: 1. **Place your new standalone `.nut`, `.tpl`, and `.css` files under `client/packs/gui.vromfs.bin/`**: standalone files have zero collision risk with other mods and survive game updates cleanly; 2. **Use minimal `client/gui-patches/` edits on stock files**: wire a button into an existing screen and register your stylesheet in `gui/css.css`! > **Critical Rule: Standalone `.css` Files Are NOT Auto-Loaded by DaGui!** > Dropping `gui/missions/wtomapselector.css` into `client/packs/gui.vromfs.bin/` alone **has no effect**! DaGui loads stylesheets solely through the root manifest `gui/css.css`, so you **must also patch `gui/css.css` via `client/gui-patches/`** to append `@import "missions\wtomapselector.css"` (note: paths inside `gui/css.css` are relative to `gui/`, use backslashes `\`, and have **no trailing semicolon**—see the real example in Section 2.2 below). --- ## 2. `client/gui-patches/` Format & Matching Rules `client/gui-patches/` is **not limited to `.nut` files—it works identically on `.nut` scripts, `.tpl` templates, and `.css` stylesheets** inside `gui.vromfs.bin`! Each patch lives in a folder containing `patch.jsonc` (nested subdirectories are supported): ```text client/gui-patches/ └─ mode-select-map-selector-button/ ├─ css/ │ ├─ patch.jsonc │ ├─ find-css.css │ └─ replace-css.css ├─ tpl/ │ ├─ patch.jsonc │ ├─ find-nav-right.tpl │ └─ replace-nav-right.tpl └─ script/ ├─ patch.jsonc ├─ find-imports.nut ├─ replace-imports.nut ├─ find-buttons.nut └─ replace-buttons.nut ``` ### 2.1 `.nut` Script Patch Example ```jsonc // Adds a custom entry button to the mode selection panel. { "id": "my-mod/add-button", "title": "Add custom button to mode selector", "features": [], "variants": [ { "written_for": "2.61.0.58", "file": "scripts/gamemodes/gamemodeselect.nut", "edits": [ { "find": "find-imports.nut", "replace": "replace-imports.nut" }, { "find": "find-buttons.nut", "replace": "replace-buttons.nut" } ] } ] } ``` ### 2.2 Real Example: Registering a Standalone `.css` in `gui/css.css` ```jsonc // client/gui-patches/my-style/patch.jsonc { "id": "my-mod/register-css", "title": "Include custom stylesheet in gui/css.css", "features": [], "variants": [ { "written_for": "2.61.0.58", "file": "gui/css.css", "edits": [ { "find": "find-css.css", "replace": "replace-css.css" } ] } ] } ``` `find-css.css`: ```css @import "missions\mapPreferences.css" ``` `replace-css.css`: ```css @import "missions\mapPreferences.css" @import "missions\wtomapselector.css" ``` ### 2.3 Four Critical Path & Variant Rules (Must-Read) 1. **`variant.file` Must Be All Lowercase & Exact Case-Sensitive!** Every file path inside stock `gui.vromfs.bin` is **all lowercase** (e.g. `scripts/gamemodes/gamemodeselect.nut`, `gui/gamemodeselect/gamemodeselect.tpl`, `gui/css.css`). Even though Quirrel `from "%scripts/gameModes/..."` imports are case-insensitive at runtime, the `gui-patches` builder looks up `variant.file` in the archive map via **exact case-sensitive string match**—writing camelCase like `scripts/gameModes/gameModeSelect.nut` fails immediately with `the data pack has no script ...`! Keep added files under `client/packs/gui.vromfs.bin/` all lowercase as well. 2. **Every `find` Snippet Must Match Exactly Once**: Each `edit`'s `find` text must occur **uniquely once** in the target file (`\r\n` vs `\n` line endings are normalized automatically). If it occurs 0 times or ≥2 times, the entire patch is skipped safely and logged to `launcher.log` without half-applying edits. 3. **How `variants` and `written_for` Actually Work**: `written_for` is purely an informational version label for logs and diagnostics. At build time, the builder tests **all** entries in `variants` against the client archive and requires **an exact single match** (`1` matching variant applies; `0` matches skips safely as a build mismatch; `≥2` simultaneous matches rejects the patch as an ambiguous variant definition). 4. **`{{LOCAL_ENDPOINT}}` Placeholder**: Any occurrence of `{{LOCAL_ENDPOINT}}` in `replace` text is automatically expanded to the client's bound local server `127.0.0.1:` (for example `http://{{LOCAL_ENDPOINT}}/mods/demo.my-mod/panel` for embedded browser pages). Core offline GUI patches always run first; mod `gui-patches` run afterward in load order. --- ## 3. Mandatory Check: Building `sq.exe` & Full Quirrel Bytecode Verification War Thunder pre-compiles Quirrel UI scripts during login. Any of the following mistakes in a `.nut` file will cause the client to **hang indefinitely on the "Loading" screen**: - **Lexical scope name collisions**: declaring a `let` / `local` variable that shadows a symbol imported via `from "..." import *` at the top of the file; - **Forward references to undeclared functions** or accidental use of **Quirrel reserved words** (such as `base`); - **JS-style backtick strings (`` `...` ``)**: unsupported by War Thunder's Quirrel VM—always use Quirrel's native string interpolation **`$"hello {name}"`** instead! Note: `sq.exe --syntax-check` runs AST parsing only and **misses lexical collisions and undeclared identifiers**—you must invoke `compilestring(...)` so the full bytecode generator runs! ### 3.1 How External Modders Build a Matching `sq.exe` Clone Gaijin's open-source **[GaijinEntertainment/quirrel](https://github.com/GaijinEntertainment/quirrel)** repository, check out commit `19f17df9b6ee43c91ef5c635fd45970ec76c5dbe` (matching 2.61 clients), and build `sq` with CMake + Visual Studio (C++17): ```powershell git clone https://github.com/GaijinEntertainment/quirrel.git quirrel-src git -C quirrel-src checkout 19f17df9b6ee43c91ef5c635fd45970ec76c5dbe cmake -S quirrel-src -B quirrel-build cmake --build quirrel-build --config Release --target sq # Output binary: quirrel-build\bin\Release\sq.exe ``` ### 3.2 Run `compilestring` on a **Complete `.nut` File** (Not a Partial Snippet) > **Note**: Pass a complete `.nut` file to `compilestring` rather than an isolated `replace.nut` fragment. > `replace.nut` is only an in-place snippet and will fail out of context. Always run `compilestring` against a **complete `.nut` file**—either your standalone `.nut` script, or the full stock `.nut` file **after** applying your `find`/`replace` edits: - **If you cloned the WTOffline repo**: `tools/src/wtotools/gui_check.py` automatically resolves `gui.vromfs.bin` module exports, applies your `gui-patches`, and runs `compilestring` with stub bindings across every touched file; - **Standalone full-file check example** (pass a bindings table as the 3rd argument to `compilestring` if your file uses top-level `from "..." import ...` bindings): ```powershell & "quirrel-build\bin\Release\sq.exe" -e "let io = require('io'); let f = io.file('your_complete_script.nut', 'rb'); let src = f.readblob(f.len()).as_string(); f.close(); compilestring(src, 'your_complete_script.nut'); print('OK\n')" ``` --- ## 4. Declarative EXE Patches (`client/exe-patches/`) Advanced mods can reuse WTOffline's `@wto/exepatch` engine to apply signature-located binary patches to `win64/aces.exe`. Use declarative patch files instead of packaging or distributing modified `aces.exe` binaries. ```text client/exe-patches/ └─ my-tweak/ └─ patch.jsonc ``` Example `patch.jsonc`: ```jsonc // Brief description of what this binary patch changes. // Why the local server cannot do this alone. // What happens if this patch is skipped. { "id": "my-tweak", "title": "Example declarative exe patch", "features": [], "requires": [], "variants": [ { "written_for": "2.61.0.58", "locate": { "kind": "signature", "pattern": "48 8B ?? ?? ?? ?? ?? 84 C0 74 ??", "captures": [] }, "edit": { "offset": 9, "asm": "nop; nop", "bytes": "90 90", "expect_original": "74 ??", "fixups": [] } } ] } ``` ### Supported Locators (`locate.kind`) - `signature`: byte pattern scan supporting `??` wildcards and `captures` for displacements / relative branch targets; - `string_ref`: locates code referencing a fixed ASCII string literal, with optional local instruction verification; - `within`: searches inside the PE `.pdata` function boundaries of a required patch or anchor site. ### Core Isolation Protection & Conflict Handling 1. **Core offline & isolation patches are always planned first and their byte ranges are locked** (covering Gaijin network block, anti-cheat bypass in offline copy, save/registry isolation, launcher suppression, and local TLS/matching keys); 2. **Any mod `exe` patch overlapping even 1 byte of a core patch is hard-rejected** with `overlaps protected core patch` in `launcher.log`; 3. If two mods' `exe` patches write to overlapping byte ranges, the later mod's patch is rejected with the conflicting mod ID; 4. If a signature or `expect_original` check fails on a newer game version, that mod patch is skipped cleanly and logged to `launcher.log` without breaking the offline copy build.