* dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0052 warnings * Address or silence dotnet format IDE1006 warnings * Address dotnet format CA1816 warnings * Address or silence dotnet format CA2208 warnings * Address or silence dotnet format CA1806 and a few CA1854 warnings * Address dotnet format CA2211 warnings * Address dotnet format CA1822 warnings * Address or silence dotnet format CA1069 warnings * Make dotnet format succeed in style mode * Address or silence dotnet format CA2211 warnings * Address review comments * Address dotnet format CA2208 warnings properly * Make ProcessResult readonly * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Add previously silenced warnings back I have no clue how these disappeared * Revert formatting changes for while and for-loops * Format if-blocks correctly * Run dotnet format style after rebase * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format analyzers after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Disable 'prefer switch expression' rule * Add comments to disabled warnings * Fix a few disabled warnings * Fix naming rule violation, Convert shader properties to auto-property and convert values to const * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Start working on disabled warnings * Fix and silence a few dotnet-format warnings again * Run dotnet format after rebase * Use using declaration instead of block syntax * Address IDE0251 warnings * Address a few disabled IDE0060 warnings * Silence IDE0060 in .editorconfig * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Fix naming rule violations * Fix typo * Add trailing commas, use targeted new and use array initializer * Fix build issues * Fix remaining build issues * Remove SuppressMessage for CA1069 where possible * Address dotnet format issues * Address formatting issues Co-authored-by: Ac_K <acoustik666@gmail.com> * Add GetHashCode implementation for RenderingSurfaceInfo * Explicitly silence CA1822 for every affected method in Syscall * Address formatting issues in Demangler.cs * Address review feedback Co-authored-by: Ac_K <acoustik666@gmail.com> * Revert marking service methods as static * Next dotnet format pass * Address review feedback --------- Co-authored-by: Ac_K <acoustik666@gmail.com>
263 lines
8.6 KiB
C#
263 lines
8.6 KiB
C#
using Ryujinx.Common.Logging;
|
|
using Ryujinx.HLE.HOS.Services.Arp;
|
|
using System;
|
|
using static LibHac.Ns.ApplicationControlProperty;
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory
|
|
{
|
|
class IParentalControlService : IpcService
|
|
{
|
|
private readonly ulong _pid;
|
|
private readonly int _permissionFlag;
|
|
private ulong _titleId;
|
|
private ParentalControlFlagValue _parentalControlFlag;
|
|
#pragma warning disable IDE0052, CS0414 // Remove unread private member
|
|
private int[] _ratingAge;
|
|
|
|
// TODO: Find where they are set.
|
|
private readonly bool _restrictionEnabled = false;
|
|
private readonly bool _featuresRestriction = false;
|
|
private bool _freeCommunicationEnabled = false;
|
|
private readonly bool _stereoVisionRestrictionConfigurable = true;
|
|
private bool _stereoVisionRestriction = false;
|
|
#pragma warning restore IDE0052, CS0414
|
|
|
|
public IParentalControlService(ServiceCtx context, ulong pid, bool withInitialize, int permissionFlag)
|
|
{
|
|
_pid = pid;
|
|
_permissionFlag = permissionFlag;
|
|
|
|
if (withInitialize)
|
|
{
|
|
Initialize(context);
|
|
}
|
|
}
|
|
|
|
[CommandCmif(1)] // 4.0.0+
|
|
// Initialize()
|
|
public ResultCode Initialize(ServiceCtx context)
|
|
{
|
|
if ((_permissionFlag & 0x8001) == 0)
|
|
{
|
|
return ResultCode.PermissionDenied;
|
|
}
|
|
|
|
ResultCode resultCode = ResultCode.InvalidPid;
|
|
|
|
if (_pid != 0)
|
|
{
|
|
if ((_permissionFlag & 0x40) == 0)
|
|
{
|
|
ulong titleId = ApplicationLaunchProperty.GetByPid(context).TitleId;
|
|
|
|
if (titleId != 0)
|
|
{
|
|
_titleId = titleId;
|
|
|
|
// TODO: Call nn::arp::GetApplicationControlProperty here when implemented, if it return ResultCode.Success we assign fields.
|
|
_ratingAge = Array.ConvertAll(context.Device.Processes.ActiveApplication.ApplicationControlProperties.RatingAge.ItemsRo.ToArray(), Convert.ToInt32);
|
|
_parentalControlFlag = context.Device.Processes.ActiveApplication.ApplicationControlProperties.ParentalControlFlag;
|
|
}
|
|
}
|
|
|
|
if (_titleId != 0)
|
|
{
|
|
// TODO: Service store some private fields in another object.
|
|
|
|
if ((_permissionFlag & 0x8040) == 0)
|
|
{
|
|
// TODO: Service store TitleId and FreeCommunicationEnabled in another object.
|
|
// When it's done it signal an event in this object.
|
|
Logger.Stub?.PrintStub(LogClass.ServicePctl);
|
|
}
|
|
}
|
|
|
|
resultCode = ResultCode.Success;
|
|
}
|
|
|
|
return resultCode;
|
|
}
|
|
|
|
[CommandCmif(1001)]
|
|
// CheckFreeCommunicationPermission()
|
|
public ResultCode CheckFreeCommunicationPermission(ServiceCtx context)
|
|
{
|
|
if (_parentalControlFlag == ParentalControlFlagValue.FreeCommunication && _restrictionEnabled)
|
|
{
|
|
// TODO: It seems to checks if an entry exists in the FreeCommunicationApplicationList using the TitleId.
|
|
// Then it returns FreeCommunicationDisabled if the entry doesn't exist.
|
|
|
|
return ResultCode.FreeCommunicationDisabled;
|
|
}
|
|
|
|
_freeCommunicationEnabled = true;
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServicePctl);
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
[CommandCmif(1017)] // 10.0.0+
|
|
// EndFreeCommunication()
|
|
public ResultCode EndFreeCommunication(ServiceCtx context)
|
|
{
|
|
_freeCommunicationEnabled = false;
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
[CommandCmif(1013)] // 4.0.0+
|
|
// ConfirmStereoVisionPermission()
|
|
public ResultCode ConfirmStereoVisionPermission(ServiceCtx context)
|
|
{
|
|
return IsStereoVisionPermittedImpl();
|
|
}
|
|
|
|
[CommandCmif(1018)]
|
|
// IsFreeCommunicationAvailable()
|
|
public ResultCode IsFreeCommunicationAvailable(ServiceCtx context)
|
|
{
|
|
if (_parentalControlFlag == ParentalControlFlagValue.FreeCommunication && _restrictionEnabled)
|
|
{
|
|
// TODO: It seems to checks if an entry exists in the FreeCommunicationApplicationList using the TitleId.
|
|
// Then it returns FreeCommunicationDisabled if the entry doesn't exist.
|
|
|
|
return ResultCode.FreeCommunicationDisabled;
|
|
}
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServicePctl);
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
[CommandCmif(1031)]
|
|
// IsRestrictionEnabled() -> b8
|
|
public ResultCode IsRestrictionEnabled(ServiceCtx context)
|
|
{
|
|
if ((_permissionFlag & 0x140) == 0)
|
|
{
|
|
return ResultCode.PermissionDenied;
|
|
}
|
|
|
|
context.ResponseData.Write(_restrictionEnabled);
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
[CommandCmif(1061)] // 4.0.0+
|
|
// ConfirmStereoVisionRestrictionConfigurable()
|
|
public ResultCode ConfirmStereoVisionRestrictionConfigurable(ServiceCtx context)
|
|
{
|
|
if ((_permissionFlag & 2) == 0)
|
|
{
|
|
return ResultCode.PermissionDenied;
|
|
}
|
|
|
|
if (_stereoVisionRestrictionConfigurable)
|
|
{
|
|
return ResultCode.Success;
|
|
}
|
|
else
|
|
{
|
|
#pragma warning disable CS0162 // Unreachable code
|
|
return ResultCode.StereoVisionRestrictionConfigurableDisabled;
|
|
#pragma warning restore CS0162
|
|
}
|
|
}
|
|
|
|
[CommandCmif(1062)] // 4.0.0+
|
|
// GetStereoVisionRestriction() -> bool
|
|
public ResultCode GetStereoVisionRestriction(ServiceCtx context)
|
|
{
|
|
if ((_permissionFlag & 0x200) == 0)
|
|
{
|
|
return ResultCode.PermissionDenied;
|
|
}
|
|
|
|
#pragma warning disable // Remove unnecessary value assignment
|
|
bool stereoVisionRestriction = false;
|
|
#pragma warning restore IDE0059
|
|
|
|
if (_stereoVisionRestrictionConfigurable)
|
|
{
|
|
stereoVisionRestriction = _stereoVisionRestriction;
|
|
}
|
|
|
|
context.ResponseData.Write(stereoVisionRestriction);
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
[CommandCmif(1063)] // 4.0.0+
|
|
// SetStereoVisionRestriction(bool)
|
|
public ResultCode SetStereoVisionRestriction(ServiceCtx context)
|
|
{
|
|
if ((_permissionFlag & 0x200) == 0)
|
|
{
|
|
return ResultCode.PermissionDenied;
|
|
}
|
|
|
|
bool stereoVisionRestriction = context.RequestData.ReadBoolean();
|
|
|
|
if (!_featuresRestriction)
|
|
{
|
|
if (_stereoVisionRestrictionConfigurable)
|
|
{
|
|
_stereoVisionRestriction = stereoVisionRestriction;
|
|
|
|
// TODO: It signals an internal event of service. We have to determine where this event is used.
|
|
}
|
|
}
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
[CommandCmif(1064)] // 5.0.0+
|
|
// ResetConfirmedStereoVisionPermission()
|
|
public ResultCode ResetConfirmedStereoVisionPermission(ServiceCtx context)
|
|
{
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
[CommandCmif(1065)] // 5.0.0+
|
|
// IsStereoVisionPermitted() -> bool
|
|
public ResultCode IsStereoVisionPermitted(ServiceCtx context)
|
|
{
|
|
bool isStereoVisionPermitted = false;
|
|
|
|
ResultCode resultCode = IsStereoVisionPermittedImpl();
|
|
|
|
if (resultCode == ResultCode.Success)
|
|
{
|
|
isStereoVisionPermitted = true;
|
|
}
|
|
|
|
context.ResponseData.Write(isStereoVisionPermitted);
|
|
|
|
return resultCode;
|
|
}
|
|
|
|
private ResultCode IsStereoVisionPermittedImpl()
|
|
{
|
|
/*
|
|
// TODO: Application Exemptions are read from file "appExemptions.dat" in the service savedata.
|
|
// Since we don't support the pctl savedata for now, this can be implemented later.
|
|
|
|
if (appExemption)
|
|
{
|
|
return ResultCode.Success;
|
|
}
|
|
*/
|
|
|
|
if (_stereoVisionRestrictionConfigurable && _stereoVisionRestriction)
|
|
{
|
|
return ResultCode.StereoVisionDenied;
|
|
}
|
|
else
|
|
{
|
|
return ResultCode.Success;
|
|
}
|
|
}
|
|
}
|
|
}
|