aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService
diff options
context:
space:
mode:
authorAc_K <Acoustik666@gmail.com>2021-01-02 23:34:28 +0100
committerGitHub <noreply@github.com>2021-01-02 23:34:28 +0100
commitb001040c2f005da21f91713ba1145083a01d0b01 (patch)
tree26a5967abe4ff29bf9c47f0364b87e34d9421ca8 /Ryujinx.HLE/HOS/Services/Account/Acc/AccountService
parent4f01c13f5054e3af775fc956584b553da934d476 (diff)
account: Services Refactoring (#1833)
* account: Services Refactoring * Remove extra empty space * Fix IProfile::Get * address gdkchan feedback
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Account/Acc/AccountService')
-rw-r--r--Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForApplication.cs61
-rw-r--r--Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForSystemService.cs47
-rw-r--r--Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfile.cs40
-rw-r--r--Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfileEditor.cs54
-rw-r--r--Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ManagerServer.cs122
-rw-r--r--Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs117
6 files changed, 441 insertions, 0 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForApplication.cs b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForApplication.cs
new file mode 100644
index 00000000..4631815b
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForApplication.cs
@@ -0,0 +1,61 @@
+namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
+{
+ class IManagerForApplication : IpcService
+ {
+ private ManagerServer _managerServer;
+
+ public IManagerForApplication(UserId userId)
+ {
+ _managerServer = new ManagerServer(userId);
+ }
+
+ [Command(0)]
+ // CheckAvailability()
+ public ResultCode CheckAvailability(ServiceCtx context)
+ {
+ return _managerServer.CheckAvailability(context);
+ }
+
+ [Command(1)]
+ // GetAccountId() -> nn::account::NetworkServiceAccountId
+ public ResultCode GetAccountId(ServiceCtx context)
+ {
+ return _managerServer.GetAccountId(context);
+ }
+
+ [Command(2)]
+ // EnsureIdTokenCacheAsync() -> object<nn::account::detail::IAsyncContext>
+ public ResultCode EnsureIdTokenCacheAsync(ServiceCtx context)
+ {
+ ResultCode resultCode = _managerServer.EnsureIdTokenCacheAsync(context, out IAsyncContext asyncContext);
+
+ if (resultCode == ResultCode.Success)
+ {
+ MakeObject(context, asyncContext);
+ }
+
+ return resultCode;
+ }
+
+ [Command(3)]
+ // LoadIdTokenCache() -> (u32 id_token_cache_size, buffer<bytes, 6>)
+ public ResultCode LoadIdTokenCache(ServiceCtx context)
+ {
+ return _managerServer.LoadIdTokenCache(context);
+ }
+
+ [Command(130)]
+ // GetNintendoAccountUserResourceCacheForApplication() -> (nn::account::NintendoAccountId, nn::account::nas::NasUserBaseForApplication, buffer<bytes, 6>)
+ public ResultCode GetNintendoAccountUserResourceCacheForApplication(ServiceCtx context)
+ {
+ return _managerServer.GetNintendoAccountUserResourceCacheForApplication(context);
+ }
+
+ [Command(160)] // 5.0.0+
+ // StoreOpenContext()
+ public ResultCode StoreOpenContext(ServiceCtx context)
+ {
+ return _managerServer.StoreOpenContext(context);
+ }
+ }
+} \ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForSystemService.cs b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForSystemService.cs
new file mode 100644
index 00000000..57a46666
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForSystemService.cs
@@ -0,0 +1,47 @@
+namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
+{
+ class IManagerForSystemService : IpcService
+ {
+ private ManagerServer _managerServer;
+
+ public IManagerForSystemService(UserId userId)
+ {
+ _managerServer = new ManagerServer(userId);
+ }
+
+ [Command(0)]
+ // CheckAvailability()
+ public ResultCode CheckAvailability(ServiceCtx context)
+ {
+ return _managerServer.CheckAvailability(context);
+ }
+
+ [Command(1)]
+ // GetAccountId() -> nn::account::NetworkServiceAccountId
+ public ResultCode GetAccountId(ServiceCtx context)
+ {
+ return _managerServer.GetAccountId(context);
+ }
+
+ [Command(2)]
+ // EnsureIdTokenCacheAsync() -> object<nn::account::detail::IAsyncContext>
+ public ResultCode EnsureIdTokenCacheAsync(ServiceCtx context)
+ {
+ ResultCode resultCode = _managerServer.EnsureIdTokenCacheAsync(context, out IAsyncContext asyncContext);
+
+ if (resultCode == ResultCode.Success)
+ {
+ MakeObject(context, asyncContext);
+ }
+
+ return resultCode;
+ }
+
+ [Command(3)]
+ // LoadIdTokenCache() -> (u32 id_token_cache_size, buffer<bytes, 6>)
+ public ResultCode LoadIdTokenCache(ServiceCtx context)
+ {
+ return _managerServer.LoadIdTokenCache(context);
+ }
+ }
+} \ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfile.cs b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfile.cs
new file mode 100644
index 00000000..c07d90ad
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfile.cs
@@ -0,0 +1,40 @@
+namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
+{
+ class IProfile : IpcService
+ {
+ private ProfileServer _profileServer;
+
+ public IProfile(UserProfile profile)
+ {
+ _profileServer = new ProfileServer(profile);
+ }
+
+ [Command(0)]
+ // Get() -> (nn::account::profile::ProfileBase, buffer<nn::account::profile::UserData, 0x1a>)
+ public ResultCode Get(ServiceCtx context)
+ {
+ return _profileServer.Get(context);
+ }
+
+ [Command(1)]
+ // GetBase() -> nn::account::profile::ProfileBase
+ public ResultCode GetBase(ServiceCtx context)
+ {
+ return _profileServer.GetBase(context);
+ }
+
+ [Command(10)]
+ // GetImageSize() -> u32
+ public ResultCode GetImageSize(ServiceCtx context)
+ {
+ return _profileServer.GetImageSize(context);
+ }
+
+ [Command(11)]
+ // LoadImage() -> (u32, buffer<bytes, 6>)
+ public ResultCode LoadImage(ServiceCtx context)
+ {
+ return _profileServer.LoadImage(context);
+ }
+ }
+} \ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfileEditor.cs b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfileEditor.cs
new file mode 100644
index 00000000..33fef3e1
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfileEditor.cs
@@ -0,0 +1,54 @@
+namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
+{
+ class IProfileEditor : IpcService
+ {
+ private ProfileServer _profileServer;
+
+ public IProfileEditor(UserProfile profile)
+ {
+ _profileServer = new ProfileServer(profile);
+ }
+
+ [Command(0)]
+ // Get() -> (nn::account::profile::ProfileBase, buffer<nn::account::profile::UserData, 0x1a>)
+ public ResultCode Get(ServiceCtx context)
+ {
+ return _profileServer.Get(context);
+ }
+
+ [Command(1)]
+ // GetBase() -> nn::account::profile::ProfileBase
+ public ResultCode GetBase(ServiceCtx context)
+ {
+ return _profileServer.GetBase(context);
+ }
+
+ [Command(10)]
+ // GetImageSize() -> u32
+ public ResultCode GetImageSize(ServiceCtx context)
+ {
+ return _profileServer.GetImageSize(context);
+ }
+
+ [Command(11)]
+ // LoadImage() -> (u32, buffer<bytes, 6>)
+ public ResultCode LoadImage(ServiceCtx context)
+ {
+ return _profileServer.LoadImage(context);
+ }
+
+ [Command(100)]
+ // Store(nn::account::profile::ProfileBase, buffer<nn::account::profile::UserData, 0x19>)
+ public ResultCode Store(ServiceCtx context)
+ {
+ return _profileServer.Store(context);
+ }
+
+ [Command(101)]
+ // StoreWithImage(nn::account::profile::ProfileBase, buffer<nn::account::profile::UserData, 0x19>, buffer<bytes, 5>)
+ public ResultCode StoreWithImage(ServiceCtx context)
+ {
+ return _profileServer.StoreWithImage(context);
+ }
+ }
+} \ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ManagerServer.cs b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ManagerServer.cs
new file mode 100644
index 00000000..c7efe778
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ManagerServer.cs
@@ -0,0 +1,122 @@
+using Ryujinx.Common.Logging;
+using Ryujinx.Cpu;
+using Ryujinx.HLE.HOS.Kernel.Threading;
+using Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
+{
+ class ManagerServer
+ {
+ // TODO: Determine where and how NetworkServiceAccountId is set.
+ private const long NetworkServiceAccountId = 0xcafe;
+
+ private UserId _userId;
+
+ public ManagerServer(UserId userId)
+ {
+ _userId = userId;
+ }
+
+ public ResultCode CheckAvailability(ServiceCtx context)
+ {
+ // NOTE: This opens the file at "su/baas/USERID_IN_UUID_STRING.dat" where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x".
+ // Then it searches the Availability of Online Services related to the UserId in this file and returns it.
+
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc);
+
+ // NOTE: Even if we try to return different error codes here, the guest still needs other calls.
+ return ResultCode.Success;
+ }
+
+ public ResultCode GetAccountId(ServiceCtx context)
+ {
+ // NOTE: This opens the file at "su/baas/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted
+ // as "%08x-%04x-%04x-%02x%02x-%08x%04x") in the account:/ savedata.
+ // Then it searches the NetworkServiceAccountId related to the UserId in this file and returns it.
+
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { NetworkServiceAccountId });
+
+ context.ResponseData.Write(NetworkServiceAccountId);
+
+ return ResultCode.Success;
+ }
+
+ public ResultCode EnsureIdTokenCacheAsync(ServiceCtx context, out IAsyncContext asyncContext)
+ {
+ KEvent asyncEvent = new KEvent(context.Device.System.KernelContext);
+ AsyncExecution asyncExecution = new AsyncExecution(asyncEvent);
+
+ asyncExecution.Initialize(1000, EnsureIdTokenCacheAsyncImpl);
+
+ 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 EnsureIdTokenCacheAsyncImpl(CancellationToken token)
+ {
+ // NOTE: This open the file at "su/baas/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x")
+ // in the "account:/" savedata.
+ // Then its read data, use dauth API with this data to get the Token Id and probably store the dauth response
+ // in "su/cache/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x") in the "account:/" savedata.
+ // Since we don't support online services, we can stub it.
+
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc);
+
+ // TODO: Use a real function instead, with the CancellationToken.
+ await Task.CompletedTask;
+ }
+
+ public ResultCode LoadIdTokenCache(ServiceCtx context)
+ {
+ long bufferPosition = context.Request.ReceiveBuff[0].Position;
+ long bufferSize = context.Request.ReceiveBuff[0].Size;
+
+ // NOTE: This opens the file at "su/cache/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x")
+ // in the "account:/" savedata and writes some data in the buffer.
+ // Since we don't support online services, we can stub it.
+
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc);
+
+ /*
+ if (internal_object != null)
+ {
+ if (bufferSize > 0xC00)
+ {
+ return ResultCode.InvalidIdTokenCacheBufferSize;
+ }
+ }
+ */
+
+ int idTokenCacheSize = 0;
+
+ MemoryHelper.FillWithZeros(context.Memory, bufferPosition, (int)bufferSize);
+
+ context.ResponseData.Write(idTokenCacheSize);
+
+ return ResultCode.Success;
+ }
+
+ public ResultCode GetNintendoAccountUserResourceCacheForApplication(ServiceCtx context)
+ {
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { NetworkServiceAccountId });
+
+ context.ResponseData.Write(NetworkServiceAccountId);
+
+ // TODO: determine and fill the output IPC buffer.
+
+ return ResultCode.Success;
+ }
+
+ public ResultCode StoreOpenContext(ServiceCtx context)
+ {
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc);
+
+ return ResultCode.Success;
+ }
+ }
+} \ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs
new file mode 100644
index 00000000..c6e0508f
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs
@@ -0,0 +1,117 @@
+using Ryujinx.Common.Logging;
+using Ryujinx.Cpu;
+using Ryujinx.HLE.Utilities;
+using System.IO;
+using System.Reflection;
+using System.Text;
+
+namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
+{
+ class ProfileServer
+ {
+ private UserProfile _profile;
+ private Stream _profilePictureStream;
+
+ public ProfileServer(UserProfile profile)
+ {
+ _profile = profile;
+ _profilePictureStream = Assembly.GetCallingAssembly().GetManifestResourceStream("Ryujinx.HLE.RyujinxProfileImage.jpg");
+ }
+
+ public ResultCode Get(ServiceCtx context)
+ {
+ context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(0x80L);
+
+ long bufferPosition = context.Request.RecvListBuff[0].Position;
+
+ MemoryHelper.FillWithZeros(context.Memory, bufferPosition, 0x80);
+
+ // TODO: Determine the struct.
+ context.Memory.Write((ulong)bufferPosition, 0); // Unknown
+ context.Memory.Write((ulong)bufferPosition + 4, 1); // Icon ID. 0 = Mii, the rest are character icon IDs.
+ context.Memory.Write((ulong)bufferPosition + 8, (byte)1); // Profile icon background color ID
+ // 0x07 bytes - Unknown
+ // 0x10 bytes - Some ID related to the Mii? All zeros when a character icon is used.
+ // 0x60 bytes - Usually zeros?
+
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc);
+
+ return GetBase(context);
+ }
+
+ public ResultCode GetBase(ServiceCtx context)
+ {
+ _profile.UserId.Write(context.ResponseData);
+
+ context.ResponseData.Write(_profile.LastModifiedTimestamp);
+
+ byte[] username = StringUtils.GetFixedLengthBytes(_profile.Name, 0x20, Encoding.UTF8);
+
+ context.ResponseData.Write(username);
+
+ return ResultCode.Success;
+ }
+
+ public ResultCode GetImageSize(ServiceCtx context)
+ {
+ context.ResponseData.Write(_profilePictureStream.Length);
+
+ return ResultCode.Success;
+ }
+
+ public ResultCode LoadImage(ServiceCtx context)
+ {
+ long bufferPosition = context.Request.ReceiveBuff[0].Position;
+ long bufferLen = context.Request.ReceiveBuff[0].Size;
+
+ byte[] profilePictureData = new byte[bufferLen];
+
+ _profilePictureStream.Read(profilePictureData, 0, profilePictureData.Length);
+
+ context.Memory.Write((ulong)bufferPosition, profilePictureData);
+
+ context.ResponseData.Write(_profilePictureStream.Length);
+
+ return ResultCode.Success;
+ }
+
+ public ResultCode Store(ServiceCtx context)
+ {
+ long userDataPosition = context.Request.PtrBuff[0].Position;
+ long userDataSize = context.Request.PtrBuff[0].Size;
+
+ byte[] userData = new byte[userDataSize];
+
+ context.Memory.Read((ulong)userDataPosition, userData);
+
+ // TODO: Read the nn::account::profile::ProfileBase and store everything in the savedata.
+
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { userDataSize });
+
+ return ResultCode.Success;
+ }
+
+ public ResultCode StoreWithImage(ServiceCtx context)
+ {
+ long userDataPosition = context.Request.PtrBuff[0].Position;
+ long userDataSize = context.Request.PtrBuff[0].Size;
+
+ byte[] userData = new byte[userDataSize];
+
+ context.Memory.Read((ulong)userDataPosition, userData);
+
+ long profilePicturePosition = context.Request.SendBuff[0].Position;
+ long profilePictureSize = context.Request.SendBuff[0].Size;
+
+ byte[] profilePictureData = new byte[profilePictureSize];
+
+ context.Memory.Read((ulong)profilePicturePosition, profilePictureData);
+
+ // TODO: Read the nn::account::profile::ProfileBase and store everything in the savedata.
+
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { userDataSize, profilePictureSize });
+
+ return ResultCode.Success;
+ }
+ }
+} \ No newline at end of file