-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathue2_lin_compressor.py
More file actions
41 lines (36 loc) · 1.37 KB
/
ue2_lin_compressor.py
File metadata and controls
41 lines (36 loc) · 1.37 KB
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
# Land of the Dead: Road to Fiddler's Green XBOX .lin compressor (Unreal Engine 2)
import struct
import os
import sys
import zlib
CHUNK_SIZE = 16384
def compress_lin(file):
result_filename = os.path.splitext(file)[0]
with open(file, 'rb') as f, open (result_filename, 'wb') as r:
fsize = os.path.getsize(file)
chunk_num = (fsize // CHUNK_SIZE) + 1
for i in range(chunk_num):
data_decomp = f.read(CHUNK_SIZE)
data_comp = zlib.compress(data_decomp)
r.write(len(data_decomp).to_bytes(4, byteorder='little'))
r.write(len(data_comp).to_bytes(4, byteorder='little'))
r.write(data_comp)
print('%s compressed to %s' % (file, result_filename))
def decompress_lin(file):
result_filename = file + '.dec'
with open(file, 'rb') as f, open (result_filename, 'wb') as r:
fsize = os.path.getsize(file)
cur = 0
while(cur < fsize):
size, zsize = struct.unpack('<2I', f.read(8))
data = zlib.decompress(f.read(zsize))
r.write(data)
cur = f.tell()
print('%s decompressed to %s' % (file, result_filename))
if len(sys.argv) < 2:
exit()
ext = os.path.splitext(sys.argv[1])[1]
if ext == '.lin':
decompress_lin(sys.argv[1])
elif ext == '.dec':
compress_lin(sys.argv[1])