IProfile.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(0x80L);
  24. long position = context.Request.ReceiveBuff[0].Position;
  25. MemoryHelper.FillWithZeros(context.Memory, position, 0x80);
  26. context.Memory.Write((ulong)position, 0);
  27. context.Memory.Write((ulong)position + 4, 1);
  28. context.Memory.Write((ulong)position + 8, 1L);
  29. return GetBase(context);
  30. }
  31. [Command(1)]
  32. // GetBase() -> nn::account::profile::ProfileBase
  33. public ResultCode GetBase(ServiceCtx context)
  34. {
  35. _profile.UserId.Write(context.ResponseData);
  36. context.ResponseData.Write(_profile.LastModifiedTimestamp);
  37. byte[] username = StringUtils.GetFixedLengthBytes(_profile.Name, 0x20, Encoding.UTF8);
  38. context.ResponseData.Write(username);
  39. return ResultCode.Success;
  40. }
  41. [Command(10)]
  42. // GetImageSize() -> u32
  43. public ResultCode GetImageSize(ServiceCtx context)
  44. {
  45. context.ResponseData.Write(_profilePictureStream.Length);
  46. return ResultCode.Success;
  47. }
  48. [Command(11)]
  49. // LoadImage() -> (u32, buffer<bytes, 6>)
  50. public ResultCode LoadImage(ServiceCtx context)
  51. {
  52. long bufferPosition = context.Request.ReceiveBuff[0].Position;
  53. long bufferLen = context.Request.ReceiveBuff[0].Size;
  54. byte[] profilePictureData = new byte[bufferLen];
  55. _profilePictureStream.Read(profilePictureData, 0, profilePictureData.Length);
  56. context.Memory.Write((ulong)bufferPosition, profilePictureData);
  57. context.ResponseData.Write(_profilePictureStream.Length);
  58. return ResultCode.Success;
  59. }
  60. }
  61. }