summaryrefslogtreecommitdiff
path: root/cheat/internal_rewrite/prediction.cpp
blob: 2f6f6069093a45812e98003f32d77c241df555ff (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
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
#include "prediction.hpp"
#include "hooks.hpp"
#include "context.hpp"

NAMESPACE_REGION( features )

void c_prediction::player_data_t::update( int ent_index ) {
	auto player = g_csgo.m_entlist( )->GetClientEntity( ent_index );
	if( !player || !player->is_valid( ) || player == g_ctx.m_local ) {
		m_valid = false;
		return;
	}

	float simtime = player->m_flSimulationTime( );

	if( std::abs( simtime - m_simtime ) ) {
		float delta = std::abs( m_simtime - simtime );
		if( !m_valid ) {
			m_old_velocity = player->m_vecVelocity( );
		}
		else {
			m_last_choke = TIME_TO_TICKS( delta );
			m_old_velocity = m_velocity;
			m_breaking_lc = player->m_vecOrigin( ).dist_to( m_position ) > 64;
		}

		m_velocity = player->get_animdata( ).m_last_velocity;
		m_position = player->m_vecOrigin( );

		m_valid = true;

		if( m_breaking_lc )
			m_records.push_front( { m_velocity, m_last_choke } );
	}

	m_simtime = simtime;

	while( m_records.size( ) > 32 )
		m_records.pop_back( );
}

void c_prediction::frame_stage_notify( ) {
	for( int i{ 1 }; i < 65; ++i ) {
		m_players[ i ].update( i );
	}
}

int c_prediction::get_predicted_choke( int idx ) {
	auto& data = m_players[ idx ];

	int adaptive_dtc = 0;
	int static_dtc	 = 0;
	int min_choke	 = 16;
	int max_choke	 = 0;

	if( !data.m_records.empty( ) ) {
		int prev_choke = data.m_last_choke;
		float last_dist = 0.f;
		for( auto& it : data.m_records ) {
			if( it.m_tick == prev_choke )
				static_dtc++;

			float speed = it.m_velocity.length2d( );
			float dist = speed * it.m_tick * TICK_INTERVAL( );

			if( dist > 62.f && std::abs( last_dist - dist ) < 12.f )
				adaptive_dtc++;

			prev_choke = it.m_tick;
			last_dist = dist;
			min_choke = math::min( it.m_tick, min_choke );
			max_choke = math::max( it.m_tick, max_choke );
		}
	}

	if( adaptive_dtc > 10 ) {
		return TIME_TO_TICKS( 64.f / data.m_velocity.length2d( ) ) + 1;
	}
	else if( static_dtc > 16 || data.m_records.empty( ) ) {
		return data.m_last_choke;
	}

	float factor = math::random_number( 0.f, 1.f );
	return ( 1.0f - factor ) * min_choke + factor * max_choke;
}

vec3_t c_prediction::aimware_extrapolate( c_base_player* ent, vec3_t origin, vec3_t& velocity ) {
	static auto sv_jump_impulse = g_csgo.m_cvar( )->FindVar( xors( "sv_jump_impulse" ) );
	static auto sv_gravity = g_csgo.m_cvar( )->FindVar( xors( "sv_gravity" ) );
	
	auto min = ent->m_vecMins( );
	auto max = ent->m_vecMaxs( );

	auto start = origin;
	auto end = start + velocity * TICK_INTERVAL( );

	CTraceFilter f;
	CGameTrace tr;
	Ray_t ray;
	
	ray.Init( start, end, min, max );
	f.pSkip = ent;

	g_csgo.m_trace( )->TraceRay( ray, MASK_PLAYERSOLID, &f, &tr );

	if( tr.fraction != 1.f ) {
		for( int i{ }; i < 2; ++i ) {
			velocity -= tr.plane.normal * velocity.dot( tr.plane.normal );

			auto dot = velocity.dot( tr.plane.normal );
			if( dot < 0.f ) {
				velocity -= dot * tr.plane.normal;
			}

			end = tr.endpos + ( velocity * TICK_INTERVAL( ) * ( 1.f - tr.fraction ) );
			ray.Init( tr.endpos, end, min, max );
			g_csgo.m_trace( )->TraceRay( ray, MASK_PLAYERSOLID, &f, &tr );

			if( tr.fraction == 1.f )
				break;
		}
	}

	end = tr.endpos;
	end.z -= 2.f;

	ray.Init( tr.endpos, end, min, max );
	g_csgo.m_trace( )->TraceRay( ray, MASK_PLAYERSOLID, &f, &tr );

	if( tr.fraction != 1.f && tr.plane.normal.z > 0.7f ) {
		velocity.z = sv_jump_impulse->get_float( );
	}
	else {
		velocity.z -= sv_gravity->get_float( ) * TICK_INTERVAL( );
	}

	return tr.endpos;
}

vec3_t c_prediction::full_walk_move( c_base_player* player, int ticks ) {
	auto index = player->ce( )->GetIndex( );
	auto data = get_player_data( index );
	vec3_t origin = data.m_position;
	vec3_t velocity = data.m_velocity;
	vec3_t old_velocity = data.m_velocity;
	vec3_t acceleration;

	bool is_on_ground = player->m_fFlags( ) & FL_ONGROUND;

	m_player = data;

	if( !data.m_valid )
		return origin;

	float velocity_dir = RAD2DEG( atan2( velocity.y, velocity.x ) );
	float angle_dir = velocity_dir - RAD2DEG( atan2( data.m_old_velocity.y, data.m_old_velocity.x ) );

	angle_dir *= TICKS_TO_TIME( data.m_last_choke );

	if( velocity_dir <= 180.f ) {
		if( velocity_dir < -180.f )
			velocity_dir += 360.f;
	}
	else {
		velocity_dir -= 360.f;
	}

	float length = velocity.length2d( );

	for( int i{ }; i < ticks; ++i ) {
		float extrapolated_dir = velocity_dir + angle_dir;

		velocity.x = cos( DEG2RAD( extrapolated_dir ) ) * length;
		velocity.y = sin( DEG2RAD( extrapolated_dir ) ) * length; // hey.... fix please In Fucking Correct

		start_gravity( player, origin, velocity );

		if( is_on_ground ) {
			check_jump_button( player, origin, velocity ); // Won't jump all the time
		}

		if( is_on_ground ) {
			//velocity.z = 0.f; go to hell
			friction( player, origin, velocity );
		}

		check_velocity( player, origin, velocity );

		// fuck walking
		if( !is_on_ground ) {
			air_move( player, origin, velocity, old_velocity, acceleration );
		}

		try_player_move( player, origin, velocity );

		is_on_ground = categorize_position( player, origin, velocity ); 

		check_velocity( player, origin, velocity );

		finish_gravity( player, origin, velocity );

		if( is_on_ground ) {
			velocity.z = 0.f;
		}

		old_velocity = velocity;

		velocity_dir = extrapolated_dir;
	}

	return origin;
}

void c_prediction::check_jump_button( c_base_player* player, vec3_t& origin, vec3_t& velocity ) {
	static auto sv_jump_impulse = g_csgo.m_cvar( )->FindVar( xors( "sv_jump_impulse" ) );
	float ground_factor = 1.f; 
	vec3_t ground_point = origin;

	ground_point.z -= 2.f;

	CGameTrace pm;
	trace_player_bbox( player, origin, ground_point, &pm );

	if( pm.m_pEnt ) {
		auto surface_data = g_csgo.m_phys_props( )->GetSurfaceData( pm.surface.surfaceProps );
		if( surface_data ) {
			ground_factor = surface_data->game.jumpfactor;
		}
	}


	if( !ground_factor ) {
		ground_factor = 1.f;
	}

	//if( player->m_fFlags( ) & FL_DUCKING ) {
		//velocity.z += ground_factor * sv_jump_impulse->get_float( ); // how they do it in csgo
	//}
	//else {
		velocity.z = ground_factor * sv_jump_impulse->get_float( );
	//}

	finish_gravity( player, origin, velocity );

}

void c_prediction::start_gravity( c_base_player* player, vec3_t& origin, vec3_t& velocity ) {
	static auto sv_gravity = g_csgo.m_cvar( )->FindVar( xors( "sv_gravity" ) );

	float m_flGravity = player->m_flGravity( );

	//if( !m_flGravity ) {
		m_flGravity = 1.f;
	//}

	velocity.z -= ( m_flGravity * sv_gravity->get_float( ) * 0.5f * TICK_INTERVAL( ) );

	check_velocity( player, origin, velocity );
}

void c_prediction::finish_gravity( c_base_player* player, vec3_t& origin, vec3_t& velocity ) {
	static auto sv_gravity = g_csgo.m_cvar( )->FindVar( xors( "sv_gravity" ) );

	float m_flGravity = player->m_flGravity( );
	//if( !m_flGravity ) {
		m_flGravity = 1.f;
	//}

	velocity.z -= ( m_flGravity * sv_gravity->get_float( ) * 0.5f * TICK_INTERVAL( ) );

	check_velocity( player, origin, velocity );
}

void c_prediction::friction( c_base_player* player, vec3_t& origin, vec3_t& velocity ) {
	static auto sv_friction = g_csgo.m_cvar( )->FindVar( xors( "sv_friction" ) );
	static auto sv_stopspeed = g_csgo.m_cvar( )->FindVar( xors( "sv_stopspeed" ) );
	const float m_surfaceFriction = player->m_surfaceFriction( );

	float speed = velocity.length( );

	if( speed < 0.1f )
		return;

	float friction = sv_friction->get_float( ) * m_surfaceFriction;
	float control = ( speed < sv_stopspeed->get_float( ) ) ? sv_stopspeed->get_float( ) : speed;
	float drop = control * friction * TICK_INTERVAL( );

	float newspeed = speed - drop;
	if( newspeed < 0.f )
		newspeed = 0.f;

	if( newspeed != speed ) {
		newspeed /= speed;
		velocity *= newspeed;
	}
}

void c_prediction::air_move( c_base_player* player, vec3_t& origin, vec3_t& velocity, vec3_t& old_velocity, vec3_t& acceleration ) {
	vec3_t		wishvel;
	vec3_t		wishdir;
	float		wishspeed;
	vec3_t		forward, right, up;

	//fmove = m_player.m_movement.x;
	//smove = m_player.m_movement.y;
	//
	//math::angle_vectors( m_player.m_angles, &forward, &right, &up );
	//
	//forward.z = right.z = 0.f;
	//
	//forward.normalize_vector( );
	//right.normalize_vector( );
	//
	//for( int i{ }; i < 2; ++i ) {
	//	wishvel[ i ] = forward[ i ] * fmove + right[ i ] * smove;
	//}


	wishvel = velocity;

	wishvel[ 2 ] = 0.f;

	wishdir = wishvel;
	wishdir.normalize_vector( );

	wishspeed = acceleration.length( ); // probably wrong

	air_accelerate( player, origin, old_velocity, wishdir, wishspeed );
}

void c_prediction::air_accelerate( c_base_player* player, vec3_t& origin, vec3_t& velocity, vec3_t& wishdir, float wishspeed ) {
	static auto sv_airaccelerate = g_csgo.m_cvar( )->FindVar( xors( "sv_airaccelerate" ) );

	float wishspd = wishspeed;

	if( wishspd > 30.f )
		wishspd = 30.f;

	float currentspeed = velocity.dot( wishdir );

	float addspeed = wishspd - currentspeed;

	if( addspeed <= 0 )
		return;

	float accelspeed = sv_airaccelerate->get_float( ) * wishspeed * TICK_INTERVAL( );

	if( accelspeed > addspeed )
		accelspeed = addspeed;

	for( int i{ }; i < 2; ++i ) {
		velocity[ i ] += accelspeed * wishdir[ i ];
	}
}

void c_prediction::try_player_move( c_base_player* player, vec3_t& origin, vec3_t& velocity ) {
	CGameTrace pm;
	vec3_t end_pos = origin + velocity * TICK_INTERVAL( );	

	trace_player_bbox( player, origin, end_pos, &pm );

	if( pm.fraction != 1.f ) {
		end_pos = pm.endpos;
	}

	origin = end_pos;
}



//there are supposed to be some ladder checks etc here, but we're really only supposed to be doing this when people are breaking lag comp etc
//also ugly code, please fix :(
bool c_prediction::categorize_position( c_base_player* player, vec3_t& origin, vec3_t& velocity ) {
	constexpr float NON_JUMP_VELOCITY = 140.f;
	vec3_t ground_point = origin;
	bool is_moving_up_rapidally = velocity.z > NON_JUMP_VELOCITY;
	CGameTrace pm;

	ground_point.z -= 2.f;

	if( is_moving_up_rapidally ) {
		return false;
	}
	else {
		trace_player_bbox( player, origin, ground_point, &pm );
		if( !pm.m_pEnt || pm.plane.normal.z < 0.7 ) {
			try_touch_ground_in_quadrants( player, origin, ground_point, &pm );
			if( !pm.m_pEnt || pm.plane.normal.z < 0.7 ) {
				return false;
			}
			else {
				return true;
			}
		}
		else {
			return true;
		}
	}

	return true;
}


void c_prediction::check_velocity( c_base_player* player, vec3_t& origin, vec3_t& velocity ) {
	static auto sv_max_velocity = g_csgo.m_cvar( )->FindVar( xors( "sv_maxvelocity" ) );
	const float max_velocity = sv_max_velocity->get_float( );

	for( int i{ }; i < 3; ++i ) {
		if( !std::isfinite( velocity[ i ] ) ) {
			velocity[ i ] = 0.f;
		}

		if( !std::isfinite( origin[ i ] ) ) {
			origin[ i ] = 0.f;
		}

		velocity[ i ] = std::clamp( velocity[ i ], -max_velocity, max_velocity );
	}
}



// https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/game/shared/gamemovement.cpp#L2025
vec3_t c_prediction::extrapolate_player( c_base_player* player, int ticks ) {
	static auto sv_gravity = g_csgo.m_cvar( )->FindVar( xors( "sv_gravity" ) );
	static auto sv_jump_impulse = g_csgo.m_cvar( )->FindVar( xors( "sv_jump_impulse" ) );

	auto index = player->ce( )->GetIndex( );
	auto data = get_player_data( index );

	vec3_t&		m_vecBaseVelocity = player->get< vec3_t >( 0x11C );

	vec3_t		predicted( data.m_position );
	vec3_t		velocity( data.m_velocity );
	vec3_t		acceleration{ };

	if( !data.m_valid )
		return predicted;

	float velocity_dir = RAD2DEG( atan2( velocity.y, velocity.x ) );
	float angle_dir = velocity_dir - RAD2DEG( atan2( data.m_old_velocity.y, data.m_old_velocity.x ) );
	
	angle_dir *= TICKS_TO_TIME( data.m_last_choke );

	if( velocity_dir <= 180.f ) {
		if( velocity_dir < -180.f )
			velocity_dir += 360.f;
	}
	else {
		velocity_dir -= 360.f;
	}

	float length = velocity.length2d( );

	float dir = velocity_dir;

	for( int i = 0; i < ticks; ++i ) {
		float extrapolated_dir = velocity_dir + angle_dir;

		velocity.x = cos( DEG2RAD( extrapolated_dir ) ) * length;
		velocity.y = sin( DEG2RAD( extrapolated_dir ) ) * length;

		predicted = aimware_extrapolate( player, predicted, velocity );

		velocity_dir = extrapolated_dir;
	}

	return predicted;
}

void c_prediction::trace_player_bbox( c_base_player* player, const vec3_t& start, const vec3_t& end, CGameTrace* pm ) {
	Ray_t ray;
	ray.Init( start, end, player->m_vecMins( ), player->m_vecMaxs( ) );

	CTraceFilter filter;
	filter.pSkip = player;

	g_csgo.m_trace( )->TraceRay( ray, MASK_SOLID & ~CONTENTS_MONSTER, &filter, pm );
}

void c_prediction::try_touch_ground( c_base_player* player, const vec3_t& start, const vec3_t& end, const vec3_t& mins, const vec3_t& maxs, CGameTrace* pm ) {
	Ray_t ray;
	ray.Init( start, end, mins, maxs );

	CTraceFilter filter;
	filter.pSkip = player;

	g_csgo.m_trace( )->TraceRay( ray, MASK_SOLID & ~CONTENTS_MONSTER, &filter, pm );
}

void c_prediction::try_touch_ground_in_quadrants( c_base_player* player, const vec3_t& start, const vec3_t& end, CGameTrace* pm ) {
	vec3_t mins, maxs;

	vec3_t mins_src = player->m_vecMins( );
	vec3_t maxs_src = player->m_vecMaxs( );

	float fraction = pm->fraction;
	vec3_t end_pos = pm->endpos;

	mins = mins_src;
	maxs = vec3_t( std::min( 0.f, maxs_src.x ), std::min( 0.f, maxs_src.y ), maxs_src.z );

	try_touch_ground( player, start, end, mins, maxs, pm );
	if( pm->m_pEnt && pm->plane.normal.z >= 0.7 ) {
		pm->fraction = fraction;
		pm->endpos = end_pos;
		return;
	}

	mins = vec3_t( std::max( 0.f, mins_src.x ), std::max( 0.f, mins_src.y ), mins_src.z );
	maxs = maxs_src;

	try_touch_ground( player, start, end, mins, maxs, pm );
	if( pm->m_pEnt && pm->plane.normal.z >= 0.7 ) {
		pm->fraction = fraction;
		pm->endpos = end_pos;
		return;
	}

	mins = vec3_t( mins_src.x, std::max( 0.f, mins_src.y ), mins_src.z );
	maxs = vec3_t( std::min( 0.f, maxs_src.x ), maxs_src.y, maxs_src.z );

	try_touch_ground( player, start, end, mins, maxs, pm );
	if( pm->m_pEnt && pm->plane.normal.z >= 0.7 ) {
		pm->fraction = fraction;
		pm->endpos = end_pos;
		return;
	}

	mins = vec3_t( std::max( 0.f, mins_src.x ), mins_src.y, mins_src.z );
	maxs = vec3_t( maxs_src.x, std::min( 0.f, maxs_src.y ), maxs_src.z );

	try_touch_ground( player, start, end, mins, maxs, pm );
	if( pm->m_pEnt && pm->plane.normal.z >= 0.7 ) {
		pm->fraction = fraction;
		pm->endpos = end_pos;
		return;
	}

	pm->fraction = fraction;
	pm->endpos = end_pos;
}

// This code got nasty after a while, imo. You can clean it up if you care enough.
void c_prediction::run_command( user_cmd_t *ucmd ) {
	CMoveData movedata{ };

	if ( !ucmd || !g_csgo.m_engine( )->IsConnected( ) || !g_csgo.m_engine( )->IsInGame( ) || !g_csgo.m_move_helper.get( ) )
		return;

	int   backup_buttons = ucmd->m_buttons;
	float backup_forwardmove = ucmd->m_forwardmove;
	float backup_sidemove = ucmd->m_sidemove;

	ucmd->m_forwardmove = ucmd->m_sidemove = 0.f;
	ucmd->m_buttons &= ~( IN_BACK | IN_FORWARD | IN_MOVELEFT | IN_MOVERIGHT );

	if( !ucmd || !g_ctx.m_local || !g_ctx.m_local->is_alive( ) )
		return;

	static uintptr_t run_command_address = g_csgo.m_prediction->get_old_function< uintptr_t >( 19 );

	CMoveData move_data{ };
	IClientEntity* local_ent = g_ctx.m_local->ce( );

	//backup data
	int old_buttons = ucmd->m_buttons;
	float old_curtime = g_csgo.m_globals->m_curtime;
	float old_frame_time = g_csgo.m_globals->m_frametime;
	int old_tickbase = g_ctx.m_local->m_nTickBase( );
	int old_flags = g_ctx.m_local->m_fFlags( );
	MoveType_t old_move_type = g_ctx.m_local->m_nMoveType( );
	vec3_t old_velocity = g_ctx.m_local->m_vecVelocity( );

	//set globals
	g_csgo.m_globals->m_curtime = g_csgo.m_globals->m_interval_per_tick * old_tickbase;
	g_csgo.m_globals->m_frametime = g_csgo.m_globals->m_interval_per_tick;

	//random seed is already being calculated and set in createmove
	**( uintptr_t** )( run_command_address + 0x3E ) = ucmd->m_random_seed; //prediction seed
	**( uintptr_t** )( run_command_address + 0x54 ) = uintptr_t( g_ctx.m_local ); //prediction player

																				  //start prediction
	g_csgo.m_move_helper( )->SetHost( local_ent );
	g_csgo.m_game_movement( )->StartTrackPredictionErrors( local_ent );

	//run prediction
	g_csgo.m_prediction( )->SetupMove( local_ent, ucmd, g_csgo.m_move_helper( ), &move_data );
	g_csgo.m_game_movement( )->ProcessMovement( local_ent, &move_data );
	g_csgo.m_prediction( )->FinishMove( local_ent, ucmd, &move_data );

	//finish prediction
	g_csgo.m_game_movement( )->FinishTrackPredictionErrors( local_ent );
	g_csgo.m_move_helper( )->SetHost( nullptr );

	**( uintptr_t** )( run_command_address + 0x3E ) = 0xffffffff;
	**( uintptr_t*** )( run_command_address + 0x54 ) = nullptr;

	//good to have, can be used for edge jump and such
	m_predicted_flags = g_ctx.m_local->m_fFlags( );

	//restore
	ucmd->m_buttons = old_buttons;
	g_csgo.m_globals->m_curtime = old_curtime;
	g_csgo.m_globals->m_frametime = old_frame_time;
	//g_ctx.m_local->m_nTickBase( ) = old_tickbase;
	g_ctx.m_local->m_fFlags( ) = old_flags;
	g_ctx.m_local->m_nMoveType( ) = old_move_type;
	g_ctx.m_local->m_vecVelocity( ) = old_velocity;

	ucmd->m_forwardmove = backup_forwardmove;
	ucmd->m_sidemove = backup_sidemove;
	ucmd->m_buttons = backup_buttons;

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

	if( wep ) {
		wep->update_accuracy_penalty( );
		g_ctx.m_weapon_inaccuracy = wep->get_inaccuracy( );
		g_ctx.m_weapon_spread = wep->get_spread( );
	}
	else {
		g_ctx.m_weapon_inaccuracy = g_ctx.m_weapon_spread = 0.f;
	}
}

END_REGION