Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "Gordy.h"
- #include "namedPipe.h"
- #include <iostream>
- #include "Globals.h"
- #include <time.h>
- Gordy::Gordy() {};
- WPARAM Gordy::StartGordy() {
- MSG message;
- RECT rect;
- while (TRUE) {
- ZeroMemory(&message, sizeof(MSG));
- if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
- TranslateMessage(&message);
- DispatchMessage(&message);
- }
- if (message.message == WM_QUIT) {
- exit(0);
- }
- screenWindow = NULL;
- screenWindow = FindWindow(NULL, "Rainbow Six");
- if (!screenWindow) {
- std::cout << "Application exiting, failed to find the specified window!" << std::endl;
- ExitProcess(0);
- }
- ZeroMemory(&rect, sizeof(RECT));
- GetWindowRect(screenWindow, &rect);
- captureWidth = rect.right - rect.left;
- captureHeight = rect.bottom - rect.top;
- MoveWindow(captureWindow, rect.left, rect.top, captureWidth, captureHeight, true);
- HWND primaryWindow2 = GetForegroundWindow();
- HWND primaryWindow3 = GetWindow(primaryWindow2, GW_HWNDPREV);
- SetWindowPos(captureWindow, primaryWindow3, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- UpdateWindow(captureWindow);
- GordyRender();
- Sleep(5);
- }
- return message.wParam;
- }
- void Gordy::GordyRender() {
- captureDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
- captureDevice->BeginScene();
- Brain();
- captureDevice->EndScene();
- captureDevice->Present(NULL, NULL, NULL, NULL);
- }
- void Gordy::GordyInit(HWND handleWindow) {
- //Create our direct3d object
- captureDirectX = Direct3DCreate9(D3D_SDK_VERSION);
- D3DPRESENT_PARAMETERS direct3DPresetParams;
- ZeroMemory(&direct3DPresetParams, sizeof(direct3DPresetParams));
- direct3DPresetParams.Windowed = true;
- direct3DPresetParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
- direct3DPresetParams.hDeviceWindow = handleWindow;
- direct3DPresetParams.BackBufferFormat = D3DFMT_A8R8G8B8;
- direct3DPresetParams.BackBufferWidth = captureWidth;
- direct3DPresetParams.BackBufferHeight = captureHeight;
- direct3DPresetParams.EnableAutoDepthStencil = TRUE;
- direct3DPresetParams.AutoDepthStencilFormat = D3DFMT_D16;
- captureDirectX->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, handleWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &direct3DPresetParams, &captureDevice);
- D3DXCreateFontA(captureDevice, 13, 0, FW_HEAVY, 1, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &captureFont);
- D3DXCreateLine(captureDevice, &captureLine);
- }
- void Gordy::GordyCircle(int X, int Y, int radius, int numSides, DWORD color) {
- D3DXVECTOR2 Line[128];
- float Step = PI * 2.0 / numSides;
- int Count = 0;
- for (float a = 0; a < PI*2.0; a += Step)
- {
- float X1 = radius * cos(a) + X;
- float Y1 = radius * sin(a) + Y;
- float X2 = radius * cos(a + Step) + X;
- float Y2 = radius * sin(a + Step) + Y;
- Line[Count].x = X1;
- Line[Count].y = Y1;
- Line[Count + 1].x = X2;
- Line[Count + 1].y = Y2;
- Count += 2;
- }
- captureLine->Draw(Line, Count, color);
- }
- void Gordy::GordyFillArea(float x, float y, float width, float height, D3DCOLOR color) {
- D3DXVECTOR2 vectorLine[2];
- captureLine->SetWidth(width);
- vectorLine[0].x = x + width / 2;
- vectorLine[0].y = y;
- vectorLine[1].x = x + width / 2;
- vectorLine[1].y = y + height;
- captureLine->Draw(vectorLine, 2, color);
- }
- void Gordy::GordyFillRect(double x, double y, double w, double h, D3DCOLOR color)
- {
- struct Vertex
- {
- float x, y, z, h;
- D3DCOLOR color;
- };
- Vertex vertices[4] =
- {
- x, y, 0.0f, 1.0f, color,
- x + w, y, 0.0f, 1.0f, color,
- x + w, y + h, 0.0f, 1.0f, color,
- x, y + h, 0.0f, 1.0f, color,
- };
- captureDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
- captureDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
- captureDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
- captureDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, vertices, sizeof(Vertex));
- }
- void Gordy::GordyBox(float x, float y, float width, float height, D3DCOLOR color) {
- D3DXVECTOR2 points[5];
- points[0] = D3DXVECTOR2(x, y);
- points[1] = D3DXVECTOR2(x + width, y);
- points[2] = D3DXVECTOR2(x + width, y + height);
- points[3] = D3DXVECTOR2(x, y + height);
- points[4] = D3DXVECTOR2(x, y);
- captureLine->SetWidth(1);
- captureLine->Draw(points, 5, color);
- }
- void Gordy::GordyString(int x, int y, DWORD color, LPD3DXFONT g_pFont, const char *fmt, ...)
- {
- char buf[1024] = { 0 };
- va_list va_alist;
- RECT FontPos = { x, y, x + 120, y + 16 };
- va_start(va_alist, fmt);
- vsprintf_s(buf, fmt, va_alist);
- va_end(va_alist);
- g_pFont->DrawTextA(NULL, buf, -1, &FontPos, DT_NOCLIP, color);
- }
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_PAINT:
- Global::gordy.GordyRender();
- break;
- case WM_CREATE:
- DwmExtendFrameIntoClientArea(hWnd, &Global::gordy.margins);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- std::string RandomOverlayString(int len)
- {
- srand(time(0));
- std::string str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- std::string newstr;
- int pos;
- while (newstr.size() != len) {
- pos = ((rand() % (str.size() - 1)));
- newstr += str.substr(pos, 1);
- }
- return newstr;
- }
- std::wstring s2wstr(const std::string& s)
- {
- int len;
- int slength = (int)s.length() + 1;
- len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
- wchar_t* buf = new wchar_t[len];
- MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
- std::wstring r(buf);
- delete[] buf;
- return r;
- }
- void Gordy::GordySetup() {
- RECT rect;
- while (!screenWindow) {
- screenWindow = FindWindow(NULL, "Rainbow Six");
- }
- if (screenWindow != NULL) {
- GetWindowRect(screenWindow, &rect);
- std::cout << captureWidth << "x" << captureHeight << std::endl;
- }
- else {
- std::cout << "Application exiting, error preapring the window. Error code: " << GetLastError() << std::endl;
- Sleep(3000);
- ExitProcess(0);
- }
- //WNDCLASSEX windowClass;
- //ZeroMemory(&windowClass, sizeof(WNDCLASSEX));
- //windowClass.cbSize = sizeof(WNDCLASSEX);
- //windowClass.style = CS_HREDRAW | CS_VREDRAW;
- //windowClass.lpfnWndProc = WindowProc;
- //windowClass.hInstance = GetModuleHandle(0);
- //windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
- //windowClass.hbrBackground = (HBRUSH)RGB(0, 0, 0);
- //windowClass.lpszClassName = overlayName;
- //RegisterClassEx(&windowindowClass);
- WNDCLASSEX windowClass;
- ZeroMemory(&windowClass, sizeof(WNDCLASSEX)); // Initialises, sets all bits to 0 to remove garbage data
- //std::string randomName = RandomOverlayString(10);
- //LPCSTR overlayName = s2wstr(randomName).c_str;
- windowClass.cbClsExtra = NULL;
- windowClass.cbWndExtra = NULL;
- windowClass.cbSize = sizeof(WNDCLASSEX);
- windowClass.style = CS_HREDRAW | CS_VREDRAW;
- windowClass.lpfnWndProc = WindowProc; // Function that will be executed when the window receives a "message" (input). Required! (crashes if set to NULL)
- windowClass.hInstance = NULL;
- windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
- windowClass.hIcon = LoadIcon(0, IDI_APPLICATION);
- windowClass.hIconSm = LoadIcon(0, IDI_APPLICATION);
- windowClass.hbrBackground = (HBRUSH)RGB(0, 0, 0);
- windowClass.lpszClassName = " "; // Class name to use with the Windows API function CreateWindow(Ex) to create the window
- windowClass.lpszMenuName = " ";
- RegisterClassEx(&windowClass);
- captureWindow = CreateWindowEx(NULL, " ", " ", WS_POPUP | WS_VISIBLE, 1, 1, captureWidth, captureHeight, NULL, NULL, NULL, NULL);
- MARGINS margin = { 1,1,captureWidth,captureHeight };
- DwmExtendFrameIntoClientArea(captureWindow, &margin);
- SetWindowLong(captureWindow, GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TRANSPARENT);
- //CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT, windowClass.lpszClassName, "aa", WS_POPUP, rect.left, rect.top, captureWidth, captureHeight, NULL, NULL, windowClass.hInstance, NULL);
- /*SetLayeredWindowAttributes(captureWindow, RGB(0, 0, 0), 0, ULW_COLORKEY);
- SetLayeredWindowAttributes(captureWindow, 0, 255, LWA_ALPHA);
- ShowWindow(captureWindow, SW_SHOW);*/
- GordyInit(captureWindow);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement