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 18:15:50 +01:00
|
|
|
using Ryujinx.Common.Logging;
|
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;
|
2020-01-30 16:39:05 +00:00
|
|
|
using System.Collections.Generic;
|
2019-11-24 23:45:54 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
2018-04-22 00:04:43 +01:00
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Prepo
|
2018-04-22 00:04:43 +01:00
|
|
|
{
|
2019-07-10 16:59:54 +01:00
|
|
|
[Service("prepo:a")]
|
2019-09-19 01:45:11 +01:00
|
|
|
[Service("prepo:a2")]
|
2019-07-10 16:59:54 +01:00
|
|
|
[Service("prepo:u")]
|
2018-04-22 00:04:43 +01:00
|
|
|
class IPrepoService : IpcService
|
|
|
|
{
|
2019-07-12 02:13:43 +01:00
|
|
|
public IPrepoService(ServiceCtx context) { }
|
2018-05-17 19:25:42 +01:00
|
|
|
|
2019-11-24 23:45:54 +00:00
|
|
|
[Command(10100)] // 1.0.0-5.1.0
|
|
|
|
// SaveReport(u64, pid, buffer<u8, 9>, buffer<bytes, 5>)
|
|
|
|
public ResultCode SaveReportOld(ServiceCtx context)
|
|
|
|
{
|
|
|
|
// We don't care about the differences since we don't use the play report.
|
|
|
|
return ProcessReport(context, withUserID: false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Command(10101)] // 1.0.0-5.1.0
|
|
|
|
// SaveReportWithUserOld(nn::account::Uid, u64, pid, buffer<u8, 9>, buffer<bytes, 5>)
|
|
|
|
public ResultCode SaveReportWithUserOld(ServiceCtx context)
|
|
|
|
{
|
|
|
|
// We don't care about the differences since we don't use the play report.
|
|
|
|
return ProcessReport(context, withUserID: true);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Command(10102)] // 6.0.0+
|
|
|
|
// SaveReport(u64, pid, buffer<u8, 9>, buffer<bytes, 5>)
|
|
|
|
public ResultCode SaveReport(ServiceCtx context)
|
|
|
|
{
|
|
|
|
// We don't care about the differences since we don't use the play report.
|
|
|
|
return ProcessReport(context, withUserID: false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Command(10103)] // 6.0.0+
|
2019-07-12 02:13:43 +01: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)
|
|
|
|
{
|
|
|
|
// We don't care about the differences since we don't use the play report.
|
|
|
|
return ProcessReport(context, withUserID: true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private ResultCode ProcessReport(ServiceCtx context, bool withUserID)
|
2018-05-17 19:25:42 +01:00
|
|
|
{
|
2020-02-02 03:24:17 +00:00
|
|
|
UserId userId = withUserID ? context.RequestData.ReadStruct<UserId>() : new UserId();
|
2019-11-24 23:45:54 +00:00
|
|
|
string gameRoom = StringUtils.ReadUtf8String(context);
|
|
|
|
|
|
|
|
if (withUserID)
|
|
|
|
{
|
|
|
|
if (userId.IsNull)
|
|
|
|
{
|
|
|
|
return ResultCode.InvalidArgument;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gameRoom == string.Empty)
|
|
|
|
{
|
|
|
|
return ResultCode.InvalidState;
|
|
|
|
}
|
|
|
|
|
|
|
|
long inputPosition = context.Request.SendBuff[0].Position;
|
|
|
|
long inputSize = context.Request.SendBuff[0].Size;
|
|
|
|
|
|
|
|
if (inputSize == 0)
|
|
|
|
{
|
|
|
|
return ResultCode.InvalidBufferSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte[] inputBuffer = context.Memory.ReadBytes(inputPosition, inputSize);
|
|
|
|
|
|
|
|
Logger.PrintInfo(LogClass.ServicePrepo, ReadReportBuffer(inputBuffer, gameRoom, userId));
|
2018-05-17 19:25:42 +01:00
|
|
|
|
2019-07-14 20:04:38 +01:00
|
|
|
return ResultCode.Success;
|
2018-05-17 19:25:42 +01: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
|
|
|
{
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
sb.AppendLine();
|
|
|
|
sb.AppendLine("PlayReport log:");
|
|
|
|
|
|
|
|
if (!userId.IsNull)
|
|
|
|
{
|
|
|
|
sb.AppendLine($" UserId: {userId.ToString()}");
|
|
|
|
}
|
|
|
|
|
|
|
|
sb.AppendLine($" Room: {room}");
|
|
|
|
|
2020-01-30 16:39:05 +00:00
|
|
|
var payload = Deserialize<IDictionary<string, object>>(buffer);
|
|
|
|
|
|
|
|
foreach (var field in payload)
|
2019-11-29 04:42:44 +00:00
|
|
|
{
|
2020-01-30 16:39:05 +00:00
|
|
|
sb.AppendLine($" Key: {field.Key}, Value: {field.Value}");
|
2019-11-29 04:42:44 +00:00
|
|
|
}
|
2019-11-24 23:45:54 +00:00
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
}
|
2020-01-30 16:39:05 +00:00
|
|
|
|
|
|
|
private static T Deserialize<T>(byte[] bytes)
|
|
|
|
{
|
|
|
|
MessagePackSerializer serializer = MessagePackSerializer.Get<T>();
|
|
|
|
|
|
|
|
using (MemoryStream byteStream = new MemoryStream(bytes))
|
|
|
|
{
|
|
|
|
return (T)serializer.Unpack(byteStream);
|
|
|
|
}
|
|
|
|
}
|
2018-04-22 00:04:43 +01:00
|
|
|
}
|
2020-01-30 16:39:05 +00:00
|
|
|
}
|