Skip to content

Commit 221fac0

Browse files
committed
Fix several bugs related to the initData file.
There appears to be some element of variability in the distance between the sc_account_id and the map data. Additionally, there are some instances where the map_data isn't even present in the file at all! Adjust the reader as well as the processor to account for these new findings.
1 parent 90b8e65 commit 221fac0

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

sc2reader/processors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ def Full(replay):
88
# TODO: Test this with different levels of file read.
99
# TODO: Change config.py to work with this
1010
# TODO: remove legacy code, restructure config.py: just one processor now
11-
if 'initData' in replay.raw:
12-
replay.realm = replay.raw.initData.realm
11+
if 'initData' in replay.raw and replay.raw.initData.map_data:
12+
replay.realm = replay.raw.initData.map_data[0].realm
1313

1414
if 'details' in replay.raw:
1515
replay.map = replay.raw.details.map
@@ -96,8 +96,8 @@ def Full(replay):
9696
player.actual_race = LOCALIZED_RACES.get(pdata.race, pdata.race)
9797

9898
# We need initData for the realm which is required to build the url!
99-
if 'initData' in replay.raw:
100-
player.realm = replay.raw.initData.realm
99+
if 'initData' in replay.raw and replay.realm:
100+
player.realm = replay.realm
101101

102102
# Conversion instructions to the new color object:
103103
# color_rgba is the color object itself

sc2reader/readers.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,35 @@ def __call__(self,buffer, replay):
1919
# The next block contains information about the structure of the MPQ
2020
# archive. We don't read this information because we've got mpyq for
2121
# that. Its split into 3 sections because of the variable length segment
22-
# in the middle that prevents bulk skipping.
22+
# in the middle that prevents bulk skipping. The last section also
23+
# appears to be variable length, hack it to do a find for the section
24+
# we are looking for.
2325
buffer.skip(24)
2426
sc_account_id = buffer.read_string()
25-
buffer.skip(684)
27+
distance = buffer.read_range(buffer.cursor, buffer.length).find('s2ma')
28+
buffer.skip(distance)
2629

2730
# The final block of this file that we concern ourselves with is a list
2831
# of what appears to be map data with the s2ma header on each element.
2932
# Each element consists of two unknown bytes, a realm id (e.g EU or US)
3033
# and a map hash which probably ties back to the sc2map files.
34+
#
35+
# Some replays don't seem to have a maps section at all, now we can't
36+
# know what region its from? Very strange...
37+
#
38+
# TODO: Figure out how we could be missing a maps section.
3139
map_data = list()
32-
while( buffer.read_chars(4).lower() == 's2ma' ):
40+
while buffer.read_chars(4).lower() == 's2ma':
3341
unknown = buffer.read_chars(2)
3442
realm = buffer.read_string(2).lower()
3543
map_hash = buffer.read_chars(32)
3644
map_data.append(MapData(unknown,realm,map_hash))
3745

38-
# Return the extracted information inside an AttributeDict. Promote the
39-
# realm information to top level for convenience since it is a constant.
46+
# Return the extracted information inside an AttributeDict.
4047
return AttributeDict(
4148
map_data=map_data,
4249
player_names=player_names,
4350
sc_account_id=sc_account_id,
44-
realm=map_data[0].realm
4551
)
4652

4753

0 commit comments

Comments
 (0)