1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-10-01 12:30:00 +02:00
Ryujinx/Ryujinx.HLE/HOS/Ipc/IpcHandleDesc.cs

92 lines
2.3 KiB
C#
Raw Normal View History

2018-02-05 00:08:20 +01:00
using System;
using System.IO;
namespace Ryujinx.HLE.HOS.Ipc
2018-02-05 00:08:20 +01:00
{
class IpcHandleDesc
{
public bool HasPId { get; private set; }
2018-02-05 00:08:20 +01:00
public long PId { get; private set; }
2018-02-05 00:08:20 +01:00
public int[] ToCopy { get; private set; }
public int[] ToMove { get; private set; }
2018-02-05 00:08:20 +01:00
public IpcHandleDesc(BinaryReader Reader)
2018-02-05 00:08:20 +01:00
{
int Word = Reader.ReadInt32();
2018-02-05 00:08:20 +01:00
HasPId = (Word & 1) != 0;
2018-02-05 00:08:20 +01:00
ToCopy = new int[(Word >> 1) & 0xf];
ToMove = new int[(Word >> 5) & 0xf];
2018-02-05 00:08:20 +01:00
PId = HasPId ? Reader.ReadInt64() : 0;
2018-02-05 00:08:20 +01:00
for (int Index = 0; Index < ToCopy.Length; Index++)
2018-02-05 00:08:20 +01:00
{
ToCopy[Index] = Reader.ReadInt32();
2018-02-05 00:08:20 +01:00
}
for (int Index = 0; Index < ToMove.Length; Index++)
2018-02-05 00:08:20 +01:00
{
ToMove[Index] = Reader.ReadInt32();
2018-02-05 00:08:20 +01:00
}
}
public IpcHandleDesc(int[] Copy, int[] Move)
2018-02-05 00:08:20 +01:00
{
ToCopy = Copy ?? throw new ArgumentNullException(nameof(Copy));
ToMove = Move ?? throw new ArgumentNullException(nameof(Move));
2018-02-05 00:08:20 +01:00
}
public IpcHandleDesc(int[] Copy, int[] Move, long PId) : this(Copy, Move)
2018-02-05 00:08:20 +01:00
{
this.PId = PId;
2018-02-05 00:08:20 +01:00
HasPId = true;
}
public static IpcHandleDesc MakeCopy(params int[] Handles)
{
return new IpcHandleDesc(Handles, new int[0]);
}
2018-02-05 00:08:20 +01:00
public static IpcHandleDesc MakeMove(params int[] Handles)
{
return new IpcHandleDesc(new int[0], Handles);
}
2018-02-05 00:08:20 +01:00
public byte[] GetBytes()
{
using (MemoryStream MS = new MemoryStream())
2018-02-05 00:08:20 +01:00
{
BinaryWriter Writer = new BinaryWriter(MS);
2018-02-05 00:08:20 +01:00
int Word = HasPId ? 1 : 0;
2018-02-05 00:08:20 +01:00
Word |= (ToCopy.Length & 0xf) << 1;
Word |= (ToMove.Length & 0xf) << 5;
2018-02-05 00:08:20 +01:00
Writer.Write(Word);
2018-02-05 00:08:20 +01:00
if (HasPId)
{
Writer.Write((long)PId);
2018-02-05 00:08:20 +01:00
}
foreach (int Handle in ToCopy)
2018-02-05 00:08:20 +01:00
{
Writer.Write(Handle);
2018-02-05 00:08:20 +01:00
}
foreach (int Handle in ToMove)
2018-02-05 00:08:20 +01:00
{
Writer.Write(Handle);
2018-02-05 00:08:20 +01:00
}
return MS.ToArray();
2018-02-05 00:08:20 +01:00
}
}
}
}