"""DIMENSION 4, pass 15 (last): what does the script command GetCardDuplicate
actually return -- the duplicate ITEM ID, or just a flag?

The handler FUN_180039fb0 forwards to DAT_1802def18 vtable slot +0x18.
DAT_1802def18 is installed by FUN_180039b40 / FUN_180039ba0. Decompile those and
whatever they install, so the slot can be resolved.

This matters for the server: if nothing ever reads the VALUE of
duplicateItemId, then only zero vs non-zero is observable, and the server may
put any non-zero id there.
"""
import traceback

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

def w(fh, s=""):
    fh.write(str(s) + "\n")

def dump(fh, a, label):
    s = dec(a)
    w(fh, "")
    w(fh, "#" * 70)
    w(fh, "# %s  %#x  len(src)=%d  FULL" % (label, a, len(s)))
    w(fh, "#" * 70)
    w(fh, s)

try:
    fh = open(OUT, "w")
    dump(fh, 0x180039B40, "installer A")
    dump(fh, 0x180039BA0, "installer B")
    dump(fh, 0x180094AE0, "single-card DP builder 1")
    dump(fh, 0x180096490, "single-card DP builder 2")
    w(fh, "")
    w(fh, "=== callers of the two single-card DP builders ===")
    for a in (0x180094AE0, 0x180096490):
        w(fh, "-- %#x" % a)
        for frm, typ, fn, ent in xrefs_to(a):
            w(fh, "     %#x %s in %s @ %#x" % (frm, typ, fn, ent))
    fh.close()
    print("WROTE", OUT)
except Exception:
    traceback.print_exc()
