Skip to content

Commit 70d2484

Browse files
committed
Improve readability of EMIPGenerator.py
1 parent 5eb74fb commit 70d2484

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

scripts/EMIPGenerator.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
print("Input folder " + sys.argv[2] + " must be a directory!")
1414
exit()
1515

16+
sharedassets_file = sys.argv[1]
17+
input_directory = sys.argv[2]
18+
output_file = sys.argv[3]
19+
20+
# sharedassets_file = './output/HigurashiEp09_Data/sharedassets0.assets'
21+
# input_directory = 'output/assets'
22+
# output_file = 'out.emip'
23+
1624
class AssetEdit:
1725
def __init__(self, file, id, name, type):
1826
self.file = file
@@ -23,7 +31,7 @@ def __init__(self, file, id, name, type):
2331

2432
@property
2533
def filePath(self):
26-
return sys.argv[2] + "/" + self.file
34+
return input_directory + "/" + self.file
2735

2836
def pngToTexture2D(self, pngData, unityVersion):
2937
image = Image.open(self.filePath)
@@ -157,20 +165,20 @@ def generateHeader(numEdits):
157165
header += b"\0" * 4 # Unknown
158166
header += (1).to_bytes(4, byteorder='big') # Number of files
159167
header += b"\0" * 4 # Unknown
160-
if os.path.abspath(sys.argv[1])[1] == ":": # Windows paths will be read properly, UNIX paths won't since UABE will be run with wine, so use a relative path
161-
path = os.path.abspath(sys.argv[1]).encode('utf-8')
168+
if os.path.abspath(sharedassets_file)[1] == ":": # Windows paths will be read properly, UNIX paths won't since UABE will be run with wine, so use a relative path
169+
path = os.path.abspath(sharedassets_file).encode('utf-8')
162170
else:
163-
path = sys.argv[1].encode('utf-8')
171+
path = sharedassets_file.encode('utf-8')
164172
header += len(path).to_bytes(2, byteorder='little') # Path length
165173
header += path # File path
166174
header += numEdits.to_bytes(4, byteorder='little') # Number of file changes
167175
return header
168176

169-
print(f"Running EMPIGenerator in directory [{sys.argv[2]}]")
177+
print(f"Running EMPIGenerator in directory [{input_directory}]")
170178

171179
edits = []
172180

173-
for file in os.listdir(sys.argv[2]):
181+
for file in os.listdir(input_directory):
174182
if file[0] == ".": continue
175183
matches = re.match(r"^(\d+).*", file)
176184
if matches:
@@ -181,7 +189,7 @@ def generateHeader(numEdits):
181189
if len(parts) < 2: continue
182190
edits.append(AssetEdit(file, None, "_".join(parts[:-1]), parts[-1]))
183191

184-
with open(sys.argv[1], "rb") as assetsFile:
192+
with open(sharedassets_file, "rb") as assetsFile:
185193
bundle = assetsFile.read()
186194
unityVersion = [int(x) for x in bundle[20:28].decode("utf-8").rstrip("\0").split(".")[:2]]
187195
assetsFile.seek(0)
@@ -192,7 +200,7 @@ def generateHeader(numEdits):
192200

193201
edits = sorted(edits, key=lambda x: x.id)
194202

195-
with open(sys.argv[3], "wb") as outputFile:
203+
with open(output_file, "wb") as outputFile:
196204
outputFile.write(generateHeader(len(edits)))
197205
for edit in edits:
198206
outputFile.write(edit.bytes(unityVersion))

0 commit comments

Comments
 (0)