Skip to content

Commit 2837ce6

Browse files
committed
Add the parsed flags to the AbilityEvents.
1 parent f18dc68 commit 2837ce6

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

sc2reader/events.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def __init__(self, frame, pid, event_type):
3939
self.is_init = (event_class == 0)
4040
self.is_player_action = (event_class == 1)
4141
self.is_camera_movement = (event_class == 3)
42-
#self.is_unknown = (event_class == 2 or event_class == 4 or event_class == 5)
4342

4443
#############################################3
4544
# Message Events
@@ -158,10 +157,11 @@ def __str__(self):
158157
class AbilityEvent(PlayerActionEvent):
159158
name = 'AbilityEvent'
160159

161-
def __init__(self, frame, pid, event_type, ability):
160+
def __init__(self, frame, pid, event_type, ability, flags):
162161
super(AbilityEvent, self).__init__(frame, pid, event_type)
163162
self.ability_code = ability
164163
self.ability_name = 'Uknown'
164+
self.flags = flags
165165

166166
def load_context(self, replay):
167167
super(AbilityEvent, self).load_context(replay)
@@ -192,8 +192,8 @@ def __str__(self):
192192
class TargetAbilityEvent(AbilityEvent):
193193
name = 'TargetAbilityEvent'
194194

195-
def __init__(self, frame, pid, event_type, ability, target, player, team, location):
196-
super(TargetAbilityEvent, self).__init__(frame, pid, event_type, ability)
195+
def __init__(self, frame, pid, event_type, ability, flags, target, player, team, location):
196+
super(TargetAbilityEvent, self).__init__(frame, pid, event_type, ability, flags)
197197
self.target = None
198198
self.target_id, self.target_type = target
199199

@@ -255,8 +255,8 @@ def __str__(self):
255255
class LocationAbilityEvent(AbilityEvent):
256256
name = 'LocationAbilityEvent'
257257

258-
def __init__(self, frame, pid, event_type, ability, location):
259-
super(LocationAbilityEvent, self).__init__(frame, pid, event_type, ability)
258+
def __init__(self, frame, pid, event_type, ability, flags, location):
259+
super(LocationAbilityEvent, self).__init__(frame, pid, event_type, ability, flags)
260260
self.location = location
261261

262262
def __str__(self):
@@ -266,8 +266,8 @@ def __str__(self):
266266
class SelfAbilityEvent(AbilityEvent):
267267
name = 'SelfAbilityEvent'
268268

269-
def __init__(self, frame, pid, event_type, ability, info):
270-
super(SelfAbilityEvent, self).__init__(frame, pid, event_type, ability)
269+
def __init__(self, frame, pid, event_type, ability, flags, info):
270+
super(SelfAbilityEvent, self).__init__(frame, pid, event_type, ability, flags)
271271
self.info = info
272272

273273
@loggable

sc2reader/readers.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def __call__(self, data, replay):
232232
read_timestamp = data.read_timestamp
233233
read_bits = data.read_bits
234234
read_byte = data.read_byte
235+
tell = data.tell
235236
read_bytes = data.read_bytes
236237
byte_align = data.byte_align
237238
append = game_events.append
@@ -247,7 +248,7 @@ def __call__(self, data, replay):
247248
if event_type in EVENT_DISPATCH:
248249
event = EVENT_DISPATCH[event_type](data, fstamp, pid, event_type)
249250
if debug:
250-
event.bytes = data.read_range(event_start, data.tell())
251+
event.bytes = data.read_range(event_start, tell())
251252
append(event)
252253

253254
# Otherwise maybe it is an unknown chunk
@@ -276,7 +277,7 @@ def __call__(self, data, replay):
276277
raise ReadError("Event type {} unknown at position {}.".format(hex(event_type),hex(event_start)), event_type, event_start, replay, game_events, data)
277278

278279
byte_align()
279-
event_start = data.tell()
280+
event_start = tell()
280281

281282
return game_events
282283
except ParseError as e:
@@ -302,12 +303,12 @@ def _parse_selection_update(self, data):
302303

303304
def player_ability_event(self, data, fstamp, pid, event_type):
304305
data.read_bits(4)
305-
data.read_bytes(7)
306-
switch = data.read_bits(8)
306+
data.skip(7)
307+
switch = data.read_byte()
307308
if switch in (0x30,0x50):
308-
data.read_bytes(1)
309-
data.read_bytes(24)
310-
return AbilityEvent(fstamp, pid, event_type, None)
309+
data.skip(1)
310+
data.skip(24)
311+
return AbilityEvent(fstamp, pid, event_type, None, None)
311312

312313
def player_selection_event(self, data, fstamp, pid, event_type):
313314
bank = data.read_bits(4)
@@ -450,13 +451,12 @@ def player_ability_event(self, data, fstamp, pid, event_type):
450451
z = data.read_int(BIG_ENDIAN)
451452
z = (z>>1)/8192.0 * pow(-1, z & 0x1)
452453
unknown = data.read_bits(1)
453-
return LocationAbilityEvent(fstamp, pid, event_type, ability, (x, y, z))
454+
return LocationAbilityEvent(fstamp, pid, event_type, ability, flags, (x, y, z))
454455

455456
elif target_type == 2:
456457
player = team = None
457458

458-
data.read_byte()
459-
data.read_byte()
459+
data.skip(2)
460460
unit = (data.read_int(BIG_ENDIAN), data.read_short(BIG_ENDIAN))
461461

462462
if self.ABILITY_TEAM_FLAG and data.read_bits(1):
@@ -470,15 +470,15 @@ def player_ability_event(self, data, fstamp, pid, event_type):
470470
z = data.read_int(BIG_ENDIAN)
471471
z = (z>>1)/8192.0 * pow(-1, z & 0x1)
472472
unknown = data.read_bits(1)
473-
return TargetAbilityEvent(fstamp, pid, event_type, ability, unit, player, team, (x, y, z))
473+
return TargetAbilityEvent(fstamp, pid, event_type, ability, flags, unit, player, team, (x, y, z))
474474

475475
elif target_type == 3:
476476
unit_id = data.read_int(BIG_ENDIAN)
477477
unknown = data.read_bits(1)
478-
return SelfAbilityEvent(fstamp, pid, event_type, ability, unit_id)
478+
return SelfAbilityEvent(fstamp, pid, event_type, ability, flags, unit_id)
479479

480480
else:
481-
return AbilityEvent(fstamp, pid, event_type, ability)
481+
return AbilityEvent(fstamp, pid, event_type, ability, flags)
482482

483483

484484
class GameEventsReader_18574(GameEventsReader_16561):

0 commit comments

Comments
 (0)