From 632a84155b537298b65da0653435882a753f0bbe Mon Sep 17 00:00:00 2001
From: Ac_K <Acoustik666@gmail.com>
Date: Tue, 24 Nov 2020 21:19:06 +0100
Subject: [PATCH] pctl: Implement IsRestrictionEnabled and fix
 CheckFreeCommunicationPermission (#1747)

* pctl: Implement IsRestrictionEnabled and fix CheckFreeCommunicationPermission

* fix comment
---
 .../IParentalControlService.cs                | 24 +++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/Ryujinx.HLE/HOS/Services/Pctl/ParentalControlServiceFactory/IParentalControlService.cs b/Ryujinx.HLE/HOS/Services/Pctl/ParentalControlServiceFactory/IParentalControlService.cs
index 0c792efaed..032c157d75 100644
--- a/Ryujinx.HLE/HOS/Services/Pctl/ParentalControlServiceFactory/IParentalControlService.cs
+++ b/Ryujinx.HLE/HOS/Services/Pctl/ParentalControlServiceFactory/IParentalControlService.cs
@@ -10,8 +10,12 @@ namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory
         private ulong _titleId;
         private bool  _freeCommunicationEnabled;
         private int[] _ratingAge;
+
+        // TODO: Find where they are set.
+        private bool  _restrictionEnabled                  = false;
         private bool  _featuresRestriction                 = false;
         private bool  _stereoVisionRestrictionConfigurable = true;
+
         private bool  _stereoVisionRestriction             = false;
 
         public IParentalControlService(ServiceCtx context, bool withInitialize, int permissionFlag)
@@ -73,13 +77,15 @@ namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory
         // CheckFreeCommunicationPermission()
         public ResultCode CheckFreeCommunicationPermission(ServiceCtx context)
         {
-            Logger.Stub?.PrintStub(LogClass.ServicePctl);
+            // TODO: This checks some extra internal fields which are to be determined.
 
-            if (!_freeCommunicationEnabled)
+            if (!_freeCommunicationEnabled && _restrictionEnabled)
             {
                 return ResultCode.FreeCommunicationDisabled;
             }
 
+            Logger.Stub?.PrintStub(LogClass.ServicePctl);
+
             return ResultCode.Success;
         }
 
@@ -90,6 +96,20 @@ namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory
             return IsStereoVisionPermittedImpl();
         }
 
+        [Command(1031)]
+        // IsRestrictionEnabled() -> b8
+        public ResultCode IsRestrictionEnabled(ServiceCtx context)
+        {
+            if ((_permissionFlag & 0x140) == 0)
+            {
+                return ResultCode.PermissionDenied;
+            }
+
+            context.ResponseData.Write(_restrictionEnabled);
+
+            return ResultCode.Success;
+        }
+
         [Command(1061)] // 4.0.0+
         // ConfirmStereoVisionRestrictionConfigurable()
         public ResultCode ConfirmStereoVisionRestrictionConfigurable(ServiceCtx context)