fix: update NACP language handling and sanitization logic - #348
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix issue #347
Since commit
db06528("handle localized game titles in export filenames"), a large number of games show up over MTP and FTP as a bare[0100XXXXXXXXXXXX]with no title, and their exported NSP/NCA/XCI filenames lose the title too.The root cause is that
GetEnglishTitleName()indexes the NACP language array withSetLanguageenum values, which is the wrong index space.Two follow-on issues made the failure total instead of graceful: there was no fallback when the English name could not be resolved, and the browse listing was made to reuse the export filename, so a filesystem safety option started dictating how titles are displayed.
NACP language entries are not indexed by
SetLanguageNacpStruct::lang[]uses the NACP language ordering, not theSetLanguageordering.libnx keeps an explicit translation table for this in
nx/source/runtime/nacp.c:The old code indexed the array directly with the enum:
SetLanguage_ENUSis1andSetLanguage_ENGBis12, so it actually read:lang[1]lang[12]AmericanEnglish, slot
0, was never checked.That is the slot populated by most Nintendo of America releases (Dragon Quest for example), so those titles resolved to an empty English name.
Where a Korean entry happened to exist, the function returned Korean text, which the ASCII sanitiser then reduced to underscores.
Slot
0is also whereNormalizeNacpLangData()stores its fallback entry when it decompresses the newer NACP title format, so titles using that format were affected as well.sphaira/source/title_info.cpp,GetEnglishTitleName()now uses the NACP ordering, AmericanEnglish first:No fallback when the English name is unavailable
MakeExportTitleName()used the English name and nothing else when "Fix export filenames" was on, which is the default:An empty result means the caller emits a title ID only.
MakeExportTitleName()now degrades instead of giving up. The sanitising step is factored into a lambda and applied:With the option off, behaviour is unchanged: the displayed name with Unicode preserved.
This keeps the documented promise of the option, that filenames stay ASCII safe, while no longer throwing away a usable name.
Browse listing reused the export filename
commit
db06528made the MTP/FTP folder name and the exported NSP filename the same string.Those serve different purposes.
The folder name is a browse convenience, the filename is what lands on the host filesystem.
Tying the folder name to the ASCII sanitiser meant any title with non ASCII characters, CJK text, a leading decorative character, or just a trademark or accented character, was displayed mangled into underscores or dropped to a bare title ID.
UTF-8 truncation
The old code truncated with a byte precision specifier:
That can cut a UTF-8 sequence in half. It was harmless while every name was forced to ASCII, but now that real titles reach the listing, a trailing partial sequence can make MTP clients bug or drop the entry.
A
TruncateUtf8()helper was added to the anonymous namespace indevoptab_game.cpp.It walks back off any continuation bytes so the name is always cut on a character boundary.