-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
121 lines (113 loc) · 3.14 KB
/
main.cpp
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "defines.h"
#include "IDirect3D9Proxy.h"
#pragma pack(1)
HINSTANCE hlThis = 0;
HINSTANCE hlD3D9 = 0;
FARPROC origProc[15] = {0};
BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID){
if (reason == DLL_PROCESS_ATTACH){
hlThis = hInst;
//Get path to the original d3d9.dll
char infoBuf[MAX_PATH];
GetSystemDirectory(infoBuf, MAX_PATH);
strcat_s(infoBuf, MAX_PATH, "\\d3d9.dll");
//And load it...
hlD3D9 = LoadLibrary(infoBuf);
if (!hlD3D9){
MessageBox(NULL, "D3D9 Proxy DLL error", "Cannot find original d3d9.dll in the system directory!", MB_OK | MB_ICONERROR);
return FALSE;
}
//Load original functions
origProc[0] = GetProcAddress(hlD3D9, "D3DPERF_BeginEvent");
origProc[1] = GetProcAddress(hlD3D9, "D3DPERF_EndEvent");
origProc[2] = GetProcAddress(hlD3D9, "D3DPERF_GetStatus");
origProc[3] = GetProcAddress(hlD3D9, "D3DPERF_QueryRepeatFrame");
origProc[4] = GetProcAddress(hlD3D9, "D3DPERF_SetMarker");
origProc[5] = GetProcAddress(hlD3D9, "D3DPERF_SetOptions");
origProc[6] = GetProcAddress(hlD3D9, "D3DPERF_SetRegion");
origProc[7] = GetProcAddress(hlD3D9, "DebugSetLevel");
origProc[8] = GetProcAddress(hlD3D9, "DebugSetMute");
origProc[9] = GetProcAddress(hlD3D9, "Direct3DCreate9");
origProc[10] = GetProcAddress(hlD3D9, "Direct3DCreate9Ex");
origProc[11] = GetProcAddress(hlD3D9, "Direct3DShaderValidatorCreate9");
origProc[12] = GetProcAddress(hlD3D9, "PSGPError");
origProc[13] = GetProcAddress(hlD3D9, "PSGPSampleTexture");
}else if (reason == DLL_PROCESS_DETACH){
FreeLibrary(hlD3D9);
}
return TRUE;
}
//Direct3DCreate9
extern "C" IDirect3D9* WINAPI __ProxyFunc9(UINT SDKVersion){
//Recall original function
typedef IDirect3D9* (WINAPI* Direct3DCreate9Func)(UINT sdkver);
Direct3DCreate9Func origDirect3DCreate9 = (Direct3DCreate9Func)GetProcAddress(hlD3D9, "Direct3DCreate9");
IDirect3D9* res = origDirect3DCreate9(SDKVersion);
return new IDirect3D9Proxy(res);
}
//Direct3DCreate9Ex
extern "C" __declspec(naked) void __stdcall __ProxyFunc10(){
__asm{
jmp origProc[10*4];
}
}
extern "C" __declspec(naked) void __stdcall __ProxyFunc0(){
__asm{
jmp origProc[0*4];
}
}
extern "C" __declspec(naked) void __stdcall __ProxyFunc1(){
__asm{
jmp origProc[1*4];
}
}
extern "C" __declspec(naked) void __stdcall __ProxyFunc2(){
__asm{
jmp origProc[2*4];
}
}
extern "C" __declspec(naked) void __stdcall __ProxyFunc3(){
__asm{
jmp origProc[3*4];
}
}
extern "C" __declspec(naked) void __stdcall __ProxyFunc4(){
__asm{
jmp origProc[4*4];
}
}
extern "C" __declspec(naked) void __stdcall __ProxyFunc5(){
__asm{
jmp origProc[5*4];
}
}
extern "C" __declspec(naked) void __stdcall __ProxyFunc6(){
__asm{
jmp origProc[6*4];
}
}
extern "C" __declspec(naked) void __stdcall __ProxyFunc7(){
__asm{
jmp origProc[7*4];
}
}
extern "C" __declspec(naked) void __stdcall __ProxyFunc8(){
__asm{
jmp origProc[8*4];
}
}
extern "C" __declspec(naked) void __stdcall __ProxyFunc11(){
__asm{
jmp origProc[11*4];
}
}
extern "C" __declspec(naked) void __stdcall __ProxyFunc12(){
__asm{
jmp origProc[12*4];
}
}
extern "C" __declspec(naked) void __stdcall __ProxyFunc13(){
__asm{
jmp origProc[13*4];
}
}