Zamiel

floor_counter.py

Sep 4th, 2018
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. import struct
  2.  
  3. f = open('dump/layouts_47808388.bin', 'r')
  4.  
  5. def main():
  6. seed = ReadUInt32()
  7. print('--------')
  8. print(SeedToString(seed))
  9. print('--------\n')
  10.  
  11. # Stages
  12. for i in xrange(0, 14):
  13. stageId = ReadInt8()
  14. stageType = ReadInt8()
  15. roomCount = ReadInt8()
  16. gridCount = ReadInt8()
  17. print('Stage: ' + str(stageId) + '.' + str(stageType) + ', gridCount: ' + str(gridCount))
  18.  
  19. w, h = 13, 13;
  20. grid = [[0 for x in range(w)] for y in range(h)]
  21. for j in xrange(0, gridCount):
  22. room = readRoom()
  23. print(' Room ' + str(j) + ': ' + str(room.Id) + ' @ (' + str(room.X) + ', ' + str(room.Y) + ')')
  24. grid[room.X][room.Y] = room
  25.  
  26. iAmEror = readRoom(True)
  27. crawlSpace = readRoom(True)
  28. blackMarket = readRoom(True)
  29. if stageId == 6:
  30. bossRush = readRoom(True)
  31.  
  32. # Keep track of the stage
  33. # TODO
  34. print(' End of stage ' + str(stageId) + '.\n')
  35.  
  36. def SeedToString(num):
  37. #print('Converting ' + str(num) + ' to a seed string...')
  38. chars = "ABCDEFGHJKLMNPQRSTWXYZ01234V6789"
  39. x = 0
  40. tnum = num;
  41. while tnum != 0:
  42. x = (tnum + x) & 0xFF;
  43. x = ((x >> 7) + (x << 1)) & 0xFF;
  44. tnum >>= 5
  45. num ^= 0x0FEF7FFD
  46. tnum = num << 8 | x
  47.  
  48. s = ""
  49. for i in xrange(0, 8):
  50. if i >= 0 and i <= 5:
  51. index = num >> (27 - (i * 5)) & 0x1F
  52. elif i == 6:
  53. index = tnum >> 5 & 0x1F
  54. elif i == 7:
  55. index = tnum & 0x1F
  56. s += chars[index]
  57.  
  58. return s
  59.  
  60. def readRoom(grid = False):
  61. room = dotdict({})
  62. if grid:
  63. room.Offset = -1
  64. room.X = -1
  65. room.Y = 1
  66. else:
  67. room.Offset = ReadInt8()
  68. room.X = ReadInt8()
  69. room.Y = ReadInt8()
  70. room.StageIndex = ReadInt8()
  71. room.Type = ReadInt8()
  72. room.SubType = ReadInt8()
  73. room.Id = ReadInt16()
  74. return room
  75.  
  76. def ReadInt8():
  77. #print(f.tell())
  78. return ord(struct.unpack('c', f.read(1))[0])
  79.  
  80. def ReadInt16():
  81. return struct.unpack('H', f.read(2))[0]
  82.  
  83. def ReadUInt32():
  84. return struct.unpack('I', f.read(4))[0]
  85.  
  86. # From: https://stackoverflow.com/questions/2352181/how-to-use-a-dot-to-access-members-of-dictionary
  87. class dotdict(dict):
  88. """dot.notation access to dictionary attributes"""
  89. __getattr__ = dict.get
  90. __setattr__ = dict.__setitem__
  91. __delattr__ = dict.__delitem__
  92.  
  93. if __name__ == "__main__":
  94. main()
Advertisement
Add Comment
Please, Sign In to add comment