hohav / py-slippi

Python library for parsing SSBM replay files
MIT License
56 stars 25 forks source link

ParseError: Unexpected Event Type: 0x55 #18

Closed blink1415 closed 4 years ago

blink1415 commented 4 years ago

Some games give the following error upon running Game("filename.slp"):

  File "/home/blink/.local/lib/python3.8/site-packages/slippi/parse.py", line 64, in _parse_event
    try: size = payload_sizes[code]
KeyError: 85

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/blink/.local/lib/python3.8/site-packages/slippi/parse.py", line 207, in parse
    _parse(f, handlers)
  File "/home/blink/.local/lib/python3.8/site-packages/slippi/parse.py", line 182, in _parse
    _parse_events(stream, payload_sizes, handlers)
  File "/home/blink/.local/lib/python3.8/site-packages/slippi/parse.py", line 116, in _parse_events
    event = _parse_event(stream, payload_sizes)
  File "/home/blink/.local/lib/python3.8/site-packages/slippi/parse.py", line 65, in _parse_event
    except KeyError: raise ValueError('unexpected event type: 0x%02x' % code)
ValueError: unexpected event type: 0x55

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/blink/.local/lib/python3.8/site-packages/slippi/game.py", line 36, in __init__
    parse(input, handlers)
  File "/home/blink/.local/lib/python3.8/site-packages/slippi/parse.py", line 221, in parse
    raise e
slippi.parse.ParseError: Parse error (games/3.slp @0x15a08): unexpected event type: 0x55

I don't know if it's character dependent, but I've noticed it happen in games with ICs, Marth, Falco, Sheik, Fox, Yoshi and Bowser, so I would guess not. I can't find 0x55 listed as an event type in event.py, but I don't know what that value is supposed to represent in the first place.

hohav commented 4 years ago

Thanks for the report. This happens when there's no Game End event at the end of the event stream, which indicates a bug in Slippi.

Of your recent replays, what proportion of them have this issue? I'm seeing this roughly once out of every 100+ of my own replays. I brought it up on the Slippi discord; feel free to provide any additional context there.

The reason for the misleading error message is that py-slippi doesn't realize the event stream is done and tries to parse the next byte as an event code. That byte is normally the character U (ASCII code 0x55), which comes at the start of the metadata UBJSON element.

I made py-slippi more resilient to this in 44c6cc1b9a7c691e2370ab8f962f3cf470bf83f0. These replays now parse fine, but game.end will of course be None.

blink1415 commented 4 years ago

Thanks for the feedback and explanation! I get this error in around 7% of my rollback games from June, July and so far in August. I just tried with the updated version of py-slippi and most of them work fine now. The ones that still don't work are cause by a separate issue. Thanks for the quick fix!