Permalink
Browse files

Fix #97 and #103. Fix resource.expansion values.

  • Loading branch information...
1 parent 0dec991 commit ffd010b65d1a191bbfe63173d0fce16fe8d51fbe @GraylinKim committed Mar 7, 2013
Showing with 46 additions and 24 deletions.
  1. +2 −2 sc2reader/events.py
  2. +4 −4 sc2reader/readers.py
  3. +21 −18 sc2reader/resources.py
  4. +16 −0 test_replays/test_all.py
  5. +3 −0 test_s2gs/test_all_s2gs.py
View
@@ -17,15 +17,15 @@ def __init__(self, frame, pid):
# self.time = Length(seconds=self.second)
def load_context(self, replay):
- if replay.expansion == 'WoL' or replay.build < 24247:
+ if replay.versions[1]==1 or (replay.versions[1]==2 and replay.build < 24247):
if self.pid <= len(replay.people):
self.player = replay.person[self.pid]
elif self.pid != 16:
self.logger.error("Bad pid ({0}) for event {1} at {2}.".format(self.pid, self.__class__, Length(seconds=self.second)))
else:
pass # This is a global event
- elif replay.expansion == 'HotS':
+ else:
if self.pid < len(replay.clients):
self.player = replay.client[self.pid]
elif self.pid != 16:
View
@@ -122,7 +122,7 @@ class AttributesEventsReader_17326(AttributesEventsReader_Base):
class DetailsReader_Base(Reader):
PlayerData = namedtuple('PlayerData',['name','bnet','race','color','unknown1','unknown2','handicap','unknown3','result'])
- Details = namedtuple('Details',['players','map','unknown1','unknown2','os','file_time','utc_adjustment','unknown4','unknown5','unknown6','unknown7','unknown8','unknown9','unknown10'])
+ Details = namedtuple('Details',['players','map','unknown1','unknown2','os','file_time','utc_adjustment','unknown4','unknown5','unknown6','dependencies','unknown8','unknown9','unknown10'])
def __call__(self, data, replay):
# The entire details file is just a serialized data structure
@@ -183,16 +183,16 @@ def __call__(self, data, replay):
player = self.PlayerData(*ordered_values(pdata))
players.append(player)
details[0] = players
-
+ details[10] = [DepotFile(bytes) for bytes in details[10]]
# As a final touch, label all extracted information using the Details
# named tuple from objects.py
return self.Details(*ordered_values(details))
class DetailsReader_22612(DetailsReader_Base):
- Details = namedtuple('Details',['players','map','unknown1','unknown2','os','file_time','utc_adjustment','unknown4','unknown5','unknown6','unknown7','unknown8','unknown9','unknown10', 'unknown11'])
+ Details = namedtuple('Details',['players','map','unknown1','unknown2','os','file_time','utc_adjustment','unknown4','unknown5','unknown6','dependencies','unknown8','unknown9','unknown10', 'unknown11'])
class DetailsReader_Beta(DetailsReader_Base):
- Details = namedtuple('Details',['players','map','unknown1','unknown2','os','file_time','utc_adjustment','unknown4','unknown5','unknown6','unknown7','unknown8','unknown9','unknown10', 'unknown11', 'unknown12'])
+ Details = namedtuple('Details',['players','map','unknown1','unknown2','os','file_time','utc_adjustment','unknown4','unknown5','unknown6','dependencies','unknown8','unknown9','unknown10', 'unknown11', 'unknown12'])
class DetailsReader_Beta_24764(DetailsReader_Beta):
PlayerData = namedtuple('PlayerData',['name','bnet','race','color','unknown1','unknown2','handicap','unknown3','result','unknown4'])
View
@@ -70,10 +70,6 @@ class Replay(Resource):
#: The game speed: Slower, Slow, Normal, Fast, Faster
speed = str()
- #: The operating system the replay was recorded on.
- #: Useful for interpretting certain kind of raw data.
- os = str()
-
#: Deprecated, use :attr:`game_type` or :attr:`real_type` instead
type = str()
@@ -203,7 +199,6 @@ def __init__(self, replay_file, filename=None, load_level=4, **options):
self.other_people = set()
self.speed = ""
self.type = ""
- self.os = str()
self.game_type = ""
self.real_type = ""
self.category = ""
@@ -298,13 +293,13 @@ def load_details(self):
self.map_name = details.map
- # Keep this theory for now but it seems like it could be wrong
- if details.os == 0:
- self.os = "Windows"
- elif details.os == 1:
- self.os = "Mac"
+ dependency_hashes = [d.hash for d in details.dependencies]
+ 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:
- raise ValueError("Unknown operating system {0} detected.".format(details.os))
+ self.expansion = ''
self.windows_timestamp = details.file_time
self.unix_timestamp = utils.windows_to_unix(self.windows_timestamp)
@@ -537,22 +532,22 @@ def register_datapack(self, datapack, filterfunc=lambda r: True):
def register_default_readers(self):
"""Registers factory default readers."""
self.register_reader('replay.details', readers.DetailsReader_Base(), lambda r: r.build < 22612)
- self.register_reader('replay.details', readers.DetailsReader_22612(), lambda r: r.build >= 22612 and r.expansion=='WoL')
- self.register_reader('replay.details', readers.DetailsReader_Beta(), lambda r: r.build < 24764 and r.expansion=='HotS')
+ self.register_reader('replay.details', readers.DetailsReader_22612(), lambda r: r.build >= 22612 and r.versions[1]==1)
+ self.register_reader('replay.details', readers.DetailsReader_Beta(), lambda r: r.build < 24764 and r.versions[1]==2)
self.register_reader('replay.details', readers.DetailsReader_Beta_24764(), lambda r: r.build >= 24764)
self.register_reader('replay.initData', readers.InitDataReader_Base(), lambda r: r.build < 24764)
self.register_reader('replay.initData', readers.InitDataReader_24764(), lambda r: r.build >= 24764)
- self.register_reader('replay.message.events', readers.MessageEventsReader_Base(), lambda r: r.build < 24247 or r.expansion=='WoL')
- self.register_reader('replay.message.events', readers.MessageEventsReader_Beta_24247(), lambda r: r.build >= 24247 and r.expansion=='HotS')
+ self.register_reader('replay.message.events', readers.MessageEventsReader_Base(), lambda r: r.build < 24247 or r.versions[1]==1)
+ self.register_reader('replay.message.events', readers.MessageEventsReader_Beta_24247(), lambda r: r.build >= 24247 and r.versions[1]==2)
self.register_reader('replay.attributes.events', readers.AttributesEventsReader_Base(), lambda r: r.build < 17326)
self.register_reader('replay.attributes.events', readers.AttributesEventsReader_17326(), lambda r: r.build >= 17326)
self.register_reader('replay.game.events', readers.GameEventsReader_16117(), lambda r: 16117 <= r.build < 16561)
self.register_reader('replay.game.events', readers.GameEventsReader_16561(), lambda r: 16561 <= r.build < 18574)
self.register_reader('replay.game.events', readers.GameEventsReader_18574(), lambda r: 18574 <= r.build < 19595)
self.register_reader('replay.game.events', readers.GameEventsReader_19595(), lambda r: 19595 <= r.build < 22612)
- self.register_reader('replay.game.events', readers.GameEventsReader_22612(), lambda r: 22612 <= r.build and r.expansion=='WoL')
- self.register_reader('replay.game.events', readers.GameEventsReader_Beta(), lambda r: r.expansion=='HotS' and r.build < 23925)
- self.register_reader('replay.game.events', readers.GameEventsReader_Beta_23925(), lambda r: r.expansion=='HotS' and 23925 <= r.build)
+ self.register_reader('replay.game.events', readers.GameEventsReader_22612(), lambda r: 22612 <= r.build and r.versions[1]==1)
+ self.register_reader('replay.game.events', readers.GameEventsReader_Beta(), lambda r: r.versions[1]==2 and r.build < 23925)
+ self.register_reader('replay.game.events', readers.GameEventsReader_Beta_23925(), lambda r: r.versions[1]==2 and 23925 <= r.build)
def register_default_datapacks(self):
@@ -747,6 +742,14 @@ def __init__(self, summary_file, filename=None, lang='enUS', **options):
self.load_player_stats()
self.load_players()
+ dependencies = [sheet[1] for sheet in self.lang_sheets['enUS']]
+ if 'Swarm (Mod)' in dependencies:
+ self.expansion = 'HotS'
+ elif 'Liberty (Mod)' in dependencies:
+ self.expansion = 'WoL'
+ else:
+ self.expansion = ''
+
self.game_type = self.settings['Teams'].replace(" ","")
self.real_type = real_type(self.teams.values())
View
@@ -16,6 +16,7 @@
def test_standard_1v1():
replay = sc2reader.load_replay("test_replays/1.2.2.17811/1.SC2Replay")
+ assert replay.expansion == 'WoL'
assert str(replay.length) == "32.47"
assert replay.map_name == "Lost Temple"
assert replay.build == 17811
@@ -82,6 +83,7 @@ def test_standard_1v1():
def test_private_category():
replay = sc2reader.load_replay("test_replays/1.2.2.17811/2.SC2Replay")
+ assert replay.expansion == 'WoL'
assert replay.is_private == True
assert replay.is_ladder == False
@@ -137,8 +139,11 @@ def test_us_realm():
# Waiting for response https://github.com/arkx/mpyq/issues/closed#issue/7
def test_kr_realm_and_tampered_messages():
replay = sc2reader.load_replay("test_replays/1.1.3.16939/11.SC2Replay")
+ assert replay.expansion == 'WoL'
+
first = next(player for player in replay.players if player.name == '명지대학교')
second = next(player for player in replay.players if player.name == '티에스엘사기수')
+
assert first.url == "http://kr.battle.net/sc2/en/profile/258945/1/명지대학교/"
assert second.url == "http://kr.battle.net/sc2/en/profile/102472/1/티에스엘사기수/"
@@ -190,6 +195,8 @@ def test_hots_pids():
print "Processing {fname}".format(fname=replayfilename)
replay = sc2reader.load_replay(replayfilename)
+ assert replay.expansion == 'HotS'
+
player_pids = set( [ player.pid for player in replay.players if player.is_human] )
ability_pids = set( [ event.player.pid for event in replay.events if 'AbilityEvent' in event.name ] )
@@ -198,6 +205,8 @@ def test_hots_pids():
def test_wol_pids():
replay = sc2reader.load_replay("test_replays/1.5.4.24540/ggtracker_1471849.SC2Replay")
+ assert replay.expansion == 'WoL'
+
ability_pids = set( [ event.player.pid for event in replay.events if 'AbilityEvent' in event.name ] )
player_pids = set( [ player.pid for player in replay.players ] )
@@ -212,10 +221,13 @@ def test_hots_hatchfun():
def test_hots_vs_ai():
replay = sc2reader.load_replay("test_replays/2.0.0.24247/Cloud Kingdom LE (13).SC2Replay")
+ assert replay.expansion == 'HotS'
replay = sc2reader.load_replay("test_replays/2.0.0.24247/Korhal City (19).SC2Replay")
+ assert replay.expansion == 'HotS'
def test_oracle_parsing():
replay = sc2reader.load_replay("test_replays/2.0.3.24764/ggtracker_1571740.SC2Replay")
+ assert replay.expansion == 'HotS'
oracles = [unit for unit in replay.objects.values() if unit.name=='Oracle']
assert len(oracles) == 2
@@ -224,10 +236,14 @@ def test_resume_from_replay():
def test_clan_players():
replay = sc2reader.load_replay("test_replays/2.0.4.24944/Lunar Colony V.SC2Replay")
+ assert replay.expansion == 'WoL'
assert len(replay.people) == 4
def test_WoL_204():
replay = sc2reader.load_replay("test_replays/2.0.4.24944/ggtracker_1789768.SC2Replay")
+ assert replay.expansion == 'WoL'
assert len(replay.people) == 2
+
+def test_send_resources():
replay = sc2reader.load_replay("test_replays/2.0.4.24944/Backwater Complex (15).SC2Replay")
@@ -14,11 +14,13 @@ def test_a_WoL_s2gs():
summary = sc2reader.load_game_summary("test_s2gs/s2gs1.s2gs")
assert summary.players[0].resource_collection_rate == 1276
assert summary.players[0].build_order[0].order == 'Probe'
+ assert summary.expansion == 'WoL'
def test_a_HotS_s2gs():
summary = sc2reader.load_game_summary("test_s2gs/hots1.s2gs")
assert summary.players[0].resource_collection_rate == 1599
assert summary.players[0].build_order[0].order == 'SCV'
+ assert summary.expansion == 'HotS'
def test_another_HotS_s2gs():
summary = sc2reader.load_game_summary("test_s2gs/hots2.s2gs")
@@ -29,4 +31,5 @@ def test_another_HotS_s2gs():
assert summary.players[0].apm == 204
assert summary.players[0].workers_active_graph.as_points()[8][1] == 25
assert summary.players[0].upgrade_spending_graph.as_points()[8][1] == 300
+ assert summary.expansion == 'HotS'

0 comments on commit ffd010b

Please sign in to comment.