Skip to content

Commit

Permalink
Dev (#11)
Browse files Browse the repository at this point in the history
* Create LICENSE.md (#5) (#6)

* refactor (#7)

* Add readmes (#8)

* readmes

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Console app (#10)

* remove debug output

* add help and basic parameter support
  • Loading branch information
avvie authored Jan 28, 2023
1 parent e2da8a0 commit 7122208
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 20 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,26 @@ 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.*

## Contributions
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

Expand Down
4 changes: 0 additions & 4 deletions Randomizer/Generators/PaletteGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions Randomizer/Generators/WeaponGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ 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)
return New_Weapons

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
Expand Down
69 changes: 55 additions & 14 deletions Randomizer/MMRando.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
7 changes: 7 additions & 0 deletions Randomizer/Utilities.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 7122208

Please sign in to comment.