summaryrefslogtreecommitdiff
path: root/cheat/internal_rewrite/lag_mgr.cpp
blob: 0233e4a606517f0d9dba3d62ce3feb10204b102e (plain)
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
#include "lag_mgr.hpp"
#include "c_base_player.hpp"
#include "context.hpp"
#include "interface.hpp"
#include "base_cheat.hpp"

namespace features
{
	void c_lagmgr::on_antiaim( ) {
		if( m_sent_ticks ) {
			*m_sendpacket = false;
		}
	}
	
	bool c_lagmgr::predict_position( float dist ) {
		vec3_t local_pos = g_ctx.m_local->get_eye_pos( );

		auto i = util::get_closest_player( );
		auto ent = g_csgo.m_entlist( )->GetClientEntity< >( i );

		if( !ent || !ent->is_valid( ) )
			return true;
		
		auto wep = ent->get_weapon( );
		if( !wep ) {
			return true;
		}

		float dmg_begin = g_cheat.m_autowall.run( ent, g_ctx.m_local, local_pos, false );
		bool is_visible = dmg_begin > 10.f;

		if( !is_visible ) {
			vec3_t position = local_pos;

			vec3_t velocity_ang = math::vector_angles( vec3_t( ), g_ctx.m_local->m_vecVelocity( ) );
			vec3_t velocity_dir = math::angle_vectors( velocity_ang );

			//fuck getting pulled back on peek
			position += velocity_dir * 20.f;

			float dmg = g_cheat.m_autowall.run( ent, g_ctx.m_local, position, false );

			if( dmg > 25.f )
				return false;
		}

		return true;
	}

	void c_lagmgr::fakelag( ) {
		//2017 sucked
		//i hope 2018 goes better

		if( !g_settings.rage.fakelag.mode( ) ||
			!g_settings.rage.fakelag.ticks( ) ) {
			m_breaking_lc = false;
			return;
		}

		static float last_rand = 0.f;

		auto& settings = g_settings.rage.fakelag;

		auto weapon = g_ctx.m_local->get_weapon( );

		if( g_cheat.m_ragebot.m_antiaim->is_fakewalking( ) ) {
			return;
		}

		bool moving = g_ctx.m_local->m_vecVelocity( ).length2d( ) > 0.f;

		vec3_t delta = g_ctx.m_last_origin - g_ctx.m_local->m_vecOrigin( );
		int max_ticks = g_settings.rage.fakelag.ticks( );
		if( settings.fluctuate )
			max_ticks *= last_rand;

		static bool changed = false;
		static auto cl_sendmove = pattern::first_code_match( g_csgo.m_engine.dll( ), xors( "55 8B EC A1 ? ? ? ? 81 EC ? ? ? ? B9 ? ? ? ? 53 8B 98" ), 0 );
		
		if( !changed ) {
			ulong_t old;
			VirtualProtect( ( void* )( cl_sendmove + 0xbd ), 1, PAGE_EXECUTE_READWRITE, &old );
			*( uint8_t* )( cl_sendmove + 0xbd ) = 50;
			VirtualProtect( ( void* )( cl_sendmove + 0xbd ), 1, old, nullptr );
		}

		changed = true;

		max_ticks = math::min( max_ticks, 16 );

		bool force_send = m_held_ticks >= max_ticks;
		if( settings.mode == 1 ) {
			if( delta.length2dsqr( ) > 4096.f ) {
				force_send = get_choked( ) > 3;
			}
		}

		if( settings.mode == 2 ) {
			static bool broken_lc = false;
			bool should_send = false;

			if( broken_lc ) {
				should_send = math::random_number( 0, 100 ) % 2;
				if( get_choked( ) > 1 )
					broken_lc = false;
			}

			if( should_send )
				force_send = true;
			else if( delta.length2dsqr( ) > 4096.f ) {
				force_send = get_choked( ) > 3;
				broken_lc = true;
			}
		}

		bool send = true;
		static bool was_onground{ };

		if( settings.in_move && ( g_ctx.m_local->m_fFlags( ) & FL_ONGROUND ) && moving ) {
			send = false;
		}

		if( settings.on_peek && moving ) {
			static int	choke_ticks = 0;

			bool peeking = predict_position( 20.f + g_ctx.m_local->m_vecVelocity( ) * TICK_INTERVAL( ) * 2.f );
			bool predicted = predict_position( 20.f );
			
			if( !peeking && predicted ) {
				choke_ticks = 0;
				send = true;
			}
			else if( !predicted )
				choke_ticks = settings.ticks;

			if( choke_ticks ) {
				send = !choke_ticks--;
			}
		}

		if( settings.in_air && !( g_ctx.m_local->m_fFlags( ) & FL_ONGROUND ) ) {
			send = false;
		}

		if( settings.avoid_ground ) {
			static int choked = 0;

			if( !was_onground && ( g_ctx.m_local->m_fFlags( ) & FL_ONGROUND ) ) {
				choked = settings.ticks;
			}

			if( choked )
				send = !--choked;
		}

		if( settings.jump_reset ) {
			if( settings.avoid_ground ) {
				if( was_onground && !( g_ctx.m_local->m_fFlags( ) & FL_ONGROUND ) ) {
					send = get_choked( ) > 0;
				}
			}
			else {
				if( !was_onground && ( g_ctx.m_local->m_fFlags( ) & FL_ONGROUND ) ) {
					send = get_choked( ) > 0;
				}
			}
		}

		was_onground = ( g_ctx.m_local->m_fFlags( ) & FL_ONGROUND );

		if( settings.on_duck && ( g_ctx.m_local->m_fFlags( ) & FL_ONGROUND ) ) { 
			float amt = g_ctx.m_local->m_flDuckAmount( );
			if( m_cmd->m_buttons & IN_DUCK ) {
				if( amt < 1.0f )
					send = false;
			} else if( amt > 0.f )
					send = false;
		}

		static int wep_choke = 0;
		if( wep_choke )
			send = !--wep_choke;

		if( m_cmd->m_weaponselect && settings.on_select ) {
			wep_choke = max_ticks;
		}

		if( ( m_cmd->m_buttons & IN_ATTACK ) && g_ctx.m_local->can_attack( ) &&
			!settings.in_attack ) {
			if( !weapon->is_grenade( ) || ( weapon->is_grenade( ) && weapon->m_fThrowTime( ) < TICK_INTERVAL( ) ) ) {
				send = get_choked( ) > 0;
			}
		}

		*m_sendpacket = ( send || force_send ) && !get_sent( );
		if( *m_sendpacket ) {
			m_breaking_lc = delta.length2d( ) > 64.f;
			last_rand = ( 1.f + math::random_number( -settings.fluctuate, settings.fluctuate( ) ) * 0.01f );
		}
	}

	void c_lagmgr::on_cmove_end( ) {
		if( !m_sendpacket ) return;

		if( *m_sendpacket ) {
			++m_sent_ticks;
			m_held_ticks = 0;
			m_has_fired = false;
		}
		else {
			++m_held_ticks;
			m_sent_ticks = 0;

			if( ( m_cmd->m_buttons & IN_ATTACK ) && g_ctx.m_local->can_attack( ) ) {
				m_has_fired = true;
			}
		}
	}
}