-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_unpack_assets.py
More file actions
93 lines (76 loc) · 3.11 KB
/
debug_unpack_assets.py
File metadata and controls
93 lines (76 loc) · 3.11 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
import warnings
import UnityPy
import configparser
def unpack_all_assets(source_folder: str, destination_folder: str):
if not os.path.exists(source_folder):
raise FileNotFoundError(f"Source folder '{source_folder}' does not exist.")
if not os.path.exists(destination_folder):
os.makedirs(destination_folder, exist_ok=True)
print(f"Destination folder '{destination_folder}' created.")
# iterate over all files in source folder
for root, dirs, files in os.walk(source_folder):
for file_name in files:
# generate file_path
file_path = os.path.join(root, file_name)
# load that file via UnityPy.load
env = UnityPy.load(file_path)
# iterate over internal objects
for obj in env.objects:
# process specific object types
if obj.type.name in ["Texture2D"]:
# parse the object data
data = obj.read()
# create destination path
if hasattr(data, "name"):
# if the object has a name attribute, use it
name = data.name
elif hasattr(data, "m_Name"):
# if the object has a m_Name attribute, use it
name = data.m_Name
else:
# fallback to a generic name
name = "unknown_asset"
try:
dest = os.path.join(destination_folder, f"{file_name}/{name}")
os.makedirs(os.path.dirname(dest), exist_ok=True)
# make sure that the extension is correct
# you probably only want to do so with images/textures
dest, ext = os.path.splitext(dest)
dest = dest + ".png"
img = data.image
img.save(dest)
print(f"Unpacked {name} from {file_name}")
except Exception as e:
warnings.warn(f"Failed to unpack {name} from {file_name}: {e}")
def main():
print("\n[DEBUG UNPACK ASSETS] Unpacking assets...")
config = configparser.ConfigParser()
config.read("config.ini")
unpack_all_assets(
config.get(
"Stronghold Definitive Edition",
"target_folder",
fallback="downloads/Stronghold Definitive Edition",
),
config.get(
"Stronghold Definitive Edition",
"debug_unpacked_folder",
fallback="downloads/unpacked",
),
)
unpack_all_assets(
config.get(
"Stronghold Crusader Definitive Edition",
"target_folder",
fallback="downloads/Stronghold Crusader Definitive Edition",
),
config.get(
"Stronghold Crusader Definitive Edition",
"debug_unpacked_folder",
fallback="downloads/unpacked",
),
)
print("\n[DEBUG UNPACK ASSETS] Unpacking completed.")
if __name__ == "__main__":
main()