forked from HashEdits/EditDistributionTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonPatcher.py
More file actions
188 lines (119 loc) · 5.82 KB
/
Copy pathPythonPatcher.py
File metadata and controls
188 lines (119 loc) · 5.82 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import os
import sys
import shutil
import subprocess
def print_ascii_art():
ascii_art = r"""
____ __ ___ ____ ____ ____ __ ___ __ _ __ __ _ ___ ____ __ ____ ___ _ _ ____ ____
( __)/ _\ / __)( __) (_ _)( _ \ / _\ / __)( / )( )( ( \ / __) ( _ \ / _\(_ _)/ __)/ )( \( __)( _ \
) _)/ \( (__ ) _) )( ) // \( (__ ) ( )( / /( (_ \ ) __// \ )( ( (__ ) __ ( ) _) ) /
(__) \_/\_/ \___)(____) (__) (__\_)\_/\_/ \___)(__\_)(__)\_)__) \___/ (__) \_/\_/(__) \___)\_)(_/(____)(__\_)
"""
credits = r"""
Made By Hash - vVersionNumber
"""
print(ascii_art)
print(credits)
def print_ascii_success():
ascii_art = r"""
____ _ _ ___ ____ ____ ____ _
/ ___)/ )( \ / __)( __)/ ___)/ ___) / \
\___ \) \/ (( (__ ) _) \___ \\___ \ \_/
(____/\____/ \___)(____)(____/(____/ (_)
"""
desc = r"""
Please import the prefab in your scene
"""
print(ascii_art)
print(desc)
def print_ascii_error():
ascii_art = r"""
____ ____ ____ __ ____
( __)( _ \( _ \ / \( _ \
) _) ) / ) /( O )) /
(____)(__\_)(__\_) \__/(__\_)
"""
print(ascii_art)
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def delete_files_in_directory(directory_path):
try:
# Check if the directory exists
if os.path.exists(directory_path):
# Iterate over all files and subdirectories in the directory
for root, dirs, files in os.walk(directory_path, topdown=False):
for file_name in files:
file_path = os.path.join(root, file_name)
os.remove(file_path) # Delete the file
for dir_name in dirs:
dir_path = os.path.join(root, dir_name)
shutil.rmtree(dir_path) # Delete the subdirectory and its contents
print(f"OSC Config cleared.")
else:
print(f"no OSC config found")
except Exception as e:
print(f"An error occurred while clearing OSC conifg: {e}")
def patch_model(original_model_path, original_meta_file_path, diff_file_path, meta_diff_file_path, output_name):
script_directory = resource_path(os.path.dirname(os.path.abspath(__file__)))
original_model = resource_path(original_model_path)
original_meta_file = resource_path(original_meta_file_path)
diff_file = resource_path(diff_file_path)
meta_diff_file = resource_path(meta_diff_file_path)
ErrorFlag = False
if not os.path.exists(original_model):
error_msg = f"Please make sure you have the original .fbx at:\n{original_model}"
print_ascii_error()
print(error_msg)
input("Press Enter to continue...")
ErrorFlag = True
return
if not os.path.exists(diff_file):
print_ascii_error()
print("Missing diff file")
input("Press Enter to continue...")
ErrorFlag = True
return
backup_dir = os.path.abspath(os.path.join(__file__, '..', '..', 'fbx'))
os.makedirs(backup_dir, exist_ok=True)
shutil.copy(original_model, original_model + '.bak')
shutil.copy(original_meta_file, original_meta_file + '.bak')
shutil.copy(original_model, os.path.join(backup_dir, f'{output_name}'))
shutil.copy(original_meta_file, os.path.join(backup_dir, f'{output_name}.meta'))
patcher_exe = os.path.join(os.path.dirname(__file__), 'data', 'hpatchz.exe')
patched_model = os.path.join(backup_dir, f'{output_name}')
patched_meta_file = os.path.join(backup_dir, f'{output_name}.meta')
if subprocess.run([patcher_exe, '-f', patched_model, diff_file, patched_model]).returncode != 0:
print_ascii_error()
print("Error occurred during patching process for model.")
input("Press Enter to continue...")
ErrorFlag = True
return
if subprocess.run([patcher_exe, '-f', patched_meta_file, meta_diff_file, patched_meta_file]).returncode != 0:
print_ascii_error()
print("Error occurred during patching process for meta file.")
input("Press Enter to continue...")
ErrorFlag = True
return
return ErrorFlag
def main():
print_ascii_art()
ErrorFlag = False
ErrorFlag = patch_model(
original_model_path="../../../ Location of your FBX relative to Assets", # Change this to the relative directory to your FBX
original_meta_file_path="../../../ Location of your FBX.meta relative to Assets", # Change this to the relative directory to your FBX's import settings
diff_file_path="data/DiffFiles/NameOfYourDiffFile.hdiff", # Change the name to the name of the Hdiff file you generated
meta_diff_file_path="data/DiffFiles/NameOfYourMetaDiffFile.hdiff", # Change the name to the name of the MetaHdiff file you generated
output_name = "MyCoolAvatar_FT" # Change this to your desired output name # Change this to your desired output name
)
delete_files_in_directory(os.path.join(os.path.expanduser("~"), "AppData", "LocalLow", "VRChat", "VRChat", "OSC"))
if ErrorFlag==False:
print_ascii_success()
input("Press Enter to continue...")
if __name__ == "__main__":
main()