kinnay / SMB35

An open source server for Super Mario Bros. 35
GNU Affero General Public License v3.0
180 stars 24 forks source link

Is it compatible with Switch Emulators? #5

Closed Vaskiemaia closed 2 years ago

Vaskiemaia commented 3 years ago

Hey there,

Been trying to test it with both Ryujinx and Yuzu and i haven't been able to get it working but i am not sure i have set it up properly.

Could you confirm that it works with either ?

kinnay commented 3 years ago

Hi, I didn't try it but if the emulator supports sockets it should be compatible.

Vaskiemaia commented 3 years ago

Would you be able to test it ?

I put the exefs mod in the mod folder for the game. Ryujinx has an option to open the folder for the game mods

As i start the game and go intro practice or 35 battle the game just gets back to the main menu

kinnay commented 3 years ago

Sure, I will try when I have time 👍

It would actually be really nice if it works on an emulator, because it would make it much easier to test the game with many connections at once.

Vaskiemaia commented 3 years ago

I would really appreciate that.

There could be a whole new community for it since Ryujinx is well developed and the game would run on a potato.

Excited to find out, let me know as soon as you can test it.

kinnay commented 3 years ago

I tried it on Ryujinx. It went back to the menu, like you said. I'll try to figure it out, but Ryujinx doesn't seem to provide a debugger unfortunately.

Vaskiemaia commented 3 years ago

That was my experience as well

You might have to use the LDN build as that one has some online facilities

kinnay commented 3 years ago

I think I found the problem.

The game requires that a network connection is available. If nn::nifm::IsNetworkAvailable() returns false it goes back to the main menu. This function always returns false in Ryujinx however, because it is stubbed.

Maybe we can patch the game such that it skips the network connection check.

Vaskiemaia commented 3 years ago

Sounds like there is a potential solution for it.

Do you have the interest in digging further into it ?

kinnay commented 3 years ago

Ryujinx might not be ready for this. After I patched IsNetworkAvailable() I could see the match making screen, but it immediately popped up error 2306-0520, which means Transport::DnsError. I haven't been able to fix this yet.

Vaskiemaia commented 3 years ago

That's unfortunate. It's fully up to you if you're willing to persevere and keep digging but it could well be that Ryujinx is just not developed enough.

From Ryujinx perspective they have no interest in developing the online side, only on the local network.

theboy181 commented 3 years ago

Force Network Available.zip Updated

This MOD will force Network Available, there is something more needed, do you have any more ideas?

thomasnet-mc commented 3 years ago

I'm pretty sure the Ryujinx team does not wish to provide online services for Switch before the end of life of the console.

ha1vorsen commented 3 years ago

There's also a check for any links to an active Nintendo Account, is this related? For example, using a console that has never connected to a Nintendo server, I get kicked out before I start a match, since no Nintendo Account has been linked.

thomasnet-mc commented 3 years ago

AAUTH likely refuses to provide an access token for the title, so it'll kick you out even before it'd ask you to create an account.

LuisMayo commented 2 years ago

Hi!

I've been trying to check what's going on in case I can help a bit, although I know nothing of switch internals, but I love this game and I'd love to see it being played on emulator.

My setup: Windows 10 Ryujinx 1.0.0-ldn2.4 (I have done some tests with Ryujinx 1.0.7096 with the same result)

All tests were done with the "Force network Available" patch 1 Testing with the patch provided in this repository ended up with an exception due to Ryujinx not being able to create a service. This happened during game load 00:00:14.867 |E| HLE.OsThread.16 Application : Unhandled exception caught: Ryujinx.HLE.Exceptions.ServiceNotImplementedException: Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator.IBcatService: 10101

smb35-Ryujinx_1.0.0-ldn2.4_2021-11-02_21-00-01.log (edit: both tests had the same result: https://github.com/kinnay/SMB35/issues/5#issuecomment-961211760)

  1. Testing with https://smb35server.com/'s patch, the game did load. When trying to enter training mode, I was kicked out to the main menu again. This is probably due to the inability of the emulator to do DNS solving 00:00:23.898 |S| HLE.OsThread.16 ServiceSfdnsres GetAddrInfoRequestImpl: Stubbed. {enableNsdResolve: True ; cancelHandle: 0 ; pidPlaceHolder: 0 ; host: smb35server.com ; service: } smb35server.txt

I guess there is no much we can do on this side. Should an issue be opened on Ryujinx repository?

They are not huge fans of emulating Nintendo's services as they're afraid of legal issues. But given that this is emulating a non-existing service... It should be fine?

I'm really looking forward to seeing this working.

kinnay commented 2 years ago

Yeah, they haven't implemented enough networking functions to make this work.

Should an issue be opened on Ryujinx repository?

I guess it's worth a shot. They will probably tell you if they don't want to implement this. A good pull request would probably be even better.

LuisMayo commented 2 years ago

I'm back to clarify a few things

About the test I made with this repo's patch, I seem to have applied the patch incorrectly, after doing it properly the result is exactly the same for both patches. I have also tested by self-hosting the server, obviously with the same result.

I was wondering whether Ryujinx team may help us to make this work, but I found this reasoning in their blog

The first option would be connecting directly to Nintendo's servers using information and user accounts dumped from your console. If you've been in the Switch modding community for a while, you already know what the problem with this is. Unlike the Wii U, official server communication is known to have a bunch of traps that can easily get your console banned from the service if we don't behave exactly like an unmodified switch. That isn't reasonable to expect right now, and we don't want to be responsible for bans, so that's out of the question.

And even while connecting to this server is not connecting directly to NSO servers, this server is indeed relaying information to NSO servers. So I highly doubt they'll approve this.

The other big emulator team, Yuzu, possibly has the same opinion, as when they thought about emulating online they were about to make their own NSO replacement, which they scrapped anyway.

So unless someone is willing to do the work of forking one of these emulators and adding NSO-like support, I think this is unfortunately out of the question

EDIT: P.S: (well, there may be technically a third way which would be to modify the game and server in order not to expect NSO authorization so the Ryujinx team may be more inclined to help, but that's like really heavy modding)

kinnay commented 2 years ago

And even while connecting to this server is not connecting directly to NSO servers, this server is indeed relaying information to NSO servers. So I highly doubt they'll approve this.

That is wrong, unless I misunderstood what you are saying. This server is a replacement for NSO servers and does not relay anything to official NSO servers. In fact, it can even be used on a banned Switch.

The emulators don't have to implement any specific NSO functionality at all. They only need to support DNS lookup and TCP sockets.

P.S: (well, there may be technically a third way which would be to modify the game and server in order not to expect NSO authorization so the Ryujinx team may be more inclined to help, but that's like really heavy modding)

Actually, that is exactly what the patch is doing. It bypasses NSO completely.

LuisMayo commented 2 years ago

Oh.

I'm truly sorry for the misunderstanding, I though I had seen something on the NintendoClients repo that made me thought that.

If that's the case I'll ask the Ryujinx team their opinions about this issue then.

Sorry for the confussion!

LuisMayo commented 2 years ago

Ah, also, DNS resolution is working. I don't know about TCP sockets, they should end up working due to their efforts to make multiplayer games work with LDN though

ha1vorsen commented 2 years ago

And even while connecting to this server is not connecting directly to NSO servers, this server is indeed relaying information to NSO servers. So I highly doubt they'll approve this.

That is wrong, unless I misunderstood what you are saying. This server is a replacement for NSO servers and does not relay anything to official NSO servers. In fact, it can even be used on a banned Switch.

The emulators don't have to implement any specific NSO functionality at all. They only need to support DNS lookup and TCP sockets.

P.S: (well, there may be technically a third way which would be to modify the game and server in order not to expect NSO authorization so the Ryujinx team may be more inclined to help, but that's like really heavy modding)

Actually, that is exactly what the patch is doing. It bypasses NSO completely.

Question: does your server rely on AWS in any capacity? NSO at the moment is down, and so seems to be your hosted replacement server.

kinnay commented 2 years ago

No I am hosting it on Vultr.

Lekuruu commented 2 years ago

It seems to be working now on Ryujinx, as the Devs implemented SSL connection for the emulator.

LuisMayo commented 2 years ago

When have you tried this? How far have you reached within the game?

I tried with main release like three weeks ago, when trying to enter practice mode it just kicks me out. I've also tried with LDN 2.4, the last LDN available, and that one gives out a DNS error, as the DNS was properly implemented in the main build after LDN 2.4 launch

Lekuruu commented 2 years ago

When have you tried this? How far have you reached within the game?

I tried it just yesterday and I have come up to the "Searching for players" screen

I tried with main release like three weeks ago, when trying to enter practice mode it just kicks me out.

This happened also for me. But three Weeks ago there was no SSL Implementation, so I am a bit confused.

Anyway, if you want to try it out you need to enable "Guest Internet Access" in the system settings.

LuisMayo commented 2 years ago

I can't wait to get home to try it. If it works I'll be beyond happy.

There doesn't seem to be many people playing, not on https://smb35.ymar.dev:20002 or https://smb35server.com/dashboard . Although this one seems a bit more active.

I never tried practice mode, not even when servers where online. I guess it lets you play by yourself? Does this mode work with the replacement server?

Lekuruu commented 2 years ago

Practice mode still connects you to the server, but I don't know if it is implemented... I would need to test this on my switch.

LuisMayo commented 2 years ago

It doesn't seem to be working as of right now, throwing a 2306-0332 error when attempting to play with this log. Sad

00:02:18.964 |W| HLE.OsThread.5 ServiceBsd SetSocketOption: Unsupported SetSockOpt Option: SoNoSigpipe Level: Socket 00:02:19.373 |S| HLE.OsThread.15 ServiceSsl CreateContext: Stubbed. {sslVersion: Auto} 00:02:19.374 |S| HLE.OsThread.15 ServiceSsl SetOption: Stubbed. {option: DoNotCloseSocket ; value: True} 00:02:19.375 |I| HLE.OsThread.15 ServiceSsl SetHostName: smb35.ymar.dev 00:02:19.375 |S| HLE.OsThread.15 ServiceSsl SetOption: Stubbed. {option: SkipDefaultVerify ; value: False} 00:02:19.375 |S| HLE.OsThread.15 ServiceSsl SetVerifyOption: Stubbed. {_verifyOption: PeerCa, HostName} 00:02:19.375 |S| HLE.OsThread.15 ServiceSsl SetSessionCacheMode: Stubbed. {sessionCacheMode: SessionId} 00:02:19.375 |S| HLE.OsThread.15 ServiceSsl SetIoMode: Stubbed. {_ioMode: NonBlocking} 00:02:47.676 |I| .NET ThreadPool Worker Ptc Save: Saved Profiling Info (size: 43404 bytes, profiled functions: 13564). 00:02:56.051 |I| HLE.OsThread.15 ServiceNifm GetCurrentIpAddress: Console's local IP is "192.168.0.196". 00:02:56.197 |S| HLE.OsThread.15 ServiceSsl GetConnectionCount: Stubbed. {_connectionCount: 1} 00:02:56.310 |I| HLE.OsThread.15 ServiceNifm GetCurrentIpAddress: Console's local IP is "192.168.0.196". 00:02:56.354 |I| HLE.OsThread.15 ServiceAm .ctor: Applet 'Error' created. 00:02:56.357 |I| HLE.OsThread.15 ServiceAm : ErrorApplet version: 0x00000000

LuisMayo commented 2 years ago

After further testing, it does boot into Practice mode with https://smb35server.com/ server, not with this repo server though.

Anyway, playing is not possible since just a black screen is shown. The game is running in the background as audio works, but video doesn't.

This is of course an emulation issue (well, maybe the fact that it doesn't connect to this server but it does to the other may mean something) but it means this issue may not be closed yet :P image

EnigmaWave commented 2 years ago

The version of ryujinx at https://github.com/gdkchan/Ryujinx/tree/true-bindless works if the line of code "Port = IPAddress.HostToNetworkOrder(Port);" is removed from the file "AddrInfo4.cs"

I found that the byte order of the port number was being reversed, so instead of connecting to port 20001, the emulator was trying to connect to port 8526.

LuisMayo commented 2 years ago

Interesting, I struggle to understand how does it properly connect to sm35server then if the same error should happen

And while is true that on the true-bindless branch works, it goes at a less than optimal speed. This issue is being discussed on Ryujinx repo https://github.com/Ryujinx/Ryujinx/issues/3009

just-another-random-person commented 2 years ago

Seems the game runs at full-speed now, at constant 60 FPS, on several other high-end systems. Several players on smb35server have claimed to have played full-speed in Discord, notably:

So regarding the original listed issue, it seems the game is now 100% fully playable on emulator (albeit having high system requirements, hopefully only for now).

LuisMayo commented 2 years ago

I'm happy it works for them then. This issue may now be closed I guess.

I'm sad I won't be able to play it though, but the issue is solved :P

just-another-random-person commented 2 years ago

This issue anyway, but I'd say the issue on the Ryujinx GitHub would still be worth pursuing to get them to improve the performance.

LuisMayo commented 2 years ago

Yeah, also issues usually don't get closed after their associated PR is closed anyway. So it's worth keeping it up

Vaskiemaia commented 2 years ago

I am struggling getting the game to run even after following the steps EnigmaWave described.

Could someone upload a build with the issue solved ?

As it is it seems like a few people have confirmed online works now, but i still haven't been able to experience it

LuisMayo commented 2 years ago

You have to use an special branch of the emulator. This is the Pull Request of said branch: https://github.com/Ryujinx/Ryujinx/pull/3001 In this comment by Github Actions Bot you can find binaries, download the "release" variant, not the headless one: https://github.com/Ryujinx/Ryujinx/pull/3001#issuecomment-1013764503

Once using that branch, ensure to be using the smb35server.com replacement server and the force network available mods. Also ensure that in your Ryujinx settings, the "Enable guest internet access" option is enabled. Finally, make sure that you're running latest version (1.0.2) of the game.

I didn't need to make the changes specified by EnigmaGuest.

Please note that it requires really high end hardware. I'm only being able to pull 8fps with a 1060 6GB, but they've been able to run it at full speed with a 2080 Ti

just-another-random-person commented 2 years ago

@Vaskiemaia seems that smb35server.com has now been updated to include a download link of a fully-working build with all necessary changes packaged into it (via using portable mode), as well as instructions for emulator.

Lekuruu commented 2 years ago

Works like a charm! I have a 1660S and a Ryzen 5 5600X, and I get around 55 FPS average.

Edit: (Forgot to mention that I was in Handheld Mode, because Docked Mode gave me a Blackscreen)

Vaskiemaia commented 2 years ago

Just tested it and it worked perfectly for me (but i can't for the life of me understand the concept of the game)

Will this be merged to the Master build ?

LuisMayo commented 2 years ago

I guess it will, but it's still in development

just-another-random-person commented 2 years ago

Please note that it requires really high end hardware. I'm only being able to pull 8fps with a 1060 6GB, but they've been able to run it at full speed with a 2080 Ti

Really strange btw, but 83kY (the person who recorded the YouTube video I posted above on a 2080Ti with a lagless lakitu party) just posted this in Discord:

image

Maybe it's something with your settings? I'd suggest trying the packaged build @ smb35server and seeing how it performs on your machine.

LuisMayo commented 2 years ago

Maybe my CPU is the problem after all? It's strange because I'm getting a 100% GPU usage. I have the same problem with the smb35server build. I'll try to update drivers later.

Can you send link to the discord channel?

just-another-random-person commented 2 years ago

https://discord.gg/vjtVQHnGG9 It's the discord of the one who sets up the weekly SMB35 tournaments.

EnigmaWave commented 2 years ago

I didn't need to make the changes specified by EnigmaGuest.

Did you join a match? The unmodified build freezes when the countdown reaches zero.

LuisMayo commented 2 years ago

I didn't need to make the changes specified by EnigmaGuest.

Did you join a match? The unmodified build freezes when the countdown reaches zero.

No, as I've only tried practice mode. My performance being so bad I haven't tried an actual match. I'll do just to test.

In that case, maybe a PR to Ryujinx may be warranted?

LuisMayo commented 2 years ago

I've now tried and you're right, it does freeze. I have yet to try with your modification though

Vaskiemaia commented 2 years ago

The build on smb35server.com works perfectly online.

At this point i have played well above 25 matches and it just works. I even had a friend of mine join me for some games.