-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAimbot.cpp
2010 lines (1678 loc) · 61.5 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 "precompiled.h"
#include "Aimbot_imi.h"
#include "AutoBone_imi.h"
#include "Eventlog.h"
#include "LocalPlayer.h"
#include "WeaponController.h"
#include "Assistance.h"
#include "Events.h"
#include "UsedConvars.h"
#include "INetchannelInfo.h"
#include "Removals.h"
#include "datamap.h"
#include "Adriel/stdafx.hpp"
#include "Adriel/renderer.hpp"
#include "Adriel/adr_util.hpp"
#include "Adriel/console.hpp"
#include "Adriel/input.hpp"
CRagebot g_Ragebot;
CRagebot m_RagebotState;
//CLegitbot_imi g_Legitbot;
void SmoothAngle(QAngle& From, QAngle& To, float Percent)
{
QAngle VecDelta = From - To;
NormalizeAngles(VecDelta);
VecDelta *= Percent;
To = From - VecDelta;
}
void CRagebot::ClearAimbotTarget()
{
LocalPlayer.UseDoubleTapHitchance = false;
m_LastTarget.Reset();
m_bHasTarget = false;
}
bool CRagebot::IsValidTarget(int i)
{
return i != INVALID_PLAYER && IsValidTarget(Interfaces::ClientEntList->GetBaseEntity(i));
}
bool CRagebot::IsValidTarget(CBaseEntity* Player)
{
if (!LocalPlayer.Entity)
return false;
return Player && Player->IsPlayer() && !Player->GetImmune() && Player->IsEnemy(LocalPlayer.Entity);
}
bool CRagebot::IsValidTarget(CPlayerrecord* Player)
{
return IsValidTarget(Player->m_pEntity);
}
void CRagebot::SetLowestFovEntity()
{
START_PROFILING
m_LowestFOVTarget.Reset();
for (int i = 1; i <= MAX_PLAYERS; i++)
{
// get player record
CPlayerrecord* _playerRecord = &m_PlayerRecords[i];
// invalid playerrecord
if (!_playerRecord)
continue;
auto _Entity = _playerRecord->m_pEntity;
if (!Interfaces::ClientEntList->EntityExists(_Entity))
continue;
bool _IsValidFarESPTarget = _Entity && _playerRecord->IsValidFarESPAimbotTarget();
// invalid/dead entity
if (!_Entity || (!_Entity->GetAlive() && !_IsValidFarESPTarget))
continue;
// not a valid target
if (!_IsValidFarESPTarget && !_playerRecord->IsValidTarget())
continue;
if (!_Entity->GetAlive())
continue;
Target_s _Target = Target_s();
_Target.m_iEntIndex = _Entity->index;
_Target.m_flFOV = GetFov(LocalPlayer.ShootPosition, _Entity->GetEyePosition(), LocalPlayer.CurrentEyeAngles);
if (_Target.m_flFOV < m_LowestFOVTarget.m_flFOV || m_LowestFOVTarget.m_iEntIndex == INVALID_PLAYER)
{
Vector EyePos = _Entity->GetLocalOriginDirect() - LocalPlayer.Entity->GetLocalOriginDirect();
VectorAngles(EyePos, _Target.m_AtTargetAngle);
m_LowestFOVTarget = _Target;
}
}
END_PROFILING
}
void CRagebot::GetTargettableEntityListUnsorted(std::vector<Target_s>&list, Target_s& lowestfovtarget)
{
START_PROFILING
list.clear();
lowestfovtarget.Reset();
// loop through all streamed entities
for (int i = 1; i <= MAX_PLAYERS; i++)
{
// get player record
CPlayerrecord* _playerRecord = &m_PlayerRecords[i];
// get entity
auto _Entity = _playerRecord->m_pEntity;
if (!Interfaces::ClientEntList->EntityExists(_Entity))
continue;
bool _IsValidFarESPTarget = _Entity && _playerRecord->IsValidFarESPAimbotTarget();
// invalid/dead entity
if (!_Entity || (!_Entity->GetAlive() && !_IsValidFarESPTarget))
continue;
// not a valid target
if (!_IsValidFarESPTarget && !_playerRecord->IsValidTarget())
continue;
if (!_Entity->GetAlive())
continue;
Target_s _Target;
_Target.m_Weight = 0;
_Target.m_iEntIndex = _Entity->index;
_Target.m_flFOV = GetFov(LocalPlayer.ShootPosition, _Entity->GetEyePosition(), LocalPlayer.CurrentEyeAngles);
Vector EyePos = _Entity->GetLocalOriginDirect() - LocalPlayer.Current_Origin;
VectorAngles(EyePos, _Target.m_AtTargetAngle);
// todo: nit; somehow incorporate v4's sorting into this. not in beta though, got no time atm.
// until then, we'll just use the best record if available or best fov
auto _record = _playerRecord->GetBestRecord(false);
if (_record)
_Target.m_Weight = _record->GetWeight();
if (_Target.m_flFOV < lowestfovtarget.m_flFOV || lowestfovtarget.m_iEntIndex == INVALID_PLAYER)
{
lowestfovtarget = _Target;
}
// add target
list.emplace_back(_Target);
}
END_PROFILING
}
void CRagebot::SortTargettableEntityList(std::vector<Target_s>&list)
{
START_PROFILING
// check if all weights are the same, if they are, resort to using FOV instead to prevent aimbots from not shooting at proper targets
if (list.size() > 1)
{
auto target_to_compare = list[0].m_Weight;
if (std::all_of(list.begin(), list.end(), [target_to_compare](Target_s& a) { return a.m_Weight == target_to_compare; }))
{
std::sort(list.begin(), list.end(), [](Target_s& lhs, Target_s& rhs) { return lhs.m_flFOV < rhs.m_flFOV; });
}
else
{
std::sort(list.begin(), list.end(), [](Target_s& lhs, Target_s& rhs) { return lhs.m_Weight > rhs.m_Weight; });
}
}
END_PROFILING
}
void CRagebot::TargetEntities()
{
Target_s _lowestFOV;
bool _gotFreshList = false;
if (m_flLastSortTime != Interfaces::Globals->curtime)
{
//First, get a fresh list of players
std::vector<Target_s> _freshList;
GetTargettableEntityListUnsorted(_freshList, _lowestFOV);
SortTargettableEntityList(_freshList);
m_flLastSortTime = Interfaces::Globals->curtime;
//If there are none available, just clear our lists and exit
if (_freshList.empty())
{
ClearAimbotTarget();
ClearPossibleTargets();
ClearIgnorePlayerIndex();
return;
}
for (auto i = 0; i < m_PossibleTargets.size(); ++i)
{
Target_s &old = m_PossibleTargets[i];
if (std::find(_freshList.begin(), _freshList.end(), old) == _freshList.end())
{
//no longer a valid target
if (m_LowestFOVTarget.m_iEntIndex == old.m_iEntIndex)
m_LowestFOVTarget = _lowestFOV;
//erase this target from the list of scannable targets
m_PossibleTargets.erase(m_PossibleTargets.begin() + i);
if (m_iPossibleTargetIndex > i)
m_iPossibleTargetIndex = max(0, m_iPossibleTargetIndex - 1); //decrease the index since we removed an entity
}
}
if (m_PossibleTargets.empty())
{
m_PossibleTargets = _freshList;
m_LowestFOVTarget = _lowestFOV;
m_iPossibleTargetIndex = 0;
if (m_PossibleTargets.empty())
{
ClearAimbotTarget();
ClearPossibleTargets();
ClearIgnorePlayerIndex();
return; //still empty
}
}
_gotFreshList = true;
}
else
{
if (m_PossibleTargets.empty())
{
ClearAimbotTarget();
ClearPossibleTargets();
ClearIgnorePlayerIndex();
return;
}
}
int MaxTargetsPerTick = variable::get().ragebot.i_targets_per_tick;
if (m_iIgnorePlayerIndex != -1) //we are excluding a person that we already scanned this tick
++MaxTargetsPerTick;
int _maxTargets = min(m_iPossibleTargetIndex + MaxTargetsPerTick, (int)m_PossibleTargets.size());
//unsigned char _numChecked = 0;
//unsigned char _CheckedEntIndexes[MAX_PLAYERS + 1]{ 0 };
//bool _foundTarget = false;
for (; m_iPossibleTargetIndex < _maxTargets; ++m_iPossibleTargetIndex)
{
auto target = &m_PossibleTargets[m_iPossibleTargetIndex];
if (target->m_iEntIndex != m_iIgnorePlayerIndex)
{
//++_numChecked;
//_CheckedEntIndexes[target->m_iEntIndex] = 1;
if (TargetEntity(target))
{
// _foundTarget = true;
break;
}
}
else
{
//if (target->m_iEntIndex <= MAX_PLAYERS)
//{
// ++_numChecked;
// _CheckedEntIndexes[target->m_iEntIndex] = 1;
//}
}
}
if (m_iPossibleTargetIndex >= (int)m_PossibleTargets.size())
{
// scanned all targets. note: there is a flaw here
// if we have for example 2 targets per tick and only 1 was valid anymore this tick, we will have only scanned 1 person instead of 2
// todo: come up with a better way than what we used to to deal with this case that doesn't break the whole ragebot
ClearPossibleTargets();
ClearIgnorePlayerIndex();
if (_gotFreshList)
m_LowestFOVTarget = _lowestFOV;
}
}
bool CRagebot::TargetEntity(Target_s* Target)
{
CBaseEntity* _Entity = Interfaces::ClientEntList->GetBaseEntity(Target->m_iEntIndex);
if (!_Entity)
{
m_LastTarget.Reset();
return false;
}
// net player record for entity
CPlayerrecord* _playerRecord = g_LagCompensation.GetPlayerrecord(_Entity);
// no playerrecord or spectating or no target tick
if (!_playerRecord || !_playerRecord->m_pEntity || (_playerRecord->m_bSpectating && !_playerRecord->IsValidFarESPAimbotTarget()) || !_playerRecord->m_TargetRecord)
{
m_LastTarget.Reset();
return false;
}
if (g_AutoBone.Run_AutoBone(_Entity))
{
m_LastTarget = *Target;
m_LastTarget.m_pBestHitbox = g_AutoBone.m_pBestHitbox;
//m_iLastChecked = 0;
return true;
}
m_LastTarget.Reset();
return false;
}
bool CRagebot::Finalize()
{
m_iIgnorePlayerIndex = -1;
if (m_LastTarget.m_iEntIndex == INVALID_PLAYER || g_AutoBone.m_pBestHitbox == nullptr)
return false;
CPlayerrecord* _playerRecord = &m_PlayerRecords[m_LastTarget.m_iEntIndex];
WeaponInfo_t* wpn_data = LocalPlayer.CurrentWeapon->GetCSWpnData();
if (!wpn_data || !_playerRecord || !_playerRecord->m_pEntity)
{
ClearAimbotTarget();
return false;
}
Vector& vecHitboxPos = g_AutoBone.m_pBestHitbox->origin;
#ifndef IMI_MENU
g_Visuals.m_lastBestAimbotPos = vecHitboxPos;
g_Visuals.m_lastBestDamage = g_AutoBone.m_pBestHitbox->damage;
g_Visuals.m_prioritize_body = (g_AutoBone.m_pBestHitbox->actual_hitbox_due_to_penetration != HITBOX_HEAD && g_AutoBone.m_pBestHitbox->actual_hitbox_due_to_penetration != HITBOX_LOWER_NECK);
#endif
#if defined _DEBUG || defined INTERNAL_DEBUG
Interfaces::DebugOverlay->AddTextOverlay(Vector(vecHitboxPos.x, vecHitboxPos.y, vecHitboxPos.z - 1.0f), 0.05f, "Aimbot Target");
Interfaces::DebugOverlay->AddBoxOverlay(vecHitboxPos, Vector(-2, -2, -2), Vector(1, 1, 1), LocalPlayer.CurrentEyeAngles, 255, 0, 0, 255, 0.05f);
#endif
if (g_WeaponController.WeaponDidFire(CurrentUserCmd.cmd->buttons | IN_ATTACK) != 1 || !variable::get().ragebot.b_autofire)
return false;
m_angAimAngles = g_AutoBone.m_pBestHitbox->localplayer_eyeangles;
return true;
}
void CRagebot::Run()
{
m_angAimAngles = LocalPlayer.FinalEyeAngles;
m_bTracedEnemy = false;
g_Info.UsingForwardTrack = false;
m_iIgnorePlayerIndex = -1;
if (IsValidTarget(m_LastTarget.m_iEntIndex))
{
m_iIgnorePlayerIndex = m_LastTarget.m_iEntIndex;
CPlayerrecord* _playerRecord = g_LagCompensation.GetPlayerrecord(m_LastTarget.m_iEntIndex);
if (_playerRecord && _playerRecord->m_pEntity && _playerRecord->m_pEntity->GetAlive() && _playerRecord->m_pEntity->IsEnemy(LocalPlayer.Entity)
&& !((_playerRecord->m_bSpectating || _playerRecord->m_bDormant) && !_playerRecord->IsValidFarESPAimbotTarget()) && _playerRecord->m_TargetRecord)
{
if (TargetEntity(&m_LastTarget))
{
SetLowestFovEntity();
m_bHasTarget = Finalize();
return;
}
}
}
ClearAimbotTarget();
if (m_iPossibleTargetIndex == 0)
{
GetTargettableEntityListUnsorted(m_PossibleTargets, m_LowestFOVTarget);
SortTargettableEntityList(m_PossibleTargets);
m_flLastSortTime = Interfaces::Globals->realtime;
}
else
SetLowestFovEntity();
TargetEntities();
m_bHasTarget = Finalize();
}
extern void FillImpactTempEntResultsAndResolveFromPlayerHurt(CBaseEntity* EntityHit, CPlayerrecord* pCPlayer, CShotrecord* shotrecord, bool CalledFromQueuedEventProcessor);
void CRagebot::OutputMissedShots()
{
// we want event
CPlayerrecord *localrecord = &m_PlayerRecords[LocalPlayer.Entity->index];
LocalPlayer.ShotMutex.Lock();
// Run all queued shot resolver events
if (!g_QueuedImpactResolveEvents.empty())
{
for (auto& _Impact : g_QueuedImpactResolveEvents)
{
FillImpactTempEntResultsAndResolveFromPlayerHurt(_Impact.m_EntityHit, _Impact.pCPlayer, &_Impact.m_ShotRecord, true);
}
g_QueuedImpactResolveEvents.clear();
}
// don't show missed shots via manual fire
float shot_time = std::fabsf(LocalPlayer.ManualFireShotInfo.m_flLastManualShotRealTime - Interfaces::Globals->realtime);
if (shot_time < 1.f)
{
LocalPlayer.m_ShotResults.clear();
LocalPlayer.ShotMutex.Unlock();
return;
}
// detect fake fires
LocalPlayer.Get(&LocalPlayer);
#if 0
// todo: nit; get way to detect predictable/networked clip one from the current weapon, this currently gives an access violation
if (LocalPlayer.CurrentWeapon != nullptr)
{
typedescription_t *td = FindFlatFieldByName(XorStr("m_iClip1"), LocalPlayer.CurrentWeapon->GetPredDescMap());
if (td != nullptr)
{
int m_nServerCommandsAcknowledged = Interfaces::Prediction->m_Split[0].m_nServerCommandsAcknowledged;
void* slot = LocalPlayer.Entity->GetPredictedFrame(m_nServerCommandsAcknowledged - 1);
if (slot != nullptr)
{
int predicted_clip = *(int*)((byte *)slot + td->flatOffset[TD_OFFSET_PACKED]);
int networked_clip = LocalPlayer.CurrentWeapon->GetClipOne();
if (predicted_clip != networked_clip)
{
#if _DEBUG
logger::add(LERROR, XorStr("Cheat int differs (m_Clip1 net %i pred %i) diff(%i)\n"), networked_clip, predicted_clip, predicted_clip - networked_clip);
#endif
fake_fired = true;
}
}
}
}
#else
bool fake_fired = LocalPlayer.FakeFired && sv_infinite_ammo.GetVar()->GetInt() < 1;
#endif
if(variable::get().visuals.i_shot_logs > 0)
{
for (auto& _ShotResultIterator : LocalPlayer.m_ShotResults)
{
auto &_ShotResult = _ShotResultIterator.second;
// miss caused due to fake fire/shot dropped
if (fake_fired)
{
// set it to false again after acknowledging the fake fire
LocalPlayer.FakeFired = false;
#if defined DEBUG_SHOTS || defined _DEBUG || defined INTERNAL_DEBUG
g_Eventlog.AddEventElement(0x2, XorStr("[OM] "));
#endif
g_Eventlog.AddEventElement(0x2, XorStr("missed [shot dropped!] "));
}
if (_ShotResult.m_bAcked || !_ShotResult.m_bInflictorIsLocalPlayer)
continue;
_ShotResult.m_bAcked = true;
auto flags = _ShotResult.m_MissFlags;
// skip over hit and resolved shit (only if we didn't fake fire, otherwise we need to replay the shot
if (!fake_fired)
{
if (flags & HIT_PLAYER && flags & HIT_IS_RESOLVED)
continue;
}
//decrypts(0)
std::string victim_name = XorStr("!invalid!");
//encrypts(0)
CBaseEntity* _Entity = Interfaces::ClientEntList->EntityExists(_ShotResult.m_pInflictedEntity) ? _ShotResult.m_pInflictedEntity : nullptr;
if (_Entity)
{
victim_name = adr_util::sanitize_name((char*)_Entity->GetName().data());
}
int color = (flags & HIT_PLAYER) && (flags & MISS_FROM_BAD_HITGROUP) ? 0x9 : 0x2;
bool unresolved = _ShotResult.m_ResolveMode != RESOLVE_MODE_NONE && (flags & MISS_FROM_BADRESOLVE || (flags & MISS_SHOULDNT_HAVE_MISSED && !(flags & HIT_PLAYER)));
std::string resolve_name{};
std::string hitgroup_name = get_hitgroup_name(_ShotResult.m_iHitgroupShotAt);
if (!fake_fired)
{
#if defined DEBUG_SHOTS || defined _DEBUG || defined INTERNAL_DEBUG
g_Eventlog.AddEventElement(color, "[OM] ");
g_Eventlog.AddEventElement(color, std::to_string(_ShotResult.m_flTimeCreated));
g_Eventlog.AddEventElement(color, " | ");
#endif
//decrypts(0)
g_Eventlog.AddEventElement(color, XorStr("missed "));
//encrypts(0)
}
// todo: nit; miss due to far esp/dormancy
if (_ShotResult.m_bAwaitingImpact)
{
//decrypts(0)
g_Eventlog.AddEventElement(color, XorStr("[ missing impact! miss was ignored] "));
//encrypts(0)
}
else
{
// invalid miss since MISS_FROM_SPREAD is used as a default flag
if (flags == MISS_FROM_SPREAD)
{
//decrypts(0)
g_Eventlog.AddEventElement(color, XorStr("[ invalid! ] "));
//encrypts(0)
}
else
{
resolve_name = g_Visuals.GetResolveType(_ShotResult);
if (unresolved)
{
//decrypts(0)
g_Eventlog.AddEventElement(color, XorStr("[ resolver ] "));
//encrypts(0)
}
else
{
if (flags & MISS_FROM_BAD_HITGROUP && flags & HIT_PLAYER)
{
//decrypts(0)
g_Eventlog.AddEventElement(color, XorStr("[ wrong hitbox ] "));
//encrypts(0)
}
if (flags & MISS_AUTOWALL)
{
//decrypts(0)
g_Eventlog.AddEventElement(color, XorStr("[ wall interference ] "));
//encrypts(0)
}
// we only want to show if we're missing via spread/inaccuracy if we haven't hit them
if (!(flags & HIT_PLAYER))
{
if (weapon_accuracy_nospread.GetVar()->GetInt() < 1)
{
if (flags & MISS_FROM_SPREAD)
{
//decrypts(0)
g_Eventlog.AddEventElement(color, XorStr("[ spread ] "));
//encrypts(0)
}
}
if (flags & MISS_RAY_OFF_TARGET)
{
//decrypts(0)
g_Eventlog.AddEventElement(color, XorStr("[ inaccuracy ] "));
//encrypts(0)
}
}
}
}
}
// if we havent hit a reason to miss yet, don't draw out a reason
if (g_Eventlog.Size() == 1)
{
g_Eventlog.ClearEvent();
LocalPlayer.m_ShotResults.clear();
LocalPlayer.ShotMutex.Unlock();
continue;
}
int backtrack = 0;
if (LocalPlayer.ShotRecord != nullptr)
{
backtrack = _ShotResult.m_iTickCountWhenWeShot - LocalPlayer.ShotRecord->m_iEnemySimulationTickCount;
}
// missed a x-tick backtrack on '[name]''s [hitgroup]
if (backtrack > 0)
{
//decrypts(0)
g_Eventlog.AddEventElement(color, XorStr("a "));
g_Eventlog.AddEventElement(color, std::to_string(backtrack));
g_Eventlog.AddEventElement(color, XorStr("-tick backtrack on \'"));
g_Eventlog.AddEventElement(color, victim_name);
//encrypts(0)
}
else if (backtrack < 0)
{
//decrypts(0)
g_Eventlog.AddEventElement(color, XorStr("a "));
g_Eventlog.AddEventElement(color, std::to_string(-backtrack));
g_Eventlog.AddEventElement(color, XorStr("-tick forwardtrack on \'"));
g_Eventlog.AddEventElement(color, victim_name);
//encrypts(0)
}
//missed '[name]'
else
{
//decrypts(0)
g_Eventlog.AddEventElement(color, XorStr("\'"));
g_Eventlog.AddEventElement(color, victim_name);
//encrypts(0)
}
//decrypts(0)
g_Eventlog.AddEventElement(color, XorStr("\'"));
//encrypts(0)
// gear/generic
if (hitgroup_name[0] != 'G' && !(flags & MISS_FROM_BAD_HITGROUP))
{
//decrypts(0)
g_Eventlog.AddEventElement(color, XorStr(" \'s "));
//encrypts(0)
g_Eventlog.AddEventElement(color, hitgroup_name);
}
// wrong hitbox clarification
if (flags & MISS_FROM_BAD_HITGROUP && flags & HIT_PLAYER)
{
//decrypts(0)
g_Eventlog.AddEventElement(color, "[ ");
g_Eventlog.AddEventElement(color, hitgroup_name);
g_Eventlog.AddEventElement(color, XorStr(" -> "));
g_Eventlog.AddEventElement(0x04, get_hitgroup_name(_ShotResult.m_iHitgroupHit));
g_Eventlog.AddEventElement(color, " ]");
//encrypts(0)
if (_ShotResult.m_iDamageGiven > 0)
{
//decrypts(0)
g_Eventlog.AddEventElement(0x4, XorStr(" for "));
g_Eventlog.AddEventElement(0x4, std::to_string(_ShotResult.m_iDamageGiven));
g_Eventlog.AddEventElement(0x4, XorStr(" dmg "));
//encrypts(0)
}
else
{
#if _DEBUG
logger::add(LERROR, "damage given: %d | miss flags: %s", _ShotResult.m_iDamageGiven, _ShotResult.get_miss_reason(fake_fired).data());
#endif
}
g_Eventlog.AddEventElement(0x4, "( ");
g_Eventlog.AddEventElement(0x4, _Entity ? std::to_string(_Entity->GetHealth()) : "?");
//decrypts(0)
g_Eventlog.AddEventElement(0x4, XorStr(" remaining )"));
//encrypts(0)
}
// via [resolve name]
#if defined _DEBUG || defined INTERNAL_DEBUG
if (!resolve_name.empty())
#else
if(unresolved && !resolve_name.empty())
#endif
{
//decrypts(0)
g_Eventlog.AddEventElement(color, XorStr(" via "));
//encrypts(0)
//if (resolve_type.empty())
//{
// DebugBreak();
//}
g_Eventlog.AddEventElement(color, resolve_name);
}
#if defined DEBUG_SHOTS || defined _DEBUG || defined INTERNAL_DEBUG
g_Eventlog.AddEventElement(0x01, " | ");
g_Eventlog.AddEventElement(0x01, _ShotResult.get_miss_reason(fake_fired).data());
#endif
g_Eventlog.OutputEvent(variable::get().visuals.i_shot_logs);
}
}
LocalPlayer.m_ShotResults.clear();
LocalPlayer.ShotMutex.Unlock();
}
void AirAccelerate(CBaseEntity* player, QAngle &angle, float fmove, float smove) {
Vector fwd, right, wishvel, wishdir;
float maxspeed, wishspd, wishspeed, currentspeed, addspeed, accelspeed;
// determine movement angles.
AngleVectors(angle, &fwd, &right, nullptr);
// zero out z components of movement vectors.
fwd.z = 0.f;
right.z = 0.f;
// normalize remainder of vectors.
VectorNormalizeFast(fwd);
VectorNormalizeFast(right);
// determine x and y parts of velocity.
for (int i{}; i < 2; ++i)
wishvel[i] = (fwd[i] * fmove) + (right[i] * smove);
// zero out z part of velocity.
wishvel.z = 0.f;
// determine maginitude of speed of move.
wishdir = wishvel;
Vector wishdir2 = wishdir;
wishspeed = wishdir2.NormalizeInPlace();
// get maxspeed.
// TODO; maybe global this or whatever its 260 anyway always.
maxspeed = player->GetMaxSpeed();
// clamp to server defined max speed.
if (wishspeed != 0.f && wishspeed > maxspeed)
wishspeed = maxspeed;
// make copy to preserve original variable.
wishspd = wishspeed;
// cap speed.
if (wishspd > 30.f)
wishspd = 30.f;
// determine veer amount.
currentspeed = player->GetVelocity().Dot(wishdir);
// see how much to add.
addspeed = wishspd - currentspeed;
// if not adding any, done.
if (addspeed <= 0.f)
return;
// Determine acceleration speed after acceleration
accelspeed = Interfaces::Cvar->FindVar("sv_airaccelerate")->GetFloat() * wishspeed * TICK_INTERVAL;
// cap it.
if (accelspeed > addspeed)
accelspeed = addspeed;
// add accel.
player->SetVelocity(player->GetVelocity() + (wishdir * accelspeed));
}
void PlayerMove(CBaseEntity* player) {
Vector start, end, normal;
CGameTrace trace;
CTraceFilterWorldOnly filter;
// define trace start.
start = player->GetNetworkOrigin();
Vector pVelocity = player->GetVelocity();
// move trace end one tick into the future using predicted velocity.
end = start + (pVelocity * TICK_INTERVAL);
Ray_t ray;
ray.Init(start, end, player->GetMins(), player->GetMaxs());
// trace.
Interfaces::EngineTrace->TraceRay(ray, CONTENTS_SOLID, &filter, &trace);
// we hit shit
// we need to fix hit.
if (trace.fraction != 1.f) {
// fix sliding on planes.
for (int i{}; i < 2; ++i) {
pVelocity -= trace.plane.normal * pVelocity.Dot(trace.plane.normal);
float adjust = pVelocity.Dot(trace.plane.normal);
if (adjust < 0.f)
pVelocity -= (trace.plane.normal * adjust);
start = trace.endpos;
end = start + (pVelocity * (TICK_INTERVAL * (1.f - trace.fraction)));
Ray_t ray2;
ray2.Init(start, end, player->GetMins(), player->GetMaxs());
Interfaces::EngineTrace->TraceRay(ray2, CONTENTS_SOLID, &filter, &trace);
if (trace.fraction == 1.f)
break;
}
}
// set new final origin.
start = end = trace.endpos;
player->SetNetworkOrigin(trace.endpos);
// move endpos 2 units down.
// this way we can check if we are in/on the ground.
end.z -= 2.f;
// trace.
Ray_t ray3;
ray3.Init(start, end, player->GetMins(), player->GetMaxs());
Interfaces::EngineTrace->TraceRay(ray3, CONTENTS_SOLID, &filter, &trace);
// strip onground flag.
player->RemoveFlag(FL_ONGROUND);
// add back onground flag if we are onground.
if (trace.fraction != 1.f && trace.plane.normal.z > 0.7f)
player->AddFlag(FL_ONGROUND);
player->SetVelocity(pVelocity);
}
CBaseEntity* CRagebot::ForwardTrack(CPlayerrecord* pCPlayer, bool ForceForwardTrack, bool* AlreadyForwardTracked)
{
auto& var = variable::get();
if (!var.ragebot.b_forwardtrack.get() || pCPlayer->m_bIsUsingFarESP || pCPlayer->m_bIsUsingServerSide)
return nullptr;
if (*AlreadyForwardTracked)
{
return nullptr;
}
*AlreadyForwardTracked = true;
if (ForceForwardTrack || pCPlayer->m_bTeleporting || (pCPlayer->m_ValidRecordCount == 0 && pCPlayer->m_flTotalInvalidRecordTime > 0.5f))
{
//if (/*!g_Convars.Ragebot.ragebot_prediction->GetBool() ||*/ pCPlayer->m_bTickbaseShiftedBackwards_Rendering)
// return nullptr;
#ifdef _DEBUG
#if 0
//prevent drawing tons of hitboxes
static float nagger = FLT_MIN;
if (QPCTime() - nagger < 0.5f)
return nullptr;
nagger = QPCTime();
#endif
#endif
std::deque<CTickrecord*> m_PredictedTicks;
std::deque<CTickrecord*> m_NewTicks;
CBaseEntity* pEntity = pCPlayer->m_pEntity;
INetChannelInfo* nci = Interfaces::EngineClient->GetNetChannelInfo();
//First restore to current record in case the player has been placed somewhere else. This ensures we have a pristine animation state and position for predicting future ticks
CTickrecord* CurrentRecord = pCPlayer->GetCurrentRecord();
CTickrecord* PreviousRecord = pCPlayer->GetPreviousRecord();
CTickrecord* PrePreviousRecord = pCPlayer->GetPrePreviousRecord();
if (!CurrentRecord)
{
return nullptr;
}
if (!PreviousRecord || PreviousRecord->m_Dormant)
{
return nullptr;
}
pCPlayer->CM_BacktrackPlayer(CurrentRecord);
//If standing still and not changing duck stance, just return
if (pCPlayer->m_ValidRecordCount > 0 &&
(CurrentRecord->m_AbsVelocity.Length() < MINIMUM_PLAYERSPEED_CONSIDERED_MOVING
&& (CurrentRecord->m_DuckAmount == 0.0f
|| CurrentRecord->m_DuckAmount == 1.0f)))
{
return nullptr;
}
bool ducking = pCPlayer->m_bIsHoldingDuck;
if (!ducking)
{
CTickrecord* PreviousRecord = pCPlayer->m_Tickrecords.size() > 1 ? pCPlayer->m_Tickrecords[1] : nullptr;
if (PreviousRecord) //check for fakeduck
if (CurrentRecord->m_DuckAmount > 0.0f && CurrentRecord->m_DuckAmount == PreviousRecord->m_DuckAmount)
ducking = true;
}
int forwardtrackticks = TIME_TO_TICKS(g_ClientState->m_pNetChannel->GetLatency(FLOW_OUTGOING));
int arrivaltick = g_ClientState->m_nServerTick + 1 + forwardtrackticks;
bool jumping = !(pEntity->GetFlags() & FL_ONGROUND) || !(PreviousRecord->m_Flags & FL_ONGROUND);
//int simulationtick = TIME_TO_TICKS(CurrentRecord->m_flFirstCmdTickbaseTime) + CurrentRecord->m_iTicksChoked;
int simtick = TIME_TO_TICKS(CurrentRecord->m_SimulationTime);
//prioritize choked ticks that aren't 0
bool found_choked_count = false;
int average_choked = 0;
int total_choked_count = 0;
for (int i = 0; i < min(pCPlayer->m_Tickrecords.size(), 10); ++i)
{
auto& tick = pCPlayer->m_Tickrecords[i];
if (!tick->m_bIsDuplicateTickbase && tick->m_iTicksChoked > 0)
{
average_choked += tick->m_iTicksChoked;
++total_choked_count;
}
}
if (total_choked_count)
{
average_choked /= total_choked_count;
}
else
{
average_choked = CurrentRecord->m_iTicksChoked;
}
int lerpticks = TIME_TO_TICKS(g_LagCompensation.GetLerpTime());
int deltaticks = average_choked + 1;
int tickbase = CurrentRecord->m_iTickcount;
int cmd_tickcount = tickbase + lerpticks;
int desired_cmd_tickcount = tickbase + lerpticks;
int max_future_tick;// g_ClientState->m_ClockDriftMgr.m_nServerTick + 1 + TIME_TO_TICKS(g_ClientState->m_pNetChannel->GetLatency(FLOW_OUTGOING)) + sv_max_usercmd_future_ticks.GetVar()->GetInt();
//hard clamp it since latency causes us to fake fire a lot
//max_future_tick -= 10;
max_future_tick = Interfaces::Globals->tickcount + sv_max_usercmd_future_ticks.GetVar()->GetInt() + 1;//max(max_future_tick, g_ClientState->m_ClockDriftMgr.m_nServerTick + 1);
// get the delta in ticks between the last server net update
// and the net update on which we created this record.
int updatedelta = g_ClientState->m_nServerTick - CurrentRecord->m_iServerTick;
PlayerBackup_t backup(pEntity);
// if the lag delta that is remaining is less than the current netlag
// that means that we can shoot now and when our shot will get processed
// the origin will still be valid, therefore we do not have to predict.
if (forwardtrackticks <= deltaticks - updatedelta)
{
// don't allow fake fires
if (g_LagCompensation.IsTickValid(CurrentRecord))
{
pCPlayer->m_bCountResolverStatsEvenWhenForwardtracking = true;
goto ShootAnyway;
}
return nullptr;
}
// the next update will come in, wait for it.
//FIXME: don't do this when forwardtracking
int next = CurrentRecord->m_iServerTick + 1;
if (next + deltaticks >= arrivaltick)
return nullptr;
desired_cmd_tickcount = desired_cmd_tickcount + deltaticks;
cmd_tickcount = Interfaces::Globals->tickcount + 1 + lerpticks;//desired_cmd_tickcount;
// don't allow fake fires
if (desired_cmd_tickcount > max_future_tick)
cmd_tickcount = max_future_tick;
// if the enemy is moving and on ground, check around them to see if we can hit there, so we don't simulate and scan tons of crap
if (CurrentRecord->m_Flags & FL_ONGROUND && CurrentRecord->m_Velocity.Length() >= MINIMUM_PLAYERSPEED_CONSIDERED_MOVING)
{
Autowall_Output_t output;
Vector testposition = pEntity->GetAbsOriginDirect() + Vector(0.0f, 0.0f, 64.0f);
QAngle angletoenemy = CalcAngle(LocalPlayer.ShootPosition, pEntity->GetAbsOriginDirect() + Vector(0.0f, 0.0f, 64.0f));
Vector vRight;
AngleVectors(angletoenemy, nullptr, &vRight, nullptr);
#ifdef _DEBUG
Interfaces::DebugOverlay->AddBoxOverlay(testposition + vRight * 35.0f, Vector(-4, -4, -4), Vector(4, 4, 4), angletoenemy, 0, 0, 255, 255, TICKS_TO_TIME(2));
#endif
Autowall(LocalPlayer.ShootPosition, testposition + vRight * 35.0f, output, false, true, pEntity, HITBOX_BODY);
if (!output.entity_hit)
{
#ifdef _DEBUG
Interfaces::DebugOverlay->AddBoxOverlay(testposition - vRight * 35.0f, Vector(-4, -4, -4), Vector(4, 4, 4), angletoenemy, 0, 0, 255, 255, TICKS_TO_TIME(2));
#endif
Autowall(LocalPlayer.ShootPosition, testposition - vRight * 35.0f, output, false, true, pEntity, HITBOX_BODY);
if (!output.entity_hit)
{
return nullptr;
}
}
}
float change = 0.f, dir = 0.f;
// get the direction of the current velocity.
if (CurrentRecord->m_Velocity.y != 0.f || CurrentRecord->m_Velocity.x != 0.f)