#!/usr/bin/env python3 """ bsl_pair.py -- decode the wire BSL slice-selector encoding by pairing: wire side: mode-0 texmap pages + the texture nodes' selector words file side: which .BSL file each page is (byte compare) + the bitslice values (b2z tag 0x018) of every texture entry that references that .BSL in the scene's .BGF/.BMF models. python bsl_pair.py sdemo2.raw.bin c:\\temp\\flykc\\HPDAVE\\VIDEO """ import os, sys, struct, glob sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'parser')) from vrboard import VirtualBoard, Assembler from decode_anim import find_framed_start import b2z cap = sys.argv[1] if len(sys.argv) > 1 else 'sdemo2.raw.bin' vid = sys.argv[2] if len(sys.argv) > 2 else r'c:\temp\flykc\HPDAVE\VIDEO' data = open(cap, 'rb').read() board = VirtualBoard(); asm = Assembler(); asm.feed(data[find_framed_start(data):]) for m in asm: try: board.handle(m) except Exception: pass if board.frames >= 50: break types = {h: nd.get('type') for h, nd in board.nodes.items()} # wire: selectors per texmap sel_by_texmap = {} for h, nd in board.nodes.items(): if types.get(h) != 0xc: continue b = nd.get('body') or b'' if len(b) < 56: continue texm = struct.unpack_from(' file {match}") print(f" wire selectors: {sorted(set(s for _, s in sels))} " f"({[hex(s) for _, s in sorted(sels)]})") if match: keys = [k for k in filetex if match.split('.')[0] in k] for k in keys: for name, bs, src in sorted(set(filetex[k])): print(f" file: {name:24} bitslice={bs:3} (in {src}, map {k})")