SHARE
TWEET

Untitled

a guest Aug 25th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  antiaim.cpp
  3. //  vHook
  4. //
  5.  
  6. //#include "hacks.h"
  7. #include "antiaim.h"
  8. #include "../Hacks/autowall.h"
  9. #include <algorithm>
  10. #define RandomFloat(min, max) (rand() % (max - min + 1) + min)
  11.  
  12. //#include "../Hooks/FrameStage.h"
  13.  
  14. Vector GFakeAngle;
  15. Vector GRealAngle;
  16.  
  17. Vector atTargets;
  18. bool isManual = false;
  19.  
  20. float next_lby_update;
  21. float old_lby;
  22. bool Swtich = false;
  23.  
  24. float GetMaxDelta(CCSGOAnimState *animState) {
  25.    
  26.     float speedFraction = std::max(0.0f, std::min(animState->feetShuffleSpeed, 1.0f));
  27.    
  28.     float speedFactor = std::max(0.0f, std::min(1.0f, animState->feetShuffleSpeed2));
  29.    
  30.     float unk1 = ((animState->runningAccelProgress * -0.30000001) - 0.19999999) * speedFraction;
  31.     float unk2 = unk1 + 1.0f;
  32.     float delta;
  33.    
  34.     if (animState->duckProgress > 0)
  35.     {
  36.         unk2 += ((animState->duckProgress * speedFactor) * (0.5f - unk2));// - 1.f
  37.     }
  38.    
  39.     delta = *(float*)((uintptr_t)animState + 0x3A4) * unk2;
  40.    
  41.     return delta - 0.5f;
  42. }
  43.  
  44.  
  45. float GetLatency(INetChannelInfo* nci)
  46. {
  47.     // INetChannelInfo *nci = Interfaces::Engine->GetNetChannelInfo();
  48.     if (nci)
  49.     {
  50.        
  51.         float Latency = nci->GetAvgLatency(FLOW_OUTGOING) + nci->GetAvgLatency(FLOW_INCOMING);
  52.         return Latency;
  53.     }
  54.     else
  55.     {
  56.        
  57.         return 0.0f;
  58.     }
  59. }
  60. float GetOutgoingLatency(INetChannelInfo* nci)
  61. {
  62.     // INetChannelInfo *nci = Interfaces::Engine->GetNetChannelInfo();
  63.     if (nci)
  64.     {
  65.        
  66.         float OutgoingLatency = nci->GetAvgLatency(FLOW_OUTGOING);
  67.         return OutgoingLatency;
  68.     }
  69.     else
  70.     {
  71.        
  72.         return 0.0f;
  73.     }
  74. }
  75. int jitterRange = 0;
  76. float GetIncomingLatency(INetChannelInfo* nci)
  77. {
  78.     // INetChannelInfo *nci = pEngine->GetNetChannelInfo();
  79.     if (nci)
  80.     {
  81.         float IncomingLatency = nci->GetAvgLatency(FLOW_INCOMING);
  82.         return IncomingLatency;
  83.     }
  84.     else
  85.     {
  86.        
  87.         return 0.0f;
  88.     }
  89. }
  90.  
  91. float OldLBY;
  92. float LBYBreakerTimer;
  93. float LastLBYUpdateTime;
  94. bool bSwitch;
  95.  
  96. float CurrentVelocity(C_BaseEntity* local)
  97. {
  98.     int vel = local->GetVelocity().Length2D();
  99.     return vel;
  100. }
  101. bool NextLBYUpdate(C_BaseEntity* local)
  102. {
  103.     //  IClientEntity* LocalPlayer = hackManager.pLocal();
  104.    
  105.     float flServerTime = (float)(local->GetTickBase()  * pGlobals->interval_per_tick);
  106.    
  107.    
  108.     if (OldLBY != local->GetLowerBodyYawTarget())
  109.     {
  110.        
  111.         LBYBreakerTimer++;
  112.         OldLBY = local->GetLowerBodyYawTarget();
  113.         bSwitch = !bSwitch;
  114.         LastLBYUpdateTime = flServerTime;
  115.     }
  116.    
  117.     if (CurrentVelocity(local) > 1)
  118.     {
  119.         LastLBYUpdateTime = flServerTime;
  120.         return false;
  121.     }
  122.    
  123.     if ((LastLBYUpdateTime + 1 - (GetLatency(nci) * 2) < flServerTime) && (local->GetFlags() & FL_ONGROUND))
  124.     {
  125.         if (LastLBYUpdateTime + 1.099 - (GetLatency(nci) * 2) < flServerTime)
  126.         {
  127.             LastLBYUpdateTime += 1.099;
  128.         }
  129.         return true;
  130.     }
  131.     return false;
  132. }
  133.  
  134. bool NextMovingLBYUpdate(C_BaseEntity* local)
  135. {
  136.     //  IClientEntity* LocalPlayer = hackManager.pLocal();
  137.    
  138.     float flServerTime = (float)(local->GetTickBase()  * pGlobals->interval_per_tick);
  139.    
  140.    
  141.     if (OldLBY != local->GetLowerBodyYawTarget())
  142.     {
  143.        
  144.         LBYBreakerTimer++;
  145.         OldLBY = local->GetLowerBodyYawTarget();
  146.         bSwitch = !bSwitch;
  147.         LastLBYUpdateTime = flServerTime;
  148.     }
  149.    
  150.     if (CurrentVelocity(local) > 1)
  151.     {
  152.         LastLBYUpdateTime = flServerTime;
  153.         return false;
  154.     }
  155.    
  156.     if ((LastLBYUpdateTime + 1 - (GetLatency(nci) * 2) < flServerTime) && (local->GetFlags() & FL_ONGROUND))
  157.     {
  158.         if (LastLBYUpdateTime + 0.22 - (GetLatency(nci) * 2) < flServerTime)
  159.         {
  160.             LastLBYUpdateTime += 0.22;
  161.         }
  162.         return true;
  163.     }
  164.     return false;
  165. }
  166.  
  167. float WallThickness(Vector from, Vector to, C_BasePlayer* skip, C_BasePlayer* skip2)
  168. {
  169.     Vector endpos1, endpos2;
  170.    
  171.     Ray_t ray;
  172.     ray.Init(from, to);
  173.    
  174.     CTraceFilterSkipTwoEntities filter(skip, skip2);
  175.    
  176.     trace_t trace1, trace2;
  177.     pEngineTrace->TraceRay(ray, MASK_SHOT_BRUSHONLY, &filter, &trace1);
  178.    
  179.     if (trace1.DidHit())
  180.         endpos1 = trace1.endpos;
  181.     else
  182.         return -1.f;
  183.    
  184.     ray.Init(to, from);
  185.     pEngineTrace->TraceRay(ray, MASK_SHOT_BRUSHONLY, &filter, &trace2);
  186.    
  187.     if (trace2.DidHit())
  188.         endpos2 = trace2.endpos;
  189.    
  190.     return endpos1.DistTo(endpos2);
  191. }
  192.  
  193.  
  194. /*void freestanding(CUserCmd* cmd)
  195.  {
  196.  static float FinalAngle;
  197.  bool bside1 = false;
  198.  bool bside2 = false;
  199.  bool autowalld = false;
  200.  
  201.  C_BaseEntity* localplayer = (C_BaseEntity*)pEntList->GetClientEntity(pEngine->GetLocalPlayer());
  202.  
  203.  for (int i = 0; i <= pEngine->GetMaxClients(); ++i)
  204.  {
  205.  C_BaseEntity* pPlayerEntity = pEntList->GetClientEntity(i);
  206.  
  207.  if (!pPlayerEntity
  208.  || !pPlayerEntity->GetAlive()
  209.  || pPlayerEntity->GetDormant()
  210.  || pPlayerEntity == localplayer
  211.  || pPlayerEntity->GetTeam() == localplayer->GetTeam())
  212.  continue;
  213.  
  214.  float angToLocal = CalcAngle(localplayer->GetVecOrigin(), pPlayerEntity->GetVecOrigin()).y;
  215.  Vector ViewPoint = pPlayerEntity->GetVecOrigin() + Vector(0, 0, 90);
  216.  
  217.  Vector2D Side1 = { (45 * sin(GRD_TO_BOG(angToLocal))),(45 * cos(GRD_TO_BOG(angToLocal))) };
  218.  Vector2D Side2 = { (45 * sin(GRD_TO_BOG(angToLocal + 180))) ,(45 * cos(GRD_TO_BOG(angToLocal + 180))) };
  219.  
  220.  Vector2D Side3 = { (50 * sin(GRD_TO_BOG(angToLocal))),(50 * cos(GRD_TO_BOG(angToLocal))) };
  221.  Vector2D Side4 = { (50 * sin(GRD_TO_BOG(angToLocal + 180))) ,(50 * cos(GRD_TO_BOG(angToLocal + 180))) };
  222.  
  223.  Vector Origin = localplayer->GetVecOrigin();
  224.  
  225.  Vector2D OriginLeftRight[] = { Vector2D(Side1.x, Side1.y), Vector2D(Side2.x, Side2.y) };
  226.  
  227.  Vector2D OriginLeftRightLocal[] = { Vector2D(Side3.x, Side3.y), Vector2D(Side4.x, Side4.y) };
  228.  
  229.  for (int side = 0; side < 2; side++)
  230.  {
  231.  Vector OriginAutowall = { Origin.x + OriginLeftRight[side].x,  Origin.y - OriginLeftRight[side].y , Origin.z + 80 };
  232.  Vector OriginAutowall2 = { ViewPoint.x + OriginLeftRightLocal[side].x,  ViewPoint.y - OriginLeftRightLocal[side].y , ViewPoint.z };
  233.  
  234.  if (Autowall::CanHitFloatingPoint(OriginAutowall, ViewPoint))
  235.  {
  236.  if (side == 0)
  237.  {
  238.  bside1 = true;
  239.  FinalAngle = angToLocal + 90;
  240.  }
  241.  else if (side == 1)
  242.  {
  243.  bside2 = true;
  244.  FinalAngle = angToLocal - 90;
  245.  }
  246.  autowalld = true;
  247.  }
  248.  else
  249.  {
  250.  for (int side222 = 0; side222 < 2; side222++)
  251.  {
  252.  Vector OriginAutowall222 = { Origin.x + OriginLeftRight[side222].x,  Origin.y - OriginLeftRight[side222].y , Origin.z + 80 };
  253.  
  254.  if (Autowall::CanHitFloatingPoint(OriginAutowall222, OriginAutowall2))
  255.  {
  256.  if (side222 == 0)
  257.  {
  258.  bside1 = true;
  259.  FinalAngle = angToLocal + 90;
  260.  }
  261.  else if (side222 == 1)
  262.  {
  263.  bside2 = true;
  264.  FinalAngle = angToLocal - 90;
  265.  }
  266.  autowalld = true;
  267.  }
  268.  }
  269.  }
  270.  }
  271.  }
  272.  
  273.  if (!autowalld || (bside1 && bside2)) {
  274.  cmd->viewangles.y += 180;
  275.  }
  276.  else
  277.  cmd->viewangles.y = FinalAngle;
  278.  
  279.  if (vars.aimbot.jitter != 0)
  280.  {
  281.  float Offset = vars.aimbot.jitter;
  282.  
  283.  
  284.  Swtich ? cmd->viewangles.y -= Offset : cmd->viewangles.y += Offset;
  285.  }
  286.  }*/
  287.  
  288. float fov_player(Vector ViewOffSet, Vector View, C_BaseEntity* entity, int hitbox)
  289. {
  290.     // Anything past 180 degrees is just going to wrap around
  291.     const float MaxDegrees = 180.0f;
  292.    
  293.     // Get local angles
  294.     Vector Angles = View;
  295.    
  296.     // Get local view / eye position
  297.     Vector Origin = ViewOffSet;
  298.    
  299.     // Create and intiialize vectors for calculations below
  300.     Vector Delta(0, 0, 0);
  301.     //Vector Origin(0, 0, 0);
  302.     Vector Forward(0, 0, 0);
  303.    
  304.     // Convert angles to normalized directional forward vector
  305.     AngleVectors(Angles, &Forward);
  306.    
  307.     Vector AimPos = GetHitboxPosition(entity, hitbox); //pvs fix disabled
  308.    
  309.     VectorSubtract(AimPos, Origin, Delta);
  310.     //Delta = AimPos - Origin;
  311.    
  312.     // Normalize our delta vector
  313.     NormalizeNum(Delta, Delta);
  314.    
  315.     // Get dot product between delta position and directional forward vectors
  316.     float DotProduct = Forward.Dot(Delta);
  317.    
  318.     // Time to calculate the field of view
  319.     return (acos(DotProduct) * (MaxDegrees / M_PI));
  320. }
  321. /*
  322.  float Vector::DistTo(const Vector &vOther) const
  323.  {
  324.  Vector delta;
  325.  
  326.  delta.x = x - vOther.x;
  327.  delta.y = y - vOther.y;
  328.  delta.z = z - vOther.z;
  329.  
  330.  return delta.Length();
  331.  }
  332.  */
  333. int closest_to_crosshair()
  334. {
  335.     int index = -1;
  336.     float lowest_fov = INT_MAX;
  337.    
  338.     auto* local = pEntList->GetClientEntity(pEngine->GetLocalPlayer());
  339.    
  340.    
  341.     if (!local)
  342.         return -1;
  343.    
  344.     Vector local_position = local->GetVecOrigin() + local->GetVecViewOffset();
  345.    
  346.     Vector angles;
  347.     pEngine->GetViewAngles(angles);
  348.    
  349.     for (int i = 1; i <= pEntList->GetHighestEntityIndex(); i++)
  350.     {
  351.         auto* entity = pEntList->GetClientEntity(i);
  352.        
  353.         if (!entity || !entity->GetAlive() || entity->GetTeam() == local->GetTeam() || entity->GetDormant() || entity == local)
  354.             continue;
  355.        
  356.         float fov = fov_player(local_position, angles, entity, 0);
  357.        
  358.         if (fov < lowest_fov)
  359.         {
  360.             lowest_fov = fov;
  361.             index = i;
  362.         }
  363.     }
  364.    
  365.     return index;
  366. }
  367. ////////////////////////////////////////////////////***/////////////////////////////////////////////////////////////
  368. void AngleVectors3(const Vector &angles, Vector& forward, Vector& right, Vector& up)
  369. {
  370.     float sr, sp, sy, cr, cp, cy;
  371.    
  372.     SinCos(DEG2RAD(angles[1]), &sy, &cy);
  373.     SinCos(DEG2RAD(angles[0]), &sp, &cp);
  374.     SinCos(DEG2RAD(angles[2]), &sr, &cr);
  375.    
  376.     forward.x = (cp * cy);
  377.     forward.y = (cp * sy);
  378.     forward.z = (-sp);
  379.     right.x = (-1 * sr * sp * cy + -1 * cr * -sy);
  380.     right.y = (-1 * sr * sp * sy + -1 * cr *  cy);
  381.     right.z = (-1 * sr * cp);
  382.     up.x = (cr * sp * cy + -sr * -sy);
  383.     up.y = (cr * sp * sy + -sr * cy);
  384.     up.z = (cr * cp);
  385. }
  386.  
  387. inline float NormalizeYaw(float yaw)
  388. {
  389.     if (yaw > 180)
  390.         yaw -= (round(yaw / 360) * 360.f);
  391.     else if (yaw < -180)
  392.         yaw += (round(yaw / 360) * -360.f);
  393.    
  394.     return yaw;
  395. }
  396.  
  397.  
  398. bool desync(C_BaseEntity *const local, CUserCmd* cmd, int mode) {
  399.     static bool switch_;
  400.     float yaw = 0.f;
  401.     float desyncdelta = GetMaxDelta(local->GetAnimState());
  402.    
  403.     if(mode > 0)
  404.         yaw = GRealAngle.y + mode == 1 ? desyncdelta : -desyncdelta;
  405.     else
  406.         yaw = GRealAngle.y + switch_ == true ? desyncdelta : -desyncdelta;
  407.    
  408.     NormalizeYaw(yaw);
  409.  
  410.     GFakeAngle.y = yaw;
  411.     cmd->viewangles.y = yaw;
  412.  
  413.     switch_ = !switch_;
  414. }
  415.  
  416.  
  417. //--------------------------------------------------------------------------------
  418.  
  419. float Freestand(C_BaseEntity *const local, CUserCmd* cmd)
  420. {
  421.     //Vector oldAngle = cmd->viewangles;
  422.     float Back, Right, Left;
  423.     bool no_active = true;
  424.     Vector src3D, dst3D, forward, right, up, src, dst;
  425.     trace_t tr;
  426.     Ray_t backray, rightray, leftray;
  427.     CTraceFilter filter;
  428.    
  429.     Vector angles;
  430.     pEngine->GetViewAngles(angles);
  431.    
  432.     AngleVectors3(angles, forward, right, up);
  433.    
  434.     filter.pSkip = local;
  435.     src3D = local->GetVecOrigin() + local->GetVecViewOffset();
  436.     dst3D = src3D + (forward * 384.f);
  437.    
  438.     backray.Init(src3D, dst3D);
  439.     pEngineTrace->TraceRay(backray, MASK_SHOT, &filter, &tr);
  440.     Back = (tr.endpos - tr.startpos).Length();
  441.    
  442.     rightray.Init(src3D + right * 35.f, dst3D + right * 35.f);
  443.     pEngineTrace->TraceRay(rightray, MASK_SHOT, &filter, &tr);
  444.     Right = (tr.endpos - tr.startpos).Length();
  445.    
  446.     leftray.Init(src3D - right * 35.f, dst3D - right * 35.f);
  447.     pEngineTrace->TraceRay(leftray, MASK_SHOT, &filter, &tr);
  448.     Left = (tr.endpos - tr.startpos).Length();
  449.    
  450.     if (Left > Right){
  451.        
  452.         if (*bSendPacket)
  453.         {
  454.             desync(local, cmd, 2);
  455.         }
  456.         else
  457.         {
  458.             cmd->viewangles.y -= 90;
  459.            
  460.             GRealAngle.y = cmd->viewangles.y;
  461.         }
  462.        
  463.     }else if (Right > Left){
  464.        
  465.         if (*bSendPacket)
  466.         {
  467.             desync(local, cmd, 1);
  468.         }
  469.         else
  470.         {
  471.             cmd->viewangles.y += 90;
  472.            
  473.             GRealAngle.y = cmd->viewangles.y;
  474.         }
  475.        
  476.     }else if (Back > Right || Back > Left){
  477.        
  478.         if (*bSendPacket)
  479.         {
  480.             desync(local, cmd, 0);
  481.         }
  482.         else
  483.         {
  484.             cmd->viewangles.y += 180;
  485.            
  486.             GRealAngle.y = cmd->viewangles.y;
  487.         }
  488.        
  489.     } else if(no_active){
  490.        
  491.         if (*bSendPacket)
  492.         {
  493.             desync(local, cmd, 0);
  494.         }
  495.         else
  496.         {
  497.             cmd->viewangles.y -= 180;
  498.            
  499.             GRealAngle.y = cmd->viewangles.y;
  500.         }
  501.        
  502.     }
  503.     return 0;
  504. }
  505.  
  506. void DoAntiaim(CUserCmd* cmd, C_BaseEntity* local, C_BaseCombatWeapon* weapon)
  507. {
  508.    
  509.     if (!vars.misc.antiaim)
  510.         return;
  511.    
  512.     if (!local || !local->GetAlive())
  513.         return;
  514.    
  515.     if (!weapon)
  516.         return;
  517.    
  518.     if (weapon->IsGrenade())
  519.         return;
  520.    
  521.     if (local->GetMoveType() == MOVETYPE_LADDER || local->GetMoveType() == MOVETYPE_NOCLIP)
  522.         return;
  523.    
  524.     if (cmd->buttons & IN_ATTACK || cmd->buttons & IN_USE)
  525.     {
  526.         GRealAngle = GFakeAngle = cmd->viewangles;
  527.         return;
  528.     }
  529.    
  530.     if (local->GetImmune())
  531.         return;
  532.    
  533.    
  534.     if (!vars.misc.fakelag)
  535.         *bSendPacket = cmd->command_number % 2;
  536.    
  537.     if(vars.misc.pitch)
  538.     {
  539.         cmd->viewangles.x = 89;
  540.     }
  541.    
  542.     if(vars.misc.AAenabled)
  543.     {
  544.        
  545.         if(!vars.misc.freestand){
  546.             isManual = true;
  547.         }
  548.         else{
  549.             Freestand(local, cmd);
  550.             isManual = false;
  551.         }
  552.  
  553.        
  554.         if (local->GetFlags() & FL_ONGROUND && cmd->sidemove < 3 && cmd->sidemove > -3) {
  555.             static bool switch_ = false;
  556.             if (switch_)
  557.                 cmd->sidemove = 2;
  558.             else
  559.                 cmd->sidemove = -2;
  560.             switch_ = !switch_;
  561.         }
  562.     }
  563.     cmd->viewangles.ClampAngles();
  564. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top