"""DIMENSION 5 pass 3: the unopenedPacks consumer, and the tokenizer's EOF behaviour.

Resolved LIVE (read-only probe, pid 134663): model singleton = *DAT_1802e6398,
its vtable = static 0x18021c2a0, and
    slot 0x4e0 -> 0x18011e120   <- the unopenedPacks(0x35e) consumer
    slot 0x480 -> 0x18011baf0   <- CONTROL, the squadList(0x2d4) consumer, which is
                                   live-confirmed working (MY SQUADS renders)
Both land inside CardsDLL, so both are analysable. If 0x18011baf0 does not look like
a squad-roster accessor, the vtable resolution is wrong and 0x4e0 means nothing.

HYPOTHESES
  H1 0x18011e120 stores the pack count into a model field; xrefs to that field give
     the UI consumer.
  H2 the tokenizer 0x1801c7f10 returns a specific token at end of input; that value
     decides whether a trailing re-dispatch terminates or spins (the 0x1801c7f1a
     freeze).
"""
import traceback, os

OUT = "/tmp/claude-1000/-home-alex-Documents-OpenFUT/8e521ca1-ca3e-4138-bb96-df1744dd1d30/scratchpad/store"

try:
    for name, a in [
        ("consumer_18011e120", 0x18011e120),
        ("control_18011baf0",  0x18011baf0),
        ("nexttok_1801c7f10",  0x1801c7f10),
    ]:
        src = dec(a, 300)
        open(os.path.join(OUT, "dec_%s.c" % name), "w").write(src)
        print("\n#### %s @ %#x  len=%d\n%s" % (name, a, len(src), src if len(src) < 6000 else "(see file)"))

    print("\n---- asm of 0x18011e120 ----")
    f = func(0x18011e120)
    it = listing.getInstructions(f.getBody(), True)
    while it.hasNext():
        ins = it.next()
        print("  %#x  %s" % (int(ins.getAddress().getOffset()), str(ins)))

    print("\n---- vtable static 0x18021c2a0 slots 0x470..0x500 ----")
    for s in range(0x470, 0x508, 8):
        t = qword(0x18021c2a0 + s)
        fn = fm.getFunctionAt(addr(t)) if 0x180000000 <= t < 0x181000000 else None
        print("  +%#05x -> %#x %s" % (s, t, fn.getName() if fn else ""))
except Exception:
    traceback.print_exc()
