"""Wwise RIFF (.wem) container for Arkham City (Wwise 2011.1, fmt size 0x42, Vorbis 0xFFFF).""" import re import struct from dataclasses import dataclass, field VORB_FMT = " "Wem": if b[:4] != b"RIFF" or b[8:12] != b"WAVE": raise ValueError("not RIFF/WAVE") riff_end = 8 + struct.unpack_from(" bytes: return self.get(b"data") def setup_packet(self) -> bytes: d = self.data off = self.vorb["seek_table_size"] ln = struct.unpack_from(" len(d): break out.append((pos, d[pos + 2: pos + 2 + ln])) pos += 2 + ln return out, pos # ---- serialization ---- def build_fmt(self) -> bytes: v = self.vorb return (struct.pack(" bytes: self.set(b"fmt ", self.build_fmt()) body = b"WAVE" for c in self.chunks: # the game's WEMs never pad odd-sized chunks (all chunks before 'data' are even) body += struct.pack("<4sI", c.tag, len(c.data)) + c.data return b"RIFF" + struct.pack("= FILL_MIN and pad % 2 == 0) def fill(wem: bytes, size: int) -> bytes: """`wem` grown to exactly `size` bytes (see above). ValueError if `fillable` is False.""" if not fillable(len(wem), size): raise ValueError("a %d-byte WEM cannot fill a %d-byte slot exactly" % (len(wem), size)) pad = size - len(wem) if not pad: return wem i = _data_chunk(wem) text = pad - 8 - 4 - 8 - 4 chunk = (b"LIST" + struct.pack(" bytes: """The WEM without a filler chunk added by `fill` (a game WEM is returned unchanged).""" i = _data_chunk(wem) if i is None: return wem for j in range(12, i, 2): if wem[j:j + 4] == b"LIST" and wem[j + 8:j + 16] == b"adtllabl": n = 8 + struct.unpack_from("