Skip to content

Commit e6a485f

Browse files
committed
Refactoring 18574 for clarity. Also backports some commandcard fixes.
1 parent 687cae2 commit e6a485f

File tree

1 file changed

+76
-4
lines changed

1 file changed

+76
-4
lines changed

sc2reader/readers.py

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,15 +594,24 @@ def right_click_move(self, buffer, frames, type, code, pid, flag, atype):
594594

595595

596596
class GameEventsReader_18574(GameEventsReader_16561):
597+
def cancel(self, buffer, frames, type, code, pid, flag, atype):
598+
ability = buffer.read_short(endian=BIG_ENDIAN)
599+
ability = ability << 8 | buffer.read_byte()
600+
601+
# creation autoid number / object id
602+
created_id = buffer.read_object_id()
603+
# TODO : expose the id
604+
return AbilityEvent(frames, pid, type, code, ability)
605+
597606
def parse_ability_event(self, buffer, frames, type, code, pid):
598607
"""Moves the right click move to the top level"""
599608
flag = buffer.read_byte()
600609
atype = buffer.read_byte()
601610

602-
if atype & 0x20: # command card
611+
if atype & 0x20: # cancels only now
612+
return self.cancel(buffer, frames, type, code, pid, flag, atype)
613+
elif atype & 0x40: # all command card abilities?
603614
return self.command_card(buffer, frames, type, code, pid, flag, atype)
604-
elif atype & 0x40: # location/move ??
605-
return self.location_move(buffer, frames, type, code, pid, flag, atype)
606615
elif atype & 0x80: # right-click on target?
607616
return self.right_click_target(buffer, frames, type, code, pid, flag, atype)
608617
elif atype < 0x10: #new to patch 1.3.3, location now??
@@ -612,14 +621,77 @@ def parse_ability_event(self, buffer, frames, type, code, pid):
612621

613622
def right_click_move(self, buffer, frames, type, code, pid, flag, atype):
614623
# This may port back to previous versions. Haven't checked
615-
# 10 bytes total, coordinates have a different format?
624+
# Can differ by up to (+/-1, +/-8) from sc2gears readings
625+
# See command_card implementation for details
616626
x = buffer.read_short(BIG_ENDIAN)/256.0
617627
buffer.shift(5) # what is this for, why 5 bits instead of 4?
618628
y = buffer.read_short(BIG_ENDIAN)/256.0
619629
buffer.read(bits=5) # I'll just assume we should do it again
620630
buffer.skip(4)
621631
return LocationAbilityEvent(frames, pid, type, code, 0x3601, (x,y))
622632

633+
def command_card(self, buffer, frames, type, code, pid, flag, atype):
634+
# ability flags one longer now and shifted << 1
635+
ability = buffer.read_short(endian=BIG_ENDIAN)
636+
ability = ability << 8 | buffer.shift(7)
637+
638+
if ability & 0x20:
639+
# Matches sc2gears, but has crazy alignments. Example:
640+
# 0c210b0440002a20b000546ab600007c3f
641+
# 88.0,87.3 ~ (0x58,0x57)
642+
# 20 0 010000
643+
# b0 10110000
644+
# 00 00000000
645+
# 54 01010100
646+
# 6a 01101010
647+
# b6 10110110
648+
#
649+
# 00000000. |
650+
# 1011000.0 |
651+
# 0.0000000 |
652+
# 01011000.0000000 |
653+
#
654+
# 01010100. |
655+
# 011.01010 |
656+
# . 10110110 |
657+
#
658+
# TODO: Check if these are actually (somehow) the right numbers
659+
#x = ((buffer.shift(1) << 23) | (buffer.read_byte() << 15) | (buffer.read_byte() << 9)
660+
#y = (buffer.read_byte() << 16) | (buffer.read_byte() << 11) | (buffer.read_byte() << 2)
661+
#x = x/2.0**16
662+
#y = y/2.0**16
663+
#buffer.skip(4)
664+
#
665+
# This doesn't match sc2gears, but makes a hell of a lot more sense
666+
# 0c210b0440002a20b000546ab600007c3f
667+
# (Xx/256.0, Yy/256.0)
668+
#
669+
# 20 X 010000
670+
# b0 XXXXXXXx
671+
# 00 ?xxxxxxx
672+
# 54 YYYY????
673+
# 6a YYYYyyyy
674+
# b6 ????yyyy
675+
#
676+
# Can differ by up to (+/-1, +/-8) from sc2gears readings
677+
x = buffer.read_short(BIG_ENDIAN)/256.0
678+
buffer.read(bits=5) # what is this for?
679+
y = buffer.read_short(BIG_ENDIAN)/256.0
680+
buffer.read(bits=4) # I'll just assume we should do it again
681+
buffer.skip(4)
682+
return LocationAbilityEvent(frames, pid, type, code, ability, (x,y))
683+
684+
elif ability & 0x40:
685+
buffer.read_short()
686+
target = (buffer.read_int(BIG_ENDIAN),buffer.read_short(BIG_ENDIAN))
687+
buffer.skip(10)
688+
return TargetAbilityEvent(frames, pid, type, code, ability, target)
689+
690+
else:
691+
pass
692+
693+
return UnknownLocationAbilityEvent(frames, pid, type, code, ability)
694+
623695

624696
class GameEventsReader_19595(GameEventsReader_18574):
625697
def location_move(self, buffer, frames, type, code, pid, flag, atype):

0 commit comments

Comments
 (0)