😳 Drawing to an overlay
Hi guys, im new around here
Just trying to start out my hacking campaign by creating a simple esp for assault cube but i cannot figure out how to draw to my transparent overlay. Here is the code, thanks in advance:
Just trying to start out my hacking campaign by creating a simple esp for assault cube but i cannot figure out how to draw to my transparent overlay. Here is the code, thanks in advance: Code:
#include <iostream>
#include <windows.h>
#include <Dwmapi.h>
#include <TlHelp32.h>
#include <objidl.h>
#include <gdiplus.h>
#include "Offsets.h"
#pragma comment (lib,"Gdiplus.lib")
using namespace std;
/* Address Vars */
DWORD localPlayerAddress = 0x00509B74;
DWORD playerStrucPointer = 0x0050F4F8;
DWORD totalPlayers = 0x0050F500;
DWORD vMatrix = 0x00501AE8;
CONST DWORD EntityLoopDistance = 0x4;
int overlayPosX = 0;
int overlayPosY = 0;
int overlayWidth = 1920;
int overlayHeight = 1080;
HWND hwndOverlayWindow;
HANDLE handle;
int numberOfPlayers = 0;
RECT m_Rect;
void GamePaint(HDC hDC)
{
TextOut(hDC, 5 , 70, TEXT("Overlay Attached"), strlen("Overlay Attached"));
}
typedef struct {
float projMatrix[4][4];
}WorldToScreenMatrix_t;
struct localPlayer_t
{
DWORD pLocalAddress;
int health;
float pos[3];
WorldToScreenMatrix_t WorldToScreenMatrix;
void ReadPlayerInfo()
{
//Pointer to local player info
ReadProcessMemory(handle, (LPCVOID)localPlayerAddress, &pLocalAddress, sizeof(pLocalAddress), nullptr);
//Read player health
ReadProcessMemory(handle, (LPCVOID)(pLocalAddress + o_Health), &health, sizeof(health), nullptr);
//Fetch player pos
ReadProcessMemory(handle, (LPCVOID)(pLocalAddress + o_Pos), &pos, sizeof(float[3]), nullptr);
//Read View Matrix
ReadProcessMemory(handle, (LPCVOID)vMatrix, &WorldToScreenMatrix, sizeof(WorldToScreenMatrix), nullptr);
}
void WPM(int newVal, int changingOffset)
{
WriteProcessMemory(handle, (LPVOID)(pLocalAddress + changingOffset), &newVal, sizeof(newVal), nullptr);
}
}localPlayer;
struct OtherPlayers_t
{
DWORD pPlayerAddress;
DWORD botPointed;
int health;
float pos[3];
char name[16];
void ReadPlayerInfo(int Player)
{
//Pointer to local player info
ReadProcessMemory(handle, (LPCVOID)playerStrucPointer, &pPlayerAddress, sizeof(pPlayerAddress), nullptr);
ReadProcessMemory(handle, (LPCVOID*)(pPlayerAddress + (0x4 + (0x4 * Player))), &botPointed, sizeof(botPointed), nullptr);
//Read player health
ReadProcessMemory(handle, (LPCVOID)(botPointed + o_Health), &health, sizeof(health), nullptr);
//Fetch player pos
ReadProcessMemory(handle, (LPCVOID)(botPointed + o_Pos), &pos, sizeof(float[3]), nullptr);
//Fetch Name
ReadProcessMemory(handle, (WCHAR*)(botPointed + o_Name), &name, sizeof(name), nullptr);
}
}OtherPlayers[32];
LRESULT CALLBACK WndProc(_In_ HWND hWnd,
_In_ UINT Msg,
_In_ WPARAM wParam,
_In_ LPARAM lParam)
{
switch (Msg)
{
case WM_PAINT: {
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hWnd, &ps);
// Paint the Hacks
GamePaint(hDC);
EndPaint(hWnd, &ps);
}
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
void CreateOverlayWindow()
{
// External Overlay.
/* Registering Window Class for our overlay window
More help on MSDN (RegisterClassEx function): https://msdn.microsoft.com/en-us/library/windows/desktop/ms633587(v=vs.85).aspx */
// out windows proc.
WNDCLASSEX overlayWindowClass;
ZeroMemory(&overlayWindowClass, sizeof(WNDCLASSEX));
overlayWindowClass.cbClsExtra = NULL;
overlayWindowClass.cbWndExtra = NULL;
overlayWindowClass.cbSize = sizeof(WNDCLASSEX);
overlayWindowClass.style = CS_HREDRAW | CS_VREDRAW;
overlayWindowClass.lpfnWndProc = WndProc;
overlayWindowClass.hInstance = NULL;
overlayWindowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
overlayWindowClass.hIcon = LoadIcon(0, IDI_APPLICATION);
overlayWindowClass.hIconSm = LoadIcon(0, IDI_APPLICATION);
overlayWindowClass.hbrBackground = (HBRUSH)RGB(0, 0, 0);
overlayWindowClass.lpszClassName = L"H4x0r";
overlayWindowClass.lpszMenuName = L"H4x0r";
RegisterClassEx(&overlayWindowClass);
hwndOverlayWindow = CreateWindowEx(NULL,
L"H4x0r",
L"H4x0r",
WS_POPUP | WS_VISIBLE,
overlayPosX,
overlayPosY,
overlayWidth,
overlayHeight,
NULL,
NULL,
NULL,
NULL);
MARGINS margin = { 0, 0, 0, 0 };
DwmExtendFrameIntoClientArea(hwndOverlayWindow, &margin);
// No need to use WS_EX_TOPMOST since I replace the window on top periodically
SetWindowLong(hwndOverlayWindow, GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TRANSPARENT);
}
void UpdateOverlay(HWND TargetWindow)
{
// No top most overlay.
RECT r;
GetWindowRect(TargetWindow, &r);
SetWindowPos(hwndOverlayWindow, nullptr, r.left, r.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
SetWindowPos(hwndOverlayWindow, nullptr, 0, 0, r.right - r.left, r.bottom - r.top, SWP_NOMOVE | SWP_NOZORDER);
// Detect if game XX is active by using get Foregroundwindow.
if (TargetWindow == GetForegroundWindow())
{
ShowWindow(hwndOverlayWindow, SW_RESTORE);
SetWindowPos(hwndOverlayWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
SetWindowPos(hwndOverlayWindow, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
// NON TOPMOST MAGIC.
SetWindowPos(TargetWindow, hwndOverlayWindow, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
SendMessage(hwndOverlayWindow, WM_PAINT, 0, 0);
}
else
{
ShowWindow(hwndOverlayWindow, SW_HIDE);
}
}
bool WorldToScreen(float * from, float * to)
{
float w = 0.0f;
to[0] = localPlayer.WorldToScreenMatrix.projMatrix[0][0] * from[0] + localPlayer.WorldToScreenMatrix.projMatrix[0][1] * from[1] + localPlayer.WorldToScreenMatrix.projMatrix[0][2] * from[2] + localPlayer.WorldToScreenMatrix.projMatrix[0][3];
to[1] = localPlayer.WorldToScreenMatrix.projMatrix[1][0] * from[0] + localPlayer.WorldToScreenMatrix.projMatrix[1][1] * from[1] + localPlayer.WorldToScreenMatrix.projMatrix[1][2] * from[2] + localPlayer.WorldToScreenMatrix.projMatrix[1][3];
w = localPlayer.WorldToScreenMatrix.projMatrix[3][0] * from[0] + localPlayer.WorldToScreenMatrix.projMatrix[3][1] * from[1] + localPlayer.WorldToScreenMatrix.projMatrix[3][2] * from[2] + localPlayer.WorldToScreenMatrix.projMatrix[3][3];
if (w < 0.01f)
return false;
float invw = 1.0f / w;
to[0] *= invw;
to[1] *= invw;
int width = (int)(m_Rect.right - m_Rect.left);
int height = (int)(m_Rect.bottom - m_Rect.top);
float x = width / 2;
float y = height / 2;
x += 0.5 * to[0] * width + 0.5;
y -= 0.5 * to[1] * height + 0.5;
to[0] = x + m_Rect.left;
to[1] = y + m_Rect.top;
return true;
}
void ESP()
{
for (int i = 0; i < (numberOfPlayers - 1); i++)
{
OtherPlayers->ReadPlayerInfo(i);
if (OtherPlayers[i].health < 2) {
continue;
}
float EnemyXY[3];
if (WorldToScreen(OtherPlayers[i].pos, EnemyXY)) {
//ESP_DrawString(EnemyXY[0] - m_Rect.left, EnemyXY[1] - m_Rect.top, OtherPlayers[i].name);
}
/* Used for debug only
cout << "--------" << i << "--------" << endl;
cout << "Bot Name: " << OtherPlayers[i].name << endl;
cout << "Bot Health: " << OtherPlayers[i].health << endl;
cout << "X - Cord: " << OtherPlayers[i].pos[0] << endl;
cout << "Z - Cord: " << OtherPlayers[i].pos[1] << endl;
cout << "Y - Cord: " << OtherPlayers[i].pos[2] << endl;
cout << "-----------------" << endl;
cout << endl;
*/
}
}
int main() {
//Searches for the "AssaultCube" window
HWND hwnd = FindWindowA(NULL, "AssaultCube");
if (hwnd == NULL)
{
cout << "Cannot find window." << endl;
Sleep(20);
exit(-1);
}
else
{
//Fetches the proccess id through reference
DWORD procID;
GetWindowThreadProcessId(hwnd, &procID);
CreateOverlayWindow();
//If the window is found then create a handle and find the "Pointed" address
handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);
if (procID == NULL)
{
cout << "Cannot obtian process." << endl;
Sleep(20);
exit(-1);
}
else
{
GetWindowRect(FindWindowA(NULL, "AssaultCube"), &m_Rect);
for (;;)
{
localPlayer.ReadPlayerInfo();
UpdateOverlay(hwnd);
//Godmode, Infini Ammo and Armour
localPlayer.WPM(1000, o_Health);
localPlayer.WPM(20, o_MP5Ammo);
localPlayer.WPM(100, o_Armour);
ESP();
//Number of players in lobby
ReadProcessMemory(handle, (LPVOID)totalPlayers, &numberOfPlayers, sizeof(numberOfPlayers), nullptr);
Sleep(1);
}
}
}
return 0;
}
