Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions UnityPy/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ def load(self, files: list):
}
)

def _load_split_file(self, basename):
file = []
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())
elif i:
break
return b"".join(file)

def load_file(
self,
file: Union[io.IOBase, str],
Expand All @@ -95,29 +106,25 @@ def load_file(
split_match = reSplit.match(file)
if split_match:
basepath, basename = split_match.groups()
file = []
for i in range(0, 999):
item = f"{basepath}.split{i}"
if self.fs.exists(item):
with self.fs.open(item, "rb") as f:
file.append(f.read())
elif i:
break
name = basepath
file = b"".join(file)
file = self._load_split_file(name)
else:
name = file
if not os.path.exists(file):
# relative paths are in the asset directory, not the cwd
if not os.path.isabs(file):
file = os.path.join(self.path, file)
# for dependency loading of split files
if os.path.exists(f"{file}.split0"):
file = self._load_split_file(file)
# Unity paths are case insensitive, so we need to find "Resources/Foo.asset" when the record says "resources/foo.asset"
if not os.path.exists(file):
elif not os.path.exists(file):
file = ImportHelper.find_sensitive_path(self.path, file)
# nonexistent files might be packaging errors or references to Unity's global Library/
if file is None:
return
file = self.fs.open(file, "rb")
if type(file) == str:
file = self.fs.open(file, "rb")

typ, reader = ImportHelper.check_file_type(file)

Expand Down Expand Up @@ -273,15 +280,7 @@ def load_assets(self, assets: List[str], open_f: Callable[[str], io.IOBase]):
continue

split_files.append(basepath)
data = []
for i in range(0, 999):
item = f"{basepath}.split{i}"
if item in assets:
with open_f(item) as f:
data.append(f.read())
elif i:
break
data = b"".join(data)
data = self._load_split_file(basepath)
path = basepath
else:
data = open_f(path).read()
Expand Down