2020-03-24 22:26:37 +00:00
|
|
|
using MsgPack;
|
2020-01-30 16:39:05 +00:00
|
|
|
using MsgPack.Serialization;
|
2020-02-02 03:24:17 +00:00
|
|
|
using Ryujinx.Common;
|
2018-10-17 17:15:50 +00:00
|
|
|
using Ryujinx.Common.Logging;
|
2020-03-25 21:33:18 +00:00
|
|
|
using Ryujinx.Common.Utilities;
|
2020-02-02 03:24:17 +00:00
|
|
|
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
2019-11-24 23:45:54 +00:00
|
|
|
using Ryujinx.HLE.Utilities;
|
2021-02-11 19:24:54 +00:00
|
|
|
using System;
|
2019-11-24 23:45:54 +00:00
|
|
|
using System.Text;
|
2018-04-21 23:04:43 +00:00
|
|
|
|
2018-08-16 23:47:36 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Prepo
|
2018-04-21 23:04:43 +00:00
|
|
|
{
|
2021-02-11 19:24:54 +00:00
|
|
|
[Service("prepo:a", PrepoServicePermissionLevel.Admin)] // 1.0.0-5.1.0
|
|
|
|
[Service("prepo:a2", PrepoServicePermissionLevel.Admin)] // 6.0.0+
|
|
|
|
[Service("prepo:m", PrepoServicePermissionLevel.Manager)]
|
|
|
|
[Service("prepo:u", PrepoServicePermissionLevel.User)]
|
|
|
|
[Service("prepo:s", PrepoServicePermissionLevel.System)]
|
2018-04-21 23:04:43 +00:00
|
|
|
class IPrepoService : IpcService
|
|
|
|
{
|
2021-02-11 19:24:54 +00:00
|
|
|
private PrepoServicePermissionLevel _permission;
|
|
|
|
private ulong _systemSessionId;
|
|
|
|
|
|
|
|
public IPrepoService(ServiceCtx context, PrepoServicePermissionLevel permission)
|
|
|
|
{
|
|
|
|
_permission = permission;
|
|
|
|
}
|
2018-05-17 18:25:42 +00:00
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(10100)] // 1.0.0-5.1.0
|
|
|
|
[CommandHipc(10102)] // 6.0.0-9.2.0
|
|
|
|
[CommandHipc(10104)] // 10.0.0+
|
2019-11-24 23:45:54 +00:00
|
|
|
// SaveReport(u64, pid, buffer<u8, 9>, buffer<bytes, 5>)
|
|
|
|
public ResultCode SaveReport(ServiceCtx context)
|
|
|
|
{
|
2021-06-23 20:41:44 +00:00
|
|
|
if ((_permission & PrepoServicePermissionLevel.User) == 0)
|
2021-02-11 19:24:54 +00:00
|
|
|
{
|
|
|
|
return ResultCode.PermissionDenied;
|
|
|
|
}
|
|
|
|
|
2019-11-24 23:45:54 +00:00
|
|
|
// We don't care about the differences since we don't use the play report.
|
|
|
|
return ProcessReport(context, withUserID: false);
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(10101)] // 1.0.0-5.1.0
|
|
|
|
[CommandHipc(10103)] // 6.0.0-9.2.0
|
|
|
|
[CommandHipc(10105)] // 10.0.0+
|
2019-07-12 01:13:43 +00:00
|
|
|
// SaveReportWithUser(nn::account::Uid, u64, pid, buffer<u8, 9>, buffer<bytes, 5>)
|
2019-11-24 23:45:54 +00:00
|
|
|
public ResultCode SaveReportWithUser(ServiceCtx context)
|
|
|
|
{
|
2021-06-23 20:41:44 +00:00
|
|
|
if ((_permission & PrepoServicePermissionLevel.User) == 0)
|
2021-02-11 19:24:54 +00:00
|
|
|
{
|
|
|
|
return ResultCode.PermissionDenied;
|
|
|
|
}
|
|
|
|
|
2019-11-24 23:45:54 +00:00
|
|
|
// We don't care about the differences since we don't use the play report.
|
|
|
|
return ProcessReport(context, withUserID: true);
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(10200)]
|
2020-03-25 11:28:15 +00:00
|
|
|
// RequestImmediateTransmission()
|
|
|
|
public ResultCode RequestImmediateTransmission(ServiceCtx context)
|
|
|
|
{
|
|
|
|
// It signals an event of nn::prepo::detail::service::core::TransmissionStatusManager that requests the transmission of the report.
|
|
|
|
// Since we don't use reports it's fine to do nothing.
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(10300)]
|
2020-03-25 11:28:15 +00:00
|
|
|
// GetTransmissionStatus() -> u32
|
|
|
|
public ResultCode GetTransmissionStatus(ServiceCtx context)
|
|
|
|
{
|
|
|
|
// It returns the transmission result of nn::prepo::detail::service::core::TransmissionStatusManager.
|
|
|
|
// Since we don't use reports it's fine to return ResultCode.Success.
|
|
|
|
context.ResponseData.Write((int)ResultCode.Success);
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(10400)] // 9.0.0+
|
2021-02-11 19:24:54 +00:00
|
|
|
// GetSystemSessionId() -> u64
|
|
|
|
public ResultCode GetSystemSessionId(ServiceCtx context)
|
|
|
|
{
|
2021-06-23 20:41:44 +00:00
|
|
|
if ((_permission & PrepoServicePermissionLevel.User) == 0)
|
2021-02-11 19:24:54 +00:00
|
|
|
{
|
|
|
|
return ResultCode.PermissionDenied;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_systemSessionId == 0)
|
|
|
|
{
|
|
|
|
byte[] randomBuffer = new byte[8];
|
|
|
|
|
2022-11-16 18:34:18 +00:00
|
|
|
Random.Shared.NextBytes(randomBuffer);
|
2021-02-11 19:24:54 +00:00
|
|
|
|
|
|
|
_systemSessionId = BitConverter.ToUInt64(randomBuffer, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
context.ResponseData.Write(_systemSessionId);
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-06-23 20:41:44 +00:00
|
|
|
[CommandHipc(20100)]
|
|
|
|
// SaveSystemReport(u64, pid, buffer<u8, 9>, buffer<bytes, 5>)
|
|
|
|
public ResultCode SaveSystemReport(ServiceCtx context)
|
|
|
|
{
|
|
|
|
if ((_permission & PrepoServicePermissionLevel.System) != 0)
|
|
|
|
{
|
|
|
|
return ResultCode.PermissionDenied;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't care about the differences since we don't use the play report.
|
|
|
|
return ProcessReport(context, withUserID: false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[CommandHipc(20101)]
|
|
|
|
// SaveSystemReportWithUser(nn::account::Uid, u64, pid, buffer<u8, 9>, buffer<bytes, 5>)
|
|
|
|
public ResultCode SaveSystemReportWithUser(ServiceCtx context)
|
|
|
|
{
|
|
|
|
if ((_permission & PrepoServicePermissionLevel.System) != 0)
|
|
|
|
{
|
|
|
|
return ResultCode.PermissionDenied;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't care about the differences since we don't use the play report.
|
|
|
|
return ProcessReport(context, withUserID: true);
|
|
|
|
}
|
|
|
|
|
2019-11-24 23:45:54 +00:00
|
|
|
private ResultCode ProcessReport(ServiceCtx context, bool withUserID)
|
2018-05-17 18:25:42 +00:00
|
|
|
{
|
2020-07-05 00:58:11 +00:00
|
|
|
UserId userId = withUserID ? context.RequestData.ReadStruct<UserId>() : new UserId();
|
|
|
|
string gameRoom = StringUtils.ReadUtf8String(context);
|
2019-11-24 23:45:54 +00:00
|
|
|
|
|
|
|
if (withUserID)
|
|
|
|
{
|
|
|
|
if (userId.IsNull)
|
|
|
|
{
|
|
|
|
return ResultCode.InvalidArgument;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gameRoom == string.Empty)
|
|
|
|
{
|
|
|
|
return ResultCode.InvalidState;
|
|
|
|
}
|
|
|
|
|
2021-04-24 10:16:01 +00:00
|
|
|
ulong inputPosition = context.Request.SendBuff[0].Position;
|
|
|
|
ulong inputSize = context.Request.SendBuff[0].Size;
|
2019-11-24 23:45:54 +00:00
|
|
|
|
|
|
|
if (inputSize == 0)
|
|
|
|
{
|
|
|
|
return ResultCode.InvalidBufferSize;
|
|
|
|
}
|
|
|
|
|
2020-05-03 22:54:50 +00:00
|
|
|
byte[] inputBuffer = new byte[inputSize];
|
|
|
|
|
2021-04-24 10:16:01 +00:00
|
|
|
context.Memory.Read(inputPosition, inputBuffer);
|
2019-11-24 23:45:54 +00:00
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
Logger.Info?.Print(LogClass.ServicePrepo, ReadReportBuffer(inputBuffer, gameRoom, userId));
|
2018-05-17 18:25:42 +00:00
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2018-05-17 18:25:42 +00:00
|
|
|
}
|
2019-11-24 23:45:54 +00:00
|
|
|
|
2020-02-02 03:24:17 +00:00
|
|
|
private string ReadReportBuffer(byte[] buffer, string room, UserId userId)
|
2019-11-24 23:45:54 +00:00
|
|
|
{
|
2021-06-23 20:41:44 +00:00
|
|
|
StringBuilder builder = new StringBuilder();
|
2020-03-24 22:26:37 +00:00
|
|
|
MessagePackObject deserializedReport = MessagePackSerializer.UnpackMessagePackObject(buffer);
|
2019-11-24 23:45:54 +00:00
|
|
|
|
2020-03-24 22:26:37 +00:00
|
|
|
builder.AppendLine();
|
|
|
|
builder.AppendLine("PlayReport log:");
|
2019-11-24 23:45:54 +00:00
|
|
|
|
|
|
|
if (!userId.IsNull)
|
|
|
|
{
|
2020-07-05 00:58:11 +00:00
|
|
|
builder.AppendLine($" UserId: {userId}");
|
2019-11-24 23:45:54 +00:00
|
|
|
}
|
|
|
|
|
2020-03-24 22:26:37 +00:00
|
|
|
builder.AppendLine($" Room: {room}");
|
2020-03-25 21:33:18 +00:00
|
|
|
builder.AppendLine($" Report: {MessagePackObjectFormatter.Format(deserializedReport)}");
|
2019-11-24 23:45:54 +00:00
|
|
|
|
2020-03-24 22:26:37 +00:00
|
|
|
return builder.ToString();
|
2020-01-30 16:39:05 +00:00
|
|
|
}
|
2018-04-21 23:04:43 +00:00
|
|
|
}
|
2020-01-30 16:39:05 +00:00
|
|
|
}
|