From cde38fb1c5c71a0c5a01e8a0188931cf4acd2333 Mon Sep 17 00:00:00 2001
From: Evan Husted <gr33m11@gmail.com>
Date: Wed, 4 Dec 2024 02:24:40 -0600
Subject: [PATCH] chore: applets: Cleanup redundant ReadStruct implementations
 & provide a default implementation for IApplet#GetResult.

---
 src/Ryujinx.HLE/HOS/Applets/AppletManager.cs        |  4 +---
 .../HOS/Applets/Browser/BrowserApplet.cs            |  7 -------
 .../HOS/Applets/Cabinet/CabinetApplet.cs            | 13 -------------
 .../HOS/Applets/Controller/ControllerApplet.cs      |  5 -----
 src/Ryujinx.HLE/HOS/Applets/Dummy/DummyApplet.cs    | 12 ++++--------
 src/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs    |  5 -----
 src/Ryujinx.HLE/HOS/Applets/IApplet.cs              |  2 +-
 .../HOS/Applets/PlayerSelect/PlayerSelectApplet.cs  |  5 -----
 .../SoftwareKeyboard/SoftwareKeyboardApplet.cs      |  5 -----
 .../HOS/Applets/SoftwareKeyboard/TRef.cs            |  2 +-
 10 files changed, 7 insertions(+), 53 deletions(-)

diff --git a/src/Ryujinx.HLE/HOS/Applets/AppletManager.cs b/src/Ryujinx.HLE/HOS/Applets/AppletManager.cs
index a2ddd573d..5895c67bb 100644
--- a/src/Ryujinx.HLE/HOS/Applets/AppletManager.cs
+++ b/src/Ryujinx.HLE/HOS/Applets/AppletManager.cs
@@ -24,11 +24,9 @@ namespace Ryujinx.HLE.HOS.Applets
                 case AppletId.SoftwareKeyboard:
                     return new SoftwareKeyboardApplet(system);
                 case AppletId.LibAppletWeb:
-                    return new BrowserApplet(system);
                 case AppletId.LibAppletShop:
-                    return new BrowserApplet(system);
                 case AppletId.LibAppletOff:
-                    return new BrowserApplet(system);
+                    return new BrowserApplet();
                 case AppletId.MiiEdit:
                     Logger.Warning?.Print(LogClass.Application, $"Please use the MiiEdit inside File/Open Applet");
                     return new DummyApplet(system);
diff --git a/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserApplet.cs b/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserApplet.cs
index 6afbe4a72..c5f13dab3 100644
--- a/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserApplet.cs
+++ b/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserApplet.cs
@@ -18,13 +18,6 @@ namespace Ryujinx.HLE.HOS.Applets.Browser
         private List<BrowserArgument> _arguments;
         private ShimKind _shimKind;
 
-        public BrowserApplet(Horizon system) { }
-
-        public ResultCode GetResult()
-        {
-            return ResultCode.Success;
-        }
-
         public ResultCode Start(AppletSession normalSession, AppletSession interactiveSession)
         {
             _normalSession = normalSession;
diff --git a/src/Ryujinx.HLE/HOS/Applets/Cabinet/CabinetApplet.cs b/src/Ryujinx.HLE/HOS/Applets/Cabinet/CabinetApplet.cs
index f4f935d34..294b8d1f6 100644
--- a/src/Ryujinx.HLE/HOS/Applets/Cabinet/CabinetApplet.cs
+++ b/src/Ryujinx.HLE/HOS/Applets/Cabinet/CabinetApplet.cs
@@ -125,19 +125,6 @@ namespace Ryujinx.HLE.HOS.Applets.Cabinet
             return bytes;
         }
 
-        public static T ReadStruct<T>(byte[] data) where T : unmanaged
-        {
-            if (data.Length < Unsafe.SizeOf<T>())
-            {
-                throw new ArgumentException("Not enough data to read the struct");
-            }
-
-            fixed (byte* dataPtr = data)
-            {
-                return Unsafe.Read<T>(dataPtr);
-            }
-        }
-
         #region Structs
 
         [StructLayout(LayoutKind.Sequential, Pack = 1)]
diff --git a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerApplet.cs b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerApplet.cs
index 5ec9d4b08..3a7b29ab5 100644
--- a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerApplet.cs
+++ b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerApplet.cs
@@ -117,11 +117,6 @@ namespace Ryujinx.HLE.HOS.Applets
             return ResultCode.Success;
         }
 
-        public ResultCode GetResult()
-        {
-            return ResultCode.Success;
-        }
-
         private static byte[] BuildResponse(ControllerSupportResultInfo result)
         {
             using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
diff --git a/src/Ryujinx.HLE/HOS/Applets/Dummy/DummyApplet.cs b/src/Ryujinx.HLE/HOS/Applets/Dummy/DummyApplet.cs
index 75df7a373..6b16aee7b 100644
--- a/src/Ryujinx.HLE/HOS/Applets/Dummy/DummyApplet.cs
+++ b/src/Ryujinx.HLE/HOS/Applets/Dummy/DummyApplet.cs
@@ -11,11 +11,14 @@ namespace Ryujinx.HLE.HOS.Applets.Dummy
     {
         private readonly Horizon _system;
         private AppletSession _normalSession;
+        
         public event EventHandler AppletStateChanged;
+        
         public DummyApplet(Horizon system)
         {
             _system = system;
         }
+        
         public ResultCode Start(AppletSession normalSession, AppletSession interactiveSession)
         {
             _normalSession = normalSession;
@@ -24,10 +27,7 @@ namespace Ryujinx.HLE.HOS.Applets.Dummy
             _system.ReturnFocus();
             return ResultCode.Success;
         }
-        private static T ReadStruct<T>(byte[] data) where T : struct
-        {
-            return MemoryMarshal.Read<T>(data.AsSpan());
-        }
+        
         private static byte[] BuildResponse()
         {
             using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
@@ -35,9 +35,5 @@ namespace Ryujinx.HLE.HOS.Applets.Dummy
             writer.Write((ulong)ResultCode.Success);
             return stream.ToArray();
         }
-        public ResultCode GetResult()
-        {
-            return ResultCode.Success;
-        }
     }
 }
diff --git a/src/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs b/src/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs
index 87d88fc65..0e043cc45 100644
--- a/src/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs
+++ b/src/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs
@@ -203,10 +203,5 @@ namespace Ryujinx.HLE.HOS.Applets.Error
                 _horizon.Device.UIHandler.DisplayErrorAppletDialog($"Error Number: {applicationErrorArg.ErrorNumber} (Details)", "\n" + detailsText, buttons.ToArray());
             }
         }
-
-        public ResultCode GetResult()
-        {
-            return ResultCode.Success;
-        }
     }
 }
diff --git a/src/Ryujinx.HLE/HOS/Applets/IApplet.cs b/src/Ryujinx.HLE/HOS/Applets/IApplet.cs
index bc5353841..4500b2f63 100644
--- a/src/Ryujinx.HLE/HOS/Applets/IApplet.cs
+++ b/src/Ryujinx.HLE/HOS/Applets/IApplet.cs
@@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Applets
         ResultCode Start(AppletSession normalSession,
                          AppletSession interactiveSession);
 
-        ResultCode GetResult();
+        ResultCode GetResult() => ResultCode.Success;
 
         bool DrawTo(RenderingSurfaceInfo surfaceInfo, IVirtualMemoryManager destination, ulong position) => false;
 
diff --git a/src/Ryujinx.HLE/HOS/Applets/PlayerSelect/PlayerSelectApplet.cs b/src/Ryujinx.HLE/HOS/Applets/PlayerSelect/PlayerSelectApplet.cs
index ccc761ba1..05bddc76f 100644
--- a/src/Ryujinx.HLE/HOS/Applets/PlayerSelect/PlayerSelectApplet.cs
+++ b/src/Ryujinx.HLE/HOS/Applets/PlayerSelect/PlayerSelectApplet.cs
@@ -37,11 +37,6 @@ namespace Ryujinx.HLE.HOS.Applets
             return ResultCode.Success;
         }
 
-        public ResultCode GetResult()
-        {
-            return ResultCode.Success;
-        }
-
         private byte[] BuildResponse()
         {
             UserProfile currentUser = _system.AccountManager.LastOpenedUser;
diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs
index e04fc64fe..9ec202357 100644
--- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs
+++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs
@@ -144,11 +144,6 @@ namespace Ryujinx.HLE.HOS.Applets
             }
         }
 
-        public ResultCode GetResult()
-        {
-            return ResultCode.Success;
-        }
-
         private bool IsKeyboardActive()
         {
             return _backgroundState >= InlineKeyboardState.Appearing && _backgroundState < InlineKeyboardState.Disappearing;
diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/TRef.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/TRef.cs
index 32d9e68da..51571401f 100644
--- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/TRef.cs
+++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/TRef.cs
@@ -2,7 +2,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
 {
     /// <summary>
     /// Wraps a type in a class so it gets stored in the GC managed heap. This is used as communication mechanism
-    /// between classed that need to be disposed and, thus, can't share their references.
+    /// between classes that need to be disposed and, thus, can't share their references.
     /// </summary>
     /// <typeparam name="T">The internal type.</typeparam>
     class TRef<T>