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.
This commit is contained in:
1 parent
dde852e2b1
commit
fdac56a036
23 files changed
+721
-805
No files matched your search
@@ -1,7 +1,6 @@
|
||||
"""Commands that work on the game executable.
|
||||
|
||||
wtotools check-patches --exe <aces.exe> [--patches patches/exe]
|
||||
wtotools check-offsets --exe <aces.exe> [--header native/wto-net/src/local_mp_offsets.h]
|
||||
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
|
||||
@@ -16,11 +15,9 @@ from pathlib import Path
|
||||
|
||||
from ..exepatch import apply_writes, changed_ranges, load_patches, plan_patches
|
||||
from ..exepatch.assemble import disagreement, needs_site
|
||||
from ..offset_check import parse_offset_header, verify_offsets
|
||||
from ..pe import PeImage
|
||||
|
||||
DEFAULT_PATCHES = Path("patches/exe")
|
||||
DEFAULT_OFFSET_HEADER = Path("native/wto-net/src/local_mp_offsets.h")
|
||||
|
||||
|
||||
def register(commands: argparse._SubParsersAction) -> None:
|
||||
@@ -28,11 +25,6 @@ def register(commands: argparse._SubParsersAction) -> None:
|
||||
_add_common(check)
|
||||
check.set_defaults(handler=_check_patches)
|
||||
|
||||
offsets = commands.add_parser("check-offsets", help="verify native LocalMP signatures and anchor strings")
|
||||
offsets.add_argument("--exe", type=Path, required=True, help="the game executable to read")
|
||||
offsets.add_argument("--header", type=Path, default=DEFAULT_OFFSET_HEADER, help="C header with LMP_SIG_* and @anchor tags")
|
||||
offsets.set_defaults(handler=_check_offsets)
|
||||
|
||||
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")
|
||||
@@ -75,14 +67,6 @@ def _source_problems(definitions, plan) -> list[str]:
|
||||
return problems
|
||||
|
||||
|
||||
def _check_offsets(args: argparse.Namespace) -> int:
|
||||
spec = parse_offset_header(args.header)
|
||||
ok, lines = verify_offsets(PeImage(args.exe.read_bytes()), spec)
|
||||
for line in lines:
|
||||
print(line)
|
||||
return 0 if ok else 1
|
||||
|
||||
|
||||
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)
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
"""Verify native LocalMP signatures, RIP opcodes, and English anchor strings against aces.exe.
|
||||
|
||||
Parses `native/wto-net/src/local_mp_offsets.h` directly as the single source of truth so
|
||||
C hook code and binary calibration checks can never drift apart across game updates.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from .pe import PeImage
|
||||
|
||||
_SIG_RE = re.compile(r'^#define\s+(LMP_SIG_\w+)\s+"([0-9a-fA-F? ]+)"', re.MULTILINE)
|
||||
_RIP_RE = re.compile(r"@rip_check\s+(LMP_SIG_\w+)\s*\+\s*0x([0-9a-fA-F]+)\s*:\s*([0-9a-fA-F ]+)")
|
||||
_ANCHOR_RE = re.compile(r'^\s*\*\s*@anchor\s+"([^"]+)"', re.MULTILINE)
|
||||
_LEA_RE = re.compile(rb"[\x48\x4c]\x8d[\x05\x0d\x15\x1d\x25\x2d\x35\x3d](....)", re.DOTALL)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RipCheckSpec:
|
||||
sig_name: str
|
||||
offset: int
|
||||
expected_prefix: bytes
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class OffsetHeaderSpec:
|
||||
signatures: list[tuple[str, str]]
|
||||
rip_checks: list[RipCheckSpec]
|
||||
anchors: list[str]
|
||||
|
||||
|
||||
def parse_offset_header(header_path: Path) -> OffsetHeaderSpec:
|
||||
source = header_path.read_text(encoding="utf-8")
|
||||
signatures = _SIG_RE.findall(source)
|
||||
rip_checks = [
|
||||
RipCheckSpec(name, int(off_hex, 16), bytes.fromhex(prefix_hex))
|
||||
for name, off_hex, prefix_hex in _RIP_RE.findall(source)
|
||||
]
|
||||
anchors = list(dict.fromkeys(_ANCHOR_RE.findall(source)))
|
||||
return OffsetHeaderSpec(signatures=signatures, rip_checks=rip_checks, anchors=anchors)
|
||||
|
||||
|
||||
def _compile_signature(spec: str) -> re.Pattern[bytes]:
|
||||
parts: list[bytes] = []
|
||||
for token in spec.split():
|
||||
if token == "??":
|
||||
parts.append(b".")
|
||||
else:
|
||||
parts.append(re.escape(bytes([int(token, 16)])))
|
||||
return re.compile(b"".join(parts), re.DOTALL)
|
||||
|
||||
|
||||
def _index_rip_lea_targets(text_rva: int, text_bytes: bytes) -> dict[int, list[int]]:
|
||||
targets: dict[int, list[int]] = {}
|
||||
for match in _LEA_RE.finditer(text_bytes):
|
||||
insn_rva = text_rva + match.start()
|
||||
disp = int.from_bytes(match.group(1), "little", signed=True)
|
||||
target_rva = insn_rva + 7 + disp
|
||||
bucket = targets.get(target_rva)
|
||||
if bucket is None:
|
||||
targets[target_rva] = [insn_rva]
|
||||
elif len(bucket) < 4:
|
||||
bucket.append(insn_rva)
|
||||
return targets
|
||||
|
||||
|
||||
def _find_cstring_rvas(pe: PeImage, text: str) -> list[int]:
|
||||
needle = text.encode("ascii") + b"\x00"
|
||||
rvas: list[int] = []
|
||||
for sec in pe.sections:
|
||||
if sec.name == ".text" or sec.raw_size == 0:
|
||||
continue
|
||||
raw = pe.data[sec.raw_offset : sec.raw_offset + min(sec.virtual_size, sec.raw_size)]
|
||||
pos = 0
|
||||
while True:
|
||||
idx = raw.find(needle, pos)
|
||||
if idx < 0:
|
||||
break
|
||||
rvas.append(sec.rva + idx)
|
||||
pos = idx + len(needle)
|
||||
return rvas
|
||||
|
||||
|
||||
def verify_offsets(pe: PeImage, spec: OffsetHeaderSpec) -> tuple[bool, list[str]]:
|
||||
lines: list[str] = []
|
||||
failures = 0
|
||||
text_sec = pe.section(".text")
|
||||
text_bytes = pe.section_bytes(".text")
|
||||
resolved_sigs: dict[str, int] = {}
|
||||
|
||||
lines.append(f"Checking {len(spec.signatures)} .text signature(s):")
|
||||
for name, pattern in spec.signatures:
|
||||
hits = [text_sec.rva + m.start() for m in _compile_signature(pattern).finditer(text_bytes)]
|
||||
if len(hits) == 1:
|
||||
resolved_sigs[name] = hits[0]
|
||||
lines.append(f" [OK] {name:<34} -> {hits[0]:#09x}")
|
||||
else:
|
||||
failures += 1
|
||||
lines.append(f" [FAIL] {name:<34} -> {len(hits)} match(es)")
|
||||
|
||||
lines.append(f"Checking {len(spec.rip_checks)} RIP displacement anchor(s):")
|
||||
for chk in spec.rip_checks:
|
||||
base_rva = resolved_sigs.get(chk.sig_name)
|
||||
if base_rva is None:
|
||||
failures += 1
|
||||
lines.append(f" [FAIL] {chk.sig_name} + {chk.offset:#x}: base signature unresolved")
|
||||
continue
|
||||
actual = pe.read(base_rva + chk.offset, len(chk.expected_prefix))
|
||||
if actual == chk.expected_prefix:
|
||||
lines.append(f" [OK] {chk.sig_name} + {chk.offset:#x} == {actual.hex(' ')}")
|
||||
else:
|
||||
failures += 1
|
||||
lines.append(
|
||||
f" [FAIL] {chk.sig_name} + {chk.offset:#x}: expected {chk.expected_prefix.hex(' ')}, got {actual.hex(' ')}"
|
||||
)
|
||||
|
||||
lea_targets = _index_rip_lea_targets(text_sec.rva, text_bytes)
|
||||
lines.append(f"Checking {len(spec.anchors)} English anchor string(s):")
|
||||
for anchor in spec.anchors:
|
||||
str_rvas = _find_cstring_rvas(pe, anchor)
|
||||
xrefs = [xr for sr in str_rvas for xr in lea_targets.get(sr, ())]
|
||||
if str_rvas and xrefs:
|
||||
fn_range = pe.function_containing(xrefs[0])
|
||||
fn_str = f"{fn_range[0]:#x}" if fn_range else f"{xrefs[0]:#x}"
|
||||
lines.append(f" [OK] {anchor!r:<58} -> str {str_rvas[0]:#x}, fn {fn_str}")
|
||||
elif str_rvas:
|
||||
lines.append(f" [OK] {anchor!r:<58} -> str {str_rvas[0]:#x} (table/data ref)")
|
||||
else:
|
||||
failures += 1
|
||||
lines.append(f" [FAIL] {anchor!r}: string not found in image")
|
||||
|
||||
return failures == 0, lines
|
||||
Reference in new issue
Block a user