Skip to content

Commit

Permalink
jump before object section in players parsing in fast header parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Void / aoe2insights.com committed Jul 27, 2023
1 parent c479f89 commit d036a89
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mgz/fast/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,22 @@ def parse_player(header, player_number, num_players, save):
end += 10
if data[end:end + 2] == BLOCK_END:
end += 2
header.seek(offset + end)

device = 0
if save >= 37:
# sometimes the object parsing is a bit buggy and i can't figure out why, so we skip back before the object
# block and search from there for `player_end`.
header.seek(offset)
offset = header.tell()
data = header.read(100)
data = header.read()
# Jump to the end of player data
player_end = re.search(b'\xff\xff\xff\xff\xff\xff\xff\xff.\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0b', data)
if not player_end:
raise RuntimeError("could not find player end")
device = data[8]
header.seek(offset + player_end.end())
else:
header.seek(offset + end)

return dict(
number=player_number,
Expand Down
Binary file added tests/recs/de-50.6-objects-bug.aoe2record
Binary file not shown.
15 changes: 15 additions & 0 deletions tests/test_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ def test_players(self):
self.assertEqual(len(players), 3)


class TestFastDEObjectsBug(unittest.TestCase):

@classmethod
def setUpClass(cls):
with open('tests/recs/de-50.6-objects-bug.aoe2record', 'rb') as handle:
cls.data = parse(handle)

def test_version(self):
self.assertEqual(self.data['version'], Version.DE)

def test_players(self):
players = self.data.get('players')
self.assertEqual(len(players), 9)


class TestFastHD(unittest.TestCase):

@classmethod
Expand Down

0 comments on commit d036a89

Please sign in to comment.