From 1fd4311e121771782055a220d86b95e9a1f990ee Mon Sep 17 00:00:00 2001
From: greggameplayer <33609333+greggameplayer@users.noreply.github.com>
Date: Sat, 11 Aug 2018 14:12:28 +0200
Subject: [PATCH] Add the ability to set or not docked mode via config file
 (#227)

* Add a toggleable DockedMode bool
---
 Ryujinx.HLE/OsHle/Services/Am/ICommonStateGetter.cs | 9 ++++++---
 Ryujinx.HLE/OsHle/SystemStateMgr.cs                 | 4 +++-
 Ryujinx/Config.cs                                   | 4 ++++
 Ryujinx/Ryujinx.conf                                | 5 ++++-
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/Ryujinx.HLE/OsHle/Services/Am/ICommonStateGetter.cs b/Ryujinx.HLE/OsHle/Services/Am/ICommonStateGetter.cs
index e1a13c5979..fd9ea40138 100644
--- a/Ryujinx.HLE/OsHle/Services/Am/ICommonStateGetter.cs
+++ b/Ryujinx.HLE/OsHle/Services/Am/ICommonStateGetter.cs
@@ -3,6 +3,7 @@ using Ryujinx.HLE.OsHle.Handles;
 using Ryujinx.HLE.OsHle.Ipc;
 using System.Collections.Generic;
 
+using static Ryujinx.HLE.OsHle.SystemStateMgr;
 using static Ryujinx.HLE.OsHle.ErrorCode;
 
 namespace Ryujinx.HLE.OsHle.Services.Am
@@ -57,14 +58,16 @@ namespace Ryujinx.HLE.OsHle.Services.Am
 
         public long GetOperationMode(ServiceCtx Context)
         {
-            Context.ResponseData.Write((byte)OperationMode.Handheld);
+            OperationMode Mode = DockedMode?OperationMode.Docked:  OperationMode.Handheld;
+            Context.ResponseData.Write((byte)Mode);
 
             return 0;
         }
 
         public long GetPerformanceMode(ServiceCtx Context)
         {
-            Context.ResponseData.Write((byte)Apm.PerformanceMode.Handheld);
+            Apm.PerformanceMode Mode = DockedMode?Apm.PerformanceMode.Docked:  Apm.PerformanceMode.Handheld;
+            Context.ResponseData.Write((byte)Mode);
 
             return 0;
         }
@@ -104,4 +107,4 @@ namespace Ryujinx.HLE.OsHle.Services.Am
             return 0;
         }
     }
-}
\ No newline at end of file
+}
diff --git a/Ryujinx.HLE/OsHle/SystemStateMgr.cs b/Ryujinx.HLE/OsHle/SystemStateMgr.cs
index 7b6ef7f3cf..87e3de1e17 100644
--- a/Ryujinx.HLE/OsHle/SystemStateMgr.cs
+++ b/Ryujinx.HLE/OsHle/SystemStateMgr.cs
@@ -36,6 +36,8 @@ namespace Ryujinx.HLE.OsHle
         internal long DesiredLanguageCode { get; private set; }
 
         internal string ActiveAudioOutput { get; private set; }
+        
+        public bool DockedMode { get; set; }
 
         public SystemStateMgr()
         {
@@ -82,4 +84,4 @@ namespace Ryujinx.HLE.OsHle
             return Code;
         }
     }
-}
\ No newline at end of file
+}
diff --git a/Ryujinx/Config.cs b/Ryujinx/Config.cs
index 4ed35b3d7e..b63455ee8a 100644
--- a/Ryujinx/Config.cs
+++ b/Ryujinx/Config.cs
@@ -7,6 +7,8 @@ using System.IO;
 using System.Linq;
 using System.Reflection;
 
+using static Ryujinx.HLE.OsHle.SystemStateMgr;
+
 namespace Ryujinx
 {
     public static class Config
@@ -31,6 +33,8 @@ namespace Ryujinx
             Log.SetEnable(LogLevel.Info,    Convert.ToBoolean(Parser.Value("Logging_Enable_Info")));
             Log.SetEnable(LogLevel.Warning, Convert.ToBoolean(Parser.Value("Logging_Enable_Warn")));
             Log.SetEnable(LogLevel.Error,   Convert.ToBoolean(Parser.Value("Logging_Enable_Error")));
+            
+            DockedMode = Convert.ToBoolean(Parser.Value("Docked_Mode"));
 
             string[] FilteredLogClasses = Parser.Value("Logging_Filtered_Classes").Split(',', StringSplitOptions.RemoveEmptyEntries);
 
diff --git a/Ryujinx/Ryujinx.conf b/Ryujinx/Ryujinx.conf
index 063bb2de4e..3225acc347 100644
--- a/Ryujinx/Ryujinx.conf
+++ b/Ryujinx/Ryujinx.conf
@@ -22,6 +22,9 @@ Logging_Enable_Error = true
 #Filtered log classes, seperated by ", ", eg. `Logging_Filtered_Classes = Loader, ServiceFS`
 Logging_Filtered_Classes =
 
+#Enable or Disable Docked Mode
+Docked_Mode = false
+
 #Controller Device Index
 GamePad_Index = 0
 
@@ -82,4 +85,4 @@ Controls_Right_JoyConController_Button_R = RShoulder
 Controls_Right_JoyConController_Button_ZR = RTrigger
 
 Controls_Left_JoyConController_Stick = LJoystick
-Controls_Right_JoyConController_Stick = RJoystick
\ No newline at end of file
+Controls_Right_JoyConController_Stick = RJoystick