import subprocess, argparse
from pathlib import Path
H = b"beeplay"; K = 0x44; O = 16; L = 8
def decrypt(data: bytes) -> bytes:
buf = bytearray(data[len(H):])
for i in range(L): buf[O + i] ^= K
return bytes(buf)
def astc2png(astc: Path, png: Path, mode: str):
subprocess.run(["astcenc", f"-d{mode}", str(astc), str(png)], check=True)
def main():
p = argparse.ArgumentParser()
p.add_argument("file")
p.add_argument("--mode", choices=list("lshH"), default="l")
p.add_argument("--outdir")
a = p.parse_args()
src = Path(a.file)
outdir = Path(a.outdir) if a.outdir else src.parent
outdir.mkdir(parents=True, exist_ok=True)
astc = outdir / (src.stem + ".astc")
png = outdir / (src.stem + ".png")
astc.write_bytes(decrypt(src.read_bytes()))
astc2png(astc, png, a.mode)
if __name__ == "__main__":
main()