| 380 | } |
| 381 | |
| 382 | static void LoadProxyLibrary() |
| 383 | { |
| 384 | // Attempt to load the chain-load DLL from the game's directory |
| 385 | wchar_t modulePath[MAX_PATH]; |
| 386 | if (GetModuleFileNameW(NULL, modulePath, MAX_PATH)) |
| 387 | { |
| 388 | wchar_t* lastBackslash = wcsrchr(modulePath, L'\\'); |
| 389 | if (lastBackslash != NULL) |
| 390 | { |
| 391 | *lastBackslash = L'\0'; |
| 392 | lstrcatW(modulePath, L"\\dinput8_hook.dll"); |
| 393 | |
| 394 | HINSTANCE hChain = LoadLibraryExW(modulePath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); |
| 395 | if (hChain) |
| 396 | { |
| 397 | // Set up proxies to use the chain-loaded DLL |
| 398 | if (dinput8.ProxySetup(hChain)) |
| 399 | { |
| 400 | return; // Successfully chained |
| 401 | } |
| 402 | else |
| 403 | { |
| 404 | // Handle missing exports in chain DLL |
| 405 | FreeLibrary(hChain); |
| 406 | // Fall through to system DLL |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | // Fallback to system dinput8.dll |
| 413 | wchar_t systemPath[MAX_PATH]; |
| 414 | GetSystemDirectoryW(systemPath, MAX_PATH); |
| 415 | lstrcatW(systemPath, L"\\dinput8.dll"); |
| 416 | |
| 417 | HINSTANCE hOriginal = LoadLibraryExW(systemPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH); |
| 418 | if (!hOriginal) |
| 419 | { |
| 420 | DWORD errorCode = GetLastError(); |
| 421 | wchar_t errorMessage[512]; |
| 422 | |
| 423 | FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorCode, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), errorMessage, sizeof(errorMessage) / sizeof(wchar_t), NULL); |
| 424 | MessageBoxW(NULL, errorMessage, L"Error Loading dinput8.dll", MB_ICONERROR); |
| 425 | return; |
| 426 | } |
| 427 | |
| 428 | // Set up proxies to system DLL |
| 429 | dinput8.ProxySetup(hOriginal); |
| 430 | } |
| 431 | }; |
| 432 | |
| 433 | namespace IniHelper |