Emulator Issues #12323

Wii network not fully emulated

Added by Leseratte10 7 days ago.

% Done:


Operating system:
Issue type:
Relates to usability:
Relates to performance:
Relates to maintainability:
Regression start:
Fixed in:


Game Name?

Any game that's using Nintendo's DWC library, meaning, any game with online support. Tested with MKWii (RMCP01).

What's the problem? Describe what went wrong.

When a game initializes the DWC library, a network socket is created using a random port. This is NOT done by requesting a port of 0, as it is usually done on Unix, but instead the library itself has code to generate a random number between 49152 and 65535, and then opens this specific port. If this port is already in use, the initialization of the library (and thus the connection to the online servers) fails.

On a real Wii, that's not a problem - the currently running software (game) is the only software to run on the Wii and thus the only software which could ever be using ports, so the software can make sure not to use ports it's already using for other stuff.

On Dolphin, that's not necessarily the case. Depending on how many applications are currently running on the computer that might all be doing network connections, it becomes increasingly more likely that the random port the game picked is already in use by another application, forcing the user to try to connect to the online servers over and over again until the game randomly picks a port that's not yet in use by the operating system.

Sure, that's a pretty artificial problem by itself, and I actually noticed it while doing something different:
Usually, as described above, games will pick a random port. That's not really helpful if you want to add port forwardings to help with the connection, as you'd have to forward the whole 49152-65535 range to your Wii / Dolphin. To prevent that we added some code in our Wiimmfi update for MKWii that allows the user to manually pick a port to use on the Wiimmfi webpage.

A while later we've then received a bug report from a user who was running two instances of Dolphin on the same machine to test stuff, and he was unable to go online with the 2nd instance. Further investigation showed why that was the case, the two Dolphins were trying to use the same port (the port they were told to use by Wiimmfi), and that obviously didn't work.


An additional instance where we noticed the Wii network not fully being emulated by Dolphin would be the fact that MKWii on a Wii does not support SNI in SSL requests, while booting MKWii on Dolphin "magically" makes that work (because Dolphin doesn't emulate the Wii network code, instead it all hands these requests to the operating system / standard SSL libraries instead).


All this is not really an important problem for us / for Wiimmfi, we'll just add some update code to the game to make it retry with a different random port on error, until it gets a random port that is free to use. But because I was unable to find information about this behaviour elsewhere I just wanted to open this bug report so that this bug (or rather, emulation inaccuracy) is documented somewhere just in case it causes other trouble in the future.

What steps will reproduce the problem?

Yeah, that's where it gets difficult. This is more a design issue (handing network connections straight through to the OS instead of handling them inside Dolphin, including DHCP and its own IP for the emulated console). To fix that Dolphin would probably need to do all the network handling itself - meaning, send its own DHCP requests to the router with the MAC address defined in the config, and get its own local IP which is only used for this one instance of Dolphin. That is probably not feasible, though.

If you do want to reproduce this somehow you can take a Wiimmfi patched copy of Mario Kart Wii PAL (RMCP01), run it in Dolphin and set an execute breakpoint at 800d2848. That's where the random port generation happens, and when you replace 800d2878 with "li r4, X" you can force the game to use port X for testing. If that X (or, in the unmodified game, that random port) is already in use by some other software on the OS, the game will fail to connect to Wiimmfi.

Is the issue present in the latest development version? For future reference, please also write down the version number of the latest development version.

Yes, 5.0-13063

Other stuff

As said above, I don't expect this to be fixed soon (or at all) due to how convoluted this all is (and we can work around the port issue with some additional code in the Wiimmfi update anyways), I just wanted to let people know that this issue exists.

Also available in: Atom PDF