"""DIMENSION 5 SBC/Objectives -- query 4.

- classify 0x180154990's 3 data xrefs (0x1802fceb8 vtable? 0x180277430 dispatch?
  0x180226fc8 factory/name?). Read the .rdata name near 0x180226fc8 and the qwords
  around each site.
- full 0x180154990: what does FUT/SBC_USE_STUBS==1 actually build? (print full)
- grep the hub tile builder text for SBC/CHALLENGE/SET/GOTO_ destinations + switch arms.
- check for a CompetitionManager-style SBC singleton or count writer.
"""
import traceback
try:
    def ctx_qwords(a, before=4, after=6):
        print("  qwords around %#x:" % a)
        for i in range(-before, after):
            p = a + i*8
            v = qword(p)
            nm = fname(v) if 0x180000000 <= v < 0x181000000 else ""
            s = ""
            if 0x180000000 <= v < 0x181000000:
                st = rd_str(v, 40)
                if st.isprintable() and len(st) > 2:
                    s = repr(st)
            print("    [%#x] = %#x  %s %s" % (p, v, nm, s))

    for site in (0x1802fceb8, 0x180277430, 0x180226fc8):
        print("\n=== xref site %#x ===" % site)
        # what block
        b = None
        for blk in mem.getBlocks():
            if blk.getStart().getOffset() <= site <= blk.getEnd().getOffset():
                b = blk.getName()
        print("  block:", b)
        ctx_qwords(site)

    print("\n=== full FUN_180154990 ===")
    print(dec(0x180154990))
except Exception:
    traceback.print_exc()
