feat(patches)!: support game-version variants in patch definitions

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.

BREAKING CHANGE: Each patch needs a variants list. Move executable locators into patch.jsonc and regenerate game version records with record-game-version.ts.
This commit is contained in:
N0VAN0M4LY committed 2026-11-29 11:47:08 +08:00
1 parent 32e513c6db
commit 927201a462
94 files changed
+1884 -933

No files matched your search

+13 -12
View File
@@ -15,7 +15,8 @@ import tempfile
from dataclasses import dataclass
from pathlib import Path
from .guipatch import apply, load_gui_patches
from .exepatch.errors import PatchError
from .guipatch import GuiVariant, load_gui_patches, select
from .vromfs import Archive, read_archive
MOUNT_PREFIXES: tuple[tuple[str, str], ...] = (
@@ -120,19 +121,18 @@ def verify_gui_patches(
touched_files: list[str] = []
errors: list[str] = []
chosen: dict[str, GuiVariant] = {}
for patch in patches:
target = patch.file.lower()
if target not in archive.files:
errors.append(f"{patch.identifier}: missing file {target} in gui.vromfs.bin")
continue
if any("`" in edit.replace for edit in patch.edits):
errors.append(f"{patch.identifier}: backtick string syntax is unsupported by 2.61.0.37 Quirrel VM; use $\"...\" or +")
continue
try:
updated = apply(archive.files[target].decode("utf-8"), patch, endpoint)
except ValueError as error:
variant, updated = select(archive.files, patch, endpoint)
except PatchError as error:
errors.append(str(error))
continue
if any("`" in edit.replace for edit in variant.edits):
errors.append(f"{patch.identifier}: backtick string syntax is unsupported by the game's Quirrel VM; use $\"...\" or +")
continue
target = variant.file.lower()
chosen[patch.identifier] = variant
archive.put(target, updated.encode("utf-8"))
if target not in touched_files:
touched_files.append(target)
@@ -145,12 +145,13 @@ def verify_gui_patches(
stock_archive = read_archive(gui_pack_path.read_bytes())
for patch in patches:
target = patch.file.lower()
variant = chosen[patch.identifier]
target = variant.file.lower()
stock_src = stock_archive.files[target].decode("utf-8")
imp_names, imp_classes = _resolve_file_bindings(stock_src, stock_archive, export_cache, native_syms)
reserved = (imp_names | imp_classes) - set(MODULE_BUILTINS)
new_locals: set[str] = set()
for edit in patch.edits:
for edit in variant.edits:
new_locals |= _declared_locals(edit.replace) - _declared_locals(edit.find)
collisions = sorted(new_locals & reserved)
if collisions: