From 9925b2f6b0be269bb5119769232c6989dac1f8fb Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Sun, 11 Apr 2021 20:45:40 +0000 Subject: [PATCH] Add an extract option to write afp/bsi/geo files out of TXP2 containers similar to IFS containers. --- bemani/utils/afputils.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/bemani/utils/afputils.py b/bemani/utils/afputils.py index 054b50b..eb40fb8 100644 --- a/bemani/utils/afputils.py +++ b/bemani/utils/afputils.py @@ -62,6 +62,12 @@ def main() -> int: action="store_true", help="Split textures into individual sprites", ) + extract_parser.add_argument( + "-b", + "--write-binaries", + action="store_true", + help="Write binary SWF files to disk", + ) update_parser = subparsers.add_parser('update', help='Update relevant textures in a file from a directory') update_parser.add_argument( @@ -214,6 +220,33 @@ def main() -> int: with open(filename, "w") as sfp: sfp.write(str(afpfile.fontdata)) + if args.write_binaries: + for i, name in enumerate(afpfile.swfmap.entries): + swf = afpfile.swfdata[i] + filename = os.path.join(args.dir, name) + + if args.pretend: + print(f"Would write {filename}.afp SWF data...") + print(f"Would write {filename}.bsi SWF descramble data...") + else: + print(f"Writing {filename}.afp SWF data...") + with open(f"{filename}.afp", "wb") as bfp: + bfp.write(swf.data) + print(f"Writing {filename}.bsi SWF descramble data...") + with open(f"{filename}.bsi", "wb") as bfp: + bfp.write(swf.descramble_info) + + for i, name in enumerate(afpfile.shapemap.entries): + shape = afpfile.shapes[i] + filename = os.path.join(args.dir, f"{name}.geo") + + if args.pretend: + print(f"Would write {filename} shape data...") + else: + print(f"Writing {filename} shape data...") + with open(filename, "wb") as bfp: + bfp.write(shape.data) + if args.generate_mapping_overlays: overlays: Dict[str, Any] = {}