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
27 changes: 14 additions & 13 deletions UnityPy/helpers/ResourceReader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os

from .ImportHelper import find_all_files
import os, glob

def search_resource(path, name):
files = glob.glob(os.path.join(path, "**", name), recursive = True)
return files[0] if len(files) else ""

def get_resource_data(*args):
"""
Expand Down Expand Up @@ -30,27 +31,28 @@ def get_resource_data(*args):
resource_file_name = path

reader = assets_file.environment.resources.get(resource_file_name)
base_name = os.path.basename(resource_file_name)
if not reader:
reader = assets_file.environment.resources.get(
os.path.basename(resource_file_name)
)
reader = assets_file.environment.resources.get(base_name)
if not reader:
reader = assets_file.environment.resources.get(
os.path.basename(resource_file_name.replace('.assets.resS', '.resource'))
base_name.replace('.assets.resS', '.resource')
)

if reader:
reader.Position = offset
return reader.read_bytes(size)

current_directory = ''
if not assets_file.environment.path:
return
current_directory = os.path.dirname(assets_file.environment.path)
current_directory = os.getcwd()
else:
current_directory = os.path.dirname(assets_file.environment.path)
resource_file_path = os.path.join(current_directory, resource_file_name)
if not os.path.isfile(resource_file_path):
find_files = find_all_files(current_directory, resource_file_name)
if find_files:
resource_file_path = find_files[0]
resource_file_path = search_resource(current_directory, base_name)
if not os.path.isfile(resource_file_path):
resource_file_path = search_resource(current_directory, base_name.replace('.assets.resS', '.resource'))

if os.path.isfile(resource_file_path):
with open(resource_file_path, "rb") as f:
Expand All @@ -60,7 +62,6 @@ def get_resource_data(*args):
raise FileNotFoundError(
f"Can't find the resource file {resource_file_name}"
)

else:
reader.Position = offset
return reader.read_bytes(size)