"""Q4: the enum converter helpers and their callers.

Q3 established two request-side vocabularies:
  table 0x180229ab0 "subtype filter": any=-1 playerGK=1..physio=9 badge=0xa kit=0xb
      leagueLogo=0xc playerTraining=0xd GKTraining=0xe position=0xf playStyle=0x10
      managerLeagueModifier=0x11 contract=0x12 fitness=0x13 healing=0x14
      stadium=0x15 ball=0x16
  table 0x180229c30 "type filter": any=-1 player=1 staff=2 clubInfo=3 training=4
      development=5 stadium=6 ball=7
  table 0x180229cc0 "itemState": invalid=0 free=1 WAITING_FOR_GAME=2 inGame=2
      forSale=5 offered=6 activeBadge=0x64 .. activeStadium=0x68 active=0xff

HYPOTHESIS: the converter functions FUN_180166300 (subtype), FUN_180166340 (type),
FUN_180166660 (itemState) are string<->code helpers; their CALLERS are the request
builder and the equip path. The equip path must choose 0x64..0x68 from the item, and
that choice is the subtype->family mapping we want.

CONTROL: FUN_1800d8330, decompiled in full here, must reproduce the documented
cardtype-9 subtype set {0x1e,0x1f,0x91..0x96,0xe7..0xe9,0xec}. If it does not, my
project copy is not the analysed one.
"""
import traceback

try:
    for a, tag in [(0x1800D8330, "CONTROL FUN_1800d8330 cardsubtype->cardtype"),
                   (0x180166300, "subtype-enum helper"),
                   (0x180166340, "type-enum helper"),
                   (0x180166660, "itemState helper A"),
                   (0x1801666F0, "itemState/other helper B"),
                   (0x180166790, "helper C")]:
        src = dec(a)
        print("=" * 78)
        print("%s  @%#x   len=%d" % (tag, a, len(src)))
        print(src)
    print("=" * 78)
    print("=== callers ===")
    for a in (0x180166300, 0x180166340, 0x180166660, 0x1801666F0, 0x180166790):
        print("  callers of %#x:" % a)
        seen = set()
        for frm, typ, fn, ent in xrefs_to(a):
            if ent in seen:
                continue
            seen.add(ent)
            print("     %s(%#x) via %#x %s" % (fn, ent, frm, typ))
except Exception:
    traceback.print_exc()
