IPrepoService.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using MsgPack;
  2. using MsgPack.Serialization;
  3. using Ryujinx.Common;
  4. using Ryujinx.Common.Logging;
  5. using Ryujinx.Common.Utilities;
  6. using Ryujinx.HLE.HOS.Services.Account.Acc;
  7. using Ryujinx.HLE.Utilities;
  8. using System.Text;
  9. namespace Ryujinx.HLE.HOS.Services.Prepo
  10. {
  11. [Service("prepo:a")]
  12. [Service("prepo:a2")]
  13. [Service("prepo:u")]
  14. class IPrepoService : IpcService
  15. {
  16. public IPrepoService(ServiceCtx context) { }
  17. [Command(10100)] // 1.0.0-5.1.0
  18. [Command(10102)] // 6.0.0-9.2.0
  19. [Command(10104)] // 10.0.0+
  20. // SaveReport(u64, pid, buffer<u8, 9>, buffer<bytes, 5>)
  21. public ResultCode SaveReport(ServiceCtx context)
  22. {
  23. // We don't care about the differences since we don't use the play report.
  24. return ProcessReport(context, withUserID: false);
  25. }
  26. [Command(10101)] // 1.0.0-5.1.0
  27. [Command(10103)] // 6.0.0-9.2.0
  28. [Command(10105)] // 10.0.0+
  29. // SaveReportWithUser(nn::account::Uid, u64, pid, buffer<u8, 9>, buffer<bytes, 5>)
  30. public ResultCode SaveReportWithUser(ServiceCtx context)
  31. {
  32. // We don't care about the differences since we don't use the play report.
  33. return ProcessReport(context, withUserID: true);
  34. }
  35. [Command(10200)]
  36. // RequestImmediateTransmission()
  37. public ResultCode RequestImmediateTransmission(ServiceCtx context)
  38. {
  39. // It signals an event of nn::prepo::detail::service::core::TransmissionStatusManager that requests the transmission of the report.
  40. // Since we don't use reports it's fine to do nothing.
  41. return ResultCode.Success;
  42. }
  43. [Command(10300)]
  44. // GetTransmissionStatus() -> u32
  45. public ResultCode GetTransmissionStatus(ServiceCtx context)
  46. {
  47. // It returns the transmission result of nn::prepo::detail::service::core::TransmissionStatusManager.
  48. // Since we don't use reports it's fine to return ResultCode.Success.
  49. context.ResponseData.Write((int)ResultCode.Success);
  50. return ResultCode.Success;
  51. }
  52. private ResultCode ProcessReport(ServiceCtx context, bool withUserID)
  53. {
  54. UserId userId = withUserID ? context.RequestData.ReadStruct<UserId>() : new UserId();
  55. string gameRoom = StringUtils.ReadUtf8String(context);
  56. if (withUserID)
  57. {
  58. if (userId.IsNull)
  59. {
  60. return ResultCode.InvalidArgument;
  61. }
  62. }
  63. if (gameRoom == string.Empty)
  64. {
  65. return ResultCode.InvalidState;
  66. }
  67. long inputPosition = context.Request.SendBuff[0].Position;
  68. long inputSize = context.Request.SendBuff[0].Size;
  69. if (inputSize == 0)
  70. {
  71. return ResultCode.InvalidBufferSize;
  72. }
  73. byte[] inputBuffer = new byte[inputSize];
  74. context.Memory.Read((ulong)inputPosition, inputBuffer);
  75. Logger.Info?.Print(LogClass.ServicePrepo, ReadReportBuffer(inputBuffer, gameRoom, userId));
  76. return ResultCode.Success;
  77. }
  78. private string ReadReportBuffer(byte[] buffer, string room, UserId userId)
  79. {
  80. StringBuilder builder = new StringBuilder();
  81. MessagePackObject deserializedReport = MessagePackSerializer.UnpackMessagePackObject(buffer);
  82. builder.AppendLine();
  83. builder.AppendLine("PlayReport log:");
  84. if (!userId.IsNull)
  85. {
  86. builder.AppendLine($" UserId: {userId}");
  87. }
  88. builder.AppendLine($" Room: {room}");
  89. builder.AppendLine($" Report: {MessagePackObjectFormatter.Format(deserializedReport)}");
  90. return builder.ToString();
  91. }
  92. }
  93. }