vanilla ROM parsing fix + stuff
parent
43e16025da
commit
bd7e1bc15d
|
@ -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,37 +51,40 @@ 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
|
||||||
connectionType = int.from_bytes(sourceRom.read(1), 'little')
|
while True:
|
||||||
roomNumber = int.from_bytes(sourceRom.read(1), 'little')
|
connectionType = int.from_bytes(sourceRom.read(1), 'little')
|
||||||
sourceRom.seek(4, 1)
|
roomNumber = int.from_bytes(sourceRom.read(1), 'little')
|
||||||
connectedDoor = int.from_bytes(sourceRom.read(1), 'little')
|
sourceRom.seek(4, 1)
|
||||||
sourceRom.seek(5, 1)
|
connectedDoor = int.from_bytes(sourceRom.read(1), 'little')
|
||||||
if connectionType == 0 and connectedDoor == 0:
|
sourceRom.seek(5, 1)
|
||||||
continue
|
if connectionType == 0 and connectedDoor == 0:
|
||||||
sourceNode = 'S{}-{:02X}'.format(currentArea, doorNumber)
|
break
|
||||||
connectedArea = self.areaConnections.get(sourceNode, currentArea)
|
sourceNode = 'S{}-{:02X}'.format(currentArea, doorNumber)
|
||||||
targetNode = 'S{}-{:02X}'.format(connectedArea, connectedDoor)
|
connectedArea = self.areaConnections.get(sourceNode, currentArea)
|
||||||
self.doorConnections.update({
|
targetNode = 'S{}-{:02X}'.format(connectedArea, connectedDoor)
|
||||||
sourceNode: targetNode })
|
self.doorConnections.update({
|
||||||
roomNumber = format(roomNumber, '02X')
|
sourceNode: targetNode })
|
||||||
roomString = 'Room-S{}-{}'.format(currentArea, roomNumber)
|
roomNumber = format(roomNumber, '02X')
|
||||||
doorString = 'S{}-{:02X}'.format(currentArea, doorNumber)
|
roomString = 'Room-S{}-{}'.format(currentArea, roomNumber)
|
||||||
print('DEBUG: Adding door {} to S{}-{:02X}'.format(doorNumber, currentArea, roomNumber))
|
doorString = 'S{}-{:02X}'.format(currentArea, doorNumber)
|
||||||
if roomString in self.rooms:
|
# print('DEBUG: Adding door S{}-{:02X} to S{}-{}'.format(currentArea, doorNumber, currentArea, roomNumber))
|
||||||
self.rooms[roomString].append(doorString)
|
if roomString in self.rooms:
|
||||||
else:
|
self.rooms[roomString].append(doorString)
|
||||||
self.rooms[roomString] = [
|
else:
|
||||||
doorString]
|
self.rooms[roomString] = [
|
||||||
doorNumber += 1
|
doorString]
|
||||||
print('DEBUG: Parsing seemingly done?')
|
doorNumber += 1
|
||||||
|
# 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,21 +153,18 @@ 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:
|
||||||
self.graph[start].append(end)
|
if end not in self.graph[start]:
|
||||||
|
self.graph[start].append(end)
|
||||||
else:
|
else:
|
||||||
self.graph[start] = [
|
self.graph[start] = [
|
||||||
end]
|
end]
|
||||||
|
|
||||||
def add_edges(self, start, *nodes):
|
def add_edges(self, start, *nodes):
|
||||||
for end in nodes:
|
for end in nodes:
|
||||||
|
|
2275
Randomizer.py
2275
Randomizer.py
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue