diff --git a/Fusion_Graph.py b/Fusion_Graph.py index 5675570..9e76284 100644 --- a/Fusion_Graph.py +++ b/Fusion_Graph.py @@ -32,6 +32,8 @@ class Game: self.itemLocations.clear() self.patcher.clear() + print('DEBUG: Opening ROM to pick stuff') + try: with open(vanillaGame, 'rb') as sourceRom: sourceRom.seek(3967888, 0) @@ -48,7 +50,6 @@ class Game: sourceDoor = int.from_bytes(sourceRom.read(1), 'little') targetOffset = sourceRom.tell() targetArea = int.from_bytes(sourceRom.read(1), 'little') - continue for currentArea in range(7): sourceRom.seek(7977108 + currentArea * 4, 0) data = sourceRom.read(4) @@ -71,18 +72,17 @@ class Game: roomNumber = format(roomNumber, '02X') roomString = 'Room-S{}-{}'.format(currentArea, roomNumber) doorString = 'S{}-{:02X}'.format(currentArea, doorNumber) + print('DEBUG: Adding door {} to S{}-{:02X}'.format(doorNumber, currentArea, roomNumber)) if roomString in self.rooms: self.rooms[roomString].append(doorString) else: self.rooms[roomString] = [ doorString] doorNumber += 1 - finally: - pass - except FileNotFoundError: - sys.exit('Error:', vanillaGame, 'could not be opened.') + print('DEBUG: Parsing seemingly done?') + except: + sys.exit('Error:', vanillaGame, 'could not be opened.') - return None def set_setting(self, setting, value): @@ -126,19 +126,12 @@ class Game: for end in self.rooms[room]: if start != end: self.add_edges(start, end) - continue - continue - continue - return None def ConnectNodesBetweenRooms(self): for connection in self.doorConnections.items(): if len(connection) == 2: self.add_directed_edge(connection[0], connection[1]) - continue - return None - def UpdateDoorConnection(self, source, destination): self.doorConnections.update({ @@ -172,7 +165,6 @@ class Game: else: self.graph[start] = [ end] - def add_edges(self, start, *nodes): for end in nodes: @@ -193,16 +185,12 @@ class Game: self.itemLocations.append(item) if item not in self.majorItemLocations: self.majorItemLocations.append(item) - continue - return None - def add_to_minors(self, item): if item not in self.itemLocations: self.itemLocations.append(item) if item not in self.minorItemLocations: self.minorItemLocations.append(item) - def add_list_to_minors(self, locations): for item in locations: @@ -210,14 +198,10 @@ class Game: self.itemLocations.append(item) if item not in self.minorItemLocations: self.minorItemLocations.append(item) - continue - return None - def get_requirements(self, start, end): checkRequirement = (start, end) return self.requirements.get(checkRequirement) - def get_path(self, start, end, LimitArea, path, depth = (False, None, 100)): if path == None: @@ -262,7 +246,5 @@ class Game: path = path + [ node] return newpath - continue - return None diff --git a/MFOR.py b/MFOR.py index 5ad8cc7..279b5b2 100644 --- a/MFOR.py +++ b/MFOR.py @@ -20,6 +20,7 @@ parser.add_argument('-num', help='Number of seeds to generate (default 1)') parser.add_argument('-hideitems', default=False, action='store_true', help='All items use ? tank graphics') parser.add_argument('-debug', default=False, action='store_true', help='Debugging, for my own use') args = parser.parse_args() + if not os.path.exists(os.path.join('.', 'data')): os.mkdir('data') if not os.path.exists(os.path.join('.', 'seeds')): diff --git a/Randomizer.py b/Randomizer.py index 6c15e04..527165e 100644 --- a/Randomizer.py +++ b/Randomizer.py @@ -17,6 +17,9 @@ from bps.apply import apply_to_files version = '0.11.6' +# FIXME: Debug should not be set here +Debug = False + def ceiling(num, denom): return -(num // -denom) @@ -4696,8 +4699,6 @@ def patch_game(): if len(x) > 1 and re.search('^[a-zA-Z]', x[1]): sym.update({ x[1]: x[0][2:] }) - finally: - pass os.remove(os.path.join('.', 'data', 'asm', 'temp.sym')) roomEventOffset = int(sym.get('t_bossanddownloadevents'), 16) itemEventOffset = int(sym.get('t_obtainitemevents'), 16) @@ -4841,37 +4842,37 @@ def patch_game(): patchedGame.seek(offset) patchedGame.write(location.encode('ascii')) for x in range(len(location), 35): - patchedGame.write(0.to_bytes(1, 'little')) + patchedGame.write((0).to_bytes(1, 'little')) if SeedSettings['HideItems']: patchedGame.seek(3926048) - patchedGame.write(76.to_bytes(2, 'little')) - patchedGame.write(77.to_bytes(2, 'little')) - patchedGame.write(78.to_bytes(2, 'little')) - patchedGame.write(79.to_bytes(2, 'little')) - patchedGame.write(76.to_bytes(2, 'little')) - patchedGame.write(77.to_bytes(2, 'little')) - patchedGame.write(78.to_bytes(2, 'little')) - patchedGame.write(79.to_bytes(2, 'little')) - patchedGame.write(76.to_bytes(2, 'little')) - patchedGame.write(77.to_bytes(2, 'little')) - patchedGame.write(78.to_bytes(2, 'little')) - patchedGame.write(79.to_bytes(2, 'little')) + patchedGame.write((76).to_bytes(2, 'little')) + patchedGame.write((77).to_bytes(2, 'little')) + patchedGame.write((78).to_bytes(2, 'little')) + patchedGame.write((79).to_bytes(2, 'little')) + patchedGame.write((76).to_bytes(2, 'little')) + patchedGame.write((77).to_bytes(2, 'little')) + patchedGame.write((78).to_bytes(2, 'little')) + patchedGame.write((79).to_bytes(2, 'little')) + patchedGame.write((76).to_bytes(2, 'little')) + patchedGame.write((77).to_bytes(2, 'little')) + patchedGame.write((78).to_bytes(2, 'little')) + patchedGame.write((79).to_bytes(2, 'little')) if SeedSettings['SplitSecurity'] == True: security = securityOffset patchedGame.seek(security) - patchedGame.write(0.to_bytes(2, 'little')) + patchedGame.write((0).to_bytes(2, 'little')) if SeedSettings['MissilesWithoutMainData']: patchedGame.seek(24828) - patchedGame.write(15.to_bytes(1, 'little')) + patchedGame.write((15).to_bytes(1, 'little')) patchedGame.seek(395742) - patchedGame.write(15.to_bytes(1, 'little')) + patchedGame.write((15).to_bytes(1, 'little')) patchedGame.seek(465582) - patchedGame.write(15.to_bytes(1, 'little')) + patchedGame.write((15).to_bytes(1, 'little')) if SeedSettings['PowerBombsWithoutBombs']: patchedGame.seek(24756) - patchedGame.write(32.to_bytes(1, 'little')) + patchedGame.write((32).to_bytes(1, 'little')) patchedGame.seek(465672) - patchedGame.write(32.to_bytes(1, 'little')) + patchedGame.write((32).to_bytes(1, 'little')) if SeedSettings['SectorShuffle'] == True: for currentArea in range(7): patchedGame.seek(7977108 + currentArea * 4, 0) @@ -4910,8 +4911,7 @@ def patch_game(): value = World.patcher.get(target) patchedGame.seek(target) patchedGame.write(value.to_bytes(1, 'little')) - finally: - pass + if Patch: # FIXME: replace with internal patch creator os.system('.\\flips\\flips.exe --create --bps "{}" ".\\seeds\\{}.gba"'.format(BaseGame, FileName)) @@ -4998,8 +4998,6 @@ def patch_game(): 'Items': itemDict }) with open(os.path.join('.', 'spoilers', '{}.json'.format(FileName)), 'w') as spoiler: json.dump(spoilerLog, spoiler, indent=4) - finally: - pass return None @@ -5008,8 +5006,6 @@ def initialize(): HashList = list() with open(os.path.join('.', 'data', 'SeedHash.json')) as jsonFile: HashList = json.load(jsonFile) - finally: - pass HashList.sort() AreaOpen = list() for area in range(0, 7): @@ -5113,6 +5109,7 @@ def start_randomizer(rom, settings): Difficulty = SeedSettings['Difficulty'] DamageRuns = SeedSettings['DamageRuns'] random.seed(SeedValue + str(SeedSettings)) + print('DEBUG: Calling Graph creation') World = Graph.Game(BaseGame) World.RemoveNodeFromRoom('Room-S2-07', 'S2-10') World.RemoveNodeFromRoom('Room-S2-0D', 'S2-1E') @@ -5140,8 +5137,6 @@ def start_randomizer(rom, settings): AreaItemLocations.append(list()) with open(os.path.join('.', 'data', 'NodeData.json')) as jsonFile: RoomNodes = json.load(jsonFile) - finally: - pass for area in RoomNodes: areaIndex = list(RoomNodes.keys()).index(area) for node in RoomNodes[area]: