Reads the live world out of guest RAM and drives the pad from it. Working: loop-rate memory reads, whole-RAM float scanning with numpy (1270 orthonormal 3x3 blocks in 6.2 s), entity enumeration by unit type (116 live instances in Stage 02), pad control written straight into the vgamepad FIFO (the CLI spawns a process per command and its tap/hold sleep inside the server, so neither is usable in a control loop), unattended mission entry, and the Hangar loadout -- the "Recommended" control is AUTO SELECT, which at 5 % progress is a no-op because only two weapons are developed and both are already mounted. Not working, and the reason the craft is not yet flown: the class 0x820af030 is NOT the live entity. It has one object per spawned thing and carries the unit-ID string, which is why it looked like the entity list, but every one of its 384 words is constant across a 29 s in-flight capture. No transform lives in it or one pointer hop from it. Input correlation (hard left yaw vs hard right, looking for a turn axis that reverses) does find self-like objects at cos = -0.99, but they cluster in what looks like a camera volume rather than the craft, and with no definition pointer near them the trick of learning one entity's layout and applying it to the rest has nothing to anchor on -- so the 33418 moving triples in a firefight cannot be split into enemies, friendlies and bullets, and there is nothing to aim at. Two dead ends are recorded so they are not repeated: RT is not the throttle (the two-state speed scan therefore found nothing), and comparing orientation matrices 2 s apart is outside the small-angle regime, which is what produced "angular velocities" of 30000. Also corrects the claim in unit-struct-runtime.md that 0x820af030 holds live state. The definition class 0x820af844 and every value derived from it are unaffected. autopilot2.py (a PD controller using body angular velocity from consecutive rotation matrices) is committed but has never had a valid config to run against, and is marked as untested.
106 lines
3.6 KiB
Python
106 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Type the live entities: link each moving position back to a unit definition.
|
|
|
|
findplayer.py locates positions by motion alone, but a bare (x,y,z) says nothing
|
|
about *what* is moving. Every live entity should reference its parsed `.tbl`
|
|
definition (vtable 0x820af844, one object per unit type, addresses known), so
|
|
scanning the neighbourhood of each position for a word equal to a definition
|
|
address both types the entity and reveals the live object's own layout — the
|
|
delta from that pointer to the position triple is the position offset.
|
|
|
|
Usage: liveents.py [radius_hex]
|
|
"""
|
|
import os
|
|
import struct
|
|
import sys
|
|
from collections import Counter
|
|
|
|
import numpy as np
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import gmem # noqa: E402
|
|
import gworld # noqa: E402
|
|
|
|
|
|
def definitions(w):
|
|
"""{definition_va: unit_id}"""
|
|
out = {}
|
|
for off in w.scan_vtable(gworld.DEF_VTABLE):
|
|
nm = w.name_of(off)
|
|
if nm and nm.startswith("UN_"):
|
|
va = gmem.primary_va(off)
|
|
if va is not None:
|
|
out[va] = nm
|
|
return out
|
|
|
|
|
|
def main():
|
|
radius = int(sys.argv[1], 16) if len(sys.argv) > 1 else 0x600
|
|
w = gworld.World()
|
|
defs = definitions(w)
|
|
print(f"# {len(defs)} unit definitions")
|
|
by_word = {struct.pack(">I", va): nm for va, nm in defs.items()}
|
|
|
|
# sample twice to locate movers, exactly as findplayer.py does
|
|
import time
|
|
fd, size = w.fd, w.size
|
|
|
|
def snap():
|
|
return [(a, np.frombuffer(os.pread(fd, (b - a) // 4 * 4, a), dtype=">f4"))
|
|
for a, b in gmem.extents(fd, size) if (b - a) >= 64]
|
|
|
|
s0 = snap(); t0 = time.time()
|
|
time.sleep(0.4)
|
|
s1 = snap(); t1 = time.time()
|
|
shapes0 = {(o, len(a)) for o, a in s0}
|
|
pairs = [(o, a, b) for (o, a), (o2, b) in zip(s0, s1)
|
|
if o == o2 and len(a) == len(b) and (o, len(a)) in shapes0]
|
|
|
|
movers = []
|
|
for base, a, b in pairs:
|
|
af = np.nan_to_num(a.astype(np.float64), nan=0, posinf=0, neginf=0)
|
|
bf = np.nan_to_num(b.astype(np.float64), nan=0, posinf=0, neginf=0)
|
|
d = bf - af
|
|
m = np.abs(d) > 1e-3
|
|
idx = np.flatnonzero(m)
|
|
cand = idx[np.isin(idx + 1, idx) & np.isin(idx + 2, idx)]
|
|
for i in cand:
|
|
v = np.array([d[i], d[i + 1], d[i + 2]])
|
|
sp = float(np.linalg.norm(v)) / (t1 - t0)
|
|
if 20.0 < sp < 3000.0:
|
|
movers.append((base + int(i) * 4, tuple(float(af[i + j]) for j in range(3)), sp))
|
|
|
|
print(f"# {len(movers)} moving triples; typing them...")
|
|
typed, untyped = [], 0
|
|
seen = set()
|
|
for off, pos, sp in movers:
|
|
lo = max(0, off - radius)
|
|
blob = os.pread(fd, radius * 2, lo)
|
|
hit = None
|
|
for k in range(0, len(blob) - 3, 4):
|
|
nm = by_word.get(blob[k:k + 4])
|
|
if nm:
|
|
hit = (lo + k, nm)
|
|
break
|
|
if hit:
|
|
ptr_off, nm = hit
|
|
key = (ptr_off, nm)
|
|
if key in seen:
|
|
continue
|
|
seen.add(key)
|
|
typed.append((ptr_off, off - ptr_off, nm, pos, sp))
|
|
else:
|
|
untyped += 1
|
|
|
|
print(f"# typed {len(typed)}, untyped {untyped}")
|
|
deltas = Counter(d for _, d, _, _, _ in typed)
|
|
print(f"# most common (def-pointer -> position) deltas: {deltas.most_common(6)}")
|
|
for ptr_off, d, nm, pos, sp in sorted(typed, key=lambda x: x[2])[:40]:
|
|
va = gmem.primary_va(ptr_off)
|
|
print(f" obj~{va:#010x} defptr+{d:#06x} {nm:<40} "
|
|
f"({pos[0]:+10.1f},{pos[1]:+10.1f},{pos[2]:+10.1f}) {sp:7.1f}/s")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|