Author Topic: Cod4 aimbot tut  (Read 2441 times)

0 Members and 1 Guest are viewing this topic.

[TKC]cptnhankey

  • Online Villain
  • ***
  • Posts: 240
    • View Profile
    • Cptn Hankey
Cod4 aimbot tut
« on: October 10, 2008, 02:49:48 pm »
Hello i found this will googlin and thought this might help some ppl.  This is for Cod 4 Only i think.


The three main values you need to have and understand are:
1. lerporigin - vec3_t containing the position coordinates of the target
2. vieworg - vec3_t containing the position coordinates of you
3. refdefviewangles - vec3_t containing the displacement angle between your line of sight and the origin

For headshots only you need to do the following transformation of lerporigin.
Code:

float newlerp[3]={lerpOrigin[0] , lerpOrigin[1], lerpOrigin[2]+60.0f};

By adding 60 the 3rd value, the z-value, it moved the position of the lerporigin into the middle of the target's head. This will come in handy later when we do our PITCH calculations.

Now that we have the new lerporigin where we want it, it's time to begin calculation the two angles for our aim. The angles are YAW (side to side) and PITCH (up and down).

First figure out the YAW...
Code:

//********** YAW CALCULATIONS **********//
VectorSubtract(lerpOrigin,vieworg,vec);
distance=VectorLength(vec);
VectorAngles(vec,rot);
rot[1]=AngleNormalize180(rot[1]-refdefViewAngles[1]);
rot[0]=AngleNormalize180(rot[0]-refdefViewAngles[0]);
rot[2]=AngleNormalize180(rot[2]-refdefViewAngles[2]);

This block creates two new variables: vec & rot. "Vec" stores the differences in the (x,y,z) values of you and your target. "Rot" stores the angles between you and your target. To get the net angle between our line of sight and the enemy we subtract our refdefViewAngles from our rot angles. Since the maximum angle we want to aim left or right is 180 degrees we run our net angle through the AngleNormalize180 function.

From the "vec" variable we can extract vec[0] and vec[1] and assign them to a new variable called "screen".
Code:

screen[0]=-vec[1];
screen[1]=-vec[0];

float screen0=screen[0]-160.000f;
float screen1=screen[1]-1280.000f;

When I was testing I had "screen0" and "screen1" printed to the screen so I could see how they were changing in realtime as I moved around the target. I noticed that my coordinates seemed to be centered on a random point that was offset by (160,1280) on the coordinate system so I subtracted those values from "screen" to produce the values I wanted. Below are 4 screenshots of me testing in-game... they're there to help you picture exactly what the "screen0" and "screen1" values represent.
http://img204.imageshack.us/my.php?i...hot0105pi8.jpg
http://img529.imageshack.us/img529/2...0106qj8.th.jpg
http://img529.imageshack.us/img529/9...0107qs2.th.jpg
http://img46.imageshack.us/img46/191...0108qk8.th.jpg

Use the radar and the yellow box in the top left corner of each screenshot to familiarize yourself with the "screen" variable and to figure out exactly what it represents. If there is a negative sign where you don't think there should be one don't worry, they will be taken care of later on.

The next calculations are just simple trigonometry calculations to find the angle you need to aim at.
Code:

float delta_deg=57.29577951;
float hyp=sqrt((screen0*screen0)+(screen1*screen1));
float angle_x=-(asin(screen0/hyp))*delta_deg;

if(screen0>0 && screen1>0)  // quadrant D
   angle_x=-180.000f-angle_x;
else if(screen0<0 && screen1>0)  // quadrant C
   angle_x=180.000f-angle_x;
else if(screen0<0 && screen1<0)  // quadrant B
   angle_x=angle_x;
else if(screen0>0 && screen1<0)  // quadrant A
   angle_x=angle_x;

When inputting the angles for your aim they must be in degrees but when using trig functions in C++ they are calculated in radians. The variable "delta_deg" is used here as the conversion factor between radians and degrees. The exact value of the conversion factor is (180/PI)... here it has been solved and rounded off. By using the values of "screen" with the Pythagorean Theorem we get the magnitude of the direct line between you and your target. Based on where the target is located on the coordinate system we adjust the angles to aim at the correct quadrant. When looking at the radar the quadrants are labeled counter-clockwise starting with "A" and the top right.

And FINALLY... the YAW calculations are done. We are left with a variable, "angle_x", that is the angle we want to send the game.


Now for the PITCH calculations... (don't worry, this is much shorter)

Code:

//********** PITCH CALCULATIONS **********//
VectorSubtract(newlerp,vieworg,vec);
hyp2=sqrt((vec[0]*vec[0])+(vec[1]*vec[1])+(vec[2]*vec[2]));
angle2=(asin(vec[2]/hyp2))*(180/3.14159);

if(refdefViewAngles[0]>90.0f)
{
        refdefViewAngles[0]=(refdefViewAngles[0])-360.0f;
}

Again we start off by getting the difference vector between us and our target. Here is where the "newlerp" variable we created in the beginning comes into play. We run through the same basic trig calculations as we did above to get the angle between you and your target. Another weird thing I noticed while testing (again by printing values to the screen) is how the "refdefViewAngles[0]" value changes as you look up and down. I assumed that when I looked down the values go from 0 to -85 (only 85 b/c of the 5 degree blind spot above and below you) and when I looked up the values would go from 0 to +85. However, when you look up, the values go from 360 to 275. Below are 2 diagrams I created to try to explain this better. The red line simulates the "centerview" mark.
http://img528.imageshack.us/img528/1140/oldyz3.png
http://img401.imageshack.us/img401/9797/newuo7.png


The first image is what the normal game setup is. The second image is the new setup we created to make things easier. It helps keep things more uniform and less confusing.

After we have that completed we calculate the angle to send to the game by subtracting our new "refdefViewAngles[0]" from "angle2".
Code:

angle_y=-(angle2+refdefViewAngles[0]);

Now that we have the two target angles, angle_x and angle_y, it is time to aim! I had mine set up with a simple aimkey, left shift...
Code:

if(GetAsyncKeyState(VK_LSHIFT)&1)
{
   *AngleX += angle_x;
   *AngleY += angle_y;
      
}

And there you have it! A simple, yet effective method for head shots on your aimbot. This code is kind of long and drawn out, and it can surely be almost cut in half but I showed every detail here to make sure it made sense. Things to be added on to this code would be prediction, some kinda of visibilty check (obviously), and more vectors that would aim at players in various postions (ie. leaning, crouch, prone, etc.). This code will get 100% headshots ONLY when the target is standing!

MrMedic

  • MasstKer
  • ********
  • Posts: 8900
  • programmer/dev/software engineer
    • View Profile
Re: Cod4 aimbot tut
« Reply #1 on: October 10, 2008, 03:39:45 pm »
credits silencer  , hanky allways give credits :) , btw i helped him with the code , for some reason a lot of people get stuck with reversing the angles , its simple maths
EnCoded Message: i3iy9yl8kr2xf3g2Txs3pr6ye3ya7jg5ty2z

https://www.youtube.com/watch?v=62_7-AYfdkQ
you need a paypal account for the private versions.

Website:
http://bit.ly/medic101

Teamspeak 3: 85.236.101.5:10157

rarus

  • Intentional Cheater
  • **
  • Posts: 26
    • View Profile
Re: Cod4 aimbot tut
« Reply #2 on: October 10, 2008, 03:53:08 pm »
Yes, main problem for me find player data etc  :icon_laugh

Code of I am bot its not realy problem, u can get it from sources and modify  :icon_razz2

Baaljato

  • Intentional Cheater
  • **
  • Posts: 37
    • View Profile
Re: Cod4 aimbot tut
« Reply #3 on: October 10, 2008, 04:26:57 pm »
It would be good........ if i new c++.Im learning and maybe just maybe a maybe be able to do this lol

Rav3n

  • Klass Klown
  • ***
  • Posts: 419
    • View Profile
Re: Cod4 aimbot tut
« Reply #4 on: October 18, 2008, 12:49:05 am »
If i knew what this was it would be really useful for me...

As it is, i haven't a clue and never will i might copy paste it into notepad and put it in the recycle bin for fun  :icon_laugh

Free Rapidshare Prem Accounts
http://rapidshare dot com/files/111551586/Free-PremAccs.rar