diff --git a/Ryujinx.HLE/HOS/Applets/IApplet.cs b/Ryujinx.HLE/HOS/Applets/IApplet.cs index b10ede68..a29eeb84 100644 --- a/Ryujinx.HLE/HOS/Applets/IApplet.cs +++ b/Ryujinx.HLE/HOS/Applets/IApplet.cs @@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Applets ResultCode GetResult(); - static T ReadStruct(ReadOnlySpan data) where T : struct + static T ReadStruct(ReadOnlySpan data) where T : unmanaged { return MemoryMarshal.Cast(data)[0]; } diff --git a/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs b/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs index ed54eb98..e142838c 100644 --- a/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs +++ b/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs @@ -41,7 +41,7 @@ namespace Ryujinx.HLE.HOS.Applets var keyboardConfig = _normalSession.Pop(); var transferMemory = _normalSession.Pop(); - _keyboardConfig = IApplet.ReadStruct(keyboardConfig); + _keyboardConfig = ReadStruct(keyboardConfig); if (_keyboardConfig.UseUtf8) { @@ -176,5 +176,20 @@ namespace Ryujinx.HLE.HOS.Applets return stream.ToArray(); } } + + private static T ReadStruct(byte[] data) + where T : struct + { + GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); + + try + { + return Marshal.PtrToStructure(handle.AddrOfPinnedObject()); + } + finally + { + handle.Free(); + } + } } }