store last used adjuster settings and use them for patching
might use them as gui defaults later
This commit is contained in:
parent
f380542bab
commit
56e57de574
11
Adjuster.py
11
Adjuster.py
|
@ -47,17 +47,20 @@ def main():
|
||||||
|
|
||||||
# ToDo: Validate files further than mere existance
|
# ToDo: Validate files further than mere existance
|
||||||
if not os.path.isfile(args.rom):
|
if not os.path.isfile(args.rom):
|
||||||
input('Could not find valid rom for patching at expected path %s. Please run with -h to see help for further information. \nPress Enter to exit.' % args.rom)
|
input(
|
||||||
|
'Could not find valid rom for patching at expected path %s. Please run with -h to see help for further information. \nPress Enter to exit.' % args.rom)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if args.sprite is not None and not os.path.isfile(args.sprite) and not get_sprite_from_name(args.sprite):
|
if args.sprite is not None and not os.path.isfile(args.sprite) and not get_sprite_from_name(args.sprite):
|
||||||
input('Could not find link sprite sheet at given location. \nPress Enter to exit.')
|
input('Could not find link sprite sheet at given location. \nPress Enter to exit.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# set up logger
|
# set up logger
|
||||||
loglevel = {'error': logging.ERROR, 'info': logging.INFO, 'warning': logging.WARNING, 'debug': logging.DEBUG}[args.loglevel]
|
loglevel = {'error': logging.ERROR, 'info': logging.INFO, 'warning': logging.WARNING, 'debug': logging.DEBUG}[
|
||||||
|
args.loglevel]
|
||||||
logging.basicConfig(format='%(message)s', level=loglevel)
|
logging.basicConfig(format='%(message)s', level=loglevel)
|
||||||
|
args, path = adjust(args=args)
|
||||||
adjust(args=args)
|
from Utils import persistent_store
|
||||||
|
persistent_store("adjuster", "last_settings", args)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -17,13 +17,15 @@ def adjust(args):
|
||||||
baserom = LocalRom(args.baserom, patch=True)
|
baserom = LocalRom(args.baserom, patch=True)
|
||||||
rom.orig_buffer = baserom.orig_buffer
|
rom.orig_buffer = baserom.orig_buffer
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('Provided Rom is not a valid Link to the Past Randomizer Rom. Please provide one for adjusting.')
|
raise RuntimeError(
|
||||||
|
'Provided Rom is not a valid Link to the Past Randomizer Rom. Please provide one for adjusting.')
|
||||||
|
|
||||||
apply_rom_settings(rom, args.heartbeep, args.heartcolor, args.quickswap, args.fastmenu, args.disablemusic, args.sprite, args.ow_palettes, args.uw_palettes)
|
apply_rom_settings(rom, args.heartbeep, args.heartcolor, args.quickswap, args.fastmenu, args.disablemusic,
|
||||||
|
args.sprite, args.ow_palettes, args.uw_palettes)
|
||||||
rom.write_to_file(output_path(f'{os.path.basename(args.rom)[:-4]}_adjusted.sfc'))
|
path = output_path(f'{os.path.basename(args.rom)[:-4]}_adjusted.sfc')
|
||||||
|
rom.write_to_file(path)
|
||||||
|
|
||||||
logger.info('Done. Enjoy.')
|
logger.info('Done. Enjoy.')
|
||||||
logger.debug('Total Time: %s', time.perf_counter() - start)
|
logger.debug('Total Time: %s', time.perf_counter() - start)
|
||||||
|
|
||||||
return args
|
return args, path
|
||||||
|
|
6
Gui.py
6
Gui.py
|
@ -623,12 +623,14 @@ def guiMain(args=None):
|
||||||
guiargs.baserom = romVar.get()
|
guiargs.baserom = romVar.get()
|
||||||
guiargs.sprite = sprite
|
guiargs.sprite = sprite
|
||||||
try:
|
try:
|
||||||
adjust(args=guiargs)
|
guiargs, path = adjust(args=guiargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
messagebox.showerror(title="Error while creating seed", message=str(e))
|
messagebox.showerror(title="Error while adjusting Rom", message=str(e))
|
||||||
else:
|
else:
|
||||||
messagebox.showinfo(title="Success", message="Rom patched successfully")
|
messagebox.showinfo(title="Success", message="Rom patched successfully")
|
||||||
|
from Utils import persistent_store
|
||||||
|
persistent_store("adjuster", "last_settings", guiargs)
|
||||||
|
|
||||||
adjustButton = Button(bottomFrame2, text='Adjust Rom', command=adjustRom)
|
adjustButton = Button(bottomFrame2, text='Adjust Rom', command=adjustRom)
|
||||||
|
|
||||||
|
|
|
@ -1089,9 +1089,29 @@ async def main():
|
||||||
|
|
||||||
if args.diff_file:
|
if args.diff_file:
|
||||||
import Patch
|
import Patch
|
||||||
|
logging.info("Patch file was supplied. Creating sfc rom..")
|
||||||
meta, romfile = Patch.create_rom_file(args.diff_file)
|
meta, romfile = Patch.create_rom_file(args.diff_file)
|
||||||
args.connect = meta["server"]
|
args.connect = meta["server"]
|
||||||
logging.info(f"Wrote rom file to {romfile}")
|
logging.info(f"Wrote rom file to {romfile}")
|
||||||
|
adjuster_settings = Utils.persistent_load().get("adjuster", {}).get("last_settings", {})
|
||||||
|
if adjuster_settings:
|
||||||
|
import pprint
|
||||||
|
adjuster_settings.rom = romfile
|
||||||
|
adjuster_settings.baserom = Patch.get_base_rom_path()
|
||||||
|
whitelist = {"disablemusic", "fastmenu", "heartbeep", "heartcolor", "ow_palettes", "quickswap",
|
||||||
|
"uw_palettes"}
|
||||||
|
printed_options = {name: value for name, value in vars(adjuster_settings).items() if name in whitelist}
|
||||||
|
sprite = getattr(adjuster_settings, "sprite", None)
|
||||||
|
if sprite:
|
||||||
|
printed_options["sprite"]: adjuster_settings.sprite.name
|
||||||
|
adjust_wanted = input(f"Last used adjuster settings were found. Would you like to apply these? \n"
|
||||||
|
f"{pprint.pformat(printed_options)}\n"
|
||||||
|
f"Enter yes or no: ")
|
||||||
|
if adjust_wanted and adjust_wanted.startswith("y"):
|
||||||
|
import AdjusterMain
|
||||||
|
_, romfile = AdjusterMain.adjust(adjuster_settings)
|
||||||
|
else:
|
||||||
|
logging.info("Skipping post-patch adjustment")
|
||||||
asyncio.create_task(run_game(romfile))
|
asyncio.create_task(run_game(romfile))
|
||||||
|
|
||||||
ctx = Context(args.snes, args.connect, args.password, args.founditems)
|
ctx = Context(args.snes, args.connect, args.password, args.founditems)
|
||||||
|
|
17
Patch.py
17
Patch.py
|
@ -12,17 +12,19 @@ from typing import Tuple, Optional
|
||||||
import Utils
|
import Utils
|
||||||
from Rom import JAP10HASH, read_rom
|
from Rom import JAP10HASH, read_rom
|
||||||
|
|
||||||
base_rom_bytes = None
|
|
||||||
|
|
||||||
|
def get_base_rom_path(file_name: str = "") -> str:
|
||||||
|
options = Utils.get_options()
|
||||||
|
if not file_name:
|
||||||
|
file_name = options["general_options"]["rom_file"]
|
||||||
|
if not os.path.exists(file_name):
|
||||||
|
file_name = Utils.local_path(file_name)
|
||||||
|
return file_name
|
||||||
|
|
||||||
def get_base_rom_bytes(file_name: str = "") -> bytes:
|
def get_base_rom_bytes(file_name: str = "") -> bytes:
|
||||||
global base_rom_bytes
|
base_rom_bytes = getattr(get_base_rom_bytes, "base_rom_bytes", None)
|
||||||
if not base_rom_bytes:
|
if not base_rom_bytes:
|
||||||
options = Utils.get_options()
|
file_name = get_base_rom_path(file_name)
|
||||||
if not file_name:
|
|
||||||
file_name = options["general_options"]["rom_file"]
|
|
||||||
if not os.path.exists(file_name):
|
|
||||||
file_name = Utils.local_path(file_name)
|
|
||||||
base_rom_bytes = bytes(read_rom(open(file_name, "rb")))
|
base_rom_bytes = bytes(read_rom(open(file_name, "rb")))
|
||||||
|
|
||||||
basemd5 = hashlib.md5()
|
basemd5 = hashlib.md5()
|
||||||
|
@ -30,6 +32,7 @@ def get_base_rom_bytes(file_name: str = "") -> bytes:
|
||||||
if JAP10HASH != basemd5.hexdigest():
|
if JAP10HASH != basemd5.hexdigest():
|
||||||
raise Exception('Supplied Base Rom does not match known MD5 for JAP(1.0) release. '
|
raise Exception('Supplied Base Rom does not match known MD5 for JAP(1.0) release. '
|
||||||
'Get the correct game and version, then dump it')
|
'Get the correct game and version, then dump it')
|
||||||
|
get_base_rom_bytes.base_rom_bytes = base_rom_bytes
|
||||||
return base_rom_bytes
|
return base_rom_bytes
|
||||||
|
|
||||||
|
|
||||||
|
|
2
Utils.py
2
Utils.py
|
@ -221,7 +221,7 @@ def persistent_store(category, key, value):
|
||||||
f.write(dump(storage))
|
f.write(dump(storage))
|
||||||
|
|
||||||
|
|
||||||
def persistent_load():
|
def persistent_load() -> typing.Dict[dict]:
|
||||||
path = local_path("_persistent_storage.yaml")
|
path = local_path("_persistent_storage.yaml")
|
||||||
storage: dict = {}
|
storage: dict = {}
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
|
|
Loading…
Reference in New Issue