OoT Adjuster source code

This commit is contained in:
espeon65536
2021-11-14 16:50:49 -06:00
parent f9e1db41e9
commit a53d4219b3
2 changed files with 231 additions and 13 deletions

View File

@@ -17,7 +17,7 @@ double_cache_prevention = threading.Lock()
class Rom(BigStream):
original = None
def __init__(self, file=None):
def __init__(self, file=None, force_use=False):
super().__init__([])
self.changed_address = {}
@@ -34,22 +34,25 @@ class Rom(BigStream):
self.symbols = {name: int(addr, 16) for name, addr in symbols.items()}
# If decompressed file already exists, read from it
if os.path.exists(decomp_file):
file = decomp_file
if not force_use:
if os.path.exists(decomp_file):
file = decomp_file
if file == '':
# if not specified, try to read from the previously decompressed rom
file = decomp_file
try:
if file == '':
# if not specified, try to read from the previously decompressed rom
file = decomp_file
try:
self.read_rom(file)
except FileNotFoundError:
# could not find the decompressed rom either
raise FileNotFoundError('Must specify path to base ROM')
else:
self.read_rom(file)
except FileNotFoundError:
# could not find the decompressed rom either
raise FileNotFoundError('Must specify path to base ROM')
else:
self.read_rom(file)
# decompress rom, or check if it's already decompressed
self.decompress_rom_file(file, decomp_file)
self.decompress_rom_file(file, decomp_file, force_use)
# Add file to maximum size
self.buffer.extend(bytearray([0x00] * (0x4000000 - len(self.buffer))))
@@ -69,7 +72,7 @@ class Rom(BigStream):
new_rom.force_patch = copy.copy(self.force_patch)
return new_rom
def decompress_rom_file(self, file, decomp_file):
def decompress_rom_file(self, file, decomp_file, skip_crc_check):
validCRC = [
[0xEC, 0x70, 0x11, 0xB7, 0x76, 0x16, 0xD7, 0x2B], # Compressed
[0x70, 0xEC, 0xB7, 0x11, 0x16, 0x76, 0x2B, 0xD7], # Byteswap compressed
@@ -79,7 +82,7 @@ class Rom(BigStream):
# Validate ROM file
file_name = os.path.splitext(file)
romCRC = list(self.buffer[0x10:0x18])
if romCRC not in validCRC:
if romCRC not in validCRC and not skip_crc_check:
# Bad CRC validation
raise RuntimeError('ROM file %s is not a valid OoT 1.0 US ROM.' % file)
elif len(self.buffer) < 0x2000000 or len(self.buffer) > (0x4000000) or file_name[1].lower() not in ['.z64',