Merge pull request #120 from compiling/DoorDevUnstable

Extra warnings / checks
This commit is contained in:
aerinon
2021-07-26 13:06:46 -06:00
committed by GitHub
5 changed files with 45 additions and 8 deletions

9
Gui.py
View File

@@ -24,6 +24,13 @@ from source.classes.BabelFish import BabelFish
from source.classes.Empty import Empty from source.classes.Empty import Empty
def check_python_version(fish):
import sys
version = sys.version_info
if version.major < 3 or version.minor < 7:
messagebox.showinfo("Door Shuffle " + ESVersion, fish.translate("cli","cli","old.python.version") % sys.version)
def guiMain(args=None): def guiMain(args=None):
# Save settings to file # Save settings to file
def save_settings(args): def save_settings(args):
@@ -188,6 +195,8 @@ def guiMain(args=None):
# load adjust settings into options # load adjust settings into options
loadadjustargs(self, self.settings) loadadjustargs(self, self.settings)
check_python_version(self.fish)
# run main window # run main window
mainWindow.mainloop() mainWindow.mainloop()

14
Main.py
View File

@@ -30,12 +30,22 @@ from Utils import output_path, parse_player_names
__version__ = '0.5.0.0-u' __version__ = '0.5.0.0-u'
from source.classes.BabelFish import BabelFish
class EnemizerError(RuntimeError): class EnemizerError(RuntimeError):
pass pass
def check_python_version():
import sys
version = sys.version_info
if version.major < 3 or version.minor < 7:
logging.warning(BabelFish().translate("cli","cli","old.python.version"), sys.version)
def main(args, seed=None, fish=None): def main(args, seed=None, fish=None):
check_python_version()
if args.outputpath: if args.outputpath:
os.makedirs(args.outputpath, exist_ok=True) os.makedirs(args.outputpath, exist_ok=True)
output_path.cached_path = args.outputpath output_path.cached_path = args.outputpath
@@ -258,11 +268,11 @@ def main(args, seed=None, fish=None):
rom = JsonRom() if args.jsonout or use_enemizer else LocalRom(args.rom) rom = JsonRom() if args.jsonout or use_enemizer else LocalRom(args.rom)
if use_enemizer and (args.enemizercli or not args.jsonout): 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)): 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) raise RuntimeError("Could not find valid base rom for enemizing at expected path %s." % args.rom)
if os.path.exists(args.enemizercli): 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 enemized = True
if not args.jsonout: if not args.jsonout:
rom = LocalRom.fromJsonRom(rom, args.rom, 0x400000) rom = LocalRom.fromJsonRom(rom, args.rom, 0x400000)

25
Rom.py
View File

@@ -86,10 +86,12 @@ class LocalRom(object):
self.name = name self.name = name
self.hash = hash self.hash = hash
self.orig_buffer = None self.orig_buffer = None
self.file = file
self.has_smc_header = False
if not os.path.isfile(file): if not os.path.isfile(file):
raise RuntimeError("Could not find valid local base rom for patching at expected path %s." % file) raise RuntimeError("Could not find valid local base rom for patching at expected path %s." % file)
with open(file, 'rb') as stream: with open(file, 'rb') as stream:
self.buffer = read_rom(stream) self.buffer, self.has_smc_header = read_rom(stream)
if patch: if patch:
self.patch_base_rom() self.patch_base_rom()
self.orig_buffer = self.buffer.copy() self.orig_buffer = self.buffer.copy()
@@ -187,12 +189,21 @@ def write_int32s(rom, startaddress, values):
def read_rom(stream): def read_rom(stream):
"Reads rom into bytearray and strips off any smc header" "Reads rom into bytearray and strips off any smc header"
buffer = bytearray(stream.read()) buffer = bytearray(stream.read())
has_smc_header = False
if len(buffer)%0x400 == 0x200: if len(buffer)%0x400 == 0x200:
buffer = buffer[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): def patch_enemizer(world, player, rom, local_rom, enemizercli, random_sprite_on_hit):
baserom_path = os.path.abspath(baserom_path) 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"))) 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") enemizer_basepatch_path = os.path.join(os.path.dirname(enemizercli), "enemizerBasePatch.json")
randopatch_path = os.path.abspath(output_path('enemizer_randopatch.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(0x307000 + (i * 0x8000), sprite.palette)
rom.write_bytes(0x307078 + (i * 0x8000), sprite.glove_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: try:
os.remove(randopatch_path) os.remove(randopatch_path)
except OSError: except OSError:

View File

@@ -1149,7 +1149,7 @@ def standard_rules(world, player):
set_rule(entrance, lambda state: state.has('Zelda Delivered', 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)) set_rule(world.get_entrance('Sanctuary Exit', player), lambda state: state.has('Zelda Delivered', player))
# zelda should be saved before agahnim is in play # 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? # too restrictive for crossed?
def uncle_item_rule(item): def uncle_item_rule(item):

View File

@@ -52,7 +52,8 @@
"enemizer.nothing.applied": "No Enemizer options will be applied until this is resolved.", "enemizer.nothing.applied": "No Enemizer options will be applied until this is resolved.",
"building.collection.spheres": "Building up collection spheres", "building.collection.spheres": "Building up collection spheres",
"building.calculating.spheres": "Calculated sphere %i, containing %i of %i progress items.", "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": { "help": {
"lang": [ "App Language, if available, defaults to English" ], "lang": [ "App Language, if available, defaults to English" ],