-
Notifications
You must be signed in to change notification settings - Fork 42
/
target_selection.cpp
430 lines (338 loc) · 12.4 KB
/
target_selection.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
#include "target_selection.h"
#include "context.h"
#include "autowall.h"
#include "playerlist.h"
#include "boner.h"
#include "resolver.h"
c_target_selector g_target_selector;
bool c_target_selector::is_hitbox_checked( int index, int hitbox )
{
auto data = g_playerlist.at( index );
if ( !data->is_cheater )
return hitbox == HITBOX_HEAD || hitbox == HITBOX_PELVIS;
has_remaining_shots[index] = ( ctx.m_missed_shots[index] < ctx.m_settings.rage_max_misses );
auto weapon = ctx.m_local->weapon( );
if ( weapon && weapon->item_index( ) == WEAPON_TASER )
has_remaining_shots[index] = false;
if ( ctx.m_settings.rage_baim_fakewalk && data->is_fakewalking )
has_remaining_shots[index] = false;
if ( !has_remaining_shots[index] )
{
switch ( hitbox )
{
case HITBOX_PELVIS:
case HITBOX_CHEST:
case HITBOX_THORAX:
return true;
default:
return false;
}
}
switch ( hitbox )
{
case HITBOX_HEAD:
case HITBOX_PELVIS:
case HITBOX_BODY:
case HITBOX_THORAX:
case HITBOX_UPPER_CHEST:
case HITBOX_RIGHT_UPPER_ARM:
case HITBOX_LEFT_UPPER_ARM:
case HITBOX_RIGHT_HAND:
case HITBOX_LEFT_HAND:
case HITBOX_RIGHT_THIGH:
case HITBOX_LEFT_THIGH:
case HITBOX_RIGHT_FOOT:
case HITBOX_LEFT_FOOT:
return true;
default:
return false;
}
}
bool c_target_selector::find_normal_target( possible_target_t& target )
{
possible_targets.clear( );
int local_team = ctx.m_local->team( );
for ( int i = 1; i < 65; i++ )
{
auto possible_target = csgo.m_entity_list( )->get_entity( i );
if ( !possible_target || possible_target == ctx.m_local )
continue;
if ( possible_target->dormant( ) || !possible_target->alive( ) || possible_target->immune( ) )
continue;
if ( possible_target->team( ) == local_team )
continue;
auto data = g_playerlist.at( possible_target->index( ) );
matrix3x4_t matrix[128];
if ( !g_boner.get_latest( possible_target->index( ), matrix ) )
continue;
std::vector< possible_point_t > points;
for ( auto hitbox_index = 0; hitbox_index < HITBOX_MAX; hitbox_index++ )
{
if ( !is_hitbox_checked( i, hitbox_index ) )
continue;
auto is_save_fps_hitbox = [](int hitbox) -> bool
{
switch ( hitbox )
{
case HITBOX_HEAD:
case HITBOX_PELVIS:
case HITBOX_CHEST:
case HITBOX_RIGHT_FOOT:
case HITBOX_LEFT_FOOT:
return true;
default:
return false;
}
};
if ( !is_save_fps_hitbox( hitbox_index ) && ctx.m_settings.rage_save_fps )
continue;
auto hitbox = possible_target->get_hitbox( hitbox_index );
if ( !hitbox )
continue;
if ( !g_aimbot.can_hit_point_estimate( possible_target, hitbox_index ) )
continue;
const float pointscale = 0.8f;
// this stuff needs rewrite
const float hitbox_radius = hitbox->m_Radius * pointscale;
vec3 min = hitbox->m_Mins, max = hitbox->m_Maxs;
hitbox->m_Mins = math::VectorRotate( hitbox->m_Mins, hitbox->m_Rotation );
hitbox->m_Maxs = math::VectorRotate( hitbox->m_Maxs, hitbox->m_Rotation );
math::VectorTransformASM( &hitbox->m_Mins[0], matrix[hitbox->m_Bone], &min[0] );
math::VectorTransformASM( &hitbox->m_Maxs[0], matrix[hitbox->m_Bone], &max[0] );
auto center = ( min + max ) * 0.5f;
if ( hitbox->m_Radius == -1.f )
{
points.emplace_back( center, hitbox_index );
points.emplace_back( lerp( center, vec3( min.x, min.y, min.z ), pointscale ), hitbox_index );
points.emplace_back( lerp( center, vec3( min.x, max.y, min.z ), pointscale ), hitbox_index );
points.emplace_back( lerp( center, vec3( max.x, max.y, min.z ), pointscale ), hitbox_index );
points.emplace_back( lerp( center, vec3( max.x, min.y, min.z ), pointscale ), hitbox_index );
points.emplace_back( lerp( center, vec3( min.x, min.y, max.z ), pointscale ), hitbox_index );
points.emplace_back( lerp( center, vec3( min.x, max.y, max.z ), pointscale ), hitbox_index );
points.emplace_back( lerp( center, vec3( max.x, max.y, max.z ), pointscale ), hitbox_index );
points.emplace_back( lerp( center, vec3( max.x, min.y, max.z ), pointscale ), hitbox_index );
}
else
{
points.emplace_back( center, hitbox_index );
points.emplace_back( vec3( min.x + hitbox_radius, min.y, min.z ), hitbox_index );
points.emplace_back( vec3( min.x - hitbox_radius, min.y, min.z ), hitbox_index );
points.emplace_back( vec3( min.x, min.y + hitbox_radius, min.z ), hitbox_index );
points.emplace_back( vec3( min.x, min.y - hitbox_radius, min.z ), hitbox_index );
points.emplace_back( vec3( min.x, min.y, min.z + hitbox_radius ), hitbox_index );
points.emplace_back( vec3( min.x, min.y, min.z - hitbox_radius ), hitbox_index );
points.emplace_back( vec3( max.x + hitbox_radius, max.y, max.z ), hitbox_index );
points.emplace_back( vec3( max.x - hitbox_radius, max.y, max.z ), hitbox_index );
points.emplace_back( vec3( max.x, max.y + hitbox_radius, max.z ), hitbox_index );
points.emplace_back( vec3( max.x, max.y - hitbox_radius, max.z ), hitbox_index );
points.emplace_back( vec3( max.x, max.y, max.z + hitbox_radius ), hitbox_index );
points.emplace_back( vec3( max.x, max.y, max.z - hitbox_radius ), hitbox_index );
}
}
possible_targets.emplace_back( data, points );
}
if ( possible_targets.empty( ) )
return false;
std::sort( possible_targets.begin( ), possible_targets.end( ), []( const possible_target_t& a, const possible_target_t& b) -> bool
{
// cheaters are always first
if ( a.m_data->is_cheater != b.m_data->is_cheater )
return a.m_data->is_cheater > b.m_data->is_cheater;
// don't bother baiming legits
bool force_baim = a.m_data->is_cheater && ctx.m_settings.rage_aim_mode == 2;
bool should_baim = a.m_data->is_cheater && ctx.m_settings.rage_aim_mode == 1;
// check if we can resolve them when not forcing baim
if ( !force_baim && should_baim )
{
bool a_can_resolve = g_resolver.has_logged_shot( a.m_data->index );
bool b_can_resolve = g_resolver.has_logged_shot( b.m_data->index );
if ( a_can_resolve != b_can_resolve )
return a_can_resolve > b_can_resolve;
}
// sort targets by selection type
switch ( ctx.m_settings.rage_selection )
{
case 0: // fov
{
auto get_fov = [&]( const vec3& aim_angle ) -> float
{
vec3 ang, aim;
math::angle_vectors( ctx.m_local->eye_origin( ), &ang );
math::angle_vectors( aim_angle, &aim );
return math::rad2deg( acos( aim.dot( ang ) / ( ang.dot( aim ) ) ) );
};
return get_fov( a.m_data->base->eye_origin( ) ) < get_fov( b.m_data->base->eye_origin( ) );
}
case 1: // distance
return ctx.m_local->origin( ).dist( a.m_data->origin ) < ctx.m_local->origin( ).dist( b.m_data->origin );
case 2: // lag
return a.m_data->simtime > b.m_data->simtime;
case 3: // health
return a.m_data->health < b.m_data->health;
default: // default to cycle
case 4: // cycle
return rand( ) % 2 == 0;
}
} );
auto sorted_target = possible_targets.front( );
possible_point_t best_point( vec3( 0, 0, 0 ), -1 );
for ( auto i = 0; i < sorted_target.m_points.size( ); i++ )
{
auto cur_point = sorted_target.m_points.at( i );
bool force_baim = sorted_target.m_data->is_cheater && ctx.m_settings.rage_aim_mode == 2;
bool should_baim = sorted_target.m_data->is_cheater && ctx.m_settings.rage_aim_mode == 1;
bool can_resolve = g_resolver.has_logged_shot( sorted_target.m_data->index );
if ( !force_baim && should_baim )
force_baim = !can_resolve;
if ( force_baim )
{
bool cur_baim = cur_point.m_target_hitbox >= HITBOX_PELVIS && cur_point.m_target_hitbox <= HITBOX_UPPER_CHEST;
bool best_baim = best_point.m_target_hitbox >= HITBOX_PELVIS && best_point.m_target_hitbox <= HITBOX_UPPER_CHEST;
if ( cur_baim && !best_baim )
{
best_point = cur_point;
continue;
}
}
if ( should_baim )
{
bool cur_baim = cur_point.m_target_hitbox == HITBOX_PELVIS;
bool best_baim = best_point.m_target_hitbox == HITBOX_PELVIS;
if ( cur_baim && !best_baim )
{
best_point = cur_point;
continue;
}
}
// bye foot fetish
// because legs are not protected by armor, damage based selection tends to favour shooting at legs/feet
// considering legs/feet aren't the most reliable in CSGO, its best to just skip em when possible
{
bool cur_leg = cur_point.m_target_hitbox >= HITBOX_RIGHT_THIGH && cur_point.m_target_hitbox <= HITBOX_LEFT_FOOT;
bool best_leg = best_point.m_target_hitbox >= HITBOX_RIGHT_THIGH && best_point.m_target_hitbox <= HITBOX_LEFT_FOOT;
if ( !cur_leg && best_leg )
{
best_point = cur_point;
continue;
}
}
if ( !cur_point.m_checked_damage )
{
cur_point.m_damage = g_auto_wall.get_damage( ctx.m_local, sorted_target.m_data->base, cur_point.m_aimpoint );
cur_point.m_checked_damage = true;
}
if ( cur_point.m_damage < ctx.m_settings.rage_autowall_damage )
continue;
if ( cur_point.m_damage >= sorted_target.m_data->health )
{
cur_point.m_damage = 100.f;
if ( cur_point.m_target_hitbox >= HITBOX_PELVIS )
cur_point.m_damage += 1.f;
if ( cur_point.m_target_hitbox >= HITBOX_PELVIS && cur_point.m_target_hitbox <= HITBOX_UPPER_CHEST )
cur_point.m_damage += 1.f;
}
{
bool cur_head = cur_point.m_target_hitbox >= HITBOX_HEAD == cur_point.m_target_hitbox <= HITBOX_NECK;
float required_shot = sorted_target.m_data->health * 0.5f + 1.f;
if ( !cur_head && cur_point.m_damage > required_shot )
{
best_point = cur_point;
continue;
}
}
//if ( !cur_point.m_checked_hitchance )
//{
// vec3 aim_angle;
// math::vector_angles( cur_point.m_aimpoint, aim_angle );
//
// if ( !g_aimbot.can_hit_point( aim_angle, sorted_target.m_data->base ) )
// {
// cur_point.m_checked_hitchance = true;
// continue;
// }
//
// cur_point.m_checked_hitchance = true;
//}
if ( cur_point.m_damage > best_point.m_damage )
best_point = cur_point;
}
if ( best_point.m_target_hitbox == -1 )
return false;
sorted_target.m_final_aimpoint = best_point.m_aimpoint;
target = sorted_target;
return true;
}
bool c_target_selector::find_backtrack_target( possible_target_t& target )
{
return false;
}
bool c_target_selector::find_target( possible_target_t& target )
{
if ( !ctx.m_local )
return false;
if ( find_normal_target( target ) )
return true;
if ( find_backtrack_target( target ) )
return true;
return false;
}
int c_target_selector::get_highest_threat( )
{
if ( !ctx.m_local || !ctx.m_local->alive( ) )
return 0;
static int latest_tick{ };
static int latest_target{ };
if ( latest_tick == csgo.m_globals( )->tickcount )
return latest_target;
int local_team = ctx.m_local->team( );
vec3 local_pos = ctx.m_local->origin( ) + vec3( 0.f, 0.f, 32.f );
bool found_cheater{ };
int threat_counter{ };
const player_data_t* threats[65];
for ( int i = 0; i < 65; i++ )
{
auto player_data = g_playerlist.at( i );
if ( !player_data->is_valid )
continue;
if ( player_data->is_dormant || !player_data->is_alive || player_data->is_immune || player_data->is_teammate )
continue;
if ( player_data->is_cheater )
found_cheater = true;
threats[threat_counter++] = player_data;
}
//we didnt find any possible threats
if ( !threat_counter )
{
latest_tick = csgo.m_globals( )->tickcount;
latest_target = 0;
return 0;
}
int highest_threat{ };
float distance = 9999.f;
for ( int i = 0; i < threat_counter; i++ )
{
if ( found_cheater && !threats[i]->is_cheater )
continue;
c_base_entity* ent = threats[i]->base;
vec3 enemy_pos = ent->origin( );
enemy_pos.z += 64.f;
if ( g_auto_wall.is_visible( local_pos, enemy_pos, ctx.m_local, ent ) )
{
highest_threat = threats[i]->index;
break;
}
vec3 angle;
math::vector_angles( enemy_pos - local_pos, angle );
vec3 delta = angle - csgo.m_engine( )->GetViewAngles( );
delta.sanitize( );
float dist = delta.length2d( );
if ( distance > dist )
{
highest_threat = threats[i]->index;
distance = dist;
}
}
latest_tick = csgo.m_globals( )->tickcount;
latest_target = highest_threat;
return highest_threat;
}