"""DIMENSION 5 -- query 7. Nail the verdicts.

A) OBJECTIVES gate: cVar9 = model slot 0x320 = accessor FUN_18011c570 = disp 0x1fd44,
   used to pick GOTO_MANAGER_QUEST vs GOTO_MANAGER_QUEST_DISABLED. Confirm the ONLY
   consumers of that accessor (and of the draft accessors 0x2c8/0x2d0) so we can say
   which gate byte drives which tile. CONTROL: trading accessor 0x270 (disp 0x1fd2e)
   should be consumed by the TO_TRADE_PILE predicate, not the hub builder.

B) settings arm for enableObjectives (atom 0xfd=253) in the applier chain: is it
   CLEAR-only? Decompile the settings deser 0x18013c6d0 and grep its arms near 0xfd/0xfe.

C) SBC: is there ANY CardsDLL reader of the SBC-config gate bytes as a MENU gate?
   accessor stubs for disp 0x1fd2c/0x1fd28/0x1fd42 (SBC settings) -> their callers.
"""
import traceback
try:
    def callers_of(a, tag):
        print("\n=== callers of %#x (%s) ===" % (a, tag))
        cs = callers(a)
        if not cs:
            print("   (none via getCallingFunctions)")
        for ent, nm in cs:
            print("   %#x %s" % (ent, nm))

    callers_of(0x18011c570, "objectives accessor disp 0x1fd44 / slot 0x320")
    callers_of(0x18011c4b0, "draft accessor disp 0x1fd3d / slot 0x2c8")
    callers_of(0x18011c580, "offline-draft accessor disp 0x1fd3e / slot 0x2d0")
    callers_of(0x18011c670, "trading accessor disp 0x1fd2e / slot 0x270 (CONTROL)")

    # find accessor stubs for SBC settings disps by scanning .text for 0f b6 81 <disp>
    print("\n=== find accessor stubs for SBC-config disps 0x1fd2c/0x1fd28/0x1fd42 ===")
    for disp in (0x1fd2c, 0x1fd28, 0x1fd42):
        pat = bytes.fromhex("0fb681") + disp.to_bytes(4, "little")
        for h in find_all(pat, blocks=(".text",)):
            f = func(h)
            ent = int(f.getEntryPoint().getOffset()) if f else 0
            print("   disp %#x stub @%#x in %#x" % (disp, h, ent))
            if ent:
                for cent, cnm in callers(ent):
                    print("      <- %#x %s" % (cent, cnm))

    print("\n=== settings deser 0x18013c6d0 : arms near enableObjectives 0xfd/0xfe ===")
    d = dec(0x18013c6d0)
    print("LEN", len(d))
    import re
    lines = d.splitlines()
    for i, ln in enumerate(lines):
        if re.search(r"0xfd\b|0xfe\b|== 0xfd|253|254|0x70\)|\+ 0x70|field.*0x1c", ln):
            lo=max(0,i-3); hi=min(len(lines),i+5)
            print("  --- @%d ---" % i)
            for j in range(lo,hi):
                print("    "+lines[j].strip()[:140])
except Exception:
    traceback.print_exc()
