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

+24 -12
View File
@@ -15,7 +15,7 @@ import sys
from pathlib import Path
from ..exepatch import apply_writes, changed_ranges, load_patches, plan_patches
from ..exepatch.assemble import disagreement
from ..exepatch.assemble import disagreement, needs_site
from ..offset_check import parse_offset_header, verify_offsets
from ..pe import PeImage
@@ -48,19 +48,31 @@ def _add_common(parser: argparse.ArgumentParser) -> None:
def _check_patches(args: argparse.Namespace) -> int:
definitions = load_patches(args.patches)
print(f"{len(definitions)} patch definition(s) in {args.patches}")
mismatched = 0
for definition in definitions:
problem = disagreement(definition)
if problem:
mismatched += 1
print(f" source disagrees with stored bytes: {definition.identifier}: {problem}")
if not mismatched:
print(" every patch's source (assembly or data text) encodes to its stored bytes")
plan = plan_patches(PeImage(args.exe.read_bytes()), definitions)
problems = _source_problems(definitions, plan)
for problem in problems:
print(f" source disagrees with bytes: {problem}")
if not problems:
print(" every variant's source (assembly or data text) encodes to its bytes "
"(variants naming captures: where they apply on this build)")
print(plan.describe())
return 0 if plan.complete and not mismatched else 1
return 0 if plan.complete and not problems else 1
def _source_problems(definitions, plan) -> list[str]:
"""Variants whose assembly or data text does not encode to their bytes."""
planned = {(write.patch_id, write.variant.written_for): write for write in plan.writes}
problems = []
for definition in definitions:
for variant in definition.variants:
write = planned.get((definition.identifier, variant.written_for))
if needs_site(variant) and write is None:
continue
problem = disagreement(variant, write)
if problem:
problems.append(f"{definition.identifier} variant {variant.written_for}: {problem}")
return problems
def _check_offsets(args: argparse.Namespace) -> int: