import struct
f = open('dump/layouts_47808388.bin', 'r')
def main():
seed = ReadUInt32()
print('--------')
print(SeedToString(seed))
print('--------\n')
# Stages
for i in xrange(0, 14):
stageId = ReadInt8()
stageType = ReadInt8()
roomCount = ReadInt8()
gridCount = ReadInt8()
print('Stage: ' + str(stageId) + '.' + str(stageType) + ', gridCount: ' + str(gridCount))
w, h = 13, 13;
grid = [[0 for x in range(w)] for y in range(h)]
for j in xrange(0, gridCount):
room = readRoom()
print(' Room ' + str(j) + ': ' + str(room.Id) + ' @ (' + str(room.X) + ', ' + str(room.Y) + ')')
grid[room.X][room.Y] = room
iAmEror = readRoom(True)
crawlSpace = readRoom(True)
blackMarket = readRoom(True)
if stageId == 6:
bossRush = readRoom(True)
# Keep track of the stage
# TODO
print(' End of stage ' + str(stageId) + '.\n')
def SeedToString(num):
#print('Converting ' + str(num) + ' to a seed string...')
chars = "ABCDEFGHJKLMNPQRSTWXYZ01234V6789"
x = 0
tnum = num;
while tnum != 0:
x = (tnum + x) & 0xFF;
x = ((x >> 7) + (x << 1)) & 0xFF;
tnum >>= 5
num ^= 0x0FEF7FFD
tnum = num << 8 | x
s = ""
for i in xrange(0, 8):
if i >= 0 and i <= 5:
index = num >> (27 - (i * 5)) & 0x1F
elif i == 6:
index = tnum >> 5 & 0x1F
elif i == 7:
index = tnum & 0x1F
s += chars[index]
return s
def readRoom(grid = False):
room = dotdict({})
if grid:
room.Offset = -1
room.X = -1
room.Y = 1
else:
room.Offset = ReadInt8()
room.X = ReadInt8()
room.Y = ReadInt8()
room.StageIndex = ReadInt8()
room.Type = ReadInt8()
room.SubType = ReadInt8()
room.Id = ReadInt16()
return room
def ReadInt8():
#print(f.tell())
return ord(struct.unpack('c', f.read(1))[0])
def ReadInt16():
return struct.unpack('H', f.read(2))[0]
def ReadUInt32():
return struct.unpack('I', f.read(4))[0]
# From: https://stackoverflow.com/questions/2352181/how-to-use-a-dot-to-access-members-of-dictionary
class dotdict(dict):
"""dot.notation access to dictionary attributes"""
__getattr__ = dict.get
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
if __name__ == "__main__":
main()
Comments