diff --git a/README.md b/README.md index 1588b29..2449fb3 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,17 @@ Randomizes what each boss drops at the end of the level the file header removed (this will be improved in at a later time) - Run the app using `python3 MMRando.py` +### Rando current options + +| Command | Description | +| --- | --- | +| -h | Displays the help menu in the app | +| -w | Disables randomization of weapons. Enabled by default | +| -p | Disables randomization of megaman pallete. Enabled by default | +| --- | --- | +| -o | Sets the output file path | +| -i | Sets the input file path | + ## Requirements Python 3.11.* @@ -20,6 +31,8 @@ Python 3.11.* We welcome contributions to the project. If you would like to contribute, please fork the repository and submit a pull request. +Here are some resources if you are interested in contributing. [Disassembly](https://bisqwit.iki.fi/jutut/megamansource/) + ## Authors - [JoJoCrusade](https://github.com/JoJoCrusade) - with whom this would not exit <3 diff --git a/Randomizer/Generators/PaletteGenerator.py b/Randomizer/Generators/PaletteGenerator.py index b3dc938..ea14f79 100644 --- a/Randomizer/Generators/PaletteGenerator.py +++ b/Randomizer/Generators/PaletteGenerator.py @@ -14,13 +14,10 @@ def __init__(self, file, params = None): super().__init__(file, params) def __palletteGenerator(self, color1, color2): - print("palette", color1, color2) palette_offset = color1 - color2 - print("offset", palette_offset) r_high = random.randint(1, 2) r_low = random.randrange(13) - print(r_high, r_low) new_paletteh = (r_high * 16) + r_low new_palettel = new_paletteh - palette_offset @@ -54,7 +51,6 @@ def __Write(self): Generated_Palettes = self.__palletteGenerator(self.primaryPal_Megaman[x],self.primaryPal_Megaman[(x+1)]) self.file.write(int.to_bytes(Generated_Palettes[0])) self.file.write(int.to_bytes(Generated_Palettes[1])) - print("Writing Palettes ",Generated_Palettes) x += 2 def Randomize(self): diff --git a/Randomizer/Generators/WeaponGenerator.py b/Randomizer/Generators/WeaponGenerator.py index eaec22e..fa10268 100644 --- a/Randomizer/Generators/WeaponGenerator.py +++ b/Randomizer/Generators/WeaponGenerator.py @@ -16,7 +16,6 @@ def ShuffleWeapons(self): while (len(self.Vanilla_Weapons) > 0): length = len(self.Vanilla_Weapons) r = random.randrange(length) - print("rng",r) newByte = self.Vanilla_Weapons[r] New_Weapons.append(newByte) self.Vanilla_Weapons.pop(r) @@ -24,7 +23,6 @@ def ShuffleWeapons(self): def __Generate(self): self.shuffled_weapons = self.ShuffleWeapons() - print("Randomized Weapons: ",self.shuffled_weapons) def __Write(self): self.file.seek(self.Weapons_Write_Offset) #weapons offset diff --git a/Randomizer/MMRando.py b/Randomizer/MMRando.py index 6b8ecdb..e55ce7d 100644 --- a/Randomizer/MMRando.py +++ b/Randomizer/MMRando.py @@ -1,29 +1,70 @@ +from ast import arg +from genericpath import isfile +from platform import architecture +from typing import final from Generators.PaletteGenerator import PaletteGenerator from Generators.WeaponGenerator import WeaponGenerator -import binascii -import random +from Utilities import * import shutil +import sys +import os.path -filecopy = shutil.copyfile("./Mega Man (USA).nes", "./MMRando.nes") +# Get console arguments passed +args = sys.argv[1:] -file = open("MMRando.nes", "r+b") +input_file = "./Mega Man (USA).nes" +output_file = "./MMRando.nes" + +# Gets the path to a valid file passed in arguments, positionally after param +def GetValidFileFromParameter(paramList, param, default = None): + if param in paramList: + i = paramList.index(param) + if i+1 < len(paramList): + if os.path.exists(paramList[i+1]): + local = paramList[i+1] + paramList.remove(local) + paramList.remove(param) + print("return value:"+ local) + return local + return default + +def ParamExistsInArgs(paramList, param): + if param in paramList: + return True + return False + +if ParamExistsInArgs(args, '-h'): + PrintHelp() + sys.exit(0) + +# Get input file path passed into the app, or default +input_file = GetValidFileFromParameter(args, '-i', input_file) +# Get output file path passed into the app, or default +output_file = GetValidFileFromParameter(args, '-o', output_file) #please name this more concretely Megaman_Default = [0x2c, 0x11] -##Byte writing testing -filecopy = shutil.copyfile("./Mega Man (USA).nes", "./MMRando.nes") - -file = open("MMRando.nes", "r+b") +try: + # Make a copy of the original input file + filecopy = shutil.copyfile(input_file, output_file) -GeneratorList = [] -GeneratorList.append(WeaponGenerator(file)) -GeneratorList.append(PaletteGenerator(file, Megaman_Default)) + file = open("MMRando.nes", "r+b") -for generator in GeneratorList: - generator.Randomize() + GeneratorList = [] + if not ParamExistsInArgs(args, '-w'): + GeneratorList.append(WeaponGenerator(file)) + if not ParamExistsInArgs(args, '-p'): + GeneratorList.append(PaletteGenerator(file, Megaman_Default)) + + for generator in GeneratorList: + generator.Randomize() + +except Exception as e: + print(e.with_traceback()) +finally: + file.close() -file.close() #add header for proper booting header = bytes(b'\x4E\x45\x53\x1A\x08\x00\x21\x08\x20\x00\x00\x07\x00\x00\x00\x01') diff --git a/Randomizer/Utilities.py b/Randomizer/Utilities.py new file mode 100644 index 0000000..2f3c374 --- /dev/null +++ b/Randomizer/Utilities.py @@ -0,0 +1,7 @@ +def PrintHelp(): + print ("Help menu for MegamanRandomizer:\n\n" + + "-i [filePath]:\t Set a specific input file path. Default: ./Mega Man (USA).nes\n" + + "-o [filePath]:\t Set a specific output file path. Default: ./MMRando.nes\n" + + "\nRandomizer Options:\n" + + "-w:\t Do NOT randomize weapon drops. Default: Weapons WILL get randomized\n" + + "-p:\t Do NOT randomize pallete drops. Default: Palletes WILL get randomized\n") \ No newline at end of file