diff --git a/UnityPy/environment.py b/UnityPy/environment.py index fa06ab91..8d9cf90c 100644 --- a/UnityPy/environment.py +++ b/UnityPy/environment.py @@ -86,11 +86,24 @@ 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: Optional[Callable[[str], BinaryIO]] = None, + ) -> bytes: file: List[bytes] = [] - for i in range(0, 999): + for i in range(0, 1000): item = f"{basename}.split{i}" - if self.fs.exists(item): + 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: @@ -311,7 +324,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)