-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdumpscript.py
53 lines (47 loc) · 1.82 KB
/
dumpscript.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
from sys import argv
from superdecompressor import Datapack
from utils import gen_formatted
END_ADDRESS = 0xf489540
specials = {}
for line in open("specialcodes.txt"):
code, replacement = tuple(line.strip().split(' ', 1))
replacement = replacement.replace(r"\n", "\n")
specials[code] = replacement
if __name__ == "__main__":
if len(argv) < 3:
print "\n".join([
"python dumpscript.py <input file> <output file> <initial address>"])
exit(0)
if len(argv) >= 4:
infile, outfile, address = tuple(argv[1:4])
else:
infile, outfile, address = argv[1], argv[2], "818"
#infile, outfile, address = argv[1], argv[2], "115da8"
infile = open(infile, "rb")
outfile = open(outfile, "w+")
address = int(address, 16)
while True:
if address >= END_ADDRESS:
break
print "%x" % address
try:
d = Datapack(infile=infile, address=address)
totalout = ""
for i, messages in enumerate(d.messageslist):
if messages is None:
continue
messages = map(gen_formatted, messages)
for num, message in enumerate(messages):
output = "#<{2}.{0:0>3}>\n{1}\n\n".format(num + 1, message, i)
for code, replacement in specials.items():
output = output.replace(code, replacement)
totalout += output
if totalout:
outfile.write("#<@{0:0>7}>\n".format("%x" % address))
outfile.write(totalout)
except (AssertionError, IndexError), e:
# TODO: need to double check each assertion, probably too lenient
# for example, still won't dump message at 1165fa
print e
address += 0x930