-
Notifications
You must be signed in to change notification settings - Fork 42
/
lagcomp_legit.cpp
152 lines (117 loc) · 3.47 KB
/
lagcomp_legit.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
#include "lagcomp_legit.h"
#include "boner.h"
c_lagcomp_legit g_lagcomp_legit;
void c_lagcomp_legit::init()
{
current_target = nullptr;
if ( !ctx.m_local || !ctx.m_local->alive( ) )
return;
if ( ctx.m_settings.rage_aimbot_enabled )
return;
if ( !ctx.m_settings.legit_enabled || !ctx.m_settings.legit_backtrack )
return;
update( );
set_tick( );
}
void c_lagcomp_legit::legit_record::update(c_base_entity* entity, int tickcount )
{
if ( entity != m_entity )
{
m_data.clear( );
m_entity = entity;
}
legit_record_entry new_entry;
new_entry.tickcount = tickcount;
g_boner.get_latest( entity->index( ), new_entry.bone_matrix );
new_entry.aim_pos = entity->abs_origin( ) + vec3( 0.f, 0.f, 40.f );
m_data.push_front( new_entry );
while ( m_data.size( ) > ctx.m_tickrate )
m_data.pop_back( );
}
void c_lagcomp_legit::update( )
{
for ( int i = 1; i < 65; i++ )
{
c_base_entity* entity = csgo.m_entity_list( )->get_entity( i );
if ( !entity || !entity->alive( ) || entity->dormant( ) || entity->immune( ) )
{
m_records[i].reset( );
continue;
}
m_records[i].update( entity, ctx.m_cmd->m_tickcount );
}
}
void c_lagcomp_legit::set_tick( )
{
vec3 viewangles = csgo.m_engine( )->GetViewAngles( );
vec3 punch = ctx.m_local->punch( ) * 2.0f;
viewangles -= punch;
c_base_entity* target{ };
if ( find_closest_target( &target, viewangles ) )
backtrack_target( target, viewangles );
}
bool c_lagcomp_legit::find_closest_target( c_base_entity** target, const vec3& viewangles )
{
int local_team = ctx.m_local->team( );
vec3 local_pos = ctx.m_local->eye_origin( );
c_base_entity* found_target{ };
float distance = 180.f;
for ( int i = 1; i < 65; i++ )
{
c_base_entity* entity = csgo.m_entity_list( )->get_entity( i );
if ( !entity || entity == ctx.m_local )
continue;
if ( !entity->alive( ) || entity->dormant( ) || entity->immune( ) )
continue;
if ( entity->team( ) == local_team )
continue;
vec3 target_pos = entity->abs_origin( ) + vec3( 0.f, 0.f, 40.f );
vec3 target_angles;
math::vector_angles( target_pos - local_pos, target_angles );
vec3 delta = target_angles - viewangles;
delta.sanitize( );
float dist = delta.length2d( );
if ( distance > dist )
{
distance = dist;
found_target = entity;
}
}
*target = found_target;
return !!found_target;
}
void c_lagcomp_legit::backtrack_target( c_base_entity* target, const vec3& viewangles )
{
legit_record* record = &m_records[target->index( )];
if ( record->m_entity != target )
return;
vec3 local_pos = ctx.m_local->eye_origin( );
int target_tickcount{ };
matrix3x4_t* target_matrix = nullptr;
float distance = 180.f;
for ( size_t i{ }; i < record->m_data.size( ); i++ )
{
legit_record_entry* entry = &record->m_data.at( i );
vec3 target_angles;
math::vector_angles( entry->aim_pos - local_pos, target_angles );
vec3 delta = target_angles - viewangles;
delta.sanitize( );
float dist = delta.length2d( );
float time_delta = std::abs( ( csgo.m_globals()->tickcount - entry->tickcount ) * csgo.m_globals()->interval_per_tick );
if ( distance > dist && time_delta <= ctx.m_settings.legit_backtrack_range )
{
distance = dist;
target_tickcount = entry->tickcount;
target_matrix = entry->bone_matrix;
}
}
if ( target_tickcount && target_matrix )
{
ctx.m_cmd->m_tickcount = target_tickcount;
if ( ctx.m_settings.legit_backtrack_visualize )
{
current_target = target;
memcpy( current_matrix, target_matrix, sizeof( matrix3x4_t ) * 128 );
}
}
}