From c981b362d29ee8f0e01fd8bd918e31d046af3921 Mon Sep 17 00:00:00 2001 From: compiling <8335770+compiling@users.noreply.github.com> Date: Sun, 25 Jul 2021 18:15:11 +1000 Subject: [PATCH 1/4] Add warning for old python versions. --- Gui.py | 9 +++++++++ Main.py | 12 ++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Gui.py b/Gui.py index 4cc5b106..6433c79f 100755 --- a/Gui.py +++ b/Gui.py @@ -24,6 +24,13 @@ from source.classes.BabelFish import BabelFish from source.classes.Empty import Empty +def check_python_version(): + import sys + version = sys.version_info + if version.major < 3 or version.minor < 7: + messagebox.showinfo("Door Shuffle " + ESVersion, 'Door Rando may have issues with python versions earlier than 3.7. Detected version: %s' % sys.version) + + def guiMain(args=None): # Save settings to file def save_settings(args): @@ -188,6 +195,8 @@ def guiMain(args=None): # load adjust settings into options loadadjustargs(self, self.settings) + check_python_version() + # run main window mainWindow.mainloop() diff --git a/Main.py b/Main.py index eb8380f3..5a2e4370 100644 --- a/Main.py +++ b/Main.py @@ -34,7 +34,15 @@ class EnemizerError(RuntimeError): pass +def check_python_version(): + import sys + version = sys.version_info + if version.major < 3 or version.minor < 7: + logging.warning('Door Rando may have issues with python versions earlier than 3.7. Detected version: %s', sys.version) + + def main(args, seed=None, fish=None): + check_python_version() if args.outputpath: os.makedirs(args.outputpath, exist_ok=True) output_path.cached_path = args.outputpath @@ -257,11 +265,11 @@ def main(args, seed=None, fish=None): rom = JsonRom() if args.jsonout or use_enemizer else LocalRom(args.rom) if use_enemizer and (args.enemizercli or not args.jsonout): - base_patch = LocalRom(args.rom) # update base2current.json (side effect) + local_rom = LocalRom(args.rom) # update base2current.json (side effect) if args.rom and not(os.path.isfile(args.rom)): raise RuntimeError("Could not find valid base rom for enemizing at expected path %s." % args.rom) if os.path.exists(args.enemizercli): - patch_enemizer(world, player, rom, args.rom, args.enemizercli, sprite_random_on_hit) + patch_enemizer(world, player, rom, local_rom, args.enemizercli, sprite_random_on_hit) enemized = True if not args.jsonout: rom = LocalRom.fromJsonRom(rom, args.rom, 0x400000) From 4d8bfe0e22791b17aeb7e428e76eac8a35fdc535 Mon Sep 17 00:00:00 2001 From: compiling <8335770+compiling@users.noreply.github.com> Date: Sun, 25 Jul 2021 18:15:51 +1000 Subject: [PATCH 2/4] Check for headered roms before passing to enemizer. --- Rom.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Rom.py b/Rom.py index 5c61e5c2..bde37484 100644 --- a/Rom.py +++ b/Rom.py @@ -86,10 +86,12 @@ class LocalRom(object): self.name = name self.hash = hash self.orig_buffer = None + self.file = file + self.has_smc_header = False if not os.path.isfile(file): raise RuntimeError("Could not find valid local base rom for patching at expected path %s." % file) with open(file, 'rb') as stream: - self.buffer = read_rom(stream) + self.buffer, self.has_smc_header = read_rom(stream) if patch: self.patch_base_rom() self.orig_buffer = self.buffer.copy() @@ -187,12 +189,21 @@ def write_int32s(rom, startaddress, values): def read_rom(stream): "Reads rom into bytearray and strips off any smc header" buffer = bytearray(stream.read()) + has_smc_header = False if len(buffer)%0x400 == 0x200: buffer = buffer[0x200:] - return buffer + has_smc_header = True + return buffer, has_smc_header -def patch_enemizer(world, player, rom, baserom_path, enemizercli, random_sprite_on_hit): - baserom_path = os.path.abspath(baserom_path) +def patch_enemizer(world, player, rom, local_rom, enemizercli, random_sprite_on_hit): + baserom_path = os.path.abspath(local_rom.file) + unheadered_path = None + if local_rom.has_smc_header: + headered_path = baserom_path + unheadered_path = baserom_path = os.path.abspath(output_path('unheadered_rom.sfc')) + with open(headered_path, 'rb') as headered: + with open(baserom_path, 'wb') as unheadered: + unheadered.write(headered.read()[0x200:]) basepatch_path = os.path.abspath(local_path(os.path.join("data","base2current.json"))) enemizer_basepatch_path = os.path.join(os.path.dirname(enemizercli), "enemizerBasePatch.json") randopatch_path = os.path.abspath(output_path('enemizer_randopatch.json')) @@ -336,6 +347,12 @@ def patch_enemizer(world, player, rom, baserom_path, enemizercli, random_sprite_ rom.write_bytes(0x307000 + (i * 0x8000), sprite.palette) rom.write_bytes(0x307078 + (i * 0x8000), sprite.glove_palette) + if local_rom.has_smc_header: + try: + os.remove(unheadered_path) + except OSError: + pass + try: os.remove(randopatch_path) except OSError: From dc950112d9a89e35260920cddc0324112b1a124f Mon Sep 17 00:00:00 2001 From: compiling <8335770+compiling@users.noreply.github.com> Date: Sun, 25 Jul 2021 18:17:10 +1000 Subject: [PATCH 3/4] Fix Aga rule for standard - should be Zelda + normal requirements. --- Rules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rules.py b/Rules.py index 3762b9bb..c9dc03f9 100644 --- a/Rules.py +++ b/Rules.py @@ -1149,7 +1149,7 @@ def standard_rules(world, player): set_rule(entrance, lambda state: state.has('Zelda Delivered', player)) set_rule(world.get_entrance('Sanctuary Exit', player), lambda state: state.has('Zelda Delivered', player)) # zelda should be saved before agahnim is in play - set_rule(world.get_location('Agahnim 1', player), lambda state: state.has('Zelda Delivered', player)) + add_rule(world.get_location('Agahnim 1', player), lambda state: state.has('Zelda Delivered', player)) # too restrictive for crossed? def uncle_item_rule(item): From 4d90ca9181267828dbe003686525e798bd126372 Mon Sep 17 00:00:00 2001 From: compiling <8335770+compiling@users.noreply.github.com> Date: Sun, 25 Jul 2021 19:48:07 +1000 Subject: [PATCH 4/4] Add python version warning to the translation file. --- Gui.py | 6 +++--- Main.py | 4 +++- resources/app/cli/lang/en.json | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Gui.py b/Gui.py index 6433c79f..55defa7a 100755 --- a/Gui.py +++ b/Gui.py @@ -24,11 +24,11 @@ from source.classes.BabelFish import BabelFish from source.classes.Empty import Empty -def check_python_version(): +def check_python_version(fish): import sys version = sys.version_info if version.major < 3 or version.minor < 7: - messagebox.showinfo("Door Shuffle " + ESVersion, 'Door Rando may have issues with python versions earlier than 3.7. Detected version: %s' % sys.version) + messagebox.showinfo("Door Shuffle " + ESVersion, fish.translate("cli","cli","old.python.version") % sys.version) def guiMain(args=None): @@ -195,7 +195,7 @@ def guiMain(args=None): # load adjust settings into options loadadjustargs(self, self.settings) - check_python_version() + check_python_version(self.fish) # run main window mainWindow.mainloop() diff --git a/Main.py b/Main.py index 5a2e4370..665196fc 100644 --- a/Main.py +++ b/Main.py @@ -29,6 +29,8 @@ from Utils import output_path, parse_player_names __version__ = '0.4.0.11u' +from source.classes.BabelFish import BabelFish + class EnemizerError(RuntimeError): pass @@ -38,7 +40,7 @@ def check_python_version(): import sys version = sys.version_info if version.major < 3 or version.minor < 7: - logging.warning('Door Rando may have issues with python versions earlier than 3.7. Detected version: %s', sys.version) + logging.warning(BabelFish().translate("cli","cli","old.python.version"), sys.version) def main(args, seed=None, fish=None): diff --git a/resources/app/cli/lang/en.json b/resources/app/cli/lang/en.json index 0ff910a9..d2be5eb0 100644 --- a/resources/app/cli/lang/en.json +++ b/resources/app/cli/lang/en.json @@ -52,7 +52,8 @@ "enemizer.nothing.applied": "No Enemizer options will be applied until this is resolved.", "building.collection.spheres": "Building up collection spheres", "building.calculating.spheres": "Calculated sphere %i, containing %i of %i progress items.", - "building.final.spheres": "Calculated final sphere %i, containing %i of %i progress items." + "building.final.spheres": "Calculated final sphere %i, containing %i of %i progress items.", + "old.python.version": "Door Rando may have issues with python versions earlier than 3.7. Detected version: %s" }, "help": { "lang": [ "App Language, if available, defaults to English" ],