#!/usr/bin/env python3 """Strat types (object types) of a level WAD: names from the STPC strat code, MAP instances. Strat code sits at the end of STPC (after models/animsets). Bytecode = u32 words (low16 = opcode, high16 = short operand). A strat (almost always) starts with ... 0xd4, 0xea, -> name = C string at (address after rel) + rel strats.py level.wad [--all] """ import os import struct import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import map_dump # noqa: E402 import stpcwalk # noqa: E402 def cstr(d, o): e = d.index(b'\0', o) return d[o:e].decode('latin1') def strat_name(st, entry, lo): """Name of a MAP entry: spawn stub (b2 e0 ...) -> target; otherwise first d4/ea from entry.""" w = struct.unpack_from('<8I', st, entry) for k in range(5): if w[k] == 0xb2 and w[k + 2] == 0xe0 and lo <= w[k + 1] < len(st): n = strat_name(st, w[k + 1], lo) return n + '(spawn)' if n else None for k in range(0, 1024, 4): o = entry + k if o + 12 > len(st): break a, b = struct.unpack_from('