51fa1b2cb0
* timezone: Make timezone implementation safe * hle: Do not use TrimEnd to parse ASCII strings This adds an util that handle reading an ASCII string in a safe way. Previously it was possible to read malformed data that could cause various undefined behaviours in multiple services. * hid: Remove an useless unsafe modifier on keyboard update * Address gdkchan's comment * Address gdkchan's comment
35 lines
1007 B
C#
35 lines
1007 B
C#
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
|
|
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Keyboard;
|
|
using System;
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Hid
|
|
{
|
|
public class KeyboardDevice : BaseDevice
|
|
{
|
|
public KeyboardDevice(Switch device, bool active) : base(device, active) { }
|
|
|
|
public void Update(KeyboardInput keyState)
|
|
{
|
|
ref RingLifo<KeyboardState> lifo = ref _device.Hid.SharedMemory.Keyboard;
|
|
|
|
if (!Active)
|
|
{
|
|
lifo.Clear();
|
|
|
|
return;
|
|
}
|
|
|
|
ref KeyboardState previousEntry = ref lifo.GetCurrentEntryRef();
|
|
|
|
KeyboardState newState = new KeyboardState
|
|
{
|
|
SamplingNumber = previousEntry.SamplingNumber + 1,
|
|
};
|
|
|
|
keyState.Keys.AsSpan().CopyTo(newState.Keys.RawData.ToSpan());
|
|
newState.Modifiers = (KeyboardModifier)keyState.Modifier;
|
|
|
|
lifo.Write(ref newState);
|
|
}
|
|
}
|
|
} |