Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define TIME_BEFORE_ADJUSTEMENT 50
- #define TIME_BEFORE_NEW_TARGET 250
- #define M_RADPI 57.295779513082
- byte bSendPacket;
- class HumanizedAimbot
- {
- enum AimbotState
- {
- NoTarget, //No target so find one
- ReachLocation, //aim at the random spot near them
- AimingTarget //Aim onto the target
- };
- public:
- void ClampAngles(Vector &angles)
- {
- if (angles.x > 89)
- angles.x -= 360.f;
- else if (angles.x < -89)
- angles.x += 360.f;
- if (angles.y > 180.f)
- angles.y -= 360.f;
- else if (angles.y < -180.f)
- angles.y += 360.f;
- angles.z = 0;
- }
- std::vector<int> GetVisibleBones(CBaseEntityNew* pEntity)
- {
- std::vector<int> temp;
- static int bones[]
- {
- 10, 5, 4
- };
- Vector tempv;
- for (int i = 0; i < 2; i++)
- {
- if (GetBonePosition(bones[i], tempv, pEntity) && IsVisible(Utils.LocalPlayer()->GetEyePosition(), tempv, pEntity))
- temp.push_back(bones[i]);
- }
- return temp;
- }
- Vector GetPunch()
- {
- return Utils.LocalPlayer()->GetPunch() * RandomFloat(1.8f,2.f);
- }
- bool GetBonePosition(int Hitbox, Vector& HitboxPos, CBaseEntityNew* target)
- {
- if (!target || target->IsDormant())
- return false;
- matrix3x4_t matrix[128];
- if (!target->SetupBones(matrix, 128, 0x100, 0))
- return false;
- HitboxPos = Vector(matrix[Hitbox][0][3], matrix[Hitbox][1][3], matrix[Hitbox][2][3]);
- return true;
- }
- bool __stdcall IsVisible(Vector& start, Vector& end, CBaseEntityNew* target)
- {
- Vector eyepos = start;
- trace_t trace;
- Ray_t ray;
- CTraceFilter filter;
- CBaseEntityNew* me = Utils.LocalPlayer();
- filter.pSkip1 = me;
- player_info_t info;
- ray.Init(eyepos, end);
- Interfaces.Trace->TraceRay(ray, MASK_SHOT, &filter, &trace);
- CBaseEntityNew* hit = (CBaseEntityNew*)trace.m_pEnt;
- if (!hit)
- return false;
- if (hit)
- {
- if (trace.allsolid)
- return false;
- if (Interfaces.Engine->GetPlayerInfo(hit->GetIndex(), &info) && me->GetTeamNum() != hit->GetTeamNum())
- {
- return true;
- }
- }
- return false;
- }
- HumanizedAimbot()
- {
- Target = -1;
- BestDist = 9999;
- aimkey = 0x1; // 'E'
- }
- int bone = -1;
- AimbotState AimState;
- void DropTarget()
- {
- Target = -1;
- BestDist = 9999;
- AimState = NoTarget;
- }
- int aimkey;
- bool WaitUntil = false;
- int WaitTill = 0;
- CBaseEntityNew* TargetEntity = nullptr;
- Vector AimPoint, AimAngle;
- bool IsTargetValid(CBaseEntityNew* target)
- {
- if (!target || !target->isAlive() || target->IsDormant() || target->GetTeamNum() == Utils.LocalPlayer()->GetTeamNum())
- return false;
- return true;
- }
- void AngleVectorsZ(const Vector &angles, Vector *forward)
- {
- float sp, sy, cp, cy;
- sy = sin(DEG2RAD(angles[1]));
- cy = cos(DEG2RAD(angles[1]));
- sp = sin(DEG2RAD(angles[0]));
- cp = cos(DEG2RAD(angles[0]));
- forward->x = cp*cy;
- forward->y = cp*sy;
- forward->z = -sp;
- }
- bool FindTarget()
- {
- CBaseEntityNew* me = Utils.LocalPlayer();
- DropTarget();
- Vector viewangles = Utils.GetAngles();
- Vector mang;
- Interfaces.Engine->GetViewAngles(mang);
- for (int i = 1; i < 32; i++)
- {
- CBaseEntityNew* target = (CBaseEntityNew*)Interfaces.ClientEntList->GetClientEntity(i);
- if (!IsTargetValid(target))
- continue;
- std::vector<int> bones = GetVisibleBones(target);
- if (bones.size() == 0) continue;
- Vector forward;
- AngleVectorsZ(mang, &forward);
- Vector dir = (me->GetEyePosition() - target->GetEyePosition());
- VectorNormalize(dir);
- VectorNormalize(forward);
- if (dir.Length())
- dir /= dir.Length();
- float fov = forward.Dot(dir);
- fov *= 180 / M_PI;
- fov = abs(fov - 1);
- Msg("%f\n", fov);
- if (fov > *Vars.fov) continue;
- float dist = flGetDistance(me->GetAbsOrigin(), target->GetAbsOrigin());
- if (dist > BestDist) continue;
- Target = i;
- TargetEntity = target;
- BestDist = dist;
- }
- if (Target > 0 && TargetEntity)
- {
- RandomSeed(time(null));
- std::vector<int> bones = GetVisibleBones(TargetEntity);
- int rand = RandomInt(0, bones.size() - 1);
- bone = bones[rand];
- if (!GetBonePosition(bone, AimPoint, TargetEntity)) return false;
- AimPoint += RandomFloat(-20.f, 20.f);
- VectorAngles(AimPoint - me->GetEyePosition(), (QAngle&)AimAngle);
- return true;
- }
- return false;
- }
- void AimAt(Vector targetang)
- {
- Vector delta = Utils.GetAngles() - targetang;
- ClampAngles(delta);
- //Interfaces.Engine->SetViewAngles(Utils.GetAngles() - delta / RandomFloat(3.f,11.f));
- }
- bool IsBoneVisible(int bone, CBaseEntityNew* target)
- {
- Vector tempv;
- if (GetBonePosition(bone, tempv, target) && IsVisible(Utils.LocalPlayer()->GetEyePosition(), tempv, target))
- {
- return true;
- }
- return false;
- }
- void DoAimbot()
- {
- if (!GetAsyncKeyState(aimkey))
- {
- DropTarget();
- return;
- }
- static Vector PrevVelocity;
- CBaseEntityNew* me = Utils.LocalPlayer();
- if (!me) return;
- if (WaitUntil)
- {
- if (GetTickCount() >= WaitTill)
- WaitUntil = false;
- return;
- }
- if (AimState == NoTarget)
- {
- if (FindTarget())
- {
- AimState = AimingTarget;
- }
- }
- switch (AimState)
- {
- case NoTarget:
- return;
- break;
- case ReachLocation:
- if (fabs((Utils.GetAngles().x - GetPunch().x) - AimAngle.x) <= 1.f || fabs((Utils.GetAngles().y - GetPunch().y) - AimAngle.y) <= 1.f)
- {
- WaitUntil = true;
- WaitTill = GetTickCount() + TIME_BEFORE_ADJUSTEMENT;
- AimState = AimingTarget;
- }
- break;
- case AimingTarget:
- if (!IsTargetValid(TargetEntity) || !IsBoneVisible(bone,TargetEntity))
- {
- DropTarget();
- WaitUntil = true;
- WaitTill = GetTickCount() + TIME_BEFORE_NEW_TARGET;
- return;
- }
- Vector velocity = TargetEntity->GetVelocity();
- 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))
- {
- WaitUntil = true;
- WaitTill = GetTickCount() + TIME_BEFORE_ADJUSTEMENT;
- }
- PrevVelocity = velocity;
- if (GetBonePosition(bone, AimPoint, TargetEntity))
- VectorAngles(AimPoint - me->GetEyePosition(), (QAngle&)AimAngle);
- break;
- }
- if (AimState > NoTarget)
- {
- AimAt(AimAngle - GetPunch());
- }
- }
- private:
- float flGetDistance(Vector from, Vector to)
- {
- Vector angle;
- angle.x = to.x - from.x; angle.y = to.y - from.y; angle.z = to.z - from.z;
- return sqrt(angle.x*angle.x + angle.y*angle.y + angle.z*angle.z);
- }
- void MakeVector(Vector &angle, Vector &vector)
- {
- float pitch = float(angle[0] * M_PI / 180);
- float yaw = float(angle[1] * M_PI / 180);
- float tmp = float(cos(pitch));
- vector[0] = float(-tmp * -cos(yaw));
- vector[1] = float(sin(yaw)*tmp);
- vector[2] = float(-sin(pitch));
- }
- int Target;
- float BestDist;
- };
Advertisement
Add Comment
Please, Sign In to add comment