happyleavesaoc / aoc-mgz

Age of Empires II recorded game parsing and summarization in Python 3.
MIT License
197 stars 41 forks source link

construct.core.MappingError - Same error consistently #77

Closed benglle closed 2 years ago

benglle commented 2 years ago

I keep getting the following error with any example I attempt using. I have nothing really to offer other than pointing out the obvious that the error I'm getting is occurring when I call the methods from mgz. I've tried to get around this by installing the latest version on github, and through pypi. Both versions of this library seem to have the exact same error which is shown below after a few notes:

Notes: I've tried both having the aoe2 save game file in the same folder as my python program (in case the spaces in the directory cause any issue), and I've also used the directory of file in the actual aoe2 save folder.

Traceback (most recent call last):
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 2844, in _decode
    return self.decoding[obj]
KeyError: 8

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 2784, in _parse
    return self.subcon._parse(stream, context, path)
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 867, in _parse
    subobj = sc._parse(stream, context, path)
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 311, in _parse
    return self._decode(self.subcon._parse(stream, context, path), context)
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 2849, in _decode
    raise MappingError("no decoding mapping for %r" % (obj,))
construct.core.MappingError: no decoding mapping for 8

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\barke\OneDrive\Desktop\aoe2_stats_parser\parser.py", line 8, in <module>
    header.parse_stream(data)
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 171, in parse_stream
    return self._parse(stream, context2, "(parsing)")
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 867, in _parse
    subobj = sc._parse(stream, context, path)
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 295, in _parse
    return self.subcon._parse(stream, context, path)
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 867, in _parse
    subobj = sc._parse(stream, context, path)
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 295, in _parse
    return self.subcon._parse(stream, context, path)
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\mgz\util.py", line 58, in _parse
    return self.subcon._parse(new_stream, context, path)
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 357, in _parse
    return self.subcon.parse(data, context)
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 158, in parse
    return self.parse_stream(BytesIO(data), context, **kw)
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 171, in parse_stream
    return self._parse(stream, context2, "(parsing)")
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 867, in _parse
    subobj = sc._parse(stream, context, path)
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 2784, in _parse
    return self.subcon._parse(stream, context, path)
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 1594, in _parse
    obj = self.cases.get(key, self.default)._parse(stream, context, path)
  File "C:\Users\barke\AppData\Local\Programs\Python\Python310\lib\site-packages\construct\core.py", line 2788, in _parse
    raise e.__class__("%s\n    %s" % (e, path))
construct.core.MappingError: no decoding mapping for 8
    (parsing) -> de -> de

Here's my code that I'm using, although if I use any of the examples - none of them work.

import os
from mgz import header, body

PATH = 'example.aoe2record'

with open(PATH, 'rb') as data:
    eof = os.fstat(data.fileno()).st_size
    header.parse_stream(data)
    body.meta.parse_stream(data)
    while data.tell() < eof:
        body.operation.parse_stream(data)
benglle commented 2 years ago

I've identified the issue, which is that the new DLC for aoe2 means this latest version is not compatible yet. I've tried a save example given, and it works perfectly.

happyleavesaoc commented 2 years ago

FYI, new DLC is now supported.