返回 WTOffline 主页 Back to WTOffline Home
MOD AUTHORING GUIDE · API 0.1-EXPERIMENTAL

模组制作文档 Mod Authoring Documentation

WTOffline 采用添加式、按加载顺序逐层叠加的模组架构:支持零代码数值覆盖、客户端数据包增量补丁、自定义 3D 模型载具、原生 GUI 扩展与服务端 JS/TS 脚本,关掉模组自动还原不污染原版。 WTOffline uses an additive, load-order-layered mod system supporting code-free tuning overlays, incremental client archive patches, custom 3D vehicles, native UI extensions, and Node 24 JS/TS server scripts—cleanly reverted when disabled.

1. 快速入门与清单规范(mod.jsonc) 1. Quick Start & Manifest (mod.jsonc)

实验期声明(api_version: "0.1-experimental"):WTOffline 处于早期开发阶段,服务端脚本接口、钩子契约和声明式 exe 补丁格式可能随本体演进调整,现阶段不承诺向后兼容。 Experimental Notice (api_version: "0.1-experimental"): WTOffline is in early development. Server script APIs, hook contracts, and declarative exe patch formats may change across releases without backwards compatibility.

启动游戏前,启动器从纯净备份(wtoffline/stock/)出发,先应用核心离线补丁,再按玩家在「模组」页排好的顺序叠加各模组(越靠下优先级越高)。全局模组仓库默认在 %APPDATA%\WTOffline Launcher\mods,可在启动器内自由修改。 Before launch, the launcher starts from the clean stock backup (wtoffline/stock/), applies core offline patches, and layers enabled mods in order (lower items win). The default mod repository is %APPDATA%\WTOffline Launcher\mods and can be moved in the launcher.

最小模组示例(5 分钟上手)Minimal Mod Example (5-Minute Start)

my-first-mod/mod.jsonc
{
  "format": 1,
  "id": "demo.my-first-mod",
  "name": { "zh-CN": "我的第一个模组", "en": "My First Mod" },
  "version": "0.1.0",
  "author": "YourName",
  "description": {
    "zh-CN": "把对局银狮和研发点倍率调整为 2 倍。",
    "en": "Doubles Silver Lions and Research Points battle rewards."
  },
  "api_version": "0.1-experimental",
  "game_versions": ["2.61.0.*"]
}
my-first-mod/server/tuning/battle.jsonc
{
  "rewardMultiplierSilverLions": 2.0,
  "rewardMultiplierResearchPoints": 2.0
}

完整标准目录结构(按需创建)Standard Folder Layout (Create Only What You Use)

Layout
<mod-folder>/
├─ mod.jsonc                        # Required manifest (strict whitelist schema)
├─ server/                          # Optional server extensions
│  ├─ tuning/*.jsonc                #   Code-free tuning overlays
│  └─ index.ts (or .mjs / .js)      #   Server script entry (auto-detected)
└─ client/                          # Optional client overlays
   ├─ packs/<archive>.vromfs.bin/   #   Incremental BLK/CSV patches or added files
   ├─ addon/res/                    #   3D models (.grp) & textures (.dxp.bin)
   ├─ gui-patches/<patch>/          #   Incremental Quirrel UI script patches
   ├─ exe-patches/<patch>/          #   Declarative signature-based exe patches
   ├─ files/                        #   Bundled skins/sights/sound packs
   └─ config-blk.patch.jsonc        #   Incremental patch for root config.blk

清单字段与能力徽标Key Manifest Fields & Risk Badges

  • 必填字段Required:format(1)、id(小写字母/数字/._-,推荐 <作者>.<模组名>)、name、version、author、api_version("0.1-experimental")。
  • 依赖与排序Dependencies & Ordering:requires(缺项阻断启动)、conflicts(互斥阻断启动)、load_after / load_before(自动排序建议)、game_versions(通配符,不符仅告警)。
  • 风险徽标Capability Badges:启动器自动标注 data(纯数据/资源)、gui(界面补丁)、script(服务端脚本)、exe(二进制补丁,受核心隔离锁保护)。The launcher auto-tags mods as data, gui, script, or exe (protected by core isolation locks).

2. 客户端数据包与 BLK / CSV 增量补丁 2. Client Archives & Incremental BLK / CSV Patching

支持叠加 8 个数据包: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。服务端启动时直接读取叠加后的包,新增或改动的载具价格、科技树与权重会自动同步生效。 Eight archives support additive overlays: char, aces, gui, lang, mis, game, ui/atlases, and ui/images. The local server reads the overlaid archives at startup, automatically picking up edited vehicle trees, costs, and BRs.

  • <path>.patch.jsonc:保留类型的 BLK 增量补丁,支持全部 7 种操作:setParam、addParam、removeParam、upsertBlock、addBlock(支持 before/after)、removeBlock 与 cloneBlock;路径支持 range[0] 下标寻址。Type-preserving BLK patch supporting all 7 operations: setParam, addParam, removeParam, upsertBlock, addBlock (with before/after), removeBlock, and cloneBlock, with indexed paths like range[0].
  • <path>.patch.csv:按第 1 列词条键增量合并本地化表(更新已有键或追加新键),绝不整表覆写。Merges localization entries by first-column key without replacing the whole table.
  • 其余新增文件Added files:文本 .blk 自动编译为二进制 BLK;.svg / .ddsx / .nut / .tpl 原样写入。Text .blk files are compiled to binary BLK automatically; .svg, .ddsx, .nut, and .tpl are embedded as-is.

3. 添加全新 3D 模型与贴图载具 3. Adding Custom 3D Vehicle Models & Textures

把 CDK 导出的 .grp 模型与 .dxp.bin 贴图放入 client/addon/res/。启动器自动通过 Windows NTFS 目录联接点(Junction)挂载到 content/pkg_user/<modId>——支持跨盘、免管理员、零额外磁盘空间、约 1 毫秒完成,关闭模组即拆除。 Place CDK-exported .grp models and .dxp.bin textures under client/addon/res/. The launcher mounts them to content/pkg_user/<modId> via a zero-copy cross-drive NTFS Junction (no admin required, removed cleanly on disable).

  1. 模型与贴图:放入 client/addon/res/<unit_id>.grp 与 .dxp.bin;Model & textures: place .grp and .dxp.bin in client/addon/res/.
  2. 物理与武器配置:放进 client/packs/aces.vromfs.bin/gamedata/units/.../<unit_id>.blk;Unit config: add gamedata/units/.../<unit_id>.blk under client/packs/aces.vromfs.bin/.
  3. 经济与科技树:用 .patch.jsonc 修改 wpcost.blk(推荐 cloneBlock)、shop.blk 与 unittags.blk(若带 gift:t="msi_notebook",构建器自动为其登记本地商店 GUID);Economy & tree: patch wpcost.blk (cloneBlock is fastest), shop.blk, and unittags.blk; setting gift:t="msi_notebook" auto-registers a local store GUID.
  4. 译名与图标:用 units.csv.patch.csv 加中英文名,图标放入全小写路径 ui/atlases.vromfs.bin/gameuiskin/<unit_id>_ico.svg。Localization & icons: add names via units.csv.patch.csv and lowercase gameuiskin/<unit_id>_ico.svg.
原生目录保护:普通独立涂装、瞄具与单人任务照旧放进 UserSkins/、UserSights/ 即可;大型整合包附带资源可放 client/files/,若与玩家已有原生文件撞名会自动跳过,绝不覆盖。 Native file protection: Standalone skins/sights belong in UserSkins/ and UserSights/. Bundled assets in client/files/ never overwrite existing player files.

4. 客户端 GUI 补丁与声明式 EXE 补丁 4. Client GUI Patches & Declarative EXE Patches

  • 界面扩展最佳实践UI Extension Pattern:大块逻辑写成独立 .nut / .tpl / .css 放进 client/packs/gui.vromfs.bin/,再在 client/gui-patches/ 用几行最小增量补丁挂载入口按钮;每条 find 必须唯一命中,否则整条跳过。Place new modals/logic as standalone .nut/.tpl/.css files in client/packs/gui.vromfs.bin/, and keep client/gui-patches/ minimal to hook entry buttons. Every find fragment must match exactly once.
  • 必做 Quirrel 字节码检查Mandatory Quirrel Bytecode Check:局部变量与 from ... import * 重名、前向引用或误用保留字(如 base)会导致进机库卡死在「正在加载」;务必用 sq.exe 的 compilestring 完整编译检查。Lexical scope clashes, forward references, or reserved words like base freeze login on loading. Always validate with sq.exe using compilestring.
  • 声明式 EXE 补丁与隔离红线Declarative EXE Patches & Isolation Lock:复用 @wto/exepatch 的特征码格式放入 client/exe-patches/,严禁分发改过的 aces.exe;任何企图触碰离线核心隔离补丁字节区段的模组都会被直接拒绝。Use @wto/exepatch signature patches in client/exe-patches/—never redistribute patched aces.exe. Patches overlapping protected core isolation bytes are rejected.

5. 服务端零代码数值叠加(server/tuning/) 5. Code-Free Server Tuning Overlays

12 份配置文件均可叠加:battle、battle-economy、store、marketplace、trophies、supply-chests、recycling、redeem-codes、new-profile、research、clans、limits。合并优先级:内置默认 < 模组(按排序) < 玩家在启动器「数值」页的手动覆盖。 All 12 tuning files are overlayable (battle, battle-economy, store, marketplace, trophies, supply-chests, recycling, redeem-codes, new-profile, research, clans, limits). Precedence: defaults < enabled mods in order < player overrides.

数组字段支持 $listOps(append、prepend、upsertBy、removeBy),让多个模组往礼包/兑换码/奖池追加条目时互不覆盖: Array fields support $listOps (append, prepend, upsertBy, removeBy) so multiple mods can extend packs, codes, or pools without clobbering each other:

server/tuning/store.jsonc · $listOps
{
  "multiVehiclePacks": {
    "$listOps": [
      { "op": "upsertBy", "key": "id", "item": { "id": "wto_pack_two_fronts", "priceGjn": 19.99 } }
    ]
  }
}

6. 服务端 JS / TS 脚本 API 6. Server JS / TS Scripting API

运行于启动器内置 Node.js 24(原生开启 TypeScript 类型剥离),默认探测 server/index.ts → .mjs → .js。直接写 .ts 请遵循 erasableSyntaxOnly(避免 enum、namespace 和构造函数参数属性;如需第三方依赖可自行打包为单文件 .mjs)。 Runs on bundled Node.js 24 with native TypeScript type stripping, auto-detecting server/index.ts → .mjs → .js. Follow erasableSyntaxOnly for raw .ts (no enum/namespace/parameter properties), or bundle to a single .mjs.

server/index.ts · Example
export default {
  async setup(ctx) {
    ctx.logger.info('mod ready');

    // Filter candidate maps before matchmaking picks one
    ctx.hooks.battle.onFilterMissions(({ missions }) => {
      const picked = missions.filter((m) => /poland|berlin/i.test(m.level ?? m.name));
      return picked.length > 0 ? picked : undefined;
    });

    // Register a custom matching RPC callable from Quirrel UI scripts
    ctx.routes.matching.register('wto_mod.demo.ping', ({ userId, params }) => {
      const store = ctx.storage.forPlayer(userId);
      const count = (store.read<{ count: number }>()?.count ?? 0) + 1;
      store.write({ count });
      return { ok: true, count, echo: params };
    });
  },
};
  • ctx.storage:forPlayer(userId)(按玩家隔离存进 saves/<uid>/mods/<modId>.json)与 shared(),原子写盘,切勿往原版 profile.blk 塞非标准字段。forPlayer(userId) and shared() atomic JSON stores—never pollute stock profile.blk with non-standard fields.
  • ctx.hooks:onDatasetsLoaded、onCataloguesReady、onServerListening、onServerClosing、profile.onRefresh,以及 battle 下的 onBeforeMatchmake、onFilterMissions、onLiveFact、onAfterSettle。onDatasetsLoaded, onCataloguesReady, onServerListening, onServerClosing, profile.onRefresh, and battle.{onBeforeMatchmake, onFilterMissions, onLiveFact, onAfterSettle}.
  • ctx.routes:支持 char、matching(register / wrap)与本地 HTTP 路由扩展。Register or wrap char actions, matching RPCs, and local HTTP routes.

7. 内置官方模板、排错日志与 5 条黄金习惯 7. Bundled Templates, Logs & Best Practices

启动器首次初始化模组目录时会自动分发 3 套官方模板(默认关闭,勾选即用),可直接对照学习: Three official templates are seeded into a fresh mods folder on first launch (disabled by default) as runnable references:

模板Template 演示能力Demonstrates
example-vehicle-tweak零代码数据与本地化:battle.jsonc + wpcost.blk.patch.jsonc + units.csv.patch.csv。Code-free data & localization: battle.jsonc + wpcost.blk.patch.jsonc + units.csv.patch.csv.
example-server-script最小服务端脚本:onDatasetsLoaded、profile.onRefresh、独立存档与自定义 HTTP 路由。Minimal server script: onDatasetsLoaded, profile.onRefresh, isolated storage, and custom HTTP route.
official-map-selector完整全栈官方模组:UI 入口补丁 + 原生 DaGui 小地图网格弹窗 + 匹配 RPC + 独立存储 + battle.onFilterMissions 选图。Full-stack official mod: UI button patch + native DaGui map grid modal + matching RPC + storage + battle.onFilterMissions.

排错与 5 条黄金习惯Troubleshooting & 5 Golden Rules

  • 查日志位置:启动器「设置 → 诊断 → 打开日志目录」查看 launcher.log(搜索 [build]、[mods]、[mod:<id>]),客户端界面/模型报错看 .game_logs/*.clog。Logs: Open the log folder in Launcher Settings → Diagnostics for launcher.log ([build], [mods], [mod:<id>]) and check .game_logs/*.clog for client UI/model issues.
  • 命名空间隔离:ID、载具名、涂装目录与自定义 RPC 一律带专属前缀;公共表永远用增量补丁,绝不整文件覆写。Namespace everything: Prefix IDs, units, asset folders, and custom RPCs; always patch shared tables incrementally.
  • 发布前完整回归:做一次「开启 → 游玩 → 关闭 → 重启」循环,确保卸载后客户端与主存档干干净净。Test the full toggle loop: Enable → play → disable → restart to verify clean restoration.