Skip to content

Commit

Permalink
Merge branch 'dev/di_sys_hook' into 'main'
Browse files Browse the repository at this point in the history
Always injecting into system DirectInput libraries

See merge request lightspeedrtx/bridge-remix-nv!44
  • Loading branch information
AlexDunn committed Oct 9, 2023
2 parents 5aa73bc + 58a7e24 commit 0903dd0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/client/di_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#include <strsafe.h>

#include "detours.h"
#include "d3d9_util.h"
Expand Down Expand Up @@ -510,6 +511,14 @@ class DirectInputHookBase {
API_DETACH(GetDeviceData);
API_DETACH(SetCooperativeLevel);
}

static std::string getSystemLibraryPath(const char* name) {
char szSystemLib[1024];
GetSystemDirectoryA(szSystemLib, sizeof(szSystemLib));
StringCchCatA(szSystemLib, sizeof(szSystemLib), "\\");
StringCchCatA(szSystemLib, sizeof(szSystemLib), name);
return szSystemLib;
}
};

class DirectInput8Hook: public DirectInputHookBase<8> {
Expand All @@ -531,7 +540,7 @@ class DirectInput8Hook: public DirectInputHookBase<8> {
auto OrigLoadLibraryA = DetourRetrieveOriginal(LoadLibraryA);
auto OrigGetProcAddress = DetourRetrieveOriginal(GetProcAddress);

HMODULE hdi8 = OrigLoadLibraryA("dinput8");
HMODULE hdi8 = OrigLoadLibraryA(getSystemLibraryPath("dinput8").c_str());

OrigDirectInput8Create = reinterpret_cast<decltype(OrigDirectInput8Create)>(
OrigGetProcAddress(hdi8, "DirectInput8Create"));
Expand Down Expand Up @@ -639,7 +648,7 @@ class DirectInput7Hook: public DirectInputHookBase<7> {
auto OrigLoadLibraryA = DetourRetrieveOriginal(LoadLibraryA);
auto OrigGetProcAddress = DetourRetrieveOriginal(GetProcAddress);

HMODULE hdi = OrigLoadLibraryA("dinput");
HMODULE hdi = OrigLoadLibraryA(getSystemLibraryPath("dinput").c_str());

OrigDirectInputCreateA = reinterpret_cast<decltype(OrigDirectInputCreateA)>(
OrigGetProcAddress(hdi, "DirectInputCreateA"));
Expand Down

0 comments on commit 0903dd0

Please sign in to comment.