# Patch guide 简体中文 · [English](#english) · [返回 Dev Docs](README.md#zh-cn) ## 从一个改动开始 先在目标版本核对原有行为。用英文注释说明改什么、为什么本地服务或游戏配置不足、缺少这一改动时玩家会看到什么。一个补丁目录处理一个行为。沿用项目已有的英文 `features` 标签,启动器用这些标签告知玩家哪些功能受影响。 复制下面对应的模板,再填入目标版本、路径和原内容。模板使用虚构的路径和数据。补丁加载器只接受定义中的字段,证据和解释写在注释或 PR 里。 | 改动 | 放置位置 | 模板与示例 | | --- | --- | --- | | exe 字节改动 | `patches/exe/<领域>/<名称>/patch.jsonc` | [模板](templates/exe/patch.jsonc) · [数据目录名称改动](../patches/exe/isolation/user-data-folder-name/patch.jsonc) | | 界面脚本改动 | `patches/gui/<领域>/<名称>/patch.jsonc` 及同目录片段 | [模板目录](templates/gui) · [教程跳过选项的保存改动](../patches/gui/tutorials/immediate-save-skip-tutorial/patch.jsonc) | | 本地对局的 native 模块定位 | `patches/native/<模块>.jsonc`,对应 `native/wto-net/src/<模块>.c` | [模板](templates/native/local_mp_example.jsonc) · [计分模块](../patches/native/local_mp_scores.jsonc) | ### exe 补丁 - `id` 用 `<领域>/<名称>`,`title` 说明效果,`features` 列出功能标签,`requires` 列出依赖的 exe 补丁 ID。 - 每个 `variant` 填 `written_for`、`locate` 和 `edit`。用 `signature` 按当前文件内容定位,使开发侧的 `check-patches` 和构建使用相同方式核对。特征需要唯一命中。为跨版本会变化的字节使用 `??`,把写入位置相对命中点的距离填到 `edit.offset`。 - `edit.expect_original` 核对原字节,与 `bytes` 等长。改代码用 `asm` 记汇编源码,改文本用 `data` 记编码和文本,检查工具核对源码与写入字节。随版本变化的值可通过 `captures` 读取,由 `fixups` 填入 `bytes` 里的空位。每种写法的注释记下核对版本、范围和通配或捕获的理由。 ### GUI 补丁 - 定义使用 `id`、`title`、`features` 和 `variants`。每种写法填 `written_for`、数据包内的脚本路径 `file` 和 `edits`。每条编辑的 `find` 与 `replace` 引用同目录的文件名。 - 将最小且唯一命中的原文逐字放进查找片段,缩进和空行也属于匹配内容。片段末尾的一个换行会被去掉,CRLF 和 LF 等效。新写法需要不同片段时另起文件名。替换片段需要本地服务地址时可用 `{{LOCAL_ENDPOINT}}` 代入构建时的主机和端口。 - 举例说,要改教程选项的保存行为,先核对目标脚本中的原回调和保存路径,再在对应的查找与替换片段记录差异。修改后对该版本原版数据包跑完整 `check-gui`,实机步骤写清勾选选项、退出再进入,以及期望看到的结果。[教程补丁示例](../patches/gui/tutorials/immediate-save-skip-tutorial) ### Native 模块 - `module` 与 JSONC 文件名一致。`requires` 填依赖的模块名。`sites` 用小写下划线命名,所有站点名在补丁集中唯一。每个站点的 `variants` 有 `written_for` 和 `locate`,各写法提供相同名称的捕获值。 - 定位可用 `signature`、按字符串引用定位的 `string_ref`,或在一个已定位站点所在函数内搜索的 `within`。构建解析站点和捕获值后写入 `wto_ws.cfg`。把随版本变化的地址和结构体偏移交给构建解析。站点缺失或不唯一时,相应模块及其依赖者会报告不可用。 ## 核对版本与提交 补丁引擎要求只有一种写法通过定位和原内容核对。构建会报告不可用项及受影响的功能,必需补丁失配时停止。[必需功能定义](../packages/patcher/src/essential-features.ts) 适配新版本时,先用只读原版文件生成一份本地核对记录,查看 `unavailable`,针对失配项修定位或新增写法。然后重新核对并完成适用的编译检查。通过隔离副本的实机验收后,再提交 `patches/versions/<版本>.jsonc`。`written_for` 表示写法的编写版本,启动器通过版本核对记录判断「已核对」。[检查命令](contributing.md#checks) · [记录生成脚本](../scripts/record-game-version.ts) · [PR 模板](templates/pull-request.md) [简体中文](#zh-cn) · English · [Dev Docs](README.md#english) ## Start with one behavior Check the stock behavior in the target build. Use English comments to explain the change, why the local service or stock configuration is insufficient, and what players would observe without the change. Use one directory per behavior. Reuse the project's English `features` tags so the launcher can report affected functionality. Copy the matching template and enter the target version, path, and original content. The template inputs are fictional. Keep rationale and evidence in comments or the PR because the loaders reject unknown fields. | Change | Location | Template and example | | --- | --- | --- | | Exe byte edit | `patches/exe///patch.jsonc` | [Template](templates/exe/patch.jsonc) · [User data folder name](../patches/exe/isolation/user-data-folder-name/patch.jsonc) | | UI script edit | `patches/gui///patch.jsonc` and its fragments | [Template folder](templates/gui) · [Save the tutorial opt-out](../patches/gui/tutorials/immediate-save-skip-tutorial/patch.jsonc) | | LocalMP native module site | `patches/native/.jsonc` for `native/wto-net/src/.c` | [Template](templates/native/local_mp_example.jsonc) · [Score module](../patches/native/local_mp_scores.jsonc) | ### Exe patches - Use `/` for `id`, describe the effect in `title`, list the feature tags in `features`, and put required exe patch IDs in `requires`. - Give each variant a `written_for`, `locate`, and `edit`. Use `signature` so the build and the Python `check-patches` command can both locate the site. The pattern must match once. Use `??` for bytes that vary between builds. Set `edit.offset` to the distance from the match to the edit. - Set `edit.expect_original` to the bytes expected at that edit and use the same length as `bytes`. Include `asm` for code or an encoding and text in `data` for a text edit. The check tool compares this source with the stored bytes. Use `captures` for values read from the located site and `fixups` for holes in `bytes`. Comment the build, range, wildcards, and captured values for each variant. ### GUI patches - Set `id`, `title`, `features`, and `variants`. Each variant names its `written_for` build, the internal script path in `file`, and its `edits`. An edit names the `find` and `replace` files in the patch directory. - Copy the smallest unique piece of stock text into the find fragment, including indentation and blank lines. One final newline in each fragment is removed. CRLF and LF match equivalently. Use separate fragment filenames when variants need different text. Use `{{LOCAL_ENDPOINT}}` in replacement text that needs the host and port from the build. - To change how a tutorial option is saved, for example, trace the original callback and save path, then record the change as find and replace fragments. Run the full `check-gui` against that build's stock archive. Describe how to set the option, leave and return, and observe the expected result. [Tutorial patch example](../patches/gui/tutorials/immediate-save-skip-tutorial) ### Native modules - Match `module` to the JSONC filename. Put required module names in `requires`. Use unique lowercase snake_case names for `sites` across the patch set. Each site variant has `written_for` and `locate`. All variants of a site provide the same capture names. - Use `signature`, `string_ref` for a reference to a known string, or `within` to search the function containing an already resolved site. The build resolves sites and captured values into `wto_ws.cfg`. Resolve version-dependent addresses and structure offsets at build time. A missing or ambiguous site makes its module and dependent modules unavailable. ## Check versions and submit The patch engine requires a single variant to pass location and original-content checks. The build reports unavailable changes and their affected features. Missing essential patches stop the build. [Essential features](../packages/patcher/src/essential-features.ts) To adapt a new build, generate a local version record from read-only stock files and inspect `unavailable`. Adjust the sites or add variants for the failing changes. Rerun the checks and the applicable compilation steps. Commit `patches/versions/.jsonc` after in-game acceptance in an isolated copy. `written_for` identifies the build a variant was authored against. The launcher uses the version record to report a build as checked. [Check commands](contributing.md#checks) · [Record generator](../scripts/record-game-version.ts) · [PR template](templates/pull-request.md)