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