hohav / py-slippi

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

ValueError: 2 is not a valid Method #8

Closed IAmAbszol closed 5 years ago

IAmAbszol commented 5 years ago

Python Version: 3.6.8 Slippi Version: 1.2.0

How to reproduce

  1. Install the dependencies + termcolor as it's currently not contained within the requirements.txt.
  2. Grab latest Slippi files, mine was tested on any HungryBox vs. Mang0 set at Pound 2019 (Specifically Grandfinals).
  3. Import Slippi module or just bring in the Game class.
  4. Error will be thrown whenever you invoke the constructors path to the Slippi stream file.

Error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Kyle\Miniconda3\envs\meleeai\lib\site-packages\slippi\game.py", line 33, in __init__
    self._parse_file(path)
  File "C:\Users\Kyle\Miniconda3\envs\meleeai\lib\site-packages\slippi\game.py", line 85, in _parse_file
    event = self._parse_event(stream, payload_sizes)
  File "C:\Users\Kyle\Miniconda3\envs\meleeai\lib\site-packages\slippi\game.py", line 68, in _parse_event
    return evt.End._parse(stream)
  File "C:\Users\Kyle\Miniconda3\envs\meleeai\lib\site-packages\slippi\event.py", line 192, in _parse
    return cls(cls.Method(method))
  File "C:\Users\Kyle\Miniconda3\envs\meleeai\lib\enum.py", line 293, in __call__
    return cls.__new__(cls, value)
  File "C:\Users\Kyle\Miniconda3\envs\meleeai\lib\enum.py", line 535, in __new__
    return cls._missing_(value)
  File "C:\Users\Kyle\Miniconda3\envs\meleeai\lib\enum.py", line 548, in _missing_
    raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 2 is not a valid Method

The error resides within the event.py line 192. The method variable is of type int with value 2 which doesn't match to Methods 0 or 3 being Inconclusive or Conclusive (Respectfully).

Temporary Fix I haven't played with Python's struct pack/unpack functions too much but from what I gather, the 2 being returned has something to do with how the file was packed in the first place. Thus I further assume that the creator of the Slippi file has changed it's packing parameters?

Source(s): API and example

Therefore, changing the method variable from 2 to 3 since possibly 0 could still be used to solve the issue though I felt grimy for doing so.

Final code result within event.py Before

    @classmethod
    def _parse(cls, stream):
        (method,) = unpack('B', stream)
        return cls(cls.Method(method))

After

    @classmethod
    def _parse(cls, stream):
        (method,) = unpack('B', stream)
        method = 3 if method == 2 else 0
        return cls(cls.Method(method))
vladfi1 commented 5 years ago

I am seeing this as well on the Pound data.

IAmAbszol commented 5 years ago

@vladfi1 Glad Im not the only one but trying to find documentation on file changes is like findin a needle in a haystack

hohav commented 5 years ago

Thanks for the report. The issue is caused by a change in Slippi 2.0.0. I plan to release a fix today.

@IAmAbszol this stuff is documented on the Replay File Spec wiki page. It's linked from https://github.com/project-slippi/project-slippi, but the link is easy to miss.

IAmAbszol commented 5 years ago

@hohav How likely would it be to have a live file streaming option? I see that your game.py uses ubjson which requires the file to be completely finished. I was thinking of splicing the datastream doing it myself but didnt want to intrude on anything you might be in the midst of doing. That page you provided will help a ton as well.

hohav commented 5 years ago

@IAmAbszol I'm not working on anything in that area right now— the current file format isn't great for streaming, for the reason you mentioned. I'm sure something could be hacked together, I just don't have much appetite for implementing that.

I remember chatting with Fizzi about possible alternative file formats, but AFAIK nothing came of that.

Tanbourine commented 5 years ago

Thanks for the report. The issue is caused by a change in Slippi 2.0.0. I plan to release a fix today.

@IAmAbszol this stuff is documented on the Replay File Spec wiki page. It's linked from https://github.com/project-slippi/project-slippi, but the link is easy to miss.

Has this issue been addressed? I'm running into this issue still unfortunately (with the same symptoms as above)

Thanks! This is a great tool, I'm really excited to get started

hohav commented 5 years ago

@Tanbourine what version were you running? If it was a release, then it wouldn't have had the fix as that hadn't been included in a release yet.

I just released 1.3.0, which includes that fix. If it still doesn't work, please create a new ticket.