Files
WTO-Site/mod-docs.html
T
N0VAN0M4LY fa05f36584 feat(site): upgrade documentation reader with full-book handbooks and search
Compile unabridged bilingual Developer Handbook and Mod Authoring Handbook from repository Markdown with nested list and ordered-list continuation fixes, fix primary button text contrast inside doc sections, and add full-book search, expand-all Ctrl+F mode, active chapter sub-TOC, pushState history, and local file:// link fallback.
2026-12-03 11:26:11 +08:00

1922 lines
281 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="zh-CN" data-mode="dark">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>WTOffline · 模组制作完整手册</title>
<meta name="description" content="WTOffline 全 7 章添加式模组制作手册:原版解包查阅、mod.jsonc 清单、BLK/CSV 增量补丁、权重换算、衍生车闭环实战、自定义 3D 模型、GUI/EXE 补丁与服务端 JS/TS 脚本 API。">
<link rel="icon" type="image/svg+xml" href="assets/icon.svg">
<link rel="stylesheet" href="site/tokens.css">
<link rel="stylesheet" href="site/home.css">
</head>
<body data-lang="zh" data-page="mod-docs">
<div id="blink"></div>
<div class="bg"></div>
<div class="grid"></div>
<header class="nav">
<a class="brand" href="/">
<img class="logo" src="assets/icon.svg" alt="" width="28" height="28" draggable="false">
<span>WT<span class="brand-accent">OFFLINE</span></span>
</a>
<nav class="nav-links">
<a href="/dev-docs">
<span class="lang-zh">开发者文档</span>
<span class="lang-en">Dev Docs</span>
</a>
<a class="active" href="/mod-docs">
<span class="lang-zh">模组文档</span>
<span class="lang-en">Mod Docs</span>
</a>
<a href="/releases">
<span class="lang-zh">下载</span>
<span class="lang-en">Download</span>
</a>
<a class="hide-sm" href="/#community">
<span class="lang-zh">社区</span>
<span class="lang-en">Community</span>
</a>
<a href="https://git.wto-project.net/Sh3ll_in_Sh3ll/WT-Offline" target="_blank" rel="noopener">Git ↗</a>
<button class="ui-btn" type="button" data-lang-toggle title="Switch Language / 切换语言" aria-label="Switch language">
<span class="lang-zh">EN</span>
<span class="lang-en">中文</span>
</button>
<button class="ui-btn ui-iconbtn" type="button" data-mode-toggle title="Toggle Light / Dark" aria-label="Toggle color theme">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="4"/>
<path d="M12 2.5v2.2M12 19.3v2.2M21.5 12h-2.2M4.7 12H2.5M18.7 5.3l-1.5 1.5M6.8 17.2l-1.5 1.5M18.7 18.7l-1.5-1.5M6.8 6.8 5.3 5.3"/>
</svg>
</button>
</nav>
</header>
<main class="focus-in">
<div class="wrap wrap-doc">
<section class="page-head stagger">
<a class="back-link" href="/">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M19 12H5M11 6l-6 6 6 6"/>
</svg>
<span class="lang-zh">返回 WTOffline 主页</span>
<span class="lang-en">Back to WTOffline Home</span>
</a>
<div class="eyebrow">MOD AUTHORING HANDBOOK · API 0.1-EXPERIMENTAL</div>
<h1 class="page-title">
<span class="lang-zh">模组制作完整手册(全 7 章)</span>
<span class="lang-en">Mod Authoring Handbook (7 Chapters)</span>
</h1>
<p class="lede">
<span class="lang-zh">面向模组创作者的完整在线手册:从解包查看原版文件、5 分钟入门、BLK/CSV 增量补丁、自定义 3D 载具、GUI/EXE 补丁到服务端零代码调参与全栈脚本案例,中英双语零删减呈现。</span>
<span class="lang-en">The complete unabridged 7-chapter handbook for mod authors—from inspecting stock archives and 5-minute quick start to BLK/CSV patches, custom 3D vehicles, GUI/EXE hooks, tuning overlays, and full-stack server scripts.</span>
</p>
</section>
<div class="doc-layout">
<aside class="doc-toc" aria-label="Handbook navigation">
<div class="doc-tools">
<div class="doc-search">
<input class="doc-search-input" type="search" data-doc-search placeholder="搜索全书关键词…" aria-label="Search handbook">
<div class="doc-search-results" role="listbox"></div>
</div>
<button class="doc-expand-btn" type="button" data-expand-all aria-pressed="false">
<span class="lang-zh">展开全部章节(支持 Ctrl+F)</span>
<span class="lang-en">Expand All Chapters (Ctrl+F)</span>
</button>
</div>
<div>
<p class="doc-toc-title">
<span class="lang-zh">章节目录(共 7 章)</span>
<span class="lang-en">Chapters (7)</span>
</p>
<nav>
<a href="#ch-01" data-chapter="ch-01" class="active" aria-current="page">
<span class="lang-zh">01 · 快速入门与清单规范</span>
<span class="lang-en">01 · Quick Start &amp; Manifest</span>
</a>
<a href="#ch-02" data-chapter="ch-02">
<span class="lang-zh">02 · 数据包与 BLK/CSV 补丁</span>
<span class="lang-en">02 · Client Packs &amp; BLK Patching</span>
</a>
<a href="#ch-03" data-chapter="ch-03">
<span class="lang-zh">03 · 自定义 3D 模型载具</span>
<span class="lang-en">03 · Custom 3D Vehicles</span>
</a>
<a href="#ch-04" data-chapter="ch-04">
<span class="lang-zh">04 · GUI 与声明式 EXE 补丁</span>
<span class="lang-en">04 · GUI &amp; Declarative EXE Patches</span>
</a>
<a href="#ch-05" data-chapter="ch-05">
<span class="lang-zh">05 · 服务端零代码调参</span>
<span class="lang-en">05 · Server Tuning &amp; $listOps</span>
</a>
<a href="#ch-06" data-chapter="ch-06">
<span class="lang-zh">06 · 服务端 JS/TS 脚本 API</span>
<span class="lang-en">06 · Server Scripting API</span>
</a>
<a href="#ch-07" data-chapter="ch-07">
<span class="lang-zh">07 · 排错、热重载与发布</span>
<span class="lang-en">07 · Troubleshooting &amp; Packaging</span>
</a>
</nav>
</div>
<div class="doc-toc-card">
<span class="lang-zh">启动器首次初始化已自动释放 <strong>3 套可运行官方模板</strong>,也可直接在线查阅源码:</span>
<span class="lang-en">The launcher seeds <strong>3 runnable official templates</strong> on first run—browse them online anytime:</span>
<br>
<a href="https://git.wto-project.net/Sh3ll_in_Sh3ll/WT-Offline/src/branch/main/mod-dev-docs/templates" target="_blank" rel="noopener">
<span class="lang-zh">查看官方模组模板源码 ↗</span>
<span class="lang-en">Official Mod Templates ↗</span>
</a>
</div>
</aside>
<div class="doc-body">
<article class="doc-section doc-chapter active" id="ch-01">
<div class="lang-zh">
<h2>01 · 快速入门与清单规范</h2>
<blockquote><p><strong>适用版本</strong>:<code>format: 1</code> · <code>api_version: &quot;0.1-experimental&quot;</code>(实验期接口,随本体开发可能调整)</p></blockquote>
<h3 id="ch-01-zh-1-核心思路-添加式叠加架构">1. 核心思路:添加式叠加架构</h3>
<p>WTOffline 采用<strong>添加式、按加载顺序逐层叠加</strong>的模组架构。模组通过增量补丁与新增文件作用于客户端与服务端,<strong>不支持直接整包替换原版 <code>.vromfs.bin</code> 归档文件</strong>:</p>
<ol><li>启动游戏前,启动器从纯净原版备份(<code>&lt;游戏副本&gt;/wtoffline/stock/</code>)出发,先应用离线版核心补丁,再按玩家在「模组」页排好的顺序,依次叠加所有已启用模组的客户端补丁与新增文件;</li><li>大体积 3D 模型和贴图包通过 <strong>Windows NTFS 目录联接点(Junction)</strong> 跨盘零拷贝挂载;</li><li>本地服务器启动时自动读取叠加后的客户端数据包,再按同一顺序合并各模组的 <code>server/tuning/*.jsonc</code> 并加载 <code>server/index.ts</code> 脚本;</li><li>关掉模组或切换预设时,启动器自动拆除联接点并从 <code>wtoffline/stock/</code> 还原原版文件,不破坏客户端本体。</li></ol>
<ul><li><strong>全局模组仓库</strong>:默认位于 <code>%APPDATA%\WTOffline Launcher\mods</code>(可在启动器「模组 › 预设与仓库」修改到任意硬盘)。</li><li><strong>首次启动自带 3 个官方模板</strong>:启动器首次初始化全局 <code>mods/</code> 目录时,会自动放入 <strong><code>example-vehicle-tweak</code></strong>(零代码改车与译名)、<strong><code>example-server-script</code></strong>(服务端 TS 脚本最小示例)和 <strong><code>official-map-selector</code></strong>(原生 DaGui 弹窗 + 服务端选图全栈模组)三个现成模组(默认未勾选)。点击「模组 › 打开模组目录」即可直接阅读源码或复制改造!</li><li><strong>每客户端独立配置</strong>:模组开关、加载顺序和命名预设分别保存在各自客户端的数据目录 <code>&lt;数据目录&gt;/mods-config.json</code> 中。</li></ul>
<hr>
<h3 id="ch-01-zh-2-前置准备-如何解包与查阅原版游戏数据">2. 前置准备:如何解包与查阅原版游戏数据</h3>
<p>在动手改载具属性、挂科技树或写界面补丁之前,你需要先知道原版游戏里的内部载具 ID(例如美系初始轻坦 M2A4 的内部 ID 是 <code>us_m2a4</code>,M1A2 SEP V2 是 <code>us_m1a2_sep2_abrams</code>)以及原版文件的目录结构。</p>
<h4 id="ch-01-zh-2-1-原版核心归档文件在哪里">2.1 原版核心归档文件在哪里?</h4>
<p>在你的《战争雷霆》客户端目录(以及离线副本目录)下,核心数据存放在以下 <code>.vromfs.bin</code> 虚拟文件系统包中:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>原版包路径(相对于客户端根目录)</th><th>里面的核心内容</th></tr></thead><tbody><tr><td><code>char.vromfs.bin</code></td><td>科技树排布(<code>config/shop.blk</code>)、载具价格/研发点/权重/改装件(<code>config/wpcost.blk</code>)、载具分类标签(<code>config/unittags.blk</code>)、道具与解锁配置</td></tr><tr><td><code>aces.vromfs.bin</code></td><td>坦克模型与装甲参数(<code>gamedata/units/tankmodels/*.blk</code>)、飞机气动(<code>gamedata/flightmodels/*.blk</code>)、舰船、炮弹与导弹参数(<code>gamedata/weapons/...</code>)</td></tr><tr><td><code>gui.vromfs.bin</code></td><td>客户端全部界面逻辑脚本(<code>scripts/**/*.nut</code>)、界面模板(<code>gui/**/*.tpl</code>)与样式表(<code>gui/**/*.css</code>)</td></tr><tr><td><code>lang.vromfs.bin</code></td><td>多语言本地化词条表(<code>lang/units.csv</code> 载具名、<code>lang/menu.csv</code> 界面文本、<code>lang/units_weaponry.csv</code> 武器弹药名)</td></tr><tr><td><code>ui/atlases.vromfs.bin</code></td><td>科技树与商店使用的载具剪影图标(<code>gameuiskin/&lt;载具id&gt;_ico.svg</code>)</td></tr><tr><td><code>ui/images.vromfs.bin</code></td><td>资料卡与乘员槽位载具大图(<code>units/&lt;载具id&gt;.ddsx</code>)</td></tr></tbody></table></div>
<blockquote><p><strong>备份目录说明</strong>:<code>&lt;游戏副本&gt;/wtoffline/stock/</code> 是启动器用来重建和还原纯净客户端的原版备份目录,请按只读方式对待,不要手动修改或覆盖其中的文件,以免影响关闭模组后的自动还原。所有模组改动都放在 <code>mods/&lt;你的模组&gt;/</code> 下即可。</p></blockquote>
<h4 id="ch-01-zh-2-2-查阅与解包原版数据的方法">2.2 查阅与解包原版数据的方法</h4>
<p>你可以根据自己的习惯,直接从本机原版客户端查阅 <code>.blk</code>、<code>.csv</code> 和 <code>.nut</code> 文件:</p>
<ol><li><strong>使用社区解包工具在本地查阅</strong>: 将客户端里的 <code>char.vromfs.bin</code>、<code>aces.vromfs.bin</code>、<code>gui.vromfs.bin</code> 等归档复制到单独的临时工作文件夹(不要在游戏目录原地解包),使用常见的 <code>.vromfs.bin</code> / <code>.blk</code> 社区解包工具提取目录并将二进制 <code>.blk</code> 转为可读文本,即可查找任意载具的内部 ID、科技树路径和字段名。</li><li><strong>用 WTOffline 仓库自带库直接读取(适合拉取了源码仓库的开发者)</strong>: 如果你在本地克隆了 WTOffline 仓库,可以直接在仓库根目录用 Node 24 调用内置的 <code>@wto/vromfs</code> 与 <code>@wto/blk</code> 读取任意原版包内的二进制 <code>.blk</code> 并打印为标准文本 BLK:</li></ol>
<div class="doc-pre"><div class="doc-pre-head"><span>js</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>import { readFileSync } from 'node:fs';
import { getFile, NAME_MAP_PATH, readArchive } from './packages/vromfs/src/index.ts';
import { decodeBlk, formatBlkText, parseSharedNameMap } from './packages/blk/src/index.ts';
const ar = readArchive(readFileSync('C:/WarThunder/char.vromfs.bin'));
const dict = [...ar.files.entries()].find(([k]) =&gt; k.endsWith('.dict'))?.[1];
console.log(formatBlkText(decodeBlk(getFile(ar, 'config/wpcost.blk'), { names: ar.files.has(NAME_MAP_PATH) ? parseSharedNameMap(getFile(ar, NAME_MAP_PATH), dict).names : [], dictionary: dict })));</code></pre></div>
<hr>
<h3 id="ch-01-zh-3-5-分钟做出你的第一个模组">3. 5 分钟做出你的第一个模组</h3>
<ol><li>在启动器里打开 <strong>「模组 › 打开模组目录」</strong>(你会看到里面已经有 3 个官方示例模组可供参考);</li><li>在里面新建文件夹 <code>my-first-mod</code>;</li><li>创建清单文件 <code>my-first-mod/mod.jsonc</code>:</li></ol>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;format&quot;: 1,
&quot;id&quot;: &quot;demo.my-first-mod&quot;,
&quot;name&quot;: {
&quot;zh-CN&quot;: &quot;我的第一个模组&quot;,
&quot;en&quot;: &quot;My First Mod&quot;
},
&quot;version&quot;: &quot;0.1.0&quot;,
&quot;author&quot;: &quot;YourName&quot;,
&quot;description&quot;: {
&quot;zh-CN&quot;: &quot;把对局银狮和研发点倍率调整为 2 倍。&quot;,
&quot;en&quot;: &quot;Doubles Silver Lions and Research Points battle rewards.&quot;
},
&quot;api_version&quot;: &quot;0.1-experimental&quot;,
&quot;game_versions&quot;: [&quot;2.61.0.*&quot;]
}</code></pre></div>
<ol start="4"><li>创建 <code>my-first-mod/server/tuning/battle.jsonc</code>:</li></ol>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;rewardMultiplierSilverLions&quot;: 2.0,
&quot;rewardMultiplierResearchPoints&quot;: 2.0
}</code></pre></div>
<ol start="5"><li>切回启动器窗口(页面获得焦点时会自动刷新,也可点击「刷新」),勾选启用你的模组并点击「启动游戏」即可生效。</li></ol>
<hr>
<h3 id="ch-01-zh-4-完整标准目录结构">4. 完整标准目录结构</h3>
<p>按需创建你实际用到的子目录,未用到的部分完全不必建立:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>&lt;mod-folder&gt;/
├─ mod.jsonc # 必需:模组清单
├─ server/ # 可选:服务端部分
│ ├─ tuning/ # 可调数值增量覆盖(*.jsonc)
│ └─ index.ts (或 index.mjs / .js) # 服务端脚本入口(默认自动探测)
└─ client/ # 可选:客户端部分
├─ packs/ # .vromfs.bin 数据包增量叠加
│ ├─ char.vromfs.bin/
│ ├─ aces.vromfs.bin/
│ ├─ gui.vromfs.bin/
│ ├─ lang.vromfs.bin/
│ ├─ mis.vromfs.bin/
│ ├─ game.vromfs.bin/
│ ├─ ui/atlases.vromfs.bin/
│ └─ ui/images.vromfs.bin/
├─ addon/ # 3D 模型与贴图扩展包(res/*.grp, res/*.dxp.bin)
├─ gui-patches/ # GUI 脚本/模板/样式增量补丁(与本体 patches/gui 同格式)
├─ exe-patches/ # 声明式 exe 补丁(与本体 patches/exe 同格式)
├─ files/ # 可选:大型整合包附带的配套涂装/瞄具/音效/任务
└─ config-blk.patch.jsonc # 可选:游戏根目录 config.blk 的增量补丁</code></pre></div>
<hr>
<h3 id="ch-01-zh-5-mod-jsonc-全字段参考">5. <code>mod.jsonc</code> 全字段参考</h3>
<p>清单元数据解析采用<strong>严格白名单校验</strong>,写错字段名或出现未定义字段会被直接拒绝,并在启动器报错区显示具体原因。</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>字段</th><th>必填</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>format</code></td><td>是</td><td><code>1</code></td><td>清单格式版本号,目前固定为整数 <code>1</code></td></tr><tr><td><code>id</code></td><td>是</td><td><code>string</code></td><td>全局唯一模组 ID,匹配 <code>/^[a-z0-9][a-z0-9._-]{0,63}$/</code>(仅小写字母、数字、<code>.</code>、<code>_</code>、<code>-</code>,首字符须为字母或数字,最长 64 位;推荐 <code>&lt;作者&gt;.&lt;模组名&gt;</code>)</td></tr><tr><td><code>name</code></td><td>是</td><td><code>string | { [lang]: string }</code></td><td>展示名称,支持单字符串或按语言代码映射(如 <code>zh-CN</code>、<code>en</code>)</td></tr><tr><td><code>version</code></td><td>是</td><td><code>string</code></td><td>模组版本号(推荐语义化版本,如 <code>0.1.0</code>)</td></tr><tr><td><code>author</code></td><td>是</td><td><code>string</code></td><td>作者或制作组名称</td></tr><tr><td><code>description</code></td><td>否</td><td><code>string | { [lang]: string }</code></td><td>模组简介,支持单字符串或多语言对象</td></tr><tr><td><code>api_version</code></td><td>是</td><td><code>string</code></td><td>目标接口标识,当前固定填 <code>&quot;0.1-experimental&quot;</code></td></tr><tr><td><code>game_versions</code></td><td>否</td><td><code>string[]</code></td><td>声明适配的游戏版本通配符列表(如 <code>[&quot;2.61.0.*&quot;]</code>);与客户端版本不符时仅发出警告,不强行阻断启动</td></tr><tr><td><code>requires</code></td><td>否</td><td><code>string[]</code></td><td>前置依赖模组 ID 列表:缺失或未启用时作为<strong>阻塞错误</strong>阻止启动;同时约束加载顺序(若排在前置模组上方会触发 <code>dependency-order</code> 顺序警告,并参与启动器「按依赖自动排序」)</td></tr><tr><td><code>conflicts</code></td><td>否</td><td><code>string[]</code></td><td>已知互斥模组 ID 列表;同时启用时作为<strong>阻塞错误</strong>阻止启动</td></tr><tr><td><code>load_after</code></td><td>否</td><td><code>string[]</code></td><td>建议排在这些可选模组 ID 之后(越靠下越晚加载、优先级越高);不强制要求对方启用,若同时启用则参与顺序提示与「按依赖自动排序」</td></tr><tr><td><code>load_before</code></td><td>否</td><td><code>string[]</code></td><td>建议排在这些可选模组 ID 之前;同样参与顺序提示与「按依赖自动排序」</td></tr><tr><td><code>server</code></td><td>否</td><td><code>{ entry?: string, tuning?: string }</code></td><td>显式覆盖服务端入口文件(相对路径,不得含 <code>..</code>)和 <code>tuning</code> 目录路径(默认自动探测 <code>server/index.{ts,mjs,js}</code> 与 <code>server/tuning</code>)</td></tr></tbody></table></div>
<hr>
<h3 id="ch-01-zh-6-启动器自动计算的能力与风险徽标-多徽标叠加">6. 启动器自动计算的能力与风险徽标(多徽标叠加)</h3>
<p>启动器扫描模组目录后会自动计算并展示能力徽标。<strong>徽标是多选累加(非互斥)的</strong>——例如同时包含数据包修改与服务端脚本的模组会同时显示 <code>data</code> 和 <code>script</code> 两个徽标,而 <code>official-map-selector</code> 会同时显示 <code>data</code>、<code>gui</code>、<code>script</code> 三个徽标:</p>
<ul><li><strong>数据/资源(<code>data</code>)</strong>:包含 <code>server/tuning/</code>、<code>client/packs/</code>、<code>client/addon/</code>、<code>client/files/</code> 或 <code>client/config-blk.patch.jsonc</code>(若模组仅含清单且无 <code>gui</code>/<code>script</code>/<code>exe</code>,也默认归类显示 <code>data</code>);</li><li><strong>界面补丁(<code>gui</code>)</strong>:包含 <code>client/gui-patches/</code>;</li><li><strong>服务端脚本(<code>script</code>)</strong>:包含可执行服务端 JS/TS 入口脚本;</li><li><strong>二进制补丁(<code>exe</code>)</strong>:包含 <code>client/exe-patches/</code>(高风险,且受离线核心隔离补丁锁保护)。</li></ul>
<hr>
<h3 id="ch-01-zh-7-排序规则与冲突检测">7. 排序规则与冲突检测</h3>
<ul><li><strong>加载顺序与优先级</strong>:列表中<strong>从上到下依次加载;越靠下(序号越大)越晚加载、覆盖优先级越高</strong>;</li><li><strong>一键自动排序</strong>:启动器的「按依赖自动排序」会综合全部模组的 <code>requires</code>、<code>load_after</code> 与 <code>load_before</code> 进行拓扑排序;</li><li><strong>叠加合并</strong>(提示 <code>info</code>):两个模组对同一个 BLK / CSV / <code>tuning</code> 文件做增量补丁时,按顺序先后安全叠加;</li><li><strong>顺序与覆写警告</strong>(警告 <code>warning</code>):模组排在了 <code>requires</code> / <code>load_after</code> 目标之前、目标游戏版本不匹配、或后序模组用整文件替换了前序模组修改过的数据包文件/外置配套文件;</li><li><strong>阻塞错误</strong>(错误 <code>error</code>):缺少 <code>requires</code> 前置模组、前置模组未启用、或同时启用了声明 <code>conflicts</code> 互斥的模组时,启动器禁止启动并高亮提示处理。</li></ul>
</div>
<div class="lang-en">
<h2>01 · Quick Start &amp; Manifest Reference</h2>
<blockquote><p><strong>Target Spec</strong>: <code>format: 1</code> · <code>api_version: &quot;0.1-experimental&quot;</code> (experimental API; subject to breaking changes as core development progresses)</p></blockquote>
<h3 id="ch-01-en-1-core-concept-additive-overlay-architecture">1. Core Concept: Additive Overlay Architecture</h3>
<p>WTOffline uses a <strong>stackable, load-order additive</strong> mod architecture. Mods supply incremental patches and added files to the client and server, and <strong>do not replace whole stock <code>.vromfs.bin</code> archives</strong>:</p>
<ol><li>Before launching the game, the launcher starts from clean stock backups (<code>&lt;copy&gt;/wtoffline/stock/</code>), applies core offline patches first, and then layers every enabled mod's client patches and added files in the exact order shown on the <strong>Mods</strong> page;</li><li>Large 3D model and texture addons mount across drives with zero file copying via <strong>Windows NTFS Directory Junctions</strong>;</li><li>When the local server starts, it automatically extracts static game data from the overlaid client packs, merges each mod's <code>server/tuning/*.jsonc</code> in the same order, and loads <code>server/index.ts</code> scripts;</li><li>When you disable a mod or switch presets, the launcher automatically unmounts junctions and restores clean files from <code>wtoffline/stock/</code> without corrupting the client copy.</li></ol>
<ul><li><strong>Global mod repository</strong>: defaults to <code>%APPDATA%\WTOffline Launcher\mods</code> (configurable to any drive under <strong>Mods › Presets &amp; repository</strong>).</li><li><strong>3 official templates seeded on first launch</strong>: the first time the launcher initializes the global <code>mods/</code> folder, it automatically seeds <strong><code>example-vehicle-tweak</code></strong> (code-free vehicle &amp; localization tweak), <strong><code>example-server-script</code></strong> (minimal server TypeScript mod), and <strong><code>official-map-selector</code></strong> (full-stack native DaGui modal + server map filter), all disabled by default. Click <strong>Mods › Open mods folder</strong> right away to inspect their code or duplicate one as a starting point!</li><li><strong>Per-client configuration</strong>: mod toggles, load order, and named presets are saved independently per client in <code>&lt;dataFolder&gt;/mods-config.json</code>.</li></ul>
<hr>
<h3 id="ch-01-en-2-prerequisite-how-to-unpack-inspect-stock-game-files">2. Prerequisite: How to Unpack &amp; Inspect Stock Game Files</h3>
<p>Before tweaking vehicle stats, wiring tech-tree entries, or patching UI scripts, you need to look up stock internal vehicle IDs (for example, the US reserve light tank M2A4 is <code>us_m2a4</code>, and the M1A2 SEP V2 is <code>us_m1a2_sep2_abrams</code>) and stock file paths.</p>
<h4 id="ch-01-en-2-1-where-stock-archives-live-in-the-game-client">2.1 Where Stock Archives Live in the Game Client</h4>
<p>Inside your War Thunder client folder (and offline copy folder), stock game data lives inside <code>.vromfs.bin</code> virtual filesystem archives:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>Stock Archive Path (relative to client root)</th><th>Key Contents Inside</th></tr></thead><tbody><tr><td><code>char.vromfs.bin</code></td><td>Tech-tree layout (<code>config/shop.blk</code>), vehicle prices/RP/BR/modifications (<code>config/wpcost.blk</code>), unit classification tags (<code>config/unittags.blk</code>), items, and unlocks</td></tr><tr><td><code>aces.vromfs.bin</code></td><td>Tank models &amp; armor (<code>gamedata/units/tankmodels/*.blk</code>), aircraft flight models (<code>gamedata/flightmodels/*.blk</code>), ships, shells, and missiles (<code>gamedata/weapons/...</code>)</td></tr><tr><td><code>gui.vromfs.bin</code></td><td>All client UI Quirrel scripts (<code>scripts/**/*.nut</code>), Handyman templates (<code>gui/**/*.tpl</code>), and DaGui stylesheets (<code>gui/**/*.css</code>)</td></tr><tr><td><code>lang.vromfs.bin</code></td><td>Localization tables (<code>lang/units.csv</code> vehicle names, <code>lang/menu.csv</code> UI strings, <code>lang/units_weaponry.csv</code> weapons &amp; ammo names)</td></tr><tr><td><code>ui/atlases.vromfs.bin</code></td><td>Tech-tree and local web store vehicle silhouette icons (<code>gameuiskin/&lt;unit_id&gt;_ico.svg</code>)</td></tr><tr><td><code>ui/images.vromfs.bin</code></td><td>Stat-card and crew-slot vehicle portraits (<code>units/&lt;unit_id&gt;.ddsx</code>)</td></tr></tbody></table></div>
<blockquote><p><strong>Note on the backup folder</strong>: Treat <code>&lt;copy&gt;/wtoffline/stock/</code> as read-only. The launcher relies on <code>wtoffline/stock/</code> to rebuild overlays and restore clean files when mods are disabled; modifying files inside <code>stock/</code> can prevent automatic restoration. Place all mod changes under <code>mods/&lt;your-mod&gt;/</code>.</p></blockquote>
<h4 id="ch-01-en-2-2-practical-ways-to-inspect-stock-files">2.2 Practical Ways to Inspect Stock Files</h4>
<p>You can inspect stock <code>.blk</code>, <code>.csv</code>, and <code>.nut</code> files directly from your own local game installation:</p>
<ol><li><strong>Local unpacking with community tools</strong>: Copy <code>char.vromfs.bin</code>, <code>aces.vromfs.bin</code>, or <code>gui.vromfs.bin</code> from your client into a separate scratch folder (avoid unpacking in-place inside the game directory) and use standard community <code>.vromfs.bin</code> / <code>.blk</code> unpacking tools to extract readable text <code>.blk</code> and <code>.nut</code> files, vehicle IDs, and tech-tree paths.</li><li><strong>5-line Node 24 snippet using <code>@wto/vromfs</code> + <code>@wto/blk</code> (if you cloned the WTOffline repo)</strong>: If you have the WTOffline repository checked out locally, run Node 24 from the repo root to decode any binary <code>.blk</code> straight out of a <code>.vromfs.bin</code> archive and print formatted text BLK:</li></ol>
<div class="doc-pre"><div class="doc-pre-head"><span>js</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>import { readFileSync } from 'node:fs';
import { getFile, NAME_MAP_PATH, readArchive } from './packages/vromfs/src/index.ts';
import { decodeBlk, formatBlkText, parseSharedNameMap } from './packages/blk/src/index.ts';
const ar = readArchive(readFileSync('C:/WarThunder/char.vromfs.bin'));
const dict = [...ar.files.entries()].find(([k]) =&gt; k.endsWith('.dict'))?.[1];
console.log(formatBlkText(decodeBlk(getFile(ar, 'config/wpcost.blk'), { names: ar.files.has(NAME_MAP_PATH) ? parseSharedNameMap(getFile(ar, NAME_MAP_PATH), dict).names : [], dictionary: dict })));</code></pre></div>
<hr>
<h3 id="ch-01-en-3-build-your-first-mod-in-5-minutes">3. Build Your First Mod in 5 Minutes</h3>
<ol><li>Open <strong>Mods › Open mods folder</strong> in the launcher (you will already see the 3 official template folders inside for reference);</li><li>Create a new folder named <code>my-first-mod</code>;</li><li>Create the manifest file <code>my-first-mod/mod.jsonc</code>:</li></ol>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;format&quot;: 1,
&quot;id&quot;: &quot;demo.my-first-mod&quot;,
&quot;name&quot;: {
&quot;zh-CN&quot;: &quot;我的第一个模组&quot;,
&quot;en&quot;: &quot;My First Mod&quot;
},
&quot;version&quot;: &quot;0.1.0&quot;,
&quot;author&quot;: &quot;YourName&quot;,
&quot;description&quot;: {
&quot;zh-CN&quot;: &quot;把对局银狮和研发点倍率调整为 2 倍。&quot;,
&quot;en&quot;: &quot;Doubles Silver Lions and Research Points battle rewards.&quot;
},
&quot;api_version&quot;: &quot;0.1-experimental&quot;,
&quot;game_versions&quot;: [&quot;2.61.0.*&quot;]
}</code></pre></div>
<ol start="4"><li>Create <code>my-first-mod/server/tuning/battle.jsonc</code>:</li></ol>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;rewardMultiplierSilverLions&quot;: 2.0,
&quot;rewardMultiplierResearchPoints&quot;: 2.0
}</code></pre></div>
<ol start="5"><li>Switch back to the launcher window (the Mods page refreshes automatically on focus, or click <strong>Refresh</strong>), enable your mod, and click <strong>Launch</strong>.</li></ol>
<hr>
<h3 id="ch-01-en-4-complete-standard-folder-layout">4. Complete Standard Folder Layout</h3>
<p>Create only the subdirectories your mod actually uses—unused folders can be omitted completely:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>&lt;mod-folder&gt;/
├─ mod.jsonc # Required: mod manifest
├─ server/ # Optional: server-side extensions
│ ├─ tuning/ # incremental tuning overlays (*.jsonc)
│ └─ index.ts (or index.mjs / .js) # server script entry (auto-detected by default)
└─ client/ # Optional: client-side extensions
├─ packs/ # .vromfs.bin archive overlays
│ ├─ char.vromfs.bin/
│ ├─ aces.vromfs.bin/
│ ├─ gui.vromfs.bin/
│ ├─ lang.vromfs.bin/
│ ├─ mis.vromfs.bin/
│ ├─ game.vromfs.bin/
│ ├─ ui/atlases.vromfs.bin/
│ └─ ui/images.vromfs.bin/
├─ addon/ # 3D model &amp; texture addon (res/*.grp, res/*.dxp.bin)
├─ gui-patches/ # incremental GUI script/tpl/css patches (same format as patches/gui)
├─ exe-patches/ # declarative exe patches (same format as patches/exe)
├─ files/ # optional companion skins/sights/sounds/missions
└─ config-blk.patch.jsonc # optional root config.blk incremental patch</code></pre></div>
<hr>
<h3 id="ch-01-en-5-full-mod-jsonc-schema-reference">5. Full <code>mod.jsonc</code> Schema Reference</h3>
<p>Manifest parsing enforces <strong>strict whitelist validation</strong>: typos or unknown keys are rejected immediately with a detailed error message on the Launcher Mods page.</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>Field</th><th>Required</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>format</code></td><td>Yes</td><td><code>1</code></td><td>Manifest schema version, currently fixed to integer <code>1</code></td></tr><tr><td><code>id</code></td><td>Yes</td><td><code>string</code></td><td>Globally unique mod ID matching <code>/^[a-z0-9][a-z0-9._-]{0,63}$/</code> (lowercase letters, digits, <code>.</code>, <code>_</code>, <code>-</code>; must start with letter/digit; max 64 chars; <code>&lt;author&gt;.&lt;mod-name&gt;</code> recommended)</td></tr><tr><td><code>name</code></td><td>Yes</td><td><code>string | { [lang]: string }</code></td><td>Display name as a plain string or locale map (e.g. <code>zh-CN</code>, <code>en</code>)</td></tr><tr><td><code>version</code></td><td>Yes</td><td><code>string</code></td><td>Mod version string (SemVer such as <code>0.1.0</code> recommended)</td></tr><tr><td><code>author</code></td><td>Yes</td><td><code>string</code></td><td>Author or team name</td></tr><tr><td><code>description</code></td><td>No</td><td><code>string | { [lang]: string }</code></td><td>Short summary as a plain string or locale map</td></tr><tr><td><code>api_version</code></td><td>Yes</td><td><code>string</code></td><td>Target API version tag, currently fixed to <code>&quot;0.1-experimental&quot;</code></td></tr><tr><td><code>game_versions</code></td><td>No</td><td><code>string[]</code></td><td>Supported game build wildcards (e.g. <code>[&quot;2.61.0.*&quot;]</code>); mismatches emit a warning without blocking launch</td></tr><tr><td><code>requires</code></td><td>No</td><td><code>string[]</code></td><td>Required dependency mod IDs: missing or disabled dependencies raise a <strong>blocking error</strong>; also enforces load order (emits a <code>dependency-order</code> warning if placed above its dependency and participates in <strong>Auto-Sort</strong>)</td></tr><tr><td><code>conflicts</code></td><td>No</td><td><code>string[]</code></td><td>Mutually incompatible mod IDs; enabling both raises a <strong>blocking error</strong></td></tr><tr><td><code>load_after</code></td><td>No</td><td><code>string[]</code></td><td>Optional mods this mod should load after (lower in the list = higher priority); does not require them to be enabled, and participates in order hints &amp; <strong>Auto-Sort</strong></td></tr><tr><td><code>load_before</code></td><td>No</td><td><code>string[]</code></td><td>Optional mods this mod should load before; also participates in order hints &amp; <strong>Auto-Sort</strong></td></tr><tr><td><code>server</code></td><td>No</td><td><code>{ entry?: string, tuning?: string }</code></td><td>Explicit relative paths (no <code>..</code>) overriding default auto-detection of <code>server/index.{ts,mjs,js}</code> and <code>server/tuning</code></td></tr></tbody></table></div>
<hr>
<h3 id="ch-01-en-6-automatically-computed-capability-risk-badges-additive-multi-badge">6. Automatically Computed Capability &amp; Risk Badges (Additive Multi-Badge)</h3>
<p>After scanning each mod folder, the launcher computes capability badges automatically. <strong>Badges are additive, not mutually exclusive</strong>—for example, a mod with pack overlays and a server script displays both <code>data</code> and <code>script</code>, while <code>official-map-selector</code> displays <code>data</code>, <code>gui</code>, and <code>script</code>:</p>
<ul><li><strong>Data / Assets (<code>data</code>)</strong>: contains <code>server/tuning/</code>, <code>client/packs/</code>, <code>client/addon/</code>, <code>client/files/</code>, or <code>client/config-blk.patch.jsonc</code> (a manifest-only mod with none of <code>gui</code>/<code>script</code>/<code>exe</code> also defaults to <code>data</code>);</li><li><strong>UI Patches (<code>gui</code>)</strong>: contains <code>client/gui-patches/</code>;</li><li><strong>Server Script (<code>script</code>)</strong>: contains an executable server JS/TS entry script;</li><li><strong>Binary Patches (<code>exe</code>)</strong>: contains <code>client/exe-patches/</code> (high-risk; guarded by the core offline isolation patch lock).</li></ul>
<hr>
<h3 id="ch-01-en-7-load-order-rules-conflict-detection">7. Load Order Rules &amp; Conflict Detection</h3>
<ul><li><strong>Load order &amp; priority</strong>: mods load <strong>top-to-bottom; items lower in the list (larger index) load later and take higher priority</strong>;</li><li><strong>One-click Auto-Sort</strong>: the launcher's <strong>Auto-sort by dependencies</strong> button topologically sorts mods using <code>requires</code>, <code>load_after</code>, and <code>load_before</code> together;</li><li><strong>Additive merge</strong> (<code>info</code>): when multiple mods patch the same BLK, CSV, or <code>tuning</code> file, their edits stack cleanly in load order;</li><li><strong>Order &amp; override warnings</strong> (<code>warning</code>): emitted when a mod sits above a <code>requires</code> / <code>load_after</code> target, mismatches <code>game_versions</code>, or replaces an entire pack/companion file already modified by an earlier mod;</li><li><strong>Blocking errors</strong> (<code>error</code>): missing <code>requires</code> dependencies, disabled dependencies, or simultaneously enabled <code>conflicts</code> prevent launch and highlight the exact items to fix.</li></ul>
</div>
<div class="doc-pager">
<a class="doc-pager-btn next" href="#ch-02" data-chapter="ch-02"><span class="doc-pager-label"><span class="lang-zh">下一章 →</span><span class="lang-en">Next →</span></span><span class="doc-pager-title"><span class="lang-zh">02 · 数据包与 BLK/CSV 补丁</span><span class="lang-en">02 · Client Packs &amp; BLK Patching</span></span></a>
</div>
</article>
<article class="doc-section doc-chapter" id="ch-02">
<div class="lang-zh">
<h2>02 · 客户端数据包与 BLK 增量补丁</h2>
<p>绝大多数《战争雷霆》数据模组(调整载具性能、炮弹穿深、导弹机动、科技树排布、银狮/研发点价格、分房权重、本地化译名、载具图标)都落在游戏的 <code>.vromfs.bin</code> 数据包中。本章讲解如何以<strong>完全可叠加、多模组互不顶掉</strong>的方式修改这些数据包,并在章末带你从零克隆出一辆能在美系科技树看到并直接试驾的独立新坦克。</p>
<hr>
<h3 id="ch-02-zh-1-先懂概念-什么是-blk-它为什么和-json-不一样">1. 先懂概念:什么是 BLK?它为什么和 JSON 不一样?</h3>
<p>Dagor 引擎使用自研的 <strong>BLK(DataBlock)</strong> 格式存储几乎所有游戏配置(在数据包内编译为紧凑二进制,解包后可读为文本 <code>.blk</code>)。初看很像 JSON,但它有三个关键差异:</p>
<ol><li><strong>每个参数都带显式静态类型后缀</strong>:例如 <code>:i</code>(32 位整数)、<code>:r</code>(单精度浮点)、<code>:t</code>(字符串)、<code>:b</code>(布尔 <code>yes</code>/<code>no</code>);把 <code>:r</code> 误写成 <code>:i</code> 会导致引擎读不到小数参数;</li><li><strong>同一个块内允许出现多个同名参数</strong>:例如 <code>slaveUnit:t=&quot;launcher_a&quot;</code> 下面紧跟第二行 <code>slaveUnit:t=&quot;launcher_b&quot;</code>(如果直接转成普通 JSON 对象,前一行就会被后一行覆盖丢失!);</li><li><strong>同一个父块下允许并列多个同名子块</strong>:最典型的就是科技树 <code>shop.blk</code>,每个陆军/空军分支下并列着好几个同名的 <code>range { ... }</code> 子块。</li></ol>
<p>对比下面这段 8 行原版文本 <code>.blk</code>(节选自 <code>wpcost.blk</code> 的 <code>us_m2a4</code>)与对应的 <code>.blk.patch.jsonc</code> 增量补丁,你立刻就能看懂两者的对应关系:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>blk</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// 原版可读文本 BLK(char.vromfs.bin -&gt; config/wpcost.blk 节选)
us_m2a4 {
value:i = 0
rank:i = 1
economicRankHistorical:i = 0
rewardMulHistorical:r = 0.1
country:t = &quot;country_usa&quot;
unitClass:t = &quot;exp_tank&quot;
}</code></pre></div>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// 对应的增量补丁:client/packs/char.vromfs.bin/config/wpcost.blk.patch.jsonc
// 只修改 us_m2a4 的历史模式收益倍率,不会影响其他模组对别的字段或载具的改动
{
&quot;ops&quot;: [
{
&quot;op&quot;: &quot;setParam&quot;,
&quot;path&quot;: [&quot;us_m2a4&quot;],
&quot;name&quot;: &quot;rewardMulHistorical&quot;,
&quot;value&quot;: { &quot;type&quot;: &quot;real&quot;, &quot;value&quot;: 1.2 }
}
]
}</code></pre></div>
<hr>
<h3 id="ch-02-zh-2-支持叠加的-8-个客户端数据包">2. 支持叠加的 8 个客户端数据包</h3>
<p>把文件按目标包路径放进 <code>client/packs/&lt;包路径&gt;/</code> 下即可:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>目标目录名</th><th>常见内容</th><th>备份方式</th></tr></thead><tbody><tr><td><code>client/packs/char.vromfs.bin/</code></td><td><code>config/shop.blk</code>(科技树)、<code>config/wpcost.blk</code>(经济/权重/改装件)、<code>config/unittags.blk</code>、<code>config/items.blk</code>、<code>config/modifications.blk</code></td><td>常驻备份</td></tr><tr><td><code>client/packs/aces.vromfs.bin/</code></td><td><code>gamedata/units/.../*.blk</code>(载具模型/DM/炮塔)、<code>gamedata/flightmodels/...</code>(气动)、<code>gamedata/weapons/...</code>(武器/炮弹/导弹)、<code>config/settings.blk</code></td><td>常驻备份</td></tr><tr><td><code>client/packs/gui.vromfs.bin/</code></td><td>新增独立 <code>.nut</code> 脚本、<code>.tpl</code> 模板、<code>.css</code> 样式(修改已有脚本/样式请看第 04 章 <code>gui-patches</code>)</td><td>常驻备份</td></tr><tr><td><code>client/packs/lang.vromfs.bin/</code></td><td><code>lang/units.csv</code>、<code>lang/menu.csv</code>、<code>lang/units_weaponry.csv</code> 等本地化表</td><td>按需自动备份,关闭还原</td></tr><tr><td><code>client/packs/mis.vromfs.bin/</code></td><td><code>gamedata/missions/.../*.blk</code> 联机/自定义任务</td><td>按需自动备份,关闭还原</td></tr><tr><td><code>client/packs/game.vromfs.bin/</code></td><td><code>danetlibs/...</code>、<code>game/...</code> 脚本与配置</td><td>按需自动备份,关闭还原</td></tr><tr><td><code>client/packs/ui/atlases.vromfs.bin/</code></td><td><code>gameuiskin/&lt;全小写载具id&gt;_ico.svg</code>(科技树与本地商城剪影图标)</td><td>按需自动备份,关闭还原</td></tr><tr><td><code>client/packs/ui/images.vromfs.bin/</code></td><td><code>units/&lt;载具id&gt;.ddsx</code> 或 <code>.png</code>(资料卡/乘员栏载具图)</td><td>按需自动备份,关闭还原</td></tr></tbody></table></div>
<blockquote><p><strong>自动联动服务端</strong>:本地服务器在启动时直接读取叠加后的 <code>.vromfs.bin</code>。因此你通过补丁往 <code>shop.blk</code> / <code>wpcost.blk</code> 新增或修改载具后,服务端会自动识别新车价格、前置科技树、研发点、改装件、分房权重、AI 机器人池与礼包 GUID,无需手工同步两遍。</p></blockquote>
<hr>
<h3 id="ch-02-zh-3-包内文件的-3-种处理模式-按后缀自动识别">3. 包内文件的 3 种处理模式(按后缀自动识别)</h3>
<p>构建器根据你在 <code>client/packs/&lt;包&gt;/</code> 下放置的文件名自动决定处理方式:</p>
<ol><li><strong><code>&lt;原路径&gt;.patch.jsonc</code> → BLK 结构化增量补丁</strong>:解析目标 <code>.blk</code> 为保留完整类型的内存树,按 <code>ops</code> 逐条修改后重新编码为自包含二进制 BLK 写回;</li><li><strong><code>&lt;原路径&gt;.patch.csv</code> → CSV 本地化增量合并</strong>:按第 1 列词条键合并进目标 <code>.csv</code>(已有键只更新你填写的语言列,新键追加到表尾);</li><li><strong>其余文件(如 <code>us_m2a4_mod_demo.blk</code>、<code>us_m2a4_mod_demo_ico.svg</code>)→ 新增或替换文件</strong>:
<ul><li>如果路径以 <code>.blk</code> 结尾且你的源文件是<strong>可读文本 BLK</strong>(如从原版客户端解包修改得到的),构建器会自动将其编译为游戏引擎所需的<strong>二进制 BLK</strong> 写进包内;</li><li>如果已经是二进制 BLK,或是 <code>.svg</code> / <code>.ddsx</code> / <code>.nut</code> / <code>.tpl</code> / <code>.css</code>,则原样写入包内。</li></ul></li></ol>
<hr>
<h3 id="ch-02-zh-4-blk-增量补丁-blk-patch-jsonc-完整手册">4. BLK 增量补丁(<code>*.blk.patch.jsonc</code>)完整手册</h3>
<h4 id="ch-02-zh-4-1-基本格式与路径寻址">4.1 基本格式与路径寻址</h4>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;ops&quot;: [
// 按顺序执行的操作列表
]
}</code></pre></div>
<ul><li><code>path</code> 是从 BLK 根节点出发的子块名数组,例如 <code>[&quot;country_usa&quot;, &quot;army&quot;, &quot;range[0]&quot;]</code>;</li><li>同名并列子块(如 <code>shop.blk</code> 里连续多个 <code>range</code> 块)可以用 <strong><code>名称[索引]</code></strong>(0 起始)精确定位;不写索引默认命中第 0 个同名子块;</li><li><code>[]</code> 表示当前文档根节点本身。</li></ul>
<h4 id="ch-02-zh-4-2-全部-7-种操作-op">4.2 全部 7 种操作(<code>op</code>)</h4>
<h5 id="ch-02-zh-①-setparam-设置参数-存在则覆盖并去重同名项-不存在则新增">① <code>setParam</code>:设置参数(存在则覆盖并去重同名项,不存在则新增)</h5>
<p>修改已有块上的单个字段时,<strong>永远优先用 <code>setParam</code></strong>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;op&quot;: &quot;setParam&quot;,
&quot;path&quot;: [&quot;us_m2a4&quot;],
&quot;name&quot;: &quot;rewardMulHistorical&quot;,
&quot;value&quot;: { &quot;type&quot;: &quot;real&quot;, &quot;value&quot;: 1.2 },
&quot;createBlocks&quot;: false // 可选,默认 false;设为 true 时自动补建缺失路径子块
}</code></pre></div>
<h5 id="ch-02-zh-②-addparam-追加同名参数-不删除已有同名项-适合-slaveunit-folder-aircraftgift-等可重复键">② <code>addParam</code>:追加同名参数(不删除已有同名项,适合 <code>slaveUnit</code>、<code>folder</code>、<code>aircraftGift</code> 等可重复键)</h5>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;op&quot;: &quot;addParam&quot;,
&quot;path&quot;: [&quot;country_usa&quot;, &quot;army&quot;, &quot;range[0]&quot;, &quot;us_m2a4&quot;],
&quot;name&quot;: &quot;slaveUnit&quot;,
&quot;value&quot;: &quot;my_extra_launcher&quot;
}</code></pre></div>
<h5 id="ch-02-zh-③-removeparam-删除参数-不填-value-删除全部同名参数-填-value-只删值匹配的项">③ <code>removeParam</code>:删除参数(不填 <code>value</code> 删除全部同名参数;填 <code>value</code> 只删值匹配的项)</h5>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;op&quot;: &quot;removeParam&quot;,
&quot;path&quot;: [&quot;us_m2a4&quot;],
&quot;name&quot;: &quot;showOnlyWhenBought&quot;
}</code></pre></div>
<h5 id="ch-02-zh-④-upsertblock-确保路径子块存在-并向其追加-params-与-blocks">④ <code>upsertBlock</code>:确保路径子块存在,并向其追加 <code>params</code> 与 <code>blocks</code></h5>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;op&quot;: &quot;upsertBlock&quot;,
&quot;path&quot;: [&quot;country_usa&quot;, &quot;army&quot;, &quot;range[0]&quot;, &quot;my_custom_tank&quot;],
&quot;block&quot;: {
&quot;params&quot;: [
{ &quot;name&quot;: &quot;rank&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 8 } },
{ &quot;name&quot;: &quot;reqAir&quot;, &quot;value&quot;: &quot;us_m1a2_sep2_abrams&quot; }
]
}
}</code></pre></div>
<blockquote><p><strong>重要行为说明(避免重复键踩坑)</strong>:如果目标路径的块<strong>原本不存在</strong>,<code>upsertBlock</code> 会自动创建它并写入 <code>block.params</code> 和 <code>block.blocks</code>;但如果目标块<strong>已经存在</strong>,<code>upsertBlock</code> 会把传入的 <code>params</code>(通过 <code>appendParam</code>)和 <code>blocks</code> <strong>直接追加到块末尾,而不会覆盖已有同名参数</strong>!因此:新建子块或有意追加多值字段时可用 <code>upsertBlock</code>;<strong>若要覆盖已有块上的某个参数值,请务必使用 <code>setParam</code></strong>。</p></blockquote>
<h5 id="ch-02-zh-⑤-addblock-在父块下新增一个子块-支持-before-after-指定锚点位置">⑤ <code>addBlock</code>:在父块下新增一个子块(支持 <code>before</code> / <code>after</code> 指定锚点位置)</h5>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;op&quot;: &quot;addBlock&quot;,
&quot;path&quot;: [&quot;country_usa&quot;, &quot;army&quot;, &quot;range[0]&quot;],
&quot;name&quot;: &quot;my_custom_tank&quot;,
&quot;after&quot;: &quot;us_m3a1_stuart&quot;,
&quot;block&quot;: {
&quot;params&quot;: [
{ &quot;name&quot;: &quot;rank&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 1 } },
{ &quot;name&quot;: &quot;reqAir&quot;, &quot;value&quot;: &quot;us_m2a4&quot; }
]
}
}</code></pre></div>
<h5 id="ch-02-zh-⑥-removeblock-删除指定路径的子块">⑥ <code>removeBlock</code>:删除指定路径的子块</h5>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;op&quot;: &quot;removeBlock&quot;,
&quot;path&quot;: [&quot;country_usa&quot;, &quot;army&quot;, &quot;range[0]&quot;, &quot;some_vehicle&quot;]
}</code></pre></div>
<h5 id="ch-02-zh-⑦-cloneblock-深拷贝同文档里的已有块为新名称并嵌套-ops-微调-衍生新车神器">⑦ <code>cloneBlock</code>:深拷贝同文档里的已有块为新名称并嵌套 <code>ops</code> 微调(衍生新车神器!)</h5>
<p>在 <code>wpcost.blk</code> 和 <code>unittags.blk</code> 里,一辆载具包含几十个维修/乘员/改装件/武器预设子块。用 <code>cloneBlock</code> 可以一键完整克隆原版原型车,再用嵌套 <code>ops</code> 只改差异字段:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;op&quot;: &quot;cloneBlock&quot;,
&quot;from&quot;: [&quot;us_m1a2_sep2_abrams&quot;],
&quot;toParent&quot;: [],
&quot;newName&quot;: &quot;us_m1a2_mod_example&quot;,
&quot;replaceExisting&quot;: true,
&quot;ops&quot;: [
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;value&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 10000 } },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;reqExp&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 50000 } },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;economicRankHistorical&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 34 } }
]
}</code></pre></div>
<blockquote><p>注意:<code>cloneBlock</code> 内部的嵌套 <code>ops</code> 是以<strong>刚克隆出来的新块为根节点</strong>运行的,所以修改新块自身顶层参数时 <code>path</code> 写 <code>[]</code>。</p></blockquote>
<h4 id="ch-02-zh-4-3-全部-13-种-blk-数据类型写法">4.3 全部 13 种 BLK 数据类型写法</h4>
<p>直接写 JSON 原始值时,构建器会优先沿用目标块已有同名字段的 BLK 类型(若无同名字段:字符串 → <code>string</code>,布尔 → <code>bool</code>,整数 → <code>int</code>,含小数 → <code>real</code>)。为确保万无一失(尤其是把浮点字段设为 <code>2.0</code> 时 JSON 解析为整数 <code>2</code>),推荐显式写成 <code>{ &quot;type&quot;: &quot;&lt;类型&gt;&quot;, &quot;value&quot;: &lt;值&gt; }</code>:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th><code>type</code></th><th>BLK 文本后缀</th><th><code>value</code> 示例与说明</th></tr></thead><tbody><tr><td><code>string</code></td><td><code>:t</code></td><td><code>&quot;us_m2a4&quot;</code></td></tr><tr><td><code>int</code></td><td><code>:i</code></td><td><code>120</code>(32 位有符号整数)</td></tr><tr><td><code>real</code></td><td><code>:r</code></td><td><code>1.5</code>(即使写 <code>2</code>,也会严格按 32 位浮点 <code>:r</code> 编码)</td></tr><tr><td><code>bool</code></td><td><code>:b</code></td><td><code>true</code> / <code>false</code>(对应文本 BLK 的 <code>yes</code> / <code>no</code>)</td></tr><tr><td><code>int64</code></td><td><code>:i64</code></td><td><code>&quot;133700000000000000&quot;</code> 或整数(64 位整数)</td></tr><tr><td><code>point2</code></td><td><code>:p2</code></td><td><code>[1.0, 2.5]</code>(2 个浮点数)</td></tr><tr><td><code>point3</code></td><td><code>:p3</code></td><td><code>[0.0, 1.5, -2.0]</code>(3 个浮点数)</td></tr><tr><td><code>point4</code></td><td><code>:p4</code></td><td><code>[0.0, 1.0, 0.0, 1.0]</code>(4 个浮点数)</td></tr><tr><td><code>ipoint2</code></td><td><code>:ip2</code></td><td><code>[10, 20]</code>(2 个整数)</td></tr><tr><td><code>ipoint3</code></td><td><code>:ip3</code></td><td><code>[1, 2, 3]</code>(3 个整数)</td></tr><tr><td><code>ipoint4</code></td><td><code>:ip4</code></td><td><code>[0, 1, 2, 3]</code>(4 个整数)</td></tr><tr><td><code>color</code></td><td><code>:c</code></td><td><code>[255, 128, 0, 255]</code>(<code>[r, g, b, a]</code>)或无符号打包整数 <code>0xAARRGGBB</code></td></tr><tr><td><code>matrix</code></td><td><code>:m</code></td><td>12 个浮点数的数组(4 行 × 3 列变换矩阵)</td></tr></tbody></table></div>
<hr>
<h3 id="ch-02-zh-5-分房权重-br-与内部-mrank-economicrank-换算表">5. 分房权重(BR)与内部 <code>mrank</code>(<code>economicRank*</code>)换算表</h3>
<p>新手打开 <code>wpcost.blk</code> 最常困惑的一点是:<strong>为什么里面找不到 <code>11.7</code> 或 <code>12.7</code> 这样的分房权重数字?</strong></p>
<p>在战雷内部,面板显示的 <strong>分房权重(Battle Rating, BR)</strong> 存储为从 <code>0</code> 开始的非负整数 <strong><code>mrank</code></strong>(字段名为 <code>economicRank*</code>),<strong>每 3 级整数对应 <code>1.0</code> 权重</strong>,小数位按 <code>.0</code> → <code>.3</code> → <code>.7</code> 循环:</p>
<ul><li><strong>正向换算公式(<code>mrank</code> → 面板 BR)</strong>:<code>BR = 1.0 + Math.floor(mrank / 3) + [0, 0.3, 0.7][mrank % 3]</code></li><li><strong>反向换算口诀(面板 BR → <code>mrank</code>)</strong>:<code>(整数部分 - 1) × 3</code>,再加小数档位(<code>.0</code> 加 <code>0</code>,<code>.3</code> 加 <code>1</code>,<code>.7</code> 加 <code>2</code>)。例如 <code>11.7</code> → <code>(11 - 1) × 3 + 2 = 32</code>!</li></ul>
<h4 id="ch-02-zh-5-1-完整-mrank-面板-br-速查表">5.1 完整 <code>mrank</code> ↔ 面板 BR 速查表</h4>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th><code>mrank</code></th><th>面板 BR</th><th><code>mrank</code></th><th>面板 BR</th><th><code>mrank</code></th><th>面板 BR</th><th><code>mrank</code></th><th>面板 BR</th></tr></thead><tbody><tr><td><code>0</code></td><td><strong>1.0</strong></td><td><code>10</code></td><td><strong>4.3</strong></td><td><code>20</code></td><td><strong>7.7</strong></td><td><code>30</code></td><td><strong>11.0</strong></td></tr><tr><td><code>1</code></td><td><strong>1.3</strong></td><td><code>11</code></td><td><strong>4.7</strong></td><td><code>21</code></td><td><strong>8.0</strong></td><td><code>31</code></td><td><strong>11.3</strong></td></tr><tr><td><code>2</code></td><td><strong>1.7</strong></td><td><code>12</code></td><td><strong>5.0</strong></td><td><code>22</code></td><td><strong>8.3</strong></td><td><code>32</code></td><td><strong>11.7</strong></td></tr><tr><td><code>3</code></td><td><strong>2.0</strong></td><td><code>13</code></td><td><strong>5.3</strong></td><td><code>23</code></td><td><strong>8.7</strong></td><td><code>33</code></td><td><strong>12.0</strong></td></tr><tr><td><code>4</code></td><td><strong>2.3</strong></td><td><code>14</code></td><td><strong>5.7</strong></td><td><code>24</code></td><td><strong>9.0</strong></td><td><code>34</code></td><td><strong>12.3</strong></td></tr><tr><td><code>5</code></td><td><strong>2.7</strong></td><td><code>15</code></td><td><strong>6.0</strong></td><td><code>25</code></td><td><strong>9.3</strong></td><td><code>35</code></td><td><strong>12.7</strong></td></tr><tr><td><code>6</code></td><td><strong>3.0</strong></td><td><code>16</code></td><td><strong>6.3</strong></td><td><code>26</code></td><td><strong>9.7</strong></td><td><code>36</code></td><td><strong>13.0</strong></td></tr><tr><td><code>7</code></td><td><strong>3.3</strong></td><td><code>17</code></td><td><strong>6.7</strong></td><td><code>27</code></td><td><strong>10.0</strong></td><td><code>37</code></td><td><strong>13.3</strong></td></tr><tr><td><code>8</code></td><td><strong>3.7</strong></td><td><code>18</code></td><td><strong>7.0</strong></td><td><code>28</code></td><td><strong>10.3</strong></td><td><code>38</code></td><td><strong>13.7</strong></td></tr><tr><td><code>9</code></td><td><strong>4.0</strong></td><td><code>19</code></td><td><strong>7.3</strong></td><td><code>29</code></td><td><strong>10.7</strong></td><td><code>39</code></td><td><strong>14.0</strong></td></tr></tbody></table></div>
<h4 id="ch-02-zh-5-2-wpcost-blk-模式后缀与科技树等级-rank-的区别">5.2 <code>wpcost.blk</code> 模式后缀与科技树等级 <code>rank</code> 的区别</h4>
<p>战雷沿用了远古内测时期的模式英文名,千万不要把<strong>科技树大等级 <code>rank</code></strong> 和<strong>分房权重 <code>economicRank*</code></strong> 搞混:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>字段名</th><th>取值范围</th><th>真实含义</th></tr></thead><tbody><tr><td><code>rank</code></td><td><code>1</code> .. <code>8</code></td><td><strong>科技树时代等级(Rank I – VIII)</strong>:决定它在科技树第几大行、受哪一级的开线数量门槛限制,以及默认套用哪一档商店礼包价格</td></tr><tr><td><code>economicRankArcade</code></td><td><code>0</code> .. <code>39+</code></td><td><strong>街机娱乐(AB, Arcade Battles)</strong> 的分房 <code>mrank</code></td></tr><tr><td><code>economicRankHistorical</code></td><td><code>0</code> .. <code>39+</code></td><td><strong>历史性能(RB, Realistic Battles)</strong> 的默认分房 <code>mrank</code>(战雷早期将历史模式称为 *Historical Battles*)</td></tr><tr><td><code>economicRankSimulation</code></td><td><code>0</code> .. <code>39+</code></td><td><strong>全真模拟(SB, Simulator Battles)</strong> 的默认分房 <code>mrank</code></td></tr><tr><td><code>economicRankTankHistorical</code></td><td><code>0</code> .. <code>39+</code></td><td>(可选)飞机/直升机进入<strong>陆战历史(Ground RB)</strong>时的独立对地分房权重;不填时沿用 <code>economicRankHistorical</code></td></tr><tr><td><code>economicRankTankSimulation</code></td><td><code>0</code> .. <code>39+</code></td><td>(可选)飞机/直升机进入<strong>陆战全真(Ground SB)</strong>时的独立分房权重</td></tr></tbody></table></div>
<hr>
<h3 id="ch-02-zh-6-shop-blk-科技树结构与-units-csv-四大词条后缀详解">6. <code>shop.blk</code> 科技树结构与 <code>units.csv</code> 四大词条后缀详解</h3>
<h4 id="ch-02-zh-6-1-config-shop-blk-的四层树状结构">6.1 <code>config/shop.blk</code> 的四层树状结构</h4>
<p>打开 <code>char.vromfs.bin</code> 里的 <code>config/shop.blk</code>,所有国家的科技树都遵循统一的四层结构:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>country_usa (或 country_germany / country_ussr / country_britain / country_japan / country_china / ...)
└─ army (陆军) | helicopters (直升机) | aviation (空军) | ships (远洋海军) | boats (近岸海军)
├─ range { ... } &lt;-- range[0]:科技树第 1 纵列(如美系轻坦线)
├─ range { ... } &lt;-- range[1]:科技树第 2 纵列(如美系中坦线,内部含折叠组 us_sherman_group)
├─ range { ... } &lt;-- range[2]..range[4]:其余常规银狮研发纵列
└─ range { ... } &lt;-- range[5]..range[6]:右侧金币车 / 礼包车 / 活动车 / 联队车独立纵列</code></pre></div>
<p>编写 <code>shop.blk.patch.jsonc</code> 时只需记住三条核心规则:</p>
<ol><li><strong>每个 <code>range</code> 就是科技树上的一条纵向列</strong>:因为它们都叫 <code>range</code>,在补丁 <code>path</code> 里用 <code>&quot;range[0]&quot;</code>、<code>&quot;range[1]&quot;</code>、<code>&quot;range[5]&quot;</code> 按从左到右(0 起始)定位;</li><li><strong>折叠文件夹(<code>*_group</code>)</strong>:当同一格折叠了多辆同系载具时,<code>range</code> 下会放一个以 <code>_group</code> 结尾的子块(例如 <code>us_sherman_group</code>),里面再嵌套各辆具体载具子块,折叠封面标题来自 <code>units.csv</code> 的 <code>shop/group/&lt;组名&gt;</code>;</li><li><strong>为什么坦克和军舰的前置研发箭头也叫 <code>reqAir</code>?</strong> 因为《战争雷霆》最早立项时是纯空战游戏(*World of Planes*),所有载具在底层代码里都沿用了 <code>air</code> / <code>aircraft</code> 命名,因此<strong>无论是坦克、直升机还是战列舰,指定“上一辆前置研发载具”的字段一律叫 <code>reqAir</code></strong>!
<ul><li>在 <code>wpcost.blk</code> 中设置 <code>reqAir:t=&quot;us_m2a4&quot;</code>:声明玩家必须先拥有 <code>us_m2a4</code> 才能研发本车;</li><li>在 <code>shop.blk</code> 的同一 <code>range</code> 列中:连续排列且未写 <code>reqAir</code> 的两辆车默认自动画纵向实线箭头;写 <code>reqAir:t=&quot;us_m2a4&quot;</code> 会显式从 <code>us_m2a4</code> 连出箭头;而写 <strong><code>reqAir:t=&quot;&quot;</code>(空字符串)则会显式断开与上方载具的箭头连接</strong>(科技树断线处以及右侧金币/礼包列里的车都用 <code>reqAir:t=&quot;&quot;</code>)。</li></ul></li></ol>
<h4 id="ch-02-zh-6-2-lang-units-csv-的-4-个载具译名后缀与-csv-增量合并">6.2 <code>lang/units.csv</code> 的 4 个载具译名后缀与 CSV 增量合并</h4>
<p>在 <code>client/packs/lang.vromfs.bin/lang/units.csv.patch.csv</code> 中为新载具添加译名时,每辆载具 <code>&lt;id&gt;</code> 共有 <strong>4 个标准词条键</strong>,分别对应不同界面与视距:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>词条键格式</th><th>游戏内显示位置</th><th>示例(以 <code>us_m2a4_mod_demo</code> 为例)</th></tr></thead><tbody><tr><td><code>&lt;id&gt;_shop</code></td><td><strong>科技树格子、底部乘员槽位、本地网页商店卡片</strong>上的简短名称</td><td><code>&quot;M2A4 (Mod Demo)&quot;</code> / <code>&quot;M2A4(教学改型)&quot;</code></td></tr><tr><td><code>&lt;id&gt;_0</code></td><td><strong>资料卡顶部标题、研发完成弹窗、战后结算详单</strong>里的完整正式全称</td><td><code>&quot;Light Tank M2A4 (Mod Demo)&quot;</code> / <code>&quot;M2A4 轻型坦克(教学改型)&quot;</code></td></tr><tr><td><code>&lt;id&gt;_1</code></td><td>战斗中<strong>中距离 3D 视野目标标记</strong>上显示的中等长度名称</td><td><code>&quot;M2A4 Demo&quot;</code> / <code>&quot;M2A4 教学型&quot;</code></td></tr><tr><td><code>&lt;id&gt;_2</code></td><td>战斗中<strong>远距离目标标记 / 极简击杀播报</strong>显示的超短型号或车种名</td><td><code>&quot;M2A4&quot;</code> / <code>&quot;M2A4&quot;</code></td></tr></tbody></table></div>
<p>CSV 补丁文件写法示例(<code>client/packs/lang.vromfs.bin/lang/units.csv.patch.csv</code>):</p>
<div class="doc-pre"><div class="doc-pre-head"><span>csv</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>&quot;&lt;ID|readonly|noverify&gt;&quot;;&quot;&lt;English&gt;&quot;;&quot;&lt;Chinese&gt;&quot;;&quot;&lt;HChinese&gt;&quot;
&quot;us_m2a4_mod_demo_shop&quot;;&quot;M2A4 (Mod Demo)&quot;;&quot;M2A4(教学改型)&quot;;&quot;M2A4(教學改型)&quot;
&quot;us_m2a4_mod_demo_0&quot;;&quot;Light Tank M2A4 (Mod Demo)&quot;;&quot;M2A4 轻型坦克(教学改型)&quot;;&quot;M2A4 輕型坦克(教學改型)&quot;
&quot;us_m2a4_mod_demo_1&quot;;&quot;M2A4 Demo&quot;;&quot;M2A4 教学型&quot;;&quot;M2A4 教學型&quot;
&quot;us_m2a4_mod_demo_2&quot;;&quot;M2A4&quot;;&quot;M2A4&quot;;&quot;M2A4&quot;</code></pre></div>
<ul><li>必须以分号 <code>;</code> 分隔并用双引号包裹每个字段,第 1 行写表头列名(只需列出你要填的语言列,未列出的语言列会自动保留原值或留空);</li><li>如果第 1 列 ID 在原表已存在,只更新你提供的非空语言列;不存在则自动追加到表尾。</li></ul>
<hr>
<h3 id="ch-02-zh-7-修改游戏根目录-config-blk-client-config-blk-patch-jsonc">7. 修改游戏根目录 <code>config.blk</code>(<code>client/config-blk.patch.jsonc</code>)</h3>
<p>如果模组需要调整游戏根目录的 <code>config.blk</code>(例如开启音效模组开关 <code>sound{ enable_mod:b=yes }</code> 或指定自定义机库 <code>hangarBlk:t=&quot;...&quot;</code>),放一份标准 BLK 补丁到 <code>client/config-blk.patch.jsonc</code> 即可:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;ops&quot;: [
{
&quot;op&quot;: &quot;setParam&quot;,
&quot;path&quot;: [&quot;sound&quot;],
&quot;name&quot;: &quot;enable_mod&quot;,
&quot;value&quot;: { &quot;type&quot;: &quot;bool&quot;, &quot;value&quot;: true },
&quot;createBlocks&quot;: true
}
]
}</code></pre></div>
<p>启动器会在首次修改前自动将原版 <code>config.blk</code> 备份到 <code>wtoffline/stock/config.blk</code>,关闭相关模组后自动还原。</p>
<hr>
<h3 id="ch-02-zh-8-端到端完整实战-5-分钟克隆一辆可试驾独立新坦克-usm2a4moddemo">8. 端到端完整实战:5 分钟克隆一辆可试驾独立新坦克(<code>us_m2a4_mod_demo</code>)</h3>
<p>下面我们把前面学到的知识串成一条完整闭环:复用原版美系初始轻坦 <code>us_m2a4</code> 的外观模型,衍生出一辆极速提升到 <code>90 km/h</code>、权重 <code>1.3</code>(<code>mrank = 1</code>)、挂在美系陆军 I 级科技树 <code>M2A4</code> 旁边的独立新载具 <strong><code>us_m2a4_mod_demo</code></strong>。由于每个存档天生拥有初始车 <code>us_m2a4</code>,你进游戏就能直接在美系陆军科技树看到它并点击「试驾」!</p>
<h4 id="ch-02-zh-8-1-模组目录结构">8.1 模组目录结构</h4>
<p>在全局 <code>mods/</code> 目录下新建 <code>demo-standalone-m2a4/</code>,结构如下:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>mods/demo-standalone-m2a4/
├─ mod.jsonc
└─ client/
└─ packs/
├─ aces.vromfs.bin/
│ └─ gamedata/units/tankmodels/
│ └─ us_m2a4_mod_demo.blk # ① 载具物理/装甲/武器定义(基于原版 us_m2a4.blk 修改)
├─ char.vromfs.bin/
│ └─ config/
│ ├─ wpcost.blk.patch.jsonc # ② 克隆经济、分房权重、改装件与弹药架
│ ├─ shop.blk.patch.jsonc # ③ 挂入美系陆军第 1 列 I 级科技树
│ └─ unittags.blk.patch.jsonc # ④ 克隆载具分类标签与试车场配置
└─ lang.vromfs.bin/
└─ lang/
└─ units.csv.patch.csv # ⑤ 注册 _shop / _0 / _1 / _2 中英文名称</code></pre></div>
<h4 id="ch-02-zh-8-2-各文件完整内容">8.2 各文件完整内容</h4>
<h5 id="ch-02-zh-清单-mod-jsonc">清单 <code>mod.jsonc</code></h5>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;format&quot;: 1,
&quot;id&quot;: &quot;demo.standalone-m2a4&quot;,
&quot;name&quot;: {
&quot;zh-CN&quot;: &quot;独立衍生载具示例:M2A4 教学改型&quot;,
&quot;en&quot;: &quot;Standalone Vehicle Demo: M2A4 Mod Demo&quot;
},
&quot;version&quot;: &quot;0.1.0&quot;,
&quot;author&quot;: &quot;YourName&quot;,
&quot;description&quot;: {
&quot;zh-CN&quot;: &quot;克隆原版 us_m2a4 新增一辆独立可研发、可试驾的 90km/h 高速轻坦。&quot;,
&quot;en&quot;: &quot;Clones stock us_m2a4 into a playable 90 km/h standalone tank in the US Rank I tree.&quot;
},
&quot;api_version&quot;: &quot;0.1-experimental&quot;,
&quot;game_versions&quot;: [&quot;2.61.0.*&quot;]
}</code></pre></div>
<h5 id="ch-02-zh-①-载具实体参数-client-packs-aces-vromfs-bin-gamedata-units-tankmodels-usm2a4moddemo-blk">① 载具实体参数 <code>client/packs/aces.vromfs.bin/gamedata/units/tankmodels/us_m2a4_mod_demo.blk</code></h5>
<p>按第 01 章第 2 节任一方式取出原版 <code>aces.vromfs.bin</code> 中的 <code>gamedata/units/tankmodels/us_m2a4.blk</code>(文本或二进制均可),另存为 <code>us_m2a4_mod_demo.blk</code>。保持顶部的 <code>model:t=&quot;m2a4&quot;</code> 不变(这样它会直接复用原版 M2A4 的 3D 模型和贴图),把里面的最大前进速度和加速改快即可(文本 <code>.blk</code> 在构建时会自动编译为二进制 <code>.blk</code>):</p>
<div class="doc-pre"><div class="doc-pre-head"><span>blk</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>model:t=&quot;m2a4&quot;
// ...(保留原版 us_m2a4.blk 其余内容不变,仅调高以下机动参数体验效果)...
maxFwdSpeed:r=90.0
maxRevSpeed:r=25.0
maxAccel:r=12.0</code></pre></div>
<h5 id="ch-02-zh-②-经济与权重补丁-client-packs-char-vromfs-bin-config-wpcost-blk-patch-jsonc">② 经济与权重补丁 <code>client/packs/char.vromfs.bin/config/wpcost.blk.patch.jsonc</code></h5>
<p>用 <code>cloneBlock</code> 一键复制 <code>us_m2a4</code>(自动继承全部武器、弹种、改装件与备用车配置),并把研发前提设为 <code>us_m2a4</code>、研发点设为 <code>1000</code>、银狮价格设为 <code>500</code>、三模式分房权重设为 <code>1</code>(即面板 <strong>1.3</strong>):</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;ops&quot;: [
{
&quot;op&quot;: &quot;cloneBlock&quot;,
&quot;from&quot;: [&quot;us_m2a4&quot;],
&quot;toParent&quot;: [],
&quot;newName&quot;: &quot;us_m2a4_mod_demo&quot;,
&quot;replaceExisting&quot;: true,
&quot;ops&quot;: [
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;reqAir&quot;, &quot;value&quot;: &quot;us_m2a4&quot; },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;reqExp&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 1000 } },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;value&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 500 } },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;economicRank&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 1 } },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;economicRankArcade&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 1 } },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;economicRankHistorical&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 1 } },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;economicRankSimulation&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 1 } }
]
}
]
}</code></pre></div>
<h5 id="ch-02-zh-③-科技树位置补丁-client-packs-char-vromfs-bin-config-shop-blk-patch-jsonc">③ 科技树位置补丁 <code>client/packs/char.vromfs.bin/config/shop.blk.patch.jsonc</code></h5>
<p>在 <code>country_usa -&gt; army -&gt; range[0]</code> 的 I 级段末尾(<code>us_m3a1_stuart</code> 之后、<code>us_m5a1_stuart</code> 断线之前)插入新车块,并显式声明 <code>reqAir: &quot;us_m2a4&quot;</code>,游戏就会在不打断原有斯图亚特研发线的前提下,从 <code>M2A4</code> 连出一条侧支研发箭头指向你的新车:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;ops&quot;: [
{
&quot;op&quot;: &quot;addBlock&quot;,
&quot;path&quot;: [&quot;country_usa&quot;, &quot;army&quot;, &quot;range[0]&quot;],
&quot;name&quot;: &quot;us_m2a4_mod_demo&quot;,
&quot;after&quot;: &quot;us_m3a1_stuart&quot;,
&quot;block&quot;: {
&quot;params&quot;: [
{ &quot;name&quot;: &quot;rank&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 1 } },
{ &quot;name&quot;: &quot;reqAir&quot;, &quot;value&quot;: &quot;us_m2a4&quot; }
]
}
}
]
}</code></pre></div>
<h5 id="ch-02-zh-④-载具标签与试驾场补丁-client-packs-char-vromfs-bin-config-unittags-blk-patch-jsonc">④ 载具标签与试驾场补丁 <code>client/packs/char.vromfs.bin/config/unittags.blk.patch.jsonc</code></h5>
<p>同样用 <code>cloneBlock</code> 从 <code>us_m2a4</code> 克隆出 <code>type:t=&quot;tank&quot;</code>、机库车位 <code>hangar_place:t=&quot;tank&quot;</code>、陆战试车场 <code>testFlight</code> 与轻坦标签:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;ops&quot;: [
{
&quot;op&quot;: &quot;cloneBlock&quot;,
&quot;from&quot;: [&quot;us_m2a4&quot;],
&quot;toParent&quot;: [],
&quot;newName&quot;: &quot;us_m2a4_mod_demo&quot;,
&quot;replaceExisting&quot;: true
}
]
}</code></pre></div>
<h5 id="ch-02-zh-⑤-多语言名称补丁-client-packs-lang-vromfs-bin-lang-units-csv-patch-csv">⑤ 多语言名称补丁 <code>client/packs/lang.vromfs.bin/lang/units.csv.patch.csv</code></h5>
<p>直接复用上面第 6.2 节的 4 行 CSV 内容即可。保存后在启动器勾选启用模组并启动游戏,切到美国陆军科技树 I 级,就能看到 <strong>M2A4(教学改型)</strong> 并立刻右键「试驾」体验 90 km/h 飙车!</p>
</div>
<div class="lang-en">
<h2>02 · Client Packs &amp; BLK Incremental Patching</h2>
<p>Most War Thunder data mods—tweaking vehicle performance, shell penetration, missile maneuverability, tech-tree layouts, Silver Lion / Research Point prices, Battle Ratings, localized names, and vehicle icons—live inside <code>.vromfs.bin</code> data packs. This chapter explains how to modify those packs in a <strong>100% stackable, conflict-free</strong> way, ending with a copy-pasteable walkthrough that clones a playable standalone tank into the US Rank I tech tree.</p>
<hr>
<h3 id="ch-02-en-1-plain-language-intro-what-is-blk-why-does-it-differ-from-json">1. Plain-Language Intro: What Is BLK &amp; Why Does It Differ from JSON?</h3>
<p>War Thunder's Dagor Engine stores nearly all game configurations in <strong>BLK (DataBlock)</strong> files—compiled to compact binary inside <code>.vromfs.bin</code> packs, and readable as plain text <code>.blk</code> when unpacked. While text BLK looks superficially similar to JSON, it differs in three fundamental ways:</p>
<ol><li><strong>Every parameter carries an explicit static type suffix</strong>: such as <code>:i</code> (32-bit integer), <code>:r</code> (32-bit float), <code>:t</code> (string), or <code>:b</code> (boolean <code>yes</code>/<code>no</code>). Writing <code>:i</code> where the engine expects <code>:r</code> causes the engine to ignore decimal values;</li><li><strong>Duplicate parameter names are allowed inside the same block</strong>: for instance, <code>slaveUnit:t=&quot;launcher_a&quot;</code> followed immediately by <code>slaveUnit:t=&quot;launcher_b&quot;</code> (converting naively to a plain JSON object would overwrite the first key!);</li><li><strong>Duplicate sibling block names are allowed under the same parent</strong>: most notably in <code>shop.blk</code>, where every army/aviation branch contains multiple sibling <code>range { ... }</code> blocks side by side.</li></ol>
<p>Compare this 8-line stock text <code>.blk</code> excerpt (<code>us_m2a4</code> in <code>wpcost.blk</code>) side by side with its <code>.blk.patch.jsonc</code> patch operation:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>blk</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// Stock readable text BLK (excerpt from char.vromfs.bin -&gt; config/wpcost.blk)
us_m2a4 {
value:i = 0
rank:i = 1
economicRankHistorical:i = 0
rewardMulHistorical:r = 0.1
country:t = &quot;country_usa&quot;
unitClass:t = &quot;exp_tank&quot;
}</code></pre></div>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// Matching incremental patch: client/packs/char.vromfs.bin/config/wpcost.blk.patch.jsonc
// Touches ONLY us_m2a4's Realistic reward multiplier without clobbering other fields or other mods!
{
&quot;ops&quot;: [
{
&quot;op&quot;: &quot;setParam&quot;,
&quot;path&quot;: [&quot;us_m2a4&quot;],
&quot;name&quot;: &quot;rewardMulHistorical&quot;,
&quot;value&quot;: { &quot;type&quot;: &quot;real&quot;, &quot;value&quot;: 1.2 }
}
]
}</code></pre></div>
<hr>
<h3 id="ch-02-en-2-the-8-overlayable-client-data-packs">2. The 8 Overlayable Client Data Packs</h3>
<p>Place your files under <code>client/packs/&lt;pack-path&gt;/</code> matching the target archive's internal path:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>Target Directory</th><th>Common Contents</th><th>Backup Strategy</th></tr></thead><tbody><tr><td><code>client/packs/char.vromfs.bin/</code></td><td><code>config/shop.blk</code> (tech tree), <code>config/wpcost.blk</code> (economy/BR/modifications), <code>config/unittags.blk</code>, <code>config/items.blk</code>, <code>config/modifications.blk</code></td><td>Always rebuilt from stock</td></tr><tr><td><code>client/packs/aces.vromfs.bin/</code></td><td><code>gamedata/units/.../*.blk</code> (vehicle models/DM/turrets), <code>gamedata/flightmodels/...</code> (FMs), <code>gamedata/weapons/...</code> (guns/shells/missiles), <code>config/settings.blk</code></td><td>Always rebuilt from stock</td></tr><tr><td><code>client/packs/gui.vromfs.bin/</code></td><td>New standalone <code>.nut</code> scripts, <code>.tpl</code> templates, <code>.css</code> stylesheets (to edit stock UI files, see Chapter 04 <code>gui-patches</code>)</td><td>Always rebuilt from stock</td></tr><tr><td><code>client/packs/lang.vromfs.bin/</code></td><td><code>lang/units.csv</code>, <code>lang/menu.csv</code>, <code>lang/units_weaponry.csv</code>, and other localization CSVs</td><td>Backed up on demand, restored on disable</td></tr><tr><td><code>client/packs/mis.vromfs.bin/</code></td><td><code>gamedata/missions/.../*.blk</code> multiplayer and custom missions</td><td>Backed up on demand, restored on disable</td></tr><tr><td><code>client/packs/game.vromfs.bin/</code></td><td><code>danetlibs/...</code>, <code>game/...</code> scripts and configs</td><td>Backed up on demand, restored on disable</td></tr><tr><td><code>client/packs/ui/atlases.vromfs.bin/</code></td><td><code>gameuiskin/&lt;lowercase_unit_id&gt;_ico.svg</code> (tech-tree &amp; local web store silhouette icons)</td><td>Backed up on demand, restored on disable</td></tr><tr><td><code>client/packs/ui/images.vromfs.bin/</code></td><td><code>units/&lt;unit_id&gt;.ddsx</code> or <code>.png</code> (stat-card / crew-slot vehicle images)</td><td>Backed up on demand, restored on disable</td></tr></tbody></table></div>
<blockquote><p><strong>Automatic Server Sync</strong>: The local server reads static datasets directly from the overlaid <code>.vromfs.bin</code> packs on startup. Any vehicle added or tweaked in <code>shop.blk</code> / <code>wpcost.blk</code> is automatically picked up for prices, tech-tree prerequisites, Research Points, modifications, Battle Ratings, AI bot pools, and store pack GUIDs—no duplicate server registration needed.</p></blockquote>
<hr>
<h3 id="ch-02-en-3-three-file-handling-modes-inside-packs-auto-detected-by-suffix">3. Three File Handling Modes Inside Packs (Auto-Detected by Suffix)</h3>
<p>The patcher determines how to process each file under <code>client/packs/&lt;pack&gt;/</code> by its filename suffix:</p>
<ol><li><strong><code>&lt;target-path&gt;.patch.jsonc</code> → Structured Incremental BLK Patch</strong>: decodes the target <code>.blk</code> into a type-preserving tree, applies <code>ops</code> in order, and re-encodes a self-contained binary BLK;</li><li><strong><code>&lt;target-path&gt;.patch.csv</code> → Incremental Localization CSV Merge</strong>: merges rows by column 0 (updating only the non-empty language columns you provide on existing keys, and appending new keys at the end);</li><li><strong>Any other file (e.g. <code>us_m2a4_mod_demo.blk</code>, <code>us_m2a4_mod_demo_ico.svg</code>) → Add or Replace File</strong>:
<ul><li>If the path ends with <code>.blk</code> and your source file is <strong>plain text BLK</strong> (for example, extracted and edited from your stock client), the builder automatically compiles it into <strong>binary BLK</strong> for the engine;</li><li>Binary <code>.blk</code> files and other assets (<code>.svg</code>, <code>.ddsx</code>, <code>.nut</code>, <code>.tpl</code>, <code>.css</code>) are written into the archive as-is.</li></ul></li></ol>
<hr>
<h3 id="ch-02-en-4-complete-blk-incremental-patch-blk-patch-jsonc-reference">4. Complete BLK Incremental Patch (<code>*.blk.patch.jsonc</code>) Reference</h3>
<h4 id="ch-02-en-4-1-document-format-path-addressing">4.1 Document Format &amp; Path Addressing</h4>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;ops&quot;: [
// Ordered list of patch operations
]
}</code></pre></div>
<ul><li><code>path</code> is an array of child block names starting from the BLK root, e.g. <code>[&quot;country_usa&quot;, &quot;army&quot;, &quot;range[0]&quot;]</code>;</li><li>Duplicate sibling blocks (such as consecutive <code>range</code> blocks in <code>shop.blk</code>) can be addressed precisely with <strong><code>name[index]</code></strong> (zero-based); omitting <code>[index]</code> selects occurrence <code>0</code>;</li><li><code>[]</code> refers to the root block of the current document.</li></ul>
<h4 id="ch-02-en-4-2-all-7-patch-operations-op">4.2 All 7 Patch Operations (<code>op</code>)</h4>
<h5 id="ch-02-en-①-setparam-set-a-parameter-overwrites-deduplicates-same-named-params-if-present-appends-if-absent">① <code>setParam</code>: Set a parameter (overwrites &amp; deduplicates same-named params if present; appends if absent)</h5>
<p>Always prefer <strong><code>setParam</code></strong> when updating a single parameter on an existing block:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;op&quot;: &quot;setParam&quot;,
&quot;path&quot;: [&quot;us_m2a4&quot;],
&quot;name&quot;: &quot;rewardMulHistorical&quot;,
&quot;value&quot;: { &quot;type&quot;: &quot;real&quot;, &quot;value&quot;: 1.2 },
&quot;createBlocks&quot;: false // Optional (default false); set true to auto-create missing blocks along path
}</code></pre></div>
<h5 id="ch-02-en-②-addparam-append-a-duplicate-named-parameter-preserves-existing-entries-ideal-for-slaveunit-folder-aircraftgift">② <code>addParam</code>: Append a duplicate-named parameter (preserves existing entries; ideal for <code>slaveUnit</code>, <code>folder</code>, <code>aircraftGift</code>)</h5>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;op&quot;: &quot;addParam&quot;,
&quot;path&quot;: [&quot;country_usa&quot;, &quot;army&quot;, &quot;range[0]&quot;, &quot;us_m2a4&quot;],
&quot;name&quot;: &quot;slaveUnit&quot;,
&quot;value&quot;: &quot;my_extra_launcher&quot;
}</code></pre></div>
<h5 id="ch-02-en-③-removeparam-delete-parameters-deletes-all-matching-name-when-value-is-omitted-or-only-entries-matching-value">③ <code>removeParam</code>: Delete parameters (deletes all matching <code>name</code> when <code>value</code> is omitted, or only entries matching <code>value</code>)</h5>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;op&quot;: &quot;removeParam&quot;,
&quot;path&quot;: [&quot;us_m2a4&quot;],
&quot;name&quot;: &quot;showOnlyWhenBought&quot;
}</code></pre></div>
<h5 id="ch-02-en-④-upsertblock-find-or-create-a-child-block-and-append-params-blocks">④ <code>upsertBlock</code>: Find or create a child block and append <code>params</code> &amp; <code>blocks</code></h5>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;op&quot;: &quot;upsertBlock&quot;,
&quot;path&quot;: [&quot;country_usa&quot;, &quot;army&quot;, &quot;range[0]&quot;, &quot;my_custom_tank&quot;],
&quot;block&quot;: {
&quot;params&quot;: [
{ &quot;name&quot;: &quot;rank&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 8 } },
{ &quot;name&quot;: &quot;reqAir&quot;, &quot;value&quot;: &quot;us_m1a2_sep2_abrams&quot; }
]
}
}</code></pre></div>
<blockquote><p><strong>Important Behavior Note (Avoid Duplicate Keys)</strong>: If the target block along <code>path</code> <strong>does not exist</strong>, <code>upsertBlock</code> creates it and populates <code>block.params</code> and <code>block.blocks</code>. However, if the target block <strong>already exists</strong>, <code>upsertBlock</code> <strong>appends</strong> every entry in <code>block.params</code> (via <code>appendParam</code>) and <code>block.blocks</code> to the end of the block <strong>without overwriting existing same-named parameters</strong>! Use <code>upsertBlock</code> to create new blocks or append multi-value params; <strong>to overwrite an existing parameter on an existing block, always use <code>setParam</code></strong>.</p></blockquote>
<h5 id="ch-02-en-⑤-addblock-insert-a-new-child-block-under-a-parent-supports-before-after-sibling-anchors">⑤ <code>addBlock</code>: Insert a new child block under a parent (supports <code>before</code> / <code>after</code> sibling anchors)</h5>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;op&quot;: &quot;addBlock&quot;,
&quot;path&quot;: [&quot;country_usa&quot;, &quot;army&quot;, &quot;range[0]&quot;],
&quot;name&quot;: &quot;my_custom_tank&quot;,
&quot;after&quot;: &quot;us_m3a1_stuart&quot;,
&quot;block&quot;: {
&quot;params&quot;: [
{ &quot;name&quot;: &quot;rank&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 1 } },
{ &quot;name&quot;: &quot;reqAir&quot;, &quot;value&quot;: &quot;us_m2a4&quot; }
]
}
}</code></pre></div>
<h5 id="ch-02-en-⑥-removeblock-delete-a-child-block-at-path">⑥ <code>removeBlock</code>: Delete a child block at <code>path</code></h5>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;op&quot;: &quot;removeBlock&quot;,
&quot;path&quot;: [&quot;country_usa&quot;, &quot;army&quot;, &quot;range[0]&quot;, &quot;some_vehicle&quot;]
}</code></pre></div>
<h5 id="ch-02-en-⑦-cloneblock-deep-clone-an-existing-block-in-the-same-file-under-newname-with-nested-ops-essential-for-derived-vehicles">⑦ <code>cloneBlock</code>: Deep-clone an existing block in the same file under <code>newName</code> with nested <code>ops</code> (essential for derived vehicles!)</h5>
<p>In <code>wpcost.blk</code> and <code>unittags.blk</code>, each vehicle block contains dozens of repair, crew, modification, and weapon-preset sub-blocks. <code>cloneBlock</code> copies a stock donor vehicle completely in one step and lets you tweak only the differences via nested <code>ops</code>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;op&quot;: &quot;cloneBlock&quot;,
&quot;from&quot;: [&quot;us_m1a2_sep2_abrams&quot;],
&quot;toParent&quot;: [],
&quot;newName&quot;: &quot;us_m1a2_mod_example&quot;,
&quot;replaceExisting&quot;: true,
&quot;ops&quot;: [
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;value&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 10000 } },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;reqExp&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 50000 } },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;economicRankHistorical&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 34 } }
]
}</code></pre></div>
<blockquote><p>Note: Nested <code>ops</code> inside <code>cloneBlock</code> run with <strong>the newly cloned block itself as the root</strong>, so use <code>&quot;path&quot;: []</code> when editing top-level fields on the cloned block.</p></blockquote>
<h4 id="ch-02-en-4-3-all-13-blk-data-types">4.3 All 13 BLK Data Types</h4>
<p>When you write a plain JSON primitive, the patcher infers the BLK type from any existing parameter of the same name on that block (falling back to <code>string</code>, <code>bool</code>, <code>int</code> for integers, or <code>real</code> for non-integers). To guarantee exact binary types—especially when setting a float parameter to a whole number like <code>2.0</code>, which JSON parses as integer <code>2</code>—write <code>{ &quot;type&quot;: &quot;&lt;type&gt;&quot;, &quot;value&quot;: &lt;val&gt; }</code>:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th><code>type</code></th><th>Text BLK Suffix</th><th><code>value</code> Example &amp; Notes</th></tr></thead><tbody><tr><td><code>string</code></td><td><code>:t</code></td><td><code>&quot;us_m2a4&quot;</code></td></tr><tr><td><code>int</code></td><td><code>:i</code></td><td><code>120</code> (signed 32-bit integer)</td></tr><tr><td><code>real</code></td><td><code>:r</code></td><td><code>1.5</code> (encoded strictly as 32-bit float <code>:r</code> even if written as <code>2</code>)</td></tr><tr><td><code>bool</code></td><td><code>:b</code></td><td><code>true</code> / <code>false</code> (<code>yes</code> / <code>no</code> in text BLK)</td></tr><tr><td><code>int64</code></td><td><code>:i64</code></td><td><code>&quot;133700000000000000&quot;</code> or integer (signed 64-bit integer)</td></tr><tr><td><code>point2</code></td><td><code>:p2</code></td><td><code>[1.0, 2.5]</code> (2 floats)</td></tr><tr><td><code>point3</code></td><td><code>:p3</code></td><td><code>[0.0, 1.5, -2.0]</code> (3 floats)</td></tr><tr><td><code>point4</code></td><td><code>:p4</code></td><td><code>[0.0, 1.0, 0.0, 1.0]</code> (4 floats)</td></tr><tr><td><code>ipoint2</code></td><td><code>:ip2</code></td><td><code>[10, 20]</code> (2 integers)</td></tr><tr><td><code>ipoint3</code></td><td><code>:ip3</code></td><td><code>[1, 2, 3]</code> (3 integers)</td></tr><tr><td><code>ipoint4</code></td><td><code>:ip4</code></td><td><code>[0, 1, 2, 3]</code> (4 integers)</td></tr><tr><td><code>color</code></td><td><code>:c</code></td><td><code>[255, 128, 0, 255]</code> (<code>[r, g, b, a]</code>) or unsigned packed integer <code>0xAARRGGBB</code></td></tr><tr><td><code>matrix</code></td><td><code>:m</code></td><td>Array of 12 floats (4×3 transform matrix)</td></tr></tbody></table></div>
<hr>
<h3 id="ch-02-en-5-battle-rating-br-internal-mrank-economicrank-conversion-lookup-table">5. Battle Rating (BR) ↔ Internal <code>mrank</code> (<code>economicRank*</code>) Conversion &amp; Lookup Table</h3>
<p>A classic question when opening <code>wpcost.blk</code> for the first time is: <strong>why are there no <code>11.7</code> or <code>12.7</code> Battle Rating numbers anywhere in the file?</strong></p>
<p>Internally, War Thunder stores displayed <strong>Battle Ratings (BR)</strong> as zero-based non-negative integers called <strong><code>mrank</code></strong> (stored in <code>economicRank*</code> fields), where <strong>every 3 integer steps equal <code>1.0</code> BR</strong> and fractional steps cycle <code>.0</code> → <code>.3</code> → <code>.7</code>:</p>
<ul><li><strong>Forward formula (<code>mrank</code> → displayed BR)</strong>: <code>BR = 1.0 + Math.floor(mrank / 3) + [0, 0.3, 0.7][mrank % 3]</code></li><li><strong>Reverse formula (displayed BR → <code>mrank</code>)</strong>: <code>(wholePart - 1) × 3</code> plus the decimal step (<code>+0</code> for <code>.0</code>, <code>+1</code> for <code>.3</code>, <code>+2</code> for <code>.7</code>). For example, <code>11.7</code> → <code>(11 - 1) × 3 + 2 = 32</code>!</li></ul>
<h4 id="ch-02-en-5-1-complete-mrank-displayed-br-lookup-table">5.1 Complete <code>mrank</code> ↔ Displayed BR Lookup Table</h4>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th><code>mrank</code></th><th>Displayed BR</th><th><code>mrank</code></th><th>Displayed BR</th><th><code>mrank</code></th><th>Displayed BR</th><th><code>mrank</code></th><th>Displayed BR</th></tr></thead><tbody><tr><td><code>0</code></td><td><strong>1.0</strong></td><td><code>10</code></td><td><strong>4.3</strong></td><td><code>20</code></td><td><strong>7.7</strong></td><td><code>30</code></td><td><strong>11.0</strong></td></tr><tr><td><code>1</code></td><td><strong>1.3</strong></td><td><code>11</code></td><td><strong>4.7</strong></td><td><code>21</code></td><td><strong>8.0</strong></td><td><code>31</code></td><td><strong>11.3</strong></td></tr><tr><td><code>2</code></td><td><strong>1.7</strong></td><td><code>12</code></td><td><strong>5.0</strong></td><td><code>22</code></td><td><strong>8.3</strong></td><td><code>32</code></td><td><strong>11.7</strong></td></tr><tr><td><code>3</code></td><td><strong>2.0</strong></td><td><code>13</code></td><td><strong>5.3</strong></td><td><code>23</code></td><td><strong>8.7</strong></td><td><code>33</code></td><td><strong>12.0</strong></td></tr><tr><td><code>4</code></td><td><strong>2.3</strong></td><td><code>14</code></td><td><strong>5.7</strong></td><td><code>24</code></td><td><strong>9.0</strong></td><td><code>34</code></td><td><strong>12.3</strong></td></tr><tr><td><code>5</code></td><td><strong>2.7</strong></td><td><code>15</code></td><td><strong>6.0</strong></td><td><code>25</code></td><td><strong>9.3</strong></td><td><code>35</code></td><td><strong>12.7</strong></td></tr><tr><td><code>6</code></td><td><strong>3.0</strong></td><td><code>16</code></td><td><strong>6.3</strong></td><td><code>26</code></td><td><strong>9.7</strong></td><td><code>36</code></td><td><strong>13.0</strong></td></tr><tr><td><code>7</code></td><td><strong>3.3</strong></td><td><code>17</code></td><td><strong>6.7</strong></td><td><code>27</code></td><td><strong>10.0</strong></td><td><code>37</code></td><td><strong>13.3</strong></td></tr><tr><td><code>8</code></td><td><strong>3.7</strong></td><td><code>18</code></td><td><strong>7.0</strong></td><td><code>28</code></td><td><strong>10.3</strong></td><td><code>38</code></td><td><strong>13.7</strong></td></tr><tr><td><code>9</code></td><td><strong>4.0</strong></td><td><code>19</code></td><td><strong>7.3</strong></td><td><code>29</code></td><td><strong>10.7</strong></td><td><code>39</code></td><td><strong>14.0</strong></td></tr></tbody></table></div>
<h4 id="ch-02-en-5-2-legacy-mode-suffixes-in-wpcost-blk-vs-tech-tree-tier-rank">5.2 Legacy Mode Suffixes in <code>wpcost.blk</code> vs Tech-Tree Tier <code>rank</code></h4>
<p>War Thunder retains internal field names from its alpha era—be careful not to confuse <strong>tech-tree tier <code>rank</code></strong> with <strong>matchmaking BR <code>economicRank*</code></strong>:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>Field Name</th><th>Value Range</th><th>Meaning</th></tr></thead><tbody><tr><td><code>rank</code></td><td><code>1</code> .. <code>8</code></td><td><strong>Tech-Tree Era Tier (Rank I – VIII)</strong>: controls which horizontal tier row the vehicle occupies, tier unlock gates, and default store rank-tier pricing</td></tr><tr><td><code>economicRankArcade</code></td><td><code>0</code> .. <code>39+</code></td><td><strong>Arcade Battles (AB)</strong> matchmaking <code>mrank</code></td></tr><tr><td><code>economicRankHistorical</code></td><td><code>0</code> .. <code>39+</code></td><td><strong>Realistic Battles (RB)</strong> default matchmaking <code>mrank</code> (RB was originally called *Historical Battles*)</td></tr><tr><td><code>economicRankSimulation</code></td><td><code>0</code> .. <code>39+</code></td><td><strong>Simulator Battles (SB)</strong> default matchmaking <code>mrank</code></td></tr><tr><td><code>economicRankTankHistorical</code></td><td><code>0</code> .. <code>39+</code></td><td>*(Optional)* Split <strong>Ground RB</strong> <code>mrank</code> for aircraft/helicopters with separate air vs ground BRs; falls back to <code>economicRankHistorical</code> when omitted</td></tr><tr><td><code>economicRankTankSimulation</code></td><td><code>0</code> .. <code>39+</code></td><td>*(Optional)* Split <strong>Ground SB</strong> <code>mrank</code> for aircraft/helicopters</td></tr></tbody></table></div>
<hr>
<h3 id="ch-02-en-6-shop-blk-anatomy-units-csv-localization-suffixes">6. <code>shop.blk</code> Anatomy &amp; <code>units.csv</code> Localization Suffixes</h3>
<h4 id="ch-02-en-6-1-the-4-level-hierarchy-of-config-shop-blk">6.1 The 4-Level Hierarchy of <code>config/shop.blk</code></h4>
<p>Inside <code>char.vromfs.bin</code>, <code>config/shop.blk</code> organizes every nation's research tree into a uniform 4-level hierarchy:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>country_usa (or country_germany / country_ussr / country_britain / country_japan / country_china / ...)
└─ army | helicopters | aviation | ships | boats
├─ range { ... } &lt;-- range[0]: 1st vertical column (e.g. US Light Tank line)
├─ range { ... } &lt;-- range[1]: 2nd vertical column (e.g. US Medium Tank line, containing folder us_sherman_group)
├─ range { ... } &lt;-- range[2]..range[4]: remaining regular Silver Lions research columns
└─ range { ... } &lt;-- range[5]..range[6]: right-hand Golden Eagle / Pack / Event / Squadron columns</code></pre></div>
<p>Keep three rules in mind when writing <code>shop.blk.patch.jsonc</code>:</p>
<ol><li><strong>Each sibling <code>range</code> block is one vertical column in the tech tree</strong>: since every column block is named <code>range</code>, address them left-to-right (zero-based) as <code>&quot;range[0]&quot;</code>, <code>&quot;range[1]&quot;</code>, <code>&quot;range[5]&quot;</code>, etc.;</li><li><strong>Collapsible folder groups (<code>*_group</code>)</strong>: when multiple variants share one tech-tree folder, <code>range</code> contains a child block ending in <code>_group</code> (e.g. <code>us_sherman_group</code>) whose children are the grouped vehicles; the folder's display label comes from <code>shop/group/&lt;group_name&gt;</code> in <code>units.csv</code>;</li><li><strong>Why is the prerequisite arrow field named <code>reqAir</code> even on tanks and ships?</strong> War Thunder began life as an aviation-only game (*World of Planes*), so <code>air</code> / <code>aircraft</code> remained the universal internal noun for any unit. Consequently, <strong><code>reqAir</code> defines the research prerequisite vehicle across tanks, helicopters, aircraft, and ships alike</strong>!
<ul><li>Setting <code>reqAir:t=&quot;us_m2a4&quot;</code> in <code>wpcost.blk</code> requires owning <code>us_m2a4</code> before researching the unit;</li><li>Inside a <code>range</code> column in <code>shop.blk</code>: consecutive vehicles with no <code>reqAir</code> property automatically connect with vertical arrows; <code>reqAir:t=&quot;us_m2a4&quot;</code> draws an explicit arrow from <code>us_m2a4</code>; and <strong><code>reqAir:t=&quot;&quot;</code> (empty string) explicitly breaks the arrow from the vehicle above it</strong> (used at mid-column gaps and throughout the right-hand premium/pack columns).</li></ul></li></ol>
<h4 id="ch-02-en-6-2-all-4-lang-units-csv-keys-incremental-csv-merging">6.2 All 4 <code>lang/units.csv</code> Keys &amp; Incremental CSV Merging</h4>
<p>When localizing a vehicle <code>&lt;id&gt;</code> in <code>client/packs/lang.vromfs.bin/lang/units.csv.patch.csv</code>, War Thunder uses <strong>4 standard localization keys</strong> for different UI contexts and HUD distances:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>Key Pattern</th><th>Where It Appears in Game</th><th>Example (for <code>us_m2a4_mod_demo</code>)</th></tr></thead><tbody><tr><td><code>&lt;id&gt;_shop</code></td><td><strong>Tech-tree card, crew slot bar, and local web store card</strong> short name</td><td><code>&quot;M2A4 (Mod Demo)&quot;</code> / <code>&quot;M2A4(教学改型)&quot;</code></td></tr><tr><td><code>&lt;id&gt;_0</code></td><td><strong>Stat-card header, research completion modal, and battle debriefing</strong> full formal title</td><td><code>&quot;Light Tank M2A4 (Mod Demo)&quot;</code> / <code>&quot;M2A4 轻型坦克(教学改型)&quot;</code></td></tr><tr><td><code>&lt;id&gt;_1</code></td><td>In-battle <strong>medium-distance 3D HUD marker</strong> name</td><td><code>&quot;M2A4 Demo&quot;</code> / <code>&quot;M2A4 教学型&quot;</code></td></tr><tr><td><code>&lt;id&gt;_2</code></td><td>In-battle <strong>far-distance HUD marker / compact killfeed</strong> short name</td><td><code>&quot;M2A4&quot;</code> / <code>&quot;M2A4&quot;</code></td></tr></tbody></table></div>
<p>Example <code>client/packs/lang.vromfs.bin/lang/units.csv.patch.csv</code>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>csv</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>&quot;&lt;ID|readonly|noverify&gt;&quot;;&quot;&lt;English&gt;&quot;;&quot;&lt;Chinese&gt;&quot;;&quot;&lt;HChinese&gt;&quot;
&quot;us_m2a4_mod_demo_shop&quot;;&quot;M2A4 (Mod Demo)&quot;;&quot;M2A4(教学改型)&quot;;&quot;M2A4(教學改型)&quot;
&quot;us_m2a4_mod_demo_0&quot;;&quot;Light Tank M2A4 (Mod Demo)&quot;;&quot;M2A4 轻型坦克(教学改型)&quot;;&quot;M2A4 輕型坦克(教學改型)&quot;
&quot;us_m2a4_mod_demo_1&quot;;&quot;M2A4 Demo&quot;;&quot;M2A4 教学型&quot;;&quot;M2A4 教學型&quot;
&quot;us_m2a4_mod_demo_2&quot;;&quot;M2A4&quot;;&quot;M2A4&quot;;&quot;M2A4&quot;</code></pre></div>
<ul><li>Fields must be separated by semicolons <code>;</code> and wrapped in double quotes, with column headers on line 1 (list only the language columns you want to populate; omitted columns keep their stock values or default to empty);</li><li>Existing row keys update only your non-empty columns in place; new keys are appended to the end of the file.</li></ul>
<hr>
<h3 id="ch-02-en-7-patching-root-config-blk-client-config-blk-patch-jsonc">7. Patching Root <code>config.blk</code> (<code>client/config-blk.patch.jsonc</code>)</h3>
<p>If your mod needs to adjust the client root <code>config.blk</code> (for example enabling sound mods via <code>sound{ enable_mod:b=yes }</code> or setting a custom hangar <code>hangarBlk:t=&quot;...&quot;</code>), place a standard BLK patch at <code>client/config-blk.patch.jsonc</code>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;ops&quot;: [
{
&quot;op&quot;: &quot;setParam&quot;,
&quot;path&quot;: [&quot;sound&quot;],
&quot;name&quot;: &quot;enable_mod&quot;,
&quot;value&quot;: { &quot;type&quot;: &quot;bool&quot;, &quot;value&quot;: true },
&quot;createBlocks&quot;: true
}
]
}</code></pre></div>
<p>The launcher backs up the stock <code>config.blk</code> to <code>wtoffline/stock/config.blk</code> before applying patches and restores it automatically when no enabled mod touches <code>config.blk</code>.</p>
<hr>
<h3 id="ch-02-en-8-end-to-end-walkthrough-clone-a-playable-standalone-tank-usm2a4moddemo-in-5-minutes">8. End-to-End Walkthrough: Clone a Playable Standalone Tank (<code>us_m2a4_mod_demo</code>) in 5 Minutes</h3>
<p>Let's connect every piece from this chapter into a complete, copy-pasteable mod that derives a standalone <strong><code>us_m2a4_mod_demo</code></strong> light tank from stock <code>us_m2a4</code>—boosted to <code>90 km/h</code>, rated at BR <code>1.3</code> (<code>mrank = 1</code>), and wired into US Ground Rank I with a research arrow from <code>M2A4</code>. Because every player profile owns the reserve <code>us_m2a4</code> from the start, you can see the new tank in the US tree and <strong>Test Drive</strong> it immediately!</p>
<h4 id="ch-02-en-8-1-mod-folder-tree">8.1 Mod Folder Tree</h4>
<p>Create <code>demo-standalone-m2a4/</code> inside your global <code>mods/</code> directory:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>mods/demo-standalone-m2a4/
├─ mod.jsonc
└─ client/
└─ packs/
├─ aces.vromfs.bin/
│ └─ gamedata/units/tankmodels/
│ └─ us_m2a4_mod_demo.blk # ① Tank physics/armor/weapons (copied from stock us_m2a4.blk)
├─ char.vromfs.bin/
│ └─ config/
│ ├─ wpcost.blk.patch.jsonc # ② Clone economy, BR, modifications &amp; ammo racks
│ ├─ shop.blk.patch.jsonc # ③ Insert into US Army column 0 (Rank I)
│ └─ unittags.blk.patch.jsonc # ④ Clone unit class tags &amp; test-drive mission
└─ lang.vromfs.bin/
└─ lang/
└─ units.csv.patch.csv # ⑤ Localized _shop / _0 / _1 / _2 names</code></pre></div>
<h4 id="ch-02-en-8-2-complete-file-contents">8.2 Complete File Contents</h4>
<h5 id="ch-02-en-manifest-mod-jsonc">Manifest <code>mod.jsonc</code></h5>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;format&quot;: 1,
&quot;id&quot;: &quot;demo.standalone-m2a4&quot;,
&quot;name&quot;: {
&quot;zh-CN&quot;: &quot;独立衍生载具示例:M2A4 教学改型&quot;,
&quot;en&quot;: &quot;Standalone Vehicle Demo: M2A4 Mod Demo&quot;
},
&quot;version&quot;: &quot;0.1.0&quot;,
&quot;author&quot;: &quot;YourName&quot;,
&quot;description&quot;: {
&quot;zh-CN&quot;: &quot;克隆原版 us_m2a4 新增一辆独立可研发、可试驾的 90km/h 高速轻坦。&quot;,
&quot;en&quot;: &quot;Clones stock us_m2a4 into a playable 90 km/h standalone tank in the US Rank I tree.&quot;
},
&quot;api_version&quot;: &quot;0.1-experimental&quot;,
&quot;game_versions&quot;: [&quot;2.61.0.*&quot;]
}</code></pre></div>
<h5 id="ch-02-en-①-tank-model-definition-client-packs-aces-vromfs-bin-gamedata-units-tankmodels-usm2a4moddemo-blk">① Tank Model Definition <code>client/packs/aces.vromfs.bin/gamedata/units/tankmodels/us_m2a4_mod_demo.blk</code></h5>
<p>Extract stock <code>gamedata/units/tankmodels/us_m2a4.blk</code> from <code>aces.vromfs.bin</code> using any method from Chapter 01 Section 2, and save it as <code>us_m2a4_mod_demo.blk</code>. Keep <code>model:t=&quot;m2a4&quot;</code> at the top (so the engine reuses the stock M2A4 3D mesh and textures) and raise its speed and acceleration (plain text <code>.blk</code> compiles to binary automatically on build):</p>
<div class="doc-pre"><div class="doc-pre-head"><span>blk</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>model:t=&quot;m2a4&quot;
// ... (keep the rest of stock us_m2a4.blk unchanged; tweak mobility below to feel the difference) ...
maxFwdSpeed:r=90.0
maxRevSpeed:r=25.0
maxAccel:r=12.0</code></pre></div>
<h5 id="ch-02-en-②-economy-br-patch-client-packs-char-vromfs-bin-config-wpcost-blk-patch-jsonc">② Economy &amp; BR Patch <code>client/packs/char.vromfs.bin/config/wpcost.blk.patch.jsonc</code></h5>
<p>Use <code>cloneBlock</code> to copy <code>us_m2a4</code> (inheriting all weapons, shells, modifications, and backup settings), and set <code>reqAir</code> to <code>&quot;us_m2a4&quot;</code>, RP cost to <code>1000</code>, SL price to <code>500</code>, and all mode <code>mrank</code> values to <code>1</code> (displayed BR <strong>1.3</strong>):</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;ops&quot;: [
{
&quot;op&quot;: &quot;cloneBlock&quot;,
&quot;from&quot;: [&quot;us_m2a4&quot;],
&quot;toParent&quot;: [],
&quot;newName&quot;: &quot;us_m2a4_mod_demo&quot;,
&quot;replaceExisting&quot;: true,
&quot;ops&quot;: [
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;reqAir&quot;, &quot;value&quot;: &quot;us_m2a4&quot; },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;reqExp&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 1000 } },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;value&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 500 } },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;economicRank&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 1 } },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;economicRankArcade&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 1 } },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;economicRankHistorical&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 1 } },
{ &quot;op&quot;: &quot;setParam&quot;, &quot;path&quot;: [], &quot;name&quot;: &quot;economicRankSimulation&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 1 } }
]
}
]
}</code></pre></div>
<h5 id="ch-02-en-③-tech-tree-slot-patch-client-packs-char-vromfs-bin-config-shop-blk-patch-jsonc">③ Tech-Tree Slot Patch <code>client/packs/char.vromfs.bin/config/shop.blk.patch.jsonc</code></h5>
<p>Insert <code>us_m2a4_mod_demo</code> into <code>country_usa -&gt; army -&gt; range[0]</code> right after <code>us_m3a1_stuart</code> (just before the <code>us_m5a1_stuart</code> Rank II break) with an explicit <code>reqAir: &quot;us_m2a4&quot;</code>, creating a clean Rank I side-branch arrow from <code>M2A4</code> without disturbing the stock Stuart chain:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;ops&quot;: [
{
&quot;op&quot;: &quot;addBlock&quot;,
&quot;path&quot;: [&quot;country_usa&quot;, &quot;army&quot;, &quot;range[0]&quot;],
&quot;name&quot;: &quot;us_m2a4_mod_demo&quot;,
&quot;after&quot;: &quot;us_m3a1_stuart&quot;,
&quot;block&quot;: {
&quot;params&quot;: [
{ &quot;name&quot;: &quot;rank&quot;, &quot;value&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;value&quot;: 1 } },
{ &quot;name&quot;: &quot;reqAir&quot;, &quot;value&quot;: &quot;us_m2a4&quot; }
]
}
}
]
}</code></pre></div>
<h5 id="ch-02-en-④-unit-tags-test-drive-patch-client-packs-char-vromfs-bin-config-unittags-blk-patch-jsonc">④ Unit Tags &amp; Test-Drive Patch <code>client/packs/char.vromfs.bin/config/unittags.blk.patch.jsonc</code></h5>
<p>Clone <code>us_m2a4</code> in <code>unittags.blk</code> so the new ID inherits <code>type:t=&quot;tank&quot;</code>, <code>hangar_place:t=&quot;tank&quot;</code>, the ground <code>testFlight</code> mission, and light-tank tags:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;ops&quot;: [
{
&quot;op&quot;: &quot;cloneBlock&quot;,
&quot;from&quot;: [&quot;us_m2a4&quot;],
&quot;toParent&quot;: [],
&quot;newName&quot;: &quot;us_m2a4_mod_demo&quot;,
&quot;replaceExisting&quot;: true
}
]
}</code></pre></div>
<h5 id="ch-02-en-⑤-localization-patch-client-packs-lang-vromfs-bin-lang-units-csv-patch-csv">⑤ Localization Patch <code>client/packs/lang.vromfs.bin/lang/units.csv.patch.csv</code></h5>
<p>Copy the 4-row CSV snippet from Section 6.2 above. Enable the mod in the launcher, start the game, open the US Ground Rank I tree, and right-click <strong>M2A4 (Mod Demo) › Test Drive</strong> to take your 90 km/h light tank for a spin!</p>
</div>
<div class="doc-pager">
<a class="doc-pager-btn" href="#ch-01" data-chapter="ch-01"><span class="doc-pager-label"><span class="lang-zh">← 上一章</span><span class="lang-en">← Previous</span></span><span class="doc-pager-title"><span class="lang-zh">01 · 快速入门与清单规范</span><span class="lang-en">01 · Quick Start &amp; Manifest</span></span></a>
<a class="doc-pager-btn next" href="#ch-03" data-chapter="ch-03"><span class="doc-pager-label"><span class="lang-zh">下一章 →</span><span class="lang-en">Next →</span></span><span class="doc-pager-title"><span class="lang-zh">03 · 自定义 3D 模型载具</span><span class="lang-en">03 · Custom 3D Vehicles</span></span></a>
</div>
</article>
<article class="doc-section doc-chapter" id="ch-03">
<div class="lang-zh">
<h2>03 · 添加全新 3D 模型与贴图载具</h2>
<p>本章专门讲解如何在 WTOffline 中制作<strong>带自定义 3D 模型(<code>.grp</code>)和贴图包(<code>.dxp.bin</code>)的全新载具模组</strong>,让多款不同作者的新车模组同时叠加共存、跨盘零拷贝秒挂、关闭即还原。</p>
<hr>
<h3 id="ch-03-zh-1-核心术语通俗说明与跨盘零拷贝机制">1. 核心术语通俗说明与跨盘零拷贝机制</h3>
<p>在接触 3D 载具模组时,你会遇到以下 4 个高频底层名词——其实它们非常直观:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>名词 / 后缀</th><th>通俗解释</th></tr></thead><tbody><tr><td><strong><code>.grp</code></strong></td><td>Dagor 引擎的 <strong>3D 模型与骨架归档文件</strong>(由官方 War Thunder CDK <code>AssetViewer</code> / 导出器编译生成),内含多级细节网格(LOD)、骨骼动画节点(<code>animChar</code>)、碰撞体与内构损伤模块(DM)几何体。</td></tr><tr><td><strong><code>.dxp.bin</code></strong></td><td>Dagor 引擎的<strong>批量压缩贴图包</strong>,把一辆或多辆载具用到的多张漫反射、法线、金属度贴图打包在同一个文件里供 <code>.grp</code> 材质按名索引。</td></tr><tr><td><strong><code>.ddsx</code></strong></td><td><strong>单张</strong> Dagor 压缩贴图文件(DDSx),常用于 UI 资料卡载具立绘(如 <code>ui/images.vromfs.bin/units/&lt;载具id&gt;.ddsx</code>)或涂装单贴图。</td></tr><tr><td><strong>NTFS 目录联接点(Junction)</strong></td><td>可以理解成 <strong>Windows 文件系统底层的“零拷贝文件夹快捷方式”</strong>:游戏引擎访问 <code>&lt;游戏副本&gt;/content/pkg_user/&lt;模组ID&gt;</code> 时,操作系统直接把读写透明指向你放在任意盘符 <code>mods/</code> 里的源文件夹——<strong>无需管理员权限、跨盘可用、占用 0 字节额外硬盘空间、挂载和拆除只需约 1 毫秒</strong>!</td></tr></tbody></table></div>
<h4 id="ch-03-zh-引擎是如何自动发现-client-addon-的">引擎是如何自动发现 <code>client/addon/</code> 的?</h4>
<p>经对 2.61.0.x 客户端 <code>aces.exe</code> 与 <code>aces.vromfs.bin/config/settings.blk</code> 核实:</p>
<ul><li>构建器会自动把所有已启用模组的挂载路径注册进 <code>config/settings.blk</code> 的 <code>addons</code>、<code>addons_no_check</code> 与 <code>addonsWithBasePath</code> 三个列表;</li><li>凡是路径位于 <code>/pkg_user/</code> 下的扩展目录(默认挂载到 <code>&lt;游戏副本&gt;/content/pkg_user/&lt;安全模组ID&gt;</code>),引擎会<strong>自动跳过 <code>res/grp_hdr.vromfs.bin</code> 包头强制校验,直接扫描 <code>&lt;目录&gt;/res/</code> 下的全部 <code>.grp</code> 模型与 <code>.dxp.bin</code> 贴图包并注册进全局资源管理器</strong>;</li><li>如果你的模组附带了正式 CDK 编译生成的 <code>res/grp_hdr.vromfs.bin</code>,构建器会自动改挂到 <code>&lt;游戏副本&gt;/content/pkg_wto_&lt;安全模组ID&gt;</code>,交给引擎原生的 <code>grp_hdr</code> 加载器处理;</li><li>关闭模组时启动器只拆除该目录联接点本身,不会删改 <code>mods/</code> 里的源文件。</li></ul>
<hr>
<h3 id="ch-03-zh-2-添加一辆全新-3d-模型载具的-6-步清单">2. 添加一辆全新 3D 模型载具的 6 步清单</h3>
<p>假设你的模组 ID 是 <code>demo.new-mbt</code>,新车内部 ID 叫 <code>us_mbt_demo</code>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>mods/demo-new-mbt/
├─ mod.jsonc
└─ client/
├─ addon/
│ └─ res/
│ ├─ us_mbt_demo.grp # ① 3D 模型、骨架、碰撞体(CDK 导出)
│ └─ us_mbt_demo.dxp.bin # ① 压缩贴图包(DDSx)
└─ packs/
├─ aces.vromfs.bin/
│ └─ gamedata/units/tankmodels/
│ └─ us_mbt_demo.blk # ② 载具物理、装甲、炮塔、武器配置(文本 BLK 自动编译)
├─ char.vromfs.bin/
│ └─ config/
│ ├─ wpcost.blk.patch.jsonc # ③ 价格、研发点、权重、改装件(用 cloneBlock 最快)
│ ├─ shop.blk.patch.jsonc # ④ 挂进对应国家科技树纵列位置
│ └─ unittags.blk.patch.jsonc # ④ 注册载具类型、机库车位、试车场与标签
├─ lang.vromfs.bin/
│ └─ lang/
│ └─ units.csv.patch.csv # ⑤ 中英文名称(_shop、_0、_1、_2)
├─ ui/atlases.vromfs.bin/
│ └─ gameuiskin/
│ └─ us_mbt_demo_ico.svg # ⑥ 科技树与本地商城剪影图标(文件名必须全小写)
└─ ui/images.vromfs.bin/
└─ units/
└─ us_mbt_demo.ddsx # ⑥ 资料卡/乘员栏载具大图(可选,缺失时自动回退占位图)</code></pre></div>
<h4 id="ch-03-zh-关键核对要点">关键核对要点</h4>
<ol><li><strong>保持三处载具内部 ID 完全一致</strong>:<code>tankmodels/us_mbt_demo.blk</code> 文件名(或空军 <code>flightmodels/us_jet_demo.blk</code>)、<code>wpcost.blk</code> 块名、<code>shop.blk</code> 块名与 <code>unittags.blk</code> 块名必须一字不差。</li><li><strong><code>ui/atlases.vromfs.bin</code> 图标路径必须全小写</strong>:原版图标包内部键名统一为全小写,请命名为 <code>gameuiskin/&lt;全小写载具id&gt;_ico.svg</code>(本地网页商店的商品卡片也会自动读取这张 SVG 图标!)。</li><li><strong>验证 <code>.blk</code> 里的模型资产名与 <code>.grp</code> 一致</strong>:<code>gamedata/units/tankmodels/us_mbt_demo.blk</code> 顶部的 <code>model:t=&quot;...&quot;</code> 名称必须与你在 CDK 中导出 <code>.grp</code> 时的资产名完全一致。</li></ol>
<hr>
<h3 id="ch-03-zh-3-银狮研发车-vs-gift-商城礼包车-以及-ai-机器人池准入规则">3. 银狮研发车 vs <code>gift</code> 商城礼包车(以及 AI 机器人池准入规则)</h3>
<p>在 <code>wpcost.blk.patch.jsonc</code> 和 <code>shop.blk.patch.jsonc</code> 中,你可以自由决定这辆新车是走<strong>常规银狮研发线</strong>还是走<strong>本地网页商城礼包</strong>:</p>
<h4 id="ch-03-zh-方式-a-常规银狮科技树研发车-推荐希望-ai-也能开这辆车出战时使用">方式 A:常规银狮科技树研发车(推荐希望 AI 也能开这辆车出战时使用)</h4>
<ul><li>在 <code>wpcost.blk</code> 中设置常规 <code>value</code>(银狮售价)与 <code>reqExp</code>(研发点),<strong>不要设置</strong> <code>gift</code>、<code>premPackAir</code>、<code>costGold</code>、<code>event</code> 或 <code>researchType</code>(联队车标记),也不要在 <code>shop.blk</code> 设置 <code>showOnlyWhenBought:b=yes</code>;</li><li><strong>自动进入对局 AI 机器人池</strong>:本地服务器的分房机器人选择器(<code>battle-ranks.ts</code>)会自动把已挂入科技树(<code>shop.blk</code>)且<strong>不含</strong> <code>gift</code>、<code>premPackAir</code>、<code>event</code>、<code>researchType</code>、<code>showOnlyWhenBought</code> 标记的常规银狮科技树载具纳入对应国家与分房权重的 AI 出战池!这意味着你在单机对局里也能遇到驾驶你自制新车的友军和敌军 AI。</li></ul>
<h4 id="ch-03-zh-方式-b-本地网页商城礼包车-gift-t-msinotebook">方式 B:本地网页商城礼包车(<code>gift:t=&quot;msi_notebook&quot;</code>)</h4>
<p>很多模组作者在翻看原版 <code>wpcost.blk</code> / <code>shop.blk</code> 时会好奇:<strong>为什么满地都是 <code>gift:t=&quot;msi_notebook&quot;</code>?</strong></p>
<ul><li>在原版战雷中,只要载具块带有任意非空的 <code>gift:t=&quot;...&quot;</code> 字符串(官方历史遗留常填 <code>&quot;msi_notebook&quot;</code> 等推广代号),客户端就会把该车识别为“需通过商店礼包购买解锁的礼品车”,点击「购买」按钮时会拉起商店页面而非扣除银狮/金鹰;</li><li><strong>WTOffline 自动生成本地商店商品</strong>:构建器扫描 <code>wpcost.blk</code> 时,会自动为每一辆带 <code>gift</code> 参数的载具注册确定性的本地商城商品 ID <strong><code>wto_pack_&lt;载具ID&gt;</code></strong>(例如 <code>wto_pack_us_mbt_demo</code>)与对应 GUID:
<ul><li>哪怕你一行服务端配置都不写,本地网页商店也会按该车的 <code>rank</code> 等级自动套用默认档位定价与金鹰/高账赠品,玩家点开游戏内置商店就能直接购买解锁!</li><li>如果想给它单独定 GJN 售价和附赠金鹰/高账天数,只需在 <code>server/tuning/store.jsonc</code> 的 <code>vehiclePacks.byVehicle</code> 下加一行即可(详见第 05 章)。</li></ul></li><li><strong>注意 AI 机器人池边界</strong>:带 <code>gift</code>、<code>premPackAir</code>、<code>event</code>、<code>researchType</code> 或 <code>showOnlyWhenBought</code> 标记的特殊载具<strong>不会</strong>自动混入常规 AI 机器人池,避免稀有礼包原型车在普通对局满街跑。</li></ul>
<hr>
<h3 id="ch-03-zh-4-配套涂装-瞄具-音效与原生目录的边界">4. 配套涂装、瞄具、音效与原生目录的边界</h3>
<ul><li><strong>独立涂装 / 瞄具 / 单人任务</strong>:玩家照旧直接放进游戏目录原生的 <code>UserSkins/</code>、<code>UserSights/</code>、<code>UserMissions/</code> 即可,启动器完全不会干预或清理这些原生文件夹,<strong>无需</strong>封装成模组;</li><li><strong>大型新车整合包顺带附赠的配套资源</strong>:如果你的新车模组配套做好了专属涂装、现代火控瞄具或专属火炮音效包,可以放进 <code>client/files/</code> 随模组一起启停:
<ul><li><code>client/files/UserSkins/mod_us_mbt_demo_camo/...</code>(单模组独占子目录 → 自动走跨盘 NTFS Junction 零拷贝秒挂)</li><li><code>client/files/UserSights/us_mbt_demo/...</code>(单模组独占子目录 → 自动走跨盘 NTFS Junction 零拷贝秒挂)</li><li><code>client/files/sound/mod/my_cannon.bank</code>(多模组共享的平铺目录散文件 → 依次尝试文件符号链接 → 同盘硬链接 → 按大小与修改时间比对的增量缓存复制)</li></ul></li><li><strong>玩家原生文件保护</strong>:如果 <code>client/files/</code> 中的目标路径在游戏目录里已经作为玩家手动放置的原生文件/文件夹存在,启动器会自动跳过该项并在日志中输出冲突告警,不会覆盖或删除玩家的自有文件。</li></ul>
</div>
<div class="lang-en">
<h2>03 · Adding Custom 3D Vehicle Models &amp; Textures</h2>
<p>This chapter explains how to build <strong>brand-new 3D vehicle mods shipping custom geometry (<code>.grp</code>) and texture packs (<code>.dxp.bin</code>)</strong> in WTOffline so multiple vehicle packs from different authors stack cleanly, mount across drives with zero copying, and roll back cleanly when disabled.</p>
<hr>
<h3 id="ch-03-en-1-plain-language-asset-glossary-zero-copy-mounting">1. Plain-Language Asset Glossary &amp; Zero-Copy Mounting</h3>
<p>When working with 3D vehicle mods, you will encounter four core asset and filesystem terms:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>Term / Extension</th><th>Plain-Language Meaning</th></tr></thead><tbody><tr><td><strong><code>.grp</code></strong></td><td>Dagor Engine <strong>3D geometry &amp; skeleton archive</strong> (exported from the official War Thunder CDK <code>AssetViewer</code> / exporter), containing multi-LOD meshes, animation skeleton nodes (<code>animChar</code>), collision volumes, and internal damage-model (DM) parts.</td></tr><tr><td><strong><code>.dxp.bin</code></strong></td><td>Dagor Engine <strong>compressed texture pack</strong>, bundling multiple diffuse, normal, and metallic/roughness DDSx textures referenced by name inside <code>.grp</code> materials.</td></tr><tr><td><strong><code>.ddsx</code></strong></td><td>A <strong>single</strong> Dagor compressed texture file (DDSx), commonly used for UI stat-card vehicle portraits (<code>ui/images.vromfs.bin/units/&lt;unit_id&gt;.ddsx</code>) or standalone skin textures.</td></tr><tr><td><strong>NTFS Directory Junction</strong></td><td>Think of it as an <strong>OS-level zero-copy folder shortcut</strong> built into Windows NTFS: when the game engine opens <code>&lt;copy&gt;/content/pkg_user/&lt;modId&gt;</code>, Windows transparently serves the files straight from your <code>mods/</code> folder on any drive—<strong>no administrator rights needed, works across drives, consumes 0 extra disk bytes, and mounts/unmounts in ~1 ms</strong>!</td></tr></tbody></table></div>
<h4 id="ch-03-en-how-the-engine-discovers-client-addon-automatically">How the Engine Discovers <code>client/addon/</code> Automatically</h4>
<p>Verified directly against 2.61.0.x <code>aces.exe</code> (<code>dlContent.cpp</code>) and <code>aces.vromfs.bin/config/settings.blk</code>:</p>
<ul><li>The patcher automatically registers every enabled mod's addon mount path into <code>addons</code>, <code>addons_no_check</code>, and <code>addonsWithBasePath</code> inside <code>config/settings.blk</code>;</li><li>Any addon path under <code>/pkg_user/</code> (mounted by default at <code>&lt;copy&gt;/content/pkg_user/&lt;safeModId&gt;</code>) <strong>skips the mandatory <code>res/grp_hdr.vromfs.bin</code> header check and directly scans <code>&lt;addon&gt;/res/</code> for all <code>.grp</code> model and <code>.dxp.bin</code> texture archives</strong>, registering them into the global asset manager;</li><li>If your mod ships an official CDK-compiled <code>res/grp_hdr.vromfs.bin</code>, the patcher mounts it at <code>&lt;copy&gt;/content/pkg_wto_&lt;safeModId&gt;</code> so the native <code>grp_hdr</code> loader handles it;</li><li>Disabling a mod removes only the directory junction itself and never deletes or modifies your source files inside <code>mods/</code>.</li></ul>
<hr>
<h3 id="ch-03-en-2-6-step-checklist-for-a-custom-3d-vehicle">2. 6-Step Checklist for a Custom 3D Vehicle</h3>
<p>Suppose your mod ID is <code>demo.new-mbt</code> and your new vehicle's internal ID is <code>us_mbt_demo</code>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>mods/demo-new-mbt/
├─ mod.jsonc
└─ client/
├─ addon/
│ └─ res/
│ ├─ us_mbt_demo.grp # ① 3D meshes, skeleton &amp; collision (CDK export)
│ └─ us_mbt_demo.dxp.bin # ① Compressed texture pack (DDSx)
└─ packs/
├─ aces.vromfs.bin/
│ └─ gamedata/units/tankmodels/
│ └─ us_mbt_demo.blk # ② Physics, armor, turret &amp; weapons (text BLK compiles automatically)
├─ char.vromfs.bin/
│ └─ config/
│ ├─ wpcost.blk.patch.jsonc # ③ Price, RP, BR &amp; modifications (fastest via cloneBlock)
│ ├─ shop.blk.patch.jsonc # ④ Tech-tree column &amp; position
│ └─ unittags.blk.patch.jsonc # ④ Unit class, hangar slot, test-drive mission &amp; tags
├─ lang.vromfs.bin/
│ └─ lang/
│ └─ units.csv.patch.csv # ⑤ Localized names (_shop, _0, _1, _2)
├─ ui/atlases.vromfs.bin/
│ └─ gameuiskin/
│ └─ us_mbt_demo_ico.svg # ⑥ Tech-tree &amp; local web store silhouette icon (all lowercase!)
└─ ui/images.vromfs.bin/
└─ units/
└─ us_mbt_demo.ddsx # ⑥ Stat-card / crew-slot portrait (optional; falls back to placeholder)</code></pre></div>
<h4 id="ch-03-en-key-verification-checks">Key Verification Checks</h4>
<ol><li><strong>Keep the vehicle's internal ID identical everywhere</strong>: the <code>tankmodels/us_mbt_demo.blk</code> filename (or <code>flightmodels/us_jet_demo.blk</code> for aircraft) and the block names in <code>wpcost.blk</code>, <code>shop.blk</code>, and <code>unittags.blk</code> must match character for character.</li><li><strong><code>ui/atlases.vromfs.bin</code> icon paths must be all lowercase</strong>: stock icon packs store paths in lowercase, so name your icon <code>gameuiskin/&lt;lowercase_unit_id&gt;_ico.svg</code> (the local web store also displays this exact SVG on pack cards!).</li><li><strong>Match <code>.blk</code> asset names to <code>.grp</code> exports</strong>: <code>model:t=&quot;...&quot;</code> inside <code>gamedata/units/tankmodels/us_mbt_demo.blk</code> must match the exact asset name exported into your <code>.grp</code> archive from the CDK.</li></ol>
<hr>
<h3 id="ch-03-en-3-regular-tech-tree-vehicles-vs-gift-store-packs-ai-bot-pool-rules">3. Regular Tech-Tree Vehicles vs <code>gift</code> Store Packs (&amp; AI Bot Pool Rules)</h3>
<p>In <code>wpcost.blk.patch.jsonc</code> and <code>shop.blk.patch.jsonc</code>, you can wire your custom vehicle either as a <strong>regular Silver Lions researchable vehicle</strong> or as a <strong>local web store pack vehicle</strong>:</p>
<h4 id="ch-03-en-option-a-regular-silver-lions-tech-tree-vehicle-recommended-if-you-want-ai-bots-to-drive-it">Option A: Regular Silver Lions Tech-Tree Vehicle (Recommended If You Want AI Bots to Drive It)</h4>
<ul><li>Set normal <code>value</code> (Silver Lions price) and <code>reqExp</code> (Research Points) in <code>wpcost.blk</code>, and <strong>omit</strong> <code>gift</code>, <code>premPackAir</code>, <code>costGold</code>, <code>event</code>, and <code>researchType</code> (squadron tag), as well as <code>showOnlyWhenBought:b=yes</code> in <code>shop.blk</code>;</li><li><strong>Automatically joins the AI bot pool</strong>: the local server's matchmaking bot selector (<code>battle-ranks.ts</code>) automatically includes tech-tree vehicles (<code>inTechTree</code> in <code>shop.blk</code>) that have <strong>none</strong> of <code>gift</code>, <code>premPackAir</code>, <code>event</code>, <code>researchType</code>, or <code>showOnlyWhenBought</code>! Both friendly and enemy AI bots at matching BRs and nations will spawn in your custom vehicle during offline battles.</li></ul>
<h4 id="ch-03-en-option-b-local-web-store-pack-vehicle-gift-t-msinotebook">Option B: Local Web Store Pack Vehicle (<code>gift:t=&quot;msi_notebook&quot;</code>)</h4>
<p>Modders inspecting stock <code>wpcost.blk</code> / <code>shop.blk</code> often wonder: <strong>why do dozens of pack vehicles say <code>gift:t=&quot;msi_notebook&quot;</code>?</strong></p>
<ul><li>In stock War Thunder, any non-empty <code>gift:t=&quot;...&quot;</code> string (Gaijin historically reused promo strings like <code>&quot;msi_notebook&quot;</code> across countless store vehicles) marks the vehicle as an external store pack/gift unit whose <strong>Order</strong> button opens the web store instead of spending Silver Lions or Golden Eagles;</li><li><strong>WTOffline auto-generates a local web store bundle</strong>: during copy building, WTOffline scans every vehicle carrying <code>gift</code> in <code>wpcost.blk</code> and automatically registers a deterministic local store product ID <strong><code>wto_pack_&lt;unitId&gt;</code></strong> (e.g. <code>wto_pack_us_mbt_demo</code>) and bundle GUID:
<ul><li>Even with zero server config, the local web store automatically prices the pack using <code>vehiclePacks.byRank</code> for the vehicle's <code>rank</code> tier so players can buy and unlock it right away in the in-game store!</li><li>To customize its GJN price, Golden Eagles bonus, or Premium days, simply add an entry under <code>vehiclePacks.byVehicle</code> in <code>server/tuning/store.jsonc</code> (see Chapter 05).</li></ul></li><li><strong>AI Bot Pool Note</strong>: vehicles carrying <code>gift</code>, <code>premPackAir</code>, <code>event</code>, <code>researchType</code>, or <code>showOnlyWhenBought</code> are intentionally <strong>excluded</strong> from the automatic AI bot pool so rare pack prototypes do not flood standard bot lineups.</li></ul>
<hr>
<h3 id="ch-03-en-4-companion-skins-sights-sounds-the-native-folder-boundary">4. Companion Skins, Sights, Sounds &amp; the Native Folder Boundary</h3>
<ul><li><strong>Standalone skins, sights &amp; single-player missions</strong>: players should continue placing standalone files directly into the game's native <code>UserSkins/</code>, <code>UserSights/</code>, and <code>UserMissions/</code> folders—the launcher never touches or deletes player-managed native folders, and they <strong>do not</strong> need to be wrapped as mods;</li><li><strong>Companion assets bundled inside a large vehicle overhaul mod</strong>: if your custom vehicle mod includes dedicated camouflages, custom FCS gun sights, or custom cannon sound banks, place them under <code>client/files/</code> so they mount and unmount together with the mod:
<ul><li><code>client/files/UserSkins/mod_us_mbt_demo_camo/...</code> (mod-exclusive subfolder → mounts across drives via zero-copy NTFS Junction)</li><li><code>client/files/UserSights/us_mbt_demo/...</code> (mod-exclusive subfolder → mounts across drives via zero-copy NTFS Junction)</li><li><code>client/files/sound/mod/my_cannon.bank</code> (shared flat directory file → tries file symlink → same-drive hardlink → size/mtime incremental cached copy)</li></ul></li><li><strong>Native Player File Protection</strong>: if any target path under <code>client/files/</code> already exists in the game folder as a player-created native file or folder, the launcher skips that item with a log warning and <strong>never overwrites or deletes player content</strong>.</li></ul>
</div>
<div class="doc-pager">
<a class="doc-pager-btn" href="#ch-02" data-chapter="ch-02"><span class="doc-pager-label"><span class="lang-zh">← 上一章</span><span class="lang-en">← Previous</span></span><span class="doc-pager-title"><span class="lang-zh">02 · 数据包与 BLK/CSV 补丁</span><span class="lang-en">02 · Client Packs &amp; BLK Patching</span></span></a>
<a class="doc-pager-btn next" href="#ch-04" data-chapter="ch-04"><span class="doc-pager-label"><span class="lang-zh">下一章 →</span><span class="lang-en">Next →</span></span><span class="doc-pager-title"><span class="lang-zh">04 · GUI 与声明式 EXE 补丁</span><span class="lang-en">04 · GUI &amp; Declarative EXE Patches</span></span></a>
</div>
</article>
<article class="doc-section doc-chapter" id="ch-04">
<div class="lang-zh">
<h2>04 · 客户端 GUI 补丁与声明式 EXE 补丁</h2>
<blockquote><p><strong>实验期提示</strong>:界面脚本补丁(<code>gui-patches</code>)与声明式 <code>exe</code> 补丁(<code>exe-patches</code>)直接依赖目标游戏客户端的代码结构,游戏版本更新或离线核心补丁演进时可能需要同步维护。</p></blockquote>
<hr>
<h3 id="ch-04-zh-1-先懂概念-战雷原生-dagui-界面三件套-tpl-css-nut">1. 先懂概念:战雷原生 DaGui 界面三件套(<code>.tpl</code> + <code>.css</code> + <code>.nut</code>)</h3>
<p>《战争雷霆》机库与大厅界面由 Dagor 自研的 <strong>DaGui</strong> 框架驱动(全部存放在 <code>gui.vromfs.bin</code> 包内)。一个完整的界面弹窗通常由三类文本文件配合完成:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>文件后缀</th><th>角色定位</th><th>通俗解释</th></tr></thead><tbody><tr><td><strong><code>.tpl</code></strong></td><td><strong>Handyman 布局模板</strong></td><td>类似 HTML + Mustache 模板(如 <code>gui/missions/wtomapselectormodal.tpl</code>),声明窗口骨架、按钮节点、<code>id</code> 与数据占位符(如 <code>&lt;&lt;wndTitle&gt;&gt;</code>、<code>{{#cards}}...{{/cards}}</code>)。</td></tr><tr><td><strong><code>.css</code></strong></td><td><strong>DaGui 样式表</strong></td><td>定义节点宽高、边距、背景色、字体大小以及自定义状态属性选择器(如 <code>[wtoSelected=yes]</code>)。</td></tr><tr><td><strong><code>.nut</code></strong></td><td><strong>Quirrel 界面逻辑脚本</strong></td><td>战雷使用的类 JS/Lua 强作用域脚本语言(Squirrel 衍生版),继承 <code>BaseGuiHandlerWT</code> 处理按钮点击、渲染 <code>.tpl</code> 并与本地服务器通信。</td></tr></tbody></table></div>
<h4 id="ch-04-zh-客户端界面扩展黄金准则-大块逻辑独立新建-极简增量补丁挂入口">客户端界面扩展黄金准则:「大块逻辑独立新建 + 极简增量补丁挂入口」</h4>
<p>像官方模板 <code>templates/official-map-selector</code> 一样,给游戏做新功能界面的最佳做法是:</p>
<ol><li><strong>把你自己的弹窗 <code>.nut</code>、<code>.tpl</code>、<code>.css</code> 作为新文件放进 <code>client/packs/gui.vromfs.bin/</code></strong>:独立文件与其他模组零冲突、极易维护;</li><li><strong>只用几行 <code>client/gui-patches/</code> 增量补丁修改原版文件</strong>:挂一个入口按钮,并在全局样式表入口 <code>gui/css.css</code> 里注册你的新 <code>.css</code>!</li></ol>
<blockquote><p><strong>必看高频踩坑:新增的独立 <code>.css</code> 不会被 DaGui 自动加载!</strong><br>仅仅把 <code>gui/missions/wtomapselector.css</code> 放进 <code>client/packs/gui.vromfs.bin/</code> 是<strong>不会生效</strong>的!DaGui 只从根入口 <code>gui/css.css</code> 加载样式表,因此你<strong>必须同时在 <code>client/gui-patches/</code> 里给 <code>gui/css.css</code> 打一条补丁</strong>,追加一行 <code>@import &quot;missions\wtomapselector.css&quot;</code>(注意:DaGui 的 <code>gui/css.css</code> 路径相对于 <code>gui/</code> 目录,使用反斜杠 <code>\</code> 且行尾<strong>不写分号</strong>,详见下方 2.2 节真实示例)。</p></blockquote>
<hr>
<h3 id="ch-04-zh-2-client-gui-patches-增量补丁格式与匹配规则">2. <code>client/gui-patches/</code> 增量补丁格式与匹配规则</h3>
<p><code>client/gui-patches/</code> 不仅能改 <code>.nut</code> 脚本,<strong>对 <code>gui.vromfs.bin</code> 里的 <code>.nut</code>、<code>.tpl</code> 和 <code>.css</code> 文本文件完全通用</strong>!每个补丁放在一个含 <code>patch.jsonc</code> 的子目录(支持多层子目录组织):</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>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</code></pre></div>
<h4 id="ch-04-zh-2-1-nut-脚本补丁示例">2.1 <code>.nut</code> 脚本补丁示例</h4>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// Adds a custom entry button to the mode selection panel.
{
&quot;id&quot;: &quot;my-mod/add-button&quot;,
&quot;title&quot;: &quot;Add custom button to mode selector&quot;,
&quot;features&quot;: [],
&quot;variants&quot;: [
{
&quot;written_for&quot;: &quot;2.61.0.58&quot;,
&quot;file&quot;: &quot;scripts/gamemodes/gamemodeselect.nut&quot;,
&quot;edits&quot;: [
{
&quot;find&quot;: &quot;find-imports.nut&quot;,
&quot;replace&quot;: &quot;replace-imports.nut&quot;
},
{
&quot;find&quot;: &quot;find-buttons.nut&quot;,
&quot;replace&quot;: &quot;replace-buttons.nut&quot;
}
]
}
]
}</code></pre></div>
<h4 id="ch-04-zh-2-2-注册独立-css-到-gui-css-css-的真实补丁示例">2.2 注册独立 <code>.css</code> 到 <code>gui/css.css</code> 的真实补丁示例</h4>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// client/gui-patches/my-style/patch.jsonc
{
&quot;id&quot;: &quot;my-mod/register-css&quot;,
&quot;title&quot;: &quot;Include custom stylesheet in gui/css.css&quot;,
&quot;features&quot;: [],
&quot;variants&quot;: [
{
&quot;written_for&quot;: &quot;2.61.0.58&quot;,
&quot;file&quot;: &quot;gui/css.css&quot;,
&quot;edits&quot;: [
{
&quot;find&quot;: &quot;find-css.css&quot;,
&quot;replace&quot;: &quot;replace-css.css&quot;
}
]
}
]
}</code></pre></div>
<p><code>find-css.css</code>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>css</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>@import &quot;missions\mapPreferences.css&quot;</code></pre></div>
<p><code>replace-css.css</code>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>css</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>@import &quot;missions\mapPreferences.css&quot;
@import &quot;missions\wtomapselector.css&quot;</code></pre></div>
<h4 id="ch-04-zh-2-3-匹配规则与大小写注意事项">2.3 匹配规则与大小写注意事项</h4>
<ol><li><strong><code>variant.file</code> 必须全小写、精确区分大小写!</strong> 原版 <code>gui.vromfs.bin</code> 归档内的所有文件路径均为<strong>全小写</strong>(例如 <code>scripts/gamemodes/gamemodeselect.nut</code>、<code>gui/gamemodeselect/gamemodeselect.tpl</code>、<code>gui/css.css</code>)。虽然 Quirrel 代码里的 <code>from &quot;%scripts/gameModes/...&quot;</code> 导入语句不区分大小写,但 <code>gui-patches</code> 构建器在包内查找 <code>variant.file</code> 时做的是<strong>严格区分大小写的精确键匹配</strong>——如果写成驼峰 <code>scripts/gameModes/gameModeSelect.nut</code>,会直接报错 <code>the data pack has no script ...</code>!放进 <code>client/packs/gui.vromfs.bin/</code> 的新增文件也请统一使用全小写路径。</li><li><strong>每条 <code>find</code> 必须唯一命中 1 次</strong>: 每条 <code>edit</code> 的 <code>find</code> 原文片段在目标文件中需要<strong>恰好出现 1 次</strong>(自动兼容 <code>\r\n</code> 与 <code>\n</code> 换行差异);若出现 0 次或 ≥2 次,该补丁会整条跳过并记入 <code>launcher.log</code>,避免半应用写坏脚本。</li><li><strong><code>variants</code> 与 <code>written_for</code> 的真实选择机制</strong>: <code>written_for</code> 只是便于阅读和报错排查的版本标注字符串,构建器<strong>不会</strong>按版本号盲选——它会对当前客户端文件逐一测试 <code>variants</code> 数组里的<strong>全部候选条目</strong>,且要求<strong>有且仅有 1 个 <code>variant</code> 能够完整命中</strong>(0 个命中 = 视为版本不匹配安全跳过;≥2 个同时命中 = 视为变体定义歧义直接拒绝)。</li><li><strong>本地服务器地址占位符 <code>{{LOCAL_ENDPOINT}}</code></strong>: 在任何 <code>replace</code> 文本中写入 <code>{{LOCAL_ENDPOINT}}</code>,构建器都会自动将其替换为当前客户端绑定的本地服务器 <code>127.0.0.1:&lt;端口&gt;</code>(例如拼接内置浏览器 URL <code>http://{{LOCAL_ENDPOINT}}/mods/demo.my-mod/panel</code>)。离线版核心 GUI 补丁永远最先应用,各模组的 <code>gui-patches</code> 在其后按加载顺序依次叠加。</li></ol>
<hr>
<h3 id="ch-04-zh-3-必做检查-编译-sq-exe-并对完整-nut-做字节码校验">3. 必做检查:编译 <code>sq.exe</code> 并对完整 <code>.nut</code> 做字节码校验</h3>
<p>战雷的 Quirrel 脚本在登录阶段预编译加载。如果 <code>.nut</code> 存在以下错误,游戏会在进入机库前<strong>一直卡死在「正在加载」界面</strong>:</p>
<ul><li><strong>词法作用域重名冲突</strong>:局部变量名(<code>let</code> / <code>local</code>)与文件顶部 <code>from &quot;...&quot; import *</code> 导入的常量或原生函数重名;</li><li><strong>前向引用未声明函数</strong>或误用 <strong>Quirrel 保留字</strong>(如 <code>base</code>);</li><li><strong>误用反引号字符串 `<code> </code>...<code> </code><code>**:战雷内置 Quirrel VM 不支持 JS 风格反引号模板字符串,请统一使用 Quirrel 原生插值字符串 **</code>$&quot;hello {name}&quot;`</strong>!</li></ul>
<p>注意:<code>sq.exe --syntax-check</code> 只跑语法树解析,<strong>会漏掉作用域重名和未声明标识符错误</strong>;必须通过 <code>compilestring(...)</code> 触发完整字节码生成检查!</p>
<h4 id="ch-04-zh-3-1-外部模组作者如何自行获取匹配的-sq-exe">3.1 外部模组作者如何自行获取匹配的 <code>sq.exe</code>?</h4>
<p>克隆 Gaijin 官方开源的 <strong><a href="https://github.com/GaijinEntertainment/quirrel" target="_blank" rel="noopener">GaijinEntertainment/quirrel</a></strong> 仓库,检出与 2.61 客户端匹配的提交 <code>19f17df9b6ee43c91ef5c635fd45970ec76c5dbe</code>,用 CMake + Visual Studio(C++17)即可在数秒内编译出 <code>sq.exe</code>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>powershell</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>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
# 产物位于 quirrel-build\bin\Release\sq.exe</code></pre></div>
<h4 id="ch-04-zh-3-2-正确用法-必须对-完整-nut-文件-执行-compilestring">3.2 正确用法:必须对「完整 <code>.nut</code> 文件」执行 <code>compilestring</code></h4>
<blockquote><p><strong>切勿拿半截 <code>replace.nut</code> 片段直接喂给 <code>compilestring</code>!</strong><br><code>replace.nut</code> 只是补丁上下文中的几行代码片段,单独编译必然报语法或未定义变量错误。你必须针对<strong>完整的 <code>.nut</code> 文件</strong>(即你新建的独立 <code>.nut</code> 全文,或者将 <code>find</code>/<code>replace</code> 应用到原版 <code>.nut</code> 之后的完整结果文件)运行检查:</p></blockquote>
<ul><li><strong>如果克隆了 WTOffline 源码仓库</strong>:仓库内的 <code>tools/src/wtotools/gui_check.py</code> 已经封装好全自动导入符号解析与 <code>compilestring</code> 沙箱,可一键对解包的 <code>gui.vromfs.bin</code> 应用补丁并完成全量字节码校验;</li><li><strong>单文件快速自检示例</strong>(将文件内顶部 <code>import</code> 绑定名作为第 3 参数占位表传入 <code>compilestring</code>):</li></ul>
<div class="doc-pre"><div class="doc-pre-head"><span>powershell</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>&amp; &quot;quirrel-build\bin\Release\sq.exe&quot; -e &quot;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')&quot;</code></pre></div>
<hr>
<h3 id="ch-04-zh-4-声明式-exe-补丁-client-exe-patches">4. 声明式 <code>exe</code> 补丁(<code>client/exe-patches/</code>)</h3>
<p>高级模组可以直接复用 WTOffline 本体的 <code>@wto/exepatch</code> 引擎对 <code>win64/aces.exe</code> 做特征码定位补丁。请使用声明式补丁文件,不要直接打包或分发修改后的 <code>aces.exe</code> 可执行文件。</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>client/exe-patches/
└─ my-tweak/
└─ patch.jsonc</code></pre></div>
<p><code>patch.jsonc</code> 结构示例:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// Brief description of what this binary patch changes.
// Why the local server cannot do this alone.
// What happens if this patch is skipped.
{
&quot;id&quot;: &quot;my-tweak&quot;,
&quot;title&quot;: &quot;Example declarative exe patch&quot;,
&quot;features&quot;: [],
&quot;requires&quot;: [],
&quot;variants&quot;: [
{
&quot;written_for&quot;: &quot;2.61.0.58&quot;,
&quot;locate&quot;: {
&quot;kind&quot;: &quot;signature&quot;,
&quot;pattern&quot;: &quot;48 8B ?? ?? ?? ?? ?? 84 C0 74 ??&quot;,
&quot;captures&quot;: []
},
&quot;edit&quot;: {
&quot;offset&quot;: 9,
&quot;asm&quot;: &quot;nop; nop&quot;,
&quot;bytes&quot;: &quot;90 90&quot;,
&quot;expect_original&quot;: &quot;74 ??&quot;,
&quot;fixups&quot;: []
}
}
]
}</code></pre></div>
<h4 id="ch-04-zh-支持的-3-种定位器-locate-kind">支持的 3 种定位器(<code>locate.kind</code>)</h4>
<ul><li><code>signature</code>:字节特征码扫描(支持 <code>??</code> 通配字节与 <code>captures</code> 捕获相对偏移/跳转目标);</li><li><code>string_ref</code>:按代码引用的固定 ASCII 字符串定位,可附加局部指令特征校验;</li><li><code>within</code>:在依赖补丁或锚点所在的函数边界(基于 PE <code>.pdata</code> 异常表起止范围)内搜索局部特征。</li></ul>
<h4 id="ch-04-zh-核心隔离保护与冲突处理">核心隔离保护与冲突处理</h4>
<ol><li><strong>核心离线与隔离补丁永远最先规划并锁定字节区间</strong>(涵盖断网隔离不连 Gaijin、不加载反作弊、存档目录与注册表隔离、禁止拉起官方启动器、本地 TLS/匹配公钥替换等);</li><li><strong>任何模组 <code>exe</code> 补丁只要写入范围与核心补丁重叠 1 个字节,就会被构建器硬拒绝</strong>,并在日志中报错 <code>overlaps protected core patch</code>;</li><li>若两个不同模组的 <code>exe</code> 补丁写入同一段字节,后加载的补丁会被拒绝并明确报出冲突模组 ID;</li><li>若客户端更新后特征码未命中或 <code>expect_original</code> 不匹配,该模组补丁会安全跳过并记入 <code>launcher.log</code>,不会导致离线副本构建崩溃。</li></ol>
</div>
<div class="lang-en">
<h2>04 · Client GUI Patches &amp; Declarative EXE Patches</h2>
<blockquote><p><strong>Experimental Notice</strong>: GUI script patches (<code>gui-patches</code>) and declarative <code>exe</code> patches (<code>exe-patches</code>) depend directly on target client code layout and may require maintenance when the game or core offline patches update.</p></blockquote>
<hr>
<h3 id="ch-04-en-1-plain-language-intro-war-thunder-s-dagui-ui-triad-tpl-css-nut">1. Plain-Language Intro: War Thunder's DaGui UI Triad (<code>.tpl</code> + <code>.css</code> + <code>.nut</code>)</h3>
<p>War Thunder's hangar and lobby screens are powered by Dagor's native <strong>DaGui</strong> framework (packaged inside <code>gui.vromfs.bin</code>). Every screen or modal window combines three plain-text file types:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>Extension</th><th>Role</th><th>Plain-Language Explanation</th></tr></thead><tbody><tr><td><strong><code>.tpl</code></strong></td><td><strong>Handyman Layout Template</strong></td><td>Similar to HTML + Mustache (e.g. <code>gui/missions/wtomapselectormodal.tpl</code>); declares UI containers, buttons, element <code>id</code>s, and data-binding tags (<code>&lt;&lt;wndTitle&gt;&gt;</code>, <code>{{#cards}}...{{/cards}}</code>).</td></tr><tr><td><strong><code>.css</code></strong></td><td><strong>DaGui Stylesheet</strong></td><td>Controls widths, heights, margins, colors, fonts, and custom attribute state selectors (such as <code>[wtoSelected=yes]</code>).</td></tr><tr><td><strong><code>.nut</code></strong></td><td><strong>Quirrel UI Script</strong></td><td>War Thunder's statically-scoped scripting language (derived from Squirrel); subclasses <code>BaseGuiHandlerWT</code> to render <code>.tpl</code> views, handle button clicks, and call local server RPCs.</td></tr></tbody></table></div>
<h4 id="ch-04-en-best-practice-ui-pattern-standalone-files-for-logic-minimal-patch-for-entry-hook">Best-Practice UI Pattern: &quot;Standalone Files for Logic + Minimal Patch for Entry Hook&quot;</h4>
<p>Just like the bundled <code>templates/official-map-selector</code> mod, the cleanest way to add new UI is:</p>
<ol><li><strong>Place your new standalone <code>.nut</code>, <code>.tpl</code>, and <code>.css</code> files under <code>client/packs/gui.vromfs.bin/</code></strong>: standalone files have zero collision risk with other mods and survive game updates cleanly;</li><li><strong>Use minimal <code>client/gui-patches/</code> edits on stock files</strong>: wire a button into an existing screen and register your stylesheet in <code>gui/css.css</code>!</li></ol>
<blockquote><p><strong>Critical Rule: Standalone <code>.css</code> Files Are NOT Auto-Loaded by DaGui!</strong><br>Dropping <code>gui/missions/wtomapselector.css</code> into <code>client/packs/gui.vromfs.bin/</code> alone <strong>has no effect</strong>! DaGui loads stylesheets solely through the root manifest <code>gui/css.css</code>, so you <strong>must also patch <code>gui/css.css</code> via <code>client/gui-patches/</code></strong> to append <code>@import &quot;missions\wtomapselector.css&quot;</code> (note: paths inside <code>gui/css.css</code> are relative to <code>gui/</code>, use backslashes <code>\</code>, and have <strong>no trailing semicolon</strong>—see the real example in Section 2.2 below).</p></blockquote>
<hr>
<h3 id="ch-04-en-2-client-gui-patches-format-matching-rules">2. <code>client/gui-patches/</code> Format &amp; Matching Rules</h3>
<p><code>client/gui-patches/</code> is <strong>not limited to <code>.nut</code> files—it works identically on <code>.nut</code> scripts, <code>.tpl</code> templates, and <code>.css</code> stylesheets</strong> inside <code>gui.vromfs.bin</code>! Each patch lives in a folder containing <code>patch.jsonc</code> (nested subdirectories are supported):</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>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</code></pre></div>
<h4 id="ch-04-en-2-1-nut-script-patch-example">2.1 <code>.nut</code> Script Patch Example</h4>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// Adds a custom entry button to the mode selection panel.
{
&quot;id&quot;: &quot;my-mod/add-button&quot;,
&quot;title&quot;: &quot;Add custom button to mode selector&quot;,
&quot;features&quot;: [],
&quot;variants&quot;: [
{
&quot;written_for&quot;: &quot;2.61.0.58&quot;,
&quot;file&quot;: &quot;scripts/gamemodes/gamemodeselect.nut&quot;,
&quot;edits&quot;: [
{
&quot;find&quot;: &quot;find-imports.nut&quot;,
&quot;replace&quot;: &quot;replace-imports.nut&quot;
},
{
&quot;find&quot;: &quot;find-buttons.nut&quot;,
&quot;replace&quot;: &quot;replace-buttons.nut&quot;
}
]
}
]
}</code></pre></div>
<h4 id="ch-04-en-2-2-real-example-registering-a-standalone-css-in-gui-css-css">2.2 Real Example: Registering a Standalone <code>.css</code> in <code>gui/css.css</code></h4>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// client/gui-patches/my-style/patch.jsonc
{
&quot;id&quot;: &quot;my-mod/register-css&quot;,
&quot;title&quot;: &quot;Include custom stylesheet in gui/css.css&quot;,
&quot;features&quot;: [],
&quot;variants&quot;: [
{
&quot;written_for&quot;: &quot;2.61.0.58&quot;,
&quot;file&quot;: &quot;gui/css.css&quot;,
&quot;edits&quot;: [
{
&quot;find&quot;: &quot;find-css.css&quot;,
&quot;replace&quot;: &quot;replace-css.css&quot;
}
]
}
]
}</code></pre></div>
<p><code>find-css.css</code>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>css</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>@import &quot;missions\mapPreferences.css&quot;</code></pre></div>
<p><code>replace-css.css</code>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>css</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>@import &quot;missions\mapPreferences.css&quot;
@import &quot;missions\wtomapselector.css&quot;</code></pre></div>
<h4 id="ch-04-en-2-3-four-critical-path-variant-rules-must-read">2.3 Four Critical Path &amp; Variant Rules (Must-Read)</h4>
<ol><li><strong><code>variant.file</code> Must Be All Lowercase &amp; Exact Case-Sensitive!</strong> Every file path inside stock <code>gui.vromfs.bin</code> is <strong>all lowercase</strong> (e.g. <code>scripts/gamemodes/gamemodeselect.nut</code>, <code>gui/gamemodeselect/gamemodeselect.tpl</code>, <code>gui/css.css</code>). Even though Quirrel <code>from &quot;%scripts/gameModes/...&quot;</code> imports are case-insensitive at runtime, the <code>gui-patches</code> builder looks up <code>variant.file</code> in the archive map via <strong>exact case-sensitive string match</strong>—writing camelCase like <code>scripts/gameModes/gameModeSelect.nut</code> fails immediately with <code>the data pack has no script ...</code>! Keep added files under <code>client/packs/gui.vromfs.bin/</code> all lowercase as well.</li><li><strong>Every <code>find</code> Snippet Must Match Exactly Once</strong>: Each <code>edit</code>'s <code>find</code> text must occur <strong>uniquely once</strong> in the target file (<code>\r\n</code> vs <code>\n</code> line endings are normalized automatically). If it occurs 0 times or ≥2 times, the entire patch is skipped safely and logged to <code>launcher.log</code> without half-applying edits.</li><li><strong>How <code>variants</code> and <code>written_for</code> Actually Work</strong>: <code>written_for</code> is purely an informational version label for logs and diagnostics. At build time, the builder tests <strong>all</strong> entries in <code>variants</code> against the client archive and requires <strong>an exact single match</strong> (<code>1</code> matching variant applies; <code>0</code> matches skips safely as a build mismatch; <code>≥2</code> simultaneous matches rejects the patch as an ambiguous variant definition).</li><li><strong><code>{{LOCAL_ENDPOINT}}</code> Placeholder</strong>: Any occurrence of <code>{{LOCAL_ENDPOINT}}</code> in <code>replace</code> text is automatically expanded to the client's bound local server <code>127.0.0.1:&lt;port&gt;</code> (for example <code>http://{{LOCAL_ENDPOINT}}/mods/demo.my-mod/panel</code> for embedded browser pages). Core offline GUI patches always run first; mod <code>gui-patches</code> run afterward in load order.</li></ol>
<hr>
<h3 id="ch-04-en-3-mandatory-check-building-sq-exe-full-quirrel-bytecode-verification">3. Mandatory Check: Building <code>sq.exe</code> &amp; Full Quirrel Bytecode Verification</h3>
<p>War Thunder pre-compiles Quirrel UI scripts during login. Any of the following mistakes in a <code>.nut</code> file will cause the client to <strong>hang indefinitely on the &quot;Loading&quot; screen</strong>:</p>
<ul><li><strong>Lexical scope name collisions</strong>: declaring a <code>let</code> / <code>local</code> variable that shadows a symbol imported via <code>from &quot;...&quot; import *</code> at the top of the file;</li><li><strong>Forward references to undeclared functions</strong> or accidental use of <strong>Quirrel reserved words</strong> (such as <code>base</code>);</li><li><strong>JS-style backtick strings (`<code> </code>...<code> </code><code>)**: unsupported by War Thunder's Quirrel VM—always use Quirrel's native string interpolation **</code>$&quot;hello {name}&quot;`</strong> instead!</li></ul>
<p>Note: <code>sq.exe --syntax-check</code> runs AST parsing only and <strong>misses lexical collisions and undeclared identifiers</strong>—you must invoke <code>compilestring(...)</code> so the full bytecode generator runs!</p>
<h4 id="ch-04-en-3-1-how-external-modders-build-a-matching-sq-exe">3.1 How External Modders Build a Matching <code>sq.exe</code></h4>
<p>Clone Gaijin's open-source <strong><a href="https://github.com/GaijinEntertainment/quirrel" target="_blank" rel="noopener">GaijinEntertainment/quirrel</a></strong> repository, check out commit <code>19f17df9b6ee43c91ef5c635fd45970ec76c5dbe</code> (matching 2.61 clients), and build <code>sq</code> with CMake + Visual Studio (C++17):</p>
<div class="doc-pre"><div class="doc-pre-head"><span>powershell</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>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</code></pre></div>
<h4 id="ch-04-en-3-2-run-compilestring-on-a-complete-nut-file-not-a-partial-snippet">3.2 Run <code>compilestring</code> on a <strong>Complete <code>.nut</code> File</strong> (Not a Partial Snippet)</h4>
<blockquote><p><strong>Note</strong>: Pass a complete <code>.nut</code> file to <code>compilestring</code> rather than an isolated <code>replace.nut</code> fragment.<br><code>replace.nut</code> is only an in-place snippet and will fail out of context. Always run <code>compilestring</code> against a <strong>complete <code>.nut</code> file</strong>—either your standalone <code>.nut</code> script, or the full stock <code>.nut</code> file <strong>after</strong> applying your <code>find</code>/<code>replace</code> edits:</p></blockquote>
<ul><li><strong>If you cloned the WTOffline repo</strong>: <code>tools/src/wtotools/gui_check.py</code> automatically resolves <code>gui.vromfs.bin</code> module exports, applies your <code>gui-patches</code>, and runs <code>compilestring</code> with stub bindings across every touched file;</li><li><strong>Standalone full-file check example</strong> (pass a bindings table as the 3rd argument to <code>compilestring</code> if your file uses top-level <code>from &quot;...&quot; import ...</code> bindings):</li></ul>
<div class="doc-pre"><div class="doc-pre-head"><span>powershell</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>&amp; &quot;quirrel-build\bin\Release\sq.exe&quot; -e &quot;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')&quot;</code></pre></div>
<hr>
<h3 id="ch-04-en-4-declarative-exe-patches-client-exe-patches">4. Declarative EXE Patches (<code>client/exe-patches/</code>)</h3>
<p>Advanced mods can reuse WTOffline's <code>@wto/exepatch</code> engine to apply signature-located binary patches to <code>win64/aces.exe</code>. Use declarative patch files instead of packaging or distributing modified <code>aces.exe</code> binaries.</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>client/exe-patches/
└─ my-tweak/
└─ patch.jsonc</code></pre></div>
<p>Example <code>patch.jsonc</code>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// Brief description of what this binary patch changes.
// Why the local server cannot do this alone.
// What happens if this patch is skipped.
{
&quot;id&quot;: &quot;my-tweak&quot;,
&quot;title&quot;: &quot;Example declarative exe patch&quot;,
&quot;features&quot;: [],
&quot;requires&quot;: [],
&quot;variants&quot;: [
{
&quot;written_for&quot;: &quot;2.61.0.58&quot;,
&quot;locate&quot;: {
&quot;kind&quot;: &quot;signature&quot;,
&quot;pattern&quot;: &quot;48 8B ?? ?? ?? ?? ?? 84 C0 74 ??&quot;,
&quot;captures&quot;: []
},
&quot;edit&quot;: {
&quot;offset&quot;: 9,
&quot;asm&quot;: &quot;nop; nop&quot;,
&quot;bytes&quot;: &quot;90 90&quot;,
&quot;expect_original&quot;: &quot;74 ??&quot;,
&quot;fixups&quot;: []
}
}
]
}</code></pre></div>
<h4 id="ch-04-en-supported-locators-locate-kind">Supported Locators (<code>locate.kind</code>)</h4>
<ul><li><code>signature</code>: byte pattern scan supporting <code>??</code> wildcards and <code>captures</code> for displacements / relative branch targets;</li><li><code>string_ref</code>: locates code referencing a fixed ASCII string literal, with optional local instruction verification;</li><li><code>within</code>: searches inside the PE <code>.pdata</code> function boundaries of a required patch or anchor site.</li></ul>
<h4 id="ch-04-en-core-isolation-protection-conflict-handling">Core Isolation Protection &amp; Conflict Handling</h4>
<ol><li><strong>Core offline &amp; isolation patches are always planned first and their byte ranges are locked</strong> (covering Gaijin network block, anti-cheat bypass in offline copy, save/registry isolation, launcher suppression, and local TLS/matching keys);</li><li><strong>Any mod <code>exe</code> patch overlapping even 1 byte of a core patch is hard-rejected</strong> with <code>overlaps protected core patch</code> in <code>launcher.log</code>;</li><li>If two mods' <code>exe</code> patches write to overlapping byte ranges, the later mod's patch is rejected with the conflicting mod ID;</li><li>If a signature or <code>expect_original</code> check fails on a newer game version, that mod patch is skipped cleanly and logged to <code>launcher.log</code> without breaking the offline copy build.</li></ol>
</div>
<div class="doc-pager">
<a class="doc-pager-btn" href="#ch-03" data-chapter="ch-03"><span class="doc-pager-label"><span class="lang-zh">← 上一章</span><span class="lang-en">← Previous</span></span><span class="doc-pager-title"><span class="lang-zh">03 · 自定义 3D 模型载具</span><span class="lang-en">03 · Custom 3D Vehicles</span></span></a>
<a class="doc-pager-btn next" href="#ch-05" data-chapter="ch-05"><span class="doc-pager-label"><span class="lang-zh">下一章 →</span><span class="lang-en">Next →</span></span><span class="doc-pager-title"><span class="lang-zh">05 · 服务端零代码调参</span><span class="lang-en">05 · Server Tuning &amp; $listOps</span></span></a>
</div>
</article>
<article class="doc-section doc-chapter" id="ch-05">
<div class="lang-zh">
<h2>05 · 服务端零代码数值叠加(Tuning)</h2>
<p>本地服务器把离线版自定的对局倍率、房间与 AI 数量、商城礼包、市场物价、战利品箱、兑换码、初始存档货币、联队等规则统一收纳在 <strong>12 份 <code>.jsonc</code> 配置文件</strong>中。模组作者一行代码都不用写,只需在 <code>server/tuning/</code> 下放置同名 <code>.jsonc</code> 文件即可按字段精准叠加覆盖。</p>
<blockquote><p>在线浏览全部 12 份内置默认配置文件全文与注释:<br><strong><a href="https://git.wto-project.net/Sh3ll_in_Sh3ll/WT-Offline/src/branch/main/apps/server/tuning" target="_blank" rel="noopener">WT-Offline <code>apps/server/tuning/</code> 源码目录</a></strong></p></blockquote>
<hr>
<h3 id="ch-05-zh-1-多层合并优先级-注意启动器玩家覆盖">1. 多层合并优先级(注意启动器玩家覆盖!)</h3>
<p>每次启动本地服务器时,同名的 <code>tuning/&lt;名称&gt;.jsonc</code> 按以下顺序从低到高逐层合并(后一层覆盖前一层):</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>1. 离线版内置默认配置(apps/server/tuning/&lt;名称&gt;.jsonc)
2. 已启用模组 1 的 server/tuning/&lt;名称&gt;.jsonc
3. 已启用模组 2 的 server/tuning/&lt;名称&gt;.jsonc
...(按启动器「模组」页从上到下顺序依次叠加)
N. 玩家在启动器「数值」页保存的个人覆盖(&lt;客户端数据目录&gt;/tuning/&lt;名称&gt;.jsonc,优先级最高)</code></pre></div>
<ul><li><strong>排查提示</strong>:由于<strong>玩家在启动器「数值(Tuning)」页手动改过的项优先级高于模组</strong>,如果测试模组时发现某个 <code>battle.jsonc</code> 或 <code>new-profile.jsonc</code> 字段修改没有生效,可以先检查该客户端的启动器「数值」页是否之前手动改过同一项(恢复默认或查看 <code>&lt;数据目录&gt;/tuning/*.jsonc</code> 即可)。</li><li>所有合并后的最终结果在服务器启动时都会经过严格类型与数值范围校验;字段名写错或数值越界时会直接报出文件名、字段名与期望范围。</li></ul>
<hr>
<h3 id="ch-05-zh-2-全部-12-份可叠加配置文件一览">2. 全部 12 份可叠加配置文件一览</h3>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>文件名</th><th>管辖内容</th><th>常用结构类型</th><th>典型模组用途</th></tr></thead><tbody><tr><td><code>battle.jsonc</code></td><td>银狮/研发倍率、房间人数、AI 数量与重生次数、分房跨度 <code>brSpreadMrank</code>、子模式概率、攻击无人机出生分</td><td>平面键值对象</td><td>自定义收益倍率、调整 16v16 人数、放宽/收紧分房跨度、改 AI 重生次数</td></tr><tr><td><code>battle-economy.jsonc</code></td><td>各类战斗行为基价与对局结算经济公式参数</td><td>嵌套键值对象</td><td>精细调整击杀、助攻、占点收益占比</td></tr><tr><td><code>store.jsonc</code></td><td>金鹰包、银狮包、高账档位、以及 <code>vehiclePacks</code>(含 <code>multiVehiclePacks</code> 列表、<code>byRank</code> 列表、<code>byVehicle</code> 字典)</td><td>列表(<code>$listOps</code>)+ 字典合并</td><td>为新增 <code>gift</code> 载具定礼包价、打包自定义多车组合包</td></tr><tr><td><code>marketplace.jsonc</code></td><td>交易所载具券与涂装券参考价、稀有度与手续费</td><td>嵌套对象 + 字典合并</td><td>调整交易所物价、给新增市场载具券定价</td></tr><tr><td><code>trophies.jsonc</code></td><td>经典战利品箱 <code>supplyTrophies</code>(银狮箱、老兵箱)与活动车金鹰直购价 <code>directVehicles</code></td><td>列表(<code>$listOps</code>)+ 对象</td><td>新增自定义银狮/金鹰抽卡箱、调整稀有车掉率权重</td></tr><tr><td><code>supply-chests.jsonc</code></td><td>新版外部库存补给箱与奖池配置</td><td>列表(<code>$listOps</code>)+ 对象</td><td>新增自制外部库存补给箱</td></tr><tr><td><code>recycling.jsonc</code></td><td>道具回收与零件再合成配方</td><td>嵌套键值对象</td><td>修改道具回收比例与产出权重</td></tr><tr><td><code>redeem-codes.jsonc</code></td><td>高账/GJN 前缀码规则与一次性固定兑换码 <code>fixedCodes</code></td><td>对象 + 字典合并</td><td>为你的整合包添加专属福利兑换码</td></tr><tr><td><code>new-profile.jsonc</code></td><td>新建存档初始银狮、金鹰与 GJN 余额</td><td>平面键值对象</td><td>制作高起点爽玩预设或硬核白手起家预设</td></tr><tr><td><code>research.jsonc</code></td><td>自动挑选默认下一研发目标策略</td><td>平面键值对象</td><td>调整自动研发接续行为</td></tr><tr><td><code>clans.jsonc</code></td><td>联队人数上限、活跃度与预置离线联队列表</td><td>对象 + 列表(<code>$listOps</code>)</td><td>添加模组专属预置联队</td></tr><tr><td><code>limits.jsonc</code></td><td>单次购买道具数量上限、战报/日志保留上限</td><td>平面键值对象</td><td>提高批量开箱/购买上限或历史战报条数</td></tr></tbody></table></div>
<hr>
<h3 id="ch-05-zh-3-对象字典合并-vs-列表增量语法-listops">3. 对象字典合并 vs 列表增量语法(<code>$listOps</code>)</h3>
<p>理解合并器的两条规则,就能避免多模组互相覆盖:</p>
<ol><li><strong>普通对象 / 键值字典(如 <code>vehiclePacks.byVehicle</code>、<code>redeem-codes.jsonc</code> 的 <code>fixedCodes</code>)→ 自动按字段名递归合并</strong>: 你只需要写出新增或要改的那几个键(例如只写 <code>&quot;my_new_tank&quot;: { ... }</code>),其他原有的几百个键会自动保留,<strong>不需要也不能</strong>套 <code>$listOps</code>!</li><li><strong>JSON 数组字段(如 <code>vehiclePacks.multiVehiclePacks</code>、<code>goldenEaglePacks</code>、<code>supplyTrophies</code>)→ 默认整数组替换,叠加请用 <code>{ &quot;$listOps&quot;: [...] }</code></strong>: 如果你直接写 <code>&quot;multiVehiclePacks&quot;: [ ... ]</code>,它会把原版和前序模组的多车礼包清空替换掉!为了让多个模组安全共存,请把该数组属性写成<strong>仅包含唯一键 <code>&quot;$listOps&quot;</code> 的包装对象</strong>(注意:该对象内<strong>不能有除 <code>&quot;$listOps&quot;</code> 以外的任何其他平级字段</strong>,否则不会被识别为列表增量指令!):</li></ol>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// 正确示例:server/tuning/store.jsonc
// 注意:multiVehiclePacks、byRank、byVehicle 均嵌套在顶层 &quot;vehiclePacks&quot; 对象内部,且价格字段名为 &quot;gjn&quot;!
{
&quot;vehiclePacks&quot;: {
// ① multiVehiclePacks 是数组 → 用 { &quot;$listOps&quot;: [...] } 无损追加/修改/删除
&quot;multiVehiclePacks&quot;: {
&quot;$listOps&quot;: [
{
&quot;op&quot;: &quot;append&quot;,
&quot;items&quot;: [
{
&quot;id&quot;: &quot;mod_modern_duo_pack&quot;,
&quot;title&quot;: { &quot;en&quot;: &quot;Modern Duo Pack&quot;, &quot;zh&quot;: &quot;现代双车组合包&quot; },
&quot;gjn&quot;: 49.99,
&quot;goldenEagles&quot;: 2000,
&quot;premiumDays&quot;: 15,
&quot;vehicles&quot;: [&quot;us_m1a2_sep2_abrams&quot;, &quot;germ_leopard_2a7v&quot;]
}
]
},
{
&quot;op&quot;: &quot;upsertBy&quot;,
&quot;key&quot;: &quot;id&quot;,
&quot;item&quot;: {
&quot;id&quot;: &quot;wto_pack_two_fronts&quot;,
&quot;gjn&quot;: 19.99
}
},
{
&quot;op&quot;: &quot;removeBy&quot;,
&quot;key&quot;: &quot;id&quot;,
&quot;value&quot;: &quot;some_unwanted_pack_id&quot;
}
]
},
// ② byVehicle 是键值字典(非数组)→ 直接写载具 ID 即可递归合并,不要写 $listOps!
&quot;byVehicle&quot;: {
&quot;us_mbt_demo&quot;: {
&quot;gjn&quot;: 59.99,
&quot;goldenEagles&quot;: 2000,
&quot;premiumDays&quot;: 15
}
}
}
}</code></pre></div>
<h4 id="ch-05-zh-支持的全部-4-种-listops-操作">支持的全部 4 种 <code>$listOps</code> 操作</h4>
<ul><li><code>append</code>:<code>{ &quot;op&quot;: &quot;append&quot;, &quot;items&quot;: [ ... ] }</code> — 将 <code>items</code> 依次追加到当前数组末尾;</li><li><code>prepend</code>:<code>{ &quot;op&quot;: &quot;prepend&quot;, &quot;items&quot;: [ ... ] }</code> — 将 <code>items</code> 插入到当前数组开头;</li><li><code>upsertBy</code>:<code>{ &quot;op&quot;: &quot;upsertBy&quot;, &quot;key&quot;: &quot;&lt;唯一键名&gt;&quot;, &quot;item&quot;: { ... } }</code> — 在数组中查找 <code>[key] === item[key]</code> 的首项,找到则按对象递归合并局部字段,找不到则追加到末尾;</li><li><code>removeBy</code>:<code>{ &quot;op&quot;: &quot;removeBy&quot;, &quot;key&quot;: &quot;&lt;键名&gt;&quot;, &quot;value&quot;: &lt;匹配值&gt; }</code> — 删除数组中全部 <code>[key] === value</code> 的条目。</li></ul>
<hr>
<h3 id="ch-05-zh-4-高频配置文件真实字段速查与即用范例">4. 高频配置文件真实字段速查与即用范例</h3>
<p>以下字段名均已对照 <code>apps/server/tuning/*.jsonc</code> 与服务端校验器逐一核实,可直接复制进你的 <code>server/tuning/</code>:</p>
<h4 id="ch-05-zh-4-1-battle-jsonc-对局收益-人数-分房跨度与-ai-重生">4.1 <code>battle.jsonc</code>(对局收益、人数、分房跨度与 AI 重生)</h4>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;rewardMultiplierSilverLions&quot;: 2.0, // 银狮结算总倍率(默认 1.0)
&quot;rewardMultiplierResearchPoints&quot;: 2.0, // 研发点结算总倍率(默认 1.0)
&quot;maxPlayers&quot;: 32, // 房间总席位(16v16 = 32:1 名本地玩家 + 最多 31 名 AI)
&quot;maxBots&quot;: 31, // AI 机器人上限(默认 31)
&quot;smallTeamsMaxPlayers&quot;: 16, // 战术天空(small_teams_)小队空战总人数(默认 16 = 8v8)
&quot;subModeChance&quot;: 0.5, // 同时勾选子模式与常规模式时抽中子模式的概率(0..1)
&quot;brSpreadMrank&quot;: 3, // 分房权重浮动跨度(每 3 级 mrank = ±1.0 BR;设为 0 即严格同权重分房)
&quot;botPoolLimitPerType&quot;: 80, // 单兵种写入 customBots 的候选载具上限
&quot;tankBotRespawns&quot;: 3, // 陆战多槽位对局每个 AI 的最大重生次数
&quot;airBotRespawns&quot;: 2, // 空战多槽位对局每个 AI 的最大重生次数
&quot;strikeUcavSpawnScore&quot;: 750, // 陆战历史攻击无人机出生所需分数(默认 750)
&quot;nuclearEscalationStrategicBombers&quot;: true // 空战核升级子模式是否启用战略核轰炸机(B-52H / Tu-95M)
}</code></pre></div>
<h4 id="ch-05-zh-4-2-store-jsonc-本地网页商店与游戏内金鹰-银狮-礼包定价">4.2 <code>store.jsonc</code>(本地网页商店与游戏内金鹰/银狮/礼包定价)</h4>
<ul><li>顶层共 5 个字段:<code>goldenEaglePacks</code>(数组)、<code>silverLionPacks</code>(数组)、<code>premiumForGoldenEagles</code>(数组)、<code>premiumForGjn</code>(数组)、以及 <strong><code>vehiclePacks</code>(对象)</strong>;</li><li><code>vehiclePacks</code> 下含 3 个子字段:
<ul><li><code>multiVehiclePacks</code>(数组,用 <code>$listOps</code>):每项必填 <code>id</code>、<code>vehicles</code>(非空不重复载具 ID 数组)、<code>gjn</code>(最低 <code>0.01</code>)、<code>goldenEagles</code>(整数 <code>≥0</code>)、<code>premiumDays</code>(整数 <code>≥0</code>),可选 <code>silverLions</code>(整数 <code>≥0</code>),且<strong>命名方式必须三选一</strong>——自定义双语标题 <code>&quot;title&quot;: { &quot;en&quot;: &quot;...&quot;, &quot;zh&quot;: &quot;...&quot; }</code>、复用科技树折叠组名 <code>&quot;groupKey&quot;: &quot;shop/group/...&quot;</code>、或国家新手包 <code>&quot;starter&quot;: true</code>;</li><li><code>byRank</code>(数组,按 <code>upToRank</code> 升序兜底单车礼包价):每项含 <code>upToRank</code>、<code>gjn</code>、<code>goldenEagles</code>、<code>premiumDays</code>(可选 <code>silverLions</code>);</li><li><code>byVehicle</code>(键值字典):键为 <code>wpcost.blk</code> 中带 <code>gift</code> 的载具 ID,值为 <code>{ &quot;gjn&quot;?, &quot;goldenEagles&quot;?, &quot;premiumDays&quot;?, &quot;silverLions&quot;? }</code>(未填字段自动回退该车 <code>rank</code> 对应的 <code>byRank</code> 档位)。</li></ul></li></ul>
<h4 id="ch-05-zh-4-3-new-profile-jsonc-新建存档开局货币">4.3 <code>new-profile.jsonc</code>(新建存档开局货币)</h4>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;silverLions&quot;: 1000000, // 初始银狮(默认 150000)
&quot;goldenEagles&quot;: 5000, // 初始金鹰(默认 500)
&quot;gjn&quot;: 50 // 初始 GJN 余额,支持最多两位小数(默认 0)
}</code></pre></div>
<h4 id="ch-05-zh-4-4-redeem-codes-jsonc-添加模组专属一次性兑换码">4.4 <code>redeem-codes.jsonc</code>(添加模组专属一次性兑换码)</h4>
<p><code>fixedCodes</code> 是键值字典(每个存档每个兑换码限领一次,不区分大小写,未填奖励项默认为 <code>0</code>),直接按兑换码名合并即可:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;fixedCodes&quot;: {
&quot;MYMOD-GIFT-2026&quot;: {
&quot;silverLions&quot;: 500000,
&quot;goldenEagles&quot;: 1000,
&quot;premiumDays&quot;: 7,
&quot;gjn&quot;: 25
}
}
}</code></pre></div>
<h4 id="ch-05-zh-4-5-trophies-jsonc-新增自定义银狮-金鹰战利品抽卡箱">4.5 <code>trophies.jsonc</code>(新增自定义银狮/金鹰战利品抽卡箱)</h4>
<p><code>supplyTrophies</code> 是数组,用 <code>$listOps</code> 追加新箱子,游戏客户端会自动按各奖品的 <code>weight</code> / <code>weightTotal</code> / <code>weightEach</code> 计算并展示公示掉率:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;supplyTrophies&quot;: {
&quot;$listOps&quot;: [
{
&quot;op&quot;: &quot;append&quot;,
&quot;items&quot;: [
{
&quot;id&quot;: &quot;mod_lucky_trophy&quot;,
&quot;iconStyle&quot;: &quot;big_chest&quot;,
&quot;silverLions&quot;: 100000,
&quot;goldenEagles&quot;: 0,
&quot;prizes&quot;: [
{ &quot;silverLions&quot;: 50000, &quot;weight&quot;: 50 },
{ &quot;silverLions&quot;: 250000, &quot;weight&quot;: 20 },
{ &quot;goldenEagles&quot;: 200, &quot;weight&quot;: 10 },
{ &quot;item&quot;: &quot;item_universal_spare&quot;, &quot;count&quot;: 3, &quot;weight&quot;: 15 },
{ &quot;eventVehicles&quot;: { &quot;minRank&quot;: 3, &quot;maxRank&quot;: 7, &quot;pick&quot;: 6 }, &quot;weightTotal&quot;: 5 }
]
}
]
}
]
}
}</code></pre></div>
</div>
<div class="lang-en">
<h2>05 · Server Code-Free Tuning Overlays</h2>
<p>The local server consolidates all offline-defined battle multipliers, session/bot capacities, web store bundles, marketplace prices, trophy chests, redeem codes, starter balances, and clan rules into <strong>12 <code>.jsonc</code> configuration files</strong>. Mod authors can overlay individual fields without writing a single line of code simply by placing matching <code>.jsonc</code> files inside <code>server/tuning/</code>.</p>
<blockquote><p>Browse all 12 default tuning files with full comments online:<br><strong><a href="https://git.wto-project.net/Sh3ll_in_Sh3ll/WT-Offline/src/branch/main/apps/server/tuning" target="_blank" rel="noopener">WT-Offline <code>apps/server/tuning/</code> Source Directory</a></strong></p></blockquote>
<hr>
<h3 id="ch-05-en-1-multi-layer-merge-precedence-watch-out-for-launcher-player-overrides">1. Multi-Layer Merge Precedence (Watch Out for Launcher Player Overrides!)</h3>
<p>Whenever the local server starts, each <code>tuning/&lt;name&gt;.jsonc</code> file is merged from lowest to highest priority (later layers override earlier ones):</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>1. Shipped offline defaults (apps/server/tuning/&lt;name&gt;.jsonc)
2. Enabled Mod 1's server/tuning/&lt;name&gt;.jsonc
3. Enabled Mod 2's server/tuning/&lt;name&gt;.jsonc
... (applied top-to-bottom in Launcher &quot;Mods&quot; load order)
N. Player overrides saved in the Launcher &quot;Tuning&quot; tab (&lt;dataFolder&gt;/tuning/&lt;name&gt;.jsonc — HIGHEST PRIORITY!)</code></pre></div>
<ul><li><strong>Crucial Debugging Tip</strong>: Because <strong>player overrides saved in the Launcher's &quot;Tuning&quot; tab take highest priority</strong>, if a field in your mod's <code>battle.jsonc</code> or <code>new-profile.jsonc</code> appears to be ignored during testing, check whether your test client has a manual override saved in the Launcher <strong>Tuning</strong> tab (<code>&lt;dataFolder&gt;/tuning/*.jsonc</code>) and reset that field to default!</li><li>Every merged configuration is validated strictly for types and numeric bounds at server startup; unknown keys or out-of-range numbers immediately report the exact file, key, and expected constraint.</li></ul>
<hr>
<h3 id="ch-05-en-2-all-12-overlayable-tuning-files-at-a-glance">2. All 12 Overlayable Tuning Files at a Glance</h3>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>File Name</th><th>Governs</th><th>Merge Structure</th><th>Typical Mod Use Cases</th></tr></thead><tbody><tr><td><code>battle.jsonc</code></td><td>SL/RP multipliers, room size, AI bot count &amp; respawns, <code>brSpreadMrank</code>, sub-mode chance, Strike UCAV spawn score</td><td>Flat key-value object</td><td>Custom reward rates, 16v16 capacity tweaks, tighter/wider BR spread, bot respawn counts</td></tr><tr><td><code>battle-economy.jsonc</code></td><td>Base action prices and battle settlement economy curves</td><td>Nested key-value object</td><td>Rebalance kills vs captures vs assists rewards</td></tr><tr><td><code>store.jsonc</code></td><td>GE packs, SL packs, Premium tiers, and <code>vehiclePacks</code> (<code>multiVehiclePacks</code> list, <code>byRank</code> list, <code>byVehicle</code> map)</td><td>Lists (<code>$listOps</code>) + map merge</td><td>Price custom <code>gift</code> vehicles, create custom multi-vehicle bundles</td></tr><tr><td><code>marketplace.jsonc</code></td><td>Marketplace vehicle/skin coupon reference prices, rarity tiers &amp; fees</td><td>Nested object + map merge</td><td>Adjust market economy or price custom market coupons</td></tr><tr><td><code>trophies.jsonc</code></td><td>Classic <code>supplyTrophies</code> (SL chest, Veteran chest) &amp; <code>directVehicles</code> GE buyout price</td><td>List (<code>$listOps</code>) + object</td><td>Add custom gacha chests, tweak rare vehicle drop weights</td></tr><tr><td><code>supply-chests.jsonc</code></td><td>External-inventory supply chests and drop pools</td><td>List (<code>$listOps</code>) + object</td><td>Add custom external-inventory chests</td></tr><tr><td><code>recycling.jsonc</code></td><td>Item recycling and crafting/re-roll recipes</td><td>Nested key-value object</td><td>Customize item recycling ratios and output weights</td></tr><tr><td><code>redeem-codes.jsonc</code></td><td>Dynamic Premium/GJN code prefixes and one-time <code>fixedCodes</code></td><td>Object + map merge</td><td>Add custom promo redeem codes for your modpack</td></tr><tr><td><code>new-profile.jsonc</code></td><td>Starting Silver Lions, Golden Eagles, and GJN balances for new saves</td><td>Flat key-value object</td><td>High-resource sandbox presets or zero-balance hardcore presets</td></tr><tr><td><code>research.jsonc</code></td><td>Automatic default next-research target selection</td><td>Flat key-value object</td><td>Customize auto-selected research behavior</td></tr><tr><td><code>clans.jsonc</code></td><td>Squadron member caps, activity rules, and preset offline squadrons</td><td>Object + list (<code>$listOps</code>)</td><td>Add custom preset squadrons</td></tr><tr><td><code>limits.jsonc</code></td><td>Max items per purchase, battle report &amp; log retention caps</td><td>Flat key-value object</td><td>Raise bulk-purchase limits or retained battle log history</td></tr></tbody></table></div>
<hr>
<h3 id="ch-05-en-3-recursive-key-map-merge-vs-additive-list-operations-listops">3. Recursive Key-Map Merge vs Additive List Operations (<code>$listOps</code>)</h3>
<p>Understanding how the merger treats objects versus arrays prevents mods from clobbering one another:</p>
<ol><li><strong>Plain Objects / Key-Value Maps (such as <code>vehiclePacks.byVehicle</code> and <code>redeem-codes.jsonc</code> <code>fixedCodes</code>) → Merge Recursively by Key Automatically</strong>: Just write the specific keys you want to add or override (e.g. <code>&quot;my_new_tank&quot;: { ... }</code>). All other stock keys remain intact—<strong>do not</strong> wrap key-value maps in <code>$listOps</code>!</li><li><strong>JSON Array Properties (such as <code>vehiclePacks.multiVehiclePacks</code>, <code>goldenEaglePacks</code>, <code>supplyTrophies</code>) → Replace by Default; Use <code>{ &quot;$listOps&quot;: [...] }</code> to Stack</strong>: Writing a raw array <code>&quot;multiVehiclePacks&quot;: [ ... ]</code> replaces the entire stock and earlier-mod list! To stack items cleanly across multiple mods, set that array property to an envelope object whose <strong>only key is <code>&quot;$listOps&quot;</code></strong> (note: if the object has any sibling keys alongside <code>&quot;$listOps&quot;</code>, it will NOT be recognized as a list-ops envelope!):</li></ol>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// Correct Example: server/tuning/store.jsonc
// Note: multiVehiclePacks, byRank, and byVehicle live INSIDE &quot;vehiclePacks&quot;, and the GJN price key is &quot;gjn&quot;!
{
&quot;vehiclePacks&quot;: {
// ① multiVehiclePacks is an array -&gt; wrap in { &quot;$listOps&quot;: [...] } to stack safely
&quot;multiVehiclePacks&quot;: {
&quot;$listOps&quot;: [
{
&quot;op&quot;: &quot;append&quot;,
&quot;items&quot;: [
{
&quot;id&quot;: &quot;mod_modern_duo_pack&quot;,
&quot;title&quot;: { &quot;en&quot;: &quot;Modern Duo Pack&quot;, &quot;zh&quot;: &quot;现代双车组合包&quot; },
&quot;gjn&quot;: 49.99,
&quot;goldenEagles&quot;: 2000,
&quot;premiumDays&quot;: 15,
&quot;vehicles&quot;: [&quot;us_m1a2_sep2_abrams&quot;, &quot;germ_leopard_2a7v&quot;]
}
]
},
{
&quot;op&quot;: &quot;upsertBy&quot;,
&quot;key&quot;: &quot;id&quot;,
&quot;item&quot;: {
&quot;id&quot;: &quot;wto_pack_two_fronts&quot;,
&quot;gjn&quot;: 19.99
}
},
{
&quot;op&quot;: &quot;removeBy&quot;,
&quot;key&quot;: &quot;id&quot;,
&quot;value&quot;: &quot;some_unwanted_pack_id&quot;
}
]
},
// ② byVehicle is a key-value map (NOT an array) -&gt; write vehicle IDs directly without $listOps!
&quot;byVehicle&quot;: {
&quot;us_mbt_demo&quot;: {
&quot;gjn&quot;: 59.99,
&quot;goldenEagles&quot;: 2000,
&quot;premiumDays&quot;: 15
}
}
}
}</code></pre></div>
<h4 id="ch-05-en-all-4-supported-listops-operations">All 4 Supported <code>$listOps</code> Operations</h4>
<ul><li><code>append</code>: <code>{ &quot;op&quot;: &quot;append&quot;, &quot;items&quot;: [ ... ] }</code> — appends <code>items</code> to the end of the array;</li><li><code>prepend</code>: <code>{ &quot;op&quot;: &quot;prepend&quot;, &quot;items&quot;: [ ... ] }</code> — inserts <code>items</code> at the start of the array;</li><li><code>upsertBy</code>: <code>{ &quot;op&quot;: &quot;upsertBy&quot;, &quot;key&quot;: &quot;&lt;idField&gt;&quot;, &quot;item&quot;: { ... } }</code> — finds the first element where <code>entry[key] === item[key]</code> and recursively merges <code>item</code> into it, or appends <code>item</code> if absent;</li><li><code>removeBy</code>: <code>{ &quot;op&quot;: &quot;removeBy&quot;, &quot;key&quot;: &quot;&lt;field&gt;&quot;, &quot;value&quot;: &lt;matchValue&gt; }</code> — removes every element where <code>entry[key] === value</code>.</li></ul>
<hr>
<h3 id="ch-05-en-4-practical-field-quick-reference-verified-snippets">4. Practical Field Quick-Reference &amp; Verified Snippets</h3>
<p>Every key name below is verified directly against <code>apps/server/tuning/*.jsonc</code> and the server's strict tuning readers:</p>
<h4 id="ch-05-en-4-1-battle-jsonc-multipliers-session-size-br-spread-bot-respawns">4.1 <code>battle.jsonc</code> (Multipliers, Session Size, BR Spread &amp; Bot Respawns)</h4>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;rewardMultiplierSilverLions&quot;: 2.0, // Global Silver Lions reward multiplier (default 1.0)
&quot;rewardMultiplierResearchPoints&quot;: 2.0, // Global Research Points reward multiplier (default 1.0)
&quot;maxPlayers&quot;: 32, // Total session slots (16v16 = 32: 1 local player + up to 31 bots)
&quot;maxBots&quot;: 31, // Maximum AI bots (default 31)
&quot;smallTeamsMaxPlayers&quot;: 16, // Total slots when Tactical Skies (small_teams_) rolls (default 16 = 8v8)
&quot;subModeChance&quot;: 0.5, // Probability (0..1) of rolling an enabled sub-mode alongside classic
&quot;brSpreadMrank&quot;: 3, // Matchmaking mrank spread (3 steps = +/- 1.0 BR; 0 = exact-BR matches)
&quot;botPoolLimitPerType&quot;: 80, // Max vehicles per category emitted into customBots
&quot;tankBotRespawns&quot;: 3, // Max respawns per AI bot in multi-slot Ground battles
&quot;airBotRespawns&quot;: 2, // Max respawns per AI bot in multi-slot Air battles
&quot;strikeUcavSpawnScore&quot;: 750, // Spawn points required for Strike UCAV in Ground RB (default 750)
&quot;nuclearEscalationStrategicBombers&quot;: true // Enable stage-3 strategic bombers (B-52H / Tu-95M) in Air RB Nuclear Escalation
}</code></pre></div>
<h4 id="ch-05-en-4-2-store-jsonc-local-web-store-in-game-ge-sl-vehicle-pack-pricing">4.2 <code>store.jsonc</code> (Local Web Store &amp; In-Game GE / SL / Vehicle Pack Pricing)</h4>
<ul><li>Top-level keys: <code>goldenEaglePacks</code> (array), <code>silverLionPacks</code> (array), <code>premiumForGoldenEagles</code> (array), <code>premiumForGjn</code> (array), and <strong><code>vehiclePacks</code> (object)</strong>;</li><li>Inside <code>vehiclePacks</code>:
<ul><li><code>multiVehiclePacks</code> (array; use <code>$listOps</code>): each entry requires <code>id</code>, <code>vehicles</code> (non-empty unique vehicle ID array), <code>gjn</code> (min <code>0.01</code>), <code>goldenEagles</code> (int <code>≥0</code>), <code>premiumDays</code> (int <code>≥0</code>), optional <code>silverLions</code> (int <code>≥0</code>), and <strong>exact one naming property</strong>—either custom bilingual <code>&quot;title&quot;: { &quot;en&quot;: &quot;...&quot;, &quot;zh&quot;: &quot;...&quot; }</code>, tech-tree folder <code>&quot;groupKey&quot;: &quot;shop/group/...&quot;</code>, or national starter pack <code>&quot;starter&quot;: true</code>;</li><li><code>byRank</code> (array; fallback single-vehicle pack tiers sorted by <code>upToRank</code>): each entry has <code>upToRank</code>, <code>gjn</code>, <code>goldenEagles</code>, <code>premiumDays</code> (optional <code>silverLions</code>);</li><li><code>byVehicle</code> (key-value map): keyed by <code>gift</code> vehicle ID from <code>wpcost.blk</code>, with <code>{ &quot;gjn&quot;?, &quot;goldenEagles&quot;?, &quot;premiumDays&quot;?, &quot;silverLions&quot;? }</code> (omitted fields fall back to the matching <code>byRank</code> tier).</li></ul></li></ul>
<h4 id="ch-05-en-4-3-new-profile-jsonc-starting-balances-for-brand-new-saves">4.3 <code>new-profile.jsonc</code> (Starting Balances for Brand-New Saves)</h4>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;silverLions&quot;: 1000000, // Starting Silver Lions (default 150000)
&quot;goldenEagles&quot;: 5000, // Starting Golden Eagles (default 500)
&quot;gjn&quot;: 50 // Starting GJN balance, up to 2 decimal places (default 0)
}</code></pre></div>
<h4 id="ch-05-en-4-4-redeem-codes-jsonc-custom-one-time-promo-codes">4.4 <code>redeem-codes.jsonc</code> (Custom One-Time Promo Codes)</h4>
<p><code>fixedCodes</code> is a key-value map (redeemable once per save, case-insensitive; omitted currency fields default to <code>0</code>)—merge new codes directly by key:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;fixedCodes&quot;: {
&quot;MYMOD-GIFT-2026&quot;: {
&quot;silverLions&quot;: 500000,
&quot;goldenEagles&quot;: 1000,
&quot;premiumDays&quot;: 7,
&quot;gjn&quot;: 25
}
}
}</code></pre></div>
<h4 id="ch-05-en-4-5-trophies-jsonc-adding-custom-silver-lion-golden-eagle-trophy-chests">4.5 <code>trophies.jsonc</code> (Adding Custom Silver Lion / Golden Eagle Trophy Chests)</h4>
<p><code>supplyTrophies</code> is an array—use <code>$listOps</code> to append a custom chest, and the client will automatically compute and display drop probabilities from your <code>weight</code> / <code>weightTotal</code> / <code>weightEach</code> entries:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>jsonc</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>{
&quot;supplyTrophies&quot;: {
&quot;$listOps&quot;: [
{
&quot;op&quot;: &quot;append&quot;,
&quot;items&quot;: [
{
&quot;id&quot;: &quot;mod_lucky_trophy&quot;,
&quot;iconStyle&quot;: &quot;big_chest&quot;,
&quot;silverLions&quot;: 100000,
&quot;goldenEagles&quot;: 0,
&quot;prizes&quot;: [
{ &quot;silverLions&quot;: 50000, &quot;weight&quot;: 50 },
{ &quot;silverLions&quot;: 250000, &quot;weight&quot;: 20 },
{ &quot;goldenEagles&quot;: 200, &quot;weight&quot;: 10 },
{ &quot;item&quot;: &quot;item_universal_spare&quot;, &quot;count&quot;: 3, &quot;weight&quot;: 15 },
{ &quot;eventVehicles&quot;: { &quot;minRank&quot;: 3, &quot;maxRank&quot;: 7, &quot;pick&quot;: 6 }, &quot;weightTotal&quot;: 5 }
]
}
]
}
]
}
}</code></pre></div>
</div>
<div class="doc-pager">
<a class="doc-pager-btn" href="#ch-04" data-chapter="ch-04"><span class="doc-pager-label"><span class="lang-zh">← 上一章</span><span class="lang-en">← Previous</span></span><span class="doc-pager-title"><span class="lang-zh">04 · GUI 与声明式 EXE 补丁</span><span class="lang-en">04 · GUI &amp; Declarative EXE Patches</span></span></a>
<a class="doc-pager-btn next" href="#ch-06" data-chapter="ch-06"><span class="doc-pager-label"><span class="lang-zh">下一章 →</span><span class="lang-en">Next →</span></span><span class="doc-pager-title"><span class="lang-zh">06 · 服务端 JS/TS 脚本 API</span><span class="lang-en">06 · Server Scripting API</span></span></a>
</div>
</article>
<article class="doc-section doc-chapter" id="ch-06">
<div class="lang-zh">
<h2>06 · 服务端 JS/TS 脚本完整接口手册</h2>
<blockquote><p><strong>实验期警告(API <code>0.1-experimental</code>)</strong><br>本章描述的所有服务端脚本接口与内部目录对象均处于极初期开发阶段,随时可能随本体迭代调整,现阶段不承诺向后兼容。</p></blockquote>
<hr>
<h3 id="ch-06-zh-1-运行环境-node-24-可擦除-ts-语法与-vs-code-智能补全">1. 运行环境、Node 24 可擦除 TS 语法与 VS Code 智能补全</h3>
<p>本地服务器运行在启动器内置的 <strong>Electron 43 / Node.js 24</strong> 上,<strong>原生开启 TypeScript 类型剥离(Type Stripping)</strong>——玩家电脑上无需安装 Node.js 或 TypeScript 即可直接运行你的 <code>.ts</code> 源码!</p>
<ul><li><strong>入口探测顺序</strong>:默认依次查找 <code>server/index.ts</code> → <code>server/index.mjs</code> → <code>server/index.js</code>(也可在 <code>mod.jsonc</code> 的 <code>server.entry</code> 中显式指定相对路径);</li><li><strong>若需引入第三方 npm 依赖或特殊语法</strong>:自行在发布前用 <code>esbuild</code> / <code>tsc</code> 打包为单文件 <code>server/index.mjs</code> 分发即可。</li></ul>
<h4 id="ch-06-zh-1-1-直接写-ts-的语法限制-erasablesyntaxonly-正误对照">1.1 直接写 <code>.ts</code> 的语法限制(<code>erasableSyntaxOnly</code> 正误对照)</h4>
<p>Node 24 原生类型剥离只会擦除纯类型标注,不会生成额外运行时 JS 代码。因此支持全部 <code>interface</code>、<code>type</code>、泛型与 <code>as</code>,但<strong>禁止使用 <code>enum</code>、<code>namespace</code> 或构造函数参数属性(<code>constructor(private x: number)</code>)</strong>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>ts</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// ❌ 错误写法:Node 24 原生 TS 剥离不支持 enum,启动会直接报语法错误!
enum FilterMode { All = 'all', Include = 'include', Exclude = 'exclude' }
// ✅ 正确写法:使用 as const 常量对象 + 联合类型(零运行时开销、100% 兼容!)
const FILTER_MODE = { All: 'all', Include: 'include', Exclude: 'exclude' } as const;
type FilterMode = (typeof FILTER_MODE)[keyof typeof FILTER_MODE];</code></pre></div>
<h4 id="ch-06-zh-1-2-外部模组作者如何获得完整的-vs-code-类型提示">1.2 外部模组作者如何获得完整的 VS Code 类型提示?</h4>
<p>从 WTOffline 源码仓库下载 <code>packages/mods/src/server-api.ts</code>(及其引用的同级 <code>types.ts</code>)放到你的模组 <code>server/</code> 目录下,然后用 <strong><code>import type</code></strong> 导入上下文类型:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>ts</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// ✅ 正确:import type 在运行时会被 Node 24 完全擦除,VS Code 拥有完整自动补全!
import type { WtoServerModContext } from './server-api.ts';
// ❌ 不要对 @wto/mods 做运行时值导入(外部独立模组目录没有 monorepo node_modules,运行时会找不到包)
// import { something } from '@wto/mods';
export default {
async setup(ctx: WtoServerModContext) {
ctx.logger.info('mod initialized');
},
};</code></pre></div>
<blockquote><p>提示:除 <code>export default { setup(ctx) { ... } }</code> 外,运行时也兼容直接导出默认函数 <code>export default function (ctx) { ... }</code> 或具名导出 <code>export function setup(ctx) { ... }</code>。你也可以像 <code>templates/official-map-selector/server/index.ts</code> 一样直接在文件顶部声明自己用到的精简 <code>interface</code>,做到单文件零外部依赖。</p></blockquote>
<hr>
<h3 id="ch-06-zh-2-wtoservermodcontext-上下文对象全属性表">2. <code>WtoServerModContext</code> 上下文对象全属性表</h3>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>属性</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>ctx.apiVersion</code></td><td><code>string</code></td><td>当前运行时的实验期 API 版本号(<code>&quot;0.1-experimental&quot;</code>)</td></tr><tr><td><code>ctx.manifest</code></td><td><code>ModManifest</code></td><td>本模组解析后的 <code>mod.jsonc</code> 清单对象</td></tr><tr><td><code>ctx.modDir</code></td><td><code>string</code></td><td>本模组根目录的绝对路径(可用 <code>node:fs</code> 读取模组附带的静态数据文件)</td></tr><tr><td><code>ctx.gameFolder</code></td><td><code>string</code></td><td>当前运行的离线游戏副本根目录</td></tr><tr><td><code>ctx.dataFolder</code></td><td><code>string</code></td><td>当前客户端的数据目录(含存档、缓存、日志)</td></tr><tr><td><code>ctx.port</code></td><td><code>number</code></td><td>本次启动的本地服务器监听端口</td></tr><tr><td><code>ctx.logger</code></td><td><code>{ info, warn, error }</code></td><td>自动带 <code>[mod:&lt;id&gt;]</code> 前缀的日志器,写入 <code>launcher.log</code> 与诊断包</td></tr><tr><td><code>ctx.storage</code></td><td><code>ModStorageApi</code></td><td>按账号隔离或全局共享的独立原子 JSON 存档区(见第 3 节)</td></tr><tr><td><code>ctx.hooks</code></td><td><code>ServerModHooksApi</code></td><td>生命周期、档案、匹配与对局结算钩子(见第 4 节)</td></tr><tr><td><code>ctx.routes</code></td><td><code>ServerModRoutesApi</code></td><td><code>matching</code>、<code>http</code> 与 <code>char</code> 三大协议路由扩展(见第 5 节)</td></tr></tbody></table></div>
<hr>
<h3 id="ch-06-zh-3-独立存档区-ctx-storage">3. 独立存档区(<code>ctx.storage</code>)</h3>
<p><strong>硬性最佳实践</strong>:请勿往玩家原版 <code>profile.blk</code> 塞入自定义非标字段(不仅可能干扰客户端反序列化,玩家关闭或卸载模组后还会在主存档残留脏数据)。所有模组自定进度、开关与统计请一律存入 <code>ctx.storage</code>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>ts</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// ① 按本地玩家账号隔离:&lt;dataFolder&gt;/saves/&lt;userId&gt;/mods/&lt;modId&gt;.json
const playerStore = ctx.storage.forPlayer(userId);
const prev = playerStore.read&lt;{ wins: number }&gt;() ?? { wins: 0 };
playerStore.write({ wins: prev.wins + 1 }); // 临时文件原子替换写盘,防断电损坏
// playerStore.remove();
// ② 模组跨账号全局共享存储:&lt;dataFolder&gt;/mods-data/&lt;modId&gt;.json
const sharedStore = ctx.storage.shared();</code></pre></div>
<hr>
<h3 id="ch-06-zh-4-全部生命周期-档案与对局钩子-ctx-hooks">4. 全部生命周期、档案与对局钩子(<code>ctx.hooks</code>)</h3>
<h4 id="ch-06-zh-4-1-ctx-hooks-ondatasetsloaded-async-datasets">4.1 <code>ctx.hooks.onDatasetsLoaded(async (datasets) =&gt; { ... })</code></h4>
<p>在本地服务器从叠加后的 <code>.vromfs.bin</code> 提取完静态数据集、尚未构建业务服务前触发。可读取或修改:</p>
<ul><li><code>datasets.vehicles</code>:载具目录数组(<code>CatalogueVehicle[]</code>,含价格、研发点、权重、科技树信息)</li><li><code>datasets.battleEconomy</code>:对局收益基数与单车系数表</li><li><code>datasets.battleSpawnRules</code>:出生点、支援机与重生成本规则数据</li><li><code>datasets.multiplayerMissions</code>:<code>{ categories, missions }</code> 联机任务元数据</li><li><code>datasets.uiLabels</code> / <code>datasets.unitNames</code>:多语言界面标签与载具译名映射</li><li><code>datasets.get(datasetId)</code> / <code>datasets.set(datasetId, value)</code>:按数据集 ID 读取或替换任意底层数据集</li></ul>
<h4 id="ch-06-zh-4-2-ctx-hooks-oncataloguesready-async-catalogues">4.2 <code>ctx.hooks.onCataloguesReady(async (catalogues) =&gt; { ... })</code></h4>
<p>在所有核心业务目录与服务初始化完毕、开始监听端口之前触发,可访问:</p>
<ul><li><code>catalogues.tuning</code>:合并完成后的全部只读 <code>Tuning</code></li><li><code>catalogues.gameModes</code>:<code>GameModes</code> 实例(提供 <code>ids()</code>、<code>byId(id)</code>、<code>byName(name)</code>、<code>byEconomicName(name)</code>、<code>countries()</code>)</li><li><code>catalogues.profiles</code> / <code>accounts</code> / <code>research</code> / <code>equipment</code> / <code>repair</code></li><li><code>catalogues.store</code> / <code>inventory</code> / <code>trophies</code> / <code>items</code> / <code>crew</code> / <code>decor</code> / <code>unlocks</code> / <code>clans</code></li><li><code>catalogues.battleMatchmaker</code> / <code>battleEconomy</code> / <code>battleStreaks</code></li><li><code>catalogues.notifyInventoryChanged()</code>:通知在线客户端立刻刷新外部库存</li><li><code>catalogues.notifyUser(userId, eventName, payload)</code>:向指定在线玩家推送 <code>mrpc.generic_notify</code> 实时事件</li></ul>
<h4 id="ch-06-zh-4-3-ctx-hooks-onserverlistening-port-onserverclosing">4.3 <code>ctx.hooks.onServerListening(({ port }) =&gt; { ... })</code> / <code>onServerClosing(() =&gt; { ... })</code></h4>
<p>分别在 HTTP/匹配端口监听就绪后、以及服务器关闭前(按模组逆序)触发,适合打印就绪地址或清理后台定时器。</p>
<h4 id="ch-06-zh-4-4-档案钩子-ctx-hooks-profile-onrefresh-profile-userid">4.4 档案钩子:<code>ctx.hooks.profile.onRefresh((profile, userId) =&gt; { ... })</code></h4>
<p>每次读取或更新玩家档案并跑完原生刷新管线后调用(<code>profile</code> 为 <code>@wto/blk</code> 的内存 <code>BlkBlock</code>)。建议只读取档案信息并把衍生数据存入 <code>ctx.storage.forPlayer(userId)</code>。</p>
<h4 id="ch-06-zh-4-5-对局与匹配钩子-ctx-hooks-battle">4.5 对局与匹配钩子(<code>ctx.hooks.battle</code>)</h4>
<h5 id="ch-06-zh-①-ctx-hooks-battle-onbeforematchmake-userid-eventname-request">① <code>ctx.hooks.battle.onBeforeMatchmake(({ userId, eventName, request }) =&gt; { ... })</code></h5>
<p>玩家点击「加入战斗」发起 <code>match.enqueue</code>、尚未进入 <code>BattleMatchmaker</code> 之前触发,<code>request</code> 为客户端提交的原始入队参数对象。</p>
<h5 id="ch-06-zh-②-ctx-hooks-battle-onfiltermissions-ctx">② <code>ctx.hooks.battle.onFilterMissions((ctx) =&gt; { ... })</code></h5>
<p><code>BattleMatchmaker</code> 已按当前模式与分房权重筛出双边候选任务池、尚未随机抽图时触发:</p>
<ul><li><code>ctx</code>:<code>{ userId, modeId, modeName, economicName, minMrank, maxMrank, missions }</code>;</li><li>每项 <code>mission</code> 结构为 <code>{ name, path, level?, type?, locName?, postfix? }</code>;</li><li><strong>返回值</strong>:返回过滤后的子集数组(返回 <code>undefined</code> 表示不干预)。若返回空数组 <code>[]</code>,服务端会打印告警并自动回退到过滤前的候选池,确保玩家永远不会因筛选过严而卡死匹配。</li></ul>
<div class="doc-pre"><div class="doc-pre-head"><span>ts</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// 示例:只允许匹配关卡路径或名称包含 poland 或 berlin 的地图
ctx.hooks.battle.onFilterMissions(({ missions }) =&gt; {
const picked = missions.filter((m) =&gt; /poland|berlin/i.test(m.level ?? m.name));
return picked.length &gt; 0 ? picked : undefined;
});</code></pre></div>
<h5 id="ch-06-zh-③-ctx-hooks-battle-onlivefact-userid-roomid-fact">③ <code>ctx.hooks.battle.onLiveFact(({ userId, roomId, fact }) =&gt; { ... })</code></h5>
<p>对局进行中,每当客户端通过 <code>wto_battle.fact</code> 上报一条实时战斗事件时触发(<code>roomId</code> 为 16 位十六进制对局 <code>sessionId</code>)。<code>fact</code> 公共字段包含 <code>{ sessionId, localPlayerId, localTeam, kind }</code>,并按 <code>fact.kind</code> 携带以下精确字段:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th><code>fact.kind</code></th><th>触发时机</th><th>附加字段结构</th></tr></thead><tbody><tr><td><code>&quot;event&quot;</code></td><td>本地玩家产生得分/击杀/助攻/占点/伤害事件</td><td><code>{ time, unit, code, expClass, victim, victimIsPlayer, friendly, modifier, damage }</code></td></tr><tr><td><code>&quot;life&quot;</code></td><td>本地玩家单次出击生命段更新或阵亡结算</td><td><code>{ unit, start, end, died }</code></td></tr><tr><td><code>&quot;kill&quot;</code></td><td>战场右上角击杀播报栏产生任意击杀(含 AI 互杀)</td><td><code>{ time, killer, killerTeam, victim, victimTeam }</code>(MPlayer ID,无玩家单位为 <code>-1</code>)</td></tr><tr><td><code>&quot;strike&quot;</code></td><td>本地玩家投掷的核弹成功引爆</td><td><code>{ time }</code></td></tr></tbody></table></div>
<h5 id="ch-06-zh-④-ctx-hooks-battle-onaftersettle-userid-roomid-summary">④ <code>ctx.hooks.battle.onAfterSettle(({ userId, roomId, summary }) =&gt; { ... })</code></h5>
<p>对局结束、服务端执行完原生 <code>settleBattle</code> 结算之后、档案正式写盘之前触发。<code>summary</code> 的真实结构为 <code>{ profile, report, session }</code>:</p>
<ul><li><code>summary.profile</code>:已完成本局银狮/研发点结算的玩家档案 <code>BlkBlock</code>;</li><li><code>summary.report</code>:客户端上报的本局完整事实 <code>BattleReport</code>(含 <code>outcome: 'win' | 'lose' | 'running'</code>、<code>localTeam</code>、<code>teamAScore</code>、<code>teamBScore</code>、<code>sessionStart</code>、<code>sessionEnd</code>、<code>lives</code>、<code>events</code>、<code>feed</code>、<code>players</code> 计分板、<code>nuclearStrikes</code>、<code>spares</code>);</li><li><code>summary.session</code>:本局会话元数据 <code>BattleSession</code>(含 <code>sessionId</code>、<code>roomId</code>、<code>modeId</code>、<code>modeName</code>、<code>economicName</code>、<code>difficulty</code>、<code>requiredClass</code>、<code>missionName</code>、<code>country</code> 等)。</li></ul>
<blockquote><p>再次提醒:统计模组自定成就、连胜或战役进度时,请读写 <code>ctx.storage.forPlayer(userId)</code>,切勿往 <code>summary.profile</code> 写入非原版自定义键!</p></blockquote>
<hr>
<h3 id="ch-06-zh-5-三大通信路由对比与-matchingapifunc-正确签名-ctx-routes">5. 三大通信路由对比与 <code>matchingApiFunc</code> 正确签名(<code>ctx.routes</code>)</h3>
<h4 id="ch-06-zh-5-1-我该选哪种路由-选型对照表">5.1 我该选哪种路由?(选型对照表)</h4>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>路由接口</th><th>适用场景</th><th>协议格式</th><th>客户端调用方式</th></tr></thead><tbody><tr><td><strong><code>ctx.routes.matching</code></strong>(最推荐)</td><td>原生 DaGui <code>.nut</code> 界面弹窗与服务端读写 JSON 数据(如读取/保存选图规则、模组设置)</td><td>纯 JSON 对象入参 + JSON 对象返回</td><td>Quirrel 调用 <code>matchingApiFunc(&quot;wto_mod.&lt;方法名&gt;&quot;, callback, params)</code></td></tr><tr><td><strong><code>ctx.routes.http</code></strong></td><td>用 HTML/CSS/JS 做复杂可视化面板、外部浏览器管理页或 REST 接口(自动隔离在 <code>/mods/&lt;modId&gt;/...</code>)</td><td>标准 HTTP 请求/响应</td><td>系统浏览器或游戏内置浏览器打开 <code>http://{{LOCAL_ENDPOINT}}/mods/&lt;modId&gt;/...</code></td></tr><tr><td><strong><code>ctx.routes.char</code></strong></td><td>拦截包装原版 <code>cln_*</code> 档案动作,或注册底层二进制 BLK 动作</td><td>二进制/文本请求体(<code>Buffer</code>)</td><td>客户端底层 <code>char</code> 客户端动作请求</td></tr></tbody></table></div>
<h4 id="ch-06-zh-5-2-匹配服-json-rpc-ctx-routes-matching-注意客户端参数顺序">5.2 匹配服 JSON RPC(<code>ctx.routes.matching</code>)—— 注意客户端参数顺序!</h4>
<p>服务端注册自定义匹配方法非常直观(<code>req</code> 含 <code>{ method, params, userId }</code>,同步返回任意 JSON 对象即可;也可用 <code>wrap(method, (req, next) =&gt; ...)</code> 包装原版匹配方法):</p>
<div class="doc-pre"><div class="doc-pre-head"><span>ts</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>ctx.routes.matching.register('wto_mod.my_mod.ping', ({ userId, params }) =&gt; ({
ok: true,
userId,
echo: params,
}));</code></pre></div>
<blockquote><p><strong>P0 必看:Quirrel 端 <code>matchingApiFunc</code> 的第 2 个参数是 <code>callback</code>,第 3 个参数才是 <code>params</code>!</strong><br>在原版 <code>gui.vromfs.bin</code> 的 <code>%scripts/matching/api.nut</code> 中,函数定义为 <code>function matchingApiFunc(name, cb, params = null)</code>。如果把 <code>params</code> 和 <code>callback</code> 写反,请求参数会变成空且回调永远不会触发!</p></blockquote>
<p>客户端 <code>.nut</code> 正确调用写法:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>squirrel</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>from &quot;%scripts/matching/api.nut&quot; import matchingApiFunc
// ✅ 第 1 参数:方法名 | 第 2 参数:Callback 回调 | 第 3 参数:请求参数表 params
matchingApiFunc(&quot;wto_mod.my_mod.ping&quot;,
Callback(@(resp) this.onPingResponse(resp), this),
{
hello = &quot;world&quot;
})</code></pre></div>
<h4 id="ch-06-zh-5-3-本地-http-与内置浏览器网页路由-ctx-routes-http">5.3 本地 HTTP 与内置浏览器网页路由(<code>ctx.routes.http</code>)</h4>
<p>注册的子路径会自动挂载到 <strong><code>/mods/&lt;你的modId&gt;/...</code></strong> 命名空间下(支持精确路径与 <code>/*</code> 通配后缀):</p>
<div class="doc-pre"><div class="doc-pre-head"><span>ts</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>ctx.routes.http.register('/panel', () =&gt; ({
status: 200,
contentType: 'text/html; charset=utf-8',
body: '&lt;!doctype html&gt;&lt;meta charset=&quot;utf-8&quot;&gt;&lt;h1&gt;My Mod Control Panel&lt;/h1&gt;',
}));
ctx.routes.http.register('/api/*', (req) =&gt; ({
status: 200,
contentType: 'application/json; charset=utf-8',
body: JSON.stringify({ method: req.method, path: req.path, query: req.query }),
}));</code></pre></div>
<p>如果你想在游戏机库里点一个按钮直接用战雷内置浏览器打开这个网页,只需在 <code>client/gui-patches/</code> 的替换脚本中引用 <code>{{LOCAL_ENDPOINT}}</code> 占位符即可:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>squirrel</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>from &quot;%scripts/onlineShop/url.nut&quot; import openUrl
openUrl(&quot;http://{{LOCAL_ENDPOINT}}/mods/demo.my-mod/panel&quot;, false, false)</code></pre></div>
<h4 id="ch-06-zh-5-4-char-动作拦截与扩展-ctx-routes-char">5.4 Char 动作拦截与扩展(<code>ctx.routes.char</code>)</h4>
<ul><li><code>ctx.routes.char.register(action, handler)</code>:注册全新的自定义 <code>cln_*</code> 动作;</li><li><code>ctx.routes.char.wrap(action, async (req, next) =&gt; { ... })</code>:按洋葱模型拦截现有 <code>cln_*</code> 动作(可在调用 <code>await next(req)</code> 前检查请求或在其后观测响应)。</li></ul>
<hr>
<h3 id="ch-06-zh-6-全栈模组实战拆解-官方选图器-official-map-selector-是如何串起来的">6. 全栈模组实战拆解:官方选图器(<code>official-map-selector</code>)是如何串起来的?</h3>
<p>打开 <code>mods/official-map-selector/</code>(仓库源码位于 <code>mod-dev-docs/templates/official-map-selector/</code>),它是学习「客户端原生 UI + 本地服务器 RPC + 独立存档 + 匹配钩子」完整闭环的最佳蓝本。整个模组仅由 <strong>5 个环节</strong>串联而成:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>[1. 入口挂载补丁 client/gui-patches/]
├─ gui/gamemodeselect/gamemodeselect.tpl → 在模式选择底栏右侧插入「自定义地图池」按钮节点
├─ scripts/gamemodes/gamemodeselect.nut → 点击按钮调用 WtoMapSelectorModal.open({ gameMode })
└─ gui/css.css → 追加 @import &quot;missions\wtomapselector.css&quot;
│
▼
[2. 独立原生弹窗 client/packs/gui.vromfs.bin/ + lang.vromfs.bin/]
├─ scripts/missions/wtomapselectormodal.nut → 继承 BaseGuiHandlerWT,展示搜索框、黑白名单标签与战术小地图预览
├─ gui/missions/wtomapselectormodal.tpl → 弹窗骨架与卡片网格模板(wtomapselectorcards.tpl)
├─ gui/missions/wtomapselector.css → 卡片选中高亮样式
└─ lang/menu.csv.patch.csv → 注册 wto/mapSelector/* 中英文界面词条
│
▼ matchingApiFunc(&quot;wto_mod.map_selector.get&quot; / &quot;.set&quot;, Callback(...), { modeName, ... })
[3. 服务端匹配 RPC server/index.ts -&gt; ctx.routes.matching.register]
├─ onCataloguesReady 时扫描 catalogues.gameModes 建立各 PvP 模式可用双边地图池索引
├─ wto_mod.map_selector.get → 返回该模式地图列表 + 当前玩家已保存的筛选规则
└─ wto_mod.map_selector.set → 校验参数并保存玩家的 all / include / exclude 选图列表
│
▼
[4. 玩家独立存档 ctx.storage.forPlayer(userId)]
└─ 原子写入 &lt;dataFolder&gt;/saves/&lt;userId&gt;/mods/official.map-selector.json(不改动 profile.blk)
│
▼
[5. 匹配选图拦截 ctx.hooks.battle.onFilterMissions]
└─ 玩家点「加入战斗」时按白名单/黑名单过滤候选 missions;若当前权重段过滤后为 0 张图则安全回退全池并记日志</code></pre></div>
<p>建议把 <code>templates/official-map-selector</code> 从头到尾对照本图通读一遍——你需要的几乎所有全栈模组技巧都在里面有可直接复用的生产级示范代码!</p>
</div>
<div class="lang-en">
<h2>06 · Server JS/TS Scripting API Reference</h2>
<blockquote><p><strong>Experimental Warning (API <code>0.1-experimental</code>)</strong><br>All server scripting interfaces and internal catalogue objects documented here are in early active development and may change across WTOffline releases without backwards compatibility.</p></blockquote>
<hr>
<h3 id="ch-06-en-1-runtime-environment-node-24-erasable-ts-rules-vs-code-autocomplete">1. Runtime Environment, Node 24 Erasable TS Rules &amp; VS Code Autocomplete</h3>
<p>The local server runs inside the launcher's bundled <strong>Electron 43 / Node.js 24</strong> runtime with <strong>native TypeScript type stripping enabled</strong>—players do not need Node.js or TypeScript installed on their PCs to run your <code>.ts</code> scripts directly!</p>
<ul><li><strong>Default entry lookup order</strong>: <code>server/index.ts</code> → <code>server/index.mjs</code> → <code>server/index.js</code> (or override via <code>server.entry</code> in <code>mod.jsonc</code>);</li><li><strong>Third-party npm packages or non-erasable syntax</strong>: if needed, bundle your code ahead of time into a single-file <code>server/index.mjs</code> with <code>esbuild</code> or <code>tsc</code>.</li></ul>
<h4 id="ch-06-en-1-1-raw-ts-syntax-rule-erasablesyntaxonly-do-vs-don-t">1.1 Raw <code>.ts</code> Syntax Rule (<code>erasableSyntaxOnly</code> Do vs Don't)</h4>
<p>Node 24's built-in TypeScript stripper erases type annotations without emitting extra runtime JS code. All <code>interface</code>, <code>type</code>, generic, and <code>as</code> constructs work natively, <strong>except <code>enum</code>, <code>namespace</code>, and constructor parameter properties (<code>constructor(private x: number)</code>)</strong>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>ts</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// ❌ DON'T: Node 24 native TS stripping rejects `enum` at startup!
enum FilterMode { All = 'all', Include = 'include', Exclude = 'exclude' }
// ✅ DO: Use an `as const` object + union type (zero runtime overhead, 100% compatible!)
const FILTER_MODE = { All: 'all', Include: 'include', Exclude: 'exclude' } as const;
type FilterMode = (typeof FILTER_MODE)[keyof typeof FILTER_MODE];</code></pre></div>
<h4 id="ch-06-en-1-2-how-external-modders-get-full-vs-code-autocomplete">1.2 How External Modders Get Full VS Code Autocomplete</h4>
<p>Download <code>packages/mods/src/server-api.ts</code> (along with its sibling <code>types.ts</code>) from the WTOffline repository into your mod's <code>server/</code> folder and import types using <strong><code>import type</code></strong>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>ts</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// ✅ DO: `import type` is completely erased by Node 24 at runtime while giving full VS Code IntelliSense!
import type { WtoServerModContext } from './server-api.ts';
// ❌ Avoid value-importing `@wto/mods` at runtime (external mod folders do not have monorepo node_modules)
// import { something } from '@wto/mods';
export default {
async setup(ctx: WtoServerModContext) {
ctx.logger.info('mod initialized');
},
};</code></pre></div>
<blockquote><p>Tip: Alongside <code>export default { setup(ctx) { ... } }</code>, the runtime also accepts <code>export default function (ctx) { ... }</code> or a named <code>export function setup(ctx) { ... }</code>. You can also declare lightweight structural <code>interface</code> views directly at the top of <code>server/index.ts</code> (just like <code>templates/official-map-selector/server/index.ts</code>) for a zero-dependency single file.</p></blockquote>
<hr>
<h3 id="ch-06-en-2-wtoservermodcontext-property-reference">2. <code>WtoServerModContext</code> Property Reference</h3>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>ctx.apiVersion</code></td><td><code>string</code></td><td>Active experimental API tag (<code>&quot;0.1-experimental&quot;</code>)</td></tr><tr><td><code>ctx.manifest</code></td><td><code>ModManifest</code></td><td>Parsed <code>mod.jsonc</code> manifest of this mod</td></tr><tr><td><code>ctx.modDir</code></td><td><code>string</code></td><td>Absolute path to this mod's root directory (read static mod files via <code>node:fs</code>)</td></tr><tr><td><code>ctx.gameFolder</code></td><td><code>string</code></td><td>Active offline game copy root directory</td></tr><tr><td><code>ctx.dataFolder</code></td><td><code>string</code></td><td>Active client data folder (saves, caches, logs)</td></tr><tr><td><code>ctx.port</code></td><td><code>number</code></td><td>Bound local server port for the current session</td></tr><tr><td><code>ctx.logger</code></td><td><code>{ info, warn, error }</code></td><td>Logger prefixed with <code>[mod:&lt;id&gt;]</code>, written to <code>launcher.log</code> and diagnostic exports</td></tr><tr><td><code>ctx.storage</code></td><td><code>ModStorageApi</code></td><td>Atomic JSON storage scoped per player or shared across accounts (Section 3)</td></tr><tr><td><code>ctx.hooks</code></td><td><code>ServerModHooksApi</code></td><td>Lifecycle, profile, matchmaking, and battle settlement hooks (Section 4)</td></tr><tr><td><code>ctx.routes</code></td><td><code>ServerModRoutesApi</code></td><td><code>matching</code>, <code>http</code>, and <code>char</code> route extensions (Section 5)</td></tr></tbody></table></div>
<hr>
<h3 id="ch-06-en-3-isolated-mod-storage-ctx-storage">3. Isolated Mod Storage (<code>ctx.storage</code>)</h3>
<p><strong>Recommended practice</strong>: Keep custom mod data out of the player's <code>profile.blk</code> (non-stock keys can interfere with client serialization and remain behind after a mod is removed). Store mod state, settings, and progression in <code>ctx.storage</code>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>ts</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// ① Scoped per local player account: &lt;dataFolder&gt;/saves/&lt;userId&gt;/mods/&lt;modId&gt;.json
const playerStore = ctx.storage.forPlayer(userId);
const prev = playerStore.read&lt;{ wins: number }&gt;() ?? { wins: 0 };
playerStore.write({ wins: prev.wins + 1 }); // Atomic temp-file rename write
// playerStore.remove();
// ② Shared across all accounts for this mod: &lt;dataFolder&gt;/mods-data/&lt;modId&gt;.json
const sharedStore = ctx.storage.shared();</code></pre></div>
<hr>
<h3 id="ch-06-en-4-lifecycle-profile-battle-hooks-ctx-hooks">4. Lifecycle, Profile &amp; Battle Hooks (<code>ctx.hooks</code>)</h3>
<h4 id="ch-06-en-4-1-ctx-hooks-ondatasetsloaded-async-datasets">4.1 <code>ctx.hooks.onDatasetsLoaded(async (datasets) =&gt; { ... })</code></h4>
<p>Fires after static datasets are extracted from the overlaid <code>.vromfs.bin</code> packs and before domain catalogues are constructed. Inspect or mutate:</p>
<ul><li><code>datasets.vehicles</code>: vehicle array (<code>CatalogueVehicle[]</code> with prices, RP, BRs, tech-tree links)</li><li><code>datasets.battleEconomy</code>: battle action reward rates and per-vehicle multipliers</li><li><code>datasets.battleSpawnRules</code>: spawn costs, support planes, and spawn rules</li><li><code>datasets.multiplayerMissions</code>: <code>{ categories, missions }</code> mission metadata</li><li><code>datasets.uiLabels</code> / <code>datasets.unitNames</code>: localized UI strings and vehicle names</li><li><code>datasets.get(datasetId)</code> / <code>datasets.set(datasetId, value)</code>: read or replace any raw dataset by ID</li></ul>
<h4 id="ch-06-en-4-2-ctx-hooks-oncataloguesready-async-catalogues">4.2 <code>ctx.hooks.onCataloguesReady(async (catalogues) =&gt; { ... })</code></h4>
<p>Fires after all domain catalogues and services are assembled, right before the server starts listening:</p>
<ul><li><code>catalogues.tuning</code>: merged read-only <code>Tuning</code></li><li><code>catalogues.gameModes</code>: <code>GameModes</code> instance (<code>ids()</code>, <code>byId(id)</code>, <code>byName(name)</code>, <code>byEconomicName(name)</code>, <code>countries()</code>)</li><li><code>catalogues.profiles</code> / <code>accounts</code> / <code>research</code> / <code>equipment</code> / <code>repair</code></li><li><code>catalogues.store</code> / <code>inventory</code> / <code>trophies</code> / <code>items</code> / <code>crew</code> / <code>decor</code> / <code>unlocks</code> / <code>clans</code></li><li><code>catalogues.battleMatchmaker</code> / <code>battleEconomy</code> / <code>battleStreaks</code></li><li><code>catalogues.notifyInventoryChanged()</code>: push live external-inventory refresh to connected clients</li><li><code>catalogues.notifyUser(userId, eventName, payload)</code>: send a live <code>mrpc.generic_notify</code> event to a logged-in player</li></ul>
<h4 id="ch-06-en-4-3-ctx-hooks-onserverlistening-port-onserverclosing">4.3 <code>ctx.hooks.onServerListening(({ port }) =&gt; { ... })</code> / <code>onServerClosing(() =&gt; { ... })</code></h4>
<p>Fires once the HTTP/matching port is listening, and in reverse mod order right before shutdown (ideal for logging URLs or clearing timers).</p>
<h4 id="ch-06-en-4-4-profile-hook-ctx-hooks-profile-onrefresh-profile-userid">4.4 Profile Hook: <code>ctx.hooks.profile.onRefresh((profile, userId) =&gt; { ... })</code></h4>
<p>Fires whenever a player profile is loaded or updated and finishes the native refresh pipeline (<code>profile</code> is an <code>@wto/blk</code> <code>BlkBlock</code>). Read profile facts here and persist derived mod state in <code>ctx.storage.forPlayer(userId)</code>.</p>
<h4 id="ch-06-en-4-5-matchmaking-battle-hooks-ctx-hooks-battle">4.5 Matchmaking &amp; Battle Hooks (<code>ctx.hooks.battle</code>)</h4>
<h5 id="ch-06-en-①-ctx-hooks-battle-onbeforematchmake-userid-eventname-request">① <code>ctx.hooks.battle.onBeforeMatchmake(({ userId, eventName, request }) =&gt; { ... })</code></h5>
<p>Fires when the player clicks <strong>To Battle!</strong> (<code>match.enqueue</code>) before <code>BattleMatchmaker</code> runs; <code>request</code> holds the raw client enqueue parameters.</p>
<h5 id="ch-06-en-②-ctx-hooks-battle-onfiltermissions-ctx">② <code>ctx.hooks.battle.onFilterMissions((ctx) =&gt; { ... })</code></h5>
<p>Fires after <code>BattleMatchmaker</code> narrows candidate two-sided missions for the chosen mode and BR window, right before random map selection:</p>
<ul><li><code>ctx</code>: <code>{ userId, modeId, modeName, economicName, minMrank, maxMrank, missions }</code>;</li><li>Each <code>mission</code> has <code>{ name, path, level?, type?, locName?, postfix? }</code>;</li><li><strong>Return value</strong>: return your filtered subset array (or <code>undefined</code> to leave unchanged). If an empty array <code>[]</code> is returned, the server logs a warning and safely falls back to the previous candidate pool so matchmaking never deadlocks.</li></ul>
<div class="doc-pre"><div class="doc-pre-head"><span>ts</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>// Example: restrict matches to maps whose level path or name matches poland or berlin
ctx.hooks.battle.onFilterMissions(({ missions }) =&gt; {
const picked = missions.filter((m) =&gt; /poland|berlin/i.test(m.level ?? m.name));
return picked.length &gt; 0 ? picked : undefined;
});</code></pre></div>
<h5 id="ch-06-en-③-ctx-hooks-battle-onlivefact-userid-roomid-fact">③ <code>ctx.hooks.battle.onLiveFact(({ userId, roomId, fact }) =&gt; { ... })</code></h5>
<p>Fires live during a running LocalMP battle whenever the client reports a <code>wto_battle.fact</code> event (<code>roomId</code> is the 16-character hex <code>sessionId</code>). <code>fact</code> always carries <code>{ sessionId, localPlayerId, localTeam, kind }</code> plus fields determined by <code>fact.kind</code>:</p>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th><code>fact.kind</code></th><th>When It Fires</th><th>Additional <code>fact</code> Fields</th></tr></thead><tbody><tr><td><code>&quot;event&quot;</code></td><td>Local player scores a kill, assist, capture, hit, or award event</td><td><code>{ time, unit, code, expClass, victim, victimIsPlayer, friendly, modifier, damage }</code></td></tr><tr><td><code>&quot;life&quot;</code></td><td>Local player spawn life segment updates or ends in death</td><td><code>{ unit, start, end, died }</code></td></tr><tr><td><code>&quot;kill&quot;</code></td><td>Any kill appears in the HUD killfeed (including AI-vs-AI kills)</td><td><code>{ time, killer, killerTeam, victim, victimTeam }</code> (MPlayer IDs, <code>-1</code> if unit has no player)</td></tr><tr><td><code>&quot;strike&quot;</code></td><td>Local player's nuclear bomb detonates</td><td><code>{ time }</code></td></tr></tbody></table></div>
<h5 id="ch-06-en-④-ctx-hooks-battle-onaftersettle-userid-roomid-summary">④ <code>ctx.hooks.battle.onAfterSettle(({ userId, roomId, summary }) =&gt; { ... })</code></h5>
<p>Fires at battle end right after native <code>settleBattle</code> applies SL/RP rewards and right before the updated profile is written to disk. <code>summary</code> has the exact shape <code>{ profile, report, session }</code>:</p>
<ul><li><code>summary.profile</code>: the player's <code>BlkBlock</code> profile with post-battle rewards applied;</li><li><code>summary.report</code>: parsed <code>BattleReport</code> (<code>outcome: 'win' | 'lose' | 'running'</code>, <code>localTeam</code>, <code>teamAScore</code>, <code>teamBScore</code>, <code>sessionStart</code>, <code>sessionEnd</code>, <code>lives</code>, <code>events</code>, <code>feed</code>, <code>players</code> scoreboard rows, <code>nuclearStrikes</code>, <code>spares</code>);</li><li><code>summary.session</code>: <code>BattleSession</code> metadata (<code>sessionId</code>, <code>roomId</code>, <code>modeId</code>, <code>modeName</code>, <code>economicName</code>, <code>difficulty</code>, <code>requiredClass</code>, <code>missionName</code>, <code>country</code>, etc.).</li></ul>
<blockquote><p>Reminder: Persist any custom mod achievements, streaks, or campaign progression in <code>ctx.storage.forPlayer(userId)</code> rather than mutating non-stock keys onto <code>summary.profile</code>!</p></blockquote>
<hr>
<h3 id="ch-06-en-5-choosing-between-the-3-route-channels-exact-matchingapifunc-signature-ctx-routes">5. Choosing Between the 3 Route Channels &amp; Exact <code>matchingApiFunc</code> Signature (<code>ctx.routes</code>)</h3>
<h4 id="ch-06-en-5-1-which-route-api-should-i-use">5.1 Which Route API Should I Use?</h4>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>Route API</th><th>Best For</th><th>Payload Format</th><th>How the Client Calls It</th></tr></thead><tbody><tr><td><strong><code>ctx.routes.matching</code></strong> *(Recommended)*</td><td>Native DaGui <code>.nut</code> modals exchanging JSON data with your server script (settings, map rules, custom state)</td><td>Plain JSON <code>params</code> in → JSON object out</td><td>Quirrel <code>matchingApiFunc(&quot;wto_mod.&lt;method&gt;&quot;, callback, params)</code></td></tr><tr><td><strong><code>ctx.routes.http</code></strong></td><td>Rich HTML/CSS/JS web dashboards, external browser panels, or REST endpoints (auto-namespaced under <code>/mods/&lt;modId&gt;/...</code>)</td><td>Standard HTTP request / response</td><td>System browser or War Thunder's embedded browser at <code>http://{{LOCAL_ENDPOINT}}/mods/&lt;modId&gt;/...</code></td></tr><tr><td><strong><code>ctx.routes.char</code></strong></td><td>Wrapping stock <code>cln_*</code> profile actions or adding low-level binary BLK actions</td><td>Raw binary/text <code>Buffer</code></td><td>Low-level client <code>char</code> action requests</td></tr></tbody></table></div>
<h4 id="ch-06-en-5-2-matching-json-rpc-ctx-routes-matching-mind-the-client-argument-order">5.2 Matching JSON RPC (<code>ctx.routes.matching</code>) — Mind the Client Argument Order!</h4>
<p>Registering a custom matching RPC on the server takes just a few lines (<code>req</code> provides <code>{ method, params, userId }</code> and returns any JSON object; <code>wrap(method, (req, next) =&gt; ...)</code> is also available):</p>
<div class="doc-pre"><div class="doc-pre-head"><span>ts</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>ctx.routes.matching.register('wto_mod.my_mod.ping', ({ userId, params }) =&gt; ({
ok: true,
userId,
echo: params,
}));</code></pre></div>
<blockquote><p><strong>P0 Gotcha: In Quirrel's <code>matchingApiFunc</code>, <code>callback</code> Is the 2nd Argument and <code>params</code> Is the 3rd Argument!</strong><br>In stock <code>gui.vromfs.bin</code> <code>%scripts/matching/api.nut</code>, the signature is <code>function matchingApiFunc(name, cb, params = null)</code>. Passing <code>(name, params, callback)</code> in the wrong order sends empty params and skips your callback.</p></blockquote>
<p>Correct Quirrel <code>.nut</code> call:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>squirrel</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>from &quot;%scripts/matching/api.nut&quot; import matchingApiFunc
// ✅ Arg 1: RPC method | Arg 2: Callback | Arg 3: Request params table
matchingApiFunc(&quot;wto_mod.my_mod.ping&quot;,
Callback(@(resp) this.onPingResponse(resp), this),
{
hello = &quot;world&quot;
})</code></pre></div>
<h4 id="ch-06-en-5-3-local-http-embedded-browser-routes-ctx-routes-http">5.3 Local HTTP &amp; Embedded Browser Routes (<code>ctx.routes.http</code>)</h4>
<p>Routes are automatically namespaced under <strong><code>/mods/&lt;yourModId&gt;/...</code></strong> and support both exact paths and <code>/*</code> wildcards:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>ts</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>ctx.routes.http.register('/panel', () =&gt; ({
status: 200,
contentType: 'text/html; charset=utf-8',
body: '&lt;!doctype html&gt;&lt;meta charset=&quot;utf-8&quot;&gt;&lt;h1&gt;My Mod Control Panel&lt;/h1&gt;',
}));
ctx.routes.http.register('/api/*', (req) =&gt; ({
status: 200,
contentType: 'application/json; charset=utf-8',
body: JSON.stringify({ method: req.method, path: req.path, query: req.query }),
}));</code></pre></div>
<p>To open that page inside War Thunder's native embedded browser from a hangar button, use the <code>{{LOCAL_ENDPOINT}}</code> placeholder inside a <code>client/gui-patches/</code> replacement snippet:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>squirrel</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>from &quot;%scripts/onlineShop/url.nut&quot; import openUrl
openUrl(&quot;http://{{LOCAL_ENDPOINT}}/mods/demo.my-mod/panel&quot;, false, false)</code></pre></div>
<h4 id="ch-06-en-5-4-char-action-interception-custom-actions-ctx-routes-char">5.4 Char Action Interception &amp; Custom Actions (<code>ctx.routes.char</code>)</h4>
<ul><li><code>ctx.routes.char.register(action, handler)</code>: register a brand-new <code>cln_*</code> action;</li><li><code>ctx.routes.char.wrap(action, async (req, next) =&gt; { ... })</code>: wrap an existing <code>cln_*</code> action around <code>await next(req)</code>.</li></ul>
<hr>
<h3 id="ch-06-en-6-full-stack-case-study-how-official-map-selector-connects-end-to-end">6. Full-Stack Case Study: How <code>official-map-selector</code> Connects End to End</h3>
<p>Open <code>mods/official-map-selector/</code> (source in <code>mod-dev-docs/templates/official-map-selector/</code>): it is a complete reference implementation connecting native client UI, matching RPCs, isolated player storage, and server matchmaking hooks across <strong>5 clean layers</strong>:</p>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>[1. Minimal Entry Hooks: client/gui-patches/]
├─ gui/gamemodeselect/gamemodeselect.tpl → Inserts the &quot;Custom Map Pool&quot; button into the footer bar
├─ scripts/gamemodes/gamemodeselect.nut → Wires button click to WtoMapSelectorModal.open({ gameMode })
└─ gui/css.css → Appends @import &quot;missions\wtomapselector.css&quot;
│
▼
[2. Standalone Native Modal: client/packs/gui.vromfs.bin/ + lang.vromfs.bin/]
├─ scripts/missions/wtomapselectormodal.nut → Subclasses BaseGuiHandlerWT; renders search, filter tabs &amp; tactical map preview
├─ gui/missions/wtomapselectormodal.tpl → Modal layout &amp; card grid template (wtomapselectorcards.tpl)
├─ gui/missions/wtomapselector.css → Selected card badge &amp; border styling
└─ lang/menu.csv.patch.csv → Localized wto/mapSelector/* UI strings (EN / ZH)
│
▼ matchingApiFunc(&quot;wto_mod.map_selector.get&quot; / &quot;.set&quot;, Callback(...), { modeName, ... })
[3. Server Matching RPCs: server/index.ts -&gt; ctx.routes.matching.register]
├─ Indexes playable two-sided map pools per PvP mode during onCataloguesReady(catalogues.gameModes)
├─ wto_mod.map_selector.get → Returns the mode's map list + the player's saved filter rule
└─ wto_mod.map_selector.set → Validates &amp; saves the player's all / include / exclude selection
│
▼
[4. Per-Account Isolated Storage: ctx.storage.forPlayer(userId)]
└─ Atomically writes &lt;dataFolder&gt;/saves/&lt;userId&gt;/mods/official.map-selector.json (never touches profile.blk)
│
▼
[5. Matchmaking Map Filter: ctx.hooks.battle.onFilterMissions]
└─ Filters candidate missions by whitelist/blacklist on &quot;To Battle!&quot;, falling back to the full pool with a log warning if 0 maps match at that BR</code></pre></div>
<p>Reading <code>templates/official-map-selector</code> alongside this diagram gives you a production-tested blueprint for virtually any full-stack WTOffline mod!</p>
</div>
<div class="doc-pager">
<a class="doc-pager-btn" href="#ch-05" data-chapter="ch-05"><span class="doc-pager-label"><span class="lang-zh">← 上一章</span><span class="lang-en">← Previous</span></span><span class="doc-pager-title"><span class="lang-zh">05 · 服务端零代码调参</span><span class="lang-en">05 · Server Tuning &amp; $listOps</span></span></a>
<a class="doc-pager-btn next" href="#ch-07" data-chapter="ch-07"><span class="doc-pager-label"><span class="lang-zh">下一章 →</span><span class="lang-en">Next →</span></span><span class="doc-pager-title"><span class="lang-zh">07 · 排错、热重载与发布</span><span class="lang-en">07 · Troubleshooting &amp; Packaging</span></span></a>
</div>
</article>
<article class="doc-section doc-chapter" id="ch-07">
<div class="lang-zh">
<h2>07 · 排错、日志、热重载与打包发布规范</h2>
<h3 id="ch-07-zh-1-模组出错了去哪里看日志">1. 模组出错了去哪里看日志?</h3>
<p>启动器的所有模组构建与运行日志都会汇入标准日志目录,可在 <strong>「设置 › 诊断 › 打开日志目录」</strong> 或 <strong>「关于 › 导出诊断日志」</strong> 直接打开:</p>
<ol><li><strong>启动器主日志(<code>launcher.log</code>)</strong>:
<ul><li>搜索 <code>[build]</code>:查看本轮启用了哪些模组、各 <code>.vromfs.bin</code> 数据包叠加统计、以及哪条 <code>gui-patches</code> 或 <code>exe-patches</code> 被跳过与具体原因;</li><li>搜索 <code>[mods]</code>:查看跨盘 Junction 挂载结果、被跳过的玩家原生文件重名告警、以及自动还原的按需备份数据包;</li><li>搜索 <code>[server]</code> 或 <code>[mod:&lt;你的modId&gt;]</code>:查看服务端 <code>tuning</code> 校验错误、脚本加载报错堆栈、以及你在脚本里调用 <code>ctx.logger.info/warn/error</code> 打印的全部输出。</li></ul></li><li><strong>游戏客户端运行日志(<code>&lt;游戏副本目录&gt;/.game_logs/*.clog</code>)</strong>:
<ul><li>若客户端 GUI 脚本运行报错或卡死在「正在加载」,查看最新的 <code>.clog</code>(并配合第 04 章的 <code>sq.exe</code> 完整字节码检查快速定位);</li><li>若新增 3D 模型未渲染,搜索 <code>.clog</code> 中的 <code>[PACK]</code>、<code>pkg_user</code> 或模型资产名确认是否被引擎挂载。</li></ul></li></ol>
<hr>
<h3 id="ch-07-zh-2-常见报错与疑难杂症速查表">2. 常见报错与疑难杂症速查表</h3>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>现象 / 日志报错</th><th>常见原因</th><th>解决方法</th></tr></thead><tbody><tr><td>启动器提示某模组目录读取失败</td><td><code>mod.jsonc</code> 存在 JSON 语法错误、拼错了未知字段名、<code>id</code> 含大写或非法字符、或声明的 <code>server.entry</code> 文件不存在</td><td>对照第 01 章第 5 节字段表核对 <code>mod.jsonc</code></td></tr><tr><td>点启动提示「存在阻塞性模组错误」</td><td>启用的模组缺少 <code>requires</code> 前置、前置未勾选启用,或同时勾选了声明 <code>conflicts</code> 互斥的两个模组</td><td>按「模组」页顶部的红色错误列表补齐前置或关闭其中一个互斥项</td></tr><tr><td>模组里的 <code>server/tuning/*.jsonc</code> 修改似乎没生效</td><td>测试客户端曾在启动器「数值」页手动改过同一字段(<code>&lt;数据目录&gt;/tuning/*.jsonc</code> 优先级高于模组),或 <code>store.jsonc</code> 把 <code>vehiclePacks</code> 内部字段写到了根级</td><td>在启动器「数值」页将该项重置为默认,并核对第 05 章的字段层级与 <code>&quot;gjn&quot;</code> 字段名</td></tr><tr><td>服务端加载 <code>.ts</code> 报语法错或找不到模块</td><td>在 <code>.ts</code> 中写了 <code>enum</code>/<code>namespace</code>,或写了运行时值导入 <code>import { ... } from '@wto/mods'</code></td><td>改用 <code>as const</code> 对象 + 联合类型;类型提示一律写成 <code>import type { ... } from './server-api.ts'</code></td></tr><tr><td><code>gui-patches</code> 报错 <code>the data pack has no script ...</code></td><td><code>patch.jsonc</code> 里的 <code>variant.file</code> 含有大写字母(如 <code>scripts/gameModes/...</code>)</td><td>将 <code>variant.file</code> 改为<strong>全小写</strong>(如 <code>scripts/gamemodes/gamemodeselect.nut</code>)</td></tr><tr><td>新增的独立 <code>.css</code> 样式完全没生效</td><td>只把 <code>.css</code> 放进了 <code>client/packs/gui.vromfs.bin/</code>,未在根样式表 <code>gui/css.css</code> 中注册</td><td>在 <code>client/gui-patches/</code> 给 <code>gui/css.css</code> 增加一条 <code>@import &quot;目录文件名.css&quot;</code> 补丁(见第 04 章 2.2 节)</td></tr><tr><td>客户端 <code>matchingApiFunc</code> 回调不触发或服务端收到空 <code>params</code></td><td>把 <code>matchingApiFunc</code> 的第 2、第 3 个参数顺序写反了</td><td>记住签名是 <code>matchingApiFunc(methodName, callback, params)</code>——<code>callback</code> 在第 2 位,<code>params</code> 在第 3 位!</td></tr><tr><td>进机库一直卡在「正在加载」</td><td>新增或修补后的完整 <code>.nut</code> 存在词法作用域重名、未声明标识符、保留字 <code>base</code> 误用或反引号字符串 `<code> </code>...<code> </code><code> | 用 </code>sq.exe<code> 对**完整 </code>.nut<code> 文件**跑 </code>compilestring<code> 字节码校验,插值字符串统一用 </code>$&quot;...&quot;`</td><td></td></tr><tr><td>日志提示 <code>overlaps protected core patch</code></td><td>模组的 <code>client/exe-patches/</code> 试图修改离线版核心隔离补丁锁定的字节区间</td><td>核心隔离区段受保护不可覆盖,请改用非重叠地址或服务端方案</td></tr><tr><td>日志提示 <code>target already exists as a native/player file</code></td><td><code>client/files/</code> 中的某文件与玩家自己在 <code>UserSkins/</code> 或 <code>UserSights/</code> 手动放的文件重名</td><td>给模组附带的配套子目录加上专属前缀(如 <code>mod_&lt;你的id&gt;_...</code>)避免撞名</td></tr></tbody></table></div>
<hr>
<h3 id="ch-07-zh-3-开发调试热重载循环-改完文件怎么最快看到效果">3. 开发调试热重载循环(改完文件怎么最快看到效果?)</h3>
<p>在本地编写与调试模组时,了解客户端与服务端各自的加载时机能省下大量时间:</p>
<ol><li><strong>修改客户端内容(<code>client/packs/</code>、<code>client/gui-patches/</code>、<code>client/exe-patches/</code>、<code>client/addon/</code>、<code>client/files/</code>、<code>config-blk.patch.jsonc</code>)</strong>:
<ul><li>先正常退出游戏客户端;</li><li>保存你修改的模组源文件后,直接在启动器点击 <strong>「启动游戏」</strong>:启动器会自动比对所有启用模组源文件的大小与修改时间指纹(Fingerprint),一旦发现任一补丁或包内文件有改动,就会自动从 <code>wtoffline/stock/</code> 重新叠加生成最新数据包并启动游戏!</li><li>提示:如果只是微调已通过 NTFS Junction 挂载的 <code>client/addon/res/</code> 或 <code>client/files/UserSkins/&lt;子目录&gt;/</code> 内部贴图,文件本身已经是零拷贝直连的,重启游戏(或游戏内点刷新涂装)即可直接读取最新文件。</li></ul></li><li><strong>修改服务端内容(<code>server/index.ts</code> 与 <code>server/tuning/*.jsonc</code>)</strong>:
<ul><li>每次退出游戏并在启动器重新点击 <strong>「启动游戏」</strong>拉起新一轮本地服务器会话时,服务器都会重新合并全部 <code>server/tuning/*.jsonc</code>,并通过带时间戳的 ESM 动态导入(<code>?wto_mod=&lt;timestamp&gt;</code>)全新加载 <code>server/index.ts</code>,无需重启启动器本身。</li></ul></li></ol>
<hr>
<h3 id="ch-07-zh-4-模组打包与发布分享规范-zip-结构">4. 模组打包与发布分享规范(<code>.zip</code> 结构)</h3>
<p>当你完成测试准备把模组分享给其他玩家时,请遵循统一的压缩包目录约定,让玩家解压即用、不踩套娃目录坑:</p>
<ol><li><strong>压缩包内保留且仅保留一层顶层模组文件夹</strong>: 假设你的模组目录叫 <code>my-awesome-mod</code>,打包后的 <code>my-awesome-mod.zip</code> 内部结构应当是:</li></ol>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>my-awesome-mod.zip
└─ my-awesome-mod/ &lt;-- 唯一顶层文件夹(玩家直接解压到 mods/ 即可得到 mods/my-awesome-mod/mod.jsonc)
├─ mod.jsonc
├─ client/
└─ server/</code></pre></div>
<ul><li><strong>不要</strong>把 <code>mod.jsonc</code> 裸放在 <code>.zip</code> 根目录(玩家直接“解压到当前文件夹”会把散文件撒满 <code>mods/</code> 根目录导致无法识别);</li><li>也<strong>不要</strong>套两层文件夹(如 <code>my-awesome-mod/my-awesome-mod/mod.jsonc</code>),启动器只扫描 <code>mods/</code> 下的一级子目录!</li></ul>
<ol start="2"><li><strong>打包前清理无关开发垃圾文件</strong>: 请剔除 <code>.git/</code>、<code>node_modules/</code>(若用第三方库请预打包进单文件 <code>server/index.mjs</code>)、<code>.DS_Store</code>、<code>Thumbs.db</code>、编辑器备份文件(<code>*.bak</code>、<code>*.swp</code>)以及临时解包参考用的原版大文件。</li></ol>
<hr>
<h3 id="ch-07-zh-5-跨盘与非-ntfs-磁盘行为说明">5. 跨盘与非 NTFS 磁盘行为说明</h3>
<ul><li><strong>NTFS 硬盘(绝大多数 Windows 电脑)</strong>:<code>client/addon/</code>(3D 模型与贴图)和单模组独占子目录(如 <code>UserSkins/&lt;子目录&gt;</code>)全部通过 <strong>NTFS Directory Junction</strong> 挂载——<strong>跨盘可用、免管理员权限、0 额外空间、约 1 毫秒完成</strong>;</li><li><strong>平铺共享目录散文件(如 <code>sound/mod/*.bank</code>)</strong>:依次尝试文件符号链接(开启 Windows 开发者模式时跨盘零拷贝)→ 同盘硬链接 → 按文件大小与修改时间比对的增量缓存复制(未改动文件下次启动自动跳过);</li><li><strong>exFAT 移动硬盘</strong>:因文件系统不支持 Junction 和硬链接,自动退化为按大小与修改时间比对的增量缓存复制,功能照常可用。</li></ul>
<hr>
<h3 id="ch-07-zh-6-开发与发布建议">6. 开发与发布建议</h3>
<ol><li><strong>命名空间隔离</strong>:模组 ID 用 <code>&lt;作者&gt;.&lt;模组名&gt;</code>;新增载具 ID、武器、涂装子目录、自定义匹配 RPC(<code>wto_mod.&lt;模组名&gt;.*</code>)、自定义 Char 动作均加上专属前缀,避免与其他模组撞名;</li><li><strong>公共表优先使用增量补丁而非整文件覆盖</strong>:修改 <code>shop.blk</code>、<code>wpcost.blk</code>、<code>unittags.blk</code>、<code>units.csv</code>、<code>menu.csv</code> 时使用 <code>.patch.jsonc</code> / <code>.patch.csv</code>,多车礼包与抽卡箱数组使用 <code>$listOps</code>;</li><li><strong>只读原版,不污染玩家主存档</strong>:模组自定数据一律写进 <code>ctx.storage.forPlayer(userId)</code>,卸载模组后玩家主存档干干净净;</li><li><strong>界面大逻辑拆独立文件</strong>:新弹窗放 <code>client/packs/gui.vromfs.bin/</code>,<code>client/gui-patches/</code> 里只留几行挂入口按钮与 <code>@import</code> 样式的最小补丁,游戏大版本更新时几乎不用重写;</li><li><strong>发布前做一次完整的「启用 → 进游验证 → 关闭 → 再进游还原」测试循环</strong>:确认启用时功能正常、关闭后彻底无痕还原,且能与其他常用模组同时勾选共存。</li></ol>
</div>
<div class="lang-en">
<h2>07 · Troubleshooting, Logs, Reload Loop &amp; Packaging</h2>
<h3 id="ch-07-en-1-where-to-check-logs-when-something-goes-wrong">1. Where to Check Logs When Something Goes Wrong</h3>
<p>All mod build and runtime logs flow into the launcher's standard log directory—open <strong>Settings › Diagnostics › Open logs folder</strong> or <strong>About › Export diagnostics</strong>:</p>
<ol><li><strong>Launcher Main Log (<code>launcher.log</code>)</strong>:
<ul><li>Filter <code>[build]</code>: see which mods ran in the current build, <code>.vromfs.bin</code> overlay counts, and exact reasons why any <code>gui-patches</code> or <code>exe-patches</code> item was skipped;</li><li>Filter <code>[mods]</code>: see cross-drive Junction mounts, skipped native player-file collision warnings, and restored on-demand stock packs;</li><li>Filter <code>[server]</code> or <code>[mod:&lt;yourModId&gt;]</code>: see server <code>tuning</code> validation errors, script load stack traces, and everything printed via <code>ctx.logger.info/warn/error</code>.</li></ul></li><li><strong>Game Client Runtime Logs (<code>&lt;copyFolder&gt;/.game_logs/*.clog</code>)</strong>:
<ul><li>If a client UI script throws at runtime or hangs on &quot;Loading&quot;, check the newest <code>.clog</code> (and run <code>sq.exe</code> full bytecode verification from Chapter 04);</li><li>If a custom 3D model fails to appear, search <code>.clog</code> for <code>[PACK]</code>, <code>pkg_user</code>, or your asset name to confirm engine mounting.</li></ul></li></ol>
<hr>
<h3 id="ch-07-en-2-common-issues-solutions-lookup-table">2. Common Issues &amp; Solutions Lookup Table</h3>
<div class="doc-table-wrap"><table class="doc-table"><thead><tr><th>Symptom / Log Message</th><th>Common Cause</th><th>Solution</th></tr></thead><tbody><tr><td>Discovery error on Launcher Mods page</td><td><code>mod.jsonc</code> syntax error, unknown field name, uppercase/invalid <code>id</code>, or missing <code>server.entry</code> file</td><td>Validate <code>mod.jsonc</code> against the schema table in Chapter 01 Section 5</td></tr><tr><td>&quot;Blocking mod errors&quot; when clicking Launch</td><td>Missing or disabled <code>requires</code> dependency, or two enabled mods declaring <code>conflicts</code></td><td>Enable the missing dependency or disable one of the conflicting mods highlighted in red</td></tr><tr><td><code>server/tuning/*.jsonc</code> changes appear ignored</td><td>Test client has a manual override saved in the Launcher <strong>Tuning</strong> tab (<code>&lt;dataFolder&gt;/tuning/*.jsonc</code> has highest priority), or <code>store.jsonc</code> placed <code>vehiclePacks</code> subkeys at root</td><td>Reset overridden fields in the Launcher <strong>Tuning</strong> tab and check <code>vehiclePacks</code> nesting + <code>&quot;gjn&quot;</code> key names in Chapter 05</td></tr><tr><td>Server <code>.ts</code> fails with syntax or module-not-found error</td><td>Raw <code>.ts</code> used <code>enum</code>/<code>namespace</code>, or value-imported <code>import { ... } from '@wto/mods'</code></td><td>Replace <code>enum</code> with <code>as const</code> + union type; use <code>import type { ... } from './server-api.ts'</code> for types</td></tr><tr><td><code>gui-patches</code> fails with <code>the data pack has no script ...</code></td><td><code>variant.file</code> in <code>patch.jsonc</code> used camelCase / uppercase letters (e.g. <code>scripts/gameModes/...</code>)</td><td>Change <code>variant.file</code> to <strong>all lowercase</strong> (e.g. <code>scripts/gamemodes/gamemodeselect.nut</code>)</td></tr><tr><td>Standalone <code>.css</code> stylesheet has no effect</td><td>Added <code>.css</code> to <code>client/packs/gui.vromfs.bin/</code> without registering it in <code>gui/css.css</code></td><td>Add a <code>client/gui-patches/</code> patch on <code>gui/css.css</code> appending <code>@import &quot;folderstyle.css&quot;</code> (Chapter 04 Section 2.2)</td></tr><tr><td>Client <code>matchingApiFunc</code> callback does not fire or <code>params</code> arrive empty</td><td>Swapped the 2nd and 3rd arguments of <code>matchingApiFunc</code></td><td>Use <code>matchingApiFunc(methodName, callback, params)</code> (<code>callback</code> is 2nd, <code>params</code> is 3rd)</td></tr><tr><td>Game hangs indefinitely on &quot;Loading&quot; before hangar</td><td>Resulting complete <code>.nut</code> file has a lexical scope collision, undeclared identifier, <code>base</code> keyword misuse, or backtick string `<code> </code>...<code> </code><code> | Run </code>sq.exe<code> </code>compilestring<code> on the **complete </code>.nut<code> file** and use </code>$&quot;...&quot;` for string interpolation</td><td></td></tr><tr><td>Log reports <code>overlaps protected core patch</code></td><td>Mod <code>client/exe-patches/</code> overlaps locked core offline/isolation patch bytes</td><td>Core isolation bytes are protected; pick a non-overlapping site or use a server-side hook</td></tr><tr><td>Log reports <code>target already exists as a native/player file</code></td><td>A path under <code>client/files/</code> collides with a player-owned file in <code>UserSkins/</code> or <code>UserSights/</code></td><td>Prefix bundled companion subfolders with your mod namespace (e.g. <code>mod_&lt;yourId&gt;_...</code>)</td></tr></tbody></table></div>
<hr>
<h3 id="ch-07-en-3-development-reload-loop-fastest-edit-test-cycle">3. Development Reload Loop (Fastest Edit-Test Cycle)</h3>
<p>Knowing when client builds versus server scripts reload keeps iteration fast while developing:</p>
<ol><li><strong>Client-side edits (<code>client/packs/</code>, <code>client/gui-patches/</code>, <code>client/exe-patches/</code>, <code>client/addon/</code>, <code>client/files/</code>, <code>config-blk.patch.jsonc</code>)</strong>:
<ul><li>Close the running game client first;</li><li>Save your edited mod files and click <strong>Launch</strong> in the launcher: the launcher hashes source file sizes and <code>mtime</code> timestamps into a deterministic build fingerprint, automatically rebuilding any affected <code>.vromfs.bin</code> packs from <code>wtoffline/stock/</code> before starting the game!</li><li>Tip: textures inside already-mounted NTFS Junction directories (<code>client/addon/res/</code> or <code>client/files/UserSkins/&lt;subfolder&gt;/</code>) point directly to your <code>mods/</code> folder with zero copying, so restarting the client (or refreshing skins in-game) reads updated assets immediately.</li></ul></li><li><strong>Server-side edits (<code>server/index.ts</code> &amp; <code>server/tuning/*.jsonc</code>)</strong>:
<ul><li>Every time you exit the game and click <strong>Launch</strong> to start a new session, the local server restarts cleanly, re-merges all <code>server/tuning/*.jsonc</code> overlays, and reloads <code>server/index.ts</code> with a cache-busting ESM query (<code>?wto_mod=&lt;timestamp&gt;</code>)—no need to restart the launcher itself.</li></ul></li></ol>
<hr>
<h3 id="ch-07-en-4-packaging-sharing-your-mod-zip-layout-rules">4. Packaging &amp; Sharing Your Mod (<code>.zip</code> Layout Rules)</h3>
<p>When packaging your mod for players to download, follow a consistent archive structure so unzipping into <code>mods/</code> works every time:</p>
<ol><li><strong>Wrap your mod in a single top-level <code>&lt;mod-folder&gt;/</code> directory inside the <code>.zip</code></strong>: For a mod folder named <code>my-awesome-mod</code>, structure <code>my-awesome-mod.zip</code> as:</li></ol>
<div class="doc-pre"><div class="doc-pre-head"><span>text</span><button class="hash-copy" type="button" data-copy-code><span class="lang-zh">复制</span><span class="lang-en">Copy</span></button></div><pre><code>my-awesome-mod.zip
└─ my-awesome-mod/ &lt;-- Single top-level folder (extracting straight into mods/ yields mods/my-awesome-mod/mod.jsonc)
├─ mod.jsonc
├─ client/
└─ server/</code></pre></div>
<ul><li><strong>Do NOT</strong> place <code>mod.jsonc</code> loose at the root of the <code>.zip</code> (extracting into <code>mods/</code> scatters loose files across <code>mods/</code> where discovery ignores them);</li><li><strong>Do NOT</strong> double-nest folders (<code>my-awesome-mod/my-awesome-mod/mod.jsonc</code>), as the launcher scans direct child directories of <code>mods/</code> only!</li></ul>
<ol start="2"><li><strong>Exclude development &amp; temporary clutter</strong>: Omit <code>.git/</code>, <code>node_modules/</code> (bundle third-party JS dependencies into a single <code>server/index.mjs</code> if needed), <code>.DS_Store</code>, <code>Thumbs.db</code>, editor backup files (<code>*.bak</code>, <code>*.swp</code>), and any unpacked stock game reference files.</li></ol>
<hr>
<h3 id="ch-07-en-5-cross-drive-non-ntfs-disk-behavior">5. Cross-Drive &amp; Non-NTFS Disk Behavior</h3>
<ul><li><strong>NTFS Volumes (standard on Windows)</strong>: <code>client/addon/</code> (3D models &amp; textures) and mod-exclusive subfolders (e.g. <code>UserSkins/&lt;subfolder&gt;</code>) mount via <strong>NTFS Directory Junctions</strong>—<strong>works across drives, requires no admin rights, uses 0 extra disk space, and completes in ~1 ms</strong>;</li><li><strong>Shared Flat-Folder Files (e.g. <code>sound/mod/*.bank</code>)</strong>: tries file symlink (zero-copy across drives when Windows Developer Mode is on) → same-drive NTFS hardlink → incremental size/mtime cached copy (unchanged files are skipped on subsequent launches);</li><li><strong>exFAT External Drives</strong>: since exFAT does not support Junctions or hardlinks, the deployer automatically falls back to incremental size/mtime cached copies with full functional parity.</li></ul>
<hr>
<h3 id="ch-07-en-6-practical-recommendations-for-mod-authors">6. Practical Recommendations for Mod Authors</h3>
<ol><li><strong>Namespace Everything</strong>: format your mod ID as <code>&lt;author&gt;.&lt;mod-name&gt;</code> and prefix custom vehicle IDs, weapons, skin subfolders, custom matching RPCs (<code>wto_mod.&lt;mod_name&gt;.*</code>), and custom Char actions to avoid collisions between mods;</li><li><strong>Prefer Incremental Patches Over Replacing Shared Tables</strong>: use <code>.patch.jsonc</code> / <code>.patch.csv</code> for <code>shop.blk</code>, <code>wpcost.blk</code>, <code>unittags.blk</code>, <code>units.csv</code>, and <code>menu.csv</code>, and use <code>$listOps</code> on shared tuning arrays like <code>multiVehiclePacks</code> and <code>supplyTrophies</code>;</li><li><strong>Read Stock Profiles, Persist in Isolated Storage</strong>: write all custom mod state to <code>ctx.storage.forPlayer(userId)</code> so player saves remain 100% clean if your mod is disabled or uninstalled;</li><li><strong>Keep UI Logic in Standalone Files</strong>: put custom modals under <code>client/packs/gui.vromfs.bin/</code> and keep <code>client/gui-patches/</code> down to a few lines wiring the entry button and <code>gui/css.css</code> <code>@import</code> so game updates rarely break your mod;</li><li><strong>Run One Full &quot;Enable → Play → Disable → Relaunch&quot; Cycle Before Release</strong>: verify your mod works when enabled, restores stock behavior cleanly when disabled, and coexists peacefully alongside other enabled mods.</li></ol>
</div>
<hr>
<div class="doc-links">
<a class="btn btn-primary" href="https://git.wto-project.net/Sh3ll_in_Sh3ll/WT-Offline/src/branch/main/mod-dev-docs/templates" target="_blank" rel="noopener">
<span class="lang-zh">浏览 3 套官方模组模板源码 ↗</span>
<span class="lang-en">Browse 3 Official Mod Templates ↗</span>
</a>
<a class="btn btn-ghost" href="/dev-docs">
<span class="lang-zh">阅读开发者手册 →</span>
<span class="lang-en">Read Developer Handbook →</span>
</a>
</div>
<div class="doc-pager">
<a class="doc-pager-btn" href="#ch-06" data-chapter="ch-06"><span class="doc-pager-label"><span class="lang-zh">← 上一章</span><span class="lang-en">← Previous</span></span><span class="doc-pager-title"><span class="lang-zh">06 · 服务端 JS/TS 脚本 API</span><span class="lang-en">06 · Server Scripting API</span></span></a>
</div>
</article>
</div>
</div>
</div>
<footer>
<div class="wrap">
<div class="foot">
<span class="foot-brand">
<img src="assets/icon.svg" alt="" width="20" height="20" draggable="false">
WTOffline · AGPL-3.0-or-later
</span>
<span class="right">
<a href="/"><span class="lang-zh">主页</span><span class="lang-en">Home</span></a>
<a href="/releases"><span class="lang-zh">全部版本</span><span class="lang-en">All Releases</span></a>
<a href="/dev-docs"><span class="lang-zh">开发者文档</span><span class="lang-en">Dev Docs</span></a>
<a href="https://git.wto-project.net/Sh3ll_in_Sh3ll/WT-Offline" target="_blank" rel="noopener">Gitea</a>
<a href="https://github.com/N0VAN0M4LY/WT-Offline" target="_blank" rel="noopener">GitHub</a>
<a href="https://discord.gg/P566xWNpEs" target="_blank" rel="noopener">Discord</a>
</span>
</div>
<p class="disclaimer">
<span class="lang-zh">声明:本项目是非商业性质的同人开源项目,与 Gaijin Entertainment 没有任何关联,也未获其认可。War Thunder 及相关名称与素材归其各自所有者所有。本项目不分发任何游戏文件,使用者须自行拥有合法的游戏客户端。</span>
<span class="lang-en">Disclaimer: This is a non-commercial open-source fan project and is not affiliated with or endorsed by Gaijin Entertainment. War Thunder and related names and assets belong to their respective owners. No game files are distributed; you need your own legitimate copy of the client.</span>
</p>
</div>
</footer>
</main>
<script src="site/home.js"></script>
</body>
</html>