You have to start your threads before you get to the while true loop used to handle messages and render your overlay.
Also, why if ( true )?
Hi,
I am using this code to start the DirectX overlay for my hack, but now I have no idea where to make threads to run things like Aimbot etc.
This is my main / starting code;
Tried to use this in my render code, but it doesn't reconize anything;Code:int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char * value = "Counter-Strike: Global Offensive"; RECT rc; if (true) { HWND newhwnd = FindWindow(NULL, value); if (newhwnd != NULL){ GetWindowRect(newhwnd, &rc); s_width = rc.right - rc.left; s_height = rc.bottom - rc.top; } else{ ExitProcess(0); } WNDCLASSEX wc; ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)RGB(0, 0, 0); wc.lpszClassName = "WindowClass"; RegisterClassEx(&wc); hWnd = CreateWindowEx(0, "WindowClass", "", WS_EX_TOPMOST | WS_POPUP, rc.left, rc.top, s_width, s_height, NULL, NULL, hInstance, NULL); SetWindowLong(hWnd, GWL_EXSTYLE, (int)GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED | WS_EX_TRANSPARENT); SetLayeredWindowAttributes(hWnd, RGB(0, 0, 0), 0, ULW_COLORKEY); SetLayeredWindowAttributes(hWnd, 0, 255, LWA_ALPHA); ShowWindow(hWnd, nCmdShow); initD3D(hWnd); MSG msg; ::SetWindowPos(FindWindow(NULL, value), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); while (TRUE) { ::SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); if (!FindWindow(NULL, value)) ExitProcess(0); render(); while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } if (msg.message == WM_QUIT) exit(0); } return msg.wParam; } else { exit(5); } }
Code:ThreadStart ^ t_AimBot = gcnew ThreadStart(&Aimbot); Thread ^ AimBotThread = gcnew Thread(t_AimBot); AimBotThread->Start();
You have to start your threads before you get to the while true loop used to handle messages and render your overlay.
Also, why if ( true )?
https://de.cppreference.com/w/cpp/thread/thread
Start them above the while true loop as i said above.
I've got this now, added std::thread t1(Aimbot); and t1.join(); above the while loop but now my menu doesn't open when I click on insert ;l
Code:std::thread t1(Aimbot); t1.join(); while (TRUE) { ::SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); if (!FindWindow(NULL, value)) ExitProcess(0); render(); while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } if (msg.message == WM_QUIT) exit(0); }
Look at what std::thread::join does. It blocks the execution of any further code until the thread has ended, which means that you have to place the join call after the while loop.
You're currently calling exit when the message WM_QUIT is being sent to your application, consider using break instead.
F4DE (07-16-2016)
Allright, got the thread stuff working now, thanks for that
Now, I am having the issue that when I actually enable the aimbot, I get this error:
Run-Time Check Failure #3 - The variable 'index' is being used without being initialized.
So, I changed the viariable 'int index;' to 'int index = 0;' but now my aimbot is always stuck to lock on at the ground for some reason..
In my other project, I use the same source code for the aimbot, but in there I get no error when using 'int index;'
Welp, that's not the problem because I use the same source on my other cheat and on there this doesn't happen.
Also, it does check that;
Update: Using this code right now, but still get the same error.Code:int entindex = ClosestEnemyToCrosshair(90.f); if (entindex == 0) continue;
Code:int ClosestEnemyToCrosshair(float maxfov) { int index; for (int i = 0; i < 64; i++) { DWORD LocalPlayer = Mem.Read <DWORD>(Client + 0x00A31504); DWORD entitybase = Mem.Read<DWORD>(Client + EntityList + (i * 0x10)); if (entitybase == LocalPlayer) continue; bool entitydormant = Mem.Read<bool>(entitybase + isDormant); if (entitydormant) continue; int entityteam = Mem.Read<int>(entitybase + m_iTeamNum); int LocalTeam = Mem.Read<int>(LocalPlayer + m_iTeamNum); if (entityteam == LocalTeam) continue; int entitylifestate = Mem.Read<byte>(entitybase + 0x25B); //is lifestate if (entitylifestate != 0) continue; DWORD Engine = Mem.Module("engine.dll"); DWORD clientstate = Mem.Read<DWORD>(Engine + clientState); Vec3 currentangles = Mem.Read<Vec3>(clientstate + viewAngle); Vec3 pos = BonePos(entitybase, 0x2698, aimbone); //bonematrix float entitydistance = GetFOV(currentangles, position, pos); if (entitydistance < maxfov) { maxfov = entitydistance; index = i; } } return index; }
Last edited by Hunter; 07-19-2016 at 11:01 AM. Reason: Updated.
First off you shouldn't read your localplayer everytime you read an entity, just do it before the loop. Same goes with your localteam variable.
Also, add another check to make sure that the team (of the entity) is either CT or T.
EDIT: Oh and don't read the viewangles in the loop either, do it before the loop.
Last edited by gtaplayer2; 07-17-2016 at 08:06 AM.
Works fine in my other cheat ;lCode:void CalcAngle(Vec3 src, Vec3 dst, Vec3 &angles) { Vec3 delta; delta.x = src.x - dst.x; delta.y = src.y - dst.y; delta.z = src.z - dst.z; double hyp = sqrt(delta.x * delta.x + delta.y * delta.y); angles.x = (float)(atan(delta.z / hyp) * 57.295779513082f); angles.y = (float)(atan(delta.y / delta.x) * 57.295779513082f); angles.z = 0.0f; if (delta.x >= 0.0) angles.y += 180.0f; }
1 week has passed and no further replies have been made by the OP. Assuming solved.
/Closed.