返回 WTOffline 主页 Back to WTOffline Home
DEVELOPER DOCUMENTATION

开发者文档与贡献规范 Developer Docs & Contribution Standards

面向核心代码贡献者、版本适配者与使用 AI 辅助开发的协作者。写清架构分层、动态补丁做法、常见实现陷阱与提交前检查命令,让每一笔 PR 既解决根因又经得起后续版本演进。 For core contributors, client version adapters, and AI-assisted PR authors. Covers repository layering, dynamic patching, common implementation pitfalls, and required verification commands.

1. 常见实现陷阱与工程红线(含 AI 辅助开发对照) 1. Common Implementation Pitfalls (Including AI-Assisted PRs)

欢迎使用 AI 辅助定位根因。借助 AI 阅读反汇编、分析协议和定位 bug 非常高效;但真正提交代码前,请按下面 7 条正反对照逐项收口实现——也可以直接把本节作为约束交给你的 AI 助手。 AI-assisted root-cause analysis is welcome. Before opening a PR, review the implementation itself against the 7 engineering guardrails below—feel free to pass this section directly to your AI coding assistant as constraints.
维度Area 推荐做法Preferred Practice 避免做法Avoid
定位与偏移Locating & Offsets DOexe 与 native 一律通过 patches/exe/、patches/native/ 的 signature / string_ref / within 动态捕获地址、跳转目标与结构体偏移。Resolve addresses, jump targets, and struct offsets dynamically via signature, string_ref, or within captures in patches/. AVOID在 C/TS 代码里硬编码 RVA、结构体偏移、函数地址或 _ReturnAddress(游戏一个小补丁就会全断)。Hardcoding RVAs, struct offsets, raw function pointers, or _ReturnAddress checks in C or TypeScript.
改动分层Layering DO先看本地服务器协议、任务根字段或原版配置能否解决;严守协议层 / 规则层 / 存档层 / 数据层职责,修改档案先写盘再回复。Solve in the local server or stock config first; keep protocol, rules, persistence, and datasets separate, and write saves before replying. AVOID用客户端补丁绕开本该由服务端处理的问题;在协议处理器里堆大段规则;先回成功再写盘。Adding client hacks for server-solvable issues, mixing game rules into protocol handlers, or replying before persistence.
静态数据与数值Static Data & Tuning DO载具、任务、奖励、出生点等原版数据通过缓存 datasets/ 从玩家游戏文件读取;离线自定参数放进 apps/server/tuning/*.jsonc 并做启动校验。Read stock vehicle, mission, reward, and spawn data from player archives via cached datasets/; put offline defaults in tuning/*.jsonc with startup validation. AVOID在源码里手抄原版表、写死兜底坐标或散落魔法数字。Copying stock tables into source code, hardcoding fallback coordinates, or scattering magic constants.
复用与粒度Reuse & Modularity DO复用 local_mp_core 等公共站点与现有工具;共享库 packages/* 通过参数收配置;文件接近 300 行、函数接近 50 行时拆分职责。Reuse shared native sites (local_mp_core) and helpers; pass paths/config into packages/*; split files near 300 lines or functions near 50 lines. AVOID重复挂钩同一原生函数;让 packages/* 反向读取 apps/*;把多项职责塞进单个大文件或大函数。Duplicating hooks on the same symbol, reading apps/* from packages/*, or growing monolithic handlers.
编译器兼容Toolchains DONative C 必须用 MSVC native/wto-net/build.ps1 编过且 0 警告;TS 兼容 Node 24 原生类型剥离(erasableSyntaxOnly)。Build native C cleanly with MSVC native/wto-net/build.ps1 (zero warnings); keep TS compatible with Node 24 erasable syntax. AVOID引入 GCC 专属扩展(如 typeof / 语句表达式)或未在 MSVC 编过的 C 代码。Relying on GCC-only extensions or submitting C edits without an MSVC build check.
校验与验收Verification DO按变动运行 typecheck、check-patches、完整 check-gui(Quirrel 字节码检查)与临时副本构建,如实标注待实机验收项。Run the applicable typecheck, check-patches, full check-gui (Quirrel bytecode check), and temporary copy build; honestly mark pending in-game checks. AVOID只跑模拟单测就宣称实机无误;跳过 check-gui;在未实机验收前提交 patches/versions/*.jsonc。Treating mock tests as in-game verification, skipping check-gui, or committing patches/versions/*.jsonc before live acceptance.
范围与纪律Scope & Hygiene DO一笔 PR 专注单一目标,使用英文约定式提交与英文代码注释,Co-authored-by 只留给实际协作的人类开发者。Keep one goal per PR, use English conventional commits and English comments, and reserve Co-authored-by for human collaborators. AVOID夹带无关重构或格式改动、暴露个人本机绝对路径、给 AI 助手加 Co-authored-by。Mixing unrelated refactors, leaking personal paths, or adding AI tools in Co-authored-by.

2. 架构与代码分层 2. Architecture & Code Layering

WTOffline 采用与 SPT 类似的「本地模拟服务器 + 最小客户端补丁」路线:把客户端的所有联网请求重定向至 127.0.0.1,让原生游戏逻辑照常运行。只有在本地服务器和原版配置确实无法满足时,才向客户端新增补丁。 WTOffline redirects all client network requests to 127.0.0.1 and emulates online services locally so stock client logic runs naturally. Client patches are added only when the local server and stock configuration cannot solve a behavior.

目录Path 职责Responsibility
apps/server本地服务器:内部严格拆分为协议层、规则层、存档层与数据集提取层(src/game-data/datasets/)。Local server: strictly split into protocol, rules, persistence, and game-data extraction (src/game-data/datasets/).
apps/launcherElectron 安装器与启动器(React):副本管理、存档编辑、数值覆盖、模组管理与签名更新。Electron installer and launcher (React): copies, saves, tuning overrides, mods, and signed updates.
packages/*共享库(blk、vromfs、exepatch、jsonc、patcher、mods)。依赖只能从 apps/* 指向 packages/*。Shared libraries (blk, vromfs, exepatch, jsonc, patcher, mods). Dependencies flow strictly from apps/* to packages/*.
patches/补丁集根目录:exe/、gui/、native/ 定义与 versions/ 核对记录。Patch set root: exe/, gui/, native/ definitions and versions/ verification records.
native/wto-netwto_ws.dll C 源码:网络重定向钩子与 local_mp_*.c 本地主机对局桥接模块。wto_ws.dll C source: socket redirection hooks and local_mp_*.c local host battle modules.
scripts/ · tools/副本构建脚本、版本记录脚本,以及 Python 补丁核对工具 wtotools。Copy build and version record scripts, plus the Python wtotools patch verifier.
隔离与只读原则:原版游戏目录一律只读使用;启动调试游戏只能在 Steam 库之外的独立副本和断网/隔离环境进行,使用本地账号,严禁把修改后的文件写回线上客户端。 Isolation & Read-Only Source: Always treat your stock game folder as read-only. Launch test sessions only from a separate offline copy outside your Steam library with verified network/data isolation and a local account.

3. 三类数值与数据来源 3. Three Categories of Values & Data Sources

数值类别Category 放置位置与要求Where It Belongs
协议常量Protocol constants 包头长度、消息枚举、编码魔数等保留在代码中,并用英文注释注明版本和出处(优先引用 DagorEngine 公开源码 或目标构建)。Header sizes, message enums, and encoding magic stay in code with English comments citing the build or DagorEngine public source.
游戏文件已有数据Stock game data 载具、价格、改装件、任务、奖励表等在启动时通过 apps/server/src/game-data/datasets/ 从玩家原版文件提取并缓存;缺必需字段时明确报错,不悄悄塞入编造的默认值。Vehicles, prices, modifications, missions, and reward tables are extracted from the player's stock files via apps/server/src/game-data/datasets/. Report missing required fields and fail instead of substituting invented defaults.
离线版自定数值Offline tuning defaults 倍率、商店定价、箱子权重、上限、开关等统一放进 apps/server/tuning/*.jsonc,并在启动时做完整类型与范围校验;用户目录同名文件可按字段覆盖。Multipliers, store prices, crate weights, limits, and toggles live in apps/server/tuning/*.jsonc with startup schema validation and per-client overrides.

4. 补丁体系与动态定位规范 4. Patch System & Dynamic Locating

每处客户端改动独立成文件/目录,并在头部用英文注释写明三件事:改了什么、为什么本地服务器或配置做不到、不打会有什么后果。所有补丁加载器都采用严格字段校验,分析证据写在注释或 PR 里。 Keep one behavior per patch definition, with English top comments explaining what changes, why the local server/config is insufficient, and what breaks without it. Loaders reject unknown fields, so put evidence in comments or the PR.

  • patches/exe/<domain>/<name>/patch.jsonc:使用 signature 唯一匹配特征码(易变字节用 ?? 通配),配合 expect_original、asm/data 源码与 captures/fixups 动态回填跳转和地址。多版本差异在 variants 中追加写法,不复制整套补丁。Use unique signature patterns with ?? wildcards, expect_original, asm/data source, and captures/fixups. Add new build variants in variants instead of duplicating patches.
  • patches/gui/<domain>/<name>/:由 patch.jsonc 引用最小且唯一命中的 find.nut / replace.nut 片段;改完必须跑完整 wtotools check-gui(compilestring 词法作用域与字节码编译检查),绝不能只靠 AST 语法检查。Keep minimal unique find.nut / replace.nut fragments referenced by patch.jsonc. Always run the full wtotools check-gui (compilestring lexical scope and bytecode check), never AST-only checks.
  • patches/native/<module>.jsonc:通过 signature、string_ref 或 within 在构建期解析全部函数地址、全局变量与结构体偏移写入 wto_ws.cfg;native/wto-net/src/local_mp_*.c 不写死版本相关偏移。Resolve all target functions, globals, and struct offsets at build time via signature, string_ref, or within into wto_ws.cfg; keep local_mp_*.c free of version-specific offsets.
  • patches/versions/<ver>.jsonc:由 scripts/record-game-version.ts 生成,仅在全部检查通过且完成隔离副本实机验收后才可提交入库。Generated by scripts/record-game-version.ts; commit only after all checks pass and isolated in-game acceptance succeeds.

5. 环境准备与对应检查命令 5. Environment Setup & Check Commands

环境要求:Windows x64、Node.js 24+、Visual Studio / Build Tools(含 x64 C++ 工具,用于编译 wto_ws.dll)、Python 3.12+(仅 wtotools 需要),以及一份只读的原版游戏客户端。 Requirements: Windows x64, Node.js 24+, Visual Studio / Build Tools with x64 C++ tools (for wto_ws.dll), Python 3.12+ (for wtotools), and a read-only stock client folder.

PowerShell · Checks
# TypeScript & Launcher build
npm run typecheck
npm run typecheck --workspace "@wto/launcher"
npm run build --workspace "@wto/launcher"

# Native DLL build (MSVC x64, must compile cleanly)
powershell -NoProfile -File .\native\wto-net\build.ps1

# Exe & GUI patch checks (against read-only stock client)
.\.venv\Scripts\python.exe -m wtotools.cli check-patches --exe "<stock-dir>\win64\aces.exe"
.\.venv\Scripts\python.exe -m wtotools.cli check-gui --gui "<stock-dir>\gui.vromfs.bin" --sq "build\quirrel-cli\bin\Release\sq.exe"

# Temporary isolated copy build check
node scripts/build-game-copy.ts --game "<stock-dir>" --out "<temp-out-dir>" --data "<temp-data-dir>" --port 27015

说明:项目注重「语法 / 类型 / 补丁编译 / 可运行性检查 + 隔离副本人工实机验收」,不要求编写庞大脆弱的模拟测试套件;请把实际执行过的命令与客户端版本号如实填入 PR。 Note: Focus on typecheck, patch compilation, build, and runnable startup checks plus human in-game verification on an isolated copy rather than large mock test suites. Record the exact commands and client builds actually run in your PR.

6. 提交信息与 PR 提交流程 6. Commit Messages & PR Workflow

  • 英文约定式提交English Conventional Commits:格式为 type(scope): description(如 fix(battle): ...、feat(launcher): ...,仓库级用 repo);正文写明改动原因、一手证据和验证状态,代码注释统一用英文。Use type(scope): description (e.g., fix(battle): ..., feat(launcher): ..., or repo); document rationale, evidence, and verification in the body, with English code comments.
  • 如实填写 PR 模板Complete the PR Template:逐项勾选自查表,写清目标客户端版本、一手依据(脚本路径、游戏配置或 DagorEngine 源码)、实际运行的检查命令,以及待实机验证的操作入口和预期现象。Check every self-check item, list the target build and primary evidence, report executed checks honestly, and write clear in-game acceptance steps.
  • 只传最小自有代码No Game Assets or Player Data:切勿提交任何原版游戏文件、解包产物、玩家存档或未脱敏日志。Never commit stock game files, extracted archives, player saves, or unredacted personal logs.