Let each patch carry variants written for different game builds

A game update used to fail a patch whenever any byte it compared moved, even
when only an address in the instruction changed. Patch definitions now say
what a change needs and read the rest from the code:

- patch.jsonc holds a list of variants, each written for one game build
  (written_for) with its own locate block and edit; locate.jsonc is merged
  into it. Exactly one variant must apply, otherwise the patch is left out.
  GUI script patches use the same variants rule.
- expect_original and the bytes to write use the signature syntax, so
  addresses that differ between builds can be wildcards.
- A locate block can capture values at the site (rel32 targets, immediates,
  displacements); a rel32 fixup fills a hole in the written bytes from a
  capture. allow-local-host-bot-spawns now jumps to the target of the
  conditional jump it replaces instead of a stored distance, which makes it
  apply to 2.61.0.43 as well.
- verified_on is gone from the definitions. patches/versions/<version>.jsonc
  records, per checked game build, which variant of every patch applies and
  where; scripts/record-game-version.ts writes it and the launcher reads the
  recorded versions from there.

The Python tools (check-patches, patch-exe, check-gui) read the same format;
check-patches assembles a variant whose assembly names captures at the site
it was located at.

Checked: root and launcher type checks; check-patches and check-gui on
2.61.0.37 and 2.61.0.43 (12 exe and 35 GUI patches each); check-patches and
check-gui report a deliberately broken patch with a non-zero exit;
build-game-copy from 2.61.0.43 into a temporary folder. The computed bytes of
allow-local-host-bot-spawns on 2.61.0.37 equal the bytes it stored before.
This commit is contained in:
N0VAN0M4LY committed 2026-11-29 11:47:08 +08:00
1 parent 3f366651bd
commit b819912733
94 files changed
+1884 -933

No files matched your search

+6 -6
View File
@@ -113,10 +113,10 @@ AI 的驾驶、寻路和战术使用游戏自带的 AI,目前仍有明显不
每个补丁是一个目录,以 JSONC 描述,文件内的注释说明修改原因和不修改时的后果。
- **exe 补丁**:`locate.jsonc` 给出特征码和所在节,`patch.jsonc` 给出写入的字节和预期的原始字节(`expect_original`)。特征码未命中或原始字节不符时,不写入该补丁。
- **界面脚本补丁**:`patch.jsonc` 指定目标脚本,`find.nut` 和 `replace.nut` 是替换前后的原文。原文必须在目标文件中唯一命中,否则构建失败。
- **exe 补丁**:`patch.jsonc` 的 `variants` 列出一种或多种写法,每种写法针对一个客户端版本(`written_for`)。`locate` 给出特征码、所在节,以及要从代码中读出的值(`captures`,例如跳转目标);`edit` 给出写入的字节和预期的原始字节(`expect_original`)。两者都可以用 `??`,写入字节中的 `??` 由 `fixups` 按读出的值填写。恰好一种写法命中时才写入,否则不写入该补丁。
- **界面脚本补丁**:每种写法指定目标脚本和替换片段(如 `find.nut`、`replace.nut`)。片段原文必须在目标文件中唯一命中,同样恰好一种写法命中时才写入。
每个补丁在 `features` 中列出依赖它的功能,在 `verified_on` 中列出验证过的客户端版本。补丁不可用时,安装器列出受影响的功能。涉及离线启动、正版隔离或断开 Gaijin 连接的补丁不可用时,安装会被阻止(`packages/patcher/src/essential-features.ts`)。
每个补丁在 `features` 中列出依赖它的功能。`patches/versions/<版本>.jsonc` 是每个已适配客户端版本的核对记录(由 `scripts/record-game-version.ts` 生成),记下每个补丁命中的写法和位置。补丁不可用时,安装器列出受影响的功能。涉及离线启动、正版隔离或断开 Gaijin 连接的补丁不可用时,安装会被阻止(`packages/patcher/src/essential-features.ts`)。
## 数据目录
@@ -370,10 +370,10 @@ The offline copy and the online game can be installed on the same computer. The
Each patch is a folder described in JSONC. Comments in the files explain why the change is needed and what happens without it.
- **exe patches**: `locate.jsonc` gives the signature and the section to search, and `patch.jsonc` gives the bytes to write and the expected original bytes (`expect_original`). If the signature does not match or the original bytes differ, the patch is not written.
- **UI script patches**: `patch.jsonc` names the target script, and `find.nut` and `replace.nut` hold the text before and after the change. The text must match exactly once in the target file, or the build fails.
- **exe patches**: `variants` in `patch.jsonc` lists one or more ways to make the change, each written for one client version (`written_for`). `locate` gives the signature, the section to search and the values to read from the code (`captures`, such as a jump target); `edit` gives the bytes to write and the expected original bytes (`expect_original`). Both may contain `??`; in the bytes to write, `fixups` fill them from the captured values. A patch is written only when exactly one variant matches.
- **UI script patches**: each variant names the target script and its fragments (such as `find.nut` and `replace.nut`). The text to find must match exactly once in the target file; here too a patch is written only when exactly one variant matches.
Every patch lists the features that depend on it in `features` and the client versions it was verified on in `verified_on`. When a patch is unavailable, the installer lists the affected features. If a patch needed for offline startup, isolation from the online game, or blocking Gaijin connections is unavailable, installation stops (`packages/patcher/src/essential-features.ts`).
Every patch lists the features that depend on it in `features`. `patches/versions/<version>.jsonc` is the check record of each adapted client version (written by `scripts/record-game-version.ts`): which variant of every patch applies and where. When a patch is unavailable, the installer lists the affected features. If a patch needed for offline startup, isolation from the online game, or blocking Gaijin connections is unavailable, installation stops (`packages/patcher/src/essential-features.ts`).
## Data folder