"""Q1 recon: the itemState enum table and the club?type= strings.

HYPOTHESIS: the itemState enum table at 0x180229d20 (stride 0x10, 10 entries) is
referenced by (a) a string->enum mapper in the deserializer and (b) an equip path
that WRITES activeBadge/activeHomeKit/... The equip path is the place most likely
to switch on cardsubtypeid for cardtype 9.

CONTROL: the table dump itself. The doc states the ten names; if the dump does not
reproduce WAITING_FOR_GAME, inGame, forSale, offered, activeBadge, activeHomeKit,
activeAwayKit, activeBall, activeStadium, active in that order, my table read is
wrong and every conclusion downstream is void.

Also: locate the literals for club?type= singular names (stadium/ball/equippables)
and the family caption keys, with occurrence counts, so later queries can pick a
unique anchor.
"""
import traceback

try:
    print("=== A: itemState enum table 0x180229d20, stride 0x10, 14 entries ===")
    T = 0x180229D20
    for i in range(14):
        e = T + i * 0x10
        q0 = qword(e)
        q1 = qword(e + 8)
        s = ""
        if 0x180000000 <= q0 < 0x181000000:
            try:
                s = rd_str(q0, 64)
            except Exception:
                s = "?"
        print("  [%2d] %#x: q0=%#018x %-24r q1=%#x" % (i, e, q0, s, q1))

    print()
    print("=== B: xrefs to the table start and to each row ===")
    for i in range(12):
        e = T + i * 0x10
        xs = xrefs_to(e)
        if xs:
            print("  row %d @%#x:" % (i, e))
            for frm, typ, fn, ent in xs:
                print("     from %#x %s in %s(%#x)" % (frm, typ, fn, ent))

    print()
    print("=== C: string literals of interest, all occurrences ===")
    pats = [
        b"activeBadge", b"activeHomeKit", b"activeAwayKit", b"activeBall",
        b"activeStadium", b"itemState", b"forSale", b"inGame",
        b"equippables", b"stadium", b"Stadium", b"ball", b"Ball",
        b"badge", b"Badge", b"kit", b"Kit", b"clubLogo", b"leagueLogo",
        b"CLUBLOGO", b"LEAGUELOGO", b"BADGE", b"STADIUM", b"BALL", b"KIT",
    ]
    for p in pats:
        hits = find_all(p)
        print("  %-16r  n=%d  %s" % (p.decode(), len(hits),
                                     " ".join("%#x" % h for h in hits[:12])))
except Exception:
    traceback.print_exc()
