Revert SwKbd Applet ReadStruct and fix IApplet's ReadStruct to catch (#1087)
error at compile time
This commit is contained in:
parent
e93ca84b14
commit
4d93f97408
2 changed files with 17 additions and 2 deletions
|
@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Applets
|
||||||
|
|
||||||
ResultCode GetResult();
|
ResultCode GetResult();
|
||||||
|
|
||||||
static T ReadStruct<T>(ReadOnlySpan<byte> data) where T : struct
|
static T ReadStruct<T>(ReadOnlySpan<byte> data) where T : unmanaged
|
||||||
{
|
{
|
||||||
return MemoryMarshal.Cast<byte, T>(data)[0];
|
return MemoryMarshal.Cast<byte, T>(data)[0];
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace Ryujinx.HLE.HOS.Applets
|
||||||
var keyboardConfig = _normalSession.Pop();
|
var keyboardConfig = _normalSession.Pop();
|
||||||
var transferMemory = _normalSession.Pop();
|
var transferMemory = _normalSession.Pop();
|
||||||
|
|
||||||
_keyboardConfig = IApplet.ReadStruct<SoftwareKeyboardConfig>(keyboardConfig);
|
_keyboardConfig = ReadStruct<SoftwareKeyboardConfig>(keyboardConfig);
|
||||||
|
|
||||||
if (_keyboardConfig.UseUtf8)
|
if (_keyboardConfig.UseUtf8)
|
||||||
{
|
{
|
||||||
|
@ -176,5 +176,20 @@ namespace Ryujinx.HLE.HOS.Applets
|
||||||
return stream.ToArray();
|
return stream.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static T ReadStruct<T>(byte[] data)
|
||||||
|
where T : struct
|
||||||
|
{
|
||||||
|
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Marshal.PtrToStructure<T>(handle.AddrOfPinnedObject());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
handle.Free();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue