Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.98 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "Gordy.h"
  3. #include "namedPipe.h"
  4. #include <iostream>
  5. #include "Globals.h"
  6. #include <time.h>
  7.  
  8. Gordy::Gordy() {};
  9.  
  10. WPARAM Gordy::StartGordy() {
  11. MSG message;
  12. RECT rect;
  13.  
  14. while (TRUE) {
  15. ZeroMemory(&message, sizeof(MSG));
  16.  
  17. if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
  18. TranslateMessage(&message);
  19. DispatchMessage(&message);
  20. }
  21.  
  22. if (message.message == WM_QUIT) {
  23. exit(0);
  24. }
  25.  
  26. screenWindow = NULL;
  27. screenWindow = FindWindow(NULL, L"Rainbow Six");
  28. if (!screenWindow) {
  29. std::cout << "Application exiting, failed to find the specified window!" << std::endl;
  30. ExitProcess(0);
  31. }
  32.  
  33. ZeroMemory(&rect, sizeof(RECT));
  34.  
  35. GetWindowRect(screenWindow, &rect);
  36. captureWidth = rect.right - rect.left;
  37. captureHeight = rect.bottom - rect.top;
  38.  
  39. MoveWindow(captureWindow, rect.left, rect.top, captureWidth, captureHeight, true);
  40.  
  41. HWND primaryWindow2 = GetForegroundWindow();
  42. HWND primaryWindow3 = GetWindow(primaryWindow2, GW_HWNDPREV);
  43.  
  44. SetWindowPos(captureWindow, primaryWindow3, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  45.  
  46. UpdateWindow(captureWindow);
  47.  
  48. GordyRender();
  49.  
  50. Sleep(5);
  51. }
  52. return message.wParam;
  53. }
  54.  
  55. void Gordy::GordyRender() {
  56. captureDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
  57. captureDevice->BeginScene();
  58.  
  59. Brain();
  60.  
  61. captureDevice->EndScene();
  62. captureDevice->Present(NULL, NULL, NULL, NULL);
  63. }
  64.  
  65. void Gordy::GordyInit(HWND handleWindow) {
  66. //Create our direct3d object
  67. captureDirectX = Direct3DCreate9(D3D_SDK_VERSION);
  68.  
  69. D3DPRESENT_PARAMETERS direct3DPresetParams;
  70.  
  71. ZeroMemory(&direct3DPresetParams, sizeof(direct3DPresetParams));
  72.  
  73. direct3DPresetParams.Windowed = true;
  74. direct3DPresetParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
  75. direct3DPresetParams.hDeviceWindow = handleWindow;
  76. direct3DPresetParams.BackBufferFormat = D3DFMT_A8R8G8B8;
  77. direct3DPresetParams.BackBufferWidth = captureWidth;
  78. direct3DPresetParams.BackBufferHeight = captureHeight;
  79.  
  80. direct3DPresetParams.EnableAutoDepthStencil = TRUE;
  81. direct3DPresetParams.AutoDepthStencilFormat = D3DFMT_D16;
  82.  
  83.  
  84. captureDirectX->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, handleWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &direct3DPresetParams, &captureDevice);
  85. D3DXCreateFontA(captureDevice, 13, 0, FW_HEAVY, 1, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &captureFont);
  86.  
  87. D3DXCreateLine(captureDevice, &captureLine);
  88. }
  89.  
  90. void Gordy::GordyCircle(int X, int Y, int radius, int numSides, DWORD color) {
  91. D3DXVECTOR2 Line[128];
  92. float Step = PI * 2.0 / numSides;
  93. int Count = 0;
  94. for (float a = 0; a < PI*2.0; a += Step)
  95. {
  96. float X1 = radius * cos(a) + X;
  97. float Y1 = radius * sin(a) + Y;
  98. float X2 = radius * cos(a + Step) + X;
  99. float Y2 = radius * sin(a + Step) + Y;
  100. Line[Count].x = X1;
  101. Line[Count].y = Y1;
  102. Line[Count + 1].x = X2;
  103. Line[Count + 1].y = Y2;
  104. Count += 2;
  105. }
  106. captureLine->Draw(Line, Count, color);
  107. }
  108.  
  109. void Gordy::GordyFillArea(float x, float y, float width, float height, D3DCOLOR color) {
  110. D3DXVECTOR2 vectorLine[2];
  111. captureLine->SetWidth(width);
  112.  
  113. vectorLine[0].x = x + width / 2;
  114. vectorLine[0].y = y;
  115. vectorLine[1].x = x + width / 2;
  116. vectorLine[1].y = y + height;
  117.  
  118. captureLine->Draw(vectorLine, 2, color);
  119. }
  120.  
  121. void Gordy::GordyFillRect(double x, double y, double w, double h, D3DCOLOR color)
  122. {
  123. struct Vertex
  124. {
  125. float x, y, z, h;
  126. D3DCOLOR color;
  127. };
  128.  
  129. Vertex vertices[4] =
  130. {
  131. x, y, 0.0f, 1.0f, color,
  132. x + w, y, 0.0f, 1.0f, color,
  133.  
  134. x + w, y + h, 0.0f, 1.0f, color,
  135. x, y + h, 0.0f, 1.0f, color,
  136. };
  137.  
  138. captureDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
  139. captureDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
  140. captureDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
  141. captureDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, vertices, sizeof(Vertex));
  142. }
  143.  
  144. void Gordy::GordyBox(float x, float y, float width, float height, D3DCOLOR color) {
  145. D3DXVECTOR2 points[5];
  146. points[0] = D3DXVECTOR2(x, y);
  147. points[1] = D3DXVECTOR2(x + width, y);
  148. points[2] = D3DXVECTOR2(x + width, y + height);
  149. points[3] = D3DXVECTOR2(x, y + height);
  150. points[4] = D3DXVECTOR2(x, y);
  151. captureLine->SetWidth(1);
  152. captureLine->Draw(points, 5, color);
  153. }
  154.  
  155. void Gordy::GordyString(int x, int y, DWORD color, LPD3DXFONT g_pFont, const char *fmt, ...)
  156. {
  157. char buf[1024] = { 0 };
  158. va_list va_alist;
  159. RECT FontPos = { x, y, x + 150, y + 40 };
  160. va_start(va_alist, fmt);
  161. vsprintf_s(buf, fmt, va_alist);
  162. va_end(va_alist);
  163. g_pFont->DrawTextA(NULL, buf, -1, &FontPos, DT_NOCLIP, color);
  164. }
  165.  
  166. LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  167. {
  168. switch (message)
  169. {
  170. case WM_PAINT:
  171. Global::gordy.GordyRender();
  172. break;
  173. case WM_CREATE:
  174. DwmExtendFrameIntoClientArea(hWnd, &Global::gordy.margins);
  175. break;
  176.  
  177. case WM_DESTROY:
  178. PostQuitMessage(0);
  179. return 0;
  180. }
  181.  
  182. return DefWindowProc(hWnd, message, wParam, lParam);
  183. }
  184.  
  185. std::string RandomOverlayString(int len)
  186. {
  187. srand(time(0));
  188. std::string str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  189. std::string newstr;
  190. int pos;
  191. while (newstr.size() != len) {
  192. pos = ((rand() % (str.size() - 1)));
  193. newstr += str.substr(pos, 1);
  194. }
  195. return newstr;
  196. }
  197.  
  198. std::wstring s2wstr(const std::string& s)
  199. {
  200. int len;
  201. int slength = (int)s.length() + 1;
  202. len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
  203. wchar_t* buf = new wchar_t[len];
  204. MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
  205. std::wstring r(buf);
  206. delete[] buf;
  207. return r;
  208. }
  209.  
  210. void Gordy::GordySetup() {
  211.  
  212. RECT rect;
  213.  
  214. while (!screenWindow) {
  215. screenWindow = FindWindow(NULL, L"Rainbow Six");
  216. }
  217.  
  218. if (screenWindow != NULL) {
  219. GetWindowRect(screenWindow, &rect);
  220. std::cout << captureWidth << "x" << captureHeight << std::endl;
  221. }
  222. else {
  223. std::cout << "Application exiting, error preapring the window. Error code: " << GetLastError() << std::endl;
  224. Sleep(3000);
  225. ExitProcess(0);
  226. }
  227.  
  228. WNDCLASSEX windowClass;
  229.  
  230. ZeroMemory(&windowClass, sizeof(WNDCLASSEX));
  231.  
  232. std::string randomName = RandomOverlayString(10);
  233. std::wstring stemp = s2wstr(randomName);
  234. LPCWSTR overlayName = stemp.c_str();
  235.  
  236. windowClass.cbSize = sizeof(WNDCLASSEX);
  237. windowClass.style = CS_HREDRAW | CS_VREDRAW;
  238. windowClass.lpfnWndProc = WindowProc;
  239. windowClass.hInstance = GetModuleHandle(0);
  240. windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  241. windowClass.hbrBackground = (HBRUSH)RGB(0, 0, 0);
  242. windowClass.lpszClassName = overlayName;
  243.  
  244. RegisterClassEx(&windowClass);
  245.  
  246. captureWindow = CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT, windowClass.lpszClassName, overlayName, WS_POPUP, rect.left, rect.top, captureWidth, captureHeight, NULL, NULL, windowClass.hInstance, NULL);
  247.  
  248. SetLayeredWindowAttributes(captureWindow, RGB(0, 0, 0), 0, ULW_COLORKEY);
  249. SetLayeredWindowAttributes(captureWindow, 0, 255, LWA_ALPHA);
  250.  
  251. ShowWindow(captureWindow, SW_SHOW);
  252. GordyInit(captureWindow);
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement