summaryrefslogtreecommitdiff
path: root/cheat/gmod/create_move.cpp
blob: c25d0c5e05832890c3df9cf4be986763c401bc2e (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
#include <intrin.h>

#include "hooks.hpp"
#include "mem.hpp"
#include "interface.hpp"
#include "context.hpp"
#include "input_system.hpp"
#include "math.hpp"

#include "base_cheat.hpp"


bool __fastcall hooks::create_move( void* ecx_, void* edx_, float input_sample_frametime, user_cmd_t* ucmd ) {
	static auto create_move_o = g_gmod.m_clientmode->get_old_function< decltype( &hooks::create_move ) >( 21 );

	// call from CInput::ExtraMouseSample with dummy cmd.
	if( !ucmd->m_cmd_nr || !ucmd->m_tick_count || g_gmod.m_panic )
		return create_move_o( ecx_, 0, input_sample_frametime, ucmd );

	// for interfacing with lua related stuff.
	g_ctx.m_lua = g_gmod.m_lua_shared( )->GetLuaInterface( LUA_CLIENT );
	if( !g_ctx.m_lua )
		return create_move_o( ecx_, 0, input_sample_frametime, ucmd );

	// random_seed isn't generated in ClientMode::CreateMove yet (since CInput::CreateMove handles that), we must generate it ourselves.
	ucmd->m_random_seed = math::md5_pseudorandom( ucmd->m_cmd_nr ) & 0x7fffffff;

	//get sendpacket off the stack
	stack_t stack( get_baseptr( ) );
	byte    *send_packet = stack.next( ).next( ).next( ).local< byte* >( 0x1 );

	g_ctx.create_snapshot( ucmd );

	//return create_move_o( ecx_, 0, input_sample_frametime, ucmd );

	/*
	g_cheat.m_extra.update_netchannel( );
	g_cheat.m_identity( );
	*/

	if( g_ctx.run_frame( ) && g_ctx.m_local->is_alive( ) ) {
		static int last_frame = g_gmod.m_globals->m_framecount;
		if( last_frame != g_gmod.m_globals->m_framecount )
			g_ctx.m_has_fired_this_frame = false;

		last_frame = g_gmod.m_globals->m_framecount;

		// hook fire bullets for spread compensation.
		if( !fire_bullets_o ) {
			fire_bullets_o = decltype( &hooks::fire_bullets )( c_vmt::hook_method( g_ctx.m_local, 16, hooks::fire_bullets ) );
		}
		
		g_cheat.m_prediction( ucmd );
		g_cheat.m_movement( ucmd );

		g_cheat.m_lagmgr( ucmd, send_packet );

		g_cheat.m_aimbot( ucmd );	

		//if( auto weapon = g_ctx.m_local->get_weapon( ) ) {
		//	if( auto c_class = weapon->ce( )->GetClientClass( ) ) {
		//		g_con->print( "%s\n", c_class->m_name );
		//	}
		//}

		g_cheat.m_extra.use_spammer( ucmd );

		if( g_cheat.m_lagmgr.get_choked( ) > 15 ) {
			g_cheat.m_lagmgr.set_state( true );
		}
		
		g_cheat.m_lagmgr.on_cmove_end( );
	
		g_ctx.on_cmove_end( ucmd );

		ucmd->clamp( );
		// call original *after* any changes due to anticheats detecting changes between this and any changes after.
		create_move_o( ecx_, 0, input_sample_frametime, ucmd );

		g_cheat.m_aimbot.silent( );
	}
	else {
		create_move_o( ecx_, 0, input_sample_frametime, ucmd );
	}
	
	return false;
}