forked from K0lb3/UnityPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResourceReader.py
More file actions
66 lines (57 loc) · 1.86 KB
/
Copy pathResourceReader.py
File metadata and controls
66 lines (57 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
from .ImportHelper import find_all_files
def get_resource_data(*args):
"""
Input:
Option 1:
path - file path
assets_file - SerializedFile
offset -
size -
Option 2:
reader - EndianBinaryReader
offset -
size -
"""
if len(args) == 4:
need_search = True
path = args[0]
assets_file = args[1]
elif len(args) == 3:
need_search = False
reader = args[0]
offset = args[-2]
size = args[-1]
if need_search:
resource_file_name = path
reader = assets_file.environment.resources.get(resource_file_name)
if not reader:
reader = assets_file.environment.resources.get(
os.path.basename(resource_file_name)
)
if not reader:
reader = assets_file.environment.resources.get(
os.path.basename(resource_file_name.replace('.assets.resS', '.resource'))
)
if reader:
reader.Position = offset
return reader.read_bytes(size)
if not assets_file.environment.path:
return
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]
if os.path.isfile(resource_file_path):
with open(resource_file_path, "rb") as f:
f.seek(offset)
return f.read(size)
else:
raise FileNotFoundError(
f"Can't find the resource file {resource_file_name}"
)
else:
reader.Position = offset
return reader.read_bytes(size)