IProfile.cs 2.5 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> _commands;
  15. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  16. private UserProfile _profile;
  17. private Stream _profilePictureStream;
  18. public IProfile(UserProfile profile)
  19. {
  20. _commands = new Dictionary<int, ServiceProcessRequest>
  21. {
  22. { 0, Get },
  23. { 1, GetBase },
  24. { 10, GetImageSize },
  25. { 11, LoadImage }
  26. };
  27. _profile = profile;
  28. _profilePictureStream = Assembly.GetCallingAssembly().GetManifestResourceStream("Ryujinx.HLE.RyujinxProfileImage.jpg");
  29. }
  30. public long Get(ServiceCtx context)
  31. {
  32. Logger.PrintStub(LogClass.ServiceAcc);
  33. long position = context.Request.ReceiveBuff[0].Position;
  34. MemoryHelper.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. }