From 8efe913ad546a692e7c8830dcc872a1ebd668b28 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Sun, 30 Jul 2023 17:55:59 +0000 Subject: [PATCH] Fix AFP extract always decompiling and writing code, fix colors off on some textures for some games. --- bemani/format/afp/container.py | 11 +++++++---- bemani/utils/afputils.py | 8 +++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/bemani/format/afp/container.py b/bemani/format/afp/container.py index 3cf32c6..33e2087 100644 --- a/bemani/format/afp/container.py +++ b/bemani/format/afp/container.py @@ -527,14 +527,17 @@ class TXP2File(TrackedCoverage, VerboseOutput): # Since the AFP file format can be found in both big and little endian, its # possible that some of these loaders might need byteswapping on some platforms. - # This has been tested on files intended for X86 (little endian). + # This has been tested on files intended for X86 (little endian). I've found that + # the "correct" thing to do is always treat data as little-endian instead of the + # determined endianness of the file. But, this could also be broken per-game, so + # I'm not entirely sure this is fully possible to do generically. if fmt == 0x0B: # 16-bit 565 color RGB format. Game references D3D9 texture format 23 (R5G6B5). newdata = [] for i in range(width * height): pixel = struct.unpack( - f"{self.endian}H", + " None: +def decompile_and_write_bytecode(swf: SWF, directory: str, *, verbose: bool) -> None: # Actually place the files down. os.makedirs(directory, exist_ok=True) @@ -103,6 +103,7 @@ def extract_txp2( write_mappings: bool = False, write_raw: bool = False, write_binaries: bool = False, + write_bytecode: bool = False, pretend: bool = False, verbose: bool = False, ) -> int: @@ -312,7 +313,7 @@ def extract_txp2( announced[texturename] = True if write_bytecode: for swf in afpfile.swfdata: - write_bytecode(swf, output_dir, verbose=verbose) + decompile_and_write_bytecode(swf, output_dir, verbose=verbose) return 0 @@ -414,7 +415,7 @@ def decompile_afp(afp: str, bsi: str, output_dir: str, *, verbose: bool = False) # Now, decompile it swf.parse(verbose=verbose) - write_bytecode(swf, output_dir, verbose=verbose) + decompile_and_write_bytecode(swf, output_dir, verbose=verbose) return 0 @@ -1375,6 +1376,7 @@ def main() -> int: write_mappings=args.write_mappings, write_raw=args.write_raw, write_binaries=args.write_binaries, + write_bytecode=args.write_bytecode, pretend=args.pretend, verbose=args.verbose, )