From a0946e9187052625d5b50352d3855441504d7f62 Mon Sep 17 00:00:00 2001 From: apple1417 Date: Wed, 8 Nov 2023 18:37:54 +1300 Subject: [PATCH 1/3] remove error prefix --- src/proxy/d3d11.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proxy/d3d11.cpp b/src/proxy/d3d11.cpp index 3b6d313..4494de6 100644 --- a/src/proxy/d3d11.cpp +++ b/src/proxy/d3d11.cpp @@ -66,7 +66,7 @@ void init(HMODULE /*this_dll*/) { wchar_t buf[MAX_PATH]; if (GetSystemDirectoryW(&buf[0], ARRAYSIZE(buf)) == 0) { - std::cerr << "[dhf] Unable to find system dll directory! We're probably about to crash.\n"; + std::cerr << "Unable to find system dll directory! We're probably about to crash.\n"; return; } From 400288b868b3446e3a1f6ee569d0e16b735a2fb5 Mon Sep 17 00:00:00 2001 From: apple1417 Date: Wed, 8 Nov 2023 18:38:09 +1300 Subject: [PATCH 2/3] add xinput proxy --- CMakeLists.txt | 2 + common_cmake | 2 +- src/proxy/xinput1_3.cpp | 106 ++++++++++++++++++++++++++++++++++++++++ src/proxy/xinput1_3.def | 11 +++++ 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/proxy/xinput1_3.cpp create mode 100644 src/proxy/xinput1_3.def diff --git a/CMakeLists.txt b/CMakeLists.txt index 8201a57..ad14d46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,10 +50,12 @@ endfunction() pluginloader_add_impl(no_proxy "src/proxy/none.cpp") pluginloader_add_impl(d3d11 "src/proxy/d3d11.cpp") +pluginloader_add_impl(xinput1_3 "src/proxy/xinput1_3.cpp" "src/proxy/xinput1_3.def") install( TARGETS pluginloader_no_proxy pluginloader_d3d11 + pluginloader_xinput1_3 RUNTIME DESTINATION . ) diff --git a/common_cmake b/common_cmake index c204216..43d270c 160000 --- a/common_cmake +++ b/common_cmake @@ -1 +1 @@ -Subproject commit c204216600071bf43fc1aadc2dea37b89e3b3a44 +Subproject commit 43d270c81896de6674166fa839caadf2da2c468a diff --git a/src/proxy/xinput1_3.cpp b/src/proxy/xinput1_3.cpp new file mode 100644 index 0000000..ba6c99d --- /dev/null +++ b/src/proxy/xinput1_3.cpp @@ -0,0 +1,106 @@ +#include "pch.h" +#include + +#include "util.h" + +namespace pluginloader::proxy { + +namespace { + +HMODULE xinput_dll_handle = nullptr; + +FARPROC xinput_enable_ptr = nullptr; +FARPROC xinput_get_battery_information_ptr = nullptr; +FARPROC xinput_get_capabilities_ptr = nullptr; +FARPROC xinput_get_dsound_audio_device_guids_ptr = nullptr; +FARPROC xinput_get_keystroke_ptr = nullptr; +FARPROC xinput_get_state_ptr = nullptr; +FARPROC xinput_set_state_ptr = nullptr; + +const constexpr auto XINPUT_GET_STATE_EX_ORDINAL = 100; +FARPROC xinput_get_state_ex_ptr = nullptr; + +// NOLINTBEGIN(readability-identifier-naming, readability-identifier-length) + +DLL_EXPORT void XInputEnable(BOOL enable) { + return reinterpret_cast(xinput_enable_ptr)(enable); +} + +DLL_EXPORT DWORD XInputGetBatteryInformation(DWORD dwUserIndex, + BYTE devType, + void* pBatteryInformation) { + return reinterpret_cast( + xinput_get_battery_information_ptr)(dwUserIndex, devType, pBatteryInformation); +} + +DLL_EXPORT DWORD XInputGetCapabilities(DWORD dwUserIndex, DWORD dwFlags, void* pCapabilities) { + return reinterpret_cast(xinput_get_capabilities_ptr)( + dwUserIndex, dwFlags, pCapabilities); +} + +DLL_EXPORT DWORD XInputGetDSoundAudioDeviceGuids(DWORD dwUserIndex, + GUID* pDSoundRenderGuid, + GUID* pDSoundCaptureGuid) { + return reinterpret_cast( + xinput_get_dsound_audio_device_guids_ptr)(dwUserIndex, pDSoundRenderGuid, + pDSoundCaptureGuid); +} + +DLL_EXPORT DWORD XInputGetKeystroke(DWORD dwUserIndex, DWORD dwReserved, void* pKeystroke) { + return reinterpret_cast(xinput_get_keystroke_ptr)( + dwUserIndex, dwReserved, pKeystroke); +} + +DLL_EXPORT DWORD XInputGetState(DWORD dwUserIndex, void* pState) { + return reinterpret_cast(xinput_get_state_ptr)(dwUserIndex, pState); +} + +DLL_EXPORT DWORD XInputSetState(DWORD dwUserIndex, void* pVibration) { + return reinterpret_cast(xinput_set_state_ptr)(dwUserIndex, + pVibration); +} + +DLL_EXPORT DWORD XInputGetStateEx(DWORD dwUserIndex, void* pState) { + return reinterpret_cast(xinput_get_state_ex_ptr)(dwUserIndex, + pState); +} + +// NOLINTEND(readability-identifier-naming, readability-identifier-length) + +} // namespace + +void init(HMODULE /*this_dll*/) { + // Suspend all other threads to prevent a giant race condition + const util::ThreadSuspender suspender{}; + + wchar_t buf[MAX_PATH]; + if (GetSystemDirectoryW(&buf[0], ARRAYSIZE(buf)) == 0) { + std::cerr << "Unable to find system dll directory! We're probably about to crash.\n"; + return; + } + + auto system_xinput = std::filesystem::path{static_cast(buf)} / "xinput1_3.dll"; + xinput_dll_handle = LoadLibraryA(system_xinput.generic_string().c_str()); + + xinput_enable_ptr = GetProcAddress(xinput_dll_handle, "XInputEnable"); + xinput_get_battery_information_ptr = + GetProcAddress(xinput_dll_handle, "XInputGetBatteryInformation"); + xinput_get_capabilities_ptr = GetProcAddress(xinput_dll_handle, "XInputGetCapabilities"); + xinput_get_dsound_audio_device_guids_ptr = + GetProcAddress(xinput_dll_handle, "XInputGetDSoundAudioDeviceGuids"); + xinput_get_keystroke_ptr = GetProcAddress(xinput_dll_handle, "XInputGetKeystroke"); + xinput_get_state_ptr = GetProcAddress(xinput_dll_handle, "XInputGetState"); + xinput_set_state_ptr = GetProcAddress(xinput_dll_handle, "XInputSetState"); + + xinput_get_state_ex_ptr = + GetProcAddress(xinput_dll_handle, reinterpret_cast(XINPUT_GET_STATE_EX_ORDINAL)); +} + +void free(void) { + if (xinput_dll_handle != nullptr) { + FreeLibrary(xinput_dll_handle); + xinput_dll_handle = nullptr; + } +} + +} // namespace pluginloader::proxy diff --git a/src/proxy/xinput1_3.def b/src/proxy/xinput1_3.def new file mode 100644 index 0000000..b710d6b --- /dev/null +++ b/src/proxy/xinput1_3.def @@ -0,0 +1,11 @@ +LIBRARY XINPUT1_3 +EXPORTS + DllMain @1 + XInputGetState @2 + XInputSetState @3 + XInputGetCapabilities @4 + XInputEnable @5 + XInputGetDSoundAudioDeviceGuids @6 + XInputGetBatteryInformation @7 + XInputGetKeystroke @8 + XInputGetStateEx @100 From 85bec3570f55d343122180106e01c1206ed394d8 Mon Sep 17 00:00:00 2001 From: apple1417 Date: Wed, 8 Nov 2023 19:09:16 +1300 Subject: [PATCH 3/3] bump build number and also fix naming --- CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad14d46..8050d68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.24) -project(pluginloader VERSION 1.0.0) +project(pluginloader VERSION 1.0.1) add_library(_pluginloader_base INTERFACE) set(CMAKE_EXPORT_COMPILE_COMMANDS True) @@ -9,7 +9,6 @@ target_compile_features(_pluginloader_base INTERFACE cxx_std_20) set_target_properties(_pluginloader_base PROPERTIES COMPILE_WARNING_AS_ERROR True INTERPROCEDURAL_OPTIMIZATION True - PREFIX "" ) if(MSVC) target_compile_options(_pluginloader_base INTERFACE /W4) @@ -41,7 +40,11 @@ target_precompile_headers(_pluginloader_base INTERFACE "src/pch.h") function(pluginloader_add_impl name) add_library(pluginloader_${name} SHARED ${ARGN}) - set_target_properties(pluginloader_${name} PROPERTIES OUTPUT_NAME ${name}) + set_target_properties(pluginloader_${name} PROPERTIES + PREFIX "" + OUTPUT_NAME ${name} + SUFFIX ".dll" + ) target_link_libraries(pluginloader_${name} PUBLIC _pluginloader_base) endfunction()