1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-21 04:24:43 +00:00
oot/extract_assets.py

101 lines
3.6 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import argparse
from multiprocessing import Pool, cpu_count, Event
2020-03-17 04:31:30 +00:00
import os
# Returns True if outFile doesn't exists
# or if inFile has been modified after the last modification of outFile
def checkTouchedFile(inFile: str, outFile: str) -> bool:
if not os.path.exists(outFile):
return True
return os.path.getmtime(inFile) > os.path.getmtime(outFile)
2020-03-17 04:31:30 +00:00
def Extract(xmlPath, outputPath, outputSourcePath):
ExtractFile(xmlPath, outputPath, outputSourcePath, 1, 0)
2020-03-17 04:31:30 +00:00
def ExtractScene(xmlPath, outputPath, outputSourcePath):
ExtractFile(xmlPath, outputPath, outputSourcePath, 1, 1)
2020-03-17 04:31:30 +00:00
def ExtractFile(xmlPath, outputPath, outputSourcePath, genSrcFile, incFilePrefix):
if globalAbort.is_set():
# Don't extract if another file wasn't extracted properly.
return
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)
if globalUnaccounted:
execStr += " -wu"
2020-03-17 04:31:30 +00:00
print(execStr)
exitValue = os.system(execStr)
if exitValue != 0:
globalAbort.set()
print("\n")
print("Error when extracting from file " + xmlPath, file=os.sys.stderr)
print("Aborting...", file=os.sys.stderr)
print("\n")
2020-03-17 04:31:30 +00:00
Updated Texture Asset Handling (#478) * Auto stash before rebase of "upstream/master" * A large number of scenes have been decompiled. * Fixed makefile * Decompiled around 40 scenes. * Removed old file * Finished matching remaining scenes. * Removed old commented out spec lines * Decompiled a few object files. * Reorganized xmls a bit. Updated pu_box overlay to use proper symbol. * Updated texture and object file decomp * Fixed newline issue with ZAPD * Moved scenes/ into the assets/ folder * Fixed a few compile errors * Auto stash before rebase of "upstream/master" * A large number of scenes have been decompiled. * Fixed makefile * Decompiled around 40 scenes. * Removed old file * Finished matching remaining scenes. * Removed old commented out spec lines * Decompiled a few object files. * Reorganized xmls a bit. Updated pu_box overlay to use proper symbol. * Updated texture and object file decomp * Moved scenes/ into the assets/ folder * Fixed a few compile errors * Fixed merge issues. * Fixed makefile merge error * Fixed additional merge error * Fixed several more merge issues * Commented out gameplay_keep and sk2 extraction, since currently unused. * Reenabled gameplay_keep extraction since it's used in the spec * Fixed build error * Removed test struct * Fixed makefile error that would happen on fresh builds * Fixed merge issue * Removed relative paths * Multithreading on extraction, spec uses numbers, few changes to XMLs * Removed redundant code from the extract_assets script * object_sk2 and object_spot09_obj OK * object_spot11_obj OK * object_spot17_obj OK * Test: One of the gameplay_keep dlists given a proper symbol * Updated asset symbol names based on new naming scheme * XMLs use "Offset" instead of "Address" now * Fixed merge issues, updated ovl_Magic_Dark xml and gfx file * Updated to use latest build of ZAPD * Updated ZAPD again * Updated ZAP to remove assimp dependency * Jenkins Test: Added .gitkeep file * Updated ZAP once more * Updated png file name to comply with new naming scheme. * Fixed bad include Co-authored-by: Jack Walker <7463599+Jack-Walker@users.noreply.github.com>
2020-12-26 11:39:52 +00:00
def ExtractFunc(fullPath):
*pathList, xmlName = fullPath.split(os.sep)
objectName = os.path.splitext(xmlName)[0]
outPath = os.path.join("assets", *pathList[2:], objectName)
outSourcePath = outPath
2020-03-17 04:31:30 +00:00
isScene = fullPath.startswith("assets/xml/scenes/")
if isScene:
objectName += "_scene"
if not globalForce:
cFile = os.path.join(outPath, objectName + ".c")
hFile = os.path.join(outPath, objectName + ".h")
if not checkTouchedFile(fullPath, cFile) and not checkTouchedFile(fullPath, hFile):
return
if isScene:
ExtractScene(fullPath, outPath, outSourcePath)
else:
Extract(fullPath, outPath, outSourcePath)
def initializeWorker(force: bool, abort, unaccounted: bool):
global globalForce
global globalAbort
global globalUnaccounted
globalForce = force
globalAbort = abort
globalUnaccounted = unaccounted
def main():
parser = argparse.ArgumentParser(description="baserom asset extractor")
parser.add_argument("-s", "--single", help="asset path relative to assets/, e.g. objects/gameplay_keep")
parser.add_argument("-f", "--force", help="Force the extraction of every xml instead of checking the touched ones.", action="store_true")
parser.add_argument("-u", "--unaccounted", help="Enables ZAPD unaccounted detector warning system.", action="store_true")
args = parser.parse_args()
abort = Event()
asset_path = args.single
if asset_path is not None:
# Always force if -s is used.
initializeWorker(True, abort, args.unaccounted)
fullPath = os.path.join("assets", "xml", asset_path + ".xml")
ExtractFunc(fullPath)
else:
xmlFiles = []
for currentPath, folders, files in os.walk(os.path.join("assets", "xml")):
for file in files:
fullPath = os.path.join(currentPath, file)
if file.endswith(".xml"):
xmlFiles.append(fullPath)
numCores = cpu_count()
print("Extracting assets with " + str(numCores) + " CPU cores.")
with Pool(numCores, initializer=initializeWorker, initargs=(args.force, abort, args.unaccounted)) as p:
p.map(ExtractFunc, xmlFiles)
if abort.is_set():
exit(1)
if __name__ == "__main__":
main()