Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //overlay.cpp
- // ExternalOverlay.cpp : Defines the entry point for the application.
- //
- #include <Dwmapi.h>
- #include "framework.h"
- #include "ExternalOverlay.h"
- // Global Variables:
- HINSTANCE hInst; // current instance
- WCHAR overlayWindowName[100] = L"Overlay"; // main window class name & The title bar text
- LPCSTR targetWindowName = "Halo"; // main window class name & The title bar text
- HWND targetHWND, overlayHWND;
- int width, height;
- Paint paint;
- // Forward declarations of functions included in this code module:
- ATOM registerClass(HINSTANCE hInstance);
- BOOL InitInstance(HINSTANCE, int);
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- int APIENTRY wWinMain(_In_ HINSTANCE hInstance,_In_opt_ HINSTANCE hPrevInstance,_In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
- {
- UNREFERENCED_PARAMETER(hPrevInstance);
- UNREFERENCED_PARAMETER(lpCmdLine);
- registerClass(hInstance);
- targetHWND = FindWindowA(0, targetWindowName);
- if (targetHWND) {
- RECT rect;
- GetWindowRect(targetHWND, &rect);
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
- }
- else
- return FALSE;
- // Perform application initialization:
- if (!InitInstance(hInstance, SW_SHOW)){
- return FALSE;
- }
- paint = Paint(overlayHWND,targetHWND,width,height);
- MSG msg;
- // Main message loop:
- while (GetMessage(&msg, nullptr, 0, 0)){
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- RECT rect;
- GetWindowRect(targetHWND, &rect);
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
- MoveWindow(overlayHWND, rect.left, rect.top, width, height, true);
- }
- return (int) msg.wParam;
- }
- //
- // FUNCTION: MyRegisterClass()
- //
- // PURPOSE: Registers the window class.
- //
- ATOM registerClass(HINSTANCE hInstance)
- {
- WNDCLASSEXW wcex;
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = 0;
- wcex.hCursor = LoadCursor(nullptr, IDC_CROSS);
- wcex.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
- wcex.lpszMenuName = overlayWindowName;
- wcex.lpszClassName = overlayWindowName;
- wcex.hIconSm = 0;
- return RegisterClassExW(&wcex);
- }
- //
- // FUNCTION: InitInstance(HINSTANCE, int)
- //
- // PURPOSE: Saves instance handle and creates main window
- //
- // COMMENTS:
- //
- // In this function, we save the instance handle in a global variable and
- // create and display the main program window.
- //
- BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
- {
- hInst = hInstance; // Store instance handle in our global variable
- overlayHWND = CreateWindowExW(WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED, overlayWindowName, overlayWindowName, WS_POPUP,
- 1, 1, width, height, nullptr, nullptr, hInstance, nullptr);
- if (!overlayHWND){
- return FALSE;
- }
- SetLayeredWindowAttributes(overlayHWND, RGB(0, 0, 0), 0, LWA_COLORKEY);
- ShowWindow(overlayHWND, nCmdShow);
- return TRUE;
- }
- //
- // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
- //
- // PURPOSE: Processes messages for the main window.
- //
- // WM_COMMAND - process the application menu
- // WM_PAINT - Paint the main window
- // WM_DESTROY - post a quit message and return
- //
- //
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
- switch (message){
- case WM_PAINT:
- paint.render();
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
- //Paint.h
- #pragma once
- #include <string> //save error
- #include <Windows.h>
- #include <d3d9.h>
- #include <d3dx9.h>
- #pragma comment(lib, "d3d9.lib")
- #pragma comment(lib, "d3dx9.lib")
- #include <DxErr.h> //get error from error code
- #pragma comment(lib, "dxerr.lib")
- #pragma comment(lib, "legacy_stdio_definitions.lib")
- class Paint{
- private:
- IDirect3D9Ex* d3dObject = NULL; //used to create device
- IDirect3DDevice9Ex* d3dDevice = NULL; //contains functions like begin and end scene
- D3DPRESENT_PARAMETERS d3dparams; //parameters for creating device
- ID3DXFont* d3dFont = 0; // font used when displaying text
- HWND targetWnd;
- int width;
- int height;
- int d3D9Init(HWND hWnd);
- void drawText(char* String, int x, int y, int a, int r, int g, int b);
- public:
- Paint();
- Paint(HWND hWnd, HWND targetWnd, int width, int height);
- int render();
- };
- //Paint.cpp
- #include "Paint.h"
- int Paint::d3D9Init(HWND hWnd){
- if (FAILED(Direct3DCreate9Ex(D3D_SDK_VERSION, &d3dObject))){
- exit(1);
- }
- ZeroMemory(&d3dparams, sizeof(d3dparams));
- d3dparams.BackBufferWidth = width;
- d3dparams.BackBufferHeight = height;
- d3dparams.Windowed = TRUE;
- d3dparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
- d3dparams.hDeviceWindow = hWnd;
- d3dparams.MultiSampleQuality = D3DMULTISAMPLE_NONE;
- d3dparams.BackBufferFormat = D3DFMT_A8R8G8B8;
- d3dparams.EnableAutoDepthStencil = TRUE;
- d3dparams.AutoDepthStencilFormat = D3DFMT_D16;
- HRESULT res = d3dObject->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dparams, 0, &d3dDevice);
- if (FAILED(res)){
- std::wstring ws(DXGetErrorString(res));
- std::string str(ws.begin(), ws.end());
- std::wstring ws2(DXGetErrorDescription(res));
- std::string str2(ws2.begin(), ws2.end());
- std::string error = "Error: " + str + " error description: " + str2;
- exit(1);
- }
- D3DXCreateFont(d3dDevice, 50, 0, FW_BOLD, 1, false, DEFAULT_CHARSET, OUT_DEVICE_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH, L"Comic Sans", &d3dFont);
- return 0;
- }
- Paint::Paint() {};
- Paint::Paint(HWND hWnd, HWND targetWnd, int width, int height){
- this->width = width;
- this->height = height;
- this->targetWnd = targetWnd;
- d3D9Init(hWnd);
- }
- int Paint::render()
- {
- if (d3dDevice == nullptr)
- return 1;
- d3dDevice->Clear(0, 0, D3DCLEAR_TARGET, 0, 1.0f, 0);
- d3dDevice->BeginScene();
- if (targetWnd == GetForegroundWindow())
- {
- drawText((char*)"U got hacked broo", width / 10, height / 10, 255, 171, 0, 182);
- }
- d3dDevice->EndScene();
- d3dDevice->PresentEx(0, 0, 0, 0, 0);
- return 0;
- }
- void Paint::drawText(char* String, int x, int y, int a, int r, int g, int b)
- {
- RECT FontPos;
- FontPos.left = x;
- FontPos.top = y;
- d3dFont->DrawTextA(0, String, strlen(String), &FontPos, DT_NOCLIP, D3DCOLOR_ARGB(a, r, g, b));
- }
Add Comment
Please, Sign In to add comment