def parse_unity_file file_ s_bytes Entity t_bytes Entity t_len len t_b

 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
def parse_unity_file(file_):
s_bytes = b"<Entity"
t_bytes = b"</Entity>"
t_len = len(t_bytes)
with open(file_, "rb") as f:
xml_buf = bytearray()
for line in f:
p = 0
bytes_ = bytearray(line)
# Search end of block
try:
p = bytes_.index(t_bytes)
xml_buf += bytes_[p:t_len]
save_xml(xml_buf)
xml_buf = bytearray()
bytes_ = bytes_[p + t_len:]
except ValueError:
pass
# Search start of block (<Entity)
try:
p = bytes_.index(s_bytes)
xml_buf += bytes_[p:]
continue
except ValueError:
pass
# If started but not stopped
if xml_buf:
xml_buf += bytes_