From 53b9267b47a1541d596b763894c75fdecf5698e9 Mon Sep 17 00:00:00 2001
From: Ac_K <Acoustik666@gmail.com>
Date: Thu, 25 Mar 2021 23:25:49 +0100
Subject: [PATCH] am/ectx: Implement
 SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled and add service
 placeholder (#2136)

* am/ectx: Implement SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled and add service placeholder

This PR implements `am` service call `SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled` (closes #2028) accordingly to RE and adds placeholder for the `ectx` service. Both were added in 11.0.0+ firmware and are needed to boots games which needs this version.
Some games are now playable/bootable:

* Remove unused warning
---
 .../SystemAppletProxy/ICommonStateGetter.cs         | 13 +++++++++++++
 Ryujinx.HLE/HOS/Services/Ectx/IReaderForSystem.cs   |  8 ++++++++
 .../HOS/Services/Ectx/IWriterForApplication.cs      |  8 ++++++++
 Ryujinx.HLE/HOS/Services/Ectx/IWriterForSystem.cs   |  8 ++++++++
 4 files changed, 37 insertions(+)
 create mode 100644 Ryujinx.HLE/HOS/Services/Ectx/IReaderForSystem.cs
 create mode 100644 Ryujinx.HLE/HOS/Services/Ectx/IWriterForApplication.cs
 create mode 100644 Ryujinx.HLE/HOS/Services/Ectx/IWriterForSystem.cs

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 17b8dddfd1..27f2d1c8b9 100644
--- a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ICommonStateGetter.cs
+++ b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ICommonStateGetter.cs
@@ -13,7 +13,10 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
         private Lbl.LblControllerServer _lblControllerServer;
 
         private bool _vrModeEnabled;
+#pragma warning disable CS0169
         private bool _lcdBacklighOffEnabled;
+        private bool _requestExitToLibraryAppletAtExecuteNextProgramEnabled;
+#pragma warning restore CS0169
         private int  _messageEventHandle;
         private int  _displayResolutionChangedEventHandle;
 
@@ -237,5 +240,15 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
         {
             return (ResultCode)_apmSystemManagerServer.GetCurrentPerformanceConfiguration(context);
         }
+
+        [Command(900)] // 11.0.0+
+        // SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled()
+        public ResultCode SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled(ServiceCtx context)
+        {
+            // TODO : Find where the field is used.
+            _requestExitToLibraryAppletAtExecuteNextProgramEnabled = true;
+
+            return ResultCode.Success;
+        }
     }
 }
\ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Ectx/IReaderForSystem.cs b/Ryujinx.HLE/HOS/Services/Ectx/IReaderForSystem.cs
new file mode 100644
index 0000000000..52fe870245
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Ectx/IReaderForSystem.cs
@@ -0,0 +1,8 @@
+namespace Ryujinx.HLE.HOS.Services.Ectx
+{
+    [Service("ectx:r")] // 11.0.0+
+    class IReaderForSystem : IpcService
+    {
+        public IReaderForSystem(ServiceCtx context) { }
+    }
+}
\ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Ectx/IWriterForApplication.cs b/Ryujinx.HLE/HOS/Services/Ectx/IWriterForApplication.cs
new file mode 100644
index 0000000000..9401a6d717
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Ectx/IWriterForApplication.cs
@@ -0,0 +1,8 @@
+namespace Ryujinx.HLE.HOS.Services.Ectx
+{
+    [Service("ectx:aw")] // 11.0.0+
+    class IWriterForApplication : IpcService
+    {
+        public IWriterForApplication(ServiceCtx context) { }
+    }
+}
\ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Ectx/IWriterForSystem.cs b/Ryujinx.HLE/HOS/Services/Ectx/IWriterForSystem.cs
new file mode 100644
index 0000000000..621ec777d5
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Ectx/IWriterForSystem.cs
@@ -0,0 +1,8 @@
+namespace Ryujinx.HLE.HOS.Services.Ectx
+{
+    [Service("ectx:w")] // 11.0.0+
+    class IWriterForSystem : IpcService
+    {
+        public IWriterForSystem(ServiceCtx context) { }
+    }
+}
\ No newline at end of file