This repository has been archived by the owner on Jun 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevtc-trim-after-end.py
executable file
·94 lines (73 loc) · 2.48 KB
/
evtc-trim-after-end.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
#!/usr/bin/python3
# Removes everything after the LogEnd event from EVTC files.
# Has to be used on non-compressed logs, can be used to batch-process
# This can be useful for fixing broken logs with random trash data after the
# log end.
# Example usage:
# ./evtc-trim-after-end.py 20190412-210528.evtc 20190420-204619.evtc
# Will create two files:
# 20190412-210528.evtc-mod
# 20190420-204619.evtc-mod
from sys import argv
import struct
def skip_bytes(f, result, n):
for x in range(n):
byte = f.read(1)
if byte == b"":
return False
result.write(byte)
return True
def read_byte(f, result):
byte = f.read(1)
result.write(byte)
return byte
def read_int(f, result):
data = f.read(4)
result.write(data)
value, = struct.unpack('i', data)
return value
def trim_after_log_end(filename):
print(f"Trimming data after log end from {filename}")
with open(filename, "rb") as f:
with open(filename + "-mod", "wb") as result:
# Header
skip_bytes(f, result, 12)
revision = read_byte(f, result)
assert revision == b"\x01", "Can only handle revision 1"
print(f"Revision {revision}")
skip_bytes(f, result, 3)
# Agents
agent_count = read_int(f, result)
print(f"Agent count: {agent_count}")
for _ in range(agent_count):
skip_bytes(f, result, 96)
# Skills
skill_count = read_int(f, result)
print(f"Skill count: {skill_count}")
for _ in range(skill_count):
skip_bytes(f, result, 68)
# Combat items
combatitem_count = 0
while True:
b = f.read(64)
if (b == b""):
break
state_change = b[56]
result.write(b)
combatitem_count += 1
if (int(state_change) == 10):
print(f"LogEnd on item {combatitem_count}, ending")
break
removed_combatitem_count = 0
while True:
b = f.read(64)
if (b == b""):
break
removed_combatitem_count += 1
print(f"New combat item count: {combatitem_count}, "
+ f"trimmed {removed_combatitem_count} items.")
for filename in argv[1:]:
try:
trim_after_log_end(filename)
except Exception as e:
print(e)