From 675f3f6f816d4f315c2f319d6b323834dc252590 Mon Sep 17 00:00:00 2001 From: emmauss Date: Sun, 2 Sep 2018 01:04:20 +0300 Subject: Implement loading of profile image (#391) * implement loading of profile image * rename icon to profilepicture * rename icon file --- Ryujinx.HLE/HOS/Services/Acc/IAccountService.cs | 125 +++++++++++++++++++++ .../Services/Acc/IAccountServiceForApplication.cs | 125 --------------------- Ryujinx.HLE/HOS/Services/Acc/IProfile.cs | 36 +++++- Ryujinx.HLE/HOS/Services/ServiceFactory.cs | 5 +- Ryujinx.HLE/Ryujinx.HLE.csproj | 8 ++ Ryujinx.HLE/RyujinxProfileImage.jpg | Bin 0 -> 5394 bytes 6 files changed, 171 insertions(+), 128 deletions(-) create mode 100644 Ryujinx.HLE/HOS/Services/Acc/IAccountService.cs delete mode 100644 Ryujinx.HLE/HOS/Services/Acc/IAccountServiceForApplication.cs create mode 100644 Ryujinx.HLE/RyujinxProfileImage.jpg diff --git a/Ryujinx.HLE/HOS/Services/Acc/IAccountService.cs b/Ryujinx.HLE/HOS/Services/Acc/IAccountService.cs new file mode 100644 index 00000000..8fd7bfea --- /dev/null +++ b/Ryujinx.HLE/HOS/Services/Acc/IAccountService.cs @@ -0,0 +1,125 @@ +using Ryujinx.HLE.HOS.Ipc; +using Ryujinx.HLE.HOS.SystemState; +using Ryujinx.HLE.Logging; +using System.Collections.Generic; + +using static Ryujinx.HLE.HOS.ErrorCode; + +namespace Ryujinx.HLE.HOS.Services.Acc +{ + class IAccountService : IpcService + { + private Dictionary m_Commands; + + public override IReadOnlyDictionary Commands => m_Commands; + + public IAccountService() + { + m_Commands = new Dictionary() + { + { 0, GetUserCount }, + { 1, GetUserExistence }, + { 2, ListAllUsers }, + { 3, ListOpenUsers }, + { 4, GetLastOpenedUser }, + { 5, GetProfile }, + { 100, InitializeApplicationInfo }, + { 101, GetBaasAccountManagerForApplication } + }; + } + + public long GetUserCount(ServiceCtx Context) + { + Context.ResponseData.Write(Context.Device.System.State.GetUserCount()); + + return 0; + } + + public long GetUserExistence(ServiceCtx Context) + { + UserId Uuid = new UserId( + Context.RequestData.ReadInt64(), + Context.RequestData.ReadInt64()); + + Context.ResponseData.Write(Context.Device.System.State.TryGetUser(Uuid, out _) ? 1 : 0); + + return 0; + } + + public long ListAllUsers(ServiceCtx Context) + { + return WriteUserList(Context, Context.Device.System.State.GetAllUsers()); + } + + public long ListOpenUsers(ServiceCtx Context) + { + return WriteUserList(Context, Context.Device.System.State.GetOpenUsers()); + } + + private long WriteUserList(ServiceCtx Context, IEnumerable Profiles) + { + long OutputPosition = Context.Request.RecvListBuff[0].Position; + long OutputSize = Context.Request.RecvListBuff[0].Size; + + long Offset = 0; + + foreach (UserProfile Profile in Profiles) + { + if ((ulong)Offset + 16 > (ulong)OutputSize) + { + break; + } + + byte[] Uuid = Profile.Uuid.Bytes; + + for (int Index = Uuid.Length - 1; Index >= 0; Index--) + { + Context.Memory.WriteByte(OutputPosition + Offset++, Uuid[Index]); + } + } + + return 0; + } + + public long GetLastOpenedUser(ServiceCtx Context) + { + UserProfile LastOpened = Context.Device.System.State.LastOpenUser; + + LastOpened.Uuid.Write(Context.ResponseData); + + return 0; + } + + public long GetProfile(ServiceCtx Context) + { + UserId Uuid = new UserId( + Context.RequestData.ReadInt64(), + Context.RequestData.ReadInt64()); + + if (!Context.Device.System.State.TryGetUser(Uuid, out UserProfile Profile)) + { + Context.Device.Log.PrintWarning(LogClass.ServiceAcc, $"User 0x{Uuid} not found!"); + + return MakeError(ErrorModule.Account, AccErr.UserNotFound); + } + + MakeObject(Context, new IProfile(Profile)); + + return 0; + } + + public long InitializeApplicationInfo(ServiceCtx Context) + { + Context.Device.Log.PrintStub(LogClass.ServiceAcc, "Stubbed."); + + return 0; + } + + public long GetBaasAccountManagerForApplication(ServiceCtx Context) + { + MakeObject(Context, new IManagerForApplication()); + + return 0; + } + } +} diff --git a/Ryujinx.HLE/HOS/Services/Acc/IAccountServiceForApplication.cs b/Ryujinx.HLE/HOS/Services/Acc/IAccountServiceForApplication.cs deleted file mode 100644 index 36dfd9ef..00000000 --- a/Ryujinx.HLE/HOS/Services/Acc/IAccountServiceForApplication.cs +++ /dev/null @@ -1,125 +0,0 @@ -using Ryujinx.HLE.HOS.Ipc; -using Ryujinx.HLE.HOS.SystemState; -using Ryujinx.HLE.Logging; -using System.Collections.Generic; - -using static Ryujinx.HLE.HOS.ErrorCode; - -namespace Ryujinx.HLE.HOS.Services.Acc -{ - class IAccountServiceForApplication : IpcService - { - private Dictionary m_Commands; - - public override IReadOnlyDictionary Commands => m_Commands; - - public IAccountServiceForApplication() - { - m_Commands = new Dictionary() - { - { 0, GetUserCount }, - { 1, GetUserExistence }, - { 2, ListAllUsers }, - { 3, ListOpenUsers }, - { 4, GetLastOpenedUser }, - { 5, GetProfile }, - { 100, InitializeApplicationInfo }, - { 101, GetBaasAccountManagerForApplication } - }; - } - - public long GetUserCount(ServiceCtx Context) - { - Context.ResponseData.Write(Context.Device.System.State.GetUserCount()); - - return 0; - } - - public long GetUserExistence(ServiceCtx Context) - { - UserId Uuid = new UserId( - Context.RequestData.ReadInt64(), - Context.RequestData.ReadInt64()); - - Context.ResponseData.Write(Context.Device.System.State.TryGetUser(Uuid, out _) ? 1 : 0); - - return 0; - } - - public long ListAllUsers(ServiceCtx Context) - { - return WriteUserList(Context, Context.Device.System.State.GetAllUsers()); - } - - public long ListOpenUsers(ServiceCtx Context) - { - return WriteUserList(Context, Context.Device.System.State.GetOpenUsers()); - } - - private long WriteUserList(ServiceCtx Context, IEnumerable Profiles) - { - long OutputPosition = Context.Request.RecvListBuff[0].Position; - long OutputSize = Context.Request.RecvListBuff[0].Size; - - long Offset = 0; - - foreach (UserProfile Profile in Profiles) - { - if ((ulong)Offset + 16 > (ulong)OutputSize) - { - break; - } - - byte[] Uuid = Profile.Uuid.Bytes; - - for (int Index = Uuid.Length - 1; Index >= 0; Index--) - { - Context.Memory.WriteByte(OutputPosition + Offset++, Uuid[Index]); - } - } - - return 0; - } - - public long GetLastOpenedUser(ServiceCtx Context) - { - UserProfile LastOpened = Context.Device.System.State.LastOpenUser; - - LastOpened.Uuid.Write(Context.ResponseData); - - return 0; - } - - public long GetProfile(ServiceCtx Context) - { - UserId Uuid = new UserId( - Context.RequestData.ReadInt64(), - Context.RequestData.ReadInt64()); - - if (!Context.Device.System.State.TryGetUser(Uuid, out UserProfile Profile)) - { - Context.Device.Log.PrintWarning(LogClass.ServiceAcc, $"User 0x{Uuid} not found!"); - - return MakeError(ErrorModule.Account, AccErr.UserNotFound); - } - - MakeObject(Context, new IProfile(Profile)); - - return 0; - } - - public long InitializeApplicationInfo(ServiceCtx Context) - { - Context.Device.Log.PrintStub(LogClass.ServiceAcc, "Stubbed."); - - return 0; - } - - public long GetBaasAccountManagerForApplication(ServiceCtx Context) - { - MakeObject(Context, new IManagerForApplication()); - - return 0; - } - } -} diff --git a/Ryujinx.HLE/HOS/Services/Acc/IProfile.cs b/Ryujinx.HLE/HOS/Services/Acc/IProfile.cs index 960cc49c..316f16d0 100644 --- a/Ryujinx.HLE/HOS/Services/Acc/IProfile.cs +++ b/Ryujinx.HLE/HOS/Services/Acc/IProfile.cs @@ -3,7 +3,10 @@ using Ryujinx.HLE.HOS.Ipc; using Ryujinx.HLE.HOS.SystemState; using Ryujinx.HLE.Logging; using Ryujinx.HLE.Utilities; +using System; using System.Collections.Generic; +using System.IO; +using System.Reflection; using System.Text; namespace Ryujinx.HLE.HOS.Services.Acc @@ -16,15 +19,21 @@ namespace Ryujinx.HLE.HOS.Services.Acc private UserProfile Profile; + private Stream ProfilePictureStream; + public IProfile(UserProfile Profile) { m_Commands = new Dictionary() { - { 0, Get }, - { 1, GetBase } + { 0, Get }, + { 1, GetBase }, + { 10, GetImageSize }, + { 11, LoadImage }, }; this.Profile = Profile; + + ProfilePictureStream = Assembly.GetCallingAssembly().GetManifestResourceStream("Ryujinx.HLE.RyujinxProfileImage.jpg"); } public long Get(ServiceCtx Context) @@ -54,5 +63,28 @@ namespace Ryujinx.HLE.HOS.Services.Acc return 0; } + + private long 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.WriteBytes(BufferPosition, ProfilePictureData); + + Context.ResponseData.Write(ProfilePictureStream.Length); + + return 0; + } + + private long GetImageSize(ServiceCtx Context) + { + Context.ResponseData.Write(ProfilePictureStream.Length); + + return 0; + } } } \ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/ServiceFactory.cs b/Ryujinx.HLE/HOS/Services/ServiceFactory.cs index babceb7d..5e65d1d1 100644 --- a/Ryujinx.HLE/HOS/Services/ServiceFactory.cs +++ b/Ryujinx.HLE/HOS/Services/ServiceFactory.cs @@ -31,7 +31,10 @@ namespace Ryujinx.HLE.HOS.Services switch (Name) { case "acc:u0": - return new IAccountServiceForApplication(); + return new IAccountService(); + + case "acc:u1": + return new IAccountService(); case "aoc:u": return new IAddOnContentManager(); diff --git a/Ryujinx.HLE/Ryujinx.HLE.csproj b/Ryujinx.HLE/Ryujinx.HLE.csproj index f7fb84a5..fa4c254e 100644 --- a/Ryujinx.HLE/Ryujinx.HLE.csproj +++ b/Ryujinx.HLE/Ryujinx.HLE.csproj @@ -13,6 +13,14 @@ true + + + + + + + + diff --git a/Ryujinx.HLE/RyujinxProfileImage.jpg b/Ryujinx.HLE/RyujinxProfileImage.jpg new file mode 100644 index 00000000..fe9ec2a9 Binary files /dev/null and b/Ryujinx.HLE/RyujinxProfileImage.jpg differ -- cgit v1.2.3