forked from clowd81/rift_datamine_tools
/
RIFTDataParser.py
184 lines (157 loc) · 5.49 KB
/
RIFTDataParser.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
'''
Created on 14Mar.,2017
'''
import os
from Utility import readUnsignedLeb128
from LittleEndianDataInputStream import LittleEndianDataInputStream
def log(sstr, indent):
print(sstr.rjust(len(sstr) + indent))
class CodeResult(object):
def __init__(self, _code, _data):
self.code = _code
self.data = _data
def __str__(self):
return "[" + str(self.code) + "][" + str(self.data) + "]";
class CodeResult2(object):
def __init__(self, _code, _code2, _data):
self.codeA = _code
self.codeB = _code2
self.count = _data
def __str__(self):
return "[" + str(self.codeA) + "][" + str(self.codeB) + "][" + str(self.count) + "]"
def splitCode(cin):
code = cin & 7
data = cin >> 3
if code == 7:
data = cin >> 6
v5 = (cin >> 3) & 7
if v5 <= 4:
code = v5 + 8
return CodeResult(code, data)
elif code <= 7:
return CodeResult(code, data)
return None
def readCodeAndExtract(stream, indent):
value = readUnsignedLeb128(stream)
if value == 0:
return None
codeResult = splitCode(value)
log("READ result " + str(codeResult), indent)
return codeResult
def readCodeThenReadTwice(stream, indent):
value = readUnsignedLeb128(stream)
if value == 0:
return None
codeResult = splitCode(value)
if codeResult == None:
return None
codeA = codeResult.code
codeResultB = splitCode(codeResult.data)
codeB = codeResultB.code
return CodeResult2(codeA, codeB, codeResultB.data)
def handleCode(stream, code, indent):
if code == 0 or code == 1:
log("handleCode:" + str(code) + ", boolean?", indent)
log("bool? " + str(code), indent+1)
return True
if code == 2:
#some kind of float/double. Can be UP to 80 bits long
#IEEE 754 extended precision format maybe?
log("handleCode:" + str(code) + ", (1)float/double?", indent)
i = 1
while stream.read_byte() < 0 and i < 10:
i = i + 1
return True
if code == 3:
#some kind of float/double. Can be UP to 80 bits long
#IEEE 754 extended precision format maybe?
log("handleCode:" + str(code) + ", (1)float/double?", indent)
i = 1
while stream.read_byte() < 0 and i < 10:
i = i + 1
return True
if code == 4:
log("handleCode:" + str(code) + ", int?", indent)
log("int:" + str(stream.read_int()), indent+1)
return True
if code == 5:
log("handleCode:" + str(code) + ", long?", indent)
log("long:" + str(stream.read_long()), indent+1)
return True
if code == 6:
log("handleCode:" + str(code) + ", string/data", indent)
slen = readUnsignedLeb128(stream)
sstr = stream.read_string(slen)
log("string:" + sstr, indent+1)
return True
if code == 10 or code == 9:
if code == 10:
# a value then some kind of array?
log("handleCode:" + str(code) + ", array?", indent)
value = readUnsignedLeb128(stream)
log ("value:" + str(value), indent+1)
if value > 0xFFFF or value == 0:
log("bad value code 10", indent+1)
return False
log("handleCode:" + str(code) + ", array2?", indent)
while True:
rr = readCodeAndExtract(stream, indent +1)
if rr == None:
break
if rr.code == 8:
return True
if not handleCode(stream, rr.code, indent+1):
break
log("overrun while code 9", indent +1)
return False
if code == 11:
log("handleCode:" + str(code) + ", array?", indent)
result = readCodeAndExtract(stream, indent+1)
if result == None:
log("bad result code 11", indent+1)
return False
count = result.data
if count == 0:
return True
i = 0
log("handle array count[" + str(count) + "], startingCode[" + str(result.code) + "]", indent+1)
while (handleCode(stream, result.code, indent+1)):
i = i + 1
if (i >= count):
return True
log("overrun while code 11", indent +1)
return False
if code == 12:
log("handleCode:" + str(code) + ", array3?", indent)
result = readCodeThenReadTwice(stream, indent +1)
count = result.count
if count == 0:
return True
i = 0
log("handle Multidimensional array?:" + str(result), indent+1)
while (handleCode(stream, result.codeA, indent+1) and handleCode(stream, result.codeB, indent+1)):
i = i + 1
if (i >= count):
return True
log("overrun while code 12", indent +1)
return False
if code == 8:
log("handleCode:" + str(code) + ", end of object", indent)
return False
log("UNKNOWN CODE:" + str(code))
exit(1)
def parse(file):
file = open(file, "rb")
stream = LittleEndianDataInputStream(file)
classCode = readUnsignedLeb128(stream)
print ("Found class code:", classCode)
i = 1
done = False
while not done:
print("do member " + str(i))
codeResult = readCodeAndExtract(stream, 1)
done = not handleCode(stream, codeResult.code, 1)
i = i+1
file.close()
if __name__ == '__main__':
parse("D:\\rift_stuff\\_unk_map1\\0011b0bb._unk_map1")