Skip to content

Commit

Permalink
BundleFile - fix FS writing (correct pre block data padding)
Browse files Browse the repository at this point in the history
  • Loading branch information
K0lb3 committed Dec 7, 2024
1 parent dca5ba1 commit 8e2b163
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion UnityPy/files/BundleFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 8e2b163

Please sign in to comment.