diff --git a/app/Tester/Tester.cpp b/app/Tester/Tester.cpp index 70cb574..5dcf350 100644 --- a/app/Tester/Tester.cpp +++ b/app/Tester/Tester.cpp @@ -18,7 +18,8 @@ VOID CALLBACK notification( PVIGEM_TARGET Target, UCHAR LargeMotor, UCHAR SmallMotor, - UCHAR LedNumber + UCHAR LedNumber, + LPVOID UserData ) { m.lock(); @@ -46,7 +47,7 @@ int main() ret = vigem_target_add(client, x360); - ret = vigem_target_x360_register_notification(client, x360, ¬ification); + ret = vigem_target_x360_register_notification(client, x360, ¬ification, nullptr); #endif const auto ds4 = vigem_target_ds4_alloc(); diff --git a/include/ViGEm/Client.h b/include/ViGEm/Client.h index 722f3f4..3d36283 100644 --- a/include/ViGEm/Client.h +++ b/include/ViGEm/Client.h @@ -113,7 +113,8 @@ extern "C" { PVIGEM_TARGET Target, UCHAR LargeMotor, UCHAR SmallMotor, - UCHAR LedNumber + UCHAR LedNumber, + LPVOID UserData ); typedef EVT_VIGEM_X360_NOTIFICATION *PFN_VIGEM_X360_NOTIFICATION; @@ -126,7 +127,8 @@ extern "C" { PVIGEM_TARGET Target, UCHAR LargeMotor, UCHAR SmallMotor, - DS4_LIGHTBAR_COLOR LightbarColor + DS4_LIGHTBAR_COLOR LightbarColor, + LPVOID UserData ); typedef EVT_VIGEM_DS4_NOTIFICATION *PFN_VIGEM_DS4_NOTIFICATION; @@ -291,10 +293,11 @@ extern "C" { * \param vigem The driver connection object. * \param target The target device object. * \param notification The notification callback. + * \param userData The user data passed to the notification callback. * * \return A VIGEM_ERROR. */ - VIGEM_API VIGEM_ERROR vigem_target_x360_register_notification(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, PFN_VIGEM_X360_NOTIFICATION notification); + VIGEM_API VIGEM_ERROR vigem_target_x360_register_notification(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, PFN_VIGEM_X360_NOTIFICATION notification, LPVOID userData); /** * \fn VIGEM_ERROR vigem_target_ds4_register_notification(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, PVIGEM_DS4_NOTIFICATION notification); @@ -309,10 +312,11 @@ extern "C" { * \param vigem The driver connection object. * \param target The target device object. * \param notification The notification callback. + * \param userData The user data passed to the notification callback. * * \return A VIGEM_ERROR. */ - VIGEM_API VIGEM_ERROR vigem_target_ds4_register_notification(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, PFN_VIGEM_DS4_NOTIFICATION notification); + VIGEM_API VIGEM_ERROR vigem_target_ds4_register_notification(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, PFN_VIGEM_DS4_NOTIFICATION notification, LPVOID userData); /** * \fn void vigem_target_x360_unregister_notification(PVIGEM_TARGET target); diff --git a/src/Internal.h b/src/Internal.h index d8f52ea..888a5a7 100644 --- a/src/Internal.h +++ b/src/Internal.h @@ -65,6 +65,7 @@ typedef struct _VIGEM_TARGET_T USHORT ProductId; VIGEM_TARGET_TYPE Type; FARPROC Notification; + LPVOID NotificationUserData; bool closingNotificationThreads; HANDLE cancelNotificationThreadEvent; diff --git a/src/ViGEmClient.cpp b/src/ViGEmClient.cpp index e4d0b88..18e8bd8 100644 --- a/src/ViGEmClient.cpp +++ b/src/ViGEmClient.cpp @@ -106,10 +106,11 @@ public: void ProcessNotificationRequest(PVIGEM_CLIENT client, PVIGEM_TARGET target) override { if(target->Notification != nullptr) - PFN_VIGEM_X360_NOTIFICATION(target->Notification)(client, target, + PFN_VIGEM_X360_NOTIFICATION(target->Notification)(client, target, ((PXUSB_REQUEST_NOTIFICATION)lpPayloadBuffer)->LargeMotor, ((PXUSB_REQUEST_NOTIFICATION)lpPayloadBuffer)->SmallMotor, - ((PXUSB_REQUEST_NOTIFICATION)lpPayloadBuffer)->LedNumber + ((PXUSB_REQUEST_NOTIFICATION)lpPayloadBuffer)->LedNumber, + target->NotificationUserData ); } }; @@ -129,7 +130,8 @@ public: PFN_VIGEM_DS4_NOTIFICATION(target->Notification)(client, target, ((PDS4_REQUEST_NOTIFICATION)lpPayloadBuffer)->Report.LargeMotor, ((PDS4_REQUEST_NOTIFICATION)lpPayloadBuffer)->Report.SmallMotor, - ((PDS4_REQUEST_NOTIFICATION)lpPayloadBuffer)->Report.LightbarColor + ((PDS4_REQUEST_NOTIFICATION)lpPayloadBuffer)->Report.LightbarColor, + target->NotificationUserData ); } }; @@ -658,7 +660,8 @@ void vigem_notification_thread_worker( VIGEM_ERROR vigem_target_x360_register_notification( PVIGEM_CLIENT vigem, PVIGEM_TARGET target, - PFN_VIGEM_X360_NOTIFICATION notification + PFN_VIGEM_X360_NOTIFICATION notification, + LPVOID userData ) { if (!vigem) @@ -677,6 +680,7 @@ VIGEM_ERROR vigem_target_x360_register_notification( return VIGEM_ERROR_CALLBACK_ALREADY_REGISTERED; target->Notification = reinterpret_cast(notification); + target->NotificationUserData = userData; if (target->cancelNotificationThreadEvent == 0) target->cancelNotificationThreadEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr); @@ -704,7 +708,8 @@ VIGEM_ERROR vigem_target_x360_register_notification( VIGEM_ERROR vigem_target_ds4_register_notification( PVIGEM_CLIENT vigem, PVIGEM_TARGET target, - PFN_VIGEM_DS4_NOTIFICATION notification + PFN_VIGEM_DS4_NOTIFICATION notification, + LPVOID userData ) { if (!vigem) @@ -723,6 +728,7 @@ VIGEM_ERROR vigem_target_ds4_register_notification( return VIGEM_ERROR_CALLBACK_ALREADY_REGISTERED; target->Notification = reinterpret_cast(notification); + target->NotificationUserData = userData; if (target->cancelNotificationThreadEvent == 0) target->cancelNotificationThreadEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr); @@ -767,6 +773,7 @@ void vigem_target_x360_unregister_notification(PVIGEM_TARGET target) } target->Notification = nullptr; + target->NotificationUserData = nullptr; } void vigem_target_ds4_unregister_notification(PVIGEM_TARGET target)