Advertisement
captmicro

CLaimbot.h - sauerbraten aimbot

Nov 8th, 2012
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.54 KB | None | 0 0
  1. #include "game.h"
  2.  
  3. #define TerHax_MaxTargets 8
  4.  
  5. typedef dynent* (*cla_iscl)(const vec &from,const vec &to,fpsent *at,float &dist);
  6.  
  7. typedef struct { float x, y, z; } TerHax_Pos;
  8. typedef struct { float p, y, r; } TerHax_Ang;
  9. typedef struct { TerHax_Pos pos; bool alive; } TerHax_Obj;
  10.  
  11. class TerroristHax
  12. {
  13. private:
  14.     bool ena_aimbot;
  15.     bool ena_triggerbot;
  16.     bool has_lock;
  17.     float max_dist;
  18.  
  19.     fpsent *source;
  20.     fpsent *target;
  21.     TerHax_Ang ang2trgt;
  22.  
  23. public:
  24.     TerroristHax()
  25.     {
  26.         printf("[$$$] TerroristHax ::: Initalizing\n");
  27.         ena_aimbot = true;
  28.         ena_triggerbot = true;
  29.         has_lock = false;
  30.         max_dist = 5000.0f;
  31.         source = 0;
  32.         target = 0;
  33.         memset(&ang2trgt, 0, sizeof(TerHax_Ang));
  34.     }
  35.  
  36.     void printstuff()
  37.     {
  38.         static bool initd = false;
  39.         static bool aim;
  40.         static bool trig;
  41.         static float dist;
  42.  
  43.         if (!initd)
  44.         {
  45.             initd = true;
  46.             aim = false;
  47.             trig = false;
  48.             dist = 0.0f;
  49.         }
  50.        
  51.         if (ena_aimbot != aim) {
  52.             printf("[$$$] TerroristHax :: Aimbot %s\n", ena_aimbot?"enabled":"disabled");
  53.             aim = ena_aimbot;
  54.         }
  55.         if (ena_triggerbot != trig) {
  56.             printf("[$$$] TerroristHax :: Triggerbot %s\n", ena_aimbot?"enabled":"disabled");
  57.             trig = ena_triggerbot;
  58.         }
  59.         if (max_dist != dist) {
  60.             printf("[$$$] TerroristHax :: Max Dist = %f\n", max_dist);
  61.             dist = max_dist;
  62.         }
  63.     }
  64.  
  65.     ~TerroristHax()
  66.     {
  67.         printf("[$$$] TerroristHax ::: DeInitalizing\n");
  68.     }
  69.  
  70.     bool PosVis(TerHax_Pos *from, TerHax_Pos *to)
  71.     {
  72.         vec vecFrom, vecTo, vecHit;
  73.         vecFrom.x = from->x;
  74.         vecFrom.y = from->y;
  75.         vecFrom.z = from->z;
  76.         vecTo.x = to->x;
  77.         vecTo.y = to->y;
  78.         vecTo.z = to->z;
  79.         return raycubelos(vecFrom, vecTo, vecHit);
  80.     }
  81.  
  82.     bool TriggerBotAttack(cla_iscl iscl, float isdist, fpsent *ply)
  83.     {
  84.         if (!ena_triggerbot) return false;
  85.        
  86.         dynent *o = iscl(ply->o, worldpos, ply, isdist);
  87.         fpsent *e = (fpsent*)o; vec vecHitpos;
  88.         if (!o || o->type != ENT_PLAYER) return false;
  89.         if (strcmp(ply->team, e->team) == 0) return false;
  90.         if (o->state == CS_DEAD) return false;
  91.         if (!raycubelos(ply->headpos(), e->headpos(), vecHitpos)) return false;
  92.         return true;
  93.     }
  94.  
  95.     void SelectTarget(fpsent *hudply, vector <fpsent*> players)
  96.     {
  97.         if (!ena_aimbot) return;
  98.  
  99.         if (!has_lock)
  100.         {
  101.             int i = 0; vec vecHitpos;
  102.             float t = max_dist, dX, dY, dZ, dist;
  103.             for (i = 0; i < players.length(); i++)
  104.             {
  105.                 if (players[i]->state != CS_ALIVE) continue;
  106.                 if (!raycubelos(hudply->headpos(), players[i]->headpos(), vecHitpos)) continue;
  107.  
  108.                 vec head0 = players[i]->headpos();
  109.                 vec head1 = hudply->headpos();
  110.                 dX = head0.x - head1.x;
  111.                 dY = head0.y - head1.y;
  112.                 dZ = head0.z - head1.z;
  113.                 dist = sqrt((dX*dX) + (dY*dY) + (dZ*dZ));
  114.  
  115.                 if (dist < t)
  116.                 {
  117.                     target = players[i];
  118.                     source = hudply;
  119.                     printf("target: clientnum %d dist %f\n", target->clientnum, dist);
  120.                     has_lock = true;
  121.                     t = dist;
  122.                 }
  123.             }
  124.         }
  125.         else
  126.         {
  127.             vec vecHitpos;
  128.             if (target->state != CS_ALIVE) has_lock = false;
  129.             if (!raycubelos(source->headpos(), target->headpos(), vecHitpos)) has_lock = false;
  130.         }
  131.     }
  132.  
  133.     TerHax_Ang* Ang2Target()
  134.     {
  135.         if (!ena_aimbot) return 0;
  136.  
  137.         if (has_lock && target)
  138.         {
  139.             vec head0 = target->headpos();
  140.             vec head1 = source->headpos();
  141.             float dX = head0.x - head1.x;
  142.             float dY = head0.y - head1.y;
  143.             float dZ = head0.z - head1.z;
  144.             float dist = sqrt((dX*dX) + (dY*dY) + (dZ*dZ));
  145.             ang2trgt.p = asin(dZ / dist) / RAD;
  146.             ang2trgt.y = -(float)atan2(dX, dY) / PI * 180.0f;
  147.             printf("has_lock. ang (%f, %f, 0)\n", ang2trgt.p, ang2trgt.y);
  148.             ang2trgt.r = 0.0f;
  149.             return &ang2trgt;
  150.         }
  151.  
  152.         return 0;
  153.     }
  154. };
  155. TerroristHax terroristhax;
  156.  
  157. class CLaimbot
  158. {
  159. private:
  160.     bool triggerbot;
  161.     fpsent *local;
  162.     fpsent *target;
  163.     float ann_0; //enemy dist / 5000
  164.     float ann_1; //attacking you
  165.     float ann_2; //health / maxhealth
  166.     float ann_3; //armor / maxarmor
  167.     float ann_4; //clip / maxclip
  168.     PVOID annptrs[5];
  169.  
  170. public:
  171.     CLaimbot()
  172.     {
  173.         triggerbot = true;
  174.         local = 0;
  175.         target = 0;
  176.         printf("***** Initalized CLaimbot *****\n");
  177.         ann_0 = 1.0f; ann_1 = 1.0f;
  178.         ann_2 = 0.5f; ann_3 = 0.5f;
  179.         ann_4 = 0.5f;
  180.         annptrs[0] = &ann_0;
  181.         annptrs[1] = &ann_1;
  182.         annptrs[2] = &ann_2;
  183.         annptrs[3] = &ann_3;
  184.         annptrs[4] = &ann_4;
  185.         printf("***** CLaimbot annptrs @ 0x%08X *****\n", (DWORD)&annptrs[0]);
  186.     }
  187.  
  188.     ~CLaimbot()
  189.     {
  190.         printf("***** DeInitalized CLaimbot *****\n");
  191.     }
  192.  
  193.     bool FindBestTarget(cla_iscl iscl, float isdist, fpsent *ply, vector<fpsent*> players)
  194.     {
  195.         bool attack = false;
  196.         vec vecHitpos;
  197.         local = ply;
  198.  
  199.         /*if (local->attacking && !local->k_up) local->k_up = true;
  200.         else if (!local->attacking && local->k_up) local->k_up = false;*/
  201.  
  202.         float maxDist = 99999999;
  203.         loopv(players)
  204.         {
  205.             if (strcmp(players[i]->team, local->team) == 0)
  206.                 continue;
  207.             if (players[i]->state == CS_DEAD)
  208.                 continue;
  209.             if (!raycubelos(local->headpos(), players[i]->headpos(), vecHitpos))
  210.                 continue;
  211.             float dist = local->o.dist(players[i]->o);
  212.             if (triggerbot)
  213.             {
  214.                 dynent *o = iscl(local->o, worldpos, local, isdist);
  215.                 if (o && o->type == ENT_PLAYER) attack = true;
  216.             }
  217.  
  218.             ann_0 = dist / 5000.0f;
  219.             if (ann_0 > 1.0f) ann_0 = 1.0f;
  220.             if (ann_0 < 0.0f) ann_0 = 0.0f;
  221.             ann_1 = 0.0f;
  222.             if (players[i]->attacking)
  223.             {
  224.                 dynent *o = iscl(players[i]->o, worldpos, players[i], isdist);
  225.                 if (o && o->type == ENT_PLAYER)
  226.                 {
  227.                     vec *hp0 = &o->headpos();
  228.                     vec *hp1 = &local->headpos();
  229.                     if ((hp0->x == hp1->x) && (hp0->y == hp1->y) && (hp0->z == hp1->z))
  230.                         ann_1 = 1.0f;
  231.                 }
  232.             }
  233.             ann_2 = (float)local->health / (float)local->maxhealth;
  234.             if (ann_2 > 1.0f) ann_2 = 1.0f;
  235.             ann_3 = (float)local->armour / 250.0f;
  236.             if (ann_3 > 1.0f) ann_3 = 1.0f;
  237.             ann_4 = (float)local->ammo[local->gunselect] / 25.0f;
  238.             if (ann_4 > 1.0f) ann_4 = 1.0f;
  239.  
  240.             if (dist < maxDist)
  241.             {
  242.                 if (!target || target->state != CS_ALIVE)
  243.                 {
  244.                     target = players[i];
  245.                     maxDist = dist;
  246.                 }
  247.             }
  248.         }
  249.  
  250.         return attack;
  251.     }
  252.  
  253.     void GetPitchYaw(float *pitch, float *yaw)
  254.     {
  255.         if (!target || (target->state != CS_ALIVE)) return;
  256.  
  257.         vec *vecLocal = &local->headpos();
  258.         vec *vecTarget = &target->headpos();
  259.  
  260.         float dist = vecLocal->dist(*vecTarget);
  261.         float dX = vecTarget->x-vecLocal->x;
  262.         float dY = vecTarget->y-vecLocal->y;
  263.         float dZ = vecTarget->z-vecLocal->z;
  264.         /*float dist = vecTarget->dist(*vecLocal);
  265.         float dX = vecLocal->x - vecTarget->x;
  266.         float dY = vecLocal->y - vecTarget->y;
  267.         float dZ = vecLocal->z - vecTarget->z;*/
  268.  
  269.         *pitch = asin(dZ / dist) / RAD;
  270.         *yaw = -(float)atan2(dX, dY) / PI * 180;
  271.     }
  272. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement