From 786102c43e090d83dceebab5389a1b83a6c19111 Mon Sep 17 00:00:00 2001 From: com55 <33087300+com55@users.noreply.github.com> Date: Wed, 5 Aug 2026 21:49:49 +0700 Subject: [PATCH 1/2] fix(BundleFile): correct packer tuple docstring and add lz4hc preset The save(packer=...) docstring listed the custom tuple as (block_info_flag, data_flag), but save_fs(writer, *packer) expects (data_flag, block_info_flag). LZ4HC compression was already wired through CompressionHelper; add packer="lz4hc" (data_flag=195, block_info_flag=3) and update the stale "not implemented" comment. --- UnityPy/environment.py | 2 +- UnityPy/files/BundleFile.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/UnityPy/environment.py b/UnityPy/environment.py index c4a60aea..5425b9aa 100644 --- a/UnityPy/environment.py +++ b/UnityPy/environment.py @@ -176,7 +176,7 @@ def load_zip_file(self, value): def save(self, pack="none", out_path="output"): """Saves all changed assets. Mark assets as changed using `.mark_changed()`. - pack = "none" (default) or "lz4" + pack = "none" (default), "lz4", "lz4hc", "lzma", or "original" """ for fname, fitem in self.files.items(): if getattr(fitem, "is_changed", False): diff --git a/UnityPy/files/BundleFile.py b/UnityPy/files/BundleFile.py index 3e17d7de..55390af5 100644 --- a/UnityPy/files/BundleFile.py +++ b/UnityPy/files/BundleFile.py @@ -191,10 +191,12 @@ def save(self, packer=None): packer: can be either one of the following strings - or tuple consisting of (block_info_flag, data_flag) + or tuple consisting of (data_flag, block_info_flag) allowed strings: none - no compression, default, safest bet lz4 - lz4 compression + lz4hc - lz4hc compression + lzma - lzma compression original - uses the original flags """ # file_header @@ -227,6 +229,8 @@ def save(self, packer=None): ) elif packer == "lz4": self.save_fs(writer, data_flag=194, block_info_flag=2) + elif packer == "lz4hc": + self.save_fs(writer, data_flag=195, block_info_flag=3) elif packer == "lzma": self.save_fs(writer, data_flag=65, block_info_flag=1) elif isinstance(packer, tuple): @@ -242,12 +246,13 @@ def save_fs(self, writer: EndianBinaryWriter, data_flag: int, block_info_flag: i # 0b1000000 / 0b11000000 | 64 / 192 - uncompressed # 0b11000010 | 194 - lz4 + # 0b11000011 | 195 - lz4hc # block_info_flag # 0 / 0b1000000 | 0 / 64 - uncompressed # 0b1 | 1 - lzma # 0b10 | 2 - lz4 - # 0b11 | 3 - lz4hc [not implemented] + # 0b11 | 3 - lz4hc # 0b100 | 4 - lzham [not implemented] # data_flag From 1a8dcd075cf1598cff1ad1113efad64a0c61b6cd Mon Sep 17 00:00:00 2001 From: com55 <33087300+com55@users.noreply.github.com> Date: Wed, 5 Aug 2026 23:22:14 +0700 Subject: [PATCH 2/2] docs(Environment): clarify pack options depend on file type Environment.save forwards pack to every file's save(); BundleFile and WebFile accept different packer values, so do not list BundleFile-only presets as if they were universal. --- UnityPy/environment.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/UnityPy/environment.py b/UnityPy/environment.py index 5425b9aa..08ea909f 100644 --- a/UnityPy/environment.py +++ b/UnityPy/environment.py @@ -176,7 +176,11 @@ def load_zip_file(self, value): def save(self, pack="none", out_path="output"): """Saves all changed assets. Mark assets as changed using `.mark_changed()`. - pack = "none" (default), "lz4", "lz4hc", "lzma", or "original" + + ``pack`` is forwarded as ``packer`` to each file's ``save()``. + Supported values depend on the file type, for example: + BundleFile - "none", "lz4", "lz4hc", "lzma", "original" + WebFile - "none", "gzip", "brotli" """ for fname, fitem in self.files.items(): if getattr(fitem, "is_changed", False):