IProfile.cs 2.6 KB

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