Skip to content

fix packer tuple docstring order and add packer="lz4hc" - #378

Open
com55 wants to merge 2 commits into
K0lb3:masterfrom
com55:fix/lz4hc-packer-and-docstring
Open

fix packer tuple docstring order and add packer="lz4hc"#378
com55 wants to merge 2 commits into
K0lb3:masterfrom
com55:fix/lz4hc-packer-and-docstring

Conversation

@com55

@com55 com55 commented Aug 5, 2026

Copy link
Copy Markdown

Hi, I noticed two small issues around BundleFile.save(packer=...).

1) Docstring tuple order is wrong

The docstring currently says the custom packer tuple is (block_info_flag, data_flag), but the code does:

elif isinstance(packer, tuple):
    self.save_fs(writer, *packer)

and save_fs is defined as:

def save_fs(self, writer, data_flag: int, block_info_flag: int):

So the actual order is (data_flag, block_info_flag).
Using the documented order raises:

NotImplementedError: UnityPy always writes DirectoryInfo, so data_flag must include 0x40

(because 2 gets passed as data_flag).

2) Add packer="lz4hc"

LZ4HC is already supported through CompressionHelper:

COMPRESSION_MAP = {
    ...
    CompressionFlags.LZ4: compress_lz4,
    CompressionFlags.LZ4HC: compress_lz4,
}

and compress_lz4 already uses mode="high_compression".
packer="original" can also preserve LZ4HC flags from existing bundles.

But there is no string preset for it, and the comment in save_fs still says lz4hc [not implemented], which is outdated.

This PR adds:

elif packer == "lz4hc":
    self.save_fs(writer, data_flag=195, block_info_flag=3)

195 (0xC3) mirrors the existing "lz4" preset (194 / 0xC2):

  • 0x80 BlocksInfoAtTheEnd
  • 0x40 BlocksAndDirectoryInfoCombined
  • low bits = compression type (2 = LZ4, 3 = LZ4HC)

So 0x80 | 0x40 | 3 = 195.

Changes

  • Fix docstring: (data_flag, block_info_flag)
  • Document lzma / lz4hc in the allowed strings list
  • Add packer="lz4hc"
  • Update the stale lz4hc [not implemented] comment
  • Update Environment.save docstring pack options

Related issues

I searched existing issues first — I didn't find one specifically about the docstring order or a missing lz4hc preset.
Closest nearby issue is #377 (different packer="lz4" save quirk).

Example

import UnityPy

env = UnityPy.load("example.bundle")
data = env.file.save(packer="lz4hc")

# custom flags still work; order is (data_flag, block_info_flag)
data = env.file.save(packer=(0x43, 3))

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.
Copilot AI lite review requested due to automatic review settings August 5, 2026 16:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the BundleFile.save(packer=...) UX/documentation by correcting the documented tuple argument order and adding an explicit "lz4hc" preset consistent with the existing compression flag handling.

Changes:

  • Fix the documented custom packer tuple order to match save_fs(data_flag, block_info_flag).
  • Add packer="lz4hc" preset (and update related in-code comments / docstrings).
  • Expand documented packer options (including lzma) in relevant docstrings.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
UnityPy/files/BundleFile.py Corrects packer tuple doc and adds "lz4hc" preset + updates flag comments.
UnityPy/environment.py Updates Environment.save() docstring to list additional pack options.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread UnityPy/environment.py
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants