baserom now derived from bmbp file.

This commit is contained in:
caitsith2 2020-06-09 12:18:48 -07:00
parent 9fcad5b392
commit de9ae7d111
4 changed files with 36 additions and 4 deletions

View File

@ -57,16 +57,19 @@ def create_patch_file(rom_file_to_patch: str, server: str = "") -> str:
write_lzma(bytes, target)
return target
def create_rom_file(patch_file: str) -> Tuple[dict, str]:
def create_rom_bytes(patch_file: str) -> Tuple[dict, str, bytearray]:
data = Utils.parse_yaml(lzma.decompress(load_bytes(patch_file)).decode("utf-8-sig"))
patched_data = bsdiff4.patch(get_base_rom_bytes(), data["patch"])
rom_hash = patched_data[int(0x7FC0):int(0x7FD5)]
data["meta"]["hash"] = "".join(chr(x) for x in rom_hash)
target = os.path.splitext(patch_file)[0] + ".sfc"
return data["meta"], target, patched_data
def create_rom_file(patch_file: str) -> Tuple[dict, str]:
data, target, patched_data = create_rom_bytes(patch_file)
with open(target, "wb") as f:
f.write(patched_data)
return data["meta"], target
return data, target
def update_patch_data(patch_data: bytes, server: str = "") -> bytes:

30
Rom.py
View File

@ -102,6 +102,30 @@ class LocalRom(object):
return ret
def patch_base_rom(self):
from Patch import create_patch_file, create_rom_bytes
if os.path.isfile(local_path('data/baserom.sfc')):
with open(local_path('data/baserom.sfc'), 'rb') as stream:
buffer = bytearray(stream.read())
buffermd5 = hashlib.md5()
buffermd5.update(buffer)
if RANDOMIZERBASEHASH == buffermd5.hexdigest():
self.buffer = buffer
if not os.path.exists(local_path('data/baserom.bmbp')):
create_patch_file(local_path('data/baserom.sfc'))
return
if os.path.isfile(local_path('data/baserom.bmbp')):
_, target, buffer = create_rom_bytes(local_path('data/baserom.bmbp'))
buffermd5 = hashlib.md5()
buffermd5.update(buffer)
if RANDOMIZERBASEHASH == buffermd5.hexdigest():
self.buffer = bytearray(buffer)
with open(local_path('data/baserom.sfc'), 'wb') as stream:
stream.write(buffer)
return
# verify correct checksum of baserom
basemd5 = hashlib.md5()
basemd5.update(self.buffer)
@ -124,6 +148,12 @@ class LocalRom(object):
patchedmd5.update(self.buffer)
if patchedmd5.hexdigest() not in [RANDOMIZERBASEHASH]:
raise RuntimeError('Provided Base Rom unsuitable for patching. Please provide a JAP(1.0) "Zelda no Densetsu - Kamigami no Triforce (Japan).sfc" rom to use as a base.')
else:
with open(local_path('data/baserom.sfc'), 'wb') as stream:
stream.write(self.buffer)
create_patch_file(local_path('data/baserom.sfc'))
os.remove(local_path('data/base2current.json'))
def write_crc(self):
crc = (sum(self.buffer[:0x7FDC] + self.buffer[0x7FE0:]) + 0x01FE) & 0xFFFF

File diff suppressed because one or more lines are too long

BIN
data/baserom.bmbp Normal file

Binary file not shown.