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

How to distinguish HotS replays from WoL replays #97

Closed dsjoerg closed 11 years ago

dsjoerg commented 11 years ago

WoL is now on version 2.0.4.24944 as of today. HotS continues to be on version 2.0.3.24764.

Here's a WoL 2.0.4.24944 replay: http://ggtracker.com/matches/1785997

Using the version number is probably already wrong. In the HotS beta, even now, you can go to Options->Gameplay and pick Expansion Level: Wings of Liberty.

So people can play Wings of Liberty games using the HotS client.

Presumably there is some other indicator inside the replay to say which version of the game is being played.

This will be mission-critical for GGTracker soon as in statistics we don't want to mix WoL and HotS.

GraylinKim commented 11 years ago

Agreed, the version number is already wrong. I think for this we're going to have to fall back to map dependencies information. Specifically:

>>> import sc2reader
>>> from xml.etree import ElementTree

>>> hots = sc2reader.load_replay('hots.SC2Replay', load_map=True)
>>> hots_xml = ElementTree.fromstring(hots.map.archive.read_file('DocumentInfo'))
>>> [value.text for value in hots_xml.findall('Dependencies/Value')]
['bnet:Swarm (Mod)/0.0/999,file:Mods/Swarm.SC2Mod']

>>> wol = sc2reader.load_replay('wol.SC2Replay', load_map=True)
>>> wol_xml = ElementTree.fromstring(wol.map.archive.read_file('DocumentInfo'))
>>> [value.text for value in wol_xml.findall('Dependencies/Value')]
['bnet:Liberty (Mod)/0.0/999,file:Mods/Liberty.SC2Mod']

It may also be reasonable to do this at the replay level by looking for Swarm (Mod) in the list of map resources found here:

replay.raw_data['replay.details'].unknown7

I'll try to implement something along these lines soon.

alexhanh commented 11 years ago

+1

GraylinKim commented 11 years ago

Okay, I'm pushing out an improved fix that doesn't involve fetching dependencies from the depots. Instead it takes advantage of the depot convention of naming files by the sha256 digest their contents. From what I can tell, HotS games depend on 'Standard Data: Swarm.SC2Mod' and WoL games depend on 'Standard Data: Liberty.SC2Mod'.

if hashlib.sha256('Standard Data: Swarm.SC2Mod').hexdigest() in dependency_hashes:
    self.expansion = 'HotS'
elif hashlib.sha256('Standard Data: Liberty.SC2Mod').hexdigest() in dependency_hashes:
    self.expansion = 'WoL'
else:
    self.expansion = ''

I'm pushing this out in the next batch of commits.

dsjoerg commented 11 years ago

Outstanding, thank you!