From e00ca92063b9dda7b3272f6461610743cfa83ad5 Mon Sep 17 00:00:00 2001
From: riperiperi <rhy3756547@hotmail.com>
Date: Wed, 23 Sep 2020 22:57:18 +0100
Subject: [PATCH] Return "NotAvailable" when no UserChannel data is present.
 (#1569)

* Return "NotAvailable" when no UserChannel data is present.

* Return ObjectInvalid for undefined parameter kinds.

* No need to specify which, there's only one.

* Just works as a literal string.
---
 .../ApplicationProxy/IApplicationFunctions.cs          | 10 +++++++++-
 Ryujinx.HLE/HOS/UserChannelPersistence.cs              |  4 +++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/IApplicationFunctions.cs b/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/IApplicationFunctions.cs
index 82d7c7fa7b..a090b6fa31 100644
--- a/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/IApplicationFunctions.cs
+++ b/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/IApplicationFunctions.cs
@@ -53,8 +53,16 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati
                     // Only the first 0x18 bytes of the Data seems to be actually used.
                     storageData = StorageHelper.MakeLaunchParams(context.Device.System.State.Account.LastOpenedUser);
                     break;
+                case LaunchParameterKind.Unknown:
+                    throw new NotImplementedException("Unknown LaunchParameterKind.");
+
                 default:
-                    throw new NotImplementedException($"Unknown LaunchParameterKind {kind}");
+                    return ResultCode.ObjectInvalid;
+            }
+
+            if (storageData == null)
+            {
+                return ResultCode.NotAvailable;
             }
 
             MakeObject(context, new AppletAE.IStorage(storageData));
diff --git a/Ryujinx.HLE/HOS/UserChannelPersistence.cs b/Ryujinx.HLE/HOS/UserChannelPersistence.cs
index 62f28feefb..13e7364f0b 100644
--- a/Ryujinx.HLE/HOS/UserChannelPersistence.cs
+++ b/Ryujinx.HLE/HOS/UserChannelPersistence.cs
@@ -31,7 +31,9 @@ namespace Ryujinx.HLE.HOS
 
         public byte[] Pop()
         {
-            return _userChannelStorages.Pop();
+            _userChannelStorages.TryPop(out byte[] result);
+
+            return result;
         }
 
         public bool IsEmpty => _userChannelStorages.Count == 0;