-
Notifications
You must be signed in to change notification settings - Fork 2
/
lag_comp.cpp
4008 lines (3377 loc) · 148 KB
/
lag_comp.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 "rage_aimbot.hpp"
#include "source.hpp"
#include "entity.hpp"
#include "player.hpp"
#include "weapon.hpp"
#include "hooked.hpp"
#include "math.hpp"
#include "displacement.hpp"
#include "lag_comp.hpp"
//#include "autowall.hpp"
#include "resolver.hpp"
//#include "game_movement.h"
#include "usercmd.hpp"
#include "anti_aimbot.hpp"
#include <unordered_map>
#include <algorithm>
#include "menu.hpp"
#include "visuals.hpp"
#include "prediction.hpp"
#include "movement.hpp"
#include "sound_parser.hpp"
#include "displacement.hpp"
#include "prop_manager.hpp"
#include <thread>
#define LAG_COMPENSATION_TICKS 32
void C_Tickrecord::store(C_BasePlayer* player, bool backup)
{
//if (player != nullptr)
//{
//auto activity = player->get_sec_activity(player->get_animation_layer(1).m_nSequence);
//auto shot_bt = ((activity >= ACT_CSGO_FIRE_PRIMARY && activity <= ACT_CSGO_FIRE_SECONDARY_OPT_2) && player->get_animation_layer(1).m_flWeight > 0.01f && player->get_animation_layer(1).m_flCycle < 0.05f) || (player->get_weapon() && player->get_weapon()->m_Activity() == 208);
//type = RECORD_NORMAL;
//auto priority = ((activity == ACT_CSGO_RELOAD) && player->get_animation_layer(1).m_flWeight > 0.001f && player->get_animation_layer(1).m_flCycle < 1.f);
shot_this_tick = false;
valid = false;
dormant = false;
/*if (auto wpn = player->get_weapon(); wpn != nullptr)
shot_time = wpn->m_flLastShotTime();
else
shot_time = 0;*/
//if (priority)
// type = RECORD_PRIORITY;
bones_count = player->m_bone_count();
bones_count = Math::clamp(bones_count, 0, 128);
if (backup) {
memcpy(matrixes, player->m_CachedBoneData().Base(), bones_count * sizeof(matrix3x4_t));
valid = false;
dormant = false;
animated = true;
exploit = false;
}
//memcpy(leftmatrixes, feature::resolver->player_records[player->entindex() - 1].left_mx, bones_count * sizeof(matrix3x4_t));
//memcpy(rightmatrixes, feature::resolver->player_records[player->entindex() - 1].right_mx, bones_count * sizeof(matrix3x4_t));
//memcpy(leftlmatrixes, feature::resolver->player_records[player->entindex() - 1].left_lmx, bones_count * sizeof(matrix3x4_t));
//memcpy(rightlmatrixes, feature::resolver->player_records[player->entindex() - 1].right_lmx, bones_count * sizeof(matrix3x4_t));
//left_side = feature::resolver->player_records[player->entindex() - 1].left_side;
//right_side = feature::resolver->player_records[player->entindex() - 1].right_side;
//resolver_index = 0;
origin = player->m_vecOrigin();
abs_origin = player->get_abs_origin();
velocity = player->m_vecVelocity();
animation_time = feature::lagcomp->get_interpolated_time();
object_mins = player->OBBMins();
object_maxs = player->OBBMaxs();
eye_angles = player->m_angEyeAngles();
abs_angles = player->get_abs_angles().y;
entity_flags = player->m_fFlags();
simulation_time = player->m_flSimulationTime();
simulation_time_old = player->m_flOldSimulationTime();
lower_body_yaw = player->m_flLowerBodyYawTarget();
time_of_last_injury = player->m_flTimeOfLastInjury();
velocity_modifier = player->m_flVelocityModifier();
//anim_velocity = player->m_vecVelocity();
ientity_flags = player->m_iEFlags();
duck_amt = player->m_flDuckAmount();
ground_accel_last_time = player->m_flGroundAccelLinearFracLastTime();
if (!backup)
head_pos = player->get_bone_pos(8);
if (!backup)
desync_delta = feature::anti_aim->get_max_desync_delta(player);
thirdperson_recoil = player->m_flThirdpersonRecoil();
stop_to_full_run_frac = player->get_animation_state() ? player->get_animation_state()->m_walk_run_transition : 0.f;
if (auto weapon = player->get_weapon(); weapon != nullptr && weapon)
shot_time = weapon->m_flLastShotTime();
else
shot_time = -1;
lag = TIME_TO_TICKS(player->m_flSimulationTime() - player->m_flOldSimulationTime());
// clamp it so we don't interpolate too far : )
lag = Math::clamp(lag, 0, 31);
time_delta = player->m_flSimulationTime() - player->m_flOldSimulationTime();
if (*(void**)player && player->get_animation_state())
memcpy(&animstate, player->get_animation_state(), 0x334);
/*pose_paramaters.fill(0);
left_poses.fill(0);
right_poses.fill(0);*/
fill(begin(pose_paramaters), end(pose_paramaters), 0.f);
if (!backup) {
fill(begin(left_poses), end(left_poses), 0.f);
fill(begin(right_poses), end(right_poses), 0.f);
}
if (player->get_animation_layers_count() > 0)
memcpy(anim_layers, player->animation_layers_ptr(), 0x38 * player->get_animation_layers_count());
//*(&player->get_bone_accessor()->m_WritableBones + 8) = m_writable_bones;
//readable_bones_count = player->GetBoneAccessor().m_ReadableBones;
breaking_lc = false;
tickcount = ctx.current_tickcount;
simulation_time_delay = csgo.m_client_state()->m_clockdrift_manager.m_nServerTick - TIME_TO_TICKS(player->m_flSimulationTime());
lc_exploit = simulation_time_delay >= 12;
if (csgo.m_client_state())
m_tick = csgo.m_client_state()->m_clockdrift_manager.m_nServerTick;
latency = ctx.latency[FLOW_INCOMING];
not_desyncing = false;
data_filled = true;
//}
}
void C_Tickrecord::apply(C_BasePlayer* player, bool backup, bool dont_force_matrix)
{
//auto curr = feature::resolver->player_records[entity->entindex() - 1].resolving_method;
//if (force && curr != 0 && !entity->IsBot())
//{
// std::memcpy(entity->m_CachedBoneData().Base(), /*(lower_delta ? (curr < 0 ? record_data->leftlmatrixes : record_data->rightlmatrixes) : */(curr < 0 ? record_data->leftmatrixes : record_data->rightmatrixes)/*)*/, record_data->bones_count * sizeof(matrix3x4_t));
// entity->set_abs_angles(QAngle(0, (curr < 0 ? record_data->left_side : record_data->right_side), 0));
//}
//else {
//auto r_log = &feature::resolver->player_records[player->entindex() - 1];
const auto need_rotate = !backup && resolver_index != 0 && data_filled && animated;
player->set_abs_angles(QAngle(0, (need_rotate && !player->IsBot() ? (resolver_index == 1 ? left_side : right_side) : abs_angles), 0));
player->m_vecOrigin() = origin;
player->set_collision_bounds(object_mins, object_maxs);
player->set_abs_origin(backup ? abs_origin : origin);
if (backup && player->get_animation_layers_count() > 0)
memcpy(player->animation_layers_ptr(), anim_layers, sizeof(C_AnimationLayer) * player->get_animation_layers_count());
if (!dont_force_matrix || backup)
{
if (bones_count > 0) {
if (!need_rotate || player->IsBot())
memcpy(player->m_CachedBoneData().Base(), matrixes, bones_count * sizeof(matrix3x4_t));
else
memcpy(player->m_CachedBoneData().Base(), (resolver_index == 1 ? leftmatrixes : rightmatrixes), bones_count * sizeof(matrix3x4_t));
player->m_bone_count() = bones_count;
player->force_bone_cache();
}
}
}
void c_lagcomp::backup_players(bool restore) {
if (!ctx.m_local() || ctx.m_local()->IsDead())
return;
if (restore) {
// restore stuff.
for (int i{ 0 }; i <= csgo.m_globals()->maxClients; ++i) {
auto player = csgo.m_entity_list()->GetClientEntity(i);
if (player == nullptr || player == ctx.m_local() || player->entindex() <= 0 || player->entindex() >= 64 || player->IsDead() || player->IsDormant())
continue;
auto data = &feature::lagcomp->records[player->entindex() - 1];
if (!data || data->records_count <= 1 || data->player != player || !data->restore_record.data_filled)
continue;
data->restore_record.apply(player, true);
data->is_restored = true;
data->restore_record.data_filled = false;
}
}
else {
// backup stuff.
for (int i{ 0 }; i <= csgo.m_globals()->maxClients; ++i) {
auto player = csgo.m_entity_list()->GetClientEntity(i);
if (player == nullptr || player == ctx.m_local() || player->entindex() <= 0 || player->entindex() >= 64 || player->IsDead() || player->IsDormant())
continue;
auto data = &feature::lagcomp->records[player->entindex() - 1];
if (!data || data == nullptr || data->player != player || data->records_count <= 1 )
continue;
data->restore_record.store(player, true);
}
}
}
//bool c_lagcomp::StartPrediction(C_BasePlayer* player, c_player_records* data) {
//
// static int tick = ctx.current_tickcount;
//
// static auto sv_gravity = csgo.m_engine_cvars()->FindVar("sv_gravity");
// static auto sv_enablebunnyhopping = csgo.m_engine_cvars()->FindVar("sv_enablebunnyhopping");
// static auto sv_jump_impulse = csgo.m_engine_cvars()->FindVar("sv_jump_impulse");
//
// // we have no data to work with.
// // this should never happen if we call this
// if (data->tick_records.empty())
// return false;
//
// // meme.
// if (!player || player != data->player || data->player->IsDormant())
// return false;
//
// // compute the true amount of updated records
// // since the last time the player entered pvs.
// size_t size{};
//
// // iterate records.
// for (const auto& it : data->tick_records) {
// if (it.dormant)
// break;
//
// // increment total amount of data.
// ++size;
// }
//
// static float m_latency;
// static int m_latency_ticks;
// static int m_server_tick;
// static int m_arrival_tick;
//
// if (tick != ctx.current_tickcount)
// {
// m_latency = csgo.m_engine()->GetNetChannelInfo()->GetLatency(FLOW_OUTGOING);
// m_latency = Math::clamp(m_latency, 0.f, 1.f);
// m_latency_ticks = TIME_TO_TICKS(m_latency);
// m_server_tick = *(int*)(uintptr_t(csgo.m_client_state()) + 0x170);
// m_arrival_tick = m_server_tick + m_latency_ticks;
// tick = ctx.current_tickcount;
// }
//
// // get first record.
// C_Tickrecord* record = &data->tick_records[0];
//
// // reset all prediction related variables.
// // this has been a recurring problem in all my hacks lmfao.
// // causes the prediction to stack on eachother.
// record->setup_simulation();
//
// // check if lc broken.
// if (size > 1 && ((record->origin - data->tick_records[1].origin).LengthSquared() > 4096.f
// || size > 2 && (data->tick_records[1].origin - data->tick_records[2].origin).LengthSquared() > 4096.f))
// record->m_broke_lc = true;
//
// // we are not breaking lagcomp at this point.
// // return false so it can aim at all the records it once
// // since server-sided lagcomp is still active and we can abuse that.
// if (!record->m_broke_lc)
// return false;
//
// int simulation = TIME_TO_TICKS(record->simulation_time);
//
// // this is too much lag to fix.
// if (std::abs(m_arrival_tick - simulation) >= 128)
// return true;
//
// // compute the amount of lag that we will predict for, if we have one set of data, use that.
// // if we have more data available, use the prevoius lag delta to counter weird fakelags that switch between 14 and 2.
// int lag = (size <= 2) ? TIME_TO_TICKS(record->simulation_time - data->tick_records[1].simulation_time)
// : TIME_TO_TICKS(data->tick_records[1].simulation_time - data->tick_records[2].simulation_time);
//
// // clamp this just to be sure.
// Math::clamp(lag, 1, 15);
//
// // get the delta in ticks between the last server net update
// // and the net update on which we created this record.
// int updatedelta = (*(int*)(uintptr_t(csgo.m_client_state()) + 0x170)) - record->m_tick;
//
// // 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 (m_latency_ticks <= lag - updatedelta)
// return true;
//
// // the next update will come in, wait for it.
// int next = record->m_tick + 1;
// if (next + lag >= m_arrival_tick)
// return true;
//
// float change = 0.f, dir = 0.f;
//
// // get the direction of the current velocity.
// if (record->velocity.y != 0.f || record->velocity.x != 0.f)
// dir = RAD2DEG(std::atan2(record->velocity.y, record->velocity.x));
//
// // we have more than one update
// // we can compute the direction.
// if (size > 1) {
// // get the delta time between the 2 most recent records.
// float dt = record->simulation_time - data->tick_records[1].simulation_time;
//
// // init to 0.
// float prevdir = 0.f;
//
// // get the direction of the prevoius velocity.
// if (data->tick_records[1].velocity.y != 0.f || data->tick_records[1].velocity.x != 0.f)
// prevdir = RAD2DEG(std::atan2(data->tick_records[1].velocity.y, data->tick_records[1].velocity.x));
//
// // compute the direction change per tick.
// change = (Math::normalize_angle(dir - prevdir) / dt) * csgo.m_globals()->interval_per_tick;
// }
//
// if (std::abs(change) > 6.f)
// change = 0.f;
//
// // get the pointer to the players animation state.
// CCSGOPlayerAnimState* state = player->get_animation_state();
//
// // backup the animation state.
// CCSGOPlayerAnimState backup{};
//
// if (state)
// std::memcpy(&backup, state, sizeof(CCSGOPlayerAnimState));
//
// // add in the shot prediction here.
// //int shot = 0;
//
// //auto pWeapon = player->get_weapon( );
// //if( pWeapon && pWeapon->IsGun()/*&& !data->m_fire_bullet.empty( )*/ ) {
//
// // //static Address offset = g_netvars.get( HASH( "DT_BaseCombatWeapon" ), HASH( "m_fLastShotTime" ) );
// // //float last = pWeapon->get< float >( offset );
//
// // if( TIME_TO_TICKS( player->m_flSimulationTime() - pWeapon->m_flLastShotTime() ) == 1 ) {
// // auto wpndata = pWeapon->GetCSWeaponData( );
//
// // if( wpndata )
// // shot = TIME_TO_TICKS(player->m_flSimulationTime() + wpndata->flCycleTime) + 1;
// // }
// //}
//
// int pred = 0;
//
// // start our predicton loop.
// while (true) {
// // can the player shoot within his lag delta.
// //if( shot && shot >= simulation && shot < simulation + lag ) {
//
// // // if so his new lag will be the time until he shot again.
// // lag = shot - simulation;
// // Math::clamp( lag, 3, 15 );
//
// // // only predict a shot once.
// // shot = 0;
// //}
//
// // see if by predicting this amount of lag
// // we do not break stuff.
// next += lag;
// if (next >= m_arrival_tick)
// break;
//
// // predict lag.
// for (int sim{}; sim < lag; ++sim) {
// // predict movement direction by adding the direction change per tick to the previous direction.
// // make sure to normalize it, in case we go over the -180/180 turning point.
// dir = Math::normalize_angle(dir + change);
//
// // pythagorean theorem
// // a^2 + b^2 = c^2
// // we know a and b, we square them and add them together, then root.
// float hyp = record->m_pred_velocity.Length2D();
//
// // compute the base velocity for our new direction.
// // since at this point the hypotenuse is known for us and so is the angle.
// // we can compute the adjacent and opposite sides like so:
// // cos(x) = a / h -> a = cos(x) * h
// // sin(x) = o / h -> o = sin(x) * h
// record->m_pred_velocity.x = std::cos(DEG2RAD(dir)) * hyp;
// record->m_pred_velocity.y = std::sin(DEG2RAD(dir)) * hyp;
//
// // we hit the ground, set the upwards impulse and apply CS:GO speed restrictions.
// if (record->m_pred_flags & FL_ONGROUND) {
// if (!sv_enablebunnyhopping->GetInt()) {
//
// // 260 x 1.1 = 286 units/s.
// float max = (player->get_weapon() ? player->get_weapon()->GetMaxWeaponSpeed() : 260.f) * 1.1f;
//
// // get current velocity.
// float speed = record->m_pred_velocity.Length();
//
// // reset velocity to 286 units/s.
// if (max > 0.f && speed > max)
// record->m_pred_velocity *= (max / speed);
// }
//
// // assume the player is bunnyhopping here so set the upwards impulse.
// record->m_pred_velocity.z = sv_jump_impulse->GetFloat();
// }
//
// // we are not on the ground
// // apply gravity and airaccel.
// else {
// // apply one tick of gravity.
// record->m_pred_velocity.z -= sv_gravity->GetFloat() * csgo.m_globals()->interval_per_tick;
//
// // compute the ideal strafe angle for this velocity.
// float speed2d = record->m_pred_velocity.Length2D();
// float ideal = (speed2d > 0.f) ? RAD2DEG(std::asin(15.f / speed2d)) : 90.f;
// Math::clamp(ideal, 0.f, 90.f);
//
// float smove = 0.f;
// float abschange = std::abs(change);
//
// if (abschange <= ideal || abschange >= 30.f) {
// static float mod{ 1.f };
//
// dir += (ideal * mod);
// smove = 450.f * mod;
// mod *= -1.f;
// }
//
// else if (change > 0.f)
// smove = -450.f;
//
// else
// smove = 450.f;
//
// // apply air accel.
// AirAccelerate(player, record, QAngle{ 0.f, dir, 0.f }, 0.f, smove);
// }
//
// // predict player.
// // convert newly computed velocity
// // to origin and flags.
// PlayerMove(record);
//
// // move time forward by one.
// record->m_pred_time += csgo.m_globals()->interval_per_tick;
//
// // increment total amt of predicted ticks.
// ++pred;
//
// // the server animates every first choked command.
// // therefore we should do that too.
// if (/*sim == 0 && */state)
// PredictAnimations(player, state, record);
// }
// }
//
// // restore state.
// if (state)
// std::memcpy(state, &backup, sizeof(CCSGOPlayerAnimState));
//
// if (pred <= 0)
// return true;
//
// // lagcomp broken, invalidate bones.
// //record->invalidate();
//
// // re-setup bones for this record.
// //g_bones.setup(data->player, nullptr, record);
// player->force_bone_rebuild();
// player->SetupBonesEx();
//
// return true;
//}
//
//void c_lagcomp::PlayerMove(C_Tickrecord* record) {
// Vector start, end, normal;
// CGameTrace trace;
// CTraceFilterWorldOnly filter;
//
// // define trace start.
// start = record->m_pred_origin;
//
// // move trace end one tick into the future using predicted velocity.
// end = start + (record->m_pred_velocity * csgo.m_globals()->interval_per_tick);
//
// // trace.
// Ray_t t; t.Init(start, end, record->object_mins, record->object_maxs);
//
// csgo.m_engine_trace()->TraceRay(t, 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) {
// record->m_pred_velocity -= trace.plane.normal * record->m_pred_velocity.Dot(trace.plane.normal);
//
// float adjust = record->m_pred_velocity.Dot(trace.plane.normal);
// if (adjust < 0.f)
// record->m_pred_velocity -= (trace.plane.normal * adjust);
//
// start = trace.endpos;
// end = start + (record->m_pred_velocity * (csgo.m_globals()->interval_per_tick * (1.f - trace.fraction)));
//
// Ray_t td; td.Init(start, end, record->object_mins, record->object_maxs);
// csgo.m_engine_trace()->TraceRay(td, CONTENTS_SOLID, &filter, &trace);
// if (trace.fraction == 1.f)
// break;
// }
// }
//
// // set new final origin.
// start = end = record->m_pred_origin = trace.endpos;
//
// // move endpos 2 units down.
// // this way we can check if we are in/on the ground.
// end.z -= 2.f;
//
// Ray_t tz; tz.Init(start, end, record->object_mins, record->object_maxs);
//
// // trace.
// csgo.m_engine_trace()->TraceRay(tz, CONTENTS_SOLID, &filter, &trace);
//
// // strip onground flag.
// record->m_pred_flags &= ~FL_ONGROUND;
//
// // add back onground flag if we are onground.
// if (trace.fraction != 1.f && trace.plane.normal.z > 0.7f)
// record->m_pred_flags |= FL_ONGROUND;
//}
//
//void c_lagcomp::AirAccelerate(C_BasePlayer* m_player,C_Tickrecord* record, QAngle angle, float fmove, float smove) {
// Vector fwd, right, wishvel, wishdir;
// float maxspeed, wishspd, wishspeed, currentspeed, addspeed, accelspeed;
// static auto sv_airaccelerate = csgo.m_engine_cvars()->FindVar("sv_airaccelerate");
//
// // determine movement angles.
// Math::AngleVectors(angle, &fwd, &right, nullptr);
//
// // zero out z components of movement vectors.
// fwd.z = 0.f;
// right.z = 0.f;
//
// // normalize remainder of vectors.
// fwd.Normalize();
// right.Normalize();
//
// // 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;
// wishspeed = wishdir.Normalize();
//
// // get maxspeed.
// // TODO; maybe global this or whatever its 260 anyway always.
// maxspeed = m_player->get_weapon() ? m_player->get_weapon()->GetMaxWeaponSpeed() : 260.f;
//
// // 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 = record->m_pred_velocity.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 = sv_airaccelerate->GetFloat() * wishspeed * csgo.m_globals()->interval_per_tick;
//
// // cap it.
// if (accelspeed > addspeed)
// accelspeed = addspeed;
//
// // add accel.
// record->m_pred_velocity += (wishdir * accelspeed);
//}
//
//void c_lagcomp::PredictAnimations(C_BasePlayer* m_player, CCSGOPlayerAnimState* state, C_Tickrecord* record) {
// struct AnimBackup_t {
// float curtime;
// float frametime;
// int flags;
// int eflags;
// Vector velocity;
// };
//
// const auto resolver_info = &feature::resolver->player_records[m_player->entindex()-1];
//
// // backup data.
// AnimBackup_t backup;
// backup.curtime = csgo.m_globals()->curtime;
// backup.frametime = csgo.m_globals()->frametime;
// backup.flags = m_player->m_fFlags();
// backup.eflags = m_player->m_iEFlags();
// backup.velocity = m_player->m_vecAbsVelocity();
//
// state->last_anim_upd_time = record->m_pred_time - csgo.m_globals()->interval_per_tick;
//
// // set globals appropriately for animation.
// csgo.m_globals()->curtime = record->m_pred_time;
// csgo.m_globals()->frametime = csgo.m_globals()->interval_per_tick;
//
// // EFL_DIRTY_ABSVELOCITY
// // skip call to C_BaseEntity::CalcAbsoluteVelocity
// m_player->m_iEFlags() &= ~0x1000;
//
// // set predicted flags and velocity.
// m_player->m_fFlags() = record->m_pred_flags;
// m_player->m_vecAbsVelocity() = record->m_pred_velocity;
//
// // enable re-animation in the same frame if animated already.
// if (state->last_anim_upd_tick >= csgo.m_globals()->framecount)
// state->last_anim_upd_tick = csgo.m_globals()->framecount - 1;
//
// ////bool fake = g_menu.main.aimbot.correct.get();
// //
// //// rerun the resolver since we edited the origin.
// //if (fake)
// // g_resolver.ResolveAngles(player, record);
// //
// //// update animations.
// //game::UpdateAnimationState(state, record->m_eye_angles);
//
// record->can_rotate = record->valid && !m_player->IsBot();
//
// m_player->m_angEyeAngles() = record->eye_angles;
//
// feature::resolver->store_data(m_player, record, true);
//
// if (record->can_rotate && resolver_info->resolving_method > 0)
// m_player->get_animation_state()->abs_yaw = Math::normalize_angle(record->eye_angles.y + (resolver_info->resolving_method == 1 ? -60.f : 60.f));
//
// /* update animations. */
// ctx.updating_resolver = true;
// m_player->update_clientside_animations();
// ctx.updating_resolver = false;
//
// //// rerun the pose correction cuz we are re-setupping them.
// //if (fake)
// // g_resolver.ResolvePoses(player, record);
//
// // get new rotation poses and layers.
// //player->GetPoseParameters(record->m_poses);
// //player->GetAnimLayers(record->m_layers);
// //record->m_abs_ang = player->GetAbsAngles();
//
// record->animstate = *m_player->get_animation_state();
//
// // restore globals.
// csgo.m_globals()->curtime = backup.curtime;
// csgo.m_globals()->frametime = backup.frametime;
//
// // restore player data.
// m_player->m_fFlags() = backup.flags;
// m_player->m_iEFlags() = backup.eflags;
// m_player->m_vecAbsVelocity() = backup.velocity;
//}
void c_lagcomp::update_lerp()
{
static auto cl_interp = csgo.m_engine_cvars()->FindVar(sxor("cl_interp"));
static auto cl_updaterate = csgo.m_engine_cvars()->FindVar(sxor("cl_updaterate"));
static auto cl_interp_ratio = csgo.m_engine_cvars()->FindVar(sxor("cl_interp_ratio"));
const auto a2 = cl_updaterate->GetFloat();
const auto a1 = cl_interp->GetFloat();
const auto v2 = cl_interp_ratio->GetFloat() / a2;
ctx.lerp_time = fmaxf(a1, v2);
}
void c_lagcomp::update_network_info()
{
//static auto cl_interp = csgo.m_engine_cvars()->FindVar(sxor("cl_interp"));
//static auto cl_updaterate = csgo.m_engine_cvars()->FindVar(sxor("cl_updaterate"));
//static auto cl_interp_ratio = csgo.m_engine_cvars()->FindVar(sxor("cl_interp_ratio"));
////static auto pMin = csgo.m_engine_cvars()->FindVar("sv_client_min_interp_ratio");
////static auto pMax = csgo.m_engine_cvars()->FindVar("sv_client_max_interp_ratio");
///*static auto sv_client_min_interp_ratio = csgo.m_engine_cvars()->FindVar(sxor("sv_client_min_interp_ratio"));
//static auto sv_client_max_interp_ratio = csgo.m_engine_cvars()->FindVar(sxor("sv_client_max_interp_ratio"));
//static auto sv_minupdaterate = csgo.m_engine_cvars()->FindVar(sxor("sv_minupdaterate"));
//static auto sv_maxupdaterate = csgo.m_engine_cvars()->FindVar(sxor("sv_maxupdaterate"));
//auto updaterate = std::clamp(cl_updaterate->GetFloat(), sv_minupdaterate->GetFloat(), sv_maxupdaterate->GetFloat());
//auto lerp_ratio = std::clamp(cl_interp_ratio->GetFloat(), sv_client_min_interp_ratio->GetFloat(), sv_client_max_interp_ratio->GetFloat());
//ctx.lerp_time = std::clamp(lerp_ratio / updaterate, cl_interp->GetFloat(), 1.0f);*/
//const auto a2 = cl_updaterate->GetFloat();
//const auto a1 = cl_interp->GetFloat();
//const auto v2 = cl_interp_ratio->GetFloat() / a2;
//ctx.lerp_time = fmaxf(a1, v2);
/*float flUpdateRateValue = double(cl_updaterate->GetFloat());
if (!csgo.m_engine()->IsHLTV())
{
static const ConVar* pMinUpdateRate = csgo.m_engine_cvars()->FindVar("sv_minupdaterate");
static const ConVar* pMaxUpdateRate = csgo.m_engine_cvars()->FindVar("sv_maxupdaterate");
if (pMinUpdateRate && pMaxUpdateRate)
flUpdateRateValue = Math::clamp(flUpdateRateValue, pMinUpdateRate->GetFloat(), pMaxUpdateRate->GetFloat());
}
float flLerpRatio = double(cl_interp_ratio->GetFloat());
if (flLerpRatio == 0)
flLerpRatio = 1.0f;
float flLerpAmount = double(cl_interp->GetFloat());
if (pMin && pMax && pMin->GetFloat() != -1)
{
flLerpRatio = Math::clamp(flLerpRatio, pMin->GetFloat(), pMax->GetFloat());
}
else
{
if (flLerpRatio == 0)
flLerpRatio = 1.0f;
}
ctx.lerp_time = fmax(flLerpAmount, flLerpRatio / flUpdateRateValue);*/
//static float latency;
//static int latency_count;
//else {
// latency = 0.f;
// latency_count = 0;
//}
if (auto net = csgo.m_engine()->GetNetChannelInfo(); net != nullptr) {
//latency_count++;
//latency += net->GetLatency(FLOW_OUTGOING);
//if (latency_count <= 3) {
ctx.latency[FLOW_OUTGOING] = net->GetLatency(FLOW_OUTGOING);
//}
//else
//{
// ctx.latency[FLOW_OUTGOING] = latency / latency_count;
//}
ctx.latency[FLOW_INCOMING] = net->GetLatency(FLOW_INCOMING);
ctx.avglatency[FLOW_OUTGOING] = net->GetAvgLatency(FLOW_OUTGOING);
ctx.avglatency[FLOW_INCOMING] = net->GetAvgLatency(FLOW_INCOMING);
}
else {
ctx.latency[FLOW_OUTGOING] = csgo.m_globals()->interval_per_tick;
ctx.latency[FLOW_OUTGOING] = 0;
}
//if (latency_count > 200)
//{
// latency = 0.f;
// latency_count = 0;
//}
/*const auto update_rate = cl_updaterate->GetInt();
const auto interp_ratio = cl_interp->GetFloat();
auto lerp = interp_ratio / update_rate;
if (lerp <= cl_interp->GetFloat())
lerp = cl_interp->GetFloat();
ctx.lerp_time = lerp;*/
}
void c_lagcomp::simulate_movement(C_Simulationdata& data) {
static auto sv_gravity = csgo.m_engine_cvars()->FindVar(sxor("sv_gravity"));
static auto sv_jump_impulse = csgo.m_engine_cvars()->FindVar(sxor("sv_jump_impulse"));
if (!(data.flags & FL_ONGROUND)) {
data.velocity.z -= (csgo.m_globals()->interval_per_tick * sv_gravity->GetFloat() * 0.5f);
}
else if (data.jumped) {
data.jumped = false;
data.velocity.z = sv_jump_impulse->GetFloat();
data.flags &= ~FL_ONGROUND;
}
// can't step up onto very steep slopes
static const float MIN_STEP_NORMAL = 0.7f;
if (!data.velocity.IsZero()) {
auto* collidable = data.entity->GetCollideable();
const Vector mins = collidable->OBBMins();
const Vector max = collidable->OBBMaxs();
const Vector src = data.origin;
Vector end = src + (data.velocity * csgo.m_globals()->interval_per_tick);
Ray_t ray;
ray.Init(src, end, mins, max);
CGameTrace trace;
CTraceFilter filter;
filter.pSkip = data.entity;
csgo.m_engine_trace()->TraceRay(ray, MASK_SOLID, &filter, &trace);
// CGameMovement::TryPlayerMove
if (trace.fraction != 1) {
// BUGFIXME: is it should be 4? ( not 2 )
for (int i = 0; i < 2; i++) {
// decompose velocity into plane
data.velocity -= trace.plane.normal * data.velocity.Dot(trace.plane.normal);
const float dot = data.velocity.Dot(trace.plane.normal);
if (dot < 0.f) { // moving against plane
data.velocity.x -= dot * trace.plane.normal.x;
data.velocity.y -= dot * trace.plane.normal.y;
data.velocity.z -= dot * trace.plane.normal.z;
}
end = trace.endpos + (data.velocity * (csgo.m_globals()->interval_per_tick * (1.f - trace.fraction)));
ray.Init(trace.endpos, end, mins, max);
csgo.m_engine_trace()->TraceRay(ray, MASK_SOLID, &filter, &trace);
if (trace.fraction == 1)
break;
}
}
data.origin = trace.endpos;
end = trace.endpos;
end.z -= 2;
ray.Init(data.origin, end, mins, max);
csgo.m_engine_trace()->TraceRay(ray, MASK_SOLID, &filter, &trace);
data.flags &= ~FL_ONGROUND;
if (trace.DidHit() && trace.plane.normal.z >= MIN_STEP_NORMAL) {
data.flags |= FL_ONGROUND;
}
if (data.flags & FL_ONGROUND)
data.velocity.z = 0;
else
data.velocity.z -= csgo.m_globals()->interval_per_tick * sv_gravity->GetFloat() * 0.5f;
}
}
bool c_lagcomp::is_time_delta_too_large(C_Tickrecord* wish_record, bool ignore_deadtime)
{
if (max(ctx.latency[FLOW_INCOMING], ctx.latency[FLOW_OUTGOING]) <= 0.0f) // how???
return true;
static auto sv_maxunlag = csgo.m_engine_cvars()->FindVar(sxor("sv_maxunlag"));
static auto sv_max_usercmd_future_ticks = csgo.m_engine_cvars()->FindVar(sxor("sv_max_usercmd_future_ticks"));
// server tickcount when cmd will arrive
auto latency_ticks = 1;
if (ctx.last_4_deltas.size() >= 2) {
latency_ticks = 0;
int added = 0;
for (auto d : ctx.last_4_deltas)
{
latency_ticks += d;
++added;
if (added >= 7)
break;
}
latency_ticks /= 7;
}
auto serverTickcount = csgo.m_engine()->GetTick() + TIME_TO_TICKS(ctx.latency[FLOW_OUTGOING]);
if (ctx.fakeducking)
serverTickcount += 15 - csgo.m_client_state()->m_iChockedCommands;
float total_latency = ctx.latency[FLOW_OUTGOING] + ctx.latency[FLOW_INCOMING];
total_latency = fminf(fmaxf(total_latency, 0.0f), 1.0f);
float correct = total_latency + ctx.lerp_time;
correct = Math::clamp(correct, 0.f, sv_maxunlag->GetFloat());
auto shift = 0;
if (ctx.fakeducking || !ctx.exploit_allowed || !ctx.has_exploit_toggled || ctx.main_exploit == 0 || ctx.applied_tickbase)
shift = 0;
else {
if (ctx.exploit_allowed && ctx.has_exploit_toggled && !ctx.fakeducking)
{
shift = max(ctx.shift_amount, ctx.next_shift_amount);
if (ctx.main_exploit == 2)
shift = 0;
if (ctx.main_exploit == 2 && ctx.force_aimbot < 1 && ctx.ticks_allowed > 13 && abs(ctx.current_tickcount - ctx.started_speedhack) > 16)
shift = 13;
else
if (ctx.m_settings.aimbot_extra_doubletap_options[3] && ctx.ticks_allowed > 12 && std::fabsf(csgo.m_globals()->realtime - ctx.last_speedhack_time) > 0.5f && ctx.allow_shooting < 1 && ctx.force_aimbot < 1)
shift = 12;
}
}
auto time = csgo.m_globals()->curtime;
if (ctx.m_local() && !ctx.m_local()->IsDead())
time = TICKS_TO_TIME(ctx.m_local()->m_nTickBase() - shift);
float deltaTime = abs(correct - (time - wish_record->simulation_time));
if (deltaTime >= 0.2f)
return true;
if (!(ctx.fakeducking || !ctx.exploit_allowed || !ctx.has_exploit_toggled || ctx.main_exploit != 2)
&& ctx.force_aimbot > 1
&& ctx.ticks_allowed < 13
&& abs(ctx.started_speedhack - ctx.current_tickcount) <= 16)
return false;
return ignore_deadtime || wish_record->simulation_time < float(int(TICKS_TO_TIME(serverTickcount) - sv_maxunlag->GetFloat()));
}
//void c_lagcomp::update_player_record_data(C_BasePlayer* entity)
//{
// if (entity == nullptr)
// return;
//
// auto player_index = entity->entindex() - 1;
// auto player_record = &records[player_index];
//
// auto resolve_info = &feature::resolver->player_records[player_index];
//
// if (!player_record->m_Tickrecords.empty() && player_record->m_Tickrecords.front().simulation_time >= entity->m_flSimulationTime())
// resolve_info->is_shifting = (player_record->m_Tickrecords.front().eye_angles != entity->m_angEyeAngles() || player_record->m_Tickrecords.front().origin != entity->m_vecOrigin());
//
// const float tickrate = (1 / csgo.m_globals()->interval_per_tick) / 2.f;
//
// const auto wtf = abs(csgo.m_globals()->tickcount - TIME_TO_TICKS(entity->m_flSimulationTime()));
// auto unlag = wtf <= tickrate;
//
// resolve_info->simtime_updated = false;
//
// if (entity->m_flSimulationTime() > 0.f && player_record->m_Tickrecords.empty() && unlag || !player_record->m_Tickrecords.empty() && player_record->m_Tickrecords.front().simulation_time != entity->m_flSimulationTime() && unlag)
// {
// resolve_info->simtime_updated = true;
//
// auto pasti = player_record->m_Tickrecords;
//
// if (!player_record->m_Tickrecords.empty())
// update_animations_data(entity);
//
// if (resolve_info->resolving_method == -1)
// return;
//
// if (entity->m_flSimulationTime() > 0.f && player_record->m_Tickrecords.empty() || !is_time_delta_too_large(entity->m_flSimulationTime()))