Files
WT-Offline/tools/src/wtotools/cli/exe_commands.py
T
N0VAN0M4LY fdac56a036 refactor(native)!: load LocalMP values from the build configuration
wto_ws.dll no longer scans aces.exe or carries structure offsets of a game
build. It reads the values the patcher resolved (wto_ws.cfg native.* lines)
into g_lmp through one table that names, per module, which value fills which
field (local_mp_values.c), and installs each module whose values are all
present, in dependency order, instead of giving up on the whole bridge when
one subsystem is missing. When the settings were resolved for another
executable (PE time stamp and image size differ), the bridge stays off.

local_mp_offsets.h keeps the existing names so the module code reads as
before; only Dagor library layouts (dag::Vector, DataBlock), protocol enums,
the reflection buffer size and the two change request members with no reader
in the client remain constants. A few fields are derived where the client has
no instruction of its own for them (local_mp_values.c derive_values). The
signatures moved to patches/native, and the header-based check-offsets
command is gone: record-game-version and the launcher's patch check resolve
the native modules now.

Shared sites moved to local_mp_core (mission customBots, the player's unit
eid) so modules do not depend on each other for them.

Checked: DLL build (no warnings outside MinHook); root and launcher type
checks; check-patches on 2.61.0.37; version records for 2.61.0.37 and
2.61.0.43 (10 native modules each); a lab run of the 2.61.0.37 copy logs
239 native values and "9 of 9 LocalMP modules installed". Battles were not
played in this run.

BREAKING CHANGE: Rebuild game copies to generate the new native values in wto_ws.cfg. Use record-game-version.ts or the launcher patch check in place of wtotools check-offsets.
2026-11-29 12:26:11 +08:00

93 lines
3.8 KiB
Python

"""Commands that work on the game executable.
wtotools check-patches --exe <aces.exe> [--patches patches/exe]
wtotools patch-exe --exe <aces.exe> --out <aces.exe> [--patches patches/exe] [--force]
The input executable is only ever read. `patch-exe` refuses to write over its input and
refuses an existing output unless --force is given, so it cannot modify a game install by
accident.
"""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
from ..exepatch import apply_writes, changed_ranges, load_patches, plan_patches
from ..exepatch.assemble import disagreement, needs_site
from ..pe import PeImage
DEFAULT_PATCHES = Path("patches/exe")
def register(commands: argparse._SubParsersAction) -> None:
check = commands.add_parser("check-patches", help="locate and verify every patch, write nothing")
_add_common(check)
check.set_defaults(handler=_check_patches)
patch = commands.add_parser("patch-exe", help="apply every patch to a copy of the executable")
_add_common(patch)
patch.add_argument("--out", type=Path, required=True, help="where to write the patched copy")
patch.add_argument("--force", action="store_true", help="overwrite an existing output file")
patch.set_defaults(handler=_patch_exe)
def _add_common(parser: argparse.ArgumentParser) -> None:
parser.add_argument("--exe", type=Path, required=True, help="the game executable to read")
parser.add_argument("--patches", type=Path, default=DEFAULT_PATCHES, help="patch definition directory")
def _check_patches(args: argparse.Namespace) -> int:
definitions = load_patches(args.patches)
print(f"{len(definitions)} patch definition(s) in {args.patches}")
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 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 _patch_exe(args: argparse.Namespace) -> int:
if args.out.resolve() == args.exe.resolve():
print("refusing to write over the input executable; choose a different --out", file=sys.stderr)
return 2
if args.out.exists() and not args.force:
print(f"{args.out} already exists; pass --force to overwrite", file=sys.stderr)
return 2
original = args.exe.read_bytes()
plan = plan_patches(PeImage(original), load_patches(args.patches))
print(plan.describe())
if not plan.complete:
print("some patches are unavailable; nothing was written", file=sys.stderr)
return 1
patched = apply_writes(original, plan.writes)
for start, end in changed_ranges(original, patched):
print(f" changed {end - start} byte(s) at file offset {start:#x}: "
f"{original[start:end].hex()} -> {patched[start:end].hex()}")
args.out.parent.mkdir(parents=True, exist_ok=True)
args.out.write_bytes(patched)
print(f"wrote {args.out}")
return 0