"""Check the v110 patch contracts without game data; optionally check every site and spin against local ExeFS. python tests/patches_v110_check.py --exefs [--cflags=-march=x86-64-v2] Uses the differential harness, Clang (CC) and Unicorn. Extracted bytes and generated C stay in build/. """ import argparse import math import struct import sys import tempfile import zlib from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / 'tests' / 'diff')) from common import BUF, BUF_SIZE, Emu, build_harness, diff_state, run_harness import patches from lifter import Lifter from layout import layout from module import Module # Set, offset, target register, result kind. The patch file owns the instruction words. SITES = [ ('realtime', 0xa20518, 1, 'zero'), ('cursor', 0xf31e80, 0, 'map'), ('cursor', 0x1d55f24, 12, 'aim'), ('cursor', 0x1d556a4, 3, 'gyro'), *[('aspect', a, 0, 'aspect') for a in (0xcdbf30, 0x1261a64, 0x19c2260, 0x1ed8fa4)], *[('fov', a, 0, 'fov') for a in (0xcdbef8, 0x1261a2c)], ('pooloff', 0x9b93a8, 2, 'offset'), ('pooloff', 0x9b93c4, 1, 'source'), ('shadow', 0xd0760c, 11, 'shadow'), *[('cascade', a, 8, 'cascade') for a in (0x1157fb8, 0x1158040, 0x11580c8, 0x115814c)], ('fixres', 0xce9280, 9, 'fixed'), ] def f32(v): return struct.unpack('x[30]) { ' + ' '.join(i.code for i in replacement) + ' } else { ' + original.code + ' }') words.append((orig, repl)) build = ROOT / 'build' build.mkdir(exist_ok=True) groups = {ratio: ([], []) for ratio in (1.0, 0.9, 0.8, 0.5, 0.25)} page = bytearray(0x1000) # Distinct fields reveal an accidental load from the neighboring page slot. for off, value in ((0, 0.5), (4, 1 / 60), (56, 21 / 9), (60, 1.2), (64, 25), (68, 50), (72, 100), (76, 200)): struct.pack_into('