forked from CSGOLeaks/supremacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaimbot.cpp
1152 lines (898 loc) · 33.1 KB
/
aimbot.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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "includes.h"
Aimbot g_aimbot{ };;
void AimPlayer::UpdateAnimations( LagRecord *record ) {
CCSGOPlayerAnimState *state = m_player->m_PlayerAnimState( );
if ( !state )
return;
// player respawned.
if ( m_player->m_flSpawnTime( ) != m_spawn ) {
// reset animation state.
game::ResetAnimationState( state );
// note new spawn time.
m_spawn = m_player->m_flSpawnTime( );
}
// backup curtime.
float curtime = g_csgo.m_globals->m_curtime;
float frametime = g_csgo.m_globals->m_frametime;
// set curtime to animtime.
// set frametime to ipt just like on the server during simulation.
g_csgo.m_globals->m_curtime = record->m_anim_time;
g_csgo.m_globals->m_frametime = g_csgo.m_globals->m_interval;
// backup stuff that we do not want to fuck with.
AnimationBackup_t backup;
backup.m_origin = m_player->m_vecOrigin( );
backup.m_abs_origin = m_player->GetAbsOrigin( );
backup.m_velocity = m_player->m_vecVelocity( );
backup.m_abs_velocity = m_player->m_vecAbsVelocity( );
backup.m_flags = m_player->m_fFlags( );
backup.m_eflags = m_player->m_iEFlags( );
backup.m_duck = m_player->m_flDuckAmount( );
backup.m_body = m_player->m_flLowerBodyYawTarget( );
m_player->GetAnimLayers( backup.m_layers );
// is player a bot?
bool bot = game::IsFakePlayer( m_player->index( ) );
// reset fakewalk state.
record->m_fake_walk = false;
record->m_mode = Resolver::Modes::RESOLVE_NONE;
// fix velocity.
// https://github.com/VSES/SourceEngine2007/blob/master/se2007/game/client/c_baseplayer.cpp#L659
if ( record->m_lag > 0 && record->m_lag < 16 && m_records.size( ) >= 2 ) {
// get pointer to previous record.
LagRecord *previous = m_records[ 1 ].get( );
if ( previous && !previous->dormant( ) )
record->m_velocity = ( record->m_origin - previous->m_origin ) * ( 1.f / game::TICKS_TO_TIME( record->m_lag ) );
}
// set this fucker, it will get overriden.
record->m_anim_velocity = record->m_velocity;
// fix various issues with the game eW91dHViZS5jb20vZHlsYW5ob29r
// these issues can only occur when a player is choking data.
if ( record->m_lag > 1 && !bot ) {
// detect fakewalk.
float speed = record->m_velocity.length( );
if ( record->m_flags & FL_ONGROUND && record->m_layers[ 6 ].m_weight == 0.f && speed > 0.1f && speed < 100.f )
record->m_fake_walk = true;
if ( record->m_fake_walk )
record->m_anim_velocity = record->m_velocity = { 0.f, 0.f, 0.f };
// we need atleast 2 updates/records
// to fix these issues.
if ( m_records.size( ) >= 2 ) {
// get pointer to previous record.
LagRecord *previous = m_records[ 1 ].get( );
if ( previous && !previous->dormant( ) ) {
// set previous flags.
m_player->m_fFlags( ) = previous->m_flags;
// strip the on ground flag.
m_player->m_fFlags( ) &= ~FL_ONGROUND;
// been onground for 2 consecutive ticks? fuck yeah.
if ( record->m_flags & FL_ONGROUND && previous->m_flags & FL_ONGROUND )
m_player->m_fFlags( ) |= FL_ONGROUND;
//if( record->m_layers[ 4 ].m_weight != 0.f && previous->m_layers[ 4 ].m_weight == 0.f && record->m_layers[ 5 ].m_weight != 0.f )
// m_player->m_fFlags( ) |= FL_ONGROUND;
// fix jump_fall.
if ( record->m_layers[ 4 ].m_weight != 1.f && previous->m_layers[ 4 ].m_weight == 1.f && record->m_layers[ 5 ].m_weight != 0.f )
m_player->m_fFlags( ) |= FL_ONGROUND;
if ( record->m_flags & FL_ONGROUND && !( previous->m_flags & FL_ONGROUND ) )
m_player->m_fFlags( ) &= ~FL_ONGROUND;
// fix crouching players.
// the duck amount we receive when people choke is of the last simulation.
// if a player chokes packets the issue here is that we will always receive the last duckamount.
// but we need the one that was animated.
// therefore we need to compute what the duckamount was at animtime.
// delta in duckamt and delta in time..
float duck = record->m_duck - previous->m_duck;
float time = record->m_sim_time - previous->m_sim_time;
// get the duckamt change per tick.
float change = ( duck / time ) * g_csgo.m_globals->m_interval;
// fix crouching players.
m_player->m_flDuckAmount( ) = previous->m_duck + change;
if ( !record->m_fake_walk ) {
// fix the velocity till the moment of animation.
vec3_t velo = record->m_velocity - previous->m_velocity;
// accel per tick.
vec3_t accel = ( velo / time ) * g_csgo.m_globals->m_interval;
// set the anim velocity to the previous velocity.
// and predict one tick ahead.
record->m_anim_velocity = previous->m_velocity + accel;
}
}
}
}
// // better fake angle detection.
// size_t consistency{};
// size_t size = std::min( 5u, m_records.size( ) );
//
// for( size_t i{}; i < size; i++ ) {
// // if we have lag on this record.
// if( m_records[ i ].get( )->m_lag > 1 )
// ++consistency;
// }
//
// // compute lag consistency scale.
// float scale = ( float )consistency / ( float )size;
//
// // if faking angles more than 80% of the time
// // and not bot, player uses fake angles.
// bool fake = g_menu.main.aimbot.correct.get( ) && !bot && scale > 0.8f;
// size_t consistency{ 0u };
// size_t size{ m_records.size( ) };
//
// // add up records the player didn't lag.
// for( size_t i{ 0u }; i < size; i++ ) {
// if( m_records[ i ].get( )->m_lag < 1 )
// ++consistency;
// }
//
// // compute lag consistency scale.
// float scale = ( float )consistency / size;
//
// // lagged too much.
// bool fake = !bot && scale < 0.5f;
bool fake = !bot && g_menu.main.aimbot.correct.get( );
// if using fake angles, correct angles.
if ( fake )
g_resolver.ResolveAngles( m_player, record );
// set stuff before animating.
m_player->m_vecOrigin( ) = record->m_origin;
m_player->m_vecVelocity( ) = m_player->m_vecAbsVelocity( ) = record->m_anim_velocity;
m_player->m_flLowerBodyYawTarget( ) = record->m_body;
// EFL_DIRTY_ABSVELOCITY
// skip call to C_BaseEntity::CalcAbsoluteVelocity
m_player->m_iEFlags( ) &= ~0x1000;
// write potentially resolved angles.
m_player->m_angEyeAngles( ) = record->m_eye_angles;
// fix animating in same frame.
if ( state->m_frame == g_csgo.m_globals->m_frame )
state->m_frame -= 1;
// 'm_animating' returns true if being called from SetupVelocity, passes raw velocity to animstate.
m_player->m_bClientSideAnimation( ) = true;
m_player->UpdateClientSideAnimation( );
m_player->m_bClientSideAnimation( ) = false;
// correct poses if fake angles.
if ( fake )
g_resolver.ResolvePoses( m_player, record );
// store updated/animated poses and rotation in lagrecord.
m_player->GetPoseParameters( record->m_poses );
record->m_abs_ang = m_player->GetAbsAngles( );
// restore backup data.
m_player->m_vecOrigin( ) = backup.m_origin;
m_player->m_vecVelocity( ) = backup.m_velocity;
m_player->m_vecAbsVelocity( ) = backup.m_abs_velocity;
m_player->m_fFlags( ) = backup.m_flags;
m_player->m_iEFlags( ) = backup.m_eflags;
m_player->m_flDuckAmount( ) = backup.m_duck;
m_player->m_flLowerBodyYawTarget( ) = backup.m_body;
m_player->SetAbsOrigin( backup.m_abs_origin );
m_player->SetAnimLayers( backup.m_layers );
// IMPORTANT: do not restore poses here, since we want to preserve them for rendering.
// also dont restore the render angles which indicate the model rotation.
// restore globals.
g_csgo.m_globals->m_curtime = curtime;
g_csgo.m_globals->m_frametime = frametime;
}
void AimPlayer::OnNetUpdate( Player *player ) {
bool reset = ( !g_menu.main.aimbot.enable.get( ) || player->m_lifeState( ) == LIFE_DEAD || !player->enemy( g_cl.m_local ) );
bool disable = ( !reset && !g_cl.m_processing );
// if this happens, delete all the lagrecords.
if ( reset ) {
player->m_bClientSideAnimation( ) = true;
m_records.clear( );
return;
}
// just disable anim if this is the case.
if ( disable ) {
player->m_bClientSideAnimation( ) = true;
return;
}
// update player ptr if required.
// reset player if changed.
if ( m_player != player )
m_records.clear( );
// update player ptr.
m_player = player;
// indicate that this player has been out of pvs.
// insert dummy record to separate records
// to fix stuff like animation and prediction.
if ( player->dormant( ) ) {
bool insert = true;
// we have any records already?
if ( !m_records.empty( ) ) {
LagRecord *front = m_records.front( ).get( );
// we already have a dormancy separator.
if ( front->dormant( ) )
insert = false;
}
if ( insert ) {
// add new record.
m_records.emplace_front( std::make_shared< LagRecord >( player ) );
// get reference to newly added record.
LagRecord *current = m_records.front( ).get( );
// mark as dormant.
current->m_dormant = true;
}
}
bool update = ( m_records.empty( ) || player->m_flSimulationTime( ) > m_records.front( ).get( )->m_sim_time );
if ( !update && !player->dormant( ) && player->m_vecOrigin( ) != player->m_vecOldOrigin( ) ) {
update = true;
// fix data.
player->m_flSimulationTime( ) = game::TICKS_TO_TIME( g_csgo.m_cl->m_server_tick );
}
// this is the first data update we are receving
// OR we received data with a newer simulation context.
if ( update ) {
// add new record.
m_records.emplace_front( std::make_shared< LagRecord >( player ) );
// get reference to newly added record.
LagRecord *current = m_records.front( ).get( );
// mark as non dormant.
current->m_dormant = false;
// update animations on current record.
// call resolver.
UpdateAnimations( current );
// create bone matrix for this record.
g_bones.setup( m_player, nullptr, current );
}
// no need to store insane amt of data.
while ( m_records.size( ) > 256 )
m_records.pop_back( );
}
void AimPlayer::OnRoundStart( Player *player ) {
m_player = player;
m_walk_record = LagRecord{ };
m_shots = 0;
m_missed_shots = 0;
// reset stand and body index.
m_stand_index = 0;
m_stand_index2 = 0;
m_body_index = 0;
m_records.clear( );
m_hitboxes.clear( );
// IMPORTANT: DO NOT CLEAR LAST HIT SHIT.
}
void AimPlayer::SetupHitboxes( LagRecord *record, bool history ) {
// reset hitboxes.
m_hitboxes.clear( );
if ( g_cl.m_weapon_id == ZEUS ) {
// hitboxes for the zeus.
m_hitboxes.push_back( { HITBOX_BODY, HitscanMode::PREFER } );
return;
}
// prefer, always.
if ( g_menu.main.aimbot.baim1.get( 0 ) )
m_hitboxes.push_back( { HITBOX_BODY, HitscanMode::PREFER } );
// prefer, lethal.
if ( g_menu.main.aimbot.baim1.get( 1 ) )
m_hitboxes.push_back( { HITBOX_BODY, HitscanMode::LETHAL } );
// prefer, lethal x2.
if ( g_menu.main.aimbot.baim1.get( 2 ) )
m_hitboxes.push_back( { HITBOX_BODY, HitscanMode::LETHAL2 } );
// prefer, fake.
if ( g_menu.main.aimbot.baim1.get( 3 ) && record->m_mode != Resolver::Modes::RESOLVE_NONE && record->m_mode != Resolver::Modes::RESOLVE_WALK )
m_hitboxes.push_back( { HITBOX_BODY, HitscanMode::PREFER } );
// prefer, in air.
if ( g_menu.main.aimbot.baim1.get( 4 ) && !( record->m_pred_flags & FL_ONGROUND ) )
m_hitboxes.push_back( { HITBOX_BODY, HitscanMode::PREFER } );
bool only{ false };
// only, always.
if ( g_menu.main.aimbot.baim2.get( 0 ) ) {
only = true;
m_hitboxes.push_back( { HITBOX_BODY, HitscanMode::PREFER } );
}
// only, health.
if ( g_menu.main.aimbot.baim2.get( 1 ) && m_player->m_iHealth( ) <= ( int )g_menu.main.aimbot.baim_hp.get( ) ) {
only = true;
m_hitboxes.push_back( { HITBOX_BODY, HitscanMode::PREFER } );
}
// only, fake.
if ( g_menu.main.aimbot.baim2.get( 2 ) && record->m_mode != Resolver::Modes::RESOLVE_NONE && record->m_mode != Resolver::Modes::RESOLVE_WALK ) {
only = true;
m_hitboxes.push_back( { HITBOX_BODY, HitscanMode::PREFER } );
}
// only, in air.
if ( g_menu.main.aimbot.baim2.get( 3 ) && !( record->m_pred_flags & FL_ONGROUND ) ) {
only = true;
m_hitboxes.push_back( { HITBOX_BODY, HitscanMode::PREFER } );
}
// only, on key.
if ( g_input.GetKeyState( g_menu.main.aimbot.baim_key.get( ) ) ) {
only = true;
m_hitboxes.push_back( { HITBOX_BODY, HitscanMode::PREFER } );
}
// only baim conditions have been met.
// do not insert more hitboxes.
if ( only )
return;
std::vector< size_t > hitbox{ history ? g_menu.main.aimbot.hitbox_history.GetActiveIndices( ) : g_menu.main.aimbot.hitbox.GetActiveIndices( ) };
if ( hitbox.empty( ) )
return;
for ( const auto &h : hitbox ) {
// head.
if ( h == 0 )
m_hitboxes.push_back( { HITBOX_HEAD, HitscanMode::NORMAL } );
// chest.
if ( h == 1 ) {
m_hitboxes.push_back( { HITBOX_THORAX, HitscanMode::NORMAL } );
m_hitboxes.push_back( { HITBOX_CHEST, HitscanMode::NORMAL } );
m_hitboxes.push_back( { HITBOX_UPPER_CHEST, HitscanMode::NORMAL } );
}
// stomach.
if ( h == 2 ) {
m_hitboxes.push_back( { HITBOX_PELVIS, HitscanMode::NORMAL } );
m_hitboxes.push_back( { HITBOX_BODY, HitscanMode::NORMAL } );
}
// arms.
if ( h == 3 ) {
m_hitboxes.push_back( { HITBOX_L_UPPER_ARM, HitscanMode::NORMAL } );
m_hitboxes.push_back( { HITBOX_R_UPPER_ARM, HitscanMode::NORMAL } );
}
// legs.
if ( h == 4 ) {
m_hitboxes.push_back( { HITBOX_L_THIGH, HitscanMode::NORMAL } );
m_hitboxes.push_back( { HITBOX_R_THIGH, HitscanMode::NORMAL } );
m_hitboxes.push_back( { HITBOX_L_CALF, HitscanMode::NORMAL } );
m_hitboxes.push_back( { HITBOX_R_CALF, HitscanMode::NORMAL } );
m_hitboxes.push_back( { HITBOX_L_FOOT, HitscanMode::NORMAL } );
m_hitboxes.push_back( { HITBOX_R_FOOT, HitscanMode::NORMAL } );
}
}
}
void Aimbot::init( ) {
// clear old targets.
m_targets.clear( );
m_target = nullptr;
m_aim = vec3_t{ };
m_angle = ang_t{ };
m_damage = 0.f;
m_record = nullptr;
m_stop = false;
m_best_dist = std::numeric_limits< float >::max( );
m_best_fov = 180.f + 1.f;
m_best_damage = 0.f;
m_best_hp = 100 + 1;
m_best_lag = std::numeric_limits< float >::max( );
m_best_height = std::numeric_limits< float >::max( );
}
void Aimbot::StripAttack( ) {
if ( g_cl.m_weapon_id == REVOLVER )
g_cl.m_cmd->m_buttons &= ~IN_ATTACK2;
else
g_cl.m_cmd->m_buttons &= ~IN_ATTACK;
}
void Aimbot::think( ) {
// do all startup routines.
init( );
// sanity.
if ( !g_cl.m_weapon )
return;
// no grenades or bomb.
if ( g_cl.m_weapon_type == WEAPONTYPE_GRENADE || g_cl.m_weapon_type == WEAPONTYPE_C4 )
return;
if ( !g_cl.m_weapon_fire )
StripAttack( );
// we have no aimbot enabled.
if ( !g_menu.main.aimbot.enable.get( ) )
return;
// animation silent aim, prevent the ticks with the shot in it to become the tick that gets processed.
// we can do this by always choking the tick before we are able to shoot.
bool revolver = g_cl.m_weapon_id == REVOLVER && g_cl.m_revolver_cock != 0;
// one tick before being able to shoot.
if ( revolver && g_cl.m_revolver_cock > 0 && g_cl.m_revolver_cock == g_cl.m_revolver_query ) {
*g_cl.m_packet = false;
return;
}
// we have a normal weapon or a non cocking revolver
// choke if its the processing tick.
if ( g_cl.m_weapon_fire && !g_cl.m_lag && !revolver ) {
*g_cl.m_packet = false;
StripAttack( );
return;
}
// no point in aimbotting if we cannot fire this tick.
if ( !g_cl.m_weapon_fire )
return;
// setup bones for all valid targets.
for ( int i{ 1 }; i <= g_csgo.m_globals->m_max_clients; ++i ) {
Player *player = g_csgo.m_entlist->GetClientEntity< Player * >( i );
if ( !IsValidTarget( player ) )
continue;
AimPlayer *data = &m_players[ i - 1 ];
if ( !data )
continue;
// store player as potential target this tick.
m_targets.emplace_back( data );
}
// run knifebot.
if ( g_cl.m_weapon_type == WEAPONTYPE_KNIFE && g_cl.m_weapon_id != ZEUS ) {
if ( g_menu.main.aimbot.knifebot.get( ) )
knife( );
return;
}
// scan available targets... if we even have any.
find( );
// finally set data when shooting.
apply( );
}
void Aimbot::find( ) {
struct BestTarget_t { Player *player; vec3_t pos; float damage; LagRecord *record; };
vec3_t tmp_pos;
float tmp_damage;
BestTarget_t best;
best.player = nullptr;
best.damage = -1.f;
best.pos = vec3_t{ };
best.record = nullptr;
if ( m_targets.empty( ) )
return;
if ( g_cl.m_weapon_id == ZEUS && !g_menu.main.aimbot.zeusbot.get( ) )
return;
// iterate all targets.
for ( const auto &t : m_targets ) {
if ( t->m_records.empty( ) )
continue;
// this player broke lagcomp.
// his bones have been resetup by our lagcomp.
// therfore now only the front record is valid.
if ( g_menu.main.aimbot.lagfix.get( ) && g_lagcomp.StartPrediction( t ) ) {
LagRecord *front = t->m_records.front( ).get( );
t->SetupHitboxes( front, false );
if ( t->m_hitboxes.empty( ) )
continue;
// rip something went wrong..
if ( t->GetBestAimPosition( tmp_pos, tmp_damage, front ) && SelectTarget( front, tmp_pos, tmp_damage ) ) {
// if we made it so far, set shit.
best.player = t->m_player;
best.pos = tmp_pos;
best.damage = tmp_damage;
best.record = front;
}
}
// player did not break lagcomp.
// history aim is possible at this point.
else {
LagRecord *ideal = g_resolver.FindIdealRecord( t );
if ( !ideal )
continue;
t->SetupHitboxes( ideal, false );
if ( t->m_hitboxes.empty( ) )
continue;
// try to select best record as target.
if ( t->GetBestAimPosition( tmp_pos, tmp_damage, ideal ) && SelectTarget( ideal, tmp_pos, tmp_damage ) ) {
// if we made it so far, set shit.
best.player = t->m_player;
best.pos = tmp_pos;
best.damage = tmp_damage;
best.record = ideal;
}
LagRecord *last = g_resolver.FindLastRecord( t );
if ( !last || last == ideal )
continue;
t->SetupHitboxes( last, true );
if ( t->m_hitboxes.empty( ) )
continue;
// rip something went wrong..
if ( t->GetBestAimPosition( tmp_pos, tmp_damage, last ) && SelectTarget( last, tmp_pos, tmp_damage ) ) {
// if we made it so far, set shit.
best.player = t->m_player;
best.pos = tmp_pos;
best.damage = tmp_damage;
best.record = last;
}
}
}
// verify our target and set needed data.
if ( best.player && best.record ) {
// calculate aim angle.
math::VectorAngles( best.pos - g_cl.m_shoot_pos, m_angle );
// set member vars.
m_target = best.player;
m_aim = best.pos;
m_damage = best.damage;
m_record = best.record;
// write data, needed for traces / etc.
m_record->cache( );
// set autostop shit.
m_stop = !( g_cl.m_buttons & IN_JUMP );
bool on = g_menu.main.aimbot.hitchance.get( ) && g_menu.main.config.mode.get( ) == 0;
bool hit = on && CheckHitchance( m_target, m_angle );
// if we can scope.
bool can_scope = !g_cl.m_local->m_bIsScoped( ) && ( g_cl.m_weapon_id == AUG || g_cl.m_weapon_id == SG553 || g_cl.m_weapon_type == WEAPONTYPE_SNIPER_RIFLE );
if ( can_scope ) {
// always.
if ( g_menu.main.aimbot.zoom.get( ) == 1 ) {
g_cl.m_cmd->m_buttons |= IN_ATTACK2;
return;
}
// hitchance fail.
else if ( g_menu.main.aimbot.zoom.get( ) == 2 && on && !hit ) {
g_cl.m_cmd->m_buttons |= IN_ATTACK2;
return;
}
}
if ( hit || !on ) {
// right click attack.
if ( g_menu.main.config.mode.get( ) == 1 && g_cl.m_weapon_id == REVOLVER )
g_cl.m_cmd->m_buttons |= IN_ATTACK2;
// left click attack.
else
g_cl.m_cmd->m_buttons |= IN_ATTACK;
}
}
}
bool Aimbot::CheckHitchance( Player *player, const ang_t &angle ) {
constexpr float HITCHANCE_MAX = 100.f;
constexpr int SEED_MAX = 255;
vec3_t start{ g_cl.m_shoot_pos }, end, fwd, right, up, dir, wep_spread;
float inaccuracy, spread;
CGameTrace tr;
size_t total_hits{ }, needed_hits{ ( size_t )std::ceil( ( g_menu.main.aimbot.hitchance_amount.get( ) * SEED_MAX ) / HITCHANCE_MAX ) };
// get needed directional vectors.
math::AngleVectors( angle, &fwd, &right, &up );
// store off inaccuracy / spread ( these functions are quite intensive and we only need them once ).
inaccuracy = g_cl.m_weapon->GetInaccuracy( );
spread = g_cl.m_weapon->GetSpread( );
// iterate all possible seeds.
for ( int i{ }; i <= SEED_MAX; ++i ) {
// get spread.
wep_spread = g_cl.m_weapon->CalculateSpread( i, inaccuracy, spread );
// get spread direction.
dir = ( fwd + ( right * wep_spread.x ) + ( up * wep_spread.y ) ).normalized( );
// get end of trace.
end = start + ( dir * g_cl.m_weapon_info->m_range );
// setup ray and trace.
g_csgo.m_engine_trace->ClipRayToEntity( Ray( start, end ), MASK_SHOT, player, &tr );
// check if we hit a valid player / hitgroup on the player and increment total hits.
if ( tr.m_entity == player && game::IsValidHitgroup( tr.m_hitgroup ) )
++total_hits;
// we made it.
if ( total_hits >= needed_hits )
return true;
// we cant make it anymore.
if ( ( SEED_MAX - i + total_hits ) < needed_hits )
return false;
}
return false;
}
bool AimPlayer::SetupHitboxPoints( LagRecord *record, BoneArray *bones, int index, std::vector< vec3_t > &points ) {
// reset points.
points.clear( );
const model_t *model = m_player->GetModel( );
if ( !model )
return false;
studiohdr_t *hdr = g_csgo.m_model_info->GetStudioModel( model );
if ( !hdr )
return false;
mstudiohitboxset_t *set = hdr->GetHitboxSet( m_player->m_nHitboxSet( ) );
if ( !set )
return false;
mstudiobbox_t *bbox = set->GetHitbox( index );
if ( !bbox )
return false;
// get hitbox scales.
float scale = g_menu.main.aimbot.scale.get( ) / 100.f;
// big inair fix.
if ( !( record->m_pred_flags ) & FL_ONGROUND )
scale = 0.7f;
float bscale = g_menu.main.aimbot.body_scale.get( ) / 100.f;
// these indexes represent boxes.
if ( bbox->m_radius <= 0.f ) {
// references:
// https://developer.valvesoftware.com/wiki/Rotation_Tutorial
// CBaseAnimating::GetHitboxBonePosition
// CBaseAnimating::DrawServerHitboxes
// convert rotation angle to a matrix.
matrix3x4_t rot_matrix;
g_csgo.AngleMatrix( bbox->m_angle, rot_matrix );
// apply the rotation to the entity input space (local).
matrix3x4_t matrix;
math::ConcatTransforms( bones[ bbox->m_bone ], rot_matrix, matrix );
// extract origin from matrix.
vec3_t origin = matrix.GetOrigin( );
// compute raw center point.
vec3_t center = ( bbox->m_mins + bbox->m_maxs ) / 2.f;
// the feet hiboxes have a side, heel and the toe.
if ( index == HITBOX_R_FOOT || index == HITBOX_L_FOOT ) {
float d1 = ( bbox->m_mins.z - center.z ) * 0.875f;
// invert.
if ( index == HITBOX_L_FOOT )
d1 *= -1.f;
// side is more optimal then center.
points.push_back( { center.x, center.y, center.z + d1 } );
if ( g_menu.main.aimbot.multipoint.get( 3 ) ) {
// get point offset relative to center point
// and factor in hitbox scale.
float d2 = ( bbox->m_mins.x - center.x ) * scale;
float d3 = ( bbox->m_maxs.x - center.x ) * scale;
// heel.
points.push_back( { center.x + d2, center.y, center.z } );
// toe.
points.push_back( { center.x + d3, center.y, center.z } );
}
}
// nothing to do here we are done.
if ( points.empty( ) )
return false;
// rotate our bbox points by their correct angle
// and convert our points to world space.
for ( auto &p : points ) {
// VectorRotate.
// rotate point by angle stored in matrix.
p = { p.dot( matrix[ 0 ] ), p.dot( matrix[ 1 ] ), p.dot( matrix[ 2 ] ) };
// transform point to world space.
p += origin;
}
}
// these hitboxes are capsules.
else {
// factor in the pointscale.
float r = bbox->m_radius * scale;
float br = bbox->m_radius * bscale;
// compute raw center point.
vec3_t center = ( bbox->m_mins + bbox->m_maxs ) / 2.f;
// head has 5 points.
if ( index == HITBOX_HEAD ) {
// add center.
points.push_back( center );
if ( g_menu.main.aimbot.multipoint.get( 0 ) ) {
// rotation matrix 45 degrees.
// https://math.stackexchange.com/questions/383321/rotating-x-y-points-45-degrees
// std::cos( deg_to_rad( 45.f ) )
constexpr float rotation = 0.70710678f;
// top/back 45 deg.
// this is the best spot to shoot at.
points.push_back( { bbox->m_maxs.x + ( rotation * r ), bbox->m_maxs.y + ( -rotation * r ), bbox->m_maxs.z } );
// right.
points.push_back( { bbox->m_maxs.x, bbox->m_maxs.y, bbox->m_maxs.z + r } );
// left.
points.push_back( { bbox->m_maxs.x, bbox->m_maxs.y, bbox->m_maxs.z - r } );
// back.
points.push_back( { bbox->m_maxs.x, bbox->m_maxs.y - r, bbox->m_maxs.z } );
// get animstate ptr.
CCSGOPlayerAnimState *state = record->m_player->m_PlayerAnimState( );
// add this point only under really specific circumstances.
// if we are standing still and have the lowest possible pitch pose.
if ( state && record->m_anim_velocity.length( ) <= 0.1f && record->m_eye_angles.x <= state->m_min_pitch ) {
// bottom point.
points.push_back( { bbox->m_maxs.x - r, bbox->m_maxs.y, bbox->m_maxs.z } );
}
}
}
// body has 5 points.
else if ( index == HITBOX_BODY ) {
// center.
points.push_back( center );
// back.
if ( g_menu.main.aimbot.multipoint.get( 2 ) )
points.push_back( { center.x, bbox->m_maxs.y - br, center.z } );
}
else if ( index == HITBOX_PELVIS || index == HITBOX_UPPER_CHEST ) {
// back.
points.push_back( { center.x, bbox->m_maxs.y - r, center.z } );
}
// other stomach/chest hitboxes have 2 points.
else if ( index == HITBOX_THORAX || index == HITBOX_CHEST ) {
// add center.
points.push_back( center );
// add extra point on back.
if ( g_menu.main.aimbot.multipoint.get( 1 ) )
points.push_back( { center.x, bbox->m_maxs.y - r, center.z } );
}
else if ( index == HITBOX_R_CALF || index == HITBOX_L_CALF ) {
// add center.
points.push_back( center );
// half bottom.
if ( g_menu.main.aimbot.multipoint.get( 3 ) )
points.push_back( { bbox->m_maxs.x - ( bbox->m_radius / 2.f ), bbox->m_maxs.y, bbox->m_maxs.z } );
}
else if ( index == HITBOX_R_THIGH || index == HITBOX_L_THIGH ) {
// add center.
points.push_back( center );
}
// arms get only one point.
else if ( index == HITBOX_R_UPPER_ARM || index == HITBOX_L_UPPER_ARM ) {
// elbow.
points.push_back( { bbox->m_maxs.x + bbox->m_radius, center.y, center.z } );
}
// nothing left to do here.
if ( points.empty( ) )
return false;
// transform capsule points.
for ( auto &p : points )
math::VectorTransform( p, bones[ bbox->m_bone ], p );
}
return true;
}
bool AimPlayer::GetBestAimPosition( vec3_t &aim, float &damage, LagRecord *record ) {
bool done, pen;
float dmg, pendmg;
HitscanData_t scan;
std::vector< vec3_t > points;
// get player hp.
int hp = std::min( 100, m_player->m_iHealth( ) );
if ( g_cl.m_weapon_id == ZEUS ) {
dmg = pendmg = hp;
pen = true;
}
else {
dmg = g_menu.main.aimbot.minimal_damage.get( );
if ( g_menu.main.aimbot.minimal_damage_hp.get( ) )
dmg = std::ceil( ( dmg / 100.f ) * hp );
pendmg = g_menu.main.aimbot.penetrate_minimal_damage.get( );
if ( g_menu.main.aimbot.penetrate_minimal_damage_hp.get( ) )
pendmg = std::ceil( ( pendmg / 100.f ) * hp );
pen = g_menu.main.aimbot.penetrate.get( );
}
// write all data of this record l0l.
record->cache( );
// iterate hitboxes.
for ( const auto &it : m_hitboxes ) {
done = false;
// setup points on hitbox.
if ( !SetupHitboxPoints( record, record->m_bones, it.m_index, points ) )
continue;
// iterate points on hitbox.
for ( const auto &point : points ) {
penetration::PenetrationInput_t in;
in.m_damage = dmg;
in.m_damage_pen = pendmg;
in.m_can_pen = pen;
in.m_target = m_player;
in.m_from = g_cl.m_local;
in.m_pos = point;
// ignore mindmg.
if ( it.m_mode == HitscanMode::LETHAL || it.m_mode == HitscanMode::LETHAL2 )
in.m_damage = in.m_damage_pen = 1.f;
penetration::PenetrationOutput_t out;
// we can hit p!
if ( penetration::run( &in, &out ) ) {
// nope we did not hit head..
if ( it.m_index == HITBOX_HEAD && out.m_hitgroup != HITGROUP_HEAD )
continue;
// prefered hitbox, just stop now.
if ( it.m_mode == HitscanMode::PREFER )
done = true;
// this hitbox requires lethality to get selected, if that is the case.
// we are done, stop now.
else if ( it.m_mode == HitscanMode::LETHAL && out.m_damage >= m_player->m_iHealth( ) )
done = true;
// 2 shots will be sufficient to kill.
else if ( it.m_mode == HitscanMode::LETHAL2 && ( out.m_damage * 2.f ) >= m_player->m_iHealth( ) )
done = true;
// this hitbox has normal selection, it needs to have more damage.
else if ( it.m_mode == HitscanMode::NORMAL ) {
// we did more damage.
if ( out.m_damage > scan.m_damage ) {
// save new best data.
scan.m_damage = out.m_damage;
scan.m_pos = point;
// if the first point is lethal
// screw the other ones.
if ( point == points.front( ) && out.m_damage >= m_player->m_iHealth( ) )
break;
}
}
// we found a preferred / lethal hitbox.
if ( done ) {
// save new best data.
scan.m_damage = out.m_damage;
scan.m_pos = point;
break;
}
}
}
// ghetto break out of outer loop.
if ( done )
break;
}