dantarion

Untitled

Jul 20th, 2010
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.48 KB | None | 0 0
  1. import os, struct
  2. print "Dantarion's mewtwodashit.py"
  3. commands = {}
  4. commands[0x0] = [0x4, "End"]
  5. commands[0x3] = [0x8, "Unknown"]
  6. commands[0x4] = [0x4, "Synch Timer"]
  7. commands[0x8] = [0x4, "Asynch Timer"]
  8. commands[0xc] = [0x4, "Start Loop"]
  9. commands[0x14] = [0x8, "Unknown"]
  10. commands[0x1c] = [0x8, "Unknown(GOTO?)"]
  11. commands[0x28] = [0x14, "GFX Effect"]
  12. commands[0x5c] = [0x4, "IASA"]
  13. commands[0x2c] = [0x14, "Hitbox"]
  14. commands[0x40] = [0x4, "Remove Hitboxes"]
  15. commands[0x44] = [0xc, "Sound Effect"]
  16. commands[0x4c] = [0x4, "Autocancel"]
  17. commands[0xdc] = [0xc, "Unknown"]
  18. commands[0xe0] = [0x8, "Unknown"]
  19. commands[0x68] = [0x4, "Body Invincible"]
  20. commands[0x10] = [0x4, "Execute Loop"]
  21. commands[0x2d] = [0x14, "Unknown"]
  22. commands[0xd8] = [0x12, "Unknown"]
  23.  
  24.  
  25.  
  26. #Logger borrowed fromn
  27. #stackoverflow.com/questions/616645/
  28. import sys
  29.  
  30. class Logger(object):
  31.     def __init__(self,filename):
  32.         self.terminal = sys.stdout
  33.         self.log = open("./logs/"+filename+".log", "w+",102400)
  34.        
  35.     def write(self, message):
  36.         #self.terminal.write(message)
  37.         self.log.write(message)
  38.     def close(self):
  39.         self.log.close()
  40.         self.terminal.write("Done")
  41.     def switch(self,filename):
  42.         self.log.close()
  43.         del self.log
  44.         self.log = open("./logs/"+filename+".log", "w+",102400)
  45. class Command(object):
  46.     def __init__(self,byte,length,name):
  47.         self.byte = byte
  48.         self.length = length
  49.         self.name = name
  50. def parseDat(filename):
  51.     print "Parsing \""+filename+"\""
  52.     with open(filename,"rb",102400) as infile:
  53.         #Read Header
  54.         header = struct.unpack(">8I",infile.read(0x20))
  55.         print "Header"
  56.         print "---------"
  57.         hexprint(header)
  58.         print
  59.        
  60.         #infile.seek(0x28+header[1])
  61.         #for i in range(0,header[2]):
  62.         #    tmp = struct.unpack(">I",infile.read(4))[0]
  63.         #    print hex(i),hex(tmp)
  64.         for i in range(0,header[4]):            
  65.             infile.seek(0x20+header[1]+4*header[2]+header[3]*i+8)
  66.             print hex(infile.tell())
  67.             sectionheader = struct.unpack(">2I",infile.read(8))
  68.             hexprint(sectionheader)
  69.             infile.seek(0x20+header[1]+4*header[2]+(header[3]+header[4])*8+sectionheader[1])
  70.             print readnullstring(infile)            
  71.         infile.seek(0x20+header[1]+4*header[2])
  72.         print hex(infile.tell())
  73.         offsetheader = struct.unpack(">2I",infile.read(8))
  74.         hexprint(offsetheader)
  75.         infile.seek(0x20+header[1]+4*header[2]+(header[3]+header[4])*8+offsetheader[1])
  76.         print readnullstring(infile)
  77.  
  78.         #
  79.         # Main Offset Table
  80.         #
  81.         infile.seek(0x20+offsetheader[0])
  82.         offsets = struct.unpack(">23I",infile.read(23*4))
  83.         print "Main Offset Table"
  84.         print "---------"
  85.         hexprint(offsets)
  86.         print
  87.  
  88.         #
  89.         # Attributes
  90.         #
  91. ##        intatt = [0x58,0xa4,0x16c]
  92. ##        known = {}
  93. ##        known[0x38] = "Jump Startup Lag"
  94. ##        known[0x88] = "Weight"
  95. ##        known[0xE4] = "Empty Landing Lag"
  96. ##        known[0xE8] = "N-Air Landing Lag"
  97. ##        known[0xEC] = "F-Air Landing Lag"
  98. ##        known[0xF0] = "B-Air Landing Lag"
  99. ##        known[0xF4] = "U-Air Landing Lag"
  100. ##        known[0xF8] = "D-Air Landing Lag"
  101. ##        i = 0
  102. ##        infile.seek(offsets[0]+0x20)
  103. ##        while infile.tell() < offsets[1]+0x20:
  104. ##            print hex(i),
  105. ##            if i in known:
  106. ##                print known[i],
  107. ##            if i in intatt:
  108. ##                print struct.unpack(">I",infile.read(4))[0]
  109. ##            else:
  110. ##                print struct.unpack(">f",infile.read(4))[0]
  111. ##            i += 4
  112.  
  113.         #
  114.         # Actions
  115.         #
  116.         terminal.write(hex(offsets[3]+hex(offsets[4])))
  117.         infile.seek(offsets[3]+0x20)
  118.         while infile.tell() < offsets[18]+0x20:
  119.             tmp = struct.unpack(">6I",infile.read(6*4))
  120.             print tmp[0]
  121.             tmploc = infile.tell()
  122.             tmp2 = struct.unpack(">6I",infile.read(6*4))
  123.             infile.seek(tmp[0]+0x20)
  124.             print readnullstring(infile)
  125.            
  126.             hexprint(tmp)
  127.             #
  128.             # MeleeScript
  129.             #
  130.  
  131.            
  132.             infile.seek(tmp[3]+0x20)
  133.             cur = ord(infile.read(1))
  134.             indent = 0
  135.             while cur != 0:
  136.                 if cur == 0x4 or cur == 8:
  137.                     indent = 0
  138.                 if indent == 1:
  139.                     print "    ",
  140.                 if cur == 0x4 or cur == 8:
  141.                     indent = 1
  142.                 if cur in commands:
  143.                     print "["+commands[cur][1]+"]",
  144.                     print hex(cur),"-",
  145.                     for i in range(1, commands[cur][0]):
  146.                         print "%02x" % ord(infile.read(1)),
  147.                     print
  148.                     if cur == 0x5C or cur == 0:
  149.                         print "End"
  150.                         break
  151.                 else:
  152.                     print "[Unknown!] %02x" % cur,"-",
  153.                     print "%02x" % ord(infile.read(1)),
  154.                     print "%02x" % ord(infile.read(1)),
  155.                     print "%02x" % ord(infile.read(1)),
  156.                     print
  157.                 cur = ord(infile.read(1))
  158.             print "---------"
  159.             infile.seek(tmploc)
  160.                
  161.                    
  162.        
  163.            
  164. def readnullstring(infile):
  165.     position = infile.tell()
  166.     leng = 0;
  167.     while(ord(infile.read(1)) != 0):
  168.         leng = leng+1
  169.     infile.seek(position)
  170.     return infile.read(leng)
  171. def hexprint(array):
  172.     for i,value in enumerate(array):  
  173.         print hex(i),
  174.         if type(value) != str:
  175.             print hex(value)
  176.         else:
  177.             print value
  178. #
  179. # Setup
  180. #
  181. DAT_PATH = """./dats/"""
  182.  
  183. #filenames = []
  184. #for entries in os.listdir(DAT_PATH):
  185. #    for entries2 in os.listdir(DAT_PATH+entries):
  186. #        if "AJ" not in entries2 and ".dat" in entries2 and "zz" not in entries:
  187. #            filenames.append([entries,DAT_PATH+entries+"/"+entries2])
  188. sys.stdout = Logger("log")
  189. #for filename in filenames:
  190. #    sys.stdout.switch(filename[0])
  191. #    parseDat(filename[1])
  192.    
  193. parseDat(DAT_PATH+'Mario/PlMr.dat')
  194. #parseDat(DAT_PATH+'Game & Watch/PlGw.dat')
  195. #parseDat(DAT_PATH+'Roy/PlFe.dat'):
  196. for command in commands.keys():
  197.     print "commands["+hex(command)+"] = ["+hex(commands[command][0])+", \""+commands[command][1]+"\"]"
  198. sys.stdout.close()
Add Comment
Please, Sign In to add comment