-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ragebot.cpp
1685 lines (1341 loc) · 47.4 KB
/
Ragebot.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 "Hooks.h"
#include "features.h"
#include <thread>
#include <mutex>
std::vector<ShotSnapshot> shot_snapshots;
CWeaponConfig CRagebot::CurrentSettings() {
if (csgo->weapon->IsAuto() && vars.ragebot.weapon[weap_type::scar].enable)
return vars.ragebot.weapon[weap_type::scar];
else if (csgo->weapon->GetItemDefinitionIndex() == WEAPON_SSG08 && vars.ragebot.weapon[weap_type::scout].enable)
return vars.ragebot.weapon[weap_type::scout];
else if (csgo->weapon->GetItemDefinitionIndex() == WEAPON_AWP && vars.ragebot.weapon[weap_type::_awp].enable)
return vars.ragebot.weapon[weap_type::_awp];
else if (csgo->weapon->isRifle() && vars.ragebot.weapon[weap_type::rifles].enable)
return vars.ragebot.weapon[weap_type::rifles];
else if (csgo->weapon->IsHeavyPistol() && vars.ragebot.weapon[weap_type::heavy_pistols].enable)
return vars.ragebot.weapon[weap_type::heavy_pistols];
else if (csgo->weapon->isPistol() && vars.ragebot.weapon[weap_type::pistols].enable)
return vars.ragebot.weapon[weap_type::pistols];
else
return vars.ragebot.weapon[weap_type::def];
}
std::vector<int> CRagebot::GetHitboxesToScan(IBasePlayer* pEntity)
{
std::vector< int > hitboxes;
if (!csgo->weapon)
return hitboxes;
if (g_Binds[bind_baim].active) {
hitboxes.emplace_back(CSGOHitboxID::Chest);
hitboxes.emplace_back(CSGOHitboxID::Stomach);
hitboxes.emplace_back(CSGOHitboxID::Pelvis);
hitboxes.emplace_back(CSGOHitboxID::UpperChest);
return hitboxes;
}
if (csgo->weapon->IsZeus()) {
hitboxes.emplace_back(CSGOHitboxID::Chest);
hitboxes.emplace_back(CSGOHitboxID::Stomach);
hitboxes.emplace_back(CSGOHitboxID::Pelvis);
return hitboxes;
}
if (current_settings.hitscan & 1)
hitboxes.emplace_back(CSGOHitboxID::Head);
if (current_settings.hitscan & 2)
hitboxes.emplace_back(CSGOHitboxID::UpperChest);
if (current_settings.hitscan & 4)
hitboxes.emplace_back(CSGOHitboxID::Chest);
if (current_settings.hitscan & 8)
hitboxes.emplace_back(CSGOHitboxID::LowerChest);
if (current_settings.hitscan & 16)
hitboxes.emplace_back(CSGOHitboxID::Pelvis);
if (current_settings.hitscan & 32)
hitboxes.emplace_back(CSGOHitboxID::Stomach);
if (csgo->weapon->isSniper() && !csgo->local->IsScoped())
return hitboxes;
if (current_settings.hitscan & 64) {
hitboxes.emplace_back(CSGOHitboxID::LeftShin);
hitboxes.emplace_back(CSGOHitboxID::RightShin);
hitboxes.emplace_back(CSGOHitboxID::LeftThigh);
hitboxes.emplace_back(CSGOHitboxID::RightThigh);
}
if (current_settings.hitscan & 128) {
hitboxes.emplace_back(CSGOHitboxID::LeftFoot);
hitboxes.emplace_back(CSGOHitboxID::RightFoot);
}
if (current_settings.hitscan & 256) {
hitboxes.emplace_back(CSGOHitboxID::LeftHand);
hitboxes.emplace_back(CSGOHitboxID::RightHand);
hitboxes.emplace_back(CSGOHitboxID::LeftLowerArm);
hitboxes.emplace_back(CSGOHitboxID::RightLowerArm);
hitboxes.emplace_back(CSGOHitboxID::LeftUpperArm);
hitboxes.emplace_back(CSGOHitboxID::RightUpperArm);
}
return hitboxes;
}
float CRagebot::GetBodyScale(IBasePlayer* player)
{
if (!(player->GetFlags() & FL_ONGROUND))
return 0.f;
if (current_settings.static_scale)
return std::clamp(current_settings.scale_body / 100.f, 0.f, 0.75f);
auto factor = [](float x, float min, float max) {
return 1.f - 1.f / (1.f + pow(2.f, (-([](float x, float min, float max) {
return ((x - min) * 2.f) / (max - min) - 1.f;
}(x, min, max)) / 0.115f)));
}(player->GetOrigin().DistTo(csgo->local->GetEyePosition()), 0.f, csgo->weapon_range / 4.f);
if (csgo->weapon->isSniper() && !csgo->local->IsScoped())
factor = 0.f;
if (csgo->local->GetDuckAmount() >= 0.9f && !g_Binds[bind_fake_duck].active)
return 0.65f;
return std::clamp(factor, 0.f, 0.75f);
}
float CRagebot::GetHeadScale(IBasePlayer* player)
{
if (current_settings.static_scale)
return std::clamp(current_settings.scale_head / 100.f, 0.f, 0.80f);
if (!vars.misc.antiuntrusted)
return 0.90f;
if (g_Binds[bind_fake_duck].active)
return 0.70f;
if (player->GetFlags() & FL_ONGROUND)
return GetBodyScale(player);
else
return 0.75f;
}
std::vector<Vector> CRagebot::GetAdvancedHeadPoints(IBasePlayer* pBaseEntity, matrix bones[128])
{
std::vector<Vector> vPoints;
Vector src, dst, sc1, sc2, fw1;
src = pBaseEntity->GetBonePos(bones, 8);
Math::AngleVectors(Vector(0, g_Resolver->GetBackwardYaw(pBaseEntity) - 90.f, 0), &fw1);
Vector left_side = src + (fw1 * 40);
Vector right_side = src - (fw1 * 40);
vPoints.push_back(left_side);
vPoints.push_back(right_side);
return vPoints;
}
std::vector<std::pair<Vector, bool>> CRagebot::GetMultipoints(IBasePlayer* pBaseEntity, int iHitbox, matrix bones[128])
{
std::vector<std::pair<Vector, bool>> points;
const model_t* model = pBaseEntity->GetModel();
if (!model)
return points;
studiohdr_t* hdr = interfaces.models.model_info->GetStudioModel(model);
if (!hdr)
return points;
mstudiohitboxset_t* set = hdr->pHitboxSet(pBaseEntity->GetHitboxSet());
if (!set)
return points;
mstudiobbox_t* bbox = set->pHitbox(iHitbox);
if (!bbox)
return points;
// these indexes represent boxes.
if (bbox->radius <= 0.f) {
// references:
// https://developer.valvesoftware.com/wiki/Rotation_Tutorial
// CBaseAnimating::GetHitboxBonePosition
// CBaseAnimating::DrawServerHitboxes
// convert rotation angle to a matrix.
matrix rot_matrix;
Math::AngleMatrix(bbox->rotation, rot_matrix);
// apply the rotation to the entity input space (local).
matrix mat;
Math::ConcatTransforms(bones[bbox->bone], rot_matrix, mat);
// extract origin from matrix.
Vector origin = mat.GetOrigin();
// compute raw center point.
Vector center = (bbox->bbmin + bbox->bbmax) / 2.f;
// the feet hiboxes have a side, heel and the toe.
if (iHitbox == CSGOHitboxID::RightFoot || iHitbox == CSGOHitboxID::LeftFoot) {
float d1 = (bbox->bbmin.z - center.z) * 0.875f;
// invert.
if (iHitbox == CSGOHitboxID::LeftFoot)
d1 *= -1.f;
// side is more optimal then center.
points.emplace_back(Vector{ center.x, center.y, center.z + d1 }, false);
float d2 = (bbox->bbmin.x - center.x) * 0.5f;
float d3 = (bbox->bbmax.x - center.x) * 0.5f;
// heel.
points.emplace_back(Vector{ center.x + d2, center.y, center.z }, false);
// toe.
points.emplace_back(Vector{ center.x + d3, center.y, center.z }, false);
}
else
points.emplace_back(center, true);
// nothing to do here we are done.
if (points.empty())
return points;
// 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.first = { p.first.Dot(mat[0]), p.first.Dot(mat[1]), p.first.Dot(mat[2]) };
// transform point to world space.
p.first += origin;
}
}
// these hitboxes are capsules.
else {
// compute raw center point.
Vector max = bbox->bbmax;
Vector min = bbox->bbmin;
Vector center = (bbox->bbmin + bbox->bbmax) / 2.f;
// head has 5 points.
if (iHitbox == CSGOHitboxID::Head) {
// add center.
float r = bbox->radius * GetHeadScale(pBaseEntity);
points.emplace_back(center, true);
if (true) {
// 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.emplace_back(Vector{ max.x + (rotation * r), max.y + (-rotation * r), max.z }, false);
Vector right{ max.x, max.y, max.z + r };
// right.
points.emplace_back(right, false);
Vector left{ max.x, max.y, max.z - r };
// left.
points.emplace_back(left, false);
// back.
points.emplace_back(Vector{ max.x, max.y - r, max.z }, false);
// get animstate ptr.
CCSGOPlayerAnimState* state = pBaseEntity->GetPlayerAnimState();
// add this point only under really specific circumstances.
// if we are standing still and have the lowest possible pitch pose.
if (state && pBaseEntity->GetVelocity().Length() <= 0.1f && pBaseEntity->GetEyeAngles().x <= 75.f) {
// bottom point.
points.emplace_back(Vector{ max.x - r, max.y, max.z }, false);
}
}
}
// body has 5 points.
else {
float r = bbox->radius * GetBodyScale(pBaseEntity);
if (iHitbox == CSGOHitboxID::Stomach) {
// center.
points.emplace_back(center, true);
points.emplace_back(Vector(center.x, center.y, min.z + r), false);
points.emplace_back(Vector(center.x, center.y, max.z - r), false);
// back.
points.emplace_back(Vector{ center.x, max.y - r, center.z }, true);
}
else if (iHitbox == CSGOHitboxID::Pelvis || iHitbox == CSGOHitboxID::UpperChest) {
//points.emplace_back(center);
// left & right points
points.emplace_back(Vector(center.x, center.y, max.z + r), false);
points.emplace_back(Vector(center.x, center.y, min.z - r), false);
}
// other stomach/chest hitboxes have 2 points.
else if (iHitbox == CSGOHitboxID::LowerChest || iHitbox == CSGOHitboxID::Chest) {
// left & right points
points.emplace_back(Vector(center.x, center.y, max.z + r), false);
points.emplace_back(Vector(center.x, center.y, min.z - r), false);
// add extra point on back.
points.emplace_back(Vector{ center.x, max.y - r, center.z }, false);
}
else if (iHitbox == CSGOHitboxID::RightShin || iHitbox == CSGOHitboxID::LeftShin) {
// add center.
points.emplace_back(center, true);
// half bottom.
points.emplace_back(Vector{ max.x - (bbox->radius / 2.f), max.y, max.z }, false);
}
else if (iHitbox == CSGOHitboxID::RightThigh || iHitbox == CSGOHitboxID::LeftThigh) {
// add center.
points.emplace_back(center, true);
}
// arms get only one point.
else if (iHitbox == CSGOHitboxID::RightUpperArm || iHitbox == CSGOHitboxID::LeftUpperArm) {
// elbow.
points.emplace_back(Vector{ max.x + bbox->radius, center.y, center.z }, false);
}
else
points.emplace_back(center, true);
}
// nothing left to do here.
if (points.empty())
return points;
// transform capsule points.
for (auto& p : points)
Math::VectorTransform(p.first, bones[bbox->bone], p.first);
}
return points;
}
Vector CRagebot::GetPoint(IBasePlayer* pBaseEntity, int iHitbox, matrix BoneMatrix[128])
{
std::vector<Vector> vPoints;
if (!pBaseEntity)
return Vector(0, 0, 0);
studiohdr_t* pStudioModel = interfaces.models.model_info->GetStudioModel(pBaseEntity->GetModel());
mstudiohitboxset_t* set = pStudioModel->pHitboxSet(0);
if (!set)
return Vector(0, 0, 0);
mstudiobbox_t* untransformedBox = set->pHitbox(iHitbox);
if (!untransformedBox)
return Vector(0, 0, 0);
Vector vecMin = { 0, 0, 0 };
Math::VectorTransform_Wrapper(untransformedBox->bbmin, BoneMatrix[untransformedBox->bone], vecMin);
Vector vecMax = { 0, 0, 0 };
Math::VectorTransform_Wrapper(untransformedBox->bbmax, BoneMatrix[untransformedBox->bone], vecMax);
float mod = untransformedBox->radius != -1.f ? untransformedBox->radius : 0.f;
Vector max;
Vector min;
Math::VectorTransform(untransformedBox->bbmax + mod, BoneMatrix[untransformedBox->bone], max);
Math::VectorTransform(untransformedBox->bbmin - mod, BoneMatrix[untransformedBox->bone], min);
return (min + max) * 0.5f;
}
uint8_t CRagebot::ScanMode(IBasePlayer* pEntity)
{
int scan_mode = [&]() -> int {
auto weapon = csgo->local->GetWeapon();
if (!weapon || !pEntity->isAlive() || !csgo->local->isAlive())
return ScanType::SCAN_DEFAULT;
if (weapon->IsZeus())
return ScanType::SCAN_FORCE_SAFEPOINT;
if (g_Binds[bind_baim].active)
return ScanType::SCAN_SAFE_BAIM;
if (g_Binds[bind_force_safepoint].active)
return ScanType::SCAN_FORCE_SAFEPOINT;
const int& missed_shots = csgo->actual_misses[pEntity->GetIndex()] + std::clamp(csgo->imaginary_misses[pEntity->GetIndex()] - 1, 0, INT_MAX);
if (current_settings.max_misses > 0 && missed_shots >= current_settings.max_misses)
return missed_shots == current_settings.max_misses ? ScanType::SCAN_FORCE_SAFEPOINT : ScanType::SCAN_SAFE_BAIM;
if (current_settings.prefer_safepoint)
return ScanType::SCAN_PREFER_SAFEPOINT;
return ScanType::SCAN_DEFAULT;
}();
/*
str("Head"), 1
str("Upper chest"), 2
str("Chest"), 4
str("Lower chest"), 8
str("Pelvis"), 16
str("Stomach"), 32
str("Legs"), 64
str("Feet"), 128
str("Arms"), 256
*/
bool body_hitboxes_selected = current_settings.hitscan & 2 || current_settings.hitscan & 4
|| current_settings.hitscan & 8 || current_settings.hitscan & 16 || current_settings.hitscan & 32;
if (!body_hitboxes_selected)
return clamp(scan_mode, (int)ScanType::SCAN_DEFAULT, (int)ScanType::SCAN_PREFER_SAFEPOINT);
return scan_mode;
}
void CRagebot::BackupPlayer(animation* anims) {
auto i = anims->player->GetIndex();
backup_anims[i].origin = anims->player->GetOrigin();
backup_anims[i].abs_origin = anims->player->GetAbsOrigin();
backup_anims[i].obb_mins = anims->player->GetMins();
backup_anims[i].obb_maxs = anims->player->GetMaxs();
backup_anims[i].bone_cache = anims->player->GetBoneCache().Base();
}
void CRagebot::SetAnims(animation* anims, matrix* m) {
anims->player->GetOrigin() = anims->origin;
anims->player->SetAbsOrigin(anims->abs_origin);
anims->player->GetMins() = anims->obb_mins;
anims->player->GetMaxs() = anims->obb_maxs;
anims->player->SetBoneCache(m);
}
void CRagebot::RestorePlayer(animation* anims) {
auto i = anims->player->GetIndex();
anims->player->GetOrigin() = backup_anims[i].origin;
anims->player->SetAbsOrigin(backup_anims[i].abs_origin);
anims->player->GetMins() = backup_anims[i].obb_mins;
anims->player->GetMaxs() = backup_anims[i].obb_maxs;
anims->player->SetBoneCache(backup_anims[i].bone_cache);
}
int HitboxToHitgroup(CSGOHitboxID hitbox) {
switch (hitbox)
{
case CSGOHitboxID::Head: return HITGROUP_HEAD;
case CSGOHitboxID::Neck: return HITGROUP_NECK;
case CSGOHitboxID::Pelvis:
case CSGOHitboxID::Stomach:
return HITGROUP_STOMACH;
case CSGOHitboxID::LowerChest:
case CSGOHitboxID::Chest:
case CSGOHitboxID::UpperChest:
return HITGROUP_CHEST;
case CSGOHitboxID::RightShin:
case CSGOHitboxID::RightThigh:
case CSGOHitboxID::RightFoot:
return HITGROUP_RIGHTLEG;
case CSGOHitboxID::LeftThigh:
case CSGOHitboxID::LeftShin:
case CSGOHitboxID::LeftFoot:
return HITGROUP_LEFTLEG;
case CSGOHitboxID::RightUpperArm:
case CSGOHitboxID::RightLowerArm:
case CSGOHitboxID::RightHand:
return HITGROUP_RIGHTARM;
case CSGOHitboxID::LeftHand:
case CSGOHitboxID::LeftUpperArm:
case CSGOHitboxID::LeftLowerArm:
return HITGROUP_LEFTARM;
default: return HITGROUP_GENERIC;
}
}
bool CanHitHitbox(const Vector start, const Vector end, animation* _animation, int box, matrix* bones)
{
studiohdr_t* pStudioModel = interfaces.models.model_info->GetStudioModel(_animation->player->GetModel());
mstudiohitboxset_t* set = pStudioModel->pHitboxSet(0);
if (!set)
return false;
mstudiobbox_t* studio_box = set->pHitbox(box);
if (!studio_box)
return false;
Vector min, max;
const auto is_capsule = studio_box->radius != -1.f;
if (is_capsule)
{
Math::VectorTransform(studio_box->bbmin, bones[studio_box->bone], min);
Math::VectorTransform(studio_box->bbmax, bones[studio_box->bone], max);
const auto dist = Math::segment_to_segment(start, end, min, max);
if (dist < studio_box->radius) {
if (box == CSGOHitboxID::Head) {
g_Ragebot->BackupPlayer(_animation);
g_Ragebot->SetAnims(_animation, bones);
trace_t tr;
Ray_t ray;
ray.Init(start, end);
interfaces.trace->ClipRayToEntity(ray, MASK_SHOT | CONTENTS_GRATE, _animation->player, &tr);
g_Ragebot->RestorePlayer(_animation);
return tr.m_pEnt == _animation->player && tr.hitgroup == HITGROUP_HEAD;
}
return true;
}
}
else
{
g_Ragebot->BackupPlayer(_animation);
g_Ragebot->SetAnims(_animation, bones);
trace_t tr;
Ray_t ray;
ray.Init(start, end);
interfaces.trace->ClipRayToEntity(ray, MASK_SHOT | CONTENTS_GRATE, _animation->player, &tr);
g_Ragebot->RestorePlayer(_animation);
if (auto ent = tr.m_pEnt; ent)
{
if (ent == _animation->player) {
if (HitboxToHitgroup((CSGOHitboxID)box) == tr.hitgroup)
return true;
}
}
}
return false;
}
static const auto& is_baim_hitbox = [](int id) {
static auto baim_hitbox = {
CSGOHitboxID::Pelvis,
CSGOHitboxID::Stomach,
CSGOHitboxID::LowerChest,
CSGOHitboxID::Chest,
CSGOHitboxID::UpperChest,
};
bool found = false;
for (const auto& hitbox : baim_hitbox) {
if ((int)hitbox == id) {
found = true;
break;
}
}
return found;
};
CPoint CRagebot::GetBestPoint(std::vector<CPoint> points, int health, uint8_t scan_mode) {
if (points.empty())
return CPoint{};
static auto check_safety = [&](int hitbox, bool force = false) {
if (g_Binds[bind_force_safepoint].active)
return true;
bool head_safe = false, body_safe = false, limbs_safe = false;
if (force) {
head_safe = current_settings.force_safepoint & 1;
body_safe = current_settings.force_safepoint & 2;
limbs_safe = current_settings.force_safepoint & 4;
}
else {
head_safe = current_settings.prefer_safepoint & 1;
body_safe = current_settings.prefer_safepoint & 2;
limbs_safe = current_settings.prefer_safepoint & 4;
}
switch (hitbox)
{
case Head:
return head_safe;
case Pelvis:
case Stomach:
case LowerChest:
case Chest:
case UpperChest:
return body_safe;
case RightThigh:
case LeftThigh:
case RightShin:
case LeftShin:
case LeftFoot:
case RightFoot:
case RightHand:
case LeftHand:
case RightUpperArm:
case RightLowerArm:
case LeftUpperArm:
case LeftLowerArm:
return limbs_safe;
default:
return false;
}
};
// set priority level
for (auto& point : points) {
if (is_baim_hitbox(point.hitbox) && point.damage > health)
point.priority_level += 2;
if (check_safety(point.hitbox))
point.priority_level += point.safe;
if (point.center)
point.priority_level++;
}
std::sort(points.begin(), points.end(), [](CPoint a, CPoint b) {
return a.priority_level > b.priority_level;
});
// erase invalid points
for (auto it = points.rbegin(); it != points.rend();) {
if (check_safety(it->hitbox, true) && it->safe < 2)
it = decltype(it) {
points.erase(next(it).base())
};
else
it = next(it);
}
if (points.empty())
return CPoint{};
if (points.size() == 1) // no choice
return points[0];
// find the best point
CPoint best_point{ .damage = -1.f };
int priority = points[0].priority_level;
while (priority >= 0) {
for (auto& point : points) {
if (point.priority_level != priority)
break;
if (point.damage > best_point.damage)
best_point = point;
}
if (priority == 0 || best_point.damage > health)
return best_point;
--priority;
}
return best_point;
//switch (scan_mode)
//{
//default:
//case ScanType::SCAN_DEFAULT:
//{
// // in fact this scan mode means we're choosing points by best damage,
// // but we're checking first lethal damage in body
// CPoint bestPoint{ .damage = -1.f };
// for (const auto& p : points)
// if (p.damage > bestPoint.damage && is_baim_hitbox(p.hitbox))
// bestPoint = p;
// if (bestPoint.damage > health)
// return bestPoint;
// bestPoint.damage = -1.f;
// for (const auto& p : points)
// if (p.damage > bestPoint.damage)
// bestPoint = p;
// return bestPoint;
//};
//case ScanType::SCAN_PREFER_SAFEPOINT:
//{
// CPoint bestPoint{ .damage = -1.f };
// for (const auto& p : points) // layer 1
// if (p.damage > bestPoint.damage && p.safe && is_baim_hitbox(p.hitbox))
// bestPoint = p;
// if (bestPoint.damage > health)
// return bestPoint;
// bestPoint.damage = -1.f;
// for (const auto& p : points) // layer 2
// if (p.damage > bestPoint.damage && p.safe)
// bestPoint = p;
// if (bestPoint.damage != -1.f)
// return bestPoint;
// bestPoint.damage = -1.f;
// for (const auto& p : points) // layer 3
// if (p.damage > bestPoint.damage && is_baim_hitbox(p.hitbox))
// bestPoint = p;
// if (bestPoint.damage > health)
// return bestPoint;
// bestPoint.damage = -1.f;
// for (const auto& p : points) // layer 4
// if (p.damage > bestPoint.damage)
// bestPoint = p;
// return bestPoint;
//};
//case ScanType::SCAN_FORCE_SAFEPOINT:
//{
// CPoint bestPoint{ .damage = -1.f };
// // force safepoint is easier than prefer safepoint cuz in every scan mode
// // we're checking for lethal damage in body first
// // than we're checking other hitboxes etc.
// // so, here we're checking safe and body first, than safe & head and limbs
// for (const auto& p : points)
// if (p.damage > bestPoint.damage && p.safe && is_baim_hitbox(p.hitbox))
// bestPoint = p;
// if (bestPoint.damage > health)
// return bestPoint;
// bestPoint.damage = -1.f;
// for (const auto& p : points)
// if (p.damage > bestPoint.damage && p.safe)
// bestPoint = p;
// return bestPoint;
//};
//case ScanType::SCAN_SAFE_BAIM:
//{
// CPoint bestPoint{ .damage = -1.f };
// // this is easiest scan mode 'cause we're checking only safe points in body
// for (const auto& p : points)
// if (p.damage > bestPoint.damage && p.safe && is_baim_hitbox(p.hitbox))
// bestPoint = p;
// return bestPoint;
//};
//}
}
Vector CRagebot::HeadScan(animation* anims, int& hitbox, float min_dmg, int& i) {
int idx = anims->player->EntIndex();
memcpy(BoneMatrix, anims->bones, sizeof(matrix[128]));
memcpy(BoneMatrixInversed, anims->inversed_bones, sizeof(matrix[128]));
SetAnims(anims, BoneMatrix);
int health = anims->player->GetHealth();
if (min_dmg > health)
min_dmg = health + 1;
hitbox = 0;
std::vector<CPoint> points = {};
for (const auto& Hitbox : GetMultipoints(anims->player, 0, BoneMatrix)) {
if (!CanHitHitbox(csgo->local->GetEyePosition(), Hitbox.first, anims, 0, anims->unresolved_bones)
|| !CanHitHitbox(csgo->local->GetEyePosition(), Hitbox.first, anims, 0, BoneMatrixInversed))
continue;
i++;
const auto& damage = g_AutoWall->Think(Hitbox.first, anims->player, HitboxToHitgroup(CSGOHitboxID::Head)).m_damage;
if (damage > min_dmg)
{
points.emplace_back(CPoint{
.position = Hitbox.first,
.center = Hitbox.second,
.hitbox = hitbox,
.damage = (float)damage,
.lethal = damage > health,
.safe = 2
});
}
}
auto scan_mode = ScanType::SCAN_FORCE_SAFEPOINT;
auto best_point = GetBestPoint(points, dt_ready ? health / 2.f : health, scan_mode);
RestorePlayer(anims);
hitbox = best_point.hitbox;
anims->safepoints = best_point.safe;
anims->priority = best_point.priority_level;
best_damage = best_point.damage;
return best_point.position;
}
Vector CRagebot::PrimaryScan(animation* anims, int& hitbox, float& simtime, float min_dmg) {
int idx = anims->player->EntIndex();
memcpy(BoneMatrix, anims->bones, sizeof(matrix[128]));
simtime = anims->sim_time;
SetAnims(anims, BoneMatrix);
best_damage = -1;
auto best_point = Vector(0, 0, 0);
auto health = anims->player->GetHealth();
if (min_dmg > health)
min_dmg = health + 1;
static const vector<int> hitboxes = {
CSGOHitboxID::Head,
CSGOHitboxID::Stomach,
CSGOHitboxID::LeftFoot,
CSGOHitboxID::RightFoot,
};
int i = 0;
for (auto HitboxID : hitboxes)
{
const auto& point = GetPoint(anims->player, HitboxID, BoneMatrix);
const auto& damage = g_AutoWall->Think(point, anims->player, HitboxToHitgroup((CSGOHitboxID)HitboxID)).m_damage;
if (damage > best_damage)
{
hitbox = HitboxID;
best_point = point;
best_damage = damage;
}
if (damage < 1.f && i > 0 && best_damage < 1.f)
break;
++i;
}
RestorePlayer(anims);
return best_point;
}
Vector CRagebot::FullScan(animation* anims, int& hitbox, float& simtime, float& best_damage, float min_dmg) {
int idx = anims->player->EntIndex();
memcpy(BoneMatrix, anims->bones, sizeof(matrix[128]));
memcpy(BoneMatrixInversed, anims->inversed_bones, sizeof(matrix[128]));
simtime = anims->sim_time;
best_damage = -1;
SetAnims(anims, BoneMatrix);
int health = anims->player->GetHealth();
if (min_dmg > health)
min_dmg = health + 1;
auto hitboxes = GetHitboxesToScan(anims->player);
std::vector<CPoint> points;
for (auto HitboxID : hitboxes)
{
for (const auto& Hitbox : GetMultipoints(anims->player, HitboxID, BoneMatrix)) {
const auto& damage = g_AutoWall->Think(Hitbox.first, anims->player, HitboxToHitgroup((CSGOHitboxID)HitboxID)).m_damage;
if (damage > min_dmg)
points.emplace_back(CPoint{
.position = Hitbox.first,
.center = Hitbox.second,
.hitbox = HitboxID,
.damage = (float)damage,
.lethal = damage > health,
.safe = (int)CanHitHitbox(csgo->local->GetEyePosition(), Hitbox.first, anims, HitboxID, anims->unresolved_bones)
+ (int)CanHitHitbox(csgo->local->GetEyePosition(), Hitbox.first, anims, HitboxID, BoneMatrixInversed)
});
}
}
const auto& scan_mode = ScanMode(anims->player);
const auto& best_point = GetBestPoint(points, dt_ready ? health / 2.f : health, scan_mode);
RestorePlayer(anims);
hitbox = best_point.hitbox;
anims->safepoints = best_point.safe;
anims->priority = best_point.priority_level;
best_damage = best_point.damage;
return best_point.position;
}
Vector CRagebot::GetAimVector(IBasePlayer* pTarget, float& simtime, animation*& best_anims, int& hitbox)
{
float m_damage = 0.f;
if (csgo->weapon->IsZeus()) {
m_damage = 100.f;
}
else {
m_damage = g_Binds[bind_override_dmg].active ? current_settings.mindamage_override
: current_settings.mindamage;
}
const auto& latest_animation = g_Animfix->get_latest_animation(pTarget);
auto record = latest_animation;
if (!record || !record->player)
return Vector(0, 0, 0);
BackupPlayer(record);
const auto& oldest_animation = g_Animfix->get_oldest_animation(pTarget);
Vector latest_origin = Vector(0, 0, 0);
float best_damage_0 = -1.f, best_damage_1 = -1.f;
record = latest_animation;
if (record)
{
latest_origin = record->origin;
best_damage = -1.f;
Vector full = PrimaryScan(record, hitbox, simtime, m_damage);
if (full != Vector(0, 0, 0))
best_damage_0 = best_damage;
}
record = oldest_animation;
if (record && record->origin.DistTo(latest_animation->origin) > 25.f
&& record->resolver_mode == latest_animation->resolver_mode) // stupid fixes, but work sometimes
{
best_damage = -1.f;
Vector full = PrimaryScan(record, hitbox, simtime, m_damage);
if (full != Vector(0, 0, 0))
best_damage_1 = best_damage;
}
if (best_damage_0 >= best_damage_1)
record = latest_animation;
else
record = oldest_animation;
if (!(best_damage_0 > 0.f || best_damage_1 > 0.f) && !dt_ready) {
auto valid_animations = g_Animfix->get_valid_animations(pTarget);
int i = 0;
if (current_settings.hitscan & 1 && !g_Binds[bind_baim].active) {
best_damage = -1.f;
Vector best_point = Vector(0, 0, 0);
for (const auto& rec : valid_animations) {
Vector point = HeadScan(rec, hitbox, m_damage, i);
if (point != Vector(0, 0, 0)) {
best_anims = rec;
simtime = rec->sim_time;
best_point = point;
}
if (i > 1)
break;
}
if (best_damage != -1.f)
return best_point;
}
}
if (record)
{
best_anims = record;
Vector full_scan = FullScan(record, hitbox, simtime, best_damage, m_damage);
int health = record->player->GetHealth();
simtime = record->sim_time;
best_anims = record;
return full_scan;
}
return Vector(0, 0, 0);
}
static std::vector<std::tuple<float, float, float>> precomputed_seeds = {};
typedef void(*RandomSeed_t)(UINT);
RandomSeed_t m_RandomSeed = 0;
void random_seed(uint32_t seed) {
if (m_RandomSeed == nullptr)
m_RandomSeed = (RandomSeed_t)GetProcAddress(GetModuleHandle(str("vstdlib.dll")), str("RandomSeed"));
m_RandomSeed(seed);
}
typedef float(*RandomFloat_t)(float, float);
RandomFloat_t m_RandomFloat;
float random_float(float flLow, float flHigh)
{
if (m_RandomFloat == nullptr)
m_RandomFloat = (RandomFloat_t)GetProcAddress(GetModuleHandle(str("vstdlib.dll")), str("RandomFloat"));
return m_RandomFloat(flLow, flHigh);
}
static const int total_seeds = 255;
void build_seed_table()
{