Results 1 to 12 of 12
  1. #1
    schim's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    My chair
    Posts
    367
    Reputation
    10
    Thanks
    114
    My Mood
    Twisted

    Post [TUT] How to create a crude color aimbot

    Ok, hi every one
    A while ago I took a shot at making an aimbot for the game Combat Arms. (No it did not work)
    It does work for internet games and stuff like that

    1. Explanation/Pseudo code

    The aimbot works by searching all the pixels on the screen for hardcoded colors. Once the bot has found one you can use your imagination to think up what's next ;P

    Here's what we want to aimbot the do right now:

    Code:
    while(not found pixel){
    GetPixel(hdc, x,y(;
    if(pixel == found){
    do{
    movemouse(x,y);
    shoot();
    } while ( pixel == found)
    }
    }
    As you can see we need to aimbot to scan the screen for a certain color and if it finds this color it will need a function that will make it shoot, aim, etc, etc

    2. Coding our aimbot

    So let's first have a look at the function that reads the color data from your screen which is:
    Code:
     
    COLORREF pixel = GetPixel{    //you save pixels in a COLORREF, I think this name
     HDC hdc,                         // is self explanatory
       int nXPos,                    // your hdc stands for HandleDiviceContext whatever that means :O
       int nYPos                    //X / Y are self explaination
    }
    It's clear that when looking to the prototype we need to pass a handle an 'X' and a 'Y' coordinate and a buffer to store the pixel information in.

    For the handle I tend to use my desktop or passing a 'NULL'(in correct C++ '0')
    Like this:
    Code:
    HDC hdc = GetDC(HWND_DESKTOP);  //using desktop
    HDC hdc = GetDc(NULL); // null
    Passing the 'X' and 'Y' coordinates is even more easy, you can pass any integer and it will work

    As for the identifier 'pixel' it receives the information about the color of your pixel

    So now for our Scan pixel function we have this:

    Code:
    HDC hdc = GetDC(HWND_DESKTOP);
    COLORREF pixel;  //Declaring our pixel
    Pixel = GetPixel(hdc, 100, 125);  // x = 100, y == 125
    This little piece of code does nothing more then scanning the pixel at (100,125) and we want our scanner to scan the whole screen.

    I prefer doing this with 2 'for' loops:

    Code:
    HDC hdc = GetDC(HWND_DESKTOP);
    COLORREF pixel;  //Declaring our pixel
    
    for (int y = 0; y < 1200; y++){   //scans Y values (vertical)
    for (int x = 0; x < 1200; x++){   // scans X (horizantal)
    Pixel = GetPixel(hdc, x, y);
    }
    }
    As you can see our basic color aimbot is alsmost finished. It works like this:
    As you can see, it first scans all X coordinates firs and then moves on to the next Y coordinate

    Now the only thing left to do is checking if a pixel has a specific color
    There are two ways to do this.

    1st: the long way: you can pass a given pixel into the function GetRValue(pixel) (or GValue or BValue) Using this way of extracting colors from your pixel enables you to scan for more sorts of colors since you can pack them in an if state ment like this:
    if(red > 250 && (green + blue) < 100)
    like this:

    Code:
    int red = GetRValue(pixel);
    int green = GetGValue(pixel);
    int blue = GetBValue(pixel);
    2nd: The easy way: you can scan for only one color value by doing this:
    if(pixel ==(rgb(255,100,100))
    I highly recommend the first way to scan your pixels, as you can see the Second way wil only produce a hit if all three color values are exact the same
    Which is a total of 255^3 = 16.581.375 different types of colors to scan!

    Our Program now looks like this:

    Code:
    HDC hdc = GetDC(HWND_DESKTOP);
    COLORREF pixel;  //Declaring our pixel
    int r,g,b;
    for (int y = 0; y < 1200; y++){   //scans Y values (vertical)
    for (int x = 0; x < 1200; x++){   // scans X (horizantal)
    Pixel = GetPixel(hdc, x, y);
    r = GetRValue(pixel);
    g = GetGValue(pixel);
    b = GetBValue(pixel);
    if(r > 250 && (g + b) < 100){
    
    }
    }
    }
    Now the last part of our aimot:
    The aiming and shooting/clicking part

    This is the hardest or easiest part of this tutorial it depends on what method you chose

    We start with the easy part:

    Setting the cursor position in C++ doesn't have to be hard and simulating a mous down/up is almost as easy. You use the functions:
    SetCursorPos(x,y);
    and
    mouse_event(MOUSEEVENTF_LEFTDOWN,x,y,0,0);
    mouse_event(MOUSEEVENTF_LEFTUP,x,y,0,0);
    And now you know that our basic aimbot is finnished:

    Code:
    #include <windows.h>
    int main(){
    HDC hdc = GetDC(HWND_DESKTOP);
    COLORREF pixel;  //Declaring our pixel
    int r,g,b;
    for (int y = 0; y < 1200; y++){   //scans Y values (vertical)
    for (int x = 0; x < 1200; x++){   // scans X (horizantal)
    Pixel = GetPixel(hdc, x, y);
    r = GetRValue(pixel);
    g = GetGValue(pixel);
    b = GetBValue(pixel);
    if(r > 250 && (g + b) < 100){
    SetCursorPos(x,y);
    mouse_event(MOUSEEVENTF_LEFTDOWN,x,y,0,0);
    mouse_event(MOUSEEVENTF_LEFTUP,x,y,0,0);
    }
    }
    }
    }

    As for the hard part:

    Now as you may or maynot know, not every game accepts SetCursorPos();
    I came accros this problem and found the solution in this piece of code written by foolpanda:

    Code:
    int mousemove(int x,int y){
    
    	int ix,iy;
    ix=GetSystemMetrics(SM_CXSCREEN);
    iy=GetSystemMetrics(SM_CYSCREEN);
    INPUT *buffer = new INPUT[3]; //allocate a buffer
    buffer->type = INPUT_MOUSE;
    buffer->mi.dx = x*65535/ix;
    buffer->mi.dy = y*65535/iy;
    buffer->mi.mouseData = 0;
    buffer->mi.dwFlags = (MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE);
    buffer->mi.time = 0;
    buffer->mi.dwExtraInfo = 0;
     
    (buffer+1)->type = INPUT_MOUSE;
    (buffer+1)->mi.dx = 100;
    (buffer+1)->mi.dy = 100;
    (buffer+1)->mi.mouseData = 0;
    (buffer+1)->mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
    (buffer+1)->mi.time = 0;
    (buffer+1)->mi.dwExtraInfo = 0;
     
    (buffer+2)->type = INPUT_MOUSE;
    (buffer+2)->mi.dx = 100;
    (buffer+2)->mi.dy = 100;
    (buffer+2)->mi.mouseData = 0;
    (buffer+2)->mi.dwFlags = MOUSEEVENTF_LEFTUP;
    (buffer+2)->mi.time = 0;
    (buffer+2)->mi.dwExtraInfo = 0;
    SendInput(3,buffer,sizeof(INPUT));
    
    delete (buffer);
    return 0;
    }
    Since I don't understand this code completely I can't give you any explaination if you, you can you pass your x + y cords into this function and then the magic begins

    Credits:
    You may distribute and modify, claim it as your own and even print the code and use it as toilet paper, without providing any credits.
    However, I do want credits for the tutorial which I have made myself:
    you may not:
    shit on it, use it as toiletpaper, claim is as your own, modify or any other thing without giving me credits and/or mentioning me as the creator of this tutorial
    As for the last part: as I already said foolpanda coded it

    I hope you liked it
    -SCHiM, iANDi
    Last edited by schim; 06-17-2010 at 09:46 PM.

  2. The Following 5 Users Say Thank You to schim For This Useful Post:

    B4M (06-21-2010),CoderNever (06-17-2010),Houston (06-22-2010),Melodia (06-17-2010),thekm1994 (06-18-2010)

  3. #2
    lalakijilp's Avatar
    Join Date
    Jan 2008
    Gender
    male
    Posts
    310
    Reputation
    9
    Thanks
    53
    My Mood
    Blah
    hey nice tut.

    it is more efficient if you search the area around the previous location of the colour first, this saves a lot of time.

    this is only efficient when finding a moving object



    I will try to make it when I feel like it

    probably this weekend.
    Last edited by lalakijilp; 06-17-2010 at 11:50 PM.

  4. #3
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    You can also increase speed by multithreading your scans, or scanning only every 2nd pixel(or both for massive speed increases)
    Ah we-a blaze the fyah, make it bun dem!

  5. #4
    lalakijilp's Avatar
    Join Date
    Jan 2008
    Gender
    male
    Posts
    310
    Reputation
    9
    Thanks
    53
    My Mood
    Blah
    Quote Originally Posted by Hell_Demon View Post
    You can also increase speed by multithreading your scans, or scanning only every 2nd pixel(or both for massive speed increases)
    multi threading? /

    can you explain that more.

  6. #5
    schim's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    My chair
    Posts
    367
    Reputation
    10
    Thanks
    114
    My Mood
    Twisted
    I know I know, I did both things you two mentioned already but that wasnt the scope of the tutorial, my Full code looks like this:

    Code:
    #include <windows.h>
    #define WIN32_LEAN_AND_MEAN 
    #define _WIN32_WINNT 0x0500 
    using namespace std;
    BOOL Lost = true;
    BOOL Tracking = false;
    void Trackerscan(int x, int y);
    void scan(void);
    void scan2(void);
    void scan3(void);
    void scan4(void);
    void tracking1(int x, int y);
    int gx = 0;
    int gy = 0;
    int mousemove(int x,int y);
    
    int main{
    	MessageBox(0,"Press OK to start aimbot","SCHiM",0);
    	Sleep(2000);
    	CreateThread(0, 0, (LPTHREAD_START_ROUTINE)scan, 0, 0, 0);
    	CreateThread(0, 0, (LPTHREAD_START_ROUTINE)scan2, 0, 0, 0);
    	CreateThread(0, 0, (LPTHREAD_START_ROUTINE)scan3, 0, 0, 0);
    	CreateThread(0, 0, (LPTHREAD_START_ROUTINE)scan4, 0, 0, 0);
       	Sleep(1000000);
    }
    
    void scan(){
    int x,y,aim;
    		while(Tracking == false){
    
    		HDC hdc = GetDC(HWND_DESKTOP);
    		COLORREF pixel;
    		int r,g,b,mr;
    	for( y = 0; y < 1000 ; y++){
    		
    		if(Tracking == true){
    				break;
    				}
    				for( x = 0; x < 200; x++){
    					
    					pixel = GetPixel(hdc, x, y);
    				r =	GetRValue(pixel);
    				g =	GetGValue(pixel);
    				b =	GetBValue(pixel);
    				
    					if( r > 250 && (g + b) < 90 )  {
    					//SetCursorPos(x,y);
    					Tracking = true;
    					Lost = false;
    					tracking1(x,y);
    					break;
    					}
    			}
    			Sleep(1);
    		}
    		Sleep(1);
    	} 
    }
    
    void scan2(){
    	int x,y,aim;
    	int r,g,b;
    	while(Tracking == false){
    
    		HDC hdc = GetDC(HWND_DESKTOP);
    		COLORREF pixel;
    		
    			for( y = 0; y < 1000 ; y++){
    			if(Tracking == true){
    				break;
    				}			
    			for( x = 200; x < 400; x++){
    						
    				pixel = GetPixel(hdc, x, y);
    						r =	GetRValue(pixel);
    				g =	GetGValue(pixel);
    				b =	GetBValue(pixel);
    
    					if( r > 250 && (g + b) < 90 )  {
    					//SetCursorPos(x,y);
    					Sleep(5);
    					Tracking = true;
    					Lost = false;
    					tracking1(x,y);
    					break;
    						}
    			}
    			Sleep(1);
    		}
    		Sleep(1);
    	} 
    }
    
    void scan3(){
    	int x,y,aim;
    	int r,g,b;
    			while(Tracking == false){
    
    		HDC hdc = GetDC(HWND_DESKTOP);
    		COLORREF pixel;
    		
    			for( y = 0; y < 1000 ; y++){
    			if(Tracking){
    				break;
    				}
    			for( x = 400; x < 600; x++){
    							pixel = GetPixel(hdc, x, y);
    										r =	GetRValue(pixel);
    				g =	GetGValue(pixel);
    				b =	GetBValue(pixel);
    
    				if( r > 250 && (g + b) < 90 )  {
    					//SetCursorPos(x,y);
    					Sleep(5);
    					Tracking = true;
    					Lost = false;
    					tracking1(x,y);
    					break;
    				}
    			}
    			Sleep(1);
    		}
    		Sleep(1);
    	}
    }
    
    void scan4(){
    	int x,y,aim;
    	int r,g,b;
    			while(Tracking == false){
    
    		HDC hdc = GetDC(HWND_DESKTOP);
    		COLORREF pixel;
    		
    			for( y = 0; y < 1000 ; y++){
    			if(Tracking){
    				break;
    				}
    			for( x = 600; x < 800; x++){
    							pixel = GetPixel(hdc, x, y);
    										r =	GetRValue(pixel);
    				g =	GetGValue(pixel);
    				b =	GetBValue(pixel);
    
    					if( r > 250 && (g + b) < 90 )  {
    					//SetCursorPos(x,y);
    					Sleep(5);
    					Tracking = true;
    					Lost = false;
    					tracking1(x,y);
    					break;
    				}
    			}
    			Sleep(1);
    		}
    		Sleep(1);
    	}
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    void tracking1(int x, int y){
    Trackerscan(x,y);
    	while(Lost != true && Tracking != false){
    	mousemove(gx,gy);	
    	Trackerscan(gx, gy);
    	}
    }
    
    void Trackerscan(int x, int y){
    int ya = 0;
    int xa = 0;
    int r,g,b;
    HDC hdc = GetDC(HWND_DESKTOP);
    		COLORREF pixel;
    BOOL done = false;
    	for(ya = (y-100) ; ya < (y + 100); ya++){
    	for(xa = (x-100); xa < (x + 100); xa++)
    	{
    pixel = GetPixel(hdc,xa,ya);
    				r =	GetRValue(pixel);
    				g =	GetGValue(pixel);
    				b =	GetBValue(pixel);
    				
    					if(r == 255 && (g + b) < 90 )  {
    		gx = xa;
    		gy = ya;
    		mousemove(gx,gy);
    		done = true;
    		}
    
    	}
    	}
    	if(done != true){
    	Lost = true;
    	Tracking = false;
    	}
    
    
    }
    
    int mousemove(int x,int y){
    
    	int ix,iy;
    ix=GetSystemMetrics(SM_CXSCREEN);
    iy=GetSystemMetrics(SM_CYSCREEN);
    INPUT *buffer = new INPUT[3]; //allocate a buffer
    buffer->type = INPUT_MOUSE;
    buffer->mi.dx = x*65535/ix;
    buffer->mi.dy = y*65535/iy;
    buffer->mi.mouseData = 0;
    buffer->mi.dwFlags = (MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE);
    buffer->mi.time = 0;
    buffer->mi.dwExtraInfo = 0;
     
    (buffer+1)->type = INPUT_MOUSE;
    (buffer+1)->mi.dx = 100;
    (buffer+1)->mi.dy = 100;
    (buffer+1)->mi.mouseData = 0;
    (buffer+1)->mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
    (buffer+1)->mi.time = 0;
    (buffer+1)->mi.dwExtraInfo = 0;
     
    (buffer+2)->type = INPUT_MOUSE;
    (buffer+2)->mi.dx = 100;
    (buffer+2)->mi.dy = 100;
    (buffer+2)->mi.mouseData = 0;
    (buffer+2)->mi.dwFlags = MOUSEEVENTF_LEFTUP;
    (buffer+2)->mi.time = 0;
    (buffer+2)->mi.dwExtraInfo = 0;
    SendInput(3,buffer,sizeof(INPUT));
    
    delete (buffer);
    return 0;
    }
    Scan for every 2nd pixel hey that's a good idea!

  7. The Following 2 Users Say Thank You to schim For This Useful Post:

    thekm1994 (06-18-2010),zesu08 (06-18-2010)

  8. #6
    ngh555's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Posts
    126
    Reputation
    14
    Thanks
    58
    My Mood
    Devilish
    Did you got your color aimbot working? I mean, it really does work?

  9. #7
    schim's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    My chair
    Posts
    367
    Reputation
    10
    Thanks
    114
    My Mood
    Twisted
    Quote Originally Posted by ngh555 View Post
    Did you got your color aimbot working? I mean, it really does work?
    Yes it does work, but the problem is it's to slow :O Most of the time(always) you have already been killed
    Or your target has already left your line of sight, so it isn't usefull in 'real' games, you can however use this in E.G a game of pong

  10. #8
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Quote Originally Posted by lalakijilp View Post
    multi threading? /

    can you explain that more.
    Code:
    void scanThread1(void)
    {
        while(1)
        {
            for(int x=...)
            {
               ......
            }
        }
    }
    
    void scanThread2(void)
    {
        while(1)
        {
            for(int x=...)
            {
               ......
            }
        }
    }
    
    int main()
    {
        CreateThread(0,0,(LPTHREAD_START_ROUTINE)scanThread1,0,0,0);
        CreateThread(0,0,(LPTHREAD_START_ROUTINE)scanThread2,0,0,0);
        return 1;
    }
    Now you have two threads both scanning a seperate part of the screen, so you get twice the speed without losing acurary, if you only scan every 2nd pixel in each thread you get 4x the speed(4 threads for 4 parts skipping 1 pixel each you get 8x speed gain ;P)
    Ah we-a blaze the fyah, make it bun dem!

  11. The Following User Says Thank You to Hell_Demon For This Useful Post:

    lalakijilp (06-21-2010)

  12. #9
    Disturbed's Avatar
    Join Date
    Feb 2009
    Gender
    male
    Posts
    10,472
    Reputation
    1267
    Thanks
    2,587
    Why not use:

    Code:
        mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);


  13. #10
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Quote Originally Posted by ObamaBinLaden View Post
    Why not use:

    Code:
        mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    The OP's method is better
    Ah we-a blaze the fyah, make it bun dem!

  14. #11
    kaziboy's Avatar
    Join Date
    Jun 2008
    Gender
    male
    Location
    quebec
    Posts
    11
    Reputation
    10
    Thanks
    0
    My Mood
    Angelic
    i get alot of error when i use this code think you could help me please

  15. #12
    schim's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    My chair
    Posts
    367
    Reputation
    10
    Thanks
    114
    My Mood
    Twisted
    Quote Originally Posted by kaziboy View Post
    i get alot of error when i use this code think you could help me please
    I can't help you if you don't post the errors, so post your: errors and your compiler

Similar Threads

  1. [TUT] How to use Fore/Back Color [TUT]
    By mizzer3 in forum Visual Basic Programming
    Replies: 9
    Last Post: 04-29-2010, 07:42 PM
  2. Create a tut how to get injectors workin on win7
    By elletheking in forum Programming Tutorial Requests
    Replies: 2
    Last Post: 12-15-2009, 11:07 AM
  3. [TUT] How to set ddd555 Aimbot if you don't have chams!
    By joi121 in forum Combat Arms Europe Hacks
    Replies: 30
    Last Post: 07-10-2009, 06:00 AM
  4. [QUESTION] Can someone please post a Tut on how to Create a Maplestory Private Server
    By kevi3434 in forum MapleStory Hacks, Cheats & Trainers
    Replies: 0
    Last Post: 09-06-2008, 06:09 PM
  5. (TuT)How to create red dot (crosshair)
    By w00t? in forum Visual Basic Programming
    Replies: 10
    Last Post: 10-28-2007, 06:40 AM