-
Notifications
You must be signed in to change notification settings - Fork 0
/
dinput8.c
104 lines (84 loc) · 2.32 KB
/
dinput8.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "dinputproxy.h"
BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason,LPVOID v)
{
if (reason == DLL_PROCESS_ATTACH)
{
char szPath[MAX_PATH];
if (!GetSystemDirectory(szPath, sizeof(szPath)))
return FALSE;
strcat(szPath, "\\dinput8.dll");
hLThis = hInst;
hL = LoadLibrary(szPath);
if (!hL)
return FALSE;
p[0] = GetProcAddress(hL,"DirectInput8Create");
p[1] = GetProcAddress(hL,"DllCanUnloadNow");
p[2] = GetProcAddress(hL,"DllGetClassObject");
p[3] = GetProcAddress(hL,"DllRegisterServer");
p[4] = GetProcAddress(hL,"DllUnregisterServer");
}
if (reason == DLL_PROCESS_DETACH)
{
FreeLibrary(hL);
}
return TRUE;
}
// DirectInput8Create
//extern "C" __declspec(naked) void __stdcall __E__0__()
HRESULT __stdcall __E__0__(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID * ppvOut, LPUNKNOWN punkOuter)
{
//__asm { jmp p[0*4]; }
proxy_IDirectInput *proxyDI;
IDirectInput8 *di;
typedef HRESULT (__stdcall *pCreate)(HINSTANCE, DWORD, REFIID, LPVOID *, LPUNKNOWN);
pCreate ppC = (pCreate)p[0*4];
HRESULT ret = ppC(hinst, dwVersion, riidltf, &di, punkOuter);
if (ret != DI_OK)
return ret;
proxyDI = (proxy_IDirectInput *)malloc(sizeof(proxy_IDirectInput));
proxyDI->vtbl.QueryInterface = proxy_IDirectInput_QueryInterface;
proxyDI->vtbl.AddRef = proxy_IDirectInput_AddRef;
proxyDI->vtbl.Release = proxy_IDirectInput_Release;
proxyDI->vtbl.CreateDevice = proxy_IDirectInput_CreateDevice;
proxyDI->vtbl.EnumDevices = proxy_IDirectInput_EnumDevices;
proxyDI->vtbl.GetDeviceStatus = proxy_IDirectInput_GetDeviceStatus;
proxyDI->vtbl.RunControlPanel = proxy_IDirectInput_RunControlPanel;
proxyDI->vtbl.Initialize = proxy_IDirectInput_Initialize;
proxyDI->lpVtbl = &proxyDI->vtbl;
proxyDI->di = di;
proxyDI->refcount = 1;
*ppvOut = (LPDIRECTINPUT)proxyDI;
return ret; /* */
}
// DllCanUnloadNow
__declspec(naked) void __stdcall __E__1__()
{
__asm
{
jmp p[1*4];
}
}
// DllGetClassObject
__declspec(naked) void __stdcall __E__2__()
{
__asm
{
jmp p[2*4];
}
}
// DllRegisterServer
__declspec(naked) void __stdcall __E__3__()
{
__asm
{
jmp p[3*4];
}
}
// DllUnregisterServer
__declspec(naked) void __stdcall __E__4__()
{
__asm
{
jmp p[4*4];
}
}