"""Q3: walk the whole enum-table block around 0x180229a00..0x180229e00.

Q2 found row @0x180229b50 = {'badge', 0xa}, 0x180229b60 = {'kit', 0xb},
0x180229b70 = {'leagueLogo', 0xc}, and 0x180229c10 = {'ball', 0x16} -- i.e. a
{name -> numeric code} table that NAMES THE CLUB FAMILIES. That is exactly the
mapping the brief asks for, IF the codes are cardsubtypeids.

HYPOTHESIS: one of these tables is the cardsubtypeid vocabulary. Codes 0xa/0xb/0xc
are NOT in the cardtype-9 subtype set (0x1e,0x1f,0x91..0x96), so either it is a
different axis (an "item sub-family" enum) or the mapping is indirect.

CONTROL: the itemState table at 0x180229cc0 (invalid/free/WAITING_FOR_GAME/...)
must reappear intact inside the same walk, with the same codes Q2 printed.

Dump every 0x10 row from 0x180229800 to 0x180229f00, printing ptr, string, value.
Then xref every table start candidate (a row whose predecessor is not a valid
string row) to find the lookup function.
"""
import traceback

try:
    LO, HI = 0x180229800, 0x180229F00
    rows = []
    a = LO
    while a < HI:
        try:
            q0, q1 = qword(a), qword(a + 8)
        except Exception:
            a += 0x10
            continue
        s = None
        if 0x180000000 <= q0 < 0x181000000:
            try:
                t = rd_str(q0, 64)
                if t and all(0x20 <= ord(c) < 0x7F for c in t):
                    s = t
            except Exception:
                pass
        rows.append((a, q0, s, q1))
        a += 0x10

    print("=== enum row walk %#x..%#x ===" % (LO, HI))
    prev_ok = False
    starts = []
    for (a, q0, s, q1) in rows:
        mark = ""
        ok = s is not None
        if ok and not prev_ok:
            mark = "  <== TABLE START?"
            starts.append(a)
        prev_ok = ok
        print("  %#x  ptr=%#018x %-28r val=%#-10x%s" % (a, q0, s or "", q1, mark))

    print()
    print("=== xrefs to each candidate table start ===")
    for a in starts:
        print("  start %#x" % a)
        for frm, typ, fn, ent in xrefs_to(a):
            print("     from %#x %s in %s(%#x)" % (frm, typ, fn, ent))
except Exception:
    traceback.print_exc()
