Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, struct
- print "Dantarion's mewtwodashit.py"
- commands = {}
- commands[0x0] = [0x4, "End"]
- commands[0x3] = [0x8, "Unknown"]
- commands[0x4] = [0x4, "Synch Timer"]
- commands[0x8] = [0x4, "Asynch Timer"]
- commands[0xc] = [0x4, "Start Loop"]
- commands[0x14] = [0x8, "Unknown"]
- commands[0x1c] = [0x8, "Unknown(GOTO?)"]
- commands[0x28] = [0x14, "GFX Effect"]
- commands[0x5c] = [0x4, "IASA"]
- commands[0x2c] = [0x14, "Hitbox"]
- commands[0x40] = [0x4, "Remove Hitboxes"]
- commands[0x44] = [0xc, "Sound Effect"]
- commands[0x4c] = [0x4, "Autocancel"]
- commands[0xdc] = [0xc, "Unknown"]
- commands[0xe0] = [0x8, "Unknown"]
- commands[0x68] = [0x4, "Body Invincible"]
- commands[0x10] = [0x4, "Execute Loop"]
- commands[0x2d] = [0x14, "Unknown"]
- commands[0xd8] = [0x12, "Unknown"]
- #Logger borrowed fromn
- #stackoverflow.com/questions/616645/
- import sys
- class Logger(object):
- def __init__(self,filename):
- self.terminal = sys.stdout
- self.log = open("./logs/"+filename+".log", "w+",102400)
- def write(self, message):
- #self.terminal.write(message)
- self.log.write(message)
- def close(self):
- self.log.close()
- self.terminal.write("Done")
- def switch(self,filename):
- self.log.close()
- del self.log
- self.log = open("./logs/"+filename+".log", "w+",102400)
- class Command(object):
- def __init__(self,byte,length,name):
- self.byte = byte
- self.length = length
- self.name = name
- def parseDat(filename):
- print "Parsing \""+filename+"\""
- with open(filename,"rb",102400) as infile:
- #Read Header
- header = struct.unpack(">8I",infile.read(0x20))
- print "Header"
- print "---------"
- hexprint(header)
- print
- #infile.seek(0x28+header[1])
- #for i in range(0,header[2]):
- # tmp = struct.unpack(">I",infile.read(4))[0]
- # print hex(i),hex(tmp)
- for i in range(0,header[4]):
- infile.seek(0x20+header[1]+4*header[2]+header[3]*i+8)
- print hex(infile.tell())
- sectionheader = struct.unpack(">2I",infile.read(8))
- hexprint(sectionheader)
- infile.seek(0x20+header[1]+4*header[2]+(header[3]+header[4])*8+sectionheader[1])
- print readnullstring(infile)
- infile.seek(0x20+header[1]+4*header[2])
- print hex(infile.tell())
- offsetheader = struct.unpack(">2I",infile.read(8))
- hexprint(offsetheader)
- infile.seek(0x20+header[1]+4*header[2]+(header[3]+header[4])*8+offsetheader[1])
- print readnullstring(infile)
- #
- # Main Offset Table
- #
- infile.seek(0x20+offsetheader[0])
- offsets = struct.unpack(">23I",infile.read(23*4))
- print "Main Offset Table"
- print "---------"
- hexprint(offsets)
- print
- #
- # Attributes
- #
- ## intatt = [0x58,0xa4,0x16c]
- ## known = {}
- ## known[0x38] = "Jump Startup Lag"
- ## known[0x88] = "Weight"
- ## known[0xE4] = "Empty Landing Lag"
- ## known[0xE8] = "N-Air Landing Lag"
- ## known[0xEC] = "F-Air Landing Lag"
- ## known[0xF0] = "B-Air Landing Lag"
- ## known[0xF4] = "U-Air Landing Lag"
- ## known[0xF8] = "D-Air Landing Lag"
- ## i = 0
- ## infile.seek(offsets[0]+0x20)
- ## while infile.tell() < offsets[1]+0x20:
- ## print hex(i),
- ## if i in known:
- ## print known[i],
- ## if i in intatt:
- ## print struct.unpack(">I",infile.read(4))[0]
- ## else:
- ## print struct.unpack(">f",infile.read(4))[0]
- ## i += 4
- #
- # Actions
- #
- terminal.write(hex(offsets[3]+hex(offsets[4])))
- infile.seek(offsets[3]+0x20)
- while infile.tell() < offsets[18]+0x20:
- tmp = struct.unpack(">6I",infile.read(6*4))
- print tmp[0]
- tmploc = infile.tell()
- tmp2 = struct.unpack(">6I",infile.read(6*4))
- infile.seek(tmp[0]+0x20)
- print readnullstring(infile)
- hexprint(tmp)
- #
- # MeleeScript
- #
- infile.seek(tmp[3]+0x20)
- cur = ord(infile.read(1))
- indent = 0
- while cur != 0:
- if cur == 0x4 or cur == 8:
- indent = 0
- if indent == 1:
- print " ",
- if cur == 0x4 or cur == 8:
- indent = 1
- if cur in commands:
- print "["+commands[cur][1]+"]",
- print hex(cur),"-",
- for i in range(1, commands[cur][0]):
- print "%02x" % ord(infile.read(1)),
- print
- if cur == 0x5C or cur == 0:
- print "End"
- break
- else:
- print "[Unknown!] %02x" % cur,"-",
- print "%02x" % ord(infile.read(1)),
- print "%02x" % ord(infile.read(1)),
- print "%02x" % ord(infile.read(1)),
- print
- cur = ord(infile.read(1))
- print "---------"
- infile.seek(tmploc)
- def readnullstring(infile):
- position = infile.tell()
- leng = 0;
- while(ord(infile.read(1)) != 0):
- leng = leng+1
- infile.seek(position)
- return infile.read(leng)
- def hexprint(array):
- for i,value in enumerate(array):
- print hex(i),
- if type(value) != str:
- print hex(value)
- else:
- print value
- #
- # Setup
- #
- DAT_PATH = """./dats/"""
- #filenames = []
- #for entries in os.listdir(DAT_PATH):
- # for entries2 in os.listdir(DAT_PATH+entries):
- # if "AJ" not in entries2 and ".dat" in entries2 and "zz" not in entries:
- # filenames.append([entries,DAT_PATH+entries+"/"+entries2])
- sys.stdout = Logger("log")
- #for filename in filenames:
- # sys.stdout.switch(filename[0])
- # parseDat(filename[1])
- parseDat(DAT_PATH+'Mario/PlMr.dat')
- #parseDat(DAT_PATH+'Game & Watch/PlGw.dat')
- #parseDat(DAT_PATH+'Roy/PlFe.dat'):
- for command in commands.keys():
- print "commands["+hex(command)+"] = ["+hex(commands[command][0])+", \""+commands[command][1]+"\"]"
- sys.stdout.close()
Add Comment
Please, Sign In to add comment