ProfileServer.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.Cpu;
  3. using Ryujinx.HLE.Utilities;
  4. using System.Text;
  5. namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
  6. {
  7. class ProfileServer
  8. {
  9. private UserProfile _profile;
  10. public ProfileServer(UserProfile profile)
  11. {
  12. _profile = profile;
  13. }
  14. public ResultCode Get(ServiceCtx context)
  15. {
  16. context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(0x80UL);
  17. ulong bufferPosition = context.Request.RecvListBuff[0].Position;
  18. MemoryHelper.FillWithZeros(context.Memory, bufferPosition, 0x80);
  19. // TODO: Determine the struct.
  20. context.Memory.Write(bufferPosition, 0); // Unknown
  21. context.Memory.Write(bufferPosition + 4, 1); // Icon ID. 0 = Mii, the rest are character icon IDs.
  22. context.Memory.Write(bufferPosition + 8, (byte)1); // Profile icon background color ID
  23. // 0x07 bytes - Unknown
  24. // 0x10 bytes - Some ID related to the Mii? All zeros when a character icon is used.
  25. // 0x60 bytes - Usually zeros?
  26. Logger.Stub?.PrintStub(LogClass.ServiceAcc);
  27. return GetBase(context);
  28. }
  29. public ResultCode GetBase(ServiceCtx context)
  30. {
  31. _profile.UserId.Write(context.ResponseData);
  32. context.ResponseData.Write(_profile.LastModifiedTimestamp);
  33. byte[] username = StringUtils.GetFixedLengthBytes(_profile.Name, 0x20, Encoding.UTF8);
  34. context.ResponseData.Write(username);
  35. return ResultCode.Success;
  36. }
  37. public ResultCode GetImageSize(ServiceCtx context)
  38. {
  39. context.ResponseData.Write(_profile.Image.Length);
  40. return ResultCode.Success;
  41. }
  42. public ResultCode LoadImage(ServiceCtx context)
  43. {
  44. ulong bufferPosition = context.Request.ReceiveBuff[0].Position;
  45. ulong bufferLen = context.Request.ReceiveBuff[0].Size;
  46. if ((ulong)_profile.Image.Length > bufferLen)
  47. {
  48. return ResultCode.InvalidBufferSize;
  49. }
  50. context.Memory.Write(bufferPosition, _profile.Image);
  51. context.ResponseData.Write(_profile.Image.Length);
  52. return ResultCode.Success;
  53. }
  54. public ResultCode Store(ServiceCtx context)
  55. {
  56. ulong userDataPosition = context.Request.PtrBuff[0].Position;
  57. ulong userDataSize = context.Request.PtrBuff[0].Size;
  58. byte[] userData = new byte[userDataSize];
  59. context.Memory.Read(userDataPosition, userData);
  60. // TODO: Read the nn::account::profile::ProfileBase and store everything in the savedata.
  61. Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { userDataSize });
  62. return ResultCode.Success;
  63. }
  64. public ResultCode StoreWithImage(ServiceCtx context)
  65. {
  66. ulong userDataPosition = context.Request.PtrBuff[0].Position;
  67. ulong userDataSize = context.Request.PtrBuff[0].Size;
  68. byte[] userData = new byte[userDataSize];
  69. context.Memory.Read(userDataPosition, userData);
  70. ulong profileImagePosition = context.Request.SendBuff[0].Position;
  71. ulong profileImageSize = context.Request.SendBuff[0].Size;
  72. byte[] profileImageData = new byte[profileImageSize];
  73. context.Memory.Read(profileImagePosition, profileImageData);
  74. // TODO: Read the nn::account::profile::ProfileBase and store everything in the savedata.
  75. Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { userDataSize, profileImageSize });
  76. return ResultCode.Success;
  77. }
  78. }
  79. }