Advertisement
captmicro

SOURCESDK AIMBOT/ESP

Dec 29th, 2011
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.79 KB | None | 0 0
  1.  
  2. // -------------------------------------------------------------------------------- //
  3. // CAimbot/ESP by Capt. Micro
  4. // -------------------------------------------------------------------------------- //
  5. class CAimbot
  6. {
  7. public:
  8.     CAimbot();
  9.     ~CAimbot();
  10.     bool bShowRays;
  11.     bool bAimbot;
  12.     bool bFindHits;
  13.     bool bEsp;
  14.     float fMaxDist;
  15.     IVDebugOverlay *debugoverlay;
  16.     bool ReadyForUse(void);
  17.     void ModifyUserCmd(CUserCmd *cmd);
  18.     void DrawEspOverlay(void);
  19.     //private:
  20.     C_BaseEntity *target;
  21.     C_BaseEntity *local;
  22.     bool AimbotTraceRay(C_BaseEntity *ent, Vector &start, Vector &end);
  23.     void AimbotGetAimPos(C_BaseEntity *ent, Vector &out);
  24.     void AimbotGetAimAngle(C_BaseEntity *ent, QAngle &out);
  25.     bool IsVisibleToLocalPlayer(C_BaseEntity *ent);
  26.     void AimbotGetTarget(void);
  27. };
  28. CAimbot::CAimbot()
  29. {
  30.     bShowRays = true;
  31.     bAimbot = false;
  32.     bFindHits = false;
  33.     bEsp = true;
  34.     fMaxDist = 4096.0f;
  35.     debugoverlay = 0;
  36.     target = 0;
  37.     local = 0;
  38. }
  39. CAimbot::~CAimbot()
  40. {
  41.     bShowRays = false;
  42.     bAimbot = false;
  43.     bFindHits = false;
  44.     bEsp = false;
  45.     fMaxDist = 0.0f;
  46.     debugoverlay = 0;
  47.     target = 0;
  48.     local = 0;
  49. }
  50. bool CAimbot::ReadyForUse(void)
  51. {
  52.     return (local != 0) || (debugoverlay != 0);
  53. }
  54. void CAimbot::ModifyUserCmd(CUserCmd *cmd)
  55. {
  56.     if ((!bAimbot) || (target == 0) || (local == 0)) return;
  57.  
  58.     QAngle aimang;
  59.     AimbotGetAimAngle(target, aimang);
  60.     cmd->viewangles = aimang;
  61. }
  62. bool CAimbot::AimbotTraceRay(C_BaseEntity *ent, Vector &start, Vector &end)
  63. {
  64.     Ray_t ray;
  65.     trace_t trace;
  66.     Vector scr;
  67.     ray.Init(start, end);
  68.     UTIL_TraceRay(ray, MASK_SHOT, local->GetBaseEntity(),
  69.         COLLISION_GROUP_NONE, &trace);
  70.     bool valid = (trace.m_pEnt == ent) && (ScreenTransform(end, scr) == 0);
  71.     if (bShowRays && (debugoverlay != 0))
  72.         debugoverlay->AddLineOverlay(start, end, (valid?0:255), (valid?255:0), 0, true, 0.1f);
  73.     return valid;
  74. }
  75. void CAimbot::AimbotGetAimPos(C_BaseEntity *ent, Vector &out)
  76. {
  77.     ent->EntityToWorldSpace(ent->CollisionProp()->OBBCenter(), &out);
  78.     if (ent == local->GetBaseEntity())
  79.     {
  80.         out = local->EyePosition();
  81.     }
  82.     else
  83.     {
  84.         if (bFindHits)
  85.         {
  86.             Vector lbottom, wbottom;
  87.             lbottom = ent->CollisionProp()->OBBMins();
  88.             lbottom.x = abs(lbottom.x) / 2;
  89.             lbottom.y = abs(lbottom.y) / 2;
  90.             ent->EntityToWorldSpace(lbottom, &wbottom);
  91.             Vector ltop, wtop;
  92.             ltop = ent->CollisionProp()->OBBMaxs();
  93.             ltop.x = abs(ltop.x) / 2;
  94.             ltop.y = abs(ltop.y) / 2;
  95.             ent->EntityToWorldSpace(ltop, &wtop);
  96.             Vector wscan = wtop;
  97.             Vector lpAimPos;
  98.             AimbotGetAimPos(local, lpAimPos);
  99.             for (; wscan.z <= wtop.z && wscan.z >= wbottom.z; wscan.z -= 1.0f)
  100.             {
  101.                 if (AimbotTraceRay(ent, lpAimPos, wscan)) {
  102.                     if (bShowRays && (debugoverlay != 0))
  103.                         debugoverlay->AddLineOverlay(lpAimPos, wscan, 0, 255, 0, true, 0.1f);
  104.                     out = wscan;
  105.                     return;
  106.                 }
  107.             }
  108.             return;
  109.         }
  110.  
  111.         out = ent->EyePosition();
  112.         if (ent->BoundingRadius() >= 16) out.z -= 8;
  113.     }
  114. }
  115. bool CAimbot::IsVisibleToLocalPlayer(C_BaseEntity *ent)
  116. {
  117.     Vector start, end;
  118.     AimbotGetAimPos(local, start);
  119.     AimbotGetAimPos(ent, end);
  120.     return AimbotTraceRay(ent, start, end);
  121. }
  122. void CAimbot::AimbotGetAimAngle(C_BaseEntity *ent, QAngle &out)
  123. {
  124.     Vector epos, lpos;
  125.     AimbotGetAimPos(ent, epos);
  126.     AimbotGetAimPos(local, lpos);
  127.     VectorAngles((epos - lpos), out);
  128. }
  129. void CAimbot::AimbotGetTarget(void)
  130. {
  131.     if (!bAimbot || (local == 0)) return;
  132.  
  133.     C_BaseEntity *scanner[256];
  134.     int ent_count = UTIL_EntitiesInSphere(scanner, 256,
  135.         local->GetAbsOrigin(), fMaxDist, 0);
  136.     float closest = fMaxDist;
  137.     for (int i = 0; i < ent_count; i++)
  138.     {
  139.         if (target == 0 && (scanner[i] != NULL)
  140.             && scanner[i]->IsAlive() && scanner[i]->IsNPC()
  141.             && (scanner[i]->GetMoveType() != MOVETYPE_NONE)
  142.             && (scanner[i]->GetMoveType() != MOVETYPE_OBSERVER)
  143.             && IsVisibleToLocalPlayer(scanner[i]))
  144.         {
  145.             float dist = local->GetAbsOrigin().DistTo(scanner[i]->GetAbsOrigin());
  146.             if (dist < closest) { closest = dist; target = scanner[i]; }
  147.             break;
  148.         }
  149.         else if (target != 0)
  150.         {
  151.             if ((scanner[i] == target) &&
  152.                 (!scanner[i]->IsAlive() || !scanner[i]->IsNPC()
  153.                 || (scanner[i]->GetMoveType() == MOVETYPE_NONE)
  154.                 || (scanner[i]->GetMoveType() == MOVETYPE_OBSERVER)
  155.                 || !IsVisibleToLocalPlayer(scanner[i])))
  156.             {
  157.                 target = 0;
  158.                 break;
  159.             }
  160.         }
  161.     }
  162. }
  163. void CAimbot::DrawEspOverlay(void)
  164. {
  165.     if (debugoverlay != 0)
  166.     {
  167.         debugoverlay->AddScreenTextOverlay(0.005f, 0.005f, 0.1f,
  168.             0, 0, 255, 200, "CAimbot/ESP");
  169.         debugoverlay->AddScreenTextOverlay(0.005f, 0.020f, 0.1f,
  170.             bAimbot?0:255, bAimbot?255:0, 0, 200, "bAimbot");
  171.         debugoverlay->AddScreenTextOverlay(0.005f, 0.030f, 0.1f,
  172.             bEsp?0:255, bEsp?255:0, 0, 200, "bEsp");
  173.         debugoverlay->AddScreenTextOverlay(0.005f, 0.040f, 0.1f,
  174.             bFindHits?0:255, bFindHits?255:0, 0, 200, "bFindHits");
  175.         debugoverlay->AddScreenTextOverlay(0.005f, 0.050f, 0.1f,
  176.             bShowRays?0:255, bShowRays?255:0, 0, 200, "bShowRays");
  177.     }
  178.  
  179.     if (!bEsp || (debugoverlay == 0) || (local == 0)) return;
  180.  
  181.     C_BaseEntity *scanner[256];
  182.     int ent_count = UTIL_EntitiesInSphere(scanner, 256,
  183.         local->GetAbsOrigin(), fMaxDist, 0);
  184.     for (int i = 0; i < ent_count; i++)
  185.     {
  186.         if ((scanner[i] != NULL)
  187.             && scanner[i]->IsAlive() && scanner[i]->IsNPC())
  188.         {
  189.             /*Vector vec;
  190.             AimbotGetAimPos(scanner[i], vec);
  191.             debugoverlay->AddTextOverlayRGB(vec, 0, 0.05f, 0, 0, 255, 200, "^");*/
  192.             CCollisionProperty *pCollide = scanner[i]->CollisionProp();
  193.             if (pCollide == 0) continue;
  194.             debugoverlay->AddBoxOverlay(scanner[i]->GetAbsOrigin(),
  195.                 pCollide->OBBMins(), pCollide->OBBMaxs(),
  196.                 scanner[i]->GetAbsAngles(), 255, 0, 0, 5, 0.1f);
  197.         }
  198.     }
  199.  
  200.     if (target != 0)
  201.     {
  202.         CCollisionProperty *pCollide = target->CollisionProp();
  203.         debugoverlay->AddBoxOverlay(target->GetAbsOrigin(),
  204.             pCollide->OBBMins(), pCollide->OBBMaxs(),
  205.             target->GetAbsAngles(), 0, 0, 255, 10, 0.1f);
  206.     }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement