1
0
mirror of https://github.com/blawar/ooot.git synced 2024-06-30 16:29:55 +00:00

started to refactor setup rom hashing

This commit is contained in:
Blake Warner 2022-04-09 13:19:36 -04:00
parent 4488b9915e
commit 48a5ad5bfa
4 changed files with 3554 additions and 3205 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

155
setup.py
View File

@ -11,96 +11,101 @@ from tools.oot import *
def clean(): def clean():
# Clean build environment # Clean build environment
print("Cleaning build environment") print("Cleaning build environment")
# Build list of paths (files and folders) to delete # Build list of paths (files and folders) to delete
paths = [] paths = []
# Assets # Assets
paths.append(Path('assets/')) paths.append(Path('assets/'))
paths.append(Path('build/')) paths.append(Path('build/'))
# GlideN64 # GlideN64
paths.append(Path('GLideN64/projects/msvc/build')) paths.append(Path('GLideN64/projects/msvc/build'))
paths.extend(Path('external/Win32/').glob('*GLide*')) paths.extend(Path('external/Win32/').glob('*GLide*'))
paths.extend(Path('external/Win32/').glob('osal*')) paths.extend(Path('external/Win32/').glob('osal*'))
# ooot # ooot
paths.append(Path('vs/Debug/')) paths.append(Path('vs/Debug/'))
# Delete files and folders # Delete files and folders
for path in paths: for path in paths:
if path.exists() == False: if path.exists() == False:
continue continue
elif path.is_dir(): elif path.is_dir():
shutil.rmtree(path) shutil.rmtree(path)
else: else:
os.remove(path) os.remove(path)
def build(): def build():
print("Starting asset extraction and parsing") print("Starting asset extraction and parsing")
# sys.executable points to python executable # sys.executable points to python executable
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'tqdm']) subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'tqdm'])
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'libyaz0']) subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'libyaz0'])
subprocess.check_call([sys.executable, str('tools/fixbaserom.py'), buildRom()]) subprocess.check_call([sys.executable, str('tools/fixbaserom.py'), buildRom()])
subprocess.check_call([sys.executable, str('tools/extract_baserom.py'), buildRom()]) subprocess.check_call([sys.executable, str('tools/extract_baserom.py'), buildRom()])
subprocess.check_call([sys.executable, str('tools/extract_assets.py'), buildRom()]) subprocess.check_call([sys.executable, str('tools/extract_assets.py'), buildRom()])
subprocess.check_call([sys.executable, str('tools/extract_z64_variables.py'), buildRom()]) subprocess.check_call([sys.executable, str('tools/extract_z64_variables.py'), buildRom()])
subprocess.check_call([sys.executable, str('tools/convert_assets.py'), buildRom()]) subprocess.check_call([sys.executable, str('tools/convert_assets.py'), buildRom()])
mkdir(assetPath('text')) mkdir(assetPath('text'))
subprocess.check_call([sys.executable, str('tools/msgenc.py'), str(romPath('text/charmap.txt')), str(assetPath('text/message_data.h')), str(assetPath('text/message_data.enc.h')), buildRom()]) subprocess.check_call([sys.executable, str('tools/msgenc.py'), str(romPath('text/charmap.txt')), str(assetPath('text/message_data.h')), str(assetPath('text/message_data.enc.h')), buildRom()])
subprocess.check_call([sys.executable, str('tools/msgenc.py'), str(romPath('text/charmap.txt')), str(assetPath('text/message_data_staff.h')), str(assetPath('text/message_data_staff.enc.h')), buildRom()]) subprocess.check_call([sys.executable, str('tools/msgenc.py'), str(romPath('text/charmap.txt')), str(assetPath('text/message_data_staff.h')), str(assetPath('text/message_data_staff.enc.h')), buildRom()])
subprocess.check_call([sys.executable, str('tools/extract_missing_assets.py'), buildRom()]) subprocess.check_call([sys.executable, str('tools/extract_missing_assets.py'), buildRom()])
subprocess.check_call([sys.executable, str('tools/create_luts.py'), buildRom()]) subprocess.check_call([sys.executable, str('tools/create_luts.py'), buildRom()])
subprocess.check_call([sys.executable, str('tools/fix_mtx.py'), buildRom()]) subprocess.check_call([sys.executable, str('tools/fix_mtx.py'), buildRom()])
print("Finished asset extraction and parsing") print("Finished asset extraction and parsing")
def main(): def main():
# Command Line Interface # Command Line Interface
parser = argparse.ArgumentParser(description="Setup") parser = argparse.ArgumentParser(description="Setup")
parser.add_argument("-c", "--clean", help="Cleans environment before asset extraction", action="store_true", default=False) parser.add_argument("-c", "--clean", help="Cleans environment before asset extraction", action="store_true", default=False)
parser.add_argument("-p", "--props-only", help="Only sets project properties / options (does not extract assets)", action="store_true", default=False) parser.add_argument("-p", "--props-only", help="Only sets project properties / options (does not extract assets)", action="store_true", default=False)
parser.add_argument("-co", "--clean-only", help="Cleans environment without asset extraction", action="store_true", default=False) parser.add_argument("-co", "--clean-only", help="Cleans environment without asset extraction", action="store_true", default=False)
parser.add_argument("-b", "--buildRom", choices=validBuildOptions(), help="build rom config ex: EUR_MQD") parser.add_argument("-b", "--buildRom", choices=validBuildOptions(), help="build rom config ex: EUR_MQD")
parser.add_argument("-f", "--framerate", choices=['20', '30', '60', '120', '240'], help="game framerate", default='20') parser.add_argument("-f", "--framerate", choices=['20', '30', '60', '120', '240'], help="game framerate", default='20')
parser.add_argument("-m", "--enable-mouse", help="Enables mouse controls", action="store_true", default=True) parser.add_argument("-m", "--enable-mouse", help="Enables mouse controls", action="store_true", default=True)
parser.add_argument("--refresh-configs", help="Refreshes rom config files (do not use)", action="store_true", default=False)
args = parser.parse_args() args = parser.parse_args()
if args.refresh_configs:
calcRomHashes()
exit(0)
if args.buildRom: if args.buildRom:
setBuildRom(args.buildRom) setBuildRom(args.buildRom)
else: else:
setBuildRom(findBuildRom()) setBuildRom(findBuildRom())
with open('vs/oot.props.src', 'r') as f: with open('vs/oot.props.src', 'r') as f:
buffer = f.read() buffer = f.read()
buffer = buffer.replace('#BUILD_ROM#', buildRom()) buffer = buffer.replace('#BUILD_ROM#', buildRom())
defines = [] defines = []
defines.append('ENABLE_%sFPS' % args.framerate) defines.append('ENABLE_%sFPS' % args.framerate)
if args.enable_mouse: if args.enable_mouse:
defines.append('ENABLE_MOUSE') defines.append('ENABLE_MOUSE')
if buildRom().lower()[-1] != 'd': if buildRom().lower()[-1] != 'd':
defines.append('RETAIL') defines.append('RETAIL')
defines.append(re.sub(r'[^A-Z0-9_]+', '', buildRom())) defines.append(re.sub(r'[^A-Z0-9_]+', '', buildRom()))
defines.append('NATIVE') defines.append('NATIVE')
#buffer = re.sub(r'<PreprocessorDefinitions>.*</PreprocessorDefinitions>', r'<PreprocessorDefinitions>%s</PreprocessorDefinitions>' % ';'.join(defines), buffer) #buffer = re.sub(r'<PreprocessorDefinitions>.*</PreprocessorDefinitions>', r'<PreprocessorDefinitions>%s</PreprocessorDefinitions>' % ';'.join(defines), buffer)
buffer = buffer.replace('#DEFINES#', ';'.join(defines)) buffer = buffer.replace('#DEFINES#', ';'.join(defines))
with open('vs/oot.props', 'w') as f: with open('vs/oot.props', 'w') as f:
f.write(buffer) f.write(buffer)
if not args.props_only: if not args.props_only:
if args.clean == True: if args.clean == True:
clean() clean()
build() build()
elif args.clean_only == True: elif args.clean_only == True:
clean() clean()
else: else:
build() build()
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -2,12 +2,28 @@ import sys
import os import os
import os.path import os.path
import json import json
import math
import hashlib
from pathlib import Path from pathlib import Path
_assetPath = None _assetPath = None
_buildRom = None _buildRom = None
_conf = None _conf = None
def loadJson(path):
try:
with open(path, 'r') as f:
return json.load(f)
except:
raise
def saveJson(path, data):
try:
with open(path, 'w') as f:
json.dump(data, f, indent=4, sort_keys=True)
except:
raise
class ConfSection: class ConfSection:
def __init__(self, j): def __init__(self, j):
self.offset = 0 self.offset = 0
@ -42,9 +58,8 @@ class Conf:
def __init__(self, path): def __init__(self, path):
self.path = path self.path = path
self.sections = ConfSections() self.sections = ConfSections()
j = loadJson(path)
with open(path, 'r') as f:
j = json.load(f)
for k,v in j['sections'].items(): for k,v in j['sections'].items():
self.sections.__dict__[k] = ConfSection(v) self.sections.__dict__[k] = ConfSection(v)
self.rom = ConfRom(j['rom']) self.rom = ConfRom(j['rom'])
@ -89,8 +104,10 @@ def buildRom():
_buildRom = sys.argv[1] _buildRom = sys.argv[1]
return _buildRom return _buildRom
def romPath(rom = ''): def romPath(rom = '', root = None):
return fixSlashPath('roms/%s/%s' % (buildRom(), rom)) if not root:
root = buildRom()
return fixSlashPath('roms/%s/%s' % (root, rom))
def getAssetPath(): def getAssetPath():
global _assetPath global _assetPath
@ -126,5 +143,44 @@ def relPath(path, sub = None):
if r[0] == '/' or r[0] == '\\': if r[0] == '/' or r[0] == '\\':
return r[1:] return r[1:]
return r return r
def sha256_buffer(buffer):
m = hashlib.sha256()
m.update(buffer)
return m.hexdigest()
def getRomHashes(path):
chunkSize = 0x100000 # 1MB
headerSize = 0x1000
r = {}
with open(path, 'rb') as f:
buffer = f.read()
r['complete'] = sha256_buffer(buffer)
r['body'] = sha256_buffer(buffer[headerSize:])
r['chunks'] = []
for i in range(int(math.ceil((len(buffer) - headerSize) / chunkSize))):
offset = headerSize + (i * chunkSize)
r['chunks'].append(sha256_buffer(buffer[offset:offset + chunkSize]))
return r
def calcRomHashes():
for rom in validBuildOptions():
verified = romPath('verified', rom)
configPath = romPath('config.json', rom)
config = loadJson(configPath)
config['sha256'] = []
if not os.path.isdir(verified):
continue
for path in Path(verified).rglob('*.z64'):
config['sha256'].append(getRomHashes(path))
saveJson(configPath, config)
basedir = Path(__file__).absolute().parent.parent basedir = Path(__file__).absolute().parent.parent