From ad1373248da68353226b8e1c254121d99310b829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B6glinger-Stelzer?= Date: Mon, 30 Nov 2020 17:39:59 +0100 Subject: [PATCH] Fixed rumble packet size handling in XUSB devices --- sdk/src/ViGEmClient.cpp | 4 ++-- sys/XusbPdo.cpp | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/sdk/src/ViGEmClient.cpp b/sdk/src/ViGEmClient.cpp index d09a0f8..c121494 100644 --- a/sdk/src/ViGEmClient.cpp +++ b/sdk/src/ViGEmClient.cpp @@ -621,7 +621,7 @@ VIGEM_ERROR vigem_target_x360_register_notification( continue; } - if (GetLastError() == ERROR_ACCESS_DENIED) + if (GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == ERROR_OPERATION_ABORTED) { CloseHandle(lOverlapped.hEvent); return; @@ -712,7 +712,7 @@ VIGEM_ERROR vigem_target_ds4_register_notification( continue; } - if (GetLastError() == ERROR_ACCESS_DENIED) + if (GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == ERROR_OPERATION_ABORTED) { CloseHandle(lOverlapped.hEvent); return VIGEM_ERROR_INVALID_TARGET; diff --git a/sys/XusbPdo.cpp b/sys/XusbPdo.cpp index 2a2de37..cb8e43d 100644 --- a/sys/XusbPdo.cpp +++ b/sys/XusbPdo.cpp @@ -1090,7 +1090,7 @@ void ViGEm::Bus::Targets::EmulationTargetXUSB::ProcessPendingNotification(WDFQUE // // Validate packet // - if (bufferLength != XUSB_RUMBLE_SIZE) + if (bufferLength != XUSB_RUMBLE_SIZE && bufferLength != XUSB_LEDSET_SIZE) { DMF_BufferQueue_Reuse(this->_UsbInterruptOutBufferQueue, clientBuffer); WdfRequestComplete(request, STATUS_INVALID_BUFFER_SIZE); @@ -1103,15 +1103,21 @@ void ViGEm::Bus::Targets::EmulationTargetXUSB::ProcessPendingNotification(WDFQUE reinterpret_cast(¬ify), nullptr ))) - { - // - // Assign values to output buffer - // + { notify->Size = sizeof(XUSB_REQUEST_NOTIFICATION); notify->SerialNo = this->_SerialNo; - notify->LedNumber = this->_LedNumber; - notify->LargeMotor = static_cast(clientBuffer)[3]; - notify->SmallMotor = static_cast(clientBuffer)[4]; + notify->LedNumber = this->_LedNumber; // Report last cached value + + if (bufferLength == XUSB_RUMBLE_SIZE) + { + notify->LargeMotor = static_cast(clientBuffer)[3]; + notify->SmallMotor = static_cast(clientBuffer)[4]; + } + else + { + notify->LargeMotor = this->_Rumble[3]; // Cached value + notify->SmallMotor = this->_Rumble[4]; // Cached value + } DumpAsHex("!! XUSB_REQUEST_NOTIFICATION", notify,