happyleavesaoc / aoc-mgz

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

RuntimeError: bad object parse #85

Closed jdekarske closed 1 year ago

jdekarske commented 2 years ago

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

M1ngXU commented 1 year ago

have you found any fixes for this? like 20% of the games can't be parsed due to this error ...

happyleavesaoc commented 1 year ago

If you use Summary every rec should parse.

M1ngXU commented 1 year ago

But is there a way to still access all the information? Or that these "bad object" can be skipped?

happyleavesaoc commented 1 year ago

Like I said, Summary should do the job for you. You're invoking the fast parser only, which has the failure mode you're observing. If you use Summary (which starts with fast and has a fallback to full --- as the log posted indicates) then everything should work fine (assuming you're parsing supported recs -- MP, no AIs, no scenarios).

M1ngXU commented 1 year ago

ok thanks, but i can get the same information (this issue is not created by me, I’m fetching map, building/techonology and moves information)

happyleavesaoc commented 1 year ago

Yes you can. On a summary object:

map -> get_map() actions -> _actions

M1ngXU commented 1 year ago

Oh ok, thank you very much :)

Edit: is there a way to serialize the summary?

happyleavesaoc commented 1 year ago

Unfortunately you'd have to do that yourself.

M1ngXU commented 1 year ago

Unfortunately you'd have to do that yourself.

how to access the gaia data (from model summary) in full summary (like trees etc.)? i cannot find them in _header and i have no idea where else to search ...

M1ngXU commented 1 year ago

Unfortunately you'd have to do that yourself.

how to access the gaia data (from model summary) in full summary (like trees etc.)? i cannot find them in _header and i have no idea where else to search ...

@happyleavesaoc

happyleavesaoc commented 1 year ago

model:

m= parse_match(...)
m.gaia  # gaia objects found here

full summary:

s = Summary(...)
s.get_objects() # gaia objects found here w/ `player_number` == `None`