Results 1 to 14 of 14
  1. #1
    F4DE's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Location
    The Netherlands
    Posts
    158
    Reputation
    10
    Thanks
    973

    Can't seem to make threads / loops

    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;
    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);
    
    	}
    }
    Tried to use this in my render code, but it doesn't reconize anything;

    Code:
    	ThreadStart ^ t_AimBot = gcnew ThreadStart(&Aimbot);
    	Thread ^ AimBotThread = gcnew Thread(t_AimBot);
    	AimBotThread->Start();

  2. #2
    WasserEsser's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    735
    Reputation
    174
    Thanks
    677
    My Mood
    Busy
    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 )?

  3. #3
    F4DE's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Location
    The Netherlands
    Posts
    158
    Reputation
    10
    Thanks
    973
    Quote Originally Posted by WasserEsser View Post
    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 )?
    Had a function before that, but removed it later on.
    And the problem is, is that I don't know how to start the thread nor where to place it.

  4. #4
    WasserEsser's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    735
    Reputation
    174
    Thanks
    677
    My Mood
    Busy
    Quote Originally Posted by F4DE View Post
    Had a function before that, but removed it later on.
    And the problem is, is that I don't know how to start the thread nor where to place it.
    https://de.cppreference.com/w/cpp/thread/thread

    Start them above the while true loop as i said above.

  5. #5
    F4DE's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Location
    The Netherlands
    Posts
    158
    Reputation
    10
    Thanks
    973
    Quote Originally Posted by WasserEsser View Post
    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);
    
    
    		}

  6. #6
    WasserEsser's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    735
    Reputation
    174
    Thanks
    677
    My Mood
    Busy
    Quote Originally Posted by F4DE View Post
    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.

  7. The Following User Says Thank You to WasserEsser For This Useful Post:

    F4DE (07-16-2016)

  8. #7
    F4DE's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Location
    The Netherlands
    Posts
    158
    Reputation
    10
    Thanks
    973
    Quote Originally Posted by WasserEsser View Post
    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.
    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;'

  9. #8
    gtaplayer2's Avatar
    Join Date
    Aug 2013
    Gender
    male
    Location
    Dancing with my kawaii friend
    Posts
    588
    Reputation
    22
    Thanks
    1,984
    Quote Originally Posted by F4DE View Post
    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;'
    Check for invalid entities....

  10. #9
    F4DE's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Location
    The Netherlands
    Posts
    158
    Reputation
    10
    Thanks
    973
    Quote Originally Posted by gtaplayer2 View Post
    Check for invalid entities....
    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;

    Code:
                int entindex = ClosestEnemyToCrosshair(90.f);
    
                if (entindex == 0)
                    continue;
    Update: Using this code right now, but still get the same error.

    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.

  11. #10
    gtaplayer2's Avatar
    Join Date
    Aug 2013
    Gender
    male
    Location
    Dancing with my kawaii friend
    Posts
    588
    Reputation
    22
    Thanks
    1,984
    Quote Originally Posted by F4DE View Post
    Using this code right now, but still get the same error.

    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;
    }
    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.

  12. #11
    F4DE's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Location
    The Netherlands
    Posts
    158
    Reputation
    10
    Thanks
    973
    Quote Originally Posted by gtaplayer2 View Post
    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.
    Allright, did all that but still have the same problem / error ;l

  13. #12
    gtaplayer2's Avatar
    Join Date
    Aug 2013
    Gender
    male
    Location
    Dancing with my kawaii friend
    Posts
    588
    Reputation
    22
    Thanks
    1,984
    Quote Originally Posted by F4DE View Post
    Allright, did all that but still have the same problem / error ;l
    Maybe theres something wrong with your angle calcuation function then.

  14. #13
    F4DE's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Location
    The Netherlands
    Posts
    158
    Reputation
    10
    Thanks
    973
    Quote Originally Posted by gtaplayer2 View Post
    Maybe theres something wrong with your angle calcuation function then.
    Code:
    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;
    }
    Works fine in my other cheat ;l

  15. #14
    Hunter's Avatar
    Join Date
    Dec 2013
    Gender
    male
    Location
    Depths Of My Mind.
    Posts
    17,468
    Reputation
    3771
    Thanks
    6,159
    My Mood
    Cheerful
    1 week has passed and no further replies have been made by the OP. Assuming solved.

    /Closed.

Similar Threads

  1. [Solved] Can't seem to post new threads.
    By jordanwu in forum Suggestions, Requests & General Help
    Replies: 7
    Last Post: 07-29-2014, 09:42 AM
  2. Can you make threads/reply?
    By iToXiK in forum General
    Replies: 8
    Last Post: 11-01-2011, 06:09 AM
  3. Can sum1 help me make a trainer.
    By kingz07 in forum Suggestions, Requests & General Help
    Replies: 1
    Last Post: 06-23-2007, 03:49 AM
  4. Replies: 1
    Last Post: 07-05-2006, 06:20 AM
  5. hi can any1 help me make or find a cheat code
    By CrUsHa in forum WarRock - International Hacks
    Replies: 3
    Last Post: 05-19-2006, 04:39 PM