From 2526319ea02e03bb46b9e9724fbcda097fda1ef5 Mon Sep 17 00:00:00 2001 From: Coxla Date: Tue, 2 Nov 2021 19:08:54 +0100 Subject: [PATCH] Retroarch support, and handling MSU without a .msu --- gui.py | 18 ++++++++++++++++- setup.py | 2 +- utils.py | 60 +++++++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 67 insertions(+), 13 deletions(-) diff --git a/gui.py b/gui.py index ad23902..ad8e6dd 100644 --- a/gui.py +++ b/gui.py @@ -4,8 +4,9 @@ # import sprites # TODO : debug print picked options when this will be back -# TODO : fix (?) check process tracker : I can't because that would mean checking if msedge is running, which might be the case # TODO : sprites +# TODO : text len if SNES bug +# TODO : exclude everything that is not a folder when scanning MSU dir (maybe) window = tk.Tk() @@ -116,6 +117,7 @@ btn_dict['emulator'] = tk.Button(frm_dict['copy'], text='...', width=BTN_WIDTH, command=lambda: utils.set_path(var_dict['emulator'], input_dict['emulator'], 'file')) btn_dict['emulator'].grid(row=m, column=2) + m += 1 # MSU @@ -130,6 +132,20 @@ btn_dict['msupath'] = tk.Button(frm_dict['copy'], text='...', width=BTN_WIDTH, command=lambda: utils.set_path(var_dict['msupath'], input_dict['msupath'], 'dir')) btn_dict['msupath'].grid(row=m, column=2) +m += 1 + +# RetroArch core +lbl_dict['retroarchcore'] = tk.Label(frm_dict['copy'], text='RetroArch Core', width=LBL_WIDTH, anchor=tk.W) +lbl_dict['retroarchcore'].grid(row=m, column=0) + +var_dict['retroarchcore'] = tk.StringVar() +input_dict['retroarchcore'] = tk.Entry(frm_dict['copy'], width=ENTRY_WIDTH, exportselection=0, textvariable=var_dict['retroarchcore']) +input_dict['retroarchcore'].grid(row=m, column=1) +default_dict['retroarchcore'] = 'Optional' + +btn_dict['retroarchcore'] = tk.Button(frm_dict['copy'], text='...', width=BTN_WIDTH, command=lambda: utils.set_path(var_dict['retroarchcore'], input_dict['retroarchcore'], 'file')) +btn_dict['retroarchcore'].grid(row=m, column=2) + n += 1 ## Misc diff --git a/setup.py b/setup.py index d8effb0..b34aa66 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ # base = 'Win32GUI' setup( name = 'ALTTPR Helper', - version = '2.1.1', + version = '2.2', description = 'Helper to rename seed according to MSU and to start side programs', options = {'build_exe': build_exe_options}, executables = [Executable('gui.py', base=base, icon='data/icon.ico', target_name='Helper')]) \ No newline at end of file diff --git a/utils.py b/utils.py index 977e413..cabd5de 100644 --- a/utils.py +++ b/utils.py @@ -150,7 +150,6 @@ def run(vars, input_fxpakfolders, default, log): hash = seed_hash(vars['seed']) print(f'Seed hash: {hash}') settings = seed_settings(hash) - # settings = asyncio.run(seed_settings(hash)) if settings: print('Found settings:') for x in settings['meta']: @@ -179,7 +178,7 @@ def run(vars, input_fxpakfolders, default, log): else: # Copy destination_folder = vars['msupath'].get() - filename = 'seed.sfc' + filename = 'seed' else: if vars['mode'].get() == 0: # Transfer @@ -189,14 +188,21 @@ def run(vars, input_fxpakfolders, default, log): destination_folder = '{:}{:}{:}'.format(vars['msupath'].get(), os.sep, msu) filename = '' for f in os.listdir(destination_folder)[::-1]: - if f[-4:] == '.msu': - filename = f[:-4] + '.sfc' + if f[-4:] == '.pcm': + i = f[::-1].index('-') + filename = f[::-1][i+1:][::-1] break if filename == '': - log.config(text='Could not find .msu file in the pack directory') + log.config(text='No file found in the MSU directory') return -1 + open(f'{destination_folder}{os.sep}{filename}.msu', 'w').close() + + if 'retroarch.exe' in vars['emulator'].get(): + create_manifest(filename, destination_folder) + + print(f'MSU: {msu}') print('Transfer type: {:}'.format('Copy' if vars['mode'].get() else 'USB')) @@ -204,20 +210,27 @@ def run(vars, input_fxpakfolders, default, log): print(f'Filename: {filename}') if vars['mode'].get() == 0: # Transfer - transfer.send_rom(vars['seed'].get(), vars['uri'].get(), f'{destination_folder}/{filename}') + transfer.send_rom(vars['seed'].get(), vars['uri'].get(), f'{destination_folder}/{filename}.sfc') else: # Copy - shutil.copy(vars['seed'].get(), f'{destination_folder}{os.sep}{filename}') + shutil.copy(vars['seed'].get(), f'{destination_folder}{os.sep}{filename}.sfc') except: - log.config(text='An error occured while writing the ROM, if using USB transfer consider turning SNES OFF/ON and detect FXPak one more time') + log.config(text='Could not write ROM, if using USB transfer try rebooting SNES and detect FXPak again') # Boot ROM if vars['autostart']['boot'].get() and vars['seed'].get(): if vars['mode'].get() == 0: # Transfer - transfer.boot_rom(vars['uri'].get(), f'{destination_folder}/{filename}') + transfer.boot_rom(vars['uri'].get(), f'{destination_folder}/{filename}.sfc') elif vars['emulator'].get() != default['emulator']: # Copy - thread_emu = thread('"{:}" "{:}"'.format(vars['emulator'].get(), f'{destination_folder}{os.sep}{filename}')) + if 'retroarch.exe' in vars['emulator'].get(): + if vars['retroarchcore'].get() != default['retroarchcore']: + thread_emu = thread('"{:}" -L "{:}" "{:}"'.format(vars['emulator'].get(), vars['retroarchcore'].get(), f'{destination_folder}{os.sep}{filename}.bml')) + else: + thread_emu = thread('"{:}"'.format(vars['emulator'].get())) + else: + thread_emu = thread('"{:}" "{:}"'.format(vars['emulator'].get(), f'{destination_folder}{os.sep}{filename}.sfc')) + thread_emu.start() # Timer @@ -551,4 +564,29 @@ def set_default_text(entry, text): if entry.get() == '': entry.insert(0, text) if entry.get() == text: - entry.config(fg = 'grey') \ No newline at end of file + entry.config(fg = 'grey') + +def create_manifest(name, path): + f = open(f'{path}{os.sep}{name}.bml', 'w') + + f.write('cartridge region=NTSC\n') + f.write(f' rom name={name}.sfc size=0x200000\n') + f.write(f' ram name={name}.srm size=0x8000\n') + f.write(' map id=rom address=00-ff:8000-ffff mask=0x8000\n') + f.write(' map id=rom address=40-6f,c0-ef:0000-7fff mask=0x8000\n') + f.write(' map id=ram address=70-7d,f0-ff:0000-ffff\n\n') + + f.write(' msu1\n') + f.write(f' rom name={name}.name size=0x0000\n') + f.write(f' map id=io address=00-3f,80-bf:2000-2007\n') + + for x in range(1,62): + f.write(f' track number={x} name={name}-{x}.pcm\n') + + f.write('\ninformation\n') + f.write(' title: A Link to the Past Randomizer v31\n') + f.write(' configuration\n') + f.write(f' rom name={name}.sfc size=0x200000\n') + f.write(f' ram name={name}.srm size=0x2000') + + f.close() \ No newline at end of file