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

File diff suppressed because it is too large Load Diff