From 7b6b21ebaa1670674ca5ed4218104d56f7ab7f24 Mon Sep 17 00:00:00 2001 From: GoJean Date: Sat, 31 Oct 2026 13:37:49 +0800 Subject: [PATCH 1/2] fix #397 See issue #397 --- UnityPy/environment.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/UnityPy/environment.py b/UnityPy/environment.py index fa06ab91..38500dd4 100644 --- a/UnityPy/environment.py +++ b/UnityPy/environment.py @@ -86,15 +86,22 @@ def load(self, files: List[str]): {ntpath.basename(f): self.load_file(self.fs.open(f, "rb"), self, f) for f in files if self.fs.exists(f)} ) - def _load_split_file(self, basename: str) -> bytes: + def _load_split_file(self, basename: str, open_f: Callable[[str], BinaryIO] = None) -> bytes: file: List[bytes] = [] for i in range(0, 999): item = f"{basename}.split{i}" - if self.fs.exists(item): - with self.fs.open(item, "rb") as f: - file.append(f.read()) # type: ignore - elif i: - break + if open_f: + try: + file.append(open_f(item).read()) + except: + break + else: + if self.fs.exists(item): + with self.fs.open(item, "rb") as f: + file.append(f.read()) # type: ignore + else: + break + return b"".join(file) def load_file( @@ -311,7 +318,7 @@ def load_assets(self, assets: List[str], open_f: Callable[[str], BinaryIO]): continue split_files.append(basepath) - data = self._load_split_file(basepath) + data = self._load_split_file(basepath, open_f) path = basepath else: data = open_f(path) From dedbf052959d491be6dad338a76d109008602fda Mon Sep 17 00:00:00 2001 From: GoJean Date: Mon, 2 Nov 2026 16:46:27 +0800 Subject: [PATCH 2/2] fix: restore compatibility for loading splits from 1 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 #94. --- UnityPy/environment.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/UnityPy/environment.py b/UnityPy/environment.py index 38500dd4..efd904c6 100644 --- a/UnityPy/environment.py +++ b/UnityPy/environment.py @@ -94,13 +94,15 @@ def _load_split_file(self, basename: str, open_f: Callable[[str], BinaryIO] = No try: file.append(open_f(item).read()) except: - break + if i: + break else: if self.fs.exists(item): with self.fs.open(item, "rb") as f: file.append(f.read()) # type: ignore else: - break + if i: + break return b"".join(file)