SHARE
TWEET

Super Meat Boy Time Total Reader (python)

a guest Jan 14th, 2012 1,165 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from sys import argv
  2. import struct
  3.  
  4. totalDeathsOffset = 8
  5. chapterInfoStart = 28
  6. chapterInfoOffset = 12
  7. levelOffset = 12
  8. levelStart = 0x88
  9. TheGuyWarpZoneStart = 0xF10
  10. ZoneNames = ['Forest      ',
  11.          'Hospital    ',
  12.          'Salt Factor ',
  13.          'Hell        ',
  14.          'Rapture     ',
  15.          'The End     ',
  16.          'Cotton Alley']
  17.  
  18. def maxLevelCount(zone):
  19.         if zone != 5:
  20.                 return 20
  21.         else:
  22.                 return 5
  23.  
  24. def maxWarpCount(zone):
  25.         if zone < 5:
  26.                 return 12
  27.         else:
  28.                 return 0
  29.  
  30. def toInt32(lst,offset):
  31.         s = lst[offset:offset+4]
  32.         return struct.unpack("<L",s)[0]
  33.  
  34. def getLevelInfo(save, zone, level, kind):
  35.         offset = 0
  36.         if kind == 2 and zone == 4 and level >= 3 and level <= 5:
  37.                 offset = TheGuyWarpZoneStart + (level - 3)*levelOffset
  38.         else:
  39.                 chapterOffset = 0
  40.                 for i in range(zone):
  41.                         chapterOffset += (maxLevelCount(i)*2+maxWarpCount(i))*levelOffset
  42.                 levelOffset2 = (level + maxLevelCount(zone) * kind)*levelOffset
  43.                 offset = levelStart + chapterOffset + levelOffset2
  44.         time = struct.unpack("<f", save[offset:offset+4])[0]
  45.         return time
  46.  
  47. def getLevels(save, zone, kind):
  48.         levels = []
  49.         if kind < 2:
  50.                 for i in range(maxLevelCount(zone)):
  51.                         levels.append(getLevelInfo(save, zone, i, kind))
  52.         else:
  53.                 for i in range(maxWarpCount(zone)):
  54.                         levels.append(getLevelInfo(save, zone, i, kind))
  55.         return levels
  56.  
  57. def readChapter(save, n):
  58.         offset = chapterInfoStart + (n * chapterInfoOffset)
  59.        
  60.         data = struct.unpack("bbbbb", save[offset:offset+5])
  61.        
  62.         lightLevels = getLevels(save, n, 0)
  63.         darkLevels = getLevels(save, n, 1)
  64.         warpLevels = getLevels(save, n, 2)
  65.        
  66.         #print n, data
  67.         #print lightLevels
  68.         #print darkLevels
  69.         #print warpLevels
  70.         print "Total Time (", ZoneNames[n] ,"): ", sum(lightLevels)+ sum(darkLevels) #+sum(warpLevels)
  71.  
  72. def readstats(spath):
  73.         blist = []
  74.         with open(spath, "rb") as f:
  75.                 blist = f.read()
  76.        
  77.         totalDeaths = toInt32(blist, totalDeathsOffset)
  78.        
  79.         print "Total Deaths:", totalDeaths
  80.        
  81.         chapters = []
  82.         for i in range(7):
  83.                 chapters.append(readChapter(blist, i))
  84.  
  85. def main():
  86.         if len(argv) > 1:
  87.                 readstats(argv[1])
  88.  
  89. if __name__ == "__main__":
  90.         main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top