Snorflake

broken aimbot

May 31st, 2015
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.70 KB | None | 0 0
  1. #define TIME_BEFORE_ADJUSTEMENT 50
  2. #define TIME_BEFORE_NEW_TARGET 250
  3. #define M_RADPI 57.295779513082
  4. byte bSendPacket;
  5. class HumanizedAimbot
  6. {
  7. enum AimbotState
  8. {
  9. NoTarget, //No target so find one
  10. ReachLocation, //aim at the random spot near them
  11. AimingTarget //Aim onto the target
  12. };
  13. public:
  14. void ClampAngles(Vector &angles)
  15. {
  16. if (angles.x > 89)
  17. angles.x -= 360.f;
  18. else if (angles.x < -89)
  19. angles.x += 360.f;
  20. if (angles.y > 180.f)
  21. angles.y -= 360.f;
  22. else if (angles.y < -180.f)
  23. angles.y += 360.f;
  24.  
  25. angles.z = 0;
  26. }
  27. std::vector<int> GetVisibleBones(CBaseEntityNew* pEntity)
  28. {
  29. std::vector<int> temp;
  30. static int bones[]
  31. {
  32. 10, 5, 4
  33. };
  34. Vector tempv;
  35. for (int i = 0; i < 2; i++)
  36. {
  37. if (GetBonePosition(bones[i], tempv, pEntity) && IsVisible(Utils.LocalPlayer()->GetEyePosition(), tempv, pEntity))
  38. temp.push_back(bones[i]);
  39. }
  40. return temp;
  41. }
  42. Vector GetPunch()
  43. {
  44. return Utils.LocalPlayer()->GetPunch() * RandomFloat(1.8f,2.f);
  45. }
  46. bool GetBonePosition(int Hitbox, Vector& HitboxPos, CBaseEntityNew* target)
  47. {
  48. if (!target || target->IsDormant())
  49. return false;
  50. matrix3x4_t matrix[128];
  51. if (!target->SetupBones(matrix, 128, 0x100, 0))
  52. return false;
  53. HitboxPos = Vector(matrix[Hitbox][0][3], matrix[Hitbox][1][3], matrix[Hitbox][2][3]);
  54. return true;
  55. }
  56. bool __stdcall IsVisible(Vector& start, Vector& end, CBaseEntityNew* target)
  57. {
  58. Vector eyepos = start;
  59. trace_t trace;
  60. Ray_t ray;
  61. CTraceFilter filter;
  62. CBaseEntityNew* me = Utils.LocalPlayer();
  63. filter.pSkip1 = me;
  64. player_info_t info;
  65. ray.Init(eyepos, end);
  66. Interfaces.Trace->TraceRay(ray, MASK_SHOT, &filter, &trace);
  67. CBaseEntityNew* hit = (CBaseEntityNew*)trace.m_pEnt;
  68. if (!hit)
  69. return false;
  70. if (hit)
  71. {
  72. if (trace.allsolid)
  73. return false;
  74. if (Interfaces.Engine->GetPlayerInfo(hit->GetIndex(), &info) && me->GetTeamNum() != hit->GetTeamNum())
  75. {
  76. return true;
  77. }
  78. }
  79. return false;
  80. }
  81. HumanizedAimbot()
  82. {
  83. Target = -1;
  84. BestDist = 9999;
  85. aimkey = 0x1; // 'E'
  86. }
  87. int bone = -1;
  88. AimbotState AimState;
  89. void DropTarget()
  90. {
  91. Target = -1;
  92. BestDist = 9999;
  93. AimState = NoTarget;
  94. }
  95. int aimkey;
  96. bool WaitUntil = false;
  97. int WaitTill = 0;
  98. CBaseEntityNew* TargetEntity = nullptr;
  99. Vector AimPoint, AimAngle;
  100. bool IsTargetValid(CBaseEntityNew* target)
  101. {
  102. if (!target || !target->isAlive() || target->IsDormant() || target->GetTeamNum() == Utils.LocalPlayer()->GetTeamNum())
  103. return false;
  104. return true;
  105. }
  106. void AngleVectorsZ(const Vector &angles, Vector *forward)
  107. {
  108. float sp, sy, cp, cy;
  109.  
  110. sy = sin(DEG2RAD(angles[1]));
  111. cy = cos(DEG2RAD(angles[1]));
  112. sp = sin(DEG2RAD(angles[0]));
  113. cp = cos(DEG2RAD(angles[0]));
  114.  
  115.  
  116. forward->x = cp*cy;
  117. forward->y = cp*sy;
  118. forward->z = -sp;
  119. }
  120. bool FindTarget()
  121. {
  122. CBaseEntityNew* me = Utils.LocalPlayer();
  123. DropTarget();
  124. Vector viewangles = Utils.GetAngles();
  125. Vector mang;
  126. Interfaces.Engine->GetViewAngles(mang);
  127. for (int i = 1; i < 32; i++)
  128. {
  129. CBaseEntityNew* target = (CBaseEntityNew*)Interfaces.ClientEntList->GetClientEntity(i);
  130. if (!IsTargetValid(target))
  131. continue;
  132. std::vector<int> bones = GetVisibleBones(target);
  133. if (bones.size() == 0) continue;
  134. Vector forward;
  135. AngleVectorsZ(mang, &forward);
  136. Vector dir = (me->GetEyePosition() - target->GetEyePosition());
  137. VectorNormalize(dir);
  138. VectorNormalize(forward);
  139. if (dir.Length())
  140. dir /= dir.Length();
  141. float fov = forward.Dot(dir);
  142. fov *= 180 / M_PI;
  143. fov = abs(fov - 1);
  144. Msg("%f\n", fov);
  145. if (fov > *Vars.fov) continue;
  146. float dist = flGetDistance(me->GetAbsOrigin(), target->GetAbsOrigin());
  147. if (dist > BestDist) continue;
  148. Target = i;
  149. TargetEntity = target;
  150. BestDist = dist;
  151. }
  152. if (Target > 0 && TargetEntity)
  153. {
  154. RandomSeed(time(null));
  155. std::vector<int> bones = GetVisibleBones(TargetEntity);
  156. int rand = RandomInt(0, bones.size() - 1);
  157. bone = bones[rand];
  158. if (!GetBonePosition(bone, AimPoint, TargetEntity)) return false;
  159. AimPoint += RandomFloat(-20.f, 20.f);
  160. VectorAngles(AimPoint - me->GetEyePosition(), (QAngle&)AimAngle);
  161. return true;
  162. }
  163. return false;
  164. }
  165. void AimAt(Vector targetang)
  166. {
  167. Vector delta = Utils.GetAngles() - targetang;
  168. ClampAngles(delta);
  169. //Interfaces.Engine->SetViewAngles(Utils.GetAngles() - delta / RandomFloat(3.f,11.f));
  170. }
  171. bool IsBoneVisible(int bone, CBaseEntityNew* target)
  172. {
  173. Vector tempv;
  174. if (GetBonePosition(bone, tempv, target) && IsVisible(Utils.LocalPlayer()->GetEyePosition(), tempv, target))
  175. {
  176. return true;
  177. }
  178. return false;
  179.  
  180. }
  181. void DoAimbot()
  182. {
  183. if (!GetAsyncKeyState(aimkey))
  184. {
  185. DropTarget();
  186. return;
  187. }
  188. static Vector PrevVelocity;
  189. CBaseEntityNew* me = Utils.LocalPlayer();
  190. if (!me) return;
  191. if (WaitUntil)
  192. {
  193. if (GetTickCount() >= WaitTill)
  194. WaitUntil = false;
  195. return;
  196. }
  197. if (AimState == NoTarget)
  198. {
  199. if (FindTarget())
  200. {
  201. AimState = AimingTarget;
  202. }
  203. }
  204. switch (AimState)
  205. {
  206. case NoTarget:
  207. return;
  208. break;
  209. case ReachLocation:
  210. if (fabs((Utils.GetAngles().x - GetPunch().x) - AimAngle.x) <= 1.f || fabs((Utils.GetAngles().y - GetPunch().y) - AimAngle.y) <= 1.f)
  211. {
  212. WaitUntil = true;
  213. WaitTill = GetTickCount() + TIME_BEFORE_ADJUSTEMENT;
  214. AimState = AimingTarget;
  215. }
  216. break;
  217. case AimingTarget:
  218. if (!IsTargetValid(TargetEntity) || !IsBoneVisible(bone,TargetEntity))
  219. {
  220. DropTarget();
  221. WaitUntil = true;
  222. WaitTill = GetTickCount() + TIME_BEFORE_NEW_TARGET;
  223. return;
  224. }
  225. Vector velocity = TargetEntity->GetVelocity();
  226. if ((velocity.x < 0 && PrevVelocity.x > 0) || (velocity.y < 0 && PrevVelocity.y > 0) || (velocity.x > 0 && PrevVelocity.x < 0) || (velocity.y > 0 && PrevVelocity.y < 0))
  227. {
  228. WaitUntil = true;
  229. WaitTill = GetTickCount() + TIME_BEFORE_ADJUSTEMENT;
  230. }
  231. PrevVelocity = velocity;
  232. if (GetBonePosition(bone, AimPoint, TargetEntity))
  233. VectorAngles(AimPoint - me->GetEyePosition(), (QAngle&)AimAngle);
  234. break;
  235. }
  236. if (AimState > NoTarget)
  237. {
  238. AimAt(AimAngle - GetPunch());
  239. }
  240. }
  241. private:
  242. float flGetDistance(Vector from, Vector to)
  243. {
  244. Vector angle;
  245. angle.x = to.x - from.x; angle.y = to.y - from.y; angle.z = to.z - from.z;
  246.  
  247. return sqrt(angle.x*angle.x + angle.y*angle.y + angle.z*angle.z);
  248. }
  249. void MakeVector(Vector &angle, Vector &vector)
  250. {
  251. float pitch = float(angle[0] * M_PI / 180);
  252. float yaw = float(angle[1] * M_PI / 180);
  253. float tmp = float(cos(pitch));
  254. vector[0] = float(-tmp * -cos(yaw));
  255. vector[1] = float(sin(yaw)*tmp);
  256. vector[2] = float(-sin(pitch));
  257. }
  258.  
  259. int Target;
  260. float BestDist;
  261. };
Advertisement
Add Comment
Please, Sign In to add comment