"""D5 final: CreatePack's URL suffix (undefined code at 0x180124ad0), the
FutStoreServiceImpl vtable and its PurchasePack / ValidateCoinPurchase /
ValidatePointsPurchase implementations -- i.e. where the purchase MODE is chosen.

CONTROL: 0x180123430 (StoreGetPackTypes URL builder) is a known-good comparison; it
emits "/purchasegroup" + "?ppInfo=true". Printed alongside.
"""
import traceback, os

OUT = "/tmp/claude-1000/-home-alex-Documents-OpenFUT/8e521ca1-ca3e-4138-bb96-df1744dd1d30/scratchpad/packres"

def w(name, text):
    p = os.path.join(OUT, name)
    with open(p, "w") as f:
        f.write(text)
    print("WROTE %s (%d bytes)" % (p, len(text)))

try:
    buf = []
    def P(*a):
        s = " ".join(str(x) for x in a)
        print(s); buf.append(s)

    P("CONTROL 0x180123430:")
    P(dec(0x180123430))

    P("")
    P("=== raw bytes + disasm at 0x180124ad0 ===")
    b = read_bytes(0x180124ad0, 96)
    P("  bytes: %s" % b.hex())
    a = addr(0x180124ad0)
    for i in range(24):
        ins = listing.getInstructionAt(a)
        if ins is None:
            try:
                flat.disassemble(a)
            except Exception:
                pass
            ins = listing.getInstructionAt(a)
        if ins is None:
            P("  %#x  <no instruction>" % int(a.getOffset()))
            break
        P("  %#x  %s" % (int(a.getOffset()), ins))
        a = ins.getMaxAddress().add(1)

    P("")
    P("=== FutStoreServiceImpl ctor 0x1801998e0 ===")
    P(dec(0x1801998e0))

    w("d5_q6_notes.txt", "\n".join(buf) + "\n")
    print("DONE")
except Exception:
    traceback.print_exc()
