2018-10-17 19:15:50 +02:00
|
|
|
using Ryujinx.Common.Logging;
|
2019-11-25 00:45:54 +01:00
|
|
|
using Ryujinx.HLE.Utilities;
|
|
|
|
using System;
|
|
|
|
using System.Buffers.Binary;
|
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
2018-04-22 01:04:43 +02:00
|
|
|
|
2018-08-17 01:47:36 +02:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Prepo
|
2018-04-22 01:04:43 +02:00
|
|
|
{
|
2019-07-10 17:59:54 +02:00
|
|
|
[Service("prepo:a")]
|
2019-09-19 02:45:11 +02:00
|
|
|
[Service("prepo:a2")]
|
2019-07-10 17:59:54 +02:00
|
|
|
[Service("prepo:u")]
|
2018-04-22 01:04:43 +02:00
|
|
|
class IPrepoService : IpcService
|
|
|
|
{
|
2019-07-12 03:13:43 +02:00
|
|
|
public IPrepoService(ServiceCtx context) { }
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2019-11-25 00:45:54 +01: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 03:13:43 +02:00
|
|
|
// SaveReportWithUser(nn::account::Uid, u64, pid, buffer<u8, 9>, buffer<bytes, 5>)
|
2019-11-25 00:45:54 +01: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 20:25:42 +02:00
|
|
|
{
|
2019-11-25 00:45:54 +01:00
|
|
|
UInt128 userId = withUserID ? new UInt128(context.RequestData.ReadBytes(0x10)) : new UInt128();
|
|
|
|
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 20:25:42 +02:00
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.Success;
|
2018-05-17 20:25:42 +02:00
|
|
|
}
|
2019-11-25 00:45:54 +01:00
|
|
|
|
|
|
|
public string ReadReportBuffer(byte[] buffer, string room, UInt128 userId)
|
|
|
|
{
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
sb.AppendLine();
|
|
|
|
sb.AppendLine("PlayReport log:");
|
|
|
|
|
|
|
|
if (!userId.IsNull)
|
|
|
|
{
|
|
|
|
sb.AppendLine($" UserId: {userId.ToString()}");
|
|
|
|
}
|
|
|
|
|
|
|
|
sb.AppendLine($" Room: {room}");
|
|
|
|
|
2019-11-29 05:42:44 +01:00
|
|
|
try
|
2019-11-25 00:45:54 +01:00
|
|
|
{
|
2019-11-29 05:42:44 +01:00
|
|
|
using (MemoryStream stream = new MemoryStream(buffer))
|
|
|
|
using (BinaryReader reader = new BinaryReader(stream))
|
2019-11-25 00:45:54 +01:00
|
|
|
{
|
2019-11-29 05:42:44 +01:00
|
|
|
byte unknown1 = reader.ReadByte(); // Version ?
|
|
|
|
short unknown2 = reader.ReadInt16(); // Size ?
|
2019-11-25 00:45:54 +01:00
|
|
|
|
2019-11-29 05:42:44 +01:00
|
|
|
bool isValue = false;
|
2019-11-25 00:45:54 +01:00
|
|
|
|
2019-11-29 05:42:44 +01:00
|
|
|
string fieldStr = string.Empty;
|
2019-11-25 00:45:54 +01:00
|
|
|
|
2019-11-29 05:42:44 +01:00
|
|
|
while (stream.Position != stream.Length)
|
2019-11-25 00:45:54 +01:00
|
|
|
{
|
2019-11-29 05:42:44 +01:00
|
|
|
byte descriptor = reader.ReadByte();
|
|
|
|
|
|
|
|
if (!isValue)
|
2019-11-25 00:45:54 +01:00
|
|
|
{
|
2019-11-29 05:42:44 +01:00
|
|
|
byte[] key = reader.ReadBytes(descriptor - 0xA0);
|
|
|
|
|
|
|
|
fieldStr = $" Key: {Encoding.ASCII.GetString(key)}";
|
|
|
|
|
|
|
|
isValue = true;
|
2019-11-25 00:45:54 +01:00
|
|
|
}
|
2019-11-29 05:42:44 +01:00
|
|
|
else
|
2019-11-25 00:45:54 +01:00
|
|
|
{
|
2019-11-29 05:42:44 +01:00
|
|
|
if (descriptor > 0xD0) // Int value.
|
2019-11-25 00:45:54 +01:00
|
|
|
{
|
2019-11-29 05:42:44 +01:00
|
|
|
if (descriptor - 0xD0 == 1)
|
|
|
|
{
|
|
|
|
fieldStr += $", Value: {BinaryPrimitives.ReverseEndianness(reader.ReadUInt16())}";
|
|
|
|
}
|
|
|
|
else if (descriptor - 0xD0 == 2)
|
|
|
|
{
|
|
|
|
fieldStr += $", Value: {BinaryPrimitives.ReverseEndianness(reader.ReadInt32())}";
|
|
|
|
}
|
|
|
|
else if (descriptor - 0xD0 == 4)
|
2019-11-25 00:45:54 +01:00
|
|
|
{
|
2019-11-29 05:42:44 +01:00
|
|
|
fieldStr += $", Value: {BinaryPrimitives.ReverseEndianness(reader.ReadInt64())}";
|
2019-11-25 00:45:54 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-29 05:42:44 +01:00
|
|
|
// Unknown.
|
|
|
|
break;
|
2019-11-25 00:45:54 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-29 05:42:44 +01:00
|
|
|
else if (descriptor > 0xA0 && descriptor < 0xD0) // String value, max size = 0x20 bytes ?
|
|
|
|
{
|
|
|
|
int size = descriptor - 0xA0;
|
|
|
|
string value = string.Empty;
|
|
|
|
byte[] rawValues = new byte[0];
|
2019-11-25 00:45:54 +01:00
|
|
|
|
2019-11-29 05:42:44 +01:00
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
{
|
|
|
|
byte chr = reader.ReadByte();
|
|
|
|
|
|
|
|
if (chr >= 0x20 && chr < 0x7f)
|
|
|
|
{
|
|
|
|
value += (char)chr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Array.Resize(ref rawValues, rawValues.Length + 1);
|
|
|
|
|
|
|
|
rawValues[rawValues.Length - 1] = chr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value != string.Empty)
|
|
|
|
{
|
|
|
|
fieldStr += $", Value: {value}";
|
|
|
|
}
|
2019-11-25 00:45:54 +01:00
|
|
|
|
2019-11-29 05:42:44 +01:00
|
|
|
// TODO(Ac_K): Determine why there are non-alphanumeric values sometimes.
|
|
|
|
if (rawValues.Length > 0)
|
|
|
|
{
|
|
|
|
fieldStr += $", RawValue: 0x{BitConverter.ToString(rawValues).Replace("-", "")}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Byte value.
|
2019-11-25 00:45:54 +01:00
|
|
|
{
|
2019-11-29 05:42:44 +01:00
|
|
|
fieldStr += $", Value: {descriptor}";
|
2019-11-25 00:45:54 +01:00
|
|
|
}
|
|
|
|
|
2019-11-29 05:42:44 +01:00
|
|
|
sb.AppendLine(fieldStr);
|
2019-11-25 00:45:54 +01:00
|
|
|
|
2019-11-29 05:42:44 +01:00
|
|
|
isValue = false;
|
|
|
|
}
|
2019-11-25 00:45:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-29 05:42:44 +01:00
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
sb.AppendLine(" Error while parsing the report buffer.");
|
|
|
|
}
|
2019-11-25 00:45:54 +01:00
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
}
|
2018-04-22 01:04:43 +02:00
|
|
|
}
|
2019-11-25 00:45:54 +01:00
|
|
|
}
|