summaryrefslogtreecommitdiff
path: root/internal_rewrite/proxies.cpp
blob: 13466b4ccc14234b0fd8cefb42eedd6a04cec0ff (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
#include "hooks.hpp"
#include "context.hpp"
#include "base_cheat.hpp"

void __cdecl hooks::lby_proxy_fn( const CRecvProxyData* proxy_data_const, void* entity, void* output ) {
	lby_proxy.get_old_function( )( proxy_data_const, entity, output );

	if( !g_csgo.m_panic ) {
		auto player = ( c_base_player* )( entity );
		if( player && player == g_ctx.m_local ) {
			g_cheat.m_ragebot.m_antiaim->on_lby_proxy( );
		}
	}
}

void __cdecl hooks::last_shot_proxy_fn( const CRecvProxyData* proxy_data_const, void* entity, void* output ) {
	last_shot_proxy.get_old_function( )( proxy_data_const, entity, output );
	if( !g_csgo.m_panic && proxy_data_const && g_settings.rage.enabled( ) && g_settings.rage.resolver( ) ) {
		auto wep = ( c_base_weapon* )( entity );
		if( wep && !wep->is_knife( ) && !wep->is_grenade( ) ) {
			auto owner = g_csgo.m_entlist( )->GetClientEntityFromHandle( wep->m_hOwner( ) );
			if( owner && owner->is_valid( ) && owner != g_ctx.m_local && g_ctx.m_local->is_valid( ) && owner->has_valid_anim( ) ) {
				if( owner->m_iTeamNum( ) == g_ctx.m_local->m_iTeamNum( ) && !g_settings.rage.friendlies )
					return;

				static float last_time = 0.f;
				float time = wep->m_fLastShotTime( );

				if( !time )
					return;

				float anim_time = owner->m_flOldSimulationTime( ) + TICK_INTERVAL( );
				auto record = g_cheat.m_ragebot.m_lagcomp->get_newest_record( owner->ce( )->GetIndex( ) );
				float& last_update = g_cheat.m_ragebot.m_lagcomp->get_last_updated_simtime( owner->ce( )->GetIndex( ) );

				if( time == owner->m_flSimulationTime( ) && owner->has_valid_anim( ) && owner->m_flSimulationTime( ) != last_update ) {
					last_update = owner->m_flSimulationTime( );

					vec3_t local_pos = g_ctx.m_local->m_vecOrigin( );
					vec3_t enemy_pos = owner->m_vecOrigin( );
					vec3_t ang = math::vector_angles( enemy_pos, local_pos );

					owner->m_angEyeAngles( ).y = ang.y;
					owner->fix_animations( );

					features::c_ragebot::lag_record_t record( owner );
					record.m_shot = true;
					
					g_cheat.m_ragebot.m_lagcomp->store_record( owner->ce( )->GetIndex( ), RECORD_NORMAL, record );
					last_time = time;
				}
				else if( owner->has_valid_anim( ) && time != last_time ) {
					auto lby_records = g_cheat.m_ragebot.m_lagcomp->get_records( owner->ce( )->GetIndex( ), RECORD_LBY );
					auto sim_records = g_cheat.m_ragebot.m_lagcomp->get_records( owner->ce( )->GetIndex( ), RECORD_NORMAL );

					features::c_ragebot::lag_record_t* prev_record = nullptr;
					float min_delta = FLT_MAX;
					
					if( lby_records->size( ) ) {
						for( auto& it : *lby_records ) {
							float delta = std::abs( it.m_flSimulationTime - time );
							if( delta > TICKS_TO_TIME( 15 ) )
								break;

							if( delta < g_csgo.m_globals->m_interval_per_tick )
								break;

							if( delta < min_delta ) {
								prev_record = &it;
								min_delta = delta;
							}
						}
					}

					if( sim_records->size( ) ) {
						for( auto& it : *sim_records ) {
							if( it.m_shot )
								continue;

							float delta = std::abs( it.m_flSimulationTime - time );
							if( delta > TICKS_TO_TIME( 15 ) )
								break;

							if( delta < g_csgo.m_globals->m_interval_per_tick )
								break;

							if( delta < min_delta ) {
								prev_record = &it;
								min_delta = delta;
							}
						}
					}

					if( prev_record && !prev_record->m_shot ) {
						owner->m_angEyeAngles( ).x = prev_record->m_vecAngles.x;
					}

					last_time = time;
				}
			}
		}
	}
}