all repos — m12-patcher @ 95fbc6f39894be2461591d9423a3260fbec726b2

major improvements
Marco Andronaco andronacomarco@gmail.com
Tue, 05 Jul 2022 18:34:59 +0200
commit

95fbc6f39894be2461591d9423a3260fbec726b2

parent

5ca994a538ae0cd9ced684b344799875cdcc5885

5 files changed, 219 insertions(+), 44 deletions(-)

jump to
M .gitignore.gitignore

@@ -1,4 +1,9 @@

+.vscode +build +dist __pycache__ tools venv *.gba +patcher +patcher.spec
A Constants.py

@@ -0,0 +1,139 @@

+#!/usr/bin/python3 +PATCH_VERSION = '1.1.1' +FINAL_ROM_NAME = f'Mother 1+2 [T+Ita{patch_version}].gba' + +STATUS_START = "Benvenutə al patcher per Mother 1+2." +STATUS_MD5 = "MD5 verificato." + +VAR_FILEPICKER = "ROM giapponese di Mother 1+2" + +WARNING_TITLE = "Attenzione" +WARNING_EXTRACT = "È necessario estrarre l'archivio." +WARNING_MD5_MISMATCH = "La ROM selezionata non è compatibile con la nostra patch." + + +PRESETS = { + "Scelte consigliate": { + 'font': 1, + 'sprites': 3, + 'places': 6, + 'palette': 8, + 'skip_m1': 1 + }, + "EB Beginnings (US)": { + 'font': 1, + 'sprites': 4, + 'places': 6, + 'palette': 8, + 'skip_m1': 1 + }, + "Mother 1 (JP)": { + 'font': 1, + 'sprites': 5, + 'places': 7, + 'palette': 8, + 'skip_m1': 1 + }, + "Mother 1+2": { + 'font': 1, + 'sprites': 4, + 'places': 7, + 'palette': 9, + 'skip_m1': 0 + } +} + +DEF_FILENAMES = { + 'font': ['m1_gfx_font.bin'], + 'sprites': [ + 'm1_restoration_gfx_sprites.bin', + 'm1_restoration_gfx_ending.bin', + 'm1_restoration_gfx_enemies.bin', + 'm1_restoration_gfx_maptiles.bin' + ], + 'places': [ + 'm1_main_text.txt', + 'm1_gfx_map.bin' + ] +} + +ALT_FILENAMES = { + 100: {'option': '\nFONT'}, + 1: { + 'option': 'Originale (serif)', + 'files': ['m1_gfx_font_og.bin'] + }, + 2: { + 'option': 'Tomato (sans)', + 'files': ['m1_gfx_font_new.bin'] + }, + 101: {'option': '\nSPRITE E TILE'}, + 3: { + 'option': 'Mix', + 'files': [ + 'm1_restoration_gfx_sprites_mix.bin', + 'm1_restoration_gfx_ending_us.bin', + 'm1_restoration_gfx_enemies_jp.bin', + 'm1_restoration_gfx_maptiles_jp.bin' + ] + }, + 4: { + 'option': 'US', + 'files': [ + 'm1_restoration_gfx_sprites_us.bin', + 'm1_restoration_gfx_ending_us.bin', + 'm1_restoration_gfx_enemies_us.bin', + 'm1_restoration_gfx_maptiles_us.bin' + ] + }, + 5: { + 'option': 'JP', + 'files': [ + 'm1_restoration_gfx_sprites_jp.bin', + 'm1_restoration_gfx_ending_jp.bin', + 'm1_restoration_gfx_enemies_jp.bin', + 'm1_restoration_gfx_maptiles_jp.bin' + ] + }, + 102: {'option': '\nLUOGHI'}, + 6: { + 'option': 'US', + 'files': [ + 'm1_main_text_us.txt', + 'm1_gfx_map_us.bin' + ] + }, + 7: { + 'option': 'JP', + 'files': [ + 'm1_main_text_jp.txt', + 'm1_gfx_map_jp.bin' + ] + }, + 103: {'option': '\nPALETTE'}, + 8: { + 'option': 'NES', + 'files': 'nes.ips' + }, + 9: { + 'option': 'GBA', + 'files': None + }, + 10: { + 'option': 'Nintendo Classic Mini - NES', + 'files': 'ncm.ips' + }, + 11: { + 'option': 'Virtual Console Wii e Wii U', + 'files': 'vc.ips' + }, + 104: {'option': '\nSKIP A MOTHER 1?'}, + 12: { + 'option': 'Sì', + 'files': 'skipm1.ips' + }, + 13: { + 'option': 'No', + 'files': None + } +}
A Functions.py

@@ -0,0 +1,15 @@

+#!/usr/bin/python3 +from hashlib import md5 +from tkinter.messagebox import showwarning +import Constants + +def check_rom(filename): + with open(filename, 'rb') as f: + file_hash = md5() + while chunk := f.read(8192): + file_hash.update(chunk) + + return file_hash.hexdigest() == 'f41e36204356974c94fabf7d144dd32a' + +def show_warning(message): + showwarning(title=Constants.WARNING_TITLE, message=message)
M Gui.pyGui.py

@@ -1,44 +1,16 @@

#!/usr/bin/python3 import tkinter as tk from tkinter.filedialog import askopenfilename -import pathlib, pygubu +import pathlib +import pygubu +import Constants +from Functions import check_rom, show_warning PROJECT_PATH = pathlib.Path(__file__).parent PROJECT_UI = PROJECT_PATH / "patcher.ui" - -presets = { - "Scelte consigliate": { - 'font': 1, - 'sprites': 3, - 'places': 6, - 'palette': 8, - 'skip_m1': 1 - }, - "EB Beginnings (US)": { - 'font': 1, - 'sprites': 4, - 'places': 6, - 'palette': 8, - 'skip_m1': 1 - }, - "Mother 1 (JP)": { - 'font': 1, - 'sprites': 5, - 'places': 7, - 'palette': 8, - 'skip_m1': 1 - }, - "Mother 1+2": { - 'font': 1, - 'sprites': 4, - 'places': 7, - 'palette': 9, - 'skip_m1': 0 - } -} class PatcherApp: - def __init__(self, master=None): + def __init__(self, master=None, baserom=None): self.builder = builder = pygubu.Builder() builder.add_resource_path(PROJECT_PATH) builder.add_from_file(PROJECT_UI)

@@ -52,6 +24,8 @@ self.places = None

self.sprites = None self.palette = None self.skip_m1 = None + self.progress = None + self.progress_text = None builder.import_variables( self, [

@@ -62,6 +36,8 @@ "places",

"sprites", "palette", "skip_m1", + "progress", + "progress_text", ], ) self.font.set(1)

@@ -69,27 +45,39 @@ self.sprites.set(3)

self.places.set(6) self.palette.set(8) self.skip_m1.set(1) + self.progress_text.set(Constants.STATUS_START) + + self.apply_button = builder.get_object("apply_button") + + if baserom is not None: + self.browse_path.set(baserom) builder.connect_callbacks(self) + + def set_progress(self, percent, message): + self.progress.set(percent) + self.progress_text.set(message) + + def run(self): self.mainwindow.mainloop() def on_browse_button(self): - fn = askopenfilename(filetypes=[('ROM giapponese di Mother 1+2', '*.gba'), ('Tutti i file', '*')]) + fn = askopenfilename(filetypes=[(Constants.VAR_FILEPICKER, '*.gba')]) self.browse_path.set(fn) def on_change_preset(self, option): - new_vars = presets[option] + new_vars = Constants.PRESETS[option] for key in new_vars.keys(): getattr(self, key).set(new_vars[key]) def on_apply_button(self): - pass - - -if __name__ == "__main__": - root = tk.Tk() - app = PatcherApp(root) - app.run() + self.apply_button['state'] = 'disabled' + + if check_rom(self.browse_path.get()): + self.set_progress(20, Constants.STATUS_MD5) + else: + show_warning(Constants.WARNING_MD5_MISMATCH) + self.apply_button['state'] = 'normal'
M patcher.uipatcher.ui

@@ -283,8 +283,7 @@ <object class="ttk.Button" id="apply_button">

<property name="command" type="command" cbtype="simple">on_apply_button</property> <property name="text" translatable="yes">Applica!</property> <layout manager="grid"> - <property name="column">0</property> - <property name="columnspan">2</property> + <property name="column">1</property> <property name="ipadx">2</property> <property name="ipady">2</property> <property name="padx">5</property>

@@ -292,6 +291,35 @@ <property name="pady">5</property>

<property name="row">4</property> <property name="sticky">ew</property> </layout> + </object> + </child> + <child> + <object class="ttk.Frame" id="frame1"> + <property name="height">200</property> + <property name="width">200</property> + <layout manager="grid"> + <property name="column">0</property> + <property name="row">4</property> + </layout> + <child> + <object class="ttk.Progressbar" id="progress_bar"> + <property name="length">215</property> + <property name="orient">horizontal</property> + <property name="variable">int:progress</property> + <layout manager="pack"> + <property name="side">top</property> + </layout> + </object> + </child> + <child> + <object class="ttk.Label" id="progress_label"> + <property name="text" translatable="yes">Benvenutə al patcher per Mother 1+2.</property> + <property name="textvariable">string:progress_text</property> + <layout manager="pack"> + <property name="side">top</property> + </layout> + </object> + </child> </object> </child> </object>