From 5652879f74be5fca9f630b01d049fb3912f0c82c Mon Sep 17 00:00:00 2001 From: Tinko Liu <24890691+TinkoLiu@users.noreply.github.com> Date: Sat, 25 Jun 2022 17:13:29 +0800 Subject: [PATCH 1/4] [TLAC]: add WinUSB as dependency --- source-code/source/plugins/TLAC/TLAC.vcxproj | 466 +++++------ .../source/plugins/TLAC/TLAC.vcxproj.filters | 748 +++++++++--------- 2 files changed, 619 insertions(+), 595 deletions(-) diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj b/source-code/source/plugins/TLAC/TLAC.vcxproj index 9d088f2f..5f643cd6 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj @@ -1,231 +1,237 @@ - - - - - Debug - x64 - - - Release - x64 - - - - 16.0 - {2B5533BB-04A1-424F-9BCA-1CA963B46B7F} - Win32Proj - TLAC - 10.0 - - - - DynamicLibrary - true - v142 - Unicode - - - DynamicLibrary - false - v142 - true - Unicode - - - - - - - - - - - - - - - false - $(ProjectName) - .dva - - - true - $(ProjectName) - .dva - - - - NotUsing - Level3 - MaxSpeed - true - true - true - NDEBUG;TLAC_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - - - stdcpp17 - ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\detours\include;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) - MultiThreadedDLL - -d2FH4- %(AdditionalOptions) - - - Windows - true - true - true - false - XINPUT9_1_0.LIB;dinput8.lib;dxguid.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - Xinput.h - ..\..\..\dependencies\detours\lib;..\..\..\dependencies\freeglut\lib;%(AdditionalLibraryDirectories) - -d2:-FH4- %(AdditionalOptions) - - - - - NotUsing - Level3 - Disabled - true - _DEBUG;TLAC_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - - - stdcpp17 - ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\detours\include;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) - -d2FH4- %(AdditionalOptions) - - - Windows - true - false - ..\..\..\dependencies\detours\lib;..\..\..\dependencies\freeglut\lib;%(AdditionalLibraryDirectories) - XINPUT9_1_0.LIB;dinput8.lib;dxguid.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - Xinput.h - -d2:-FH4- %(AdditionalOptions) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {2B5533BB-04A1-424F-9BCA-1CA963B46B7F} + Win32Proj + TLAC + 10.0 + + + + DynamicLibrary + true + v142 + Unicode + + + DynamicLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + false + $(ProjectName) + .dva + + + true + $(ProjectName) + .dva + + + + NotUsing + Level3 + MaxSpeed + true + true + true + NDEBUG;TLAC_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + stdcpp17 + ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\detours\include;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) + MultiThreadedDLL + -d2FH4- %(AdditionalOptions) + + + Windows + true + true + true + false + XINPUT9_1_0.LIB;dinput8.lib;dxguid.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Winusb.lib;Setupapi.lib;%(AdditionalDependencies) + Xinput.h + ..\..\..\dependencies\detours\lib;..\..\..\dependencies\freeglut\lib;%(AdditionalLibraryDirectories) + -d2:-FH4- %(AdditionalOptions) + + + + + NotUsing + Level3 + Disabled + true + _DEBUG;TLAC_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + stdcpp17 + ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\detours\include;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) + -d2FH4- %(AdditionalOptions) + + + Windows + true + false + ..\..\..\dependencies\detours\lib;..\..\..\dependencies\freeglut\lib;%(AdditionalLibraryDirectories) + XINPUT9_1_0.LIB;dinput8.lib;dxguid.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + Xinput.h + -d2:-FH4- %(AdditionalOptions) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters index 20663320..e3d29ad7 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters @@ -1,366 +1,384 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + \ No newline at end of file From 49c69de847cc53be07bdfc6399d6bfe4c2c02cd6 Mon Sep 17 00:00:00 2001 From: Tinko Liu <24890691+TinkoLiu@users.noreply.github.com> Date: Sat, 25 Jun 2022 17:17:00 +0800 Subject: [PATCH 2/4] [TLAC]: add DIVALLER support --- .../TLAC/Input/Bindings/DVLBinding.cpp | 29 ++ .../plugins/TLAC/Input/Bindings/DVLBinding.h | 19 ++ .../plugins/TLAC/Input/Divaller/Divaller.cpp | 272 ++++++++++++++++++ .../plugins/TLAC/Input/Divaller/Divaller.h | 52 ++++ .../TLAC/Input/Divaller/DivallerButton.h | 32 +++ .../TLAC/Input/Divaller/DivallerState.h | 10 + 6 files changed, 414 insertions(+) create mode 100644 source-code/source/plugins/TLAC/Input/Bindings/DVLBinding.cpp create mode 100644 source-code/source/plugins/TLAC/Input/Bindings/DVLBinding.h create mode 100644 source-code/source/plugins/TLAC/Input/Divaller/Divaller.cpp create mode 100644 source-code/source/plugins/TLAC/Input/Divaller/Divaller.h create mode 100644 source-code/source/plugins/TLAC/Input/Divaller/DivallerButton.h create mode 100644 source-code/source/plugins/TLAC/Input/Divaller/DivallerState.h diff --git a/source-code/source/plugins/TLAC/Input/Bindings/DVLBinding.cpp b/source-code/source/plugins/TLAC/Input/Bindings/DVLBinding.cpp new file mode 100644 index 00000000..7ea3d8ae --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/Bindings/DVLBinding.cpp @@ -0,0 +1,29 @@ +#include "DVLBinding.h" + +namespace TLAC::Input +{ + #define DivallerInstanceCheckDefault(checkFunc) (Divaller::InstanceInitialized() ? Divaller::GetInstance()->checkFunc : false) + + DivallerBinding::DivallerBinding(DivallerButton button) : Button(button) + { + } + + DivallerBinding::~DivallerBinding() + { + } + + bool DivallerBinding::IsDown() + { + return DivallerInstanceCheckDefault(IsDown(Button)); + } + + bool DivallerBinding::IsTapped() + { + return DivallerInstanceCheckDefault(IsTapped(Button)); + } + + bool DivallerBinding::IsReleased() + { + return DivallerInstanceCheckDefault(IsReleased(Button)); + } +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/Bindings/DVLBinding.h b/source-code/source/plugins/TLAC/Input/Bindings/DVLBinding.h new file mode 100644 index 00000000..f3503fa5 --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/Bindings/DVLBinding.h @@ -0,0 +1,19 @@ +#pragma once +#include "IInputBinding.h" +#include "../Divaller/Divaller.h" + +namespace TLAC::Input +{ + class DivallerBinding : public IInputBinding + { + public: + DivallerButton Button; + + DivallerBinding(DivallerButton button); + ~DivallerBinding(); + + bool IsDown() override; + bool IsTapped() override; + bool IsReleased() override; + }; +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/Divaller/Divaller.cpp b/source-code/source/plugins/TLAC/Input/Divaller/Divaller.cpp new file mode 100644 index 00000000..e1472fc2 --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/Divaller/Divaller.cpp @@ -0,0 +1,272 @@ +#include "Divaller.h" +#include "../../framework.h" +#include "DivallerButton.h" +#include "DivallerState.h" +#include +#include +#include + +namespace TLAC::Input +{ + Divaller *Divaller::instance; + + Divaller::Divaller() + { + memset(outputBuffer, 0, sizeof(outputBuffer)); + outputBuffer[0] = 0x44; + outputBuffer[1] = 0x4c; + outputBuffer[2] = 0x61; + } + + Divaller::~Divaller() + { + CloseHandle(hDeviceHandle); + } + + bool Divaller::TryInitializeInstance() + { + if (InstanceInitialized()) + return true; + + Divaller *divaller = new Divaller(); + + BOOL success = divaller->Initialize(); + instance = success ? divaller : nullptr; + + if (!success) + delete divaller; + + return success; + } + + bool Divaller::Initialize() + { + HDEVINFO hDevInfo = SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); + if (hDevInfo == INVALID_HANDLE_VALUE) + { + printf("[TLAC] Divaller::Initialize(): SetupDiGetClassDevs returned INVALID_HANDLE_VALUE\n"); + return false; + } + LPCWSTR devPath = NULL; + for (size_t i = 0;; i++) + { + SP_DEVICE_INTERFACE_DATA device_interface_data = {0}; + device_interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); + BOOL success = SetupDiEnumDeviceInterfaces( + hDevInfo, + NULL, + &GUID_DEVINTERFACE_USB_DEVICE, + (DWORD)i, + &device_interface_data); + if (!success) + { + break; + } + ULONG required_length = 0; + success = SetupDiGetDeviceInterfaceDetail( + hDevInfo, + &device_interface_data, + NULL, + 0, + &required_length, + NULL); + + UINT8 *interface_data = (UINT8 *)calloc(required_length, sizeof(UINT8)); + + PSP_DEVICE_INTERFACE_DETAIL_DATA device_interface_detail_data = (PSP_DEVICE_INTERFACE_DETAIL_DATA)interface_data; + device_interface_detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); + + ULONG actual_length = required_length; + success = SetupDiGetDeviceInterfaceDetail( + hDevInfo, + &device_interface_data, + device_interface_detail_data, + actual_length, + &required_length, + NULL); + + if (!success) + { + continue; + } + if ( + wcsstr(device_interface_detail_data->DevicePath, L"vid_0e8f") == 0 || + wcsstr(device_interface_detail_data->DevicePath, L"pid_2213") == 0) + { + continue; + } + devPath = device_interface_detail_data->DevicePath; + break; + } + if (devPath == NULL) + { + SetupDiDestroyDeviceInfoList(hDevInfo); + return false; + } + hDeviceHandle = CreateFile( + devPath, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL); + if (hDeviceHandle == INVALID_HANDLE_VALUE) + { + printf("[TLAC] Divaller::Initialize(): Open device failed.\n"); + SetupDiDestroyDeviceInfoList(hDevInfo); + return false; + } + + if (!WinUsb_Initialize(hDeviceHandle, &hInterfaceHandle)) + { + printf("[TLAC] Divaller::Initialize(): WinUsb_Initialize failed.\n"); + std::cout << GetLastError() << std::endl; + SetupDiDestroyDeviceInfoList(hDevInfo); + CloseHandle(hDeviceHandle); + return false; + } + + USB_INTERFACE_DESCRIPTOR USBInterfaceDescriptor; + if (!WinUsb_QueryInterfaceSettings(hInterfaceHandle, 0, &USBInterfaceDescriptor)) + { + std::cout << GetLastError() << std::endl; + SetupDiDestroyDeviceInfoList(hDevInfo); + CloseHandle(hDeviceHandle); + return false; + } + SetupDiDestroyDeviceInfoList(hDevInfo); + return true; + } + + bool Divaller::PollInput() + { + lastState = currentState; + ULONG len = 0; + memset(currentState.state, 0, sizeof(currentState.state)); + BOOL bResult = WinUsb_ReadPipe(hInterfaceHandle, (UCHAR)132, currentState.state, _countof(currentState.state), &len, nullptr); + if (!bResult || currentState.state[0] != 0x42 || currentState.state[1] != 0x56 || currentState.state[2] != 0x5a) + { + printf("[TLAC] Divaller::PollInput(): WinUsb_ReadPipe failed.\n"); + std::cout << GetLastError() << std::endl; + } + SetLED(); + return bResult; + } + + bool Divaller::SetLED() + { + outputBuffer[3] &= 0x0F; // Reset Button LED + outputBuffer[3] |= (!(*buttonLed >> 1 & 0x0001)) << 4; // SQUARE + outputBuffer[3] |= (!(*buttonLed >> 3 & 0x0001)) << 5; // CIRCLE + outputBuffer[3] |= (!(*buttonLed & 0x0001)) << 6; // TRIANGLE + outputBuffer[3] |= (!(*buttonLed >> 2 & 0x0001)) << 7; // CROSS + if (*sliderLedInit && !sliderLedData) + { + sliderLedData = reinterpret_cast(*(uint64_t *)(0x14cc5de40 + 0x68) + 0x189c); + } + if (sliderLedData) + { + for (int n = 0; n < 32; n++) + { + // LED number + 3 bytes header + color offset + outputBuffer[(31 - n) * 3 + 3 + 3] = sliderLedData[n * 3 + 1]; // BLUE + outputBuffer[(31 - n) * 3 + 3 + 2] = sliderLedData[n * 3 + 2]; // RED + outputBuffer[(31 - n) * 3 + 3 + 1] = sliderLedData[n * 3 + 3]; // GREEN + } + } + + ULONG len = 0; + BOOL bResult = WinUsb_WritePipe(hInterfaceHandle, (UCHAR)0x03, outputBuffer, 100, &len, NULL); + if (!bResult) + { + printf("[TLAC] Divaller::SetLED(): WinUsb_WritePipe failed.\n"); + std::cout << GetLastError() << std::endl; + } + return bResult; + } + + bool Divaller::IsDown(DivallerButton button) + { + switch (button) + { + case DivallerButton::DVL_L1: + return (currentState.state[5] >> 0) & 1; + case DivallerButton::DVL_L2: + return (currentState.state[4] >> 7) & 1; + case DivallerButton::DVL_L3: + return (currentState.state[4] >> 6) & 1; + case DivallerButton::DVL_FN: + return (currentState.state[3] >> 1) & 1; + case DivallerButton::DVL_TRIANGLE: + return (currentState.state[3] >> 4) & 1; + case DivallerButton::DVL_SQUARE: + return (currentState.state[3] >> 2) & 1; + case DivallerButton::DVL_CROSS: + return (currentState.state[3] >> 5) & 1; + case DivallerButton::DVL_CIRCLE: + return (currentState.state[3] >> 3) & 1; + } + return false; + } + + bool Divaller::IsUp(DivallerButton button) + { + return !IsDown(button); + } + + bool Divaller::IsTapped(DivallerButton button) + { + return IsDown(button) && WasUp(button); + } + + bool Divaller::IsReleased(DivallerButton button) + { + return IsUp(button) && WasDown(button); + } + + bool Divaller::WasDown(DivallerButton button) + { + switch (button) + { + case DivallerButton::DVL_L1: + return (lastState.state[5] >> 0) & 1; + case DivallerButton::DVL_L2: + return (lastState.state[4] >> 7) & 1; + case DivallerButton::DVL_L3: + return (lastState.state[4] >> 6) & 1; + case DivallerButton::DVL_FN: + return (lastState.state[3] >> 1) & 1; + case DivallerButton::DVL_TRIANGLE: + return (lastState.state[3] >> 4) & 1; + case DivallerButton::DVL_SQUARE: + return (lastState.state[3] >> 2) & 1; + case DivallerButton::DVL_CROSS: + return (lastState.state[3] >> 5) & 1; + case DivallerButton::DVL_CIRCLE: + return (lastState.state[3] >> 3) & 1; + } + return false; + } + + bool Divaller::WasUp(DivallerButton button) + { + return !WasDown(button); + } + + uint32_t Divaller::GetSlider() + { + uint32_t i = 0; + i |= currentState.state[5] >> 4; + i |= currentState.state[6] << 4; + i |= currentState.state[7] << 12; + i |= currentState.state[8] << 20; + i |= currentState.state[9] << 28; + // Reverse the bit order of uint32 + i = (i & 0xaaaaaaaa) >> 1 | (i & 0x55555555) << 1; + i = (i & 0xcccccccc) >> 2 | (i & 0x33333333) << 2; + i = (i & 0xf0f0f0f0) >> 4 | (i & 0x0f0f0f0f) << 4; + i = (i & 0xff00ff00) >> 8 | (i & 0x00ff00ff) << 8; + return i >> 16 | i << 16; + }; +} diff --git a/source-code/source/plugins/TLAC/Input/Divaller/Divaller.h b/source-code/source/plugins/TLAC/Input/Divaller/Divaller.h new file mode 100644 index 00000000..399736c0 --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/Divaller/Divaller.h @@ -0,0 +1,52 @@ +#pragma once +#include "../IInputDevice.h" +#include "DivallerState.h" +#include "DivallerButton.h" +#include +#include +#include +#include + +namespace TLAC::Input +{ + + class Divaller : public IInputDevice + { + public: + Divaller(); + ~Divaller(); + + static bool TryInitializeInstance(); + + bool Initialize(); + bool PollInput() override; + bool SetLED(); + bool IsDown(DivallerButton button); + bool IsUp(DivallerButton button); + bool IsTapped(DivallerButton button); + bool IsReleased(DivallerButton button); + + bool WasDown(DivallerButton button); + bool WasUp(DivallerButton button); + uint32_t GetSlider(); + static inline bool InstanceInitialized() { return instance != nullptr; }; + static inline Divaller *GetInstance() { return instance; }; + static inline void DeleteInstance() + { + delete instance; + instance = nullptr; + }; + + private: + static Divaller *instance; + DivallerState lastState; + DivallerState currentState; + WINUSB_INTERFACE_HANDLE hInterfaceHandle; + HANDLE hDeviceHandle; + UCHAR outputBuffer[100]; + int *buttonLed = reinterpret_cast(0x14119b950); + uint64_t *partionLed = reinterpret_cast(*(uint64_t*)0x140eda330 + 0xc9); + uint64_t *sliderLedInit = reinterpret_cast((uint64_t*)0x14cc5dea8); + UCHAR *sliderLedData = nullptr; + }; +} diff --git a/source-code/source/plugins/TLAC/Input/Divaller/DivallerButton.h b/source-code/source/plugins/TLAC/Input/Divaller/DivallerButton.h new file mode 100644 index 00000000..fccce618 --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/Divaller/DivallerButton.h @@ -0,0 +1,32 @@ +#pragma once + +namespace TLAC::Input +{ + enum DivallerButton : int + { + DVL_SQUARE = 0, + DVL_CROSS = 1, + DVL_CIRCLE = 2, + DVL_TRIANGLE = 3, + + DVL_FN = 4, + + DVL_L1 = 5, + DVL_L2 = 6, + DVL_L3 = 7, + + DVL_R1 = 8, + DVL_R2 = 9, + DVL_R3 = 10, + + DVL_UP = 11, + DVL_LEFT = 12, + DVL_DOWN = 13, + DVL_RIGHT = 14, + + DVL_PAD = 11, + DVL_SHARE = 12, + DVL_HOME = 13, + DVL_OPTION = 14 + }; +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/Divaller/DivallerState.h b/source-code/source/plugins/TLAC/Input/Divaller/DivallerState.h new file mode 100644 index 00000000..6844d00a --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/Divaller/DivallerState.h @@ -0,0 +1,10 @@ +#pragma once +#include "../../framework.h" +namespace TLAC::Input +{ + + struct DivallerState + { + uint8_t state[24]; + }; +} \ No newline at end of file From 5a722100236ad09d855d2a6de4ca562351f1afae Mon Sep 17 00:00:00 2001 From: Tinko Liu <24890691+TinkoLiu@users.noreply.github.com> Date: Sat, 25 Jun 2022 17:19:54 +0800 Subject: [PATCH 3/4] [TLAC]: add DIVALLER binding --- .../TLAC/Components/Input/InputEmulator.cpp | 10 ++++++++ .../Components/Input/TouchSliderEmulator.cpp | 9 +++++-- source-code/source/plugins/TLAC/dllmain.cpp | 25 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp index eb1cf8a8..d92590f1 100644 --- a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp +++ b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp @@ -8,6 +8,7 @@ #include "../../Input/Bindings/XinputBinding.h" #include "../../Input/Bindings/MouseBinding.h" #include "../../Input/Bindings/Ds4Binding.h" +#include "../../Input/Bindings/DVLBinding.h" #include "../../Input/KeyConfig/Config.h" #include "../../Utilities/Operations.h" #include "../../Utilities/EnumBitwiseOperations.h" @@ -107,6 +108,15 @@ namespace TLAC::Components Config::BindConfigKeys(configFile.ConfigMap, "WIREFRAME", *WireframeBinding, { "Backspace" }); mouseScrollPvSelection = configFile.GetBooleanValue("mouse_scroll_pv_selection"); + + TestBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_L3)); + ServiceBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_L2)); + CoinBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_L1)); + StartBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_FN)); + SankakuBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_TRIANGLE)); + ShikakuBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_SQUARE)); + BatsuBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_CROSS)); + MaruBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_CIRCLE)); } void InputEmulator::Update() diff --git a/source-code/source/plugins/TLAC/Components/Input/TouchSliderEmulator.cpp b/source-code/source/plugins/TLAC/Components/Input/TouchSliderEmulator.cpp index 1e9a3400..065296f2 100644 --- a/source-code/source/plugins/TLAC/Components/Input/TouchSliderEmulator.cpp +++ b/source-code/source/plugins/TLAC/Components/Input/TouchSliderEmulator.cpp @@ -7,6 +7,7 @@ #include "../../Input/Bindings/KeyboardBinding.h" #include "../../Input/KeyConfig/Config.h" #include "../../Input/DirectInput/Ds4/DualShock4.h" +#include "../../Input/Divaller/Divaller.h" #include "../../FileSystem/ConfigFile.h" #include "../../Utilities/Math.h" #include @@ -100,7 +101,11 @@ namespace TLAC::Components if (!componentsManager->GetUpdateGameInput() || componentsManager->IsDwGuiActive() || (!enableInMenus && !(*(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN))) return; - if (usePs4OfficialSlider) + if (Input::Divaller::GetInstance() != nullptr) + { + ApplyBitfieldState(Input::Divaller::GetInstance()->GetSlider()); + } + else if (usePs4OfficialSlider) { DualShock4* ds4 = DualShock4::GetInstance(); if (ds4 == nullptr) @@ -140,7 +145,7 @@ namespace TLAC::Components void TouchSliderEmulator::OnFocusLost() { - if (usePs4OfficialSlider) + if (usePs4OfficialSlider || Input::Divaller::GetInstance() != nullptr) sliderState->ResetSensors(TouchSliderState::SENSOR_SET_MODE_RAW); else sliderState->ResetSensors(TouchSliderState::SENSOR_SET_MODE_SECTIONS); diff --git a/source-code/source/plugins/TLAC/dllmain.cpp b/source-code/source/plugins/TLAC/dllmain.cpp index 8b60ed50..c9aece55 100644 --- a/source-code/source/plugins/TLAC/dllmain.cpp +++ b/source-code/source/plugins/TLAC/dllmain.cpp @@ -12,6 +12,7 @@ #include "Input/DirectInput/DirectInput.h" #include "Input/DirectInput/Ds4/DualShock4.h" #include "Input/DirectInput/GenericUsb/GenericUsbInput.h" +#include "Input/Divaller/Divaller.h" #include "Components/ComponentsManager.h" #include #include @@ -81,6 +82,12 @@ namespace TLAC if (Input::GenericUsbInput::TryInitializeInstance()) printf("[TLAC] UpdateTick(): GenericUsbInput connected and initialized\n"); } + + if (!Input::Divaller::InstanceInitialized()) + { + if (Input::Divaller::TryInitializeInstance()) + printf("[TLAC] UpdateTick(): Divaller connected and initialized\n"); + } } ComponentsManager.Update(); @@ -112,6 +119,15 @@ namespace TLAC } } + if (Input::Divaller::GetInstance() != nullptr) + { + if (!Input::Divaller::GetInstance()->PollInput()) + { + Input::Divaller::DeleteInstance(); + printf("[TLAC] UpdateTick(): Divaller connection lost\n"); + } + } + ComponentsManager.UpdateInput(); } @@ -140,6 +156,15 @@ namespace TLAC printf("[TLAC] UpdateTick(): GenericUsbInput connection lost\n"); } } + + if (Input::Divaller::GetInstance() != nullptr) + { + if (!Input::Divaller::GetInstance()->PollInput()) + { + Input::Divaller::DeleteInstance(); + printf("[TLAC] UpdateTick(): Divaller connection lost\n"); + } + } } if (HasWindowFocus && !HadWindowFocus) From f498fee877278d3f2e59c7014dd8f64d5c99b268 Mon Sep 17 00:00:00 2001 From: Tinko Liu <24890691+TinkoLiu@users.noreply.github.com> Date: Sat, 25 Jun 2022 17:25:45 +0800 Subject: [PATCH 4/4] chore: format code --- .../TLAC/Components/Input/InputEmulator.cpp | 16 +- .../plugins/TLAC/Input/Divaller/Divaller.cpp | 474 +++++++++--------- .../plugins/TLAC/Input/Divaller/Divaller.h | 70 +-- 3 files changed, 280 insertions(+), 280 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp index d92590f1..d3e35091 100644 --- a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp +++ b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp @@ -109,14 +109,14 @@ namespace TLAC::Components mouseScrollPvSelection = configFile.GetBooleanValue("mouse_scroll_pv_selection"); - TestBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_L3)); - ServiceBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_L2)); - CoinBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_L1)); - StartBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_FN)); - SankakuBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_TRIANGLE)); - ShikakuBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_SQUARE)); - BatsuBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_CROSS)); - MaruBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_CIRCLE)); + TestBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_L3)); + ServiceBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_L2)); + CoinBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_L1)); + StartBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_FN)); + SankakuBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_TRIANGLE)); + ShikakuBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_SQUARE)); + BatsuBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_CROSS)); + MaruBinding->AddBinding(new DivallerBinding(DivallerButton::DVL_CIRCLE)); } void InputEmulator::Update() diff --git a/source-code/source/plugins/TLAC/Input/Divaller/Divaller.cpp b/source-code/source/plugins/TLAC/Input/Divaller/Divaller.cpp index e1472fc2..2c57adc4 100644 --- a/source-code/source/plugins/TLAC/Input/Divaller/Divaller.cpp +++ b/source-code/source/plugins/TLAC/Input/Divaller/Divaller.cpp @@ -8,265 +8,265 @@ namespace TLAC::Input { - Divaller *Divaller::instance; + Divaller *Divaller::instance; - Divaller::Divaller() - { - memset(outputBuffer, 0, sizeof(outputBuffer)); - outputBuffer[0] = 0x44; - outputBuffer[1] = 0x4c; - outputBuffer[2] = 0x61; - } + Divaller::Divaller() + { + memset(outputBuffer, 0, sizeof(outputBuffer)); + outputBuffer[0] = 0x44; + outputBuffer[1] = 0x4c; + outputBuffer[2] = 0x61; + } - Divaller::~Divaller() - { - CloseHandle(hDeviceHandle); - } + Divaller::~Divaller() + { + CloseHandle(hDeviceHandle); + } - bool Divaller::TryInitializeInstance() - { - if (InstanceInitialized()) - return true; + bool Divaller::TryInitializeInstance() + { + if (InstanceInitialized()) + return true; - Divaller *divaller = new Divaller(); + Divaller *divaller = new Divaller(); - BOOL success = divaller->Initialize(); - instance = success ? divaller : nullptr; + BOOL success = divaller->Initialize(); + instance = success ? divaller : nullptr; - if (!success) - delete divaller; + if (!success) + delete divaller; - return success; - } + return success; + } - bool Divaller::Initialize() - { - HDEVINFO hDevInfo = SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); - if (hDevInfo == INVALID_HANDLE_VALUE) - { - printf("[TLAC] Divaller::Initialize(): SetupDiGetClassDevs returned INVALID_HANDLE_VALUE\n"); - return false; - } - LPCWSTR devPath = NULL; - for (size_t i = 0;; i++) - { - SP_DEVICE_INTERFACE_DATA device_interface_data = {0}; - device_interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); - BOOL success = SetupDiEnumDeviceInterfaces( - hDevInfo, - NULL, - &GUID_DEVINTERFACE_USB_DEVICE, - (DWORD)i, - &device_interface_data); - if (!success) - { - break; - } - ULONG required_length = 0; - success = SetupDiGetDeviceInterfaceDetail( - hDevInfo, - &device_interface_data, - NULL, - 0, - &required_length, - NULL); + bool Divaller::Initialize() + { + HDEVINFO hDevInfo = SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); + if (hDevInfo == INVALID_HANDLE_VALUE) + { + printf("[TLAC] Divaller::Initialize(): SetupDiGetClassDevs returned INVALID_HANDLE_VALUE\n"); + return false; + } + LPCWSTR devPath = NULL; + for (size_t i = 0;; i++) + { + SP_DEVICE_INTERFACE_DATA device_interface_data = {0}; + device_interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); + BOOL success = SetupDiEnumDeviceInterfaces( + hDevInfo, + NULL, + &GUID_DEVINTERFACE_USB_DEVICE, + (DWORD)i, + &device_interface_data); + if (!success) + { + break; + } + ULONG required_length = 0; + success = SetupDiGetDeviceInterfaceDetail( + hDevInfo, + &device_interface_data, + NULL, + 0, + &required_length, + NULL); - UINT8 *interface_data = (UINT8 *)calloc(required_length, sizeof(UINT8)); + UINT8 *interface_data = (UINT8 *)calloc(required_length, sizeof(UINT8)); - PSP_DEVICE_INTERFACE_DETAIL_DATA device_interface_detail_data = (PSP_DEVICE_INTERFACE_DETAIL_DATA)interface_data; - device_interface_detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); + PSP_DEVICE_INTERFACE_DETAIL_DATA device_interface_detail_data = (PSP_DEVICE_INTERFACE_DETAIL_DATA)interface_data; + device_interface_detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); - ULONG actual_length = required_length; - success = SetupDiGetDeviceInterfaceDetail( - hDevInfo, - &device_interface_data, - device_interface_detail_data, - actual_length, - &required_length, - NULL); + ULONG actual_length = required_length; + success = SetupDiGetDeviceInterfaceDetail( + hDevInfo, + &device_interface_data, + device_interface_detail_data, + actual_length, + &required_length, + NULL); - if (!success) - { - continue; - } - if ( - wcsstr(device_interface_detail_data->DevicePath, L"vid_0e8f") == 0 || - wcsstr(device_interface_detail_data->DevicePath, L"pid_2213") == 0) - { - continue; - } - devPath = device_interface_detail_data->DevicePath; - break; - } - if (devPath == NULL) - { - SetupDiDestroyDeviceInfoList(hDevInfo); - return false; - } - hDeviceHandle = CreateFile( - devPath, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_FLAG_OVERLAPPED, - NULL); - if (hDeviceHandle == INVALID_HANDLE_VALUE) - { - printf("[TLAC] Divaller::Initialize(): Open device failed.\n"); - SetupDiDestroyDeviceInfoList(hDevInfo); - return false; - } + if (!success) + { + continue; + } + if ( + wcsstr(device_interface_detail_data->DevicePath, L"vid_0e8f") == 0 || + wcsstr(device_interface_detail_data->DevicePath, L"pid_2213") == 0) + { + continue; + } + devPath = device_interface_detail_data->DevicePath; + break; + } + if (devPath == NULL) + { + SetupDiDestroyDeviceInfoList(hDevInfo); + return false; + } + hDeviceHandle = CreateFile( + devPath, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL); + if (hDeviceHandle == INVALID_HANDLE_VALUE) + { + printf("[TLAC] Divaller::Initialize(): Open device failed.\n"); + SetupDiDestroyDeviceInfoList(hDevInfo); + return false; + } - if (!WinUsb_Initialize(hDeviceHandle, &hInterfaceHandle)) - { - printf("[TLAC] Divaller::Initialize(): WinUsb_Initialize failed.\n"); - std::cout << GetLastError() << std::endl; - SetupDiDestroyDeviceInfoList(hDevInfo); - CloseHandle(hDeviceHandle); - return false; - } + if (!WinUsb_Initialize(hDeviceHandle, &hInterfaceHandle)) + { + printf("[TLAC] Divaller::Initialize(): WinUsb_Initialize failed.\n"); + std::cout << GetLastError() << std::endl; + SetupDiDestroyDeviceInfoList(hDevInfo); + CloseHandle(hDeviceHandle); + return false; + } - USB_INTERFACE_DESCRIPTOR USBInterfaceDescriptor; - if (!WinUsb_QueryInterfaceSettings(hInterfaceHandle, 0, &USBInterfaceDescriptor)) - { - std::cout << GetLastError() << std::endl; - SetupDiDestroyDeviceInfoList(hDevInfo); - CloseHandle(hDeviceHandle); - return false; - } - SetupDiDestroyDeviceInfoList(hDevInfo); - return true; - } + USB_INTERFACE_DESCRIPTOR USBInterfaceDescriptor; + if (!WinUsb_QueryInterfaceSettings(hInterfaceHandle, 0, &USBInterfaceDescriptor)) + { + std::cout << GetLastError() << std::endl; + SetupDiDestroyDeviceInfoList(hDevInfo); + CloseHandle(hDeviceHandle); + return false; + } + SetupDiDestroyDeviceInfoList(hDevInfo); + return true; + } - bool Divaller::PollInput() - { - lastState = currentState; - ULONG len = 0; - memset(currentState.state, 0, sizeof(currentState.state)); - BOOL bResult = WinUsb_ReadPipe(hInterfaceHandle, (UCHAR)132, currentState.state, _countof(currentState.state), &len, nullptr); - if (!bResult || currentState.state[0] != 0x42 || currentState.state[1] != 0x56 || currentState.state[2] != 0x5a) - { - printf("[TLAC] Divaller::PollInput(): WinUsb_ReadPipe failed.\n"); - std::cout << GetLastError() << std::endl; - } - SetLED(); - return bResult; - } + bool Divaller::PollInput() + { + lastState = currentState; + ULONG len = 0; + memset(currentState.state, 0, sizeof(currentState.state)); + BOOL bResult = WinUsb_ReadPipe(hInterfaceHandle, (UCHAR)132, currentState.state, _countof(currentState.state), &len, nullptr); + if (!bResult || currentState.state[0] != 0x42 || currentState.state[1] != 0x56 || currentState.state[2] != 0x5a) + { + printf("[TLAC] Divaller::PollInput(): WinUsb_ReadPipe failed.\n"); + std::cout << GetLastError() << std::endl; + } + SetLED(); + return bResult; + } - bool Divaller::SetLED() - { - outputBuffer[3] &= 0x0F; // Reset Button LED - outputBuffer[3] |= (!(*buttonLed >> 1 & 0x0001)) << 4; // SQUARE - outputBuffer[3] |= (!(*buttonLed >> 3 & 0x0001)) << 5; // CIRCLE - outputBuffer[3] |= (!(*buttonLed & 0x0001)) << 6; // TRIANGLE - outputBuffer[3] |= (!(*buttonLed >> 2 & 0x0001)) << 7; // CROSS - if (*sliderLedInit && !sliderLedData) - { - sliderLedData = reinterpret_cast(*(uint64_t *)(0x14cc5de40 + 0x68) + 0x189c); - } - if (sliderLedData) - { - for (int n = 0; n < 32; n++) - { - // LED number + 3 bytes header + color offset - outputBuffer[(31 - n) * 3 + 3 + 3] = sliderLedData[n * 3 + 1]; // BLUE - outputBuffer[(31 - n) * 3 + 3 + 2] = sliderLedData[n * 3 + 2]; // RED - outputBuffer[(31 - n) * 3 + 3 + 1] = sliderLedData[n * 3 + 3]; // GREEN - } - } + bool Divaller::SetLED() + { + outputBuffer[3] &= 0x0F; // Reset Button LED + outputBuffer[3] |= (!(*buttonLed >> 1 & 0x0001)) << 4; // SQUARE + outputBuffer[3] |= (!(*buttonLed >> 3 & 0x0001)) << 5; // CIRCLE + outputBuffer[3] |= (!(*buttonLed & 0x0001)) << 6; // TRIANGLE + outputBuffer[3] |= (!(*buttonLed >> 2 & 0x0001)) << 7; // CROSS + if (*sliderLedInit && !sliderLedData) + { + sliderLedData = reinterpret_cast(*(uint64_t *)(0x14cc5de40 + 0x68) + 0x189c); + } + if (sliderLedData) + { + for (int n = 0; n < 32; n++) + { + // LED number + 3 bytes header + color offset + outputBuffer[(31 - n) * 3 + 3 + 3] = sliderLedData[n * 3 + 1]; // BLUE + outputBuffer[(31 - n) * 3 + 3 + 2] = sliderLedData[n * 3 + 2]; // RED + outputBuffer[(31 - n) * 3 + 3 + 1] = sliderLedData[n * 3 + 3]; // GREEN + } + } - ULONG len = 0; - BOOL bResult = WinUsb_WritePipe(hInterfaceHandle, (UCHAR)0x03, outputBuffer, 100, &len, NULL); - if (!bResult) - { - printf("[TLAC] Divaller::SetLED(): WinUsb_WritePipe failed.\n"); - std::cout << GetLastError() << std::endl; - } - return bResult; - } + ULONG len = 0; + BOOL bResult = WinUsb_WritePipe(hInterfaceHandle, (UCHAR)0x03, outputBuffer, 100, &len, NULL); + if (!bResult) + { + printf("[TLAC] Divaller::SetLED(): WinUsb_WritePipe failed.\n"); + std::cout << GetLastError() << std::endl; + } + return bResult; + } - bool Divaller::IsDown(DivallerButton button) - { - switch (button) - { - case DivallerButton::DVL_L1: - return (currentState.state[5] >> 0) & 1; - case DivallerButton::DVL_L2: - return (currentState.state[4] >> 7) & 1; - case DivallerButton::DVL_L3: - return (currentState.state[4] >> 6) & 1; - case DivallerButton::DVL_FN: - return (currentState.state[3] >> 1) & 1; - case DivallerButton::DVL_TRIANGLE: - return (currentState.state[3] >> 4) & 1; - case DivallerButton::DVL_SQUARE: - return (currentState.state[3] >> 2) & 1; - case DivallerButton::DVL_CROSS: - return (currentState.state[3] >> 5) & 1; - case DivallerButton::DVL_CIRCLE: - return (currentState.state[3] >> 3) & 1; - } - return false; - } + bool Divaller::IsDown(DivallerButton button) + { + switch (button) + { + case DivallerButton::DVL_L1: + return (currentState.state[5] >> 0) & 1; + case DivallerButton::DVL_L2: + return (currentState.state[4] >> 7) & 1; + case DivallerButton::DVL_L3: + return (currentState.state[4] >> 6) & 1; + case DivallerButton::DVL_FN: + return (currentState.state[3] >> 1) & 1; + case DivallerButton::DVL_TRIANGLE: + return (currentState.state[3] >> 4) & 1; + case DivallerButton::DVL_SQUARE: + return (currentState.state[3] >> 2) & 1; + case DivallerButton::DVL_CROSS: + return (currentState.state[3] >> 5) & 1; + case DivallerButton::DVL_CIRCLE: + return (currentState.state[3] >> 3) & 1; + } + return false; + } - bool Divaller::IsUp(DivallerButton button) - { - return !IsDown(button); - } + bool Divaller::IsUp(DivallerButton button) + { + return !IsDown(button); + } - bool Divaller::IsTapped(DivallerButton button) - { - return IsDown(button) && WasUp(button); - } + bool Divaller::IsTapped(DivallerButton button) + { + return IsDown(button) && WasUp(button); + } - bool Divaller::IsReleased(DivallerButton button) - { - return IsUp(button) && WasDown(button); - } + bool Divaller::IsReleased(DivallerButton button) + { + return IsUp(button) && WasDown(button); + } - bool Divaller::WasDown(DivallerButton button) - { - switch (button) - { - case DivallerButton::DVL_L1: - return (lastState.state[5] >> 0) & 1; - case DivallerButton::DVL_L2: - return (lastState.state[4] >> 7) & 1; - case DivallerButton::DVL_L3: - return (lastState.state[4] >> 6) & 1; - case DivallerButton::DVL_FN: - return (lastState.state[3] >> 1) & 1; - case DivallerButton::DVL_TRIANGLE: - return (lastState.state[3] >> 4) & 1; - case DivallerButton::DVL_SQUARE: - return (lastState.state[3] >> 2) & 1; - case DivallerButton::DVL_CROSS: - return (lastState.state[3] >> 5) & 1; - case DivallerButton::DVL_CIRCLE: - return (lastState.state[3] >> 3) & 1; - } - return false; - } + bool Divaller::WasDown(DivallerButton button) + { + switch (button) + { + case DivallerButton::DVL_L1: + return (lastState.state[5] >> 0) & 1; + case DivallerButton::DVL_L2: + return (lastState.state[4] >> 7) & 1; + case DivallerButton::DVL_L3: + return (lastState.state[4] >> 6) & 1; + case DivallerButton::DVL_FN: + return (lastState.state[3] >> 1) & 1; + case DivallerButton::DVL_TRIANGLE: + return (lastState.state[3] >> 4) & 1; + case DivallerButton::DVL_SQUARE: + return (lastState.state[3] >> 2) & 1; + case DivallerButton::DVL_CROSS: + return (lastState.state[3] >> 5) & 1; + case DivallerButton::DVL_CIRCLE: + return (lastState.state[3] >> 3) & 1; + } + return false; + } - bool Divaller::WasUp(DivallerButton button) - { - return !WasDown(button); - } + bool Divaller::WasUp(DivallerButton button) + { + return !WasDown(button); + } - uint32_t Divaller::GetSlider() - { - uint32_t i = 0; - i |= currentState.state[5] >> 4; - i |= currentState.state[6] << 4; - i |= currentState.state[7] << 12; - i |= currentState.state[8] << 20; - i |= currentState.state[9] << 28; - // Reverse the bit order of uint32 - i = (i & 0xaaaaaaaa) >> 1 | (i & 0x55555555) << 1; - i = (i & 0xcccccccc) >> 2 | (i & 0x33333333) << 2; - i = (i & 0xf0f0f0f0) >> 4 | (i & 0x0f0f0f0f) << 4; - i = (i & 0xff00ff00) >> 8 | (i & 0x00ff00ff) << 8; - return i >> 16 | i << 16; - }; + uint32_t Divaller::GetSlider() + { + uint32_t i = 0; + i |= currentState.state[5] >> 4; + i |= currentState.state[6] << 4; + i |= currentState.state[7] << 12; + i |= currentState.state[8] << 20; + i |= currentState.state[9] << 28; + // Reverse the bit order of uint32 + i = (i & 0xaaaaaaaa) >> 1 | (i & 0x55555555) << 1; + i = (i & 0xcccccccc) >> 2 | (i & 0x33333333) << 2; + i = (i & 0xf0f0f0f0) >> 4 | (i & 0x0f0f0f0f) << 4; + i = (i & 0xff00ff00) >> 8 | (i & 0x00ff00ff) << 8; + return i >> 16 | i << 16; + }; } diff --git a/source-code/source/plugins/TLAC/Input/Divaller/Divaller.h b/source-code/source/plugins/TLAC/Input/Divaller/Divaller.h index 399736c0..2dc39041 100644 --- a/source-code/source/plugins/TLAC/Input/Divaller/Divaller.h +++ b/source-code/source/plugins/TLAC/Input/Divaller/Divaller.h @@ -10,43 +10,43 @@ namespace TLAC::Input { - class Divaller : public IInputDevice - { - public: - Divaller(); - ~Divaller(); + class Divaller : public IInputDevice + { + public: + Divaller(); + ~Divaller(); - static bool TryInitializeInstance(); + static bool TryInitializeInstance(); - bool Initialize(); - bool PollInput() override; - bool SetLED(); - bool IsDown(DivallerButton button); - bool IsUp(DivallerButton button); - bool IsTapped(DivallerButton button); - bool IsReleased(DivallerButton button); + bool Initialize(); + bool PollInput() override; + bool SetLED(); + bool IsDown(DivallerButton button); + bool IsUp(DivallerButton button); + bool IsTapped(DivallerButton button); + bool IsReleased(DivallerButton button); - bool WasDown(DivallerButton button); - bool WasUp(DivallerButton button); - uint32_t GetSlider(); - static inline bool InstanceInitialized() { return instance != nullptr; }; - static inline Divaller *GetInstance() { return instance; }; - static inline void DeleteInstance() - { - delete instance; - instance = nullptr; - }; + bool WasDown(DivallerButton button); + bool WasUp(DivallerButton button); + uint32_t GetSlider(); + static inline bool InstanceInitialized() { return instance != nullptr; }; + static inline Divaller *GetInstance() { return instance; }; + static inline void DeleteInstance() + { + delete instance; + instance = nullptr; + }; - private: - static Divaller *instance; - DivallerState lastState; - DivallerState currentState; - WINUSB_INTERFACE_HANDLE hInterfaceHandle; - HANDLE hDeviceHandle; - UCHAR outputBuffer[100]; - int *buttonLed = reinterpret_cast(0x14119b950); - uint64_t *partionLed = reinterpret_cast(*(uint64_t*)0x140eda330 + 0xc9); - uint64_t *sliderLedInit = reinterpret_cast((uint64_t*)0x14cc5dea8); - UCHAR *sliderLedData = nullptr; - }; + private: + static Divaller *instance; + DivallerState lastState; + DivallerState currentState; + WINUSB_INTERFACE_HANDLE hInterfaceHandle; + HANDLE hDeviceHandle; + UCHAR outputBuffer[100]; + int *buttonLed = reinterpret_cast(0x14119b950); + uint64_t *partionLed = reinterpret_cast(*(uint64_t *)0x140eda330 + 0xc9); + uint64_t *sliderLedInit = reinterpret_cast((uint64_t *)0x14cc5dea8); + UCHAR *sliderLedData = nullptr; + }; }