TooTallNate / switch-tools

Web app to create "NSP forwarders" for your modded Nintendo Switch
https://nsp-forwarder.n8.io
46 stars 9 forks source link

Fix compatibility with 19.0.0+ #15

Closed masagrator closed 4 days ago

masagrator commented 2 weeks ago

TL;DR this fix will work with any FW as long as you have Atmosphere 1.8.0+!

19.0.0 introduced new way of storing and reading debug flags. Now you can's set more than one flag to true. And new flag was introduced in place of old flag, while old flag was moved to new bit. Atmosphere 1.8.0 reimplemented this new behavior, so it applies to all FWs.

This fixes forwarder crashing with Atmosphere 1.8.0+ that is caused by both allow_debug set to true and force_debug(pre-19.0.0)/force_debug_prod(19.0.0+) set to true. You must choose only one. Since 19.0.0 force_debug flag has new bit.

This PR will set force_debug flag as it should be from 19.0.0 which is incompatible with Atmosphere pre-1.8.0. There is no way to make it backwards compatible with older Atmosphere versions while maintaining force_debug flag as true, and not setting it to true will make some homebrew relying on svcDebug not working properly.

Actual change since github sucks at binary comparison: Offsets: 0x330, 0x3F0 Changed: FF FF 06 00 -> FF FF 08 00

vercel[bot] commented 2 weeks ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nro-editor ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2024 8:41pm
nsp-forwarder ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2024 8:41pm
vercel[bot] commented 2 weeks ago

@masagrator is attempting to deploy a commit to the TooTallNate's Team Team on Vercel.

A member of the Team first needs to authorize it.

TooTallNate commented 2 weeks ago

Ok very cool. I haven't had a chance to look into v19 FW yet. Did you happen to have a diff of the source code for this change?

masagrator commented 2 weeks ago

Ok very cool. I haven't had a chance to look into v19 FW yet. Did you happen to have a diff of the source code for this change?

I have fixed it with hex editor. No source code involved. Explained issue in more details in edited PR.

masagrator commented 2 weeks ago

Changed description because I almost forgot. This will work with any FW as long as user is on Atmosphere 1.8.0+

TooTallNate commented 2 weeks ago

Ok thank you for the detailed explanation. So from what I am understanding, it's either:

Is my understanding correct? If so, I guess my question is which popular homebrew rely on this flag? It might be easy enough to add it as a checkbox toggle and apply this patch during generation of the forwarder, and default to having it off.

masagrator commented 2 weeks ago
  • Set force_debug_prod to true - this breaks backwards compat with Atmosphere < 1.8.0 but allows homebrew which depend on svcDebug to work properly

force_debug bit as expected from the 19.0.0 to true*

If so, I guess my question is which popular homebrew rely on this flag?

"popular" - none. 👯 Just expect if someone would make such a tool that someone would like to use it via forwarder, they wouldn't be able to use it

And as you said - it's pretty straightforward to patch. FF FF 08 00 for force_debug enabled on Atmosphere 1.8.0+, or FF FF 04 00 for compatibility with all versions (this will work the same as FF FF 06 00 on pre-1.8.0, but without crashing on 1.8.0+)

TooTallNate commented 4 days ago

@masagrator I've implemented the checkbox under Advanced mode, where 0x8 will be written to the flags bytes.

When unchecked (the default) the bytes will be 0x4 for maximum compat.

I've credited you as an author on the commit btw 😃