From aca1c37d4b17c78a9b8b579b92010d80e4c8b150 Mon Sep 17 00:00:00 2001
From: Ac_K <Acoustik666@gmail.com>
Date: Mon, 21 Jun 2021 18:41:37 +0200
Subject: [PATCH] am: Add all known AppletMessage (#2378)

This PR add all known AppletMessage values for accuracy, nothing more.
`MessageInfo` is renamed to the right `AppletMessage` name.
---
 Ryujinx.HLE/HOS/Horizon.cs                    |  6 ++--
 .../SystemAppletProxy/ICommonStateGetter.cs   |  2 +-
 .../SystemAppletProxy/Types/AppletMessage.cs  | 36 +++++++++++++++++++
 .../SystemAppletProxy/Types/MessageInfo.cs    | 10 ------
 Ryujinx.HLE/HOS/SystemState/AppletStateMgr.cs | 12 +++++--
 5 files changed, 49 insertions(+), 17 deletions(-)
 create mode 100644 Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/AppletMessage.cs
 delete mode 100644 Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/MessageInfo.cs

diff --git a/Ryujinx.HLE/HOS/Horizon.cs b/Ryujinx.HLE/HOS/Horizon.cs
index 6a3a9e21c7..b8343cd186 100644
--- a/Ryujinx.HLE/HOS/Horizon.cs
+++ b/Ryujinx.HLE/HOS/Horizon.cs
@@ -321,8 +321,8 @@ namespace Ryujinx.HLE.HOS
                 State.DockedMode = newState;
                 PerformanceState.PerformanceMode = State.DockedMode ? PerformanceMode.Boost : PerformanceMode.Default;
 
-                AppletState.Messages.Enqueue(MessageInfo.OperationModeChanged);
-                AppletState.Messages.Enqueue(MessageInfo.PerformanceModeChanged);
+                AppletState.Messages.Enqueue(AppletMessage.OperationModeChanged);
+                AppletState.Messages.Enqueue(AppletMessage.PerformanceModeChanged);
                 AppletState.MessageEvent.ReadableEvent.Signal();
 
                 SignalDisplayResolutionChange();
@@ -338,7 +338,7 @@ namespace Ryujinx.HLE.HOS
 
         public void SimulateWakeUpMessage()
         {
-            AppletState.Messages.Enqueue(MessageInfo.Resume);
+            AppletState.Messages.Enqueue(AppletMessage.Resume);
             AppletState.MessageEvent.ReadableEvent.Signal();
         }
 
diff --git a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ICommonStateGetter.cs b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ICommonStateGetter.cs
index 8dc288e638..9e47f05b0c 100644
--- a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ICommonStateGetter.cs
+++ b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ICommonStateGetter.cs
@@ -50,7 +50,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
         // ReceiveMessage() -> nn::am::AppletMessage
         public ResultCode ReceiveMessage(ServiceCtx context)
         {
-            if (!context.Device.System.AppletState.Messages.TryDequeue(out MessageInfo message))
+            if (!context.Device.System.AppletState.Messages.TryDequeue(out AppletMessage message))
             {
                 return ResultCode.NoMessages;
             }
diff --git a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/AppletMessage.cs b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/AppletMessage.cs
new file mode 100644
index 0000000000..2920c32982
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/AppletMessage.cs
@@ -0,0 +1,36 @@
+namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy
+{
+    enum AppletMessage
+    {
+        None                             = 0,
+        ChangeIntoForeground             = 1,
+        ChangeIntoBackground             = 2,
+        Exit                             = 4,
+        ApplicationExited                = 6,
+        FocusStateChanged                = 15,
+        Resume                           = 16,
+        DetectShortPressingHomeButton    = 20,
+        DetectLongPressingHomeButton     = 21,
+        DetectShortPressingPowerButton   = 22,
+        DetectMiddlePressingPowerButton  = 23,
+        DetectLongPressingPowerButton    = 24,
+        RequestToPrepareSleep            = 25,
+        FinishedSleepSequence            = 26,
+        SleepRequiredByHighTemperature   = 27,
+        SleepRequiredByLowBattery        = 28,
+        AutoPowerDown                    = 29,
+        OperationModeChanged             = 30,
+        PerformanceModeChanged           = 31,
+        DetectReceivingCecSystemStandby  = 32,
+        SdCardRemoved                    = 33,
+        LaunchApplicationRequested       = 50,
+        RequestToDisplay                 = 51,
+        ShowApplicationLogo              = 55,
+        HideApplicationLogo              = 56,
+        ForceHideApplicationLogo         = 57,
+        FloatingApplicationDetected      = 60,
+        DetectShortPressingCaptureButton = 90,
+        AlbumScreenShotTaken             = 92,
+        AlbumRecordingSaved              = 93
+    }
+}
\ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/MessageInfo.cs b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/MessageInfo.cs
deleted file mode 100644
index 0291b9bc1c..0000000000
--- a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/MessageInfo.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy
-{
-    enum MessageInfo
-    {
-        FocusStateChanged      = 0xf,
-        Resume                 = 0x10,
-        OperationModeChanged   = 0x1e,
-        PerformanceModeChanged = 0x1f
-    }
-}
\ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/SystemState/AppletStateMgr.cs b/Ryujinx.HLE/HOS/SystemState/AppletStateMgr.cs
index 8fd2f08d88..9e18b9edcb 100644
--- a/Ryujinx.HLE/HOS/SystemState/AppletStateMgr.cs
+++ b/Ryujinx.HLE/HOS/SystemState/AppletStateMgr.cs
@@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.SystemState
 {
     class AppletStateMgr
     {
-        public ConcurrentQueue<MessageInfo> Messages { get; }
+        public ConcurrentQueue<AppletMessage> Messages { get; }
 
         public FocusState FocusState { get; private set; }
 
@@ -16,7 +16,7 @@ namespace Ryujinx.HLE.HOS.SystemState
 
         public AppletStateMgr(Horizon system)
         {
-            Messages     = new ConcurrentQueue<MessageInfo>();
+            Messages     = new ConcurrentQueue<AppletMessage>();
             MessageEvent = new KEvent(system.KernelContext);
 
             AppletResourceUserIds = new IdDictionary();
@@ -26,7 +26,13 @@ namespace Ryujinx.HLE.HOS.SystemState
         {
             FocusState = isFocused ? FocusState.InFocus : FocusState.OutOfFocus;
 
-            Messages.Enqueue(MessageInfo.FocusStateChanged);
+            Messages.Enqueue(AppletMessage.FocusStateChanged);
+
+            if (isFocused)
+            {
+                Messages.Enqueue(AppletMessage.ChangeIntoForeground);
+            }
+
             MessageEvent.ReadableEvent.Signal();
         }
     }