mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-10-08 02:11:07 +02:00
* 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>
255 lines
8.1 KiB
C#
255 lines
8.1 KiB
C#
using Ryujinx.Common;
|
|
using Ryujinx.Common.Logging;
|
|
using Ryujinx.Cpu;
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
|
using Ryujinx.HLE.HOS.Services.Account.Acc.AccountService;
|
|
using Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Account.Acc
|
|
{
|
|
class ApplicationServiceServer
|
|
{
|
|
readonly AccountServiceFlag _serviceFlag;
|
|
|
|
public ApplicationServiceServer(AccountServiceFlag serviceFlag)
|
|
{
|
|
_serviceFlag = serviceFlag;
|
|
}
|
|
|
|
public ResultCode GetUserCountImpl(ServiceCtx context)
|
|
{
|
|
context.ResponseData.Write(context.Device.System.AccountManager.GetUserCount());
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
public ResultCode GetUserExistenceImpl(ServiceCtx context)
|
|
{
|
|
ResultCode resultCode = CheckUserId(context, out UserId userId);
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
{
|
|
return resultCode;
|
|
}
|
|
|
|
context.ResponseData.Write(context.Device.System.AccountManager.TryGetUser(userId, out _));
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
public ResultCode ListAllUsers(ServiceCtx context)
|
|
{
|
|
return WriteUserList(context, context.Device.System.AccountManager.GetAllUsers());
|
|
}
|
|
|
|
public ResultCode ListOpenUsers(ServiceCtx context)
|
|
{
|
|
return WriteUserList(context, context.Device.System.AccountManager.GetOpenedUsers());
|
|
}
|
|
|
|
private ResultCode WriteUserList(ServiceCtx context, IEnumerable<UserProfile> profiles)
|
|
{
|
|
if (context.Request.RecvListBuff.Count == 0)
|
|
{
|
|
return ResultCode.InvalidBuffer;
|
|
}
|
|
|
|
ulong outputPosition = context.Request.RecvListBuff[0].Position;
|
|
ulong outputSize = context.Request.RecvListBuff[0].Size;
|
|
|
|
MemoryHelper.FillWithZeros(context.Memory, outputPosition, (int)outputSize);
|
|
|
|
ulong offset = 0;
|
|
|
|
foreach (UserProfile userProfile in profiles)
|
|
{
|
|
if (offset + 0x10 > outputSize)
|
|
{
|
|
break;
|
|
}
|
|
|
|
context.Memory.Write(outputPosition + offset, userProfile.UserId.High);
|
|
context.Memory.Write(outputPosition + offset + 8, userProfile.UserId.Low);
|
|
|
|
offset += 0x10;
|
|
}
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
public ResultCode GetLastOpenedUser(ServiceCtx context)
|
|
{
|
|
context.Device.System.AccountManager.LastOpenedUser.UserId.Write(context.ResponseData);
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
public ResultCode GetProfile(ServiceCtx context, out IProfile profile)
|
|
{
|
|
profile = default;
|
|
|
|
ResultCode resultCode = CheckUserId(context, out UserId userId);
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
{
|
|
return resultCode;
|
|
}
|
|
|
|
if (!context.Device.System.AccountManager.TryGetUser(userId, out UserProfile userProfile))
|
|
{
|
|
Logger.Warning?.Print(LogClass.ServiceAcc, $"User 0x{userId} not found!");
|
|
|
|
return ResultCode.UserNotFound;
|
|
}
|
|
|
|
profile = new IProfile(userProfile);
|
|
|
|
// Doesn't occur in our case.
|
|
// return ResultCode.NullObject;
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
public ResultCode IsUserRegistrationRequestPermitted(ServiceCtx context)
|
|
{
|
|
context.ResponseData.Write(_serviceFlag != AccountServiceFlag.Application);
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
public ResultCode TrySelectUserWithoutInteraction(ServiceCtx context)
|
|
{
|
|
if (context.Device.System.AccountManager.GetUserCount() < 1)
|
|
{
|
|
// Invalid UserId.
|
|
UserId.Null.Write(context.ResponseData);
|
|
|
|
return ResultCode.UserNotFound;
|
|
}
|
|
|
|
bool isNetworkServiceAccountRequired = context.RequestData.ReadBoolean();
|
|
|
|
if (isNetworkServiceAccountRequired)
|
|
{
|
|
// NOTE: This checks something related to baas (online), and then return an invalid UserId if the check in baas returns an error code.
|
|
// In our case, we can just log it for now.
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { isNetworkServiceAccountRequired });
|
|
}
|
|
|
|
// NOTE: As we returned an invalid UserId if there is more than one user earlier, now we can return only the first one.
|
|
context.Device.System.AccountManager.GetFirst().UserId.Write(context.ResponseData);
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
public ResultCode CheckNetworkServiceAvailabilityAsync(ServiceCtx context, out IAsyncContext asyncContext)
|
|
{
|
|
KEvent asyncEvent = new(context.Device.System.KernelContext);
|
|
AsyncExecution asyncExecution = new(asyncEvent);
|
|
|
|
asyncExecution.Initialize(1000, CheckNetworkServiceAvailabilityAsyncImpl);
|
|
|
|
asyncContext = new IAsyncContext(asyncExecution);
|
|
|
|
// return ResultCode.NullObject if the IAsyncContext pointer is null. Doesn't occur in our case.
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
private async Task CheckNetworkServiceAvailabilityAsyncImpl(CancellationToken token)
|
|
{
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAcc);
|
|
|
|
// TODO: Use a real function instead, with the CancellationToken.
|
|
await Task.CompletedTask;
|
|
}
|
|
|
|
public ResultCode StoreSaveDataThumbnail(ServiceCtx context)
|
|
{
|
|
ResultCode resultCode = CheckUserId(context, out UserId _);
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
{
|
|
return resultCode;
|
|
}
|
|
|
|
if (context.Request.SendBuff.Count == 0)
|
|
{
|
|
return ResultCode.InvalidBuffer;
|
|
}
|
|
|
|
ulong inputPosition = context.Request.SendBuff[0].Position;
|
|
ulong inputSize = context.Request.SendBuff[0].Size;
|
|
|
|
if (inputSize != 0x24000)
|
|
{
|
|
return ResultCode.InvalidBufferSize;
|
|
}
|
|
|
|
byte[] thumbnailBuffer = new byte[inputSize];
|
|
|
|
context.Memory.Read(inputPosition, thumbnailBuffer);
|
|
|
|
// NOTE: Account service call nn::fs::WriteSaveDataThumbnailFile().
|
|
// TODO: Store thumbnailBuffer somewhere, in save data 0x8000000000000010 ?
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAcc);
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
public ResultCode ClearSaveDataThumbnail(ServiceCtx context)
|
|
{
|
|
ResultCode resultCode = CheckUserId(context, out UserId _);
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
{
|
|
return resultCode;
|
|
}
|
|
|
|
/*
|
|
// NOTE: Doesn't occur in our case.
|
|
if (userId == null)
|
|
{
|
|
return ResultCode.InvalidArgument;
|
|
}
|
|
*/
|
|
|
|
// NOTE: Account service call nn::fs::WriteSaveDataThumbnailFileHeader();
|
|
// TODO: Clear the Thumbnail somewhere, in save data 0x8000000000000010 ?
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAcc);
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
public ResultCode ListOpenContextStoredUsers(ServiceCtx context)
|
|
{
|
|
return WriteUserList(context, context.Device.System.AccountManager.GetStoredOpenedUsers());
|
|
}
|
|
|
|
public ResultCode ListQualifiedUsers(ServiceCtx context)
|
|
{
|
|
// TODO: Determine how users are "qualified". We assume all users are "qualified" for now.
|
|
|
|
return WriteUserList(context, context.Device.System.AccountManager.GetAllUsers());
|
|
}
|
|
|
|
public ResultCode CheckUserId(ServiceCtx context, out UserId userId)
|
|
{
|
|
userId = context.RequestData.ReadStruct<UserId>();
|
|
|
|
if (userId.IsNull)
|
|
{
|
|
return ResultCode.NullArgument;
|
|
}
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
}
|
|
}
|