From e6d23b8700aee973fe9ebcf7fd9950845e519b59 Mon Sep 17 00:00:00 2001 From: Kevin Cathcart Date: Mon, 1 Jan 2018 14:42:23 -0500 Subject: [PATCH] Add some useful developer commands to Utils.py These can be used in the interactive python shell by importing Utils.py --- Utils.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Utils.py b/Utils.py index 25489600..60ae3abd 100644 --- a/Utils.py +++ b/Utils.py @@ -72,3 +72,37 @@ def close_console(): ctypes.windll.kernel32.FreeConsole() except Exception: pass + +def new_logic_array(): + import random + l = list(range(256)) + random.SystemRandom().shuffle(l) + chunks = [l[i:i + 16] for i in range(0, len(l), 16)] + lines = [", ".join([str(j) for j in i]) for i in chunks] + print("logic_hash = ["+",\n ".join(lines)+"]") + +def make_new_base2current(old_rom='Zelda no Densetsu - Kamigami no Triforce (Japan).sfc', new_rom='working.sfc'): + from collections import OrderedDict + import json + import hashlib + with open(old_rom, 'rb') as stream: + old_rom_data = bytearray(stream.read()) + with open(new_rom, 'rb') as stream: + new_rom_data = bytearray(stream.read()) + # extend to 2 mb + old_rom_data.extend(bytearray([0x00] * (2097152 - len(old_rom_data)))) + + out_data = OrderedDict() + for idx, old in enumerate(old_rom_data): + new = new_rom_data[idx] + if old != new: + out_data[idx] = [int(new)] + for offset in reversed(list(out_data.keys())): + if offset - 1 in out_data: + out_data[offset-1].extend(out_data.pop(offset)) + with open('data/base2current.json', 'wt') as outfile: + json.dump([{key:value} for key, value in out_data.items()], outfile, separators=(",", ":")) + + basemd5 = hashlib.md5() + basemd5.update(new_rom_data) + return "New Rom Hash: " + basemd5.hexdigest()