geode/loader/launcher/windows/proxyLoader.cpp

27 lines
882 B
C++
Raw Normal View History

2024-06-01 17:50:36 -04:00
#include <Windows.h>
#include <string>
// https://github.com/mrexodia/perfect-dll-proxy
2024-06-02 11:10:44 -04:00
#define PROXY(export, ordinal) \
"/export:" #export "=\\\\.\\GLOBALROOT\\SystemRoot\\System32\\XInput1_4.dll.#" #ordinal
2024-06-01 17:50:36 -04:00
2024-06-02 14:26:06 -04:00
// These are the only two functions required by libcocos2d.dll.
2024-06-02 13:57:23 -04:00
#pragma comment(linker, PROXY(XInputGetState, 2))
#pragma comment(linker, PROXY(XInputGetCapabilities, 4))
2024-06-01 17:50:36 -04:00
static std::wstring getErrorString() {
return L"Could not load Geode. Error code: " + std::to_wstring(GetLastError());
}
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID _) {
if (reason == DLL_PROCESS_ATTACH) {
DisableThreadLibraryCalls(module);
// This is UB.
if (LoadLibraryW(L"Geode.dll") == NULL)
MessageBoxW(NULL, getErrorString().c_str(), L"Load failed" , MB_OK | MB_ICONWARNING);
}
return TRUE;
}