IProfile.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using ChocolArm64.Memory;
  2. using Ryujinx.Common.Logging;
  3. using Ryujinx.HLE.HOS.Ipc;
  4. using Ryujinx.HLE.HOS.SystemState;
  5. using Ryujinx.HLE.Utilities;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Reflection;
  9. using System.Text;
  10. namespace Ryujinx.HLE.HOS.Services.Acc
  11. {
  12. class IProfile : IpcService
  13. {
  14. private Dictionary<int, ServiceProcessRequest> m_Commands;
  15. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  16. private UserProfile Profile;
  17. private Stream ProfilePictureStream;
  18. public IProfile(UserProfile Profile)
  19. {
  20. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  21. {
  22. { 0, Get },
  23. { 1, GetBase },
  24. { 10, GetImageSize },
  25. { 11, LoadImage },
  26. };
  27. this.Profile = Profile;
  28. ProfilePictureStream = Assembly.GetCallingAssembly().GetManifestResourceStream("Ryujinx.HLE.RyujinxProfileImage.jpg");
  29. }
  30. public long Get(ServiceCtx Context)
  31. {
  32. Logger.PrintStub(LogClass.ServiceAcc, "Stubbed.");
  33. long Position = Context.Request.ReceiveBuff[0].Position;
  34. AMemoryHelper.FillWithZeros(Context.Memory, Position, 0x80);
  35. Context.Memory.WriteInt32(Position, 0);
  36. Context.Memory.WriteInt32(Position + 4, 1);
  37. Context.Memory.WriteInt64(Position + 8, 1);
  38. return GetBase(Context);
  39. }
  40. public long GetBase(ServiceCtx Context)
  41. {
  42. Profile.Uuid.Write(Context.ResponseData);
  43. Context.ResponseData.Write(Profile.LastModifiedTimestamp);
  44. byte[] Username = StringUtils.GetFixedLengthBytes(Profile.Name, 0x20, Encoding.UTF8);
  45. Context.ResponseData.Write(Username);
  46. return 0;
  47. }
  48. private long LoadImage(ServiceCtx Context)
  49. {
  50. long BufferPosition = Context.Request.ReceiveBuff[0].Position;
  51. long BufferLen = Context.Request.ReceiveBuff[0].Size;
  52. byte[] ProfilePictureData = new byte[BufferLen];
  53. ProfilePictureStream.Read(ProfilePictureData, 0, ProfilePictureData.Length);
  54. Context.Memory.WriteBytes(BufferPosition, ProfilePictureData);
  55. Context.ResponseData.Write(ProfilePictureStream.Length);
  56. return 0;
  57. }
  58. private long GetImageSize(ServiceCtx Context)
  59. {
  60. Context.ResponseData.Write(ProfilePictureStream.Length);
  61. return 0;
  62. }
  63. }
  64. }