ProfileServer.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.AccountService
  8. {
  9. class ProfileServer
  10. {
  11. private UserProfile _profile;
  12. private Stream _profilePictureStream;
  13. public ProfileServer(UserProfile profile)
  14. {
  15. _profile = profile;
  16. _profilePictureStream = Assembly.GetCallingAssembly().GetManifestResourceStream("Ryujinx.HLE.RyujinxProfileImage.jpg");
  17. }
  18. public ResultCode Get(ServiceCtx context)
  19. {
  20. context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(0x80L);
  21. long bufferPosition = context.Request.RecvListBuff[0].Position;
  22. MemoryHelper.FillWithZeros(context.Memory, bufferPosition, 0x80);
  23. // TODO: Determine the struct.
  24. context.Memory.Write((ulong)bufferPosition, 0); // Unknown
  25. context.Memory.Write((ulong)bufferPosition + 4, 1); // Icon ID. 0 = Mii, the rest are character icon IDs.
  26. context.Memory.Write((ulong)bufferPosition + 8, (byte)1); // Profile icon background color ID
  27. // 0x07 bytes - Unknown
  28. // 0x10 bytes - Some ID related to the Mii? All zeros when a character icon is used.
  29. // 0x60 bytes - Usually zeros?
  30. Logger.Stub?.PrintStub(LogClass.ServiceAcc);
  31. return GetBase(context);
  32. }
  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. public ResultCode GetImageSize(ServiceCtx context)
  42. {
  43. context.ResponseData.Write(_profilePictureStream.Length);
  44. return ResultCode.Success;
  45. }
  46. public ResultCode LoadImage(ServiceCtx context)
  47. {
  48. long bufferPosition = context.Request.ReceiveBuff[0].Position;
  49. long bufferLen = context.Request.ReceiveBuff[0].Size;
  50. byte[] profilePictureData = new byte[bufferLen];
  51. _profilePictureStream.Read(profilePictureData, 0, profilePictureData.Length);
  52. context.Memory.Write((ulong)bufferPosition, profilePictureData);
  53. context.ResponseData.Write(_profilePictureStream.Length);
  54. return ResultCode.Success;
  55. }
  56. public ResultCode Store(ServiceCtx context)
  57. {
  58. long userDataPosition = context.Request.PtrBuff[0].Position;
  59. long userDataSize = context.Request.PtrBuff[0].Size;
  60. byte[] userData = new byte[userDataSize];
  61. context.Memory.Read((ulong)userDataPosition, userData);
  62. // TODO: Read the nn::account::profile::ProfileBase and store everything in the savedata.
  63. Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { userDataSize });
  64. return ResultCode.Success;
  65. }
  66. public ResultCode StoreWithImage(ServiceCtx context)
  67. {
  68. long userDataPosition = context.Request.PtrBuff[0].Position;
  69. long userDataSize = context.Request.PtrBuff[0].Size;
  70. byte[] userData = new byte[userDataSize];
  71. context.Memory.Read((ulong)userDataPosition, userData);
  72. long profilePicturePosition = context.Request.SendBuff[0].Position;
  73. long profilePictureSize = context.Request.SendBuff[0].Size;
  74. byte[] profilePictureData = new byte[profilePictureSize];
  75. context.Memory.Read((ulong)profilePicturePosition, profilePictureData);
  76. // TODO: Read the nn::account::profile::ProfileBase and store everything in the savedata.
  77. Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { userDataSize, profilePictureSize });
  78. return ResultCode.Success;
  79. }
  80. }
  81. }