IProfile.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.Cpu;
  3. using Ryujinx.HLE.Utilities;
  4. using System.IO;
  5. using System.Reflection;
  6. using System.Text;
  7. namespace Ryujinx.HLE.HOS.Services.Account.Acc
  8. {
  9. class IProfile : IpcService
  10. {
  11. private UserProfile _profile;
  12. private Stream _profilePictureStream;
  13. public IProfile(UserProfile profile)
  14. {
  15. _profile = profile;
  16. _profilePictureStream = Assembly.GetCallingAssembly().GetManifestResourceStream("Ryujinx.HLE.RyujinxProfileImage.jpg");
  17. }
  18. [Command(0)]
  19. // Get() -> (nn::account::profile::ProfileBase, buffer<nn::account::profile::UserData, 0x1a>)
  20. public ResultCode Get(ServiceCtx context)
  21. {
  22. Logger.Stub?.PrintStub(LogClass.ServiceAcc);
  23. long position = context.Request.ReceiveBuff[0].Position;
  24. MemoryHelper.FillWithZeros(context.Memory, position, 0x80);
  25. context.Memory.Write((ulong)position, 0);
  26. context.Memory.Write((ulong)position + 4, 1);
  27. context.Memory.Write((ulong)position + 8, 1L);
  28. return GetBase(context);
  29. }
  30. [Command(1)]
  31. // GetBase() -> nn::account::profile::ProfileBase
  32. public ResultCode GetBase(ServiceCtx context)
  33. {
  34. _profile.UserId.Write(context.ResponseData);
  35. context.ResponseData.Write(_profile.LastModifiedTimestamp);
  36. byte[] username = StringUtils.GetFixedLengthBytes(_profile.Name, 0x20, Encoding.UTF8);
  37. context.ResponseData.Write(username);
  38. return ResultCode.Success;
  39. }
  40. [Command(10)]
  41. // GetImageSize() -> u32
  42. public ResultCode GetImageSize(ServiceCtx context)
  43. {
  44. context.ResponseData.Write(_profilePictureStream.Length);
  45. return ResultCode.Success;
  46. }
  47. [Command(11)]
  48. // LoadImage() -> (u32, buffer<bytes, 6>)
  49. public ResultCode LoadImage(ServiceCtx context)
  50. {
  51. long bufferPosition = context.Request.ReceiveBuff[0].Position;
  52. long bufferLen = context.Request.ReceiveBuff[0].Size;
  53. byte[] profilePictureData = new byte[bufferLen];
  54. _profilePictureStream.Read(profilePictureData, 0, profilePictureData.Length);
  55. context.Memory.Write((ulong)bufferPosition, profilePictureData);
  56. context.ResponseData.Write(_profilePictureStream.Length);
  57. return ResultCode.Success;
  58. }
  59. }
  60. }