GraylinKim / sc2reader

A python library that extracts data from various Starcraft II resources to power tools and services for the SC2 community. Who doesn't want to hack on the games they play?
http://sc2reader.readthedocs.org
MIT License
413 stars 85 forks source link

Wrong team number computed for players on MLG maps #133

Closed dsjoerg closed 11 years ago

dsjoerg commented 11 years ago

Very strange!

>>> replay = sc2reader.load_replay("/Users/david/Downloads/MLG Akilon Wastes (1).SC2Replay")
>>> [player.team.number for player in replay.players]
[2, 2]

And yet s2protocol confirms that they're on different teams:

bash-3.2$ python ./s2protocol.py --details ~/Downloads/MLG\ Akilon\ Wastes\ \(1\).SC2Replay 
{'m_campaignIndex': 0,
 'm_description': '',
 'm_difficulty': '',
 'm_imageFilePath': '',
 'm_isBlizzardMap': False,
 'm_playerList': [{'m_color': {'m_a': 255, 'm_b': 255, 'm_g': 66, 'm_r': 0},
                   'm_control': 2,
                   'm_handicap': 100,
                   'm_name': '[iTDSi]<sp/>Element',
                   'm_observe': 0,
                   'm_race': 'Terran',
                   'm_result': 2,
                   'm_teamId': 1,
                   'm_toon': {'m_id': 3996787,
                              'm_programId': '\x00\x00S2',
                              'm_realm': 1,
                              'm_region': 1},
                   'm_workingSetSlotId': 1},
                  {'m_color': {'m_a': 255, 'm_b': 30, 'm_g': 20, 'm_r': 180},
                   'm_control': 2,
                   'm_handicap': 100,
                   'm_name': '[orae]<sp/>SaintEaon',
                   'm_observe': 0,
                   'm_race': 'Protoss',
                   'm_result': 1,
                   'm_teamId': 0,
                   'm_toon': {'m_id': 2791980,
                              'm_programId': '\x00\x00S2',
                              'm_realm': 1,
                              'm_region': 1},
                   'm_workingSetSlotId': 13}],
 'm_thumbnail': {'m_file': 'Minimap.tga'},
 'm_timeLocalOffset': -144000000000,
 'm_timeUTC': 130147656551297411,
 'm_title': 'MLG Akilon Wastes*'}

This is not so important for GGTracker, it caused 18 replay processing failures in the past month, out of >100k. However, if it's a bug, fixing it might have beneficial repercussions elsewhere.

(Replays attached here as image, just rename them) mlg akilon wastes 1 sc2replay mlg star station 2 sc2replay

dsjoerg commented 11 years ago

and sc2gears and drop.sc also think they're on the same team.

GraylinKim commented 11 years ago

In sc2reader (and sc2gears I would guess) we get the team from replay.attributes.events using the 2002-2018 attributes:

2002: [{'attrid': 2002, 'namespace': 999, 'value': 'T2'}],
2003: [{'attrid': 2003, 'namespace': 999, 'value': 'T2'}],
2004: [{'attrid': 2004, 'namespace': 999, 'value': 'T2'}],
2005: [{'attrid': 2005, 'namespace': 999, 'value': 'T2'}],
2006: [{'attrid': 2006, 'namespace': 999, 'value': 'T2'}],
2007: [{'attrid': 2007, 'namespace': 999, 'value': 'T2'}],
2008: [{'attrid': 2008, 'namespace': 999, 'value': 'T2'}],
2011: [{'attrid': 2011, 'namespace': 999, 'value': 'T2'}],
2018: [{'attrid': 2018, 'namespace': 999, 'value': 'T2'}],

Each of these attributes has an entry for each player and in my experience the value after the T has always been the team number. In the attached replays it seems to not be the case.

We should switch to using the teamId from the details file, I wasn't aware that there was such a field in there until just now.

GraylinKim commented 11 years ago

This might not actually work like we thought it did @dsjoerg. See Blizzard/s2protocol#17

It seems that the team assignment might work and that the result field is misleading but I'm going to leave this open until we have some resolution.

GraylinKim commented 11 years ago

Actually, teams definitely doesn't seem to work as expected. Pushed a test to demonstrate the issue (2140fab2dbbce3e441b794224ecb8042c37ddcac).