Age of Empires II recorded game parsing and summarization in Python 3.

Overview

mgz

Age of Empires II recorded game parsing and summarization in Python 3.

Supported Versions

  • Age of Kings (.mgl)
  • The Conquerors (.mgx)
  • Userpatch 1.4 (.mgz)
  • Userpatch 1.5 (.mgz)
  • HD Edition >= 4.6 (.aoe2record)
  • Definitive Edition (.aoe2record)

Architecture

The core functionality of mgz is a parser that produces a Python data structure based on a recorded game file. It also offers abstracted representations that make it easier to use the data.

Parsers

mgz offers two parsers, fast and full. The fast parser skips data that is rarely needed, while the full parser tries to parse as much as possible. Naturally, the fast parser is faster than the full parser.

Abstractions

Abstractions take parser output as input and return an object with normalized data that is easier to use for most cases. There are two abstractions available, summary and model. The summary abstraction attempts to expose the maximum amount of usable data. The model abstraction is more limited but automatically performs more lookups.

Support

Version model summary fast (header) fast (body) full (header) full (body)
Age of Kings (.mgl)
The Conquerors (.mgx)
Userpatch <= 1.4 (.mgz)
Userpatch 1.5 (.mgz)
HD Edition >= 4.6
HD Edition 5.8
Definitive Edition <= 13.34 (.aoe2record)
Definitive Edition > 13.34 (.aoe2record)

Examples

Full Parser

import os
from mgz import header, body

with open('/path/to/file', '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)

Full Parser (header) + Fast Parser (body)

import os
from mgz import header, fast

with open('/path/to/file', 'rb') as data:
    eof = os.fstat(data.fileno()).st_size
    header.parse_stream(data)
    fast.meta(data)
    while data.tell() < eof:
        fast.operation(data)

Summary

from mgz.summary import Summary

with open('/path/to/file', 'rb') as data:
    s = Summary(data)
    s.get_map()
    s.get_platform()
    # ... etc

Model

from mgz.model import parse_match

with open('/path/to/file', 'rb') as data:
    match = parse_match(data)
    match.map.name
    match.file.perspective.number
    # ... etc

To JSON

import json
from mgz.model import parse_match, serialize

with open('/path/to/file', 'rb') as h:
    match = parse_match(h)
    print(json.dumps(serialize(match), indent=2))

Frequently Asked Questions

Q: Where are the end-of-game achievements/statistics?

A: In the postgame action, available only from Userpatch version.

Q: How can I tell the number of resources/kills/etc at a certain point?

A: You can't, without replaying the match in-game.

Q: How does a recorded game file work?

A: The first portion (the header) is a snapshot of the initial game state. The second portion (the body) is a list of moves made by players. The game loads the header, then applies each move to mutate the state according to the game rules.

Q: How can I install this package?

A: pip install mgz

Contribution

  • Pull requests & patches welcome

Resources

Comments
  • DE saved files aren't parsed correctly

    DE saved files aren't parsed correctly

    I understand DE saved files are kinda unsupported right now, Just wanna offer a corpus of ~250 DE games if that would be useful. Only 10 of my saved files parse without errors. Here is an example of the type of errors I get (each error message is from a different save file):

    invalid mgz file: no decoding mapping for 10
        (parsing) -> lobby
    invalid mgz file: no decoding mapping for 10
        (parsing) -> lobby
    invalid mgz file: no decoding mapping for 10
        (parsing) -> lobby
    invalid mgz file: no decoding mapping for 10
        (parsing) -> lobby
    invalid mgz file: no decoding mapping for 11
        (parsing) -> lobby
    invalid mgz file: no decoding mapping for 11
        (parsing) -> lobby
    invalid mgz file: unspecified builtin map: 124
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: no decoding mapping for 10
        (parsing) -> lobby
    invalid mgz file: expected 16 to 16, found 6
        (parsing) -> scenario -> players
    invalid mgz file: unspecified builtin map: 126
    invalid mgz file: unspecified builtin map: 123
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: no decoding mapping for 10
        (parsing) -> lobby
    invalid mgz file: unspecified builtin map: 123
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: no decoding mapping for 11
        (parsing) -> lobby
    invalid mgz file: no decoding mapping for 11
        (parsing) -> lobby
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: expected 16 to 16, found 4
        (parsing) -> scenario -> players
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: expected 16 to 16, found 0
        (parsing) -> scenario -> players
    invalid mgz file: unspecified builtin map: 0
    invalid mgz file: expected 16 to 16, found 0
        (parsing) -> scenario -> players
    invalid mgz file: could not read enough bytes, expected 1032, found 718
        (parsing) -> scenario -> triggers
    invalid mgz file: could not read enough bytes, expected 65535, found 29825
        (parsing) -> scenario -> messages -> instructions
    invalid mgz file: expected 16 to 16, found 0
        (parsing) -> scenario -> players
    invalid mgz file: could not read enough bytes, expected 32768, found 31170
        (parsing) -> scenario -> messages -> instructions
    invalid mgz file: expected 16 to 16, found 0
        (parsing) -> scenario -> players
    invalid mgz file: expected 16 to 16, found 0
        (parsing) -> scenario -> players
    invalid mgz file: could not read enough bytes, expected 65535, found 29871
        (parsing) -> scenario -> messages -> instructions
    invalid mgz file: could not read enough bytes, expected 12544, found 2515
        (parsing) -> scenario
    invalid mgz file: could not read enough bytes, expected 32768, found 29204
        (parsing) -> scenario -> messages -> instructions
    invalid mgz file: could not read enough bytes, expected 32768, found 27996
        (parsing) -> scenario -> messages -> instructions
    invalid mgz file: could not read enough bytes, expected 32768, found 27167
        (parsing) -> scenario -> messages -> instructions
    invalid mgz file: could not read enough bytes, expected 12544, found 2
        (parsing) -> scenario
    invalid mgz file: expected 16 to 16, found 15
        (parsing) -> scenario -> players
    invalid mgz file: expected 16 to 16, found 10
        (parsing) -> scenario -> players
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: expected 16 to 16, found 0
        (parsing) -> scenario -> players
    invalid mgz file: expected 16 to 16, found 0
        (parsing) -> scenario -> players
    invalid mgz file: expected 16 to 16, found 0
        (parsing) -> scenario -> players
    invalid mgz file: could not read enough bytes, expected 59392, found 40667
        (parsing) -> scenario -> messages -> victory
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: could not read enough bytes, expected 32768, found 31621
        (parsing) -> scenario -> messages -> instructions
    invalid mgz file: expected 16 to 16, found 0
        (parsing) -> scenario -> players
    invalid mgz file: expected 16 to 16, found 0
        (parsing) -> scenario -> players
    invalid mgz file: could not read enough bytes, expected 32768, found 31020
        (parsing) -> scenario -> messages -> instructions
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: could not read enough bytes, expected 32768, found 27266
        (parsing) -> scenario -> messages -> instructions
    invalid mgz file: expected 16 to 16, found 0
        (parsing) -> scenario -> players
    invalid mgz file: could not read enough bytes, expected 32768, found 31179
        (parsing) -> scenario -> messages -> instructions
    invalid mgz file: could not read enough bytes, expected 32768, found 31623
        (parsing) -> scenario -> messages -> instructions
    invalid mgz file: could not read enough bytes, expected 32768, found 30962
        (parsing) -> scenario -> messages -> instructions
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: expected 23 to 23, found 0
        (parsing) -> de -> de -> strings
    invalid mgz file: could not read enough bytes, expected 32768, found 31599
        (parsing) -> scenario -> messages -> instructions
    invalid mgz file: could not read enough bytes, expected 32768, found 27066
        (parsing) -> scenario -> messages -> instructions
    invalid mgz file: could not read enough bytes, expected 12544, found 5855
        (parsing) -> scenario
    invalid mgz file: could not read enough bytes, expected 32768, found 27266
        (parsing) -> scenario -> messages -> instructions
    invalid mgz file: expected 16 to 16, found 1
        (parsing) -> scenario -> players
    

    If it'd be useful, I could upload all of my saves.

    I'll start to study this code myself and see if I can help fix things.

    opened by connorjclark 14
  • RangeError: expected 50 to 50, found 0

    RangeError: expected 50 to 50, found 0

    Tried the following code:

    from mgz import header, body
    from os import fstat
    
    with open('C:\\Users\\rajje\\PycharmProjects\\helloworld\\replay.aoe2record', 'rb') as data:
        eof = fstat(data.fileno()).st_size
        header.parse_stream(data)
        while data.tell() < eof:
            body.operation.parse_stream(data)
    

    Go this error:

    Traceback (most recent call last):
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 1042, in _parse
        obj.append(self.subcon._parse(stream, context._, path))
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 1235, in _parse
        pad = _read_stream(stream, padlen)
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 67, in _read_stream
        data = stream.read(length)
    OverflowError: Python int too large to convert to C ssize_t
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 2784, in _parse
        return self.subcon._parse(stream, context, path)
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 1050, in _parse
        raise RangeError("expected %d to %d, found %d" % (min, max, len(obj)))
    construct.core.RangeError: expected 50 to 50, found 0
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "app.py", line 6, in <module>
        header.parse_stream(data)
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 171, in parse_stream
        return self._parse(stream, context2, "(parsing)")
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 295, in _parse
        return self.subcon._parse(stream, context, path)
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 295, in _parse
        return self.subcon._parse(stream, context, path)
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\mgz\util.py", line 36, in _parse
        return self.subcon._parse(new_stream, context, path)
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 357, in _parse
        return self.subcon.parse(data, context)
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 158, in parse
        return self.parse_stream(BytesIO(data), context, **kw)
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 171, in parse_stream
        return self._parse(stream, context2, "(parsing)")
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "C:\Users\rajje\PycharmProjects\helloworld\venv\lib\site-packages\construct\core.py", line 2788, in _parse
        raise e.__class__("%s\n    %s" % (e, path))
    construct.core.RangeError: expected 50 to 50, found 0
        (parsing) -> map_info
    
    opened by rajjeet 12
  • DE version 25.22 fails on header parse

    DE version 25.22 fails on header parse

    opened by Namek 11
  • Why my recordings can't be parsed?

    Why my recordings can't be parsed?

    Some recordings downloaded from Voobly are working for me but unfortunately, some are not. Including my own.

    This is what happens when I try to load my recording:

    Traceback (most recent call last):
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 506, in _parse
        return packer.unpack(self.fmtstr, _read_stream(stream, self.sizeof()))[0]
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 69, in _read_stream
        raise FieldError("could not read enough bytes, expected %d, found %d" % (length, len(data)))
    construct.core.FieldError: could not read enough bytes, expected 4, found 2
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2784, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 508, in _parse
        raise FieldError("packer %r error during parsing" % self.fmtstr)
    construct.core.FieldError: packer '<f' error during parsing
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 1042, in _parse
        obj.append(self.subcon._parse(stream, context._, path))
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2784, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2784, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2788, in _parse
        raise e.__class__("%s\n    %s" % (e, path))
    construct.core.FieldError: packer '<f' error during parsing
        (parsing) -> initial -> players -> objects -> objects -> properties -> building -> combat -> ai -> ai -> orders -> order -> target_location -> z
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2784, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 1050, in _parse
        raise RangeError("expected %d to %d, found %d" % (min, max, len(obj)))
    construct.core.RangeError: expected 4294918016 to 4294918016, found 35248
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 1042, in _parse
        obj.append(self.subcon._parse(stream, context._, path))
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2784, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 295, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 1594, in _parse
        obj = self.cases.get(key, self.default)._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2784, in _parse
        return self.subcon._parse(stream, context, path)
      File "/mnt/c/aoe2/aoc-mgz/mgz/util.py", line 196, in _parse
        subobj = self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2784, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 295, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2784, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 1594, in _parse
        obj = self.cases.get(key, self.default)._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2784, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 295, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2784, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2784, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 1594, in _parse
        obj = self.cases.get(key, self.default)._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2784, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2788, in _parse
        raise e.__class__("%s\n    %s" % (e, path))
    construct.core.RangeError: expected 4294918016 to 4294918016, found 35248
        (parsing) -> initial -> players -> objects -> objects -> properties -> building -> combat -> ai -> ai -> orders
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2784, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 1050, in _parse
        raise RangeError("expected %d to %d, found %d" % (min, max, len(obj)))
    construct.core.RangeError: expected 6 to 6, found 0
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "test.py", line 6, in <module>
        print(header.parse_stream(data))
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 171, in parse_stream
        return self._parse(stream, context2, "(parsing)")
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 295, in _parse
        return self.subcon._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 295, in _parse
        return self.subcon._parse(stream, context, path)
      File "/mnt/c/aoe2/aoc-mgz/mgz/util.py", line 54, in _parse
        return self.subcon._parse(new_stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 357, in _parse
        return self.subcon.parse(data, context)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 158, in parse
        return self.parse_stream(BytesIO(data), context, **kw)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 171, in parse_stream
        return self._parse(stream, context2, "(parsing)")
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 867, in _parse
        subobj = sc._parse(stream, context, path)
      File "/home/defozo/.local/lib/python3.7/site-packages/construct/core.py", line 2788, in _parse
        raise e.__class__("%s\n    %s" % (e, path))
    construct.core.RangeError: expected 6 to 6, found 0
        (parsing) -> initial
    

    We are using: Game Mod: v1.5 RC | Allied Vision

    You can download the recording here: https://www.voobly.com/files/view/60445255/nfw5tdx83ea9eqmior7wkqsus9zo87ik

    opened by Defozo 11
  • WiC mod support?

    WiC mod support?

    Hi HappyLeaves,

    Do you know if there's something about WiC mod that breaks this parser? I was trying to parse the Clan Masters recs here (for example: http://aoczone.net/viewtopic.php?f=1342&t=123008) and they're all crashing near the end with:

    /root/miniconda3/envs/mgz/lib/python2.7/site-packages/construct/core.pyc in _read_stream(stream, length)
        303     data = stream.read(length)
        304     if len(data) != length:
    --> 305         raise FieldError("expected %d, found %d" % (length, len(data)))
        306     return data
        307 
    
    FieldError: expected 1512, found 4
    

    I'm guessing it may be something to do with achievements since I can't get that action to extract no matter what I do, but I'm not sure exactly.

    opened by coffenbacher 9
  • Current Patch DE Game Loading Error

    Current Patch DE Game Loading Error

    Im working on a data analytics site for a league. Im trying to analyze games with your library but can't seem to get games to load from the newest patch. Your info says that the library works for version 25.02 and earlier. How do these version correspond to game version? Ex. Current version is: 101.101.54684 7486483.

    The error I am getting: `Exception has occurred: RuntimeError (note: full exception trace is shown but execution is paused at: setUpClass) could not parse File "C:\Users\Owner\Git Repos\aoc-mgz\mgz\fast\header.py", line 418, in parse de = parse_de(header, version, save) File "C:\Users\Owner\Git Repos\aoc-mgz\mgz\fast\header.py", line 296, in parse_de lobby = de_string(data) File "C:\Users\Owner\Git Repos\aoc-mgz\mgz\fast\header.py", line 47, in de_string assert data.read(2) == b'\x60\x0a'

    During handling of the above exception, another exception occurred:

    File "C:\Users\Owner\Git Repos\aoc-mgz\mgz\fast\header.py", line 47, in de_string assert data.read(2) == b'\x60\x0a' File "C:\Users\Owner\Git Repos\aoc-mgz\mgz\fast\header.py", line 296, in parse_de lobby = de_string(data) File "C:\Users\Owner\Git Repos\aoc-mgz\mgz\fast\header.py", line 418, in parse de = parse_de(header, version, save) File "C:\Users\Owner\Git Repos\aoc-mgz\mgz\fast\header.py", line 426, in parse raise RuntimeError("could not parse") File "C:\Users\Owner\Git Repos\aoc-mgz\tests\test_fast.py", line 60, in setUpClass (Current frame) cls.data = parse(handle)`

    Let me know if what I'm doing wrong or if the current version of games is not supported.

    Test_Game.zip .0

    opened by ghost 8
  • New aoe2 de recorded files parsing ending early

    New aoe2 de recorded files parsing ending early

    Hi,

    First of all want to thank for for this great work.

    I was trying to parse files in aoe2 de recorded files of the past few days. The parsing is ending early with the last operation being embedded with default consuming the rest of the file (from my understanding). Maybe they added new embedded operation which is not handled right now. I would like to help in anyway.

    Again thanks.

    opened by arunpatala 7
  • Unable to use JSON parser

    Unable to use JSON parser

    The code snippet for the JSON parser doesn't seem to be working. I've got the full parser working but one of the latest DE test files (provided in this repo) is not working with the JSON parser. Here is the error I get:

    /<my_absolute_path>/bin/python /<my_absolute_path>/test.py
    Traceback (most recent call last):
      File "/<my_absolute_path>/lib/python3.9/site-packages/mgz/fast/header.py", line 461, in parse
        de = parse_de(header, version, save)
      File "/<my_absolute_path>/lib/python3.9/site-packages/mgz/fast/header.py", line 338, in parse_de
        de_string(data)
      File "/<my_absolute_path>/lib/python3.9/site-packages/mgz/fast/header.py", line 47, in de_string
        assert data.read(2) == b'\x60\x0a'
    AssertionError
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/<my_absolute_path>/test.py", line 31, in <module>
        match = parse_match(h)
      File "/<my_absolute_path>/lib/python3.9/site-packages/mgz/model/__init__.py", line 93, in parse_match
        data = parse(handle)
      File "/<my_absolute_path>/lib/python3.9/site-packages/mgz/fast/header.py", line 469, in parse
        raise RuntimeError("could not parse")
    RuntimeError: could not parse
    

    For this file: de-26.16.zip

    Is the JSON parser not working yet for this version of DE recordings?

    opened by NathanFlegg 6
  • Unable to run any of the examples provided on the main page

    Unable to run any of the examples provided on the main page

    Hello,

    For some reason, I cannot run any of the examples provided on the main page. Are there special requirements that are not listed? My python version is 3.8.7.
    Here is a simple script that is used to test the five examples and log the error traceback to a file. All you need to change is EXAMPLE = 1|2|3|4|5 in the constants.

    # Imports.
    import mgz
    import os
    
    # Constants.
    PATH = "test.aoe2record"
    EXAMPLE = 5
    
    # Redirect the error to a file.
    with open(f"log_example_{EXAMPLE}.txt", "w") as log_file:
    
        # Open a game and get information.
        try:
            with open(PATH, "rb") as data:
    
                if EXAMPLE == 1:
                    from mgz import header, body
                    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)
    
                elif EXAMPLE == 2:
                    from mgz import header, fast
                    eof = os.fstat(data.fileno()).st_size
                    header.parse_stream(data)
                    fast.meta(data)
                    while data.tell() < eof:
                        fast.operation(data)
    
                elif EXAMPLE == 3:
                    from mgz.summary import Summary
                    s = Summary(data)
                    s.get_map()
                    s.get_platform()
    
                elif EXAMPLE == 4:
                    from mgz.model import parse_match
                    match = parse_match(data)
                    match.map.name
                    match.file.perspective.number
    
                elif EXAMPLE == 5:
                    import json
                    from mgz.model import parse_match, serialize
                    match = parse_match(data)
                    print(json.dumps(serialize(match), indent=2))
    
        except Exception:
            import traceback
            log_file.write(traceback.format_exc())
    

    test.zip contains test.aoe2record.

    Manually looking at the header, this game has the following characteristics:

    data = open(test.aoe2record, "rb")
    from mgz.summary import *
    header = decompress(data)
    version, game, save, log = parse_version(header, data)
    >>> version = <Version.DE: 21>
    >>> game = 'VER 9.4'
    >>> save = 25.22
    >>> log = 5
    

    The 5 tracebacks are here: log_example_1.txt log_example_2.txt log_example_3.txt log_example_4.txt log_example_5.txt

    The 5 top-most errors are:

    construct.core.ConstError: expected b'\x00\x0b' but parsed b'\x00\x00'
    
    construct.core.ConstError: expected b'\x00\x0b' but parsed b'\x00\x00'
    
    construct.core.ConstError: expected b'\x00\x0b' but parsed b'\x00\x00'
    
      File "C:\WPy64-3870\python-3.8.7.amd64\lib\site-packages\mgz\fast\header.py", line 48, in de_string
        assert data.read(2) == b'\x60\x0a'
    AssertionError
    
      File "C:\WPy64-3870\python-3.8.7.amd64\lib\site-packages\mgz\fast\header.py", line 48, in de_string
        assert data.read(2) == b'\x60\x0a'
    AssertionError
    

    Thank you in advance for your help.

    opened by Guimoute 6
  • Faster Parsing

    Faster Parsing

    Hi, I want to parse a lot recorded matches. At the moment parsing one match takes 1-10 seconds on my machine. I think I am already using the fast parsing option.

    I am only interested in game duration and which player has won so I do not need to parse all data.

    Is there a way to speed up the parsing process?

    I have noticed that a large portion of the processing is parsing the map tiles. Can I somehow skip this?

    opened by denniske 6
  • Can't get field 'unit_ids' for 'move' action

    Can't get field 'unit_ids' for 'move' action

    Steps to reproduce:

    • Recorded game used (I've tried with many others and there is the same problem): https://www.voobly.com/files/view/53123676/qnc2045gpo3x3vkyyqks5h526pu725er

    • Code used:

    import sys
    from mgz import header, body
    import pprint
    
    if __name__ == "__main__":
        pp = pprint.PrettyPrinter(indent=4)
        # For each input filename
        for arg in sys.argv[1:]:
            with open(arg, 'rb') as f:
                # Remember end of file
                f.seek(0, 2)
                eof = f.tell()
                f.seek(0)
                # Parse the header
                h = header.parse_stream(f)
                # Parse the body
                while f.tell() < eof:
                    # Parse a body operation
                    o = body.operation.parse_stream(f)
                    if o.type == 'action' and o.action.type == 'move':
                        pp.pprint(o)
    
    

    Problem:
    None of the 'move' action has the field 'unit_ids'

    I see that this field should be present (excepted if moving the same unit as previous command):
    https://github.com/happyleavesaoc/aoc-mgz/blob/master/mgz/body/actions.py#L63

    I'm not fluent in python so please forgive me if I made a simple mistake

    Thanks for your work!

    opened by ElKrist 6
  • RuntimeError: bad object parse

    RuntimeError: bad object parse

    Trying to get the record in json format and I get the following error:

    File "scripts/record2json.py", line 14, in <module>
        match = parse_match(h)
      File "/home//.local/lib/python3.10/site-packages/mgz/model/__init__.py", line 94, in parse_match
        data = parse(handle)
      File "/home//.local/lib/python3.10/site-packages/mgz/fast/header.py", line 498, in parse
        players, mod = parse_players(header, num_players, version)
      File "/home//.local/lib/python3.10/site-packages/mgz/fast/header.py", line 461, in parse_players
        players = [parse_player(header, number, num_players) for number in range(num_players)]
      File "/home//.local/lib/python3.10/site-packages/mgz/fast/header.py", line 461, in <listcomp>
        players = [parse_player(header, number, num_players) for number in range(num_players)]
      File "/home//.local/lib/python3.10/site-packages/mgz/fast/header.py", line 126, in parse_player
        sleeping, end = object_block(data, end, player_number, 1)
      File "/home//.local/lib/python3.10/site-packages/mgz/fast/header.py", line 97, in object_block
        objects.append(dict(parse_object(data, pos), index=index))
      File "/home//.local/lib/python3.10/site-packages/mgz/fast/header.py", line 63, in parse_object
        raise RuntimeError("bad object parse")
    RuntimeError: bad object parse
    

    When using Summary I get the following error:

    could not fast parse; falling back: bad object parse
    

    I can still get some data with Summary though. AgeIIDE_Replay_170.zip

    opened by jdekarske 0
  • RuntimeError: invalid mgz file: expected 3 to 3, found 2

    RuntimeError: invalid mgz file: expected 3 to 3, found 2

    Traceback (most recent call last):
      File "C:\dev\ant_league\backend\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 369, in run_asgi
        result = await app(self.scope, self.receive, self.send)
      File "C:\dev\ant_league\backend\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 59, in __call__
        return await self.app(scope, receive, send)
      File "C:\dev\ant_league\backend\lib\site-packages\fastapi\applications.py", line 208, in __call__
        await super().__call__(scope, receive, send)
      File "C:\dev\ant_league\backend\lib\site-packages\starlette\applications.py", line 112, in __call__
        await self.middleware_stack(scope, receive, send)
      File "C:\dev\ant_league\backend\lib\site-packages\starlette\middleware\errors.py", line 181, in __call__
        raise exc from None
      File "C:\dev\ant_league\backend\lib\site-packages\starlette\middleware\errors.py", line 159, in __call__
        await self.app(scope, receive, _send)
      File "C:\dev\ant_league\backend\lib\site-packages\starlette\middleware\cors.py", line 86, in __call__
        await self.simple_response(scope, receive, send, request_headers=headers)
      File "C:\dev\ant_league\backend\lib\site-packages\starlette\middleware\cors.py", line 142, in simple_response
        await self.app(scope, receive, send)
      File "C:\dev\ant_league\backend\lib\site-packages\starlette\middleware\sessions.py", line 75, in __call__
        await self.app(scope, receive, send_wrapper)
      File "C:\dev\ant_league\backend\lib\site-packages\starlette\exceptions.py", line 82, in __call__
        raise exc from None
      File "C:\dev\ant_league\backend\lib\site-packages\starlette\exceptions.py", line 71, in __call__
        await self.app(scope, receive, sender)
      File "C:\dev\ant_league\backend\lib\site-packages\starlette\routing.py", line 580, in __call__
        await route.handle(scope, receive, send)
      File "C:\dev\ant_league\backend\lib\site-packages\starlette\routing.py", line 241, in handle
        await self.app(scope, receive, send)
      File "C:\dev\ant_league\backend\lib\site-packages\starlette\routing.py", line 52, in app
        response = await func(request)
      File "C:\dev\ant_league\backend\lib\site-packages\fastapi\routing.py", line 219, in app
        raw_response = await run_endpoint_function(
      File "C:\dev\ant_league\backend\lib\site-packages\fastapi\routing.py", line 154, in run_endpoint_function
        return await run_in_threadpool(dependant.call, **values)
      File "C:\dev\ant_league\backend\lib\site-packages\starlette\concurrency.py", line 40, in run_in_threadpool
        return await loop.run_in_executor(None, func, *args)
      File "C:\Users\Namek\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\thread.py", line 57, in run
        result = self.fn(*self.args, **self.kwargs)
      File "C:\dev\ant_league\backend\src\website.py", line 127, in post_match
        match_info = utils.get_match_info(file.file)
      File "C:\dev\ant_league\backend\src\utils.py", line 44, in get_match_info
        s = Summary(data)
      File "c:\dev\ant_league\backend\mgz\mgz\summary\__init__.py", line 85, in __init__
        raise RuntimeError("invalid mgz file: {}".format(e))
    RuntimeError: invalid mgz file: expected 3 to 3, found 2
        (parsing) -> initial
    

    MP_Replay_v101.101.53347.0_2021.09.16_214614_1.zip

    opened by Namek 0
A calculator for common measurements used in sci-fi books.

Sci-fi-speed-calculator A calculator for common measurements used in sci-fi books. Author: Tyler Windmemuth Purpose: This program allows sci-fi author

Tyler Windemuth 0 Apr 22, 2022
A program that makes all 47 textures of Optifine CTM only using 2 textures

A program that makes all 47 textures of Optifine CTM only using 2 textures

1 Jan 22, 2022
3x - This Is 3x Friendlist Cloner Tools

3X FRIENDLIST CLONER TOOLS COMMAND $ apt update $ apt upgrade $ apt install pyth

MAHADI HASAN AFRIDI 2 Jan 17, 2022
A Python package to request and process seismic waveform data from Hi-net.

HinetPy is a Python package to simplify tedious data request, download and format conversion tasks related to NIED Hi-net. NIED Hi-net | Source Code |

Dongdong Tian 65 Dec 09, 2022
A brainfuck-based game oriented language written in python.

GF.py STILL WIP Gamefuck.py is a programming language based off brainfuck. It is oriented towards game development, and as such has many commands spec

Xenon 1 Feb 23, 2022
The program calculates the BMI of people

Programmieren Einleitung: Das Programm berechnet den BMI von Menschen. Es ist sehr einfach zu handhaben, so können alle Menschen ihren BMI berechnen.

2 Dec 16, 2021
Estimate the Market Size for Electic and Plug-In Hybrid Vehicles In Africa

Estimate the Market Size for Electic and Plug-In Hybrid Vehicles In Africa The goal of this repository is to use open data repositories to answer the

Leonce Nshuti 0 Feb 21, 2022
RxPY - The Reactive Extensions for Python (RxPY)

The Reactive Extensions for Python (RxPY) A library for composing asynchronous and event-based programs using observable collections and query operato

ReactiveX 4.4k Dec 29, 2022
A Lynx that manages a group that puts the federation first.

Lynx Super Federation Management Group Lynx was created to manage your groups on telegram and focuses on the Lynx Federation. I made this to root out

Unknown 2 Nov 01, 2022
Lagrange Interpolation Method-Python

Lagrange Interpolation Method-Python The Lagrange interpolation formula is a way to find a polynomial, called Lagrange polynomial, that takes on certa

Motahare Soltani 2 Jul 05, 2022
Regular Expressions - Use regular expressions to detect date format

A list of all the resources used https://regex101.com/ - To test regex https://w

Ravika Nagpal 1 Jan 04, 2022
pydock - Docker-based environment manager for Python

pydock - Docker-based environment manager for Python ⚠️ pydock is still in beta mode, and very unstable. It is not recommended for anything serious. p

Alejandro Piad 16 Sep 18, 2021
A project to work with databases in 4 worksheets, insert, update, select, delete using Python and MySqI

A project to work with databases in 4 worksheets, insert, update, select, delete using Python and MySqI As a small project for school or college hope it is useful

Sina Org 1 Jan 11, 2022
TrackGen - The simplest tropical cyclone track map generator

TrackGen - The simplest tropical cyclone track map generator Usage Each line is a point to be plotted on the map Each field gives information about th

TrackGen 6 Jul 20, 2022
Data Poisoning based on Adversarial Attacks using Non-Robust Features

Data Poisoning based on Adversarial Attacks using Non-Robust Features Usage python main.py [-h] [--gpu | -g GPU] [--eps |-e EPSILON] [--pert | -p PER

Jonathan E. 1 Nov 02, 2021
calculadora financiera hecha en python

Calculadora financiera Calculadora de factores financieros basicos, puede calcular tanto factores como expresiones algebraicas en funcion de dichos fa

crudo 5 Nov 10, 2021
Subcert is an subdomain enumeration tool, that finds all the subdomains from certificate transparency logs.

Subcert Subcert is a subdomain enumeration tool, that finds all the valid subdomains from certificate transparency logs. Table of contents Setup Demo

A3h1nt 59 Dec 16, 2022
Click2call for asterisk with python

Click2call para Asterisk com Python Este projeto disponibiliza uma API construíd

Benedito Marques 1 Jan 17, 2022
Junos PyEZ is a Python library to remotely manage/automate Junos devices.

The repo is under active development. If you take a clone, you are getting the latest, and perhaps not entirely stable code. DOCUMENTATION Official Do

Juniper Networks 623 Dec 10, 2022
Korg Volca Sample uploader for linux.

GnuVolca Korg Volca Sample uploader for linux. GnuVolca Usage Installation Via virtualenv Usage Store all the samples you want to upload on an empty d

Gonzalo Rafuls 12 Oct 11, 2022