Skip to content

Commit 3f148e4

Browse files
committed
Patches sc2reader to parse 1.3.3 replays
1 parent b2f455a commit 3f148e4

File tree

3 files changed

+52
-15
lines changed

3 files changed

+52
-15
lines changed

sc2reader/objects.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,14 @@ def __init__(self, framestamp, player, type, code, ability, location):
297297
super(LocationAbilityEvent, self).__init__(framestamp, player, type, code, ability)
298298
self.location = location
299299

300+
class UnknownAbilityEvent(AbilityEvent):
301+
name = 'UnknownAbilityEvent'
302+
pass
303+
304+
class UnknownLocationAbilityEvent(AbilityEvent):
305+
name = 'UnknownLocationAbilityEvent'
306+
pass
307+
300308
class HotkeyEvent(Event):
301309
name = 'HotkeyEvent'
302310
def __init__(self, framestamp, player, type, code, hotkey, overlay=None):

sc2reader/parsers.py

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,30 @@
22

33
from sc2reader.objects import *
44
from sc2reader.utils import BIG_ENDIAN,LITTLE_ENDIAN
5-
5+
from collections import defaultdict
66
class SetupParser(object):
77
def parse_join_event(self, buffer, frames, type, code, pid):
88
return PlayerJoinEvent(frames, pid, type, code)
99

1010
def parse_start_event(self, buffer, frames, type, code, pid):
1111
return GameStartEvent(frames, pid, type, code)
1212

13+
counter = defaultdict(int)
14+
flag_counter = defaultdict(int)
15+
1316
class ActionParser(object):
1417
def parse_leave_event(self, buffer, frames, type, code, pid):
1518
return PlayerLeaveEvent(frames, pid, type, code)
1619

1720
def parse_ability_event(self, buffer, frames, type, code, pid):
18-
""" Unit ability"""
1921
flag = buffer.read_byte()
2022
atype = buffer.read_byte()
2123

22-
ability = None
2324
if atype & 0x20: # command card
25+
end = buffer.peek(35)
2426
ability = buffer.read_byte() << 8 | buffer.read_byte()
25-
if flag in (0x29, 0x19): # cancels
27+
28+
if flag in (0x29, 0x19, 0x14): # cancels
2629
# creation autoid number / object id
2730
ability = ability << 8 | buffer.read_byte()
2831
created_id = buffer.read_object_id()
@@ -32,7 +35,7 @@ def parse_ability_event(self, buffer, frames, type, code, pid):
3235
else:
3336
ability_flags = buffer.shift(6)
3437
ability = ability << 8 | ability_flags
35-
38+
3639
if ability_flags & 0x10:
3740
# ability(3), coordinates (4), ?? (4)
3841
location = buffer.read_coordinate()
@@ -45,18 +48,32 @@ def parse_ability_event(self, buffer, frames, type, code, pid):
4548
obj_id = buffer.read_object_id()
4649
obj_type = buffer.read_object_type()
4750
target = (obj_id, obj_type,)
48-
buffer.skip(10)
51+
switch = buffer.read_byte()
52+
buffer.read_hex(9)
4953
return TargetAbilityEvent(frames, pid, type, code, ability, target)
50-
51-
elif ability_flags & 0x30 == 0x00:
52-
return AbilityEvent(frames, pid, type, code, ability)
53-
54+
55+
else:
56+
return AbilityEvent(frames,pid,type,code,None)
57+
5458
elif atype & 0x40: # location/move
55-
# coordinates (4), ?? (6)
56-
location = buffer.read_coordinate()
57-
buffer.skip(5)
58-
return LocationAbilityEvent(frames, pid, type, code, ability, location)
59+
if flag == 0x08:
60+
# coordinates (4), ?? (6)
61+
location = buffer.read_coordinate()
62+
buffer.skip(5)
63+
return LocationAbilityEvent(frames, pid, type, code, None, location)
5964

65+
elif flag in (0x04,0x07):
66+
h = buffer.read_hex(2)
67+
hinge = buffer.read_byte()
68+
if hinge & 0x20:
69+
"\t%s - %s" % (hex(hinge),buffer.read_hex(9))
70+
elif hinge & 0x40:
71+
"\t%s - %s" % (hex(hinge),buffer.read_hex(18))
72+
elif hinge < 0x10:
73+
pass
74+
75+
return UnknownLocationAbilityEvent(frames, pid, type, code, None)
76+
6077
elif atype & 0x80: # right-click on target?
6178
# ability (2), object id (4), object type (2), ?? (10)
6279
ability = buffer.read_byte() << 8 | buffer.read_byte()
@@ -65,6 +82,17 @@ def parse_ability_event(self, buffer, frames, type, code, pid):
6582
target = (obj_id, obj_type,)
6683
buffer.skip(10)
6784
return TargetAbilityEvent(frames, pid, type, code, ability, target)
85+
86+
elif atype < 0x10: #new to patch 1.3.3
87+
buffer.skip(10)
88+
return UnknownAbilityEvent(frames, pid, type, code, None)
89+
90+
else:
91+
print hex(buffer.cursor)
92+
raise TypeError()
93+
94+
print "%s - %s" % (hex(atype),hex(flag))
95+
raise TypeError("Shouldn't be here EVER!")
6896

6997
def parse_selection_event(self, buffer, frames, type, code, pid):
7098
bank = code >> 4

sc2reader/readers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,10 @@ def read(self, buffer, replay):
200200

201201
while not buffer.empty:
202202
#Save the start so we can trace for debug purposes
203-
#start = buffer.cursor
203+
start = buffer.cursor
204204

205205
frames += buffer.read_timestamp()
206+
#print frames
206207
pid = buffer.shift(5)
207208
type, code = buffer.shift(3), buffer.read_byte()
208209

0 commit comments

Comments
 (0)