-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirect3DDevice9WrapperExtended.cpp
154 lines (122 loc) · 5.19 KB
/
Direct3DDevice9WrapperExtended.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "Direct3DDevice9WrapperExtended.h"
DWORD Direct3DDevice9WrapperExtended::m_dwWireframe = D3DFILL_SOLID;
HWND Direct3DDevice9WrapperExtended::m_GameHwnd = NULL;
WNDPROC Direct3DDevice9WrapperExtended::m_lpOldWndProc = NULL;
set<IndexedPrimitive> *Direct3DDevice9WrapperExtended::m_setSelected = NULL;
int Direct3DDevice9WrapperExtended::m_iSelected = 0;
int Direct3DDevice9WrapperExtended::m_iCurrent = 0;
bool Direct3DDevice9WrapperExtended::m_bLogCycle = false;
bool Direct3DDevice9WrapperExtended::m_bIsUpdateSelectedCycle = false;
bool Direct3DDevice9WrapperExtended::m_bUpdateSelected = false;
bool Direct3DDevice9WrapperExtended::m_bPickedChanged = false;
bool Direct3DDevice9WrapperExtended::m_bIsPickedChangedCycle = false;
bool Direct3DDevice9WrapperExtended::m_bHideSelected = false;
bool Direct3DDevice9WrapperExtended::m_bCaptureScreen = false;
bool Direct3DDevice9WrapperExtended::m_bIsCaptureCycle = false;
Direct3DDevice9WrapperExtended::Direct3DDevice9WrapperExtended(IDirect3DDevice9* pDirect3DDevice9, IDirect3D9* pDirect3D9, D3DPRESENT_PARAMETERS *pPresentationParameters, HWND hFocusWindow):
Direct3DDevice9Wrapper(pDirect3DDevice9, pDirect3D9, pPresentationParameters)
{
m_setSelected = new set<IndexedPrimitive>();
m_GameHwnd = hFocusWindow;
m_bIsTrackingCaptureCycle = m_bIsLogCycle = false;
if (!m_GameHwnd){
DXLOG("No Game Handler :(\n");
}
if (!m_lpOldWndProc && m_GameHwnd){
DXLOG("Hooked on WndProc.\n");
m_lpOldWndProc = (WNDPROC)(LONG_PTR)SetWindowLongPtr(m_GameHwnd, GWL_WNDPROC, (LONG)(LONG_PTR)Mine_WndProc);
}
// Setting up pixel shaders
ID3DXBuffer *tmp;
if (D3DXCompileShaderFromFile(L"White.psh", 0, 0, "main", "ps_2_0", 0, &tmp, 0, 0) != D3D_OK)
DXLOGALWAYS("Failed Compiling PS.\n");
Direct3DDevice9->CreatePixelShader((DWORD*)tmp->GetBufferPointer(), &m_psWhite);
tmp->Release();
}
Direct3DDevice9WrapperExtended::~Direct3DDevice9WrapperExtended()
{
delete m_setSelected;
}
HRESULT Direct3DDevice9WrapperExtended::BeginScene()
{
// A rendering cycle has begun
DXLOGCYCLE("Direct3DDevice9WrapperExtended: BeginScene\n");
StartCycle();
return Direct3DDevice9->BeginScene();
}
HRESULT Direct3DDevice9WrapperExtended::EndScene()
{
DXLOGCYCLE("Direct3DDevice9WrapperExtended: EndScene\n");
if (m_bIsCaptureCycle || m_bIsTrackingCaptureCycle){
IDirect3DSurface9 *surf;
Direct3DDevice9->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&surf);
string filename;
if (m_bIsCaptureCycle)
filename = "Screen.bmp";
else
filename = "Tracking.bmp";
DXLOGALWAYS("Taking pic.\n")
D3DXSaveSurfaceToFileA(filename.c_str(), D3DXIFF_BMP, surf, 0, 0);
if (m_bIsCaptureCycle)
m_bIsTrackingCaptureCycle = true;
else
m_bIsTrackingCaptureCycle = false;
surf->Release();
}
return Direct3DDevice9->EndScene();
}
HRESULT Direct3DDevice9WrapperExtended::DrawIndexedPrimitive( D3DPRIMITIVETYPE PrimitiveType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount)
{
char tmp[250];
sprintf(tmp, "Direct3DDevice9WrapperExtended: DrawIndexedPrimitive. PrimitiveType = %u, BaseVertexIndex = %d, MinVertexIndex = %u, NumVertices = %u, startIndex = %u, primCount = %u\n", PrimitiveType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
DXLOGCYCLE(tmp);
bool inSet = m_setSelected->find(IndexedPrimitive(BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount)) != m_setSelected->end();
bool isCurrent = m_iSelected == m_iCurrent;
// Update the selected indexed primitive
if ((m_bIsPickedChangedCycle || m_bIsUpdateSelectedCycle) && isCurrent){
m_ipCurrentIndexedPrimitive.Set(BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
}
// Insert or remove from selected set
if (m_bIsPickedChangedCycle && isCurrent){
if (inSet)
m_setSelected->erase(m_ipCurrentIndexedPrimitive);
else
m_setSelected->insert(m_ipCurrentIndexedPrimitive);
inSet = !inSet;
}
// Draw the indexed primitive - if it's in the set or selected, use white pixel shader
if ((!m_bHideSelected && isCurrent) || inSet){
IDirect3DPixelShader9 *psTmp;
if (!m_bIsCaptureCycle){
Direct3DDevice9->GetPixelShader(&psTmp);
Direct3DDevice9->SetPixelShader(m_psWhite);
}
HRESULT res = Direct3DDevice9->DrawIndexedPrimitive( PrimitiveType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
if (!m_bIsCaptureCycle)
Direct3DDevice9->SetPixelShader(psTmp);
m_iCurrent++;
return res;
}
m_iCurrent++;
if(LOWORD(GetKeyState(VK_CAPITAL)) & 1) // Caps is on
return D3D_OK;
HRESULT res = Direct3DDevice9->DrawIndexedPrimitive( PrimitiveType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
return res;
}
void Direct3DDevice9WrapperExtended::Lock(bool &action, bool &actionCycle)
{
if (actionCycle)
actionCycle = false;
if (action){
action = false;
actionCycle = true;
}
}
void Direct3DDevice9WrapperExtended::StartCycle()
{
Lock(m_bLogCycle, m_bIsLogCycle);
Lock(m_bUpdateSelected, m_bIsUpdateSelectedCycle);
Lock(m_bPickedChanged, m_bIsPickedChangedCycle);
Lock(m_bCaptureScreen, m_bIsCaptureCycle);
m_iCurrent = 0;
}