mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-14 19:15:05 -05:00
Remove useless proxy forwarders
This commit is contained in:
parent
cdbed58178
commit
d96c9756a1
1 changed files with 32 additions and 36 deletions
|
@ -1,53 +1,49 @@
|
|||
#include <Windows.h>
|
||||
#include <string>
|
||||
|
||||
#define XINPUT_PATH "\\\\.\\GLOBALROOT\\SystemRoot\\System32\\XInput1_4.dll"
|
||||
|
||||
// https://github.com/mrexodia/perfect-dll-proxy
|
||||
#define PROXY_EXPORT(sym) \
|
||||
"/export:" #sym "=" XINPUT_PATH "." #sym
|
||||
|
||||
#pragma comment(linker, PROXY_EXPORT(XInputSetState))
|
||||
#pragma comment(linker, PROXY_EXPORT(XInputGetCapabilities))
|
||||
#pragma comment(linker, PROXY_EXPORT(XInputEnable))
|
||||
#pragma comment(linker, PROXY_EXPORT(XInputGetBatteryInformation))
|
||||
#pragma comment(linker, PROXY_EXPORT(XInputGetKeystroke))
|
||||
#pragma comment(linker, PROXY_EXPORT(XInputGetAudioDeviceIds))
|
||||
|
||||
struct XINPUT_STATE;
|
||||
struct XINPUT_CAPABILITIES;
|
||||
|
||||
// libcocos2d.dll requires for this function to have ordinal 2.
|
||||
constexpr static auto MAX_PATH_CHARS = 32768u;
|
||||
|
||||
static HMODULE getXInput() {
|
||||
static auto xinput = []() -> HMODULE {
|
||||
std::wstring path(MAX_PATH_CHARS, L'\0');
|
||||
auto size = GetSystemDirectoryW(const_cast<wchar_t*>(path.data()), path.size());
|
||||
if (size) {
|
||||
path.resize(size);
|
||||
return LoadLibraryW((path + L"\\XInput1_4.dll").c_str());
|
||||
}
|
||||
return NULL;
|
||||
}();
|
||||
|
||||
return xinput;
|
||||
}
|
||||
|
||||
static FARPROC getFP(const std::string& sym) {
|
||||
if (auto xinput = getXInput())
|
||||
return GetProcAddress(xinput, sym.c_str());
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#pragma comment(linker, "/export:XInputGetState,@2")
|
||||
extern "C" DWORD XInputGetState(DWORD dwUserIndex, XINPUT_STATE *pState) {
|
||||
auto xinput = GetModuleHandleA(XINPUT_PATH);
|
||||
if (!xinput)
|
||||
xinput = LoadLibraryA(XINPUT_PATH);
|
||||
|
||||
if (xinput) {
|
||||
auto fp = GetProcAddress(xinput, "XInputGetState");
|
||||
if (fp) {
|
||||
using FPType = decltype(&XInputGetState);
|
||||
return reinterpret_cast<FPType>(fp)(dwUserIndex, pState);
|
||||
}
|
||||
static auto fp = getFP("XInputGetState");
|
||||
if (fp) {
|
||||
using FPType = decltype(&XInputGetState);
|
||||
return reinterpret_cast<FPType>(fp)(dwUserIndex, pState);
|
||||
}
|
||||
|
||||
return ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
// Hi nikki please leave this as is, it fixes wine :)
|
||||
#pragma comment(linker, "/export:XInputGetCapabilities,@4")
|
||||
extern "C" DWORD XInputGetCapabilities(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES *pCapabilities) {
|
||||
auto xinput = GetModuleHandleA(XINPUT_PATH);
|
||||
if (!xinput)
|
||||
xinput = LoadLibraryA(XINPUT_PATH);
|
||||
|
||||
if (xinput) {
|
||||
auto fp = GetProcAddress(xinput, "XInputGetCapabilities");
|
||||
if (fp) {
|
||||
using FPType = decltype(&XInputGetCapabilities);
|
||||
return reinterpret_cast<FPType>(fp)(dwUserIndex, dwFlags, pCapabilities);
|
||||
}
|
||||
static auto fp = getFP("XInputGetCapabilities");
|
||||
if (fp) {
|
||||
using FPType = decltype(&XInputGetCapabilities);
|
||||
return reinterpret_cast<FPType>(fp)(dwUserIndex, dwFlags, pCapabilities);
|
||||
}
|
||||
|
||||
return ERROR_DEVICE_NOT_CONNECTED;
|
||||
|
@ -57,7 +53,7 @@ static std::wstring getErrorString() {
|
|||
return L"Could not load Geode. Error code: " + std::to_wstring(GetLastError());
|
||||
}
|
||||
|
||||
__declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID _) {
|
||||
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID _) {
|
||||
if (reason == DLL_PROCESS_ATTACH) {
|
||||
DisableThreadLibraryCalls(module);
|
||||
|
||||
|
|
Loading…
Reference in a new issue