-
Notifications
You must be signed in to change notification settings - Fork 5
/
rdat.py
51 lines (34 loc) · 1.11 KB
/
rdat.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
""" Copyright 2015-2017 sta256+mpskit at gmail.com
This file is part of mpskit.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See LICENSE file for more details.
"""
from common import *
"""
Raw DAT: null-terminated strings, no compression, no madspack
"""
verbose = 0
def read_rdat(name):
check_ext(name, '.DAT')
r = open(name, 'rb').read()
xs = r.split(b'\x00')
msgs = [decode_string(x) for x in xs]
on = '{}.rdat.json'.format(name)
with open(on, 'w') as f:
json.dump(msgs, f, indent=2, ensure_ascii=False)
output(on)
def write_rdat(name):
check_ext(name, '.DAT')
on = '{}.rdat.json'.format(name)
with open(on, 'r') as f:
msgs = json.load(f)
xs = [encode_string(m, null_term=True) for m in msgs]
with open(name, 'wb') as f:
for x in xs:
f.write(x)
output(name)