-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathd3d9create.cpp
More file actions
80 lines (67 loc) · 2.26 KB
/
d3d9create.cpp
File metadata and controls
80 lines (67 loc) · 2.26 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "d3d9device.h"
#include "d3d9create.h"
#include "d3d9proxy.h"
// global variables
#pragma data_seg (".d3d9_shared")
myIDirect3DDevice9* gl_pmyIDirect3DDevice9;
myIDirect3D9* gl_pmyIDirect3D9;
HINSTANCE gl_hOriginalDll;
HINSTANCE gl_hThisInstance;
#pragma data_seg ()
IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion)
{
if (!gl_hOriginalDll) LoadOriginalDll(); // looking for the "right d3d9.dll"
// Hooking IDirect3D Object from Original Library
typedef IDirect3D9 *(WINAPI* D3D9_Type)(UINT SDKVersion);
D3D9_Type D3DCreate9_fn = (D3D9_Type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9");
// Debug
if (!D3DCreate9_fn)
{
OutputDebugString("PROXYDLL: Pointer to original D3DCreate9 function not received ERROR ****\r\n");
::ExitProcess(0); // exit the hard way
}
// Request pointer from Original Dll.
IDirect3D9 *pIDirect3D9_orig = D3DCreate9_fn(SDKVersion);
// Create my IDirect3D8 object and store pointer to original object there.
// note: the object will delete itself once Ref count is zero (similar to COM objects)
gl_pmyIDirect3D9 = new myIDirect3D9(pIDirect3D9_orig);
// Return pointer to hooking Object instead of "real one"
return (gl_pmyIDirect3D9);
}
void InitInstance(HANDLE hModule)
{
OutputDebugString("PROXYDLL: InitInstance called.\r\n");
// Initialisation
gl_hOriginalDll = NULL;
gl_hThisInstance = NULL;
gl_pmyIDirect3D9 = NULL;
gl_pmyIDirect3DDevice9 = NULL;
// Storing Instance handle into global var
gl_hThisInstance = (HINSTANCE) hModule;
}
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.dll not loaded ERROR ****\r\n");
::ExitProcess(0); // exit the hard way
}
}
void ExitInstance()
{
OutputDebugString("PROXYDLL: ExitInstance called.\r\n");
// Release the system's d3d9.dll
if (gl_hOriginalDll)
{
::FreeLibrary(gl_hOriginalDll);
gl_hOriginalDll = NULL;
}
}