forked from icantstandpeople/potassium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAimbot.cpp
More file actions
148 lines (107 loc) · 3.23 KB
/
Aimbot.cpp
File metadata and controls
148 lines (107 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "Aimbot.h"
#include "Util.h"
CAimbot gAim;
void CAimbot::Run(CBaseEntity* pLocal, CUserCmd* pCommand)
{
old_movement_t old_mov = old_movement_t();
if (gCvars.aimbot_silent) { // only backup the c_usercmd data when it's needed.
old_mov.angle = pCommand->viewangles;
old_mov.fwd = pCommand->forwardmove;
old_mov.sdm = pCommand->sidemove;
}
gCvars.iAimbotIndex = -1;
if (!gCvars.aimbot_active)
return;
if (!Util->IsKeyPressed(gCvars.aimbot_key))
return;
if (!pLocal->GetActiveWeapon())
return;
CBaseEntity* pEntity = GetBaseEntity(GetBestTarget(pLocal));
if (!pEntity)
return;
int iBestHitbox = GetBestHitbox(pLocal, pEntity);
if (iBestHitbox == -1)
return;
Vector vEntity = pEntity->GetHitboxPosition(iBestHitbox);
Vector vLocal = pLocal->GetEyePosition();
Vector vAngs;
VectorAngles((vEntity - vLocal), vAngs);
ClampAngle(vAngs);
gCvars.iAimbotIndex = pEntity->GetIndex();
pCommand->viewangles = vAngs; // always set this cuz otherwise the viewangles will desync.
if (!gCvars.aimbot_silent) {
gInts.Engine->SetViewAngles(pCommand->viewangles);
}
if (gCvars.aimbot_silent) { // apply our movement fix if silent aim is enabled.
Util->FixMovementForUserCmd(pCommand, old_mov);
}
if (gCvars.aimbot_autoshoot)
pCommand->buttons |= IN_ATTACK;
}
int CAimbot::GetBestTarget(CBaseEntity* pLocal)
{
int iBestTarget = -1;
//this num could be smaller
float flDistToBest = 99999.f;
Vector vLocal = pLocal->GetEyePosition();
for (int i = 1; i <= gInts.Engine->GetMaxClients(); i++)
{
if (i == me)
continue;
CBaseEntity* pEntity = GetBaseEntity(i);
if (!pEntity)
continue;
if (pEntity->IsDormant())
continue;
if (pEntity->GetLifeState() != LIFE_ALIVE ||
pEntity->GetTeamNum() == pLocal->GetTeamNum())
continue;
int iBestHitbox = GetBestHitbox(pLocal, pEntity);
if (iBestHitbox == -1)
continue;
Vector vEntity = pEntity->GetHitboxPosition(iBestHitbox); //pEntity->GetWorldSpaceCenter(vEntity);
if (!gCvars.PlayerMode[i])
continue;
if (pEntity->GetCond() & TFCond_Ubercharged ||
pEntity->GetCond() & TFCond_UberchargeFading ||
pEntity->GetCond() & TFCond_Bonked)
continue;
float flDistToTarget = (vLocal - vEntity).Length();
if (flDistToTarget < flDistToBest)
{
flDistToBest = flDistToTarget;
iBestTarget = i;
}
if (gCvars.PlayerMode[i] == 2) //always aim at rage targets first
return i;
}
return iBestTarget;
}
int CAimbot::GetBestHitbox(CBaseEntity* pLocal, CBaseEntity* pEntity)
{
int iBestHitbox = -1;
if (!gCvars.aimbot_hitbox)
{
if (Util->IsHeadshotWeapon(pLocal, pLocal->GetActiveWeapon()))
iBestHitbox = 0;
else
iBestHitbox = 4;
}
else
{
iBestHitbox = gCvars.aimbot_hitbox - 1;
}
if (gCvars.aimbot_hitscan)
{
for (int i = 0; i < 17; i++)
{
if (Util->IsVisible(pLocal, pEntity, pLocal->GetEyePosition(), pEntity->GetHitboxPosition(i)))
return i;
}
}
if (pEntity->GetHitboxPosition(iBestHitbox).IsZero())
return -1;
if (!Util->IsVisible(pLocal, pEntity, pLocal->GetEyePosition(), pEntity->GetHitboxPosition(iBestHitbox)))
return - 1;
return iBestHitbox;
}