IProfile.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using ARMeilleure.Memory;
  2. using Ryujinx.Common.Logging;
  3. using Ryujinx.HLE.HOS.SystemState;
  4. using Ryujinx.HLE.Utilities;
  5. using System.IO;
  6. using System.Reflection;
  7. using System.Text;
  8. namespace Ryujinx.HLE.HOS.Services.Acc
  9. {
  10. class IProfile : IpcService
  11. {
  12. private UserProfile _profile;
  13. private Stream _profilePictureStream;
  14. public IProfile(UserProfile profile)
  15. {
  16. _profile = profile;
  17. _profilePictureStream = Assembly.GetCallingAssembly().GetManifestResourceStream("Ryujinx.HLE.RyujinxProfileImage.jpg");
  18. }
  19. [Command(0)]
  20. // Get() -> (nn::account::profile::ProfileBase, buffer<nn::account::profile::UserData, 0x1a>)
  21. public ResultCode Get(ServiceCtx context)
  22. {
  23. Logger.PrintStub(LogClass.ServiceAcc);
  24. long position = context.Request.ReceiveBuff[0].Position;
  25. MemoryHelper.FillWithZeros(context.Memory, position, 0x80);
  26. context.Memory.WriteInt32(position, 0);
  27. context.Memory.WriteInt32(position + 4, 1);
  28. context.Memory.WriteInt64(position + 8, 1);
  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.WriteBytes(bufferPosition, profilePictureData);
  57. context.ResponseData.Write(_profilePictureStream.Length);
  58. return ResultCode.Success;
  59. }
  60. }
  61. }