B4M (06-21-2010),CoderNever (06-17-2010),Houston (06-22-2010),Melodia (06-17-2010),thekm1994 (06-18-2010)
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:
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, etcCode:while(not found pixel){ GetPixel(hdc, x,y(; if(pixel == found){ do{ movemouse(x,y); shoot(); } while ( pixel == found) } }
2. Coding our aimbot
So let's first have a look at the function that reads the color data from your screen which is:
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.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 }
For the handle I tend to use my desktop or passing a 'NULL'(in correct C++ '0')
Like this:
Passing the 'X' and 'Y' coordinates is even more easy, you can pass any integer and it will workCode:HDC hdc = GetDC(HWND_DESKTOP); //using desktop HDC hdc = GetDc(NULL); // null
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:
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.Code:HDC hdc = GetDC(HWND_DESKTOP); COLORREF pixel; //Declaring our pixel Pixel = GetPixel(hdc, 100, 125); // x = 100, y == 125
I prefer doing this with 2 'for' loops:
As you can see our basic color aimbot is alsmost finished. It works like this: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, 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:
2nd: The easy way: you can scan for only one color value by doing this:Code:int red = GetRValue(pixel); int green = GetGValue(pixel); int blue = GetBValue(pixel);
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:
Now the last part of our aimot: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){ } } }
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);And now you know that our basic aimbot is finnished:
mouse_event(MOUSEEVENTF_LEFTUP,x,y,0,0);
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:
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 beginsCode: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; }
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.
B4M (06-21-2010),CoderNever (06-17-2010),Houston (06-22-2010),Melodia (06-17-2010),thekm1994 (06-18-2010)
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.
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!
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:
Scan for every 2nd pixel hey that's a good idea!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; }
Did you got your color aimbot working? I mean, it really does work?
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)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; }
Ah we-a blaze the fyah, make it bun dem!
lalakijilp (06-21-2010)
Why not use:
Code:mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
i get alot of error when i use this code think you could help me please