#!/usr/bin/env python3 """Extract a single compressed RED4 archive segment by resource hash.""" from __future__ import annotations import argparse import struct from pathlib import Path FILE_ENTRY_SIZE = 56 FILE_SEGMENT_SIZE = 16 def parse_hash(value: str) -> int: return int(value, 0) def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("archive", type=Path) parser.add_argument("resource_hash", type=parse_hash) parser.add_argument("outpath", type=Path) args = parser.parse_args() with args.archive.open("rb") as archive: header = archive.read(40) if len(header) != 40: raise SystemExit("archive header is too short") magic, _version, index_pos, _index_size, *_rest = struct.unpack("