"""Prepare the original default SoundEffects.omt bank (EXE423642..656). Numeric effect IDs are archive identities, not offsets into the four-entry sounds.omt archive. Preserve the original PCM/RIFF bytes and explicit metadata. """ import hashlib import json from pathlib import Path import struct from entities import _decode, resolve_asset from omt import Database, FormatError def export_sound_bank(original: Path, output: Path) -> dict: original, output = original.resolve(), output.resolve() if output.is_relative_to(original) or original.is_relative_to(output): raise FormatError('Sound output must be separate from original files') source = resolve_asset(original, 'omt/SoundEffects.omt') database = Database(source) source_hash = hashlib.sha256(database.data).hexdigest() resources = [] for entry in database.entries: if entry.type != 'Wave': continue resource = {'database': source.relative_to(original).as_posix(), 'type': 'Wave', 'id': entry.id, 'name': entry.name, 'offset': entry.offset, 'size': entry.size, 'databaseSha256': source_hash} _decode(database, entry, resource, output) if 'seconds' not in resource['audio']: # Some original resources contain MPEG Layer3 in RIFF. Preserve the # encoded bytes; duration comes from the explicit fact sample count. raw = (output/resource['path']).read_bytes() position, rate, frames, encoding = 12, None, None, None while position + 8 <= len(raw): tag = raw[position:position+4] size = struct.unpack_from(' len(raw): raise FormatError('Sound RIFF chunk escapes resource') if tag == b'fmt ' and size >= 16: encoding, channels, rate = struct.unpack_from('= 4: frames = struct.unpack_from('