"""Decompress Facade's zlib-packed rule files into vendor/rules/ for reading. python tools/extract_rules.py [facade-install-folder] vendor/ is gitignored: these are the game's files, not ours to redistribute. Read them with tools/show_rules.py. """ import sys import zlib from facade_install import REPO, from_args OUT = REPO / "vendor" / "rules" SUFFIXES = {".rul", ".map", ".bin"} def main(): sources = from_args(sys.argv).sources done, skipped = 0, [] for path in sorted(sources.rglob("*")): if path.suffix.lower() not in SUFFIXES or not path.is_file(): continue try: text = zlib.decompress(path.read_bytes()) except zlib.error: skipped.append(path.name) continue target = OUT / path.relative_to(sources) target = target.with_name(target.name + ".txt") target.parent.mkdir(parents=True, exist_ok=True) target.write_bytes(text) done += 1 print("decompressed %d files into %s" % (done, OUT)) if skipped: print("not zlib, skipped: %s" % ", ".join(skipped)) if __name__ == "__main__": main()