-
Notifications
You must be signed in to change notification settings - Fork 3
/
fez_unpack.py
executable file
·60 lines (51 loc) · 1.88 KB
/
fez_unpack.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
54
55
56
57
58
59
60
#!/usr/bin/env python
"""
Extract FEZ .pak files
"""
import sys
import os
from binstream import BinaryReader
def unpack(src, dest):
with open(src, 'rb') as in_file:
reader = BinaryReader(in_file.read())
capacity = reader.read(int)
for _ in range(capacity):
filename = reader.read(str)
filesize = reader.read(int)
filedata = reader.pull(filesize)
print '"%s" : %d' % (filename, filesize)
filename = os.path.join(dest, filename)
filedir, _, _ = filename.rpartition('\\')
if filedir:
filedir = os.path.normpath(filedir)
if not os.path.isdir(filedir):
os.makedirs(filedir)
if filedata[:3] == b'XNB':
extension = '.xnb'
elif filedata[:4] == b'OggS':
extension = '.ogg'
elif filedata[:4] == b'XGSF' or filedata[:4] == b'FSGX':
extension = '.xgs'
elif filedata[:4] == b'SDBK' or filedata[:4] == b'KBDS':
extension = '.xsb'
elif filedata[:4] == b'WBND' or filedata[:4] == b'DNBW':
extension = '.xwb'
elif filedata[2:4] == b'\xff\xfe' or filedata[:2] == b'\xfe\xff':
extension = '.fxo'
else:
extension = '.bin'
suffix = ''
if os.path.isfile(filename + suffix + extension):
for i in range(0, 100):
suffix = '.%02d' % i
if not os.path.isfile(filename + suffix + extension):
break
with open(filename + suffix + extension, 'wb') as out_file:
out_file.write(filedata)
def main():
if len(sys.argv) == 3:
unpack(sys.argv[1], sys.argv[2])
else:
print 'fez_unpack.py in.pak out_dir'
if __name__ == '__main__':
main()