kinnay / NintendoClients

Python package to communicate with Switch, Wii U and 3DS servers
MIT License
558 stars 68 forks source link

Get course replay data for SMM2 #20

Closed TheGreatRambler closed 4 years ago

TheGreatRambler commented 4 years ago

Is it possible to get the course replay data of:

In SMM2? Thank you!

kinnay commented 4 years ago

I don't think you can get the course clear and world record ghosts, but getting Ninji ghosts should be possible. After all, the Switch must be able to download them somehow because otherwise it wouldn't be possible to race against other ghosts in ninji mode.

Here's a list of methods that are provided by the server in case you're interested: https://github.com/Kinnay/NintendoClients/wiki/Data-Store-Protocol-(SMM-2)

I'd guess that the GetEventCourseGhost method is used to get a ninji ghost. I'll try to figure out its parameters and return type. If I know how you can download a ninji ghost I'll let you know.

TheGreatRambler commented 4 years ago

Thank you! I hope to see if I could actually make a TAS from the ninji data, because if it's stored as frames, that would be really cool!

kinnay commented 4 years ago

Ok I figured out how ninji ghosts are downloaded and I added an example script that downloads a ghost. The replay file looks encrypted though, and simontime's decryptor doesn't seem to support it. I'm trying to figure out the encryption right now and I'll update the example script when I can decrypt the reply file.

I know that NSMBU stores the button presses in its replay files every frame. I wouldn't be surprised if SMM2 does the same.

kinnay commented 4 years ago

Replay files are zlib compressed, not encrypted.

I noticed some patterns in reply files that made me believe that they aren't really encrypted. Then I compared different replay files against each other and I noticed that they all start with the same bytes. Then I remembered that zlib compressed data always starts with the byte 0x78, and all replay files I've downloaded also start with that byte...

Figuring out how replay data is encoded in the file is probably more difficult. I might take a look at it, because I'm actually curious about how it works myself, but I can't promise anything.

Anyway, I updated the example script.

kinnay commented 4 years ago

Actually, I've been thinking about it a little, and I don't think SMM2 stores button presses anymore. In NSMBU only one player is active at once, but in SMM2 you're racing against many ghosts at the same time. If the ninji ghosts were stored as button presses it would have to independently simulate the whole level for each ghost, because the whole ghost replay breaks if a ghost can't jump on a goomba because it's killed by another ghost.

kinnay commented 4 years ago

I discovered the method that reads the header of the replay file. I'll be documenting the file format here: https://github.com/Kinnay/Nintendo-File-Formats/wiki/SMM-2-Ninji-Ghosts. I'm closing this issue now, but feel free to reopen it if you still have any questions (or open a new one if the question is unrelated). :slightly_smiling_face:

TheGreatRambler commented 4 years ago

Fantastic! I should have checked back here sooner. Thank you so much for a new docs page! It's very helpful