aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs
diff options
context:
space:
mode:
authorLogan Stromberg <loganstromberg@gmail.com>2022-11-16 14:53:17 -0800
committerGitHub <noreply@github.com>2022-11-16 23:53:17 +0100
commit2c9ab5e45fd45d45909b9b348580c44bdfc4d36f (patch)
tree204dec18131dcdf05837999600ad1a32435a566c /Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs
parentd536cc8ae6d6725780365d858f2fd64b66d90b7f (diff)
Prevent raw Unicode control codes from showing on software keyboard applet. (#3845)1.1.350
* Revert "Add support for releasing a semaphore to DmaClass (#2926)" This reverts commit 521a07e6125d3a5d9781512639387a9be5f09107. * Revert "Revert "Add support for releasing a semaphore to DmaClass (#2926)"" This reverts commit ec8a5fd05362f04cc77436ee3e45a9188777f75e. * Strip non-visible control codes from strings before they are sent to the software keyboard to prevent ugly unicode blocks from being shown on the UI. * remove debugging junk * Initialize stringbuilder capacity at the start to prevent resizing (a tiny tiny microoptimization) * Update remarks documentation. Remove unneeded imports. * Removing a test that's actually just redundant Co-authored-by: Logan Stromberg <lostromb@microsoft.com>
Diffstat (limited to 'Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs')
-rw-r--r--Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs42
1 files changed, 38 insertions, 4 deletions
diff --git a/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs b/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs
index 3cfd192c..e287318a 100644
--- a/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs
+++ b/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs
@@ -204,12 +204,11 @@ namespace Ryujinx.HLE.HOS.Applets
else
{
// Call the configured GUI handler to get user's input.
-
var args = new SoftwareKeyboardUiArgs
{
- HeaderText = _keyboardForegroundConfig.HeaderText,
- SubtitleText = _keyboardForegroundConfig.SubtitleText,
- GuideText = _keyboardForegroundConfig.GuideText,
+ HeaderText = StripUnicodeControlCodes(_keyboardForegroundConfig.HeaderText),
+ SubtitleText = StripUnicodeControlCodes(_keyboardForegroundConfig.SubtitleText),
+ GuideText = StripUnicodeControlCodes(_keyboardForegroundConfig.GuideText),
SubmitText = (!string.IsNullOrWhiteSpace(_keyboardForegroundConfig.SubmitText) ?
_keyboardForegroundConfig.SubmitText : "OK"),
StringLengthMin = _keyboardForegroundConfig.StringLengthMin,
@@ -764,6 +763,41 @@ namespace Ryujinx.HLE.HOS.Applets
}
}
+ /// <summary>
+ /// Removes all Unicode control code characters from the input string.
+ /// This includes CR/LF, tabs, null characters, escape characters,
+ /// and special control codes which are used for formatting by the real keyboard applet.
+ /// </summary>
+ /// <remarks>
+ /// Some games send special control codes (such as 0x13 "Device Control 3") as part of the string.
+ /// Future implementations of the emulated keyboard applet will need to handle these as well.
+ /// </remarks>
+ /// <param name="input">The input string to sanitize (may be null).</param>
+ /// <returns>The sanitized string.</returns>
+ internal static string StripUnicodeControlCodes(string input)
+ {
+ if (input is null)
+ {
+ return null;
+ }
+
+ if (input.Length == 0)
+ {
+ return string.Empty;
+ }
+
+ StringBuilder sb = new StringBuilder(capacity: input.Length);
+ foreach (char c in input)
+ {
+ if (!char.IsControl(c))
+ {
+ sb.Append(c);
+ }
+ }
+
+ return sb.ToString();
+ }
+
private static T ReadStruct<T>(byte[] data)
where T : struct
{