2021-02-12 21:57:06 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
2020-03-17 04:31:30 +00:00
|
|
|
import os
|
|
|
|
from shutil import copyfile
|
2020-12-26 11:39:52 +00:00
|
|
|
from multiprocessing import Pool
|
|
|
|
from multiprocessing import cpu_count
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-04-30 21:23:22 +00:00
|
|
|
def Extract(xmlPath, outputPath, outputSourcePath):
|
|
|
|
ExtractFile(xmlPath, outputPath, outputSourcePath, 1, 0)
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-04-30 21:23:22 +00:00
|
|
|
def ExtractScene(xmlPath, outputPath, outputSourcePath):
|
|
|
|
ExtractFile(xmlPath, outputPath, outputSourcePath, 1, 1)
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-04-30 21:23:22 +00:00
|
|
|
def ExtractFile(xmlPath, outputPath, outputSourcePath, genSrcFile, incFilePrefix):
|
|
|
|
execStr = "tools/ZAPD/ZAPD.out e -eh -i %s -b baserom/ -o %s -osf %s -gsf %i -ifp %i -rconf tools/ZAPDConfigs/MqDbg/Config.xml" % (xmlPath, outputPath, outputSourcePath, genSrcFile, incFilePrefix)
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 11:39:52 +00:00
|
|
|
print(execStr)
|
|
|
|
os.system(execStr)
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 11:39:52 +00:00
|
|
|
def ExtractFunc(fullPath):
|
|
|
|
outPath = ("assets/" + fullPath.split("assets/xml/")[1]).split(".xml")[0]
|
2021-04-30 21:23:22 +00:00
|
|
|
outSourcePath = ("assets/" + fullPath.split("assets/xml/")[1]).split(".xml")[0]
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 11:39:52 +00:00
|
|
|
if (fullPath.startswith("assets/xml/scenes/")):
|
2021-04-30 21:23:22 +00:00
|
|
|
ExtractScene(fullPath, outPath, outSourcePath)
|
2020-12-26 11:39:52 +00:00
|
|
|
else:
|
2021-04-30 21:23:22 +00:00
|
|
|
Extract(fullPath, outPath, outSourcePath)
|
2020-05-26 16:53:53 +00:00
|
|
|
|
2020-12-28 23:37:52 +00:00
|
|
|
def main():
|
2021-02-12 21:57:06 +00:00
|
|
|
parser = argparse.ArgumentParser(description="baserom asset extractor")
|
|
|
|
parser.add_argument("-s", "--single", help="asset path relative to assets/, e.g. objects/gameplay_keep")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
asset_path = args.single
|
|
|
|
if asset_path is not None:
|
|
|
|
if asset_path.endswith("/"):
|
|
|
|
asset_path = asset_path[0:-1]
|
2021-04-30 21:23:22 +00:00
|
|
|
Extract(f"assets/xml/{asset_path}.xml", f"assets/{asset_path}/", f"assets/{asset_path}/")
|
2021-02-12 21:57:06 +00:00
|
|
|
else:
|
|
|
|
xmlFiles = []
|
|
|
|
for currentPath, folders, files in os.walk("assets"):
|
|
|
|
for file in files:
|
|
|
|
fullPath = os.path.join(currentPath, file)
|
|
|
|
if file.endswith(".xml") and currentPath.startswith("assets/xml/"):
|
|
|
|
outPath = ("assets/" + fullPath.split("assets/xml/")[1]).split(".xml")[0]
|
|
|
|
xmlFiles.append(fullPath)
|
|
|
|
|
|
|
|
numCores = cpu_count()
|
|
|
|
print("Extracting assets with " + str(numCores) + " CPU cores.")
|
|
|
|
p = Pool(numCores)
|
|
|
|
p.map(ExtractFunc, xmlFiles)
|
2020-12-28 23:37:52 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|