-
Notifications
You must be signed in to change notification settings - Fork 0
/
knifebot.cpp
174 lines (131 loc) · 4.17 KB
/
knifebot.cpp
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "includes.h"
void Aimbot::knife( ) {
struct KnifeTarget_t { bool stab; ang_t angle; LagRecord* record; };
KnifeTarget_t target{};
// we have no targets.
if( m_targets.empty( ) )
return;
// iterate all targets.
for( const auto& t : m_targets ) {
// this target has no records
// should never happen since it wouldnt be a target then.
if( t->m_records.empty( ) )
continue;
// see if target broke lagcomp.
if( g_menu.main.aimbot.lagfix.get( ) && g_lagcomp.StartPrediction( t ) ) {
LagRecord* front = t->m_records.front( ).get( );
front->cache( );
// trace with front.
for( const auto& a : m_knife_ang ) {
// check if we can knife.
if( !CanKnife( front, a, target.stab ) )
continue;
// set target data.
target.angle = a;
target.record = front;
break;
}
}
// we can history aim.
else {
LagRecord* best = g_resolver.FindIdealRecord( t );
if( !best )
continue;
best->cache( );
// trace with best.
for( const auto& a : m_knife_ang ) {
// check if we can knife.
if( !CanKnife( best, a, target.stab ) )
continue;
// set target data.
target.angle = a;
target.record = best;
break;
}
LagRecord* last = g_resolver.FindLastRecord( t );
if( !last || last == best )
continue;
last->cache( );
// trace with last.
for( const auto& a : m_knife_ang ) {
// check if we can knife.
if( !CanKnife( last, a, target.stab ) )
continue;
// set target data.
target.angle = a;
target.record = last;
break;
}
}
// target player has been found already.
if( target.record )
break;
}
// we found a target.
// set out data and choke.
if( target.record ) {
// set target tick.
g_cl.m_cmd->m_tick = game::TIME_TO_TICKS( target.record->m_pred_time + g_cl.m_lerp );
// set view angles.
g_cl.m_cmd->m_view_angles = target.angle;
// set attack1 or attack2.
g_cl.m_cmd->m_buttons |= target.stab ? IN_ATTACK2 : IN_ATTACK;
// choke.
*g_cl.m_packet = false;
}
}
bool Aimbot::CanKnife( LagRecord* record, ang_t angle, bool& stab ) {
// convert target angle to direction.
vec3_t forward;
math::AngleVectors( angle, &forward );
// see if we can hit the player with full range
// this means no stab.
CGameTrace trace;
KnifeTrace( forward, false, &trace );
// we hit smthing else than we were looking for.
if( !trace.m_entity || trace.m_entity != record->m_player )
return false;
bool armor = record->m_player->m_ArmorValue( ) > 0;
bool first = g_cl.m_weapon->m_flNextPrimaryAttack( ) + 0.4f < g_csgo.m_globals->m_curtime;
bool back = KnifeIsBehind( record );
int stab_dmg = m_knife_dmg.stab[ armor ][ back ];
int slash_dmg = m_knife_dmg.swing[ first ][ armor ][ back ];
int swing_dmg = m_knife_dmg.swing[ false ][ armor ][ back ];
// smart knifebot.
int health = record->m_player->m_iHealth( );
if( health <= slash_dmg )
stab = false;
else if( health <= stab_dmg )
stab = true;
else if( health > ( slash_dmg + swing_dmg + stab_dmg ) )
stab = true;
else
stab = false;
// damage wise a stab would be sufficient here.
if( stab && !KnifeTrace( forward, true, &trace ) )
return false;
return true;
}
bool Aimbot::KnifeTrace( vec3_t dir, bool stab, CGameTrace* trace ) {
float range = stab ? 32.f : 48.f;
vec3_t start = g_cl.m_shoot_pos;
vec3_t end = start + ( dir * range );
CTraceFilterSimple filter;
filter.SetPassEntity( g_cl.m_local );
g_csgo.m_engine_trace->TraceRay( Ray( start, end ), MASK_SOLID, &filter, trace );
// if the above failed try a hull trace.
if( trace->m_fraction >= 1.f ) {
g_csgo.m_engine_trace->TraceRay( Ray( start, end, { -16.f, -16.f, -18.f }, { 16.f, 16.f, 18.f } ), MASK_SOLID, &filter, trace );
return trace->m_fraction < 1.f;
}
return true;
}
bool Aimbot::KnifeIsBehind( LagRecord* record ) {
vec3_t delta{ record->m_origin - g_cl.m_shoot_pos };
delta.z = 0.f;
delta.normalize( );
vec3_t target;
math::AngleVectors( record->m_abs_ang, &target );
target.z = 0.f;
return delta.dot( target ) > 0.475f;
}