forked from GameHackingBook/GameHackingCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
127 lines (99 loc) · 3.81 KB
/
Copy pathmain.cpp
File metadata and controls
127 lines (99 loc) · 3.81 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
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
122
123
124
125
126
127
#include "DirectXHook.h"
int primitivesDrawn = 0;
int gliderImage = 0;
bool initialized = false;
////////////////// CHAPTER 9 LIGTHACK STUFF //////////////////
bool lightHack = false;
void enableLightHackDirectional(LPDIRECT3DDEVICE9 pDevice)
{
D3DLIGHT9 light;
ZeroMemory(&light, sizeof(light));
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
light.Direction = D3DXVECTOR3(-1.0f, -0.5f, -1.0f);
pDevice->SetLight(0, &light);
pDevice->LightEnable(0, TRUE);
lightHack = true;
}
void enableLightHackAmbient(LPDIRECT3DDEVICE9 pDevice)
{
pDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(100, 100, 100));
lightHack = true;
}
void lightHackFrame(DirectXHook* hook, LPDIRECT3DDEVICE9 pDevice)
{
if (!lightHack)
{
if (GetAsyncKeyState(VK_F1))
enableLightHackDirectional(pDevice);
else if (GetAsyncKeyState(VK_F2))
enableLightHackAmbient(pDevice);
}
if (!lightHack)
hook->drawText(10, 188, D3DCOLOR_ARGB(255, 255, 0, 0), "There is currently no lighting. To enable light hack, press F1 for directional or F2 for ambient.");
else
hook->drawText(10, 188, D3DCOLOR_ARGB(255, 255, 0, 0), "Lighthack has been enabled, you should see the cube clearly now.");
}
////////////////// CHAPTER 9 WALLHACK STUFF //////////////////
bool wallHack = false;
LPDIRECT3DTEXTURE9 redTexture = NULL;
void wallHackFrame(DirectXHook* hook, LPDIRECT3DDEVICE9 pDevice)
{
if (!wallHack && GetAsyncKeyState(VK_F3))
wallHack = true;
if (!wallHack)
hook->drawText(10, 203, D3DCOLOR_ARGB(255, 255, 0, 0), "Wallhack example isnt running! Press F3 to enable.");
else
hook->drawText(10, 203, D3DCOLOR_ARGB(255, 255, 0, 0), "Wallhack is enabled! The cube should be drawn in red with no z-buffering now!");
}
void onDrawIndexedPrimitive(DirectXHook* hook, LPDIRECT3DDEVICE9 device, D3DPRIMITIVETYPE primType, INT baseVertexIndex, UINT minVertexIndex, UINT numVertices, UINT startIndex, UINT primCount)
{
primitivesDrawn++;
if (wallHack && numVertices == 24 && primCount == 12)
{
device->SetRenderState(D3DRS_ZENABLE, false);
if (redTexture) device->SetTexture(0, redTexture);
DirectXHook::origDrawIndexedPrimitive(device, primType, baseVertexIndex, minVertexIndex, numVertices, startIndex, primCount);
device->SetRenderState(D3DRS_ZENABLE, true);
}
}
////////////////// CHAPTER 8 STUFF //////////////////
void initialize(LPDIRECT3DDEVICE9 pDevice)
{
gliderImage = DirectXHook::getInstance()->addSpriteImage(L"glider.png");
redTexture = DirectXHook::getInstance()->addTexture(L"red.png"); // CHAPTER 9 WALLHACK STUFF
initialized = true;
}
void onDrawFrame(DirectXHook* hook, LPDIRECT3DDEVICE9 pDevice)
{
if (!initialized) initialize(pDevice);
hook->drawText(10, 10, D3DCOLOR_ARGB(255, 255, 0, 0), "Direct3D hook working! Intercepted drawing of %d primitives!", primitivesDrawn);
hook->drawText(10, 25, D3DCOLOR_ARGB(255, 255, 0, 0), "Image drawn by hook:");
hook->drawSpriteImage(gliderImage, 10, 40, 128, 128);
lightHackFrame(hook, pDevice); // CHAPTER 9 LIGTHACK STUFF
wallHackFrame(hook, pDevice); // CHAPTER 9 WALLHACK STUFF
primitivesDrawn = 0;
}
void onDrawPrimitive(DirectXHook* hook, LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
{
primitivesDrawn++;
}
DWORD WINAPI LoopFunction(LPVOID lpParam)
{
DirectXHook::getInstance()->addDrawFrameCallback(&onDrawFrame);
DirectXHook::getInstance()->addDrawPrimitiveCallback(&onDrawPrimitive);
DirectXHook::getInstance()->addDrawIndexedPrimitiveCallback(&onDrawIndexedPrimitive);
DirectXHook::getInstance()->initialize();
return 0;
}
BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpvReserved)
{
if(dwReason == DLL_PROCESS_ATTACH)
{
CreateThread(0, 0, LoopFunction, 0, 0, 0);
}
else if(dwReason == DLL_PROCESS_DETACH)
{
}
return TRUE;
}