From 1dcd44b94fcba10e9f78f8352557d46ea84b80ab Mon Sep 17 00:00:00 2001 From: Logan Stromberg Date: Fri, 10 Feb 2023 07:37:20 -0800 Subject: [PATCH] Treat NpadIdType < 0 as invalid. Filter invalid SupportedPlayers inside IHidServer.SetSupportedNpadIdType(). (#4377) Co-authored-by: Logan Stromberg --- Ryujinx.HLE/HOS/Services/Hid/HidServer/HidUtils.cs | 4 +++- Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Ryujinx.HLE/HOS/Services/Hid/HidServer/HidUtils.cs b/Ryujinx.HLE/HOS/Services/Hid/HidServer/HidUtils.cs index 65a69bb776..b98f606581 100644 --- a/Ryujinx.HLE/HOS/Services/Hid/HidServer/HidUtils.cs +++ b/Ryujinx.HLE/HOS/Services/Hid/HidServer/HidUtils.cs @@ -38,7 +38,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid.HidServer public static bool IsValidNpadIdType(NpadIdType npadIdType) { - return npadIdType <= NpadIdType.Player8 || npadIdType == NpadIdType.Handheld || npadIdType == NpadIdType.Unknown; + return (npadIdType >= NpadIdType.Player1 && npadIdType <= NpadIdType.Player8) || + npadIdType == NpadIdType.Handheld || + npadIdType == NpadIdType.Unknown; } } } \ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs b/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs index d347a3bde9..266fc04fba 100644 --- a/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs +++ b/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs @@ -722,7 +722,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid for (int i = 0; i < supportedPlayerIds.Length; ++i) { - if (supportedPlayerIds[i] >= 0) + if (HidUtils.IsValidNpadIdType(supportedPlayerIds[i])) { context.Device.Hid.Npads.SetSupportedPlayer(HidUtils.GetIndexFromNpadIdType(supportedPlayerIds[i])); } @@ -1101,7 +1101,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid if (deviceType < NpadStyleIndex.System || deviceType >= NpadStyleIndex.FullKey) { - if (npadIdType >= (NpadIdType.Player8 + 1) && npadIdType != NpadIdType.Handheld && npadIdType != NpadIdType.Unknown) + if (!HidUtils.IsValidNpadIdType(npadIdType)) { return ResultCode.InvalidNpadIdType; }