diff --git a/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs b/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs index 4bf05c62e2..e368307694 100644 --- a/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs +++ b/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs @@ -87,7 +87,7 @@ namespace Ryujinx.HLE.HOS.Services.Time WriteObjectToSharedMemory(NetworkSystemClockContextOffset, 4, context); } - private T ReadObjectFromSharedMemory(ulong offset, ulong padding) + private T ReadObjectFromSharedMemory(ulong offset, ulong padding) where T : unmanaged { ulong indexOffset = _timeSharedMemoryAddress + offset; @@ -111,7 +111,7 @@ namespace Ryujinx.HLE.HOS.Services.Time return result; } - private void WriteObjectToSharedMemory(ulong offset, ulong padding, T value) + private void WriteObjectToSharedMemory(ulong offset, ulong padding, T value) where T : unmanaged { ulong indexOffset = _timeSharedMemoryAddress + offset; uint newIndex = _device.Memory.Read(indexOffset) + 1; diff --git a/Ryujinx.HLE/Input/Hid.cs b/Ryujinx.HLE/Input/Hid.cs index b5ae1564e1..6ef33993dc 100644 --- a/Ryujinx.HLE/Input/Hid.cs +++ b/Ryujinx.HLE/Input/Hid.cs @@ -200,10 +200,14 @@ namespace Ryujinx.HLE.Input { SamplesTimestamp = _currentKeyboardEntry.SamplesTimestamp + 1, SamplesTimestamp2 = _currentKeyboardEntry.SamplesTimestamp2 + 1, - Keys = keyboard.Keys, Modifier = keyboard.Modifier, }; + for (int index = 0; index < keyboard.Keys.Length; index++) + { + newkeyboardEntry.Keys[index] = keyboard.Keys[index]; + } + _device.Memory.Write((ulong)keyboardEntryOffset, newkeyboardEntry); _currentKeyboardEntry = newkeyboardEntry; diff --git a/Ryujinx.HLE/Input/Keyboard/KeyboardEntry.cs b/Ryujinx.HLE/Input/Keyboard/KeyboardEntry.cs index be7d9399d1..b73403efaa 100644 --- a/Ryujinx.HLE/Input/Keyboard/KeyboardEntry.cs +++ b/Ryujinx.HLE/Input/Keyboard/KeyboardEntry.cs @@ -3,13 +3,11 @@ namespace Ryujinx.HLE.Input { [StructLayout(LayoutKind.Sequential)] - public struct KeyboardEntry + public unsafe struct KeyboardEntry { public long SamplesTimestamp; public long SamplesTimestamp2; public long Modifier; - - [MarshalAs(UnmanagedType.ByValArray , SizeConst = 0x8)] - public int[] Keys; + public fixed int Keys[8]; } } diff --git a/Ryujinx.Memory/MemoryBlock.cs b/Ryujinx.Memory/MemoryBlock.cs index 83aa9f3e27..5e37f9f7a0 100644 --- a/Ryujinx.Memory/MemoryBlock.cs +++ b/Ryujinx.Memory/MemoryBlock.cs @@ -57,9 +57,9 @@ namespace Ryujinx.Memory /// Address where the data is located /// Data at the specified address [MethodImpl(MethodImplOptions.AggressiveInlining)] - public T Read(ulong address) + public T Read(ulong address) where T : unmanaged { - return GetRef(address, Unsafe.SizeOf()); + return GetRef(address); } /// @@ -80,9 +80,9 @@ namespace Ryujinx.Memory /// Address to write the data into /// Data to be written [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Write(ulong address, T data) + public void Write(ulong address, T data) where T : unmanaged { - GetRef(address, Unsafe.SizeOf()) = data; + GetRef(address) = data; } /// @@ -123,10 +123,9 @@ namespace Ryujinx.Memory /// /// Data type /// Address of the memory region - /// Size in bytes of the memory region /// A reference to the given memory region data [MethodImpl(MethodImplOptions.AggressiveInlining)] - public unsafe ref T GetRef(ulong address, int size) + public unsafe ref T GetRef(ulong address) where T : unmanaged { IntPtr ptr = _pointer; @@ -135,6 +134,8 @@ namespace Ryujinx.Memory throw new ObjectDisposedException(nameof(MemoryBlock)); } + int size = Unsafe.SizeOf(); + ulong endAddress = address + (ulong)size; if (endAddress > Size || endAddress < address)