22
33from sc2reader .objects import *
44from sc2reader .utils import BIG_ENDIAN ,LITTLE_ENDIAN
5-
5+ from collections import defaultdict
66class 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+
1316class 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
0 commit comments