-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd3d9.cpp
More file actions
58 lines (44 loc) · 1.55 KB
/
d3d9.cpp
File metadata and controls
58 lines (44 loc) · 1.55 KB
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
#include <Windows.h>
#include <d3d9.h>
#include <stdio.h>
typedef IDirect3D9*(__stdcall* D3D9_CREATE_FUNC) (UINT SDKVersion);
#pragma data_seg (".d3d9_shared")
HINSTANCE gl_hOriginalDll;
HINSTANCE gl_hThisInstance;
#pragma data_seg ()
void LoadOriginalDll(void);
void perform_ra3_patches();
IDirect3D9* __stdcall Direct3DCreate9(UINT SDKVersion) {
if (!gl_hOriginalDll) LoadOriginalDll();
D3D9_CREATE_FUNC funcAddress_Direct3DCreate9 = (D3D9_CREATE_FUNC)GetProcAddress(gl_hOriginalDll, "Direct3DCreate9");
//char dumb_msg[1024];
//sprintf_s(dumb_msg, sizeof(dumb_msg), "func pointer is: %p, thread: %d\n", funcAddress_Direct3DCreate9, GetCurrentThreadId());
//MessageBoxA(NULL, dumb_msg, "Injected", MB_OK);
if (!funcAddress_Direct3DCreate9)
{
OutputDebugString("PROXYDLL: Pointer to original DirectInput8Create function not received ERROR ****\r\n");
::ExitProcess(0); // exit the hard way
}
static bool patches_done = false;
if (!patches_done) {
patches_done = true;
perform_ra3_patches();
}
return funcAddress_Direct3DCreate9(SDKVersion);
}
void LoadOriginalDll(void)
{
char buffer[MAX_PATH];
// Getting path to system dir and to d3d8.dll
::GetSystemDirectory(buffer, MAX_PATH);
// Append dll name
strcat_s(buffer, sizeof(buffer), "\\d3d9.dll");
// try to load the system's d3d9.dll, if pointer empty
if (!gl_hOriginalDll) gl_hOriginalDll = ::LoadLibrary(buffer);
// Debug
if (!gl_hOriginalDll)
{
OutputDebugString("PROXYDLL: Original d3d9.dinput8 not loaded ERROR ****\r\n");
::ExitProcess(0); // exit the hard way
}
}