Skip to content
Browse files

Fix initData parsing for all builds.

  • Loading branch information...
1 parent aac4a6b commit 012fb737a37e22e12715bda063f90640c2a9deac @GraylinKim committed Mar 10, 2013
Showing with 47 additions and 6 deletions.
  1. +45 −5 sc2reader/readers.py
  2. +2 −1 sc2reader/resources.py
View
50 sc2reader/readers.py
@@ -36,6 +36,47 @@ def __call__(self, data, replay):
observe = data.read_bits(2),
) for i in range(data.read_bits(5))
],
+ )
+
+ distance = data.read_range(data.tell(), data.length).find('s2ma')
+ data.read_aligned_bytes(distance)
+
+ # The final block of this file that we concern ourselves with is a list
+ # of what appears to be map data with the s2ma header on each element.
+ # Each element consists of two unknown bytes, a realm id (e.g EU or US)
+ # and a map hash which probably ties back to the sc2map files.
+ #
+ # Some replays don't seem to have a maps section at all, now we can't
+ # know what gateway its from? Very strange...
+ #
+ # TODO: Figure out how we could be missing a maps section.
+ map_data = list()
+ while data.peek(4) == 's2ma':
+ map_data.append(DepotFile(data.read_aligned_bytes(40)))
+
+ return AttributeDict(
+ map_data=map_data,
+ player_names=[d['name'] for d in init_data['player_init_data'] if d['name']],
+ sc_account_id=None,#sc_account_id,
+ )
+
+class InitDataReader_23260(Reader):
+
+ def __call__(self, data, replay):
+ data = BitPackedDecoder(data)
+
+ init_data = dict( #58
+ player_init_data = [dict( #38
+ name = data.read_aligned_bytes(data.read_uint8()),
+ random_seed = data.read_uint32(),
+ race_preference = data.read_uint8() if data.read_bool() else None, #38
+ team_preference = data.read_uint8() if data.read_bool() else None, #39
+ test_map = data.read_bool(),
+ test_auto = data.read_bool(),
+ examine = data.read_bool(),
+ observe = data.read_bits(2),
+ ) for i in range(data.read_bits(5))
+ ],
game_description = dict( # 48
random_value = data.read_uint32(), # 4
@@ -83,8 +124,7 @@ def __call__(self, data, replay):
is_blizzardMap = data.read_bool(),
is_premade_ffa = data.read_bool(),
),
- )
- """ # For builds <= 1.5.4 this won't work.
+
lobby_state = dict( #56
phase = data.read_bits(3),
max_users = data.read_bits(5),
@@ -98,17 +138,17 @@ def __call__(self, data, replay):
difficulty = data.read_bits(6),
handicap = data.read_bits(7),
observe = data.read_bits(2),
- rewards = [data.read_uint32() for i in range(data.read_bits(6))],
+ rewards = [data.read_uint32() for i in range(data.read_bits(5))], # 52
toon_handle = data.read_aligned_bytes(data.read_bits(7)), # 14
- licenses = [data.read_uint32() for i in range(data.read_bits(9))], # 56
+ licenses = [data.read_uint32() for i in range(data.read_bits(9))], # 53
) for i in range(data.read_bits(5))], # 58
random_seed = data.read_uint32(),
host_user_id = data.read_bits(4) if data.read_bool() else None, # 52
is_single_player = data.read_bool(), # 27
game_duration = data.read_uint32(), # 4
default_difficulty = data.read_bits(6), # 1
),
- )"""
+ )
return AttributeDict(
map_data=init_data['game_description']['cache_handles'],
View
3 sc2reader/resources.py
@@ -549,7 +549,8 @@ def register_default_readers(self):
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_Base(), lambda r: r.build < 23260)
+ self.register_reader('replay.initData', readers.InitDataReader_23260(), lambda r: r.build >= 23260 and 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.versions[1]==1)
self.register_reader('replay.message.events', readers.MessageEventsReader_Beta_24247(), lambda r: r.build >= 24247 and r.versions[1]==2)

0 comments on commit 012fb73

Please sign in to comment.
Something went wrong with that request. Please try again.