Skip to content

fix #397 - #398

Open
GoJean wants to merge 2 commits into
K0lb3:masterfrom
GoJean:fix-#397
Open

GoJean wants to merge 2 commits into
K0lb3:masterfrom
GoJean:fix-#397

Conversation

@GoJean

@GoJean GoJean commented Oct 31, 2026

Copy link
Copy Markdown

See issue #397

Comment thread UnityPy/environment.py Resolved
GoJean

This comment was marked as outdated.

As pointed out in the review by @isHarryh, the previous commit broke the old behavior where split files could start from either 0 or 1. 

This commit fixes the regression by only breaking the loop when `i > 0` (using `if i:`). If `split0` is not found, the loop will now correctly continue and try to load `split1`, preserving the compatibility introduced in PR K0lb3#94.

@isHarryh isHarryh left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested changes:

def _load_split_file(
    self,
    basename: str,
    open_f: Optional[Callable[[str], BinaryIO]] = None,
) -> bytes:
    file: List[bytes] = []
    for i in range(0, 1000):
        item = f"{basename}.split{i}"
        if open_f is not None:
            try:
                f = open_f(item)
            except (FileNotFoundError, KeyError):
                if i:
                    break
                continue
            with f:
                file.append(f.read())
        elif self.fs.exists(item):
            with self.fs.open(item, "rb") as f:
                file.append(f.read())  # type: ignore
        elif i:
            break
    return b"".join(file)

Comment thread UnityPy/environment.py
)

def _load_split_file(self, basename: str) -> bytes:
def _load_split_file(self, basename: str, open_f: Callable[[str], BinaryIO] = None) -> bytes:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Type annotation of open_f should be wrapped with Optional[...].

Comment thread UnityPy/environment.py
if open_f:
try:
file.append(open_f(item).read())
except:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will cause E722 Do not use bare except ruff error.

Comment thread UnityPy/environment.py
else:
if i:
break

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This line has trailing spaces

This branch has not been deployed

No deployments
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