# Q17: FutSquadServiceImpl vtable = 0x180233ff0 (written by ctor FUN_180189be0).
# Dump it and decompile the placement/save slots.
out = open("/tmp/ghidra_fut/squad_svc.txt", "w")
P = lambda *a: print(*a, file=out)

VT = 0x180233FF0
SL = {0x50: "SaveCurrentSquad", 0xb8: "pre-save getter", 0x168: "AddPlayerToSquad",
      0x198: "GetSquadList", 0x1b8: "GetSquads", 0x1c8: "SelectSquadById"}

P("=== FutSquadServiceImpl vtable @ %#x ===" % VT)
n = 0x60
for i in range(n):
    a = VT + i * 8
    try:
        t = qword(a)
    except Exception:
        break
    f = fm.getFunctionContaining(addr(t)) if 0x180001000 <= t <= 0x1801e4fff else None
    if f is None and not (0x180001000 <= t <= 0x1801e4fff):
        P("  +%#05x  %#x   <end of vtable>" % (i * 8, t))
        break
    P("  +%#05x -> %#x %-18s %s" % (i * 8, t, f.getName() if f else "(no fn)",
                                    SL.get(i * 8, "")))

P("\n=== decompiles ===")
for off in (0x50, 0xb8, 0x168, 0x198, 0x1b8, 0x1c8):
    try:
        t = qword(VT + off)
    except Exception:
        continue
    f = fm.getFunctionContaining(addr(t))
    P("\n########## +%#05x  %s -> %#x %s ##########"
      % (off, SL.get(off, ""), t, f.getName() if f else ""))
    P(dec(t))
out.close()
print("wrote squad_svc.txt")
