vanilla ROM parsing fix + stuff

master
Lucent 2023-10-12 12:56:50 +02:00
parent 43e16025da
commit bd7e1bc15d
2 changed files with 1130 additions and 1219 deletions

View File

@ -32,7 +32,7 @@ class Game:
self.itemLocations.clear() self.itemLocations.clear()
self.patcher.clear() self.patcher.clear()
print('DEBUG: Opening ROM to pick stuff') # print('DEBUG: Opening ROM to pick stuff')
try: try:
with open(vanillaGame, 'rb') as sourceRom: with open(vanillaGame, 'rb') as sourceRom:
@ -51,19 +51,21 @@ class Game:
targetOffset = sourceRom.tell() targetOffset = sourceRom.tell()
targetArea = int.from_bytes(sourceRom.read(1), 'little') targetArea = int.from_bytes(sourceRom.read(1), 'little')
for currentArea in range(7): for currentArea in range(7):
# print('DEBUG: Parsing sector {}'.format(currentArea))
sourceRom.seek(7977108 + currentArea * 4, 0) sourceRom.seek(7977108 + currentArea * 4, 0)
data = sourceRom.read(4) data = sourceRom.read(4)
unpacked = struct.unpack('<L', data) unpacked = struct.unpack('<L', data)
doorData = unpacked[0] - 134217728 doorData = unpacked[0] - 134217728
sourceRom.seek(doorData, 0) sourceRom.seek(doorData, 0)
doorNumber = 0 doorNumber = 0
while True:
connectionType = int.from_bytes(sourceRom.read(1), 'little') connectionType = int.from_bytes(sourceRom.read(1), 'little')
roomNumber = int.from_bytes(sourceRom.read(1), 'little') roomNumber = int.from_bytes(sourceRom.read(1), 'little')
sourceRom.seek(4, 1) sourceRom.seek(4, 1)
connectedDoor = int.from_bytes(sourceRom.read(1), 'little') connectedDoor = int.from_bytes(sourceRom.read(1), 'little')
sourceRom.seek(5, 1) sourceRom.seek(5, 1)
if connectionType == 0 and connectedDoor == 0: if connectionType == 0 and connectedDoor == 0:
continue break
sourceNode = 'S{}-{:02X}'.format(currentArea, doorNumber) sourceNode = 'S{}-{:02X}'.format(currentArea, doorNumber)
connectedArea = self.areaConnections.get(sourceNode, currentArea) connectedArea = self.areaConnections.get(sourceNode, currentArea)
targetNode = 'S{}-{:02X}'.format(connectedArea, connectedDoor) targetNode = 'S{}-{:02X}'.format(connectedArea, connectedDoor)
@ -72,16 +74,17 @@ class Game:
roomNumber = format(roomNumber, '02X') roomNumber = format(roomNumber, '02X')
roomString = 'Room-S{}-{}'.format(currentArea, roomNumber) roomString = 'Room-S{}-{}'.format(currentArea, roomNumber)
doorString = 'S{}-{:02X}'.format(currentArea, doorNumber) doorString = 'S{}-{:02X}'.format(currentArea, doorNumber)
print('DEBUG: Adding door {} to S{}-{:02X}'.format(doorNumber, currentArea, roomNumber)) # print('DEBUG: Adding door S{}-{:02X} to S{}-{}'.format(currentArea, doorNumber, currentArea, roomNumber))
if roomString in self.rooms: if roomString in self.rooms:
self.rooms[roomString].append(doorString) self.rooms[roomString].append(doorString)
else: else:
self.rooms[roomString] = [ self.rooms[roomString] = [
doorString] doorString]
doorNumber += 1 doorNumber += 1
print('DEBUG: Parsing seemingly done?') # print('DEBUG: Parsing seemingly done?')
except: except:
sys.exit('Error:', vanillaGame, 'could not be opened.') print('Error:', vanillaGame, 'could not be opened.')
sys.exit(1)
@ -150,17 +153,14 @@ class Game:
for targetNode in self.rooms[targetRoom]: for targetNode in self.rooms[targetRoom]:
if currentNode != targetNode: if currentNode != targetNode:
self.add_edges(currentNode, targetNode) self.add_edges(currentNode, targetNode)
continue else:
continue
self.rooms[targetRoom] = [ self.rooms[targetRoom] = [
currentNode] currentNode]
continue
return None
def add_directed_edge(self, start, end): def add_directed_edge(self, start, end):
if start != end: if start != end:
if start in self.graph or end not in self.graph[start]: if start in self.graph:
if end not in self.graph[start]:
self.graph[start].append(end) self.graph[start].append(end)
else: else:
self.graph[start] = [ self.graph[start] = [

File diff suppressed because it is too large Load Diff