diff --git a/Ryujinx/OsHle/Objects/Am/IStorage.cs b/Ryujinx/OsHle/Objects/Am/IStorage.cs index 53bb5cf1..d5a7ee61 100644 --- a/Ryujinx/OsHle/Objects/Am/IStorage.cs +++ b/Ryujinx/OsHle/Objects/Am/IStorage.cs @@ -25,9 +25,7 @@ namespace Ryujinx.OsHle.Objects.Am public long Open(ServiceCtx Context) { - IStorage Storage = Context.GetObject(); - - MakeObject(Context, new IStorageAccessor(Storage)); + MakeObject(Context, new IStorageAccessor(this)); return 0; } diff --git a/Ryujinx/OsHle/Objects/Am/IStorageAccessor.cs b/Ryujinx/OsHle/Objects/Am/IStorageAccessor.cs index fdd54744..bcf0fc01 100644 --- a/Ryujinx/OsHle/Objects/Am/IStorageAccessor.cs +++ b/Ryujinx/OsHle/Objects/Am/IStorageAccessor.cs @@ -11,7 +11,7 @@ namespace Ryujinx.OsHle.Objects.Am public IReadOnlyDictionary Commands => m_Commands; - public IStorage Storage { get; private set; } + private IStorage Storage; public IStorageAccessor(IStorage Storage) { @@ -26,19 +26,13 @@ namespace Ryujinx.OsHle.Objects.Am public long GetSize(ServiceCtx Context) { - IStorageAccessor Accessor = Context.GetObject(); - - Context.ResponseData.Write((long)Accessor.Storage.Data.Length); + Context.ResponseData.Write((long)Storage.Data.Length); return 0; } public long Read(ServiceCtx Context) { - IStorageAccessor Accessor = Context.GetObject(); - - IStorage Storage = Accessor.Storage; - long ReadPosition = Context.RequestData.ReadInt64(); if (Context.Request.RecvListBuff.Count > 0) diff --git a/Ryujinx/OsHle/Objects/FspSrv/IStorage.cs b/Ryujinx/OsHle/Objects/FspSrv/IStorage.cs index 2068a2cb..40fb87ca 100644 --- a/Ryujinx/OsHle/Objects/FspSrv/IStorage.cs +++ b/Ryujinx/OsHle/Objects/FspSrv/IStorage.cs @@ -11,7 +11,7 @@ namespace Ryujinx.OsHle.Objects.FspSrv public IReadOnlyDictionary Commands => m_Commands; - public Stream BaseStream { get; private set; } + private Stream BaseStream; public IStorage(Stream BaseStream) { @@ -23,10 +23,8 @@ namespace Ryujinx.OsHle.Objects.FspSrv this.BaseStream = BaseStream; } - public static long Read(ServiceCtx Context) + public long Read(ServiceCtx Context) { - IStorage Storage = Context.GetObject(); - long Offset = Context.RequestData.ReadInt64(); long Size = Context.RequestData.ReadInt64(); @@ -42,8 +40,8 @@ namespace Ryujinx.OsHle.Objects.FspSrv byte[] Data = new byte[Size]; - Storage.BaseStream.Seek(Offset, SeekOrigin.Begin); - Storage.BaseStream.Read(Data, 0, Data.Length); + BaseStream.Seek(Offset, SeekOrigin.Begin); + BaseStream.Read(Data, 0, Data.Length); AMemoryHelper.WriteBytes(Context.Memory, BuffDesc.Position, Data); } diff --git a/Ryujinx/OsHle/Objects/Vi/IHOSBinderDriver.cs b/Ryujinx/OsHle/Objects/Vi/IHOSBinderDriver.cs index 3c3211c7..157d600f 100644 --- a/Ryujinx/OsHle/Objects/Vi/IHOSBinderDriver.cs +++ b/Ryujinx/OsHle/Objects/Vi/IHOSBinderDriver.cs @@ -13,32 +13,22 @@ namespace Ryujinx.OsHle.Objects.Vi { class IHOSBinderDriver : IIpcInterface { + private delegate long ServiceProcessParcel(ServiceCtx Context, byte[] ParcelData); + private Dictionary m_Commands; - public IReadOnlyDictionary Commands => m_Commands; + private Dictionary<(string, int), ServiceProcessParcel> m_Methods; - private delegate long ServiceProcessRequest2(ServiceCtx Context, byte[] ParcelData); - - private Dictionary<(string, int), ServiceProcessRequest2> InterfaceMthd = - new Dictionary<(string, int), ServiceProcessRequest2>() - { - { ("android.gui.IGraphicBufferProducer", 0x1), GraphicBufferProducerRequestBuffer }, - { ("android.gui.IGraphicBufferProducer", 0x3), GraphicBufferProducerDequeueBuffer }, - { ("android.gui.IGraphicBufferProducer", 0x7), GraphicBufferProducerQueueBuffer }, - //{ ("android.gui.IGraphicBufferProducer", 0x8), GraphicBufferProducerCancelBuffer }, - { ("android.gui.IGraphicBufferProducer", 0x9), GraphicBufferProducerQuery }, - { ("android.gui.IGraphicBufferProducer", 0xa), GraphicBufferProducerConnect }, - { ("android.gui.IGraphicBufferProducer", 0xe), GraphicBufferPreallocateBuffer }, - }; + public IReadOnlyDictionary Commands => m_Commands; private class BufferObj { } - public IdPoolWithObj BufferSlots { get; private set; } + private IdPoolWithObj BufferSlots; - public byte[] Gbfr; + private byte[] Gbfr; public IHOSBinderDriver() { @@ -49,6 +39,17 @@ namespace Ryujinx.OsHle.Objects.Vi { 2, GetNativeHandle } }; + m_Methods = new Dictionary<(string, int), ServiceProcessParcel>() + { + { ("android.gui.IGraphicBufferProducer", 0x1), GraphicBufferProducerRequestBuffer }, + { ("android.gui.IGraphicBufferProducer", 0x3), GraphicBufferProducerDequeueBuffer }, + { ("android.gui.IGraphicBufferProducer", 0x7), GraphicBufferProducerQueueBuffer }, + { ("android.gui.IGraphicBufferProducer", 0x8), GraphicBufferProducerCancelBuffer }, + { ("android.gui.IGraphicBufferProducer", 0x9), GraphicBufferProducerQuery }, + { ("android.gui.IGraphicBufferProducer", 0xa), GraphicBufferProducerConnect }, + { ("android.gui.IGraphicBufferProducer", 0xe), GraphicBufferPreallocateBuffer } + }; + BufferSlots = new IdPoolWithObj(); } @@ -74,7 +75,7 @@ namespace Ryujinx.OsHle.Objects.Vi string InterfaceName = Encoding.Unicode.GetString(Data, 8, StrSize * 2); - if (InterfaceMthd.TryGetValue((InterfaceName, Code), out ServiceProcessRequest2 ProcReq)) + if (m_Methods.TryGetValue((InterfaceName, Code), out ServiceProcessParcel ProcReq)) { return ProcReq(Context, Data); } @@ -85,43 +86,37 @@ namespace Ryujinx.OsHle.Objects.Vi } } - private static long GraphicBufferProducerRequestBuffer(ServiceCtx Context, byte[] ParcelData) + private long GraphicBufferProducerRequestBuffer(ServiceCtx Context, byte[] ParcelData) { - IHOSBinderDriver BinderDriver = Context.GetObject(); - - int GbfrSize = BinderDriver.Gbfr?.Length ?? 0; + int GbfrSize = Gbfr?.Length ?? 0; byte[] Data = new byte[GbfrSize + 4]; - if (BinderDriver.Gbfr != null) + if (Gbfr != null) { - Buffer.BlockCopy(BinderDriver.Gbfr, 0, Data, 0, GbfrSize); + Buffer.BlockCopy(Gbfr, 0, Data, 0, GbfrSize); } return MakeReplyParcel(Context, Data); } - private static long GraphicBufferProducerDequeueBuffer(ServiceCtx Context, byte[] ParcelData) + private long GraphicBufferProducerDequeueBuffer(ServiceCtx Context, byte[] ParcelData) { - IHOSBinderDriver BinderDriver = Context.GetObject(); - //Note: It seems that the maximum number of slots is 64, because if we return //a Slot number > 63, it seems to cause a buffer overrun and it reads garbage. //Note 2: The size of each object associated with the slot is 0x30. - int Slot = BinderDriver.BufferSlots.GenerateId(new BufferObj()); + int Slot = BufferSlots.GenerateId(new BufferObj()); return MakeReplyParcel(Context, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); } - private static long GraphicBufferProducerQueueBuffer(ServiceCtx Context, byte[] ParcelData) + private long GraphicBufferProducerQueueBuffer(ServiceCtx Context, byte[] ParcelData) { return MakeReplyParcel(Context, 1280, 720, 0, 0, 0); } - private static long GraphicBufferProducerCancelBuffer(ServiceCtx Context, byte[] ParcelData) + private long GraphicBufferProducerCancelBuffer(ServiceCtx Context, byte[] ParcelData) { - IHOSBinderDriver BinderDriver = Context.GetObject(); - using (MemoryStream MS = new MemoryStream(ParcelData)) { BinaryReader Reader = new BinaryReader(MS); @@ -130,31 +125,29 @@ namespace Ryujinx.OsHle.Objects.Vi int Slot = Reader.ReadInt32(); - BinderDriver.BufferSlots.Delete(Slot); + BufferSlots.Delete(Slot); return MakeReplyParcel(Context, 0); } } - private static long GraphicBufferProducerQuery(ServiceCtx Context, byte[] ParcelData) + private long GraphicBufferProducerQuery(ServiceCtx Context, byte[] ParcelData) { return MakeReplyParcel(Context, 0, 0); } - private static long GraphicBufferProducerConnect(ServiceCtx Context, byte[] ParcelData) + private long GraphicBufferProducerConnect(ServiceCtx Context, byte[] ParcelData) { return MakeReplyParcel(Context, 1280, 720, 0, 0, 0); } - private static long GraphicBufferPreallocateBuffer(ServiceCtx Context, byte[] ParcelData) + private long GraphicBufferPreallocateBuffer(ServiceCtx Context, byte[] ParcelData) { - IHOSBinderDriver BinderDriver = Context.GetObject(); - int GbfrSize = ParcelData.Length - 0x54; - BinderDriver.Gbfr = new byte[GbfrSize]; + Gbfr = new byte[GbfrSize]; - Buffer.BlockCopy(ParcelData, 0x54, BinderDriver.Gbfr, 0, GbfrSize); + Buffer.BlockCopy(ParcelData, 0x54, Gbfr, 0, GbfrSize); using (MemoryStream MS = new MemoryStream(ParcelData)) { @@ -172,7 +165,7 @@ namespace Ryujinx.OsHle.Objects.Vi return MakeReplyParcel(Context, 0); } - private static long MakeReplyParcel(ServiceCtx Context, params int[] Ints) + private long MakeReplyParcel(ServiceCtx Context, params int[] Ints) { using (MemoryStream MS = new MemoryStream()) { @@ -187,7 +180,7 @@ namespace Ryujinx.OsHle.Objects.Vi } } - private static long MakeReplyParcel(ServiceCtx Context, byte[] Data) + private long MakeReplyParcel(ServiceCtx Context, byte[] Data) { long ReplyPos = Context.Request.ReceiveBuff[0].Position; long ReplySize = Context.Request.ReceiveBuff[0].Position; diff --git a/Ryujinx/OsHle/ServiceCtx.cs b/Ryujinx/OsHle/ServiceCtx.cs index 88ddcdb7..61356e6c 100644 --- a/Ryujinx/OsHle/ServiceCtx.cs +++ b/Ryujinx/OsHle/ServiceCtx.cs @@ -32,21 +32,5 @@ namespace Ryujinx.OsHle this.RequestData = RequestData; this.ResponseData = ResponseData; } - - public T GetObject() - { - object Obj = null; - - if (Session is HSessionObj SessionObj) - { - Obj = SessionObj.Obj; - } - if (Session is HDomain Dom) - { - Obj = Dom.GetObject(Request.DomObjId); - } - - return Obj is T ? (T)Obj : default(T); - } } } \ No newline at end of file