From 8e2b1632365474760f72b212d6a50c1f4986afe7 Mon Sep 17 00:00:00 2001 From: Rudolf Kolbe Date: Sun, 8 Dec 2024 00:08:33 +0100 Subject: [PATCH] BundleFile - fix FS writing (correct pre block data padding) --- UnityPy/files/BundleFile.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/UnityPy/files/BundleFile.py b/UnityPy/files/BundleFile.py index 791f3138..5c6425aa 100644 --- a/UnityPy/files/BundleFile.py +++ b/UnityPy/files/BundleFile.py @@ -342,7 +342,24 @@ def align(alignment: int, value: int) -> int: size = writer.Position + 8 + 12 # total size, block header sizes & flag if self.stream_version >= 7 or self.uses_block_alignment: size += align(16, size) - size += len(compressed_block_info) + len(compressed_block_info) + if ( + self.dataflags & ArchiveFlags.BlocksInfoAtTheEnd + ): # kArchiveBlocksInfoAtTheEnd + if ( + isinstance(self.dataflags, ArchiveFlags) + and self.dataflags & ArchiveFlags.BlockInfoNeedPaddingAtStart + ): + size += align(16, size) + size += len(compressed_directory_datas) + size += len(compressed_block_info) + else: + size += len(compressed_block_info) + if ( + isinstance(self.dataflags, ArchiveFlags) + and self.dataflags & ArchiveFlags.BlockInfoNeedPaddingAtStart + ): + size += align(16, size) + size += len(compressed_directory_datas) # write file writer.write_long(size) @@ -359,10 +376,20 @@ def align(alignment: int, value: int) -> int: if ( self.dataflags & ArchiveFlags.BlocksInfoAtTheEnd ): # kArchiveBlocksInfoAtTheEnd + if ( + isinstance(self.dataflags, ArchiveFlags) + and self.dataflags & ArchiveFlags.BlockInfoNeedPaddingAtStart + ): + writer.align_stream(16) writer.write_bytes(compressed_directory_datas) writer.write_bytes(compressed_block_info) else: writer.write_bytes(compressed_block_info) + if ( + isinstance(self.dataflags, ArchiveFlags) + and self.dataflags & ArchiveFlags.BlockInfoNeedPaddingAtStart + ): + writer.align_stream(16) writer.write_bytes(compressed_directory_datas) return writer