diff --git a/Program/PacketParsing/Backends/GameInputBackendDevice.cs b/Program/PacketParsing/Backends/GameInputBackendDevice.cs index 2dec37d..4979904 100644 --- a/Program/PacketParsing/Backends/GameInputBackendDevice.cs +++ b/Program/PacketParsing/Backends/GameInputBackendDevice.cs @@ -17,6 +17,9 @@ internal class GameInputBackendDevice : IDisposable, IBackendClient private EventWaitHandle threadStop = new EventWaitHandle(false, EventResetMode.ManualReset); private volatile bool ioError = false; + private byte[] lastReport = Array.Empty(); + private int lastReportLength = 0; + private bool inputsEnabled = false; public ushort VendorId { get; } @@ -112,7 +115,9 @@ private unsafe void ReadThread() private unsafe void ReadThreaded(DeviceMapper mapper) { - ulong lastTimestamp = 0; + // We unfortunately can't rely on timestamp to determine state change, + // as guitar axis changes do not change the timestamp + // ulong lastTimestamp = 0; while (!threadStop.WaitOne(0)) { int hResult = gameInput.GetCurrentReading(GameInputKind.RawDeviceReport, device, out var reading); @@ -128,11 +133,11 @@ private unsafe void ReadThreaded(DeviceMapper mapper) using (reading) { - // Ignore unchanged reports - ulong timestamp = reading.GetTimestamp(); - if (lastTimestamp == timestamp) - continue; - lastTimestamp = timestamp; + // // Ignore unchanged reports + // ulong timestamp = reading.GetTimestamp(); + // if (lastTimestamp == timestamp) + // continue; + // lastTimestamp = timestamp; if (!HandleReading(reading, mapper)) break; @@ -158,6 +163,16 @@ private unsafe bool HandleReading(LightIGameInputReading reading, DeviceMapper m Debug.Assert(size == readSize); var data = new ReadOnlySpan(buffer, (int)size); + // Compare with last report to determine if any inputs changed + // Necessary due to the timestamp not updating on guitar axis changes + if (data.SequenceEqual(lastReport.AsSpan(0, lastReportLength))) + return true; + + if (lastReport.Length < data.Length) + lastReport = new byte[data.Length]; + data.CopyTo(lastReport); + lastReportLength = data.Length; + var packet = new XboxPacket(data, directionIn: true) { Header = new ReadOnlySpan(&reportId, sizeof(byte))