SourMesen / Mesen

Mesen is a cross-platform (Windows & Linux) NES/Famicom emulator built in C++ and C#
https://www.mesen.ca
GNU General Public License v3.0
1.25k stars 317 forks source link

Netplay becomes out of sync after a while #807

Closed properchopsticks closed 4 years ago

properchopsticks commented 4 years ago

hi,

i've tried playing over netplay with a friend over hamachi but every time we do so the game gets out of sync after 1 or 2 minutes. on my screen i see the game fine and so does he but the 2 games have completely different contexts and my input doesn't match what he sees and viceversa.

also i'm not sure if this is related but i read online that some emulators send data over the internet by sending full memory dumps and some only send input (and the input ones usually cause out of sync errors). if mesen sends only input or some other similar method, is it possible to switch it to memory dump packets?

thanks

SourMesen commented 4 years ago

I just tried playing a few minutes of few games and could only get one of them to desync. Knowing which games you've seen desyncs in would be helpful (as well as which version you were using if it's not the 0.9.9 release) - there is probably a tiny bug somewhere that is causing desyncs in some games.

The type of method used doesn't really matter - Mesen uses inputs (and resyncs with a save state when the game is paused or a save state is loaded), constantly sending memory dumps every frame could easily require 1GB of bandwidth per hour, depending on the game (I would imagine no emulator does this, though some might rely on inputs + semi-frequent full memory dumps to avoid desync issues)

properchopsticks commented 4 years ago

I tried it with battletoads (usa) and there i noticed the desync. I'm using the 0.9.9 release on windows 10. Haven't done much testing on battletoads either, we switched termorarily to another emulator that uses kaillera. I can try the pause method to see if it gets back in sync. I'll also try other games and report back with what i can find.

SourMesen commented 4 years ago

Alright, I think I've found and fixed the issue. It was an old bug introduced at some point in 2018. When the netplay host loads a game while the client is already connected, the client would end up applying the inputs to the wrong frame (1 frame late), which could eventually cause desyncs. In a lot of scenarios, this would not happen - e.g: if the client connects to the host while the game is already loaded, or if the host pauses or loads a state at any point, etc.

If you want, try this dev build, it should fix the issue: https://ci.appveyor.com/api/buildjobs/lgywd952x51atvw4/artifacts/MesenDevWin-0.9.9.31.exe You and your friend will both need to use this build. If you still get desyncs with this build, let me know.

Otherwise you should be able to workaround the problem by having the host pause and then unpause the game, which should prevent any desyncs, until you reload the game or load another game.

properchopsticks commented 4 years ago

thank you so much. i'll do some more testing and let you know if i find anything.