コード例 #1
0
ファイル: cheat_generic.cpp プロジェクト: iBelow/modsa_sobeit
void cheat_handle_stick ( struct vehicle_info *vehicle_info, struct actor_info *actor_info, float time_diff )
{
	traceLastFunc( "cheat_handle_stick()" );

	struct object_base	*base_stick, *base_self;
	struct actor_info	*actor_stick;
	struct vehicle_info *vehicle_stick;
	float				*speed_stick, *speed_self;
	float				*spin_stick, *spin_self;
	static int			id = -1;
	int					i;

	if ( KEY_PRESSED(set.key_stick) )
	{
		if ( vehicle_info != NULL )
			cheat_state->vehicle.stick ^= 1;
		else
			cheat_state->actor.stick ^= 1;
		id = actor_find( id - 1, 1, ACTOR_ALIVE | ACTOR_NOT_SAME_VEHICLE );
	}

	if ( KEY_PRESSED(set.key_stick_nearest) )
	{
		if ( vehicle_info != NULL )
			cheat_state->vehicle.stick ^= 1;
		else
			cheat_state->actor.stick ^= 1;
		id = actor_find_nearest( ACTOR_ALIVE | ACTOR_NOT_SAME_VEHICLE );
	}

	if ( (vehicle_info != NULL && cheat_state->vehicle.stick) || (actor_info != NULL && cheat_state->actor.stick) )
	{
		// remove any bad vehicle or actor stuffs
		if ( isBadPtr_GTA_pVehicle(vehicle_info) )
			vehicle_info = NULL;
		if ( isBadPtr_GTA_pPed(actor_info) )
			actor_info = NULL;

		/* check if actor has disappeared.. and if it has, switch to teh nearest */
		if ( id != -1 && actor_info_get(id, ACTOR_ALIVE) == NULL )
			id = actor_find_nearest( ACTOR_ALIVE | ACTOR_NOT_SAME_VEHICLE );

		if ( KEY_PRESSED(set.key_stick_prev) )
			id = actor_find( id, -1, ACTOR_ALIVE | ACTOR_NOT_SAME_VEHICLE );

		if ( KEY_PRESSED(set.key_stick_next) )
			id = actor_find( id, 1, ACTOR_ALIVE | ACTOR_NOT_SAME_VEHICLE );

		/* no actors to stick to */
		if ( id == -1 )
		{
			cheat_state_text( "No players found; stick disabled." );
			cheat_state->vehicle.stick = 0;
			cheat_state->actor.stick = 0;
			return;
		}

		/* get actor struct for the actor we're sticking to */
		actor_stick = actor_info_get( id, ACTOR_ALIVE | ACTOR_NOT_SAME_VEHICLE );
		if ( actor_stick == NULL )
			return;

		/* is this actor in a vehicle? */
		vehicle_stick = actor_vehicle_get( actor_stick );

		base_stick = vehicle_stick ? &vehicle_stick->base : &actor_stick->base;
		base_self = vehicle_info ? &vehicle_info->base : &actor_info->base;

		speed_stick = vehicle_stick ? vehicle_stick->speed : actor_stick->speed;
		speed_self = vehicle_info ? vehicle_info->speed : actor_info->speed;

		spin_stick = vehicle_stick ? vehicle_stick->spin : actor_stick->spin;
		spin_self = vehicle_info ? vehicle_info->spin : actor_info->spin;

		/* allow warping to work + always warp towards whatever we're sticking to...
         but only when we're in a vehicle */
		if ( KEY_PRESSED(set.key_warp_mod) && vehicle_info != NULL )
		{
			float	out[4];

			/* multiply the matrix of whatever we're sticking to with the user supplied vector */
			matrix_vect4_mult( base_stick->matrix, set.stick_vect, out );

			/* multiply the result with the negative warp-speed value, and put it in the speed vector
            (negative because we want to warp towards teh target, not away from it */
			vect3_mult( out, -set.warp_speed, speed_self );
		}

		if ( !KEY_DOWN(set.key_warp_mod) )
		{
			float	d[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
			float	accel_mult = 1.0f;
			float	out[4];

			/* handle stick movement keys */
			if ( KEY_DOWN(set.key_stick_forward) )
				d[1] += 1.0f;
			if ( KEY_DOWN(set.key_stick_backward) )
				d[1] -= 1.0f;
			if ( KEY_DOWN(set.key_stick_left) )
				d[0] -= 1.0f;
			if ( KEY_DOWN(set.key_stick_right) )
				d[0] += 1.0f;
			if ( KEY_DOWN(set.key_stick_up) )
				d[2] += 1.0f;
			if ( KEY_DOWN(set.key_stick_down) )
				d[2] -= 1.0f;
			if ( KEY_DOWN(set.key_stick_in) )
				d[3] -= 1.0f;
			if ( KEY_DOWN(set.key_stick_out) )
				d[3] += 1.0f;

			if ( !near_zero(set.stick_accel_time) )
			{
				static uint32_t time_start;

				if ( !vect4_near_zero(d) )
					time_start = ( time_start == 0 ) ? time_get() : time_start;
				else
					time_start = 0;			/* no keys pressed */

				/* acceleration */
				if ( time_start != 0 )
				{
					float	t = TIME_TO_FLOAT( time_get() - time_start );
					if ( t < set.stick_accel_time )
						accel_mult *= t / set.stick_accel_time;
				}
			}

			/* calculate new vector + dist */
			if ( !vect3_near_zero(d) && !vect3_near_zero(set.stick_vect) )
			{
				for ( i = 0; i < 3; i++ )
				{
					d[i] = set.stick_vect[i] * set.stick_vect_dist + d[i] * time_diff * 8.0f * accel_mult;
				}

				set.stick_vect_dist = vect3_length( d );
				vect3_normalize( d, set.stick_vect );
			}

			/* move towards/away from the center */
			if ( !near_zero(d[3]) )
				set.stick_vect_dist += d[3] * time_diff * 40.0f * accel_mult;

			/* Teleport vehicle detachables */
			if ( vehicle_info != NULL )
				vehicle_detachables_teleport( vehicle_info, &base_self->matrix[4 * 3], &base_stick->matrix[4 * 3] );

			matrix_copy( base_stick->matrix, base_self->matrix );
			vect3_copy( speed_stick, speed_self );
			vect3_copy( spin_stick, spin_self );

			/*base_self->interior_id = base_stick->interior_id;
         gta_interior_id_set(base_stick->interior_id);*/
			/* multiply the matrix of the target with the user supplied vector */
			matrix_vect4_mult( base_stick->matrix, set.stick_vect, out );

			/* multiply the result with the user supplied vector distance */
			vect3_mult( out, set.stick_vect_dist, out );

			/* and add it to our position */
			vect3_vect3_add( &base_self->matrix[4 * 3], out, &base_self->matrix[4 * 3] );

			if ( vehicle_info != NULL )
			{
				/* Teleport detachables again :p */
				vehicle_detachables_teleport( vehicle_info, &base_stick->matrix[4 * 3], &base_self->matrix[4 * 3] );
				vehicle_prevent_below_height( vehicle_info, set.stick_min_height );
			}
			else if ( actor_info != NULL )
			{
				// new pedFlags
				actor_info->pedFlags.bIsStanding = true;
				actor_info->pedFlags.bWasStanding = true;
				actor_info->pedFlags.bStayInSamePlace = true;
			}
		}
	}
}
コード例 #2
0
void cheat_handle_vehicle_recording ( struct vehicle_info *info, float time_diff )
{
	char buffer[512];
	float set_speed[3];
	float set_spin[3];

	if ( info == NULL || !set.recording_activated )
		return;
	
	traceLastFunc( "cheat_handle_vehicle_recording()" );
	
	// recording key
	if ( KEY_PRESSED(set.key_recording_record) )
	{
		if ( rec_state == RECORDING_RECORD )
		{
			rec_maxNum = rec_index;
			rec_state = RECORDING_OFF;
			return;
		}
		else if ( rec_state == RECORDING_OFF )
		{
			rec_state = RECORDING_RECORD;
			rec_maxNum = 0;
			rec_index = 0;
			rec_playNext = 0.0f;
		}
	}

	if ( KEY_PRESSED(set.key_recording_continueAfterFinish) )
		rec_continueAfterFin ^= 1;

	// play keys
	if ( (KEY_PRESSED(set.key_recording_play) || KEY_PRESSED(set.key_recording_customSpeed)
		|| KEY_PRESSED(set.key_recording_rev) || KEY_PRESSED(set.key_recording_rev_customSpeed)) )
	{
		// if record playing
		if ( rec_state >= RECORDING_PLAY )
		{
			 rec_state = RECORDING_OFF;
			 return;
		}
		else if ( rec_state == RECORDING_OFF )
		{
			// something to play?
			if ( rec_maxNum <= 0 )
			{
				rec_state = RECORDING_OFF;
				return;
			}

			rec_index = 0;
			rec_playNext = 0.0f;

			
			if ( KEY_PRESSED(set.key_recording_play) )
				rec_state = RECORDING_PLAY;
			else if ( KEY_PRESSED(set.key_recording_customSpeed) )
				rec_state = RECORDING_PLAY_CUSTOMSPEED;
			else if ( KEY_PRESSED(set.key_recording_rev) )
			{
				rec_index = (rec_maxNum-1);
				rec_state = RECORDING_PLAY_REV;
			}
			else if ( KEY_PRESSED(set.key_recording_rev_customSpeed) )
			{
				rec_index = (rec_maxNum-1);
				rec_state = RECORDING_PLAY_REV_CUSTOMSPEED;
			}

			// user set a maximum distance to entry point?
			if ( set.recording_maxDistToEntryPoint > 0.0f )
			{
				// check if current selected index is in maxRange, else look for a point closest
				// to the selected beginning, which is in the maxRange
				if ( vect3_dist(rec_pos[rec_index], &info->base.matrix[4*3]) > set.recording_maxDistToEntryPoint )
				{
					int i = rec_index;
					int rec_index_new = -1;

					// not a entry point we want (too far), lets find a better one
					while ( i >= 0 && i < rec_maxNum )
					{
						if ( vect3_dist(rec_pos[i], &info->base.matrix[4*3]) <= set.recording_maxDistToEntryPoint )
						{
							rec_index_new = i;
							break;
						}
						if ( rec_state == RECORDING_PLAY_REV || rec_state == RECORDING_PLAY_REV_CUSTOMSPEED )
							i--;
						else
							i++;
					}

					// nothing close enough found
					if ( rec_index_new == -1 )
					{
						rec_state = RECORDING_OFF;
						cheat_state_text( "Too far from route - maxDist: %0.2f", set.recording_maxDistToEntryPoint );
					}
					else
						rec_index = rec_index_new;
				}
			}
		}
	}

	if ( rec_state == RECORDING_RECORD )
	{
		pD3DFont->PrintShadow( 99, 250, D3DCOLOR_ARGB(255, 255, 0, 0), "Vehicle Recording" );

		if ( (TIME_TO_FLOAT(time_get()) - rec_playNext) < 0.0f )
			return;
		
		vect3_copy( &info->base.matrix[4*3+0], rec_pos[rec_index] );

		vect3_copy( &info->base.matrix[4*0+0], &rec_angle[rec_index][0] );
		vect3_copy( &info->base.matrix[4*1+0], &rec_angle[rec_index][3] );

		vect3_copy( info->spin, rec_spin[rec_index] );
		vect3_copy( info->speed, rec_speed[rec_index] );

		rec_index++;
		rec_playNext = TIME_TO_FLOAT(time_get()) + TIME_TO_FLOAT((float)MSEC_TO_TIME(REC_DEFAULT_WAITTIME));
		if ( rec_index == (REC_ARRAYSIZE-1) )
		{
			rec_maxNum = rec_index;
			rec_state = RECORDING_OFF;
		}
	}
	// >= because only play states should follow after RECORDING_PLAY
	else if ( rec_state >= RECORDING_PLAY )
	{
		// deactivate playing records while air brakeing/sticking
		if ( cheat_state->vehicle.air_brake || cheat_state->vehicle.stick )
		{
			rec_state = RECORDING_OFF;
			return;
		}

		// move into some better place (maybe hud?)
		_snprintf_s( buffer, sizeof(buffer)-1, "Vehicle Play Record%s%s", (rec_state == RECORDING_PLAY_REV
			|| rec_state == RECORDING_PLAY_REV_CUSTOMSPEED) ? " (Rev)" : "",
			rec_continueAfterFin ? " (Continuously)" : "" );
		_snprintf_s( buffer, sizeof(buffer)-1, "%s%s", buffer, (rec_state == RECORDING_PLAY_REV_CUSTOMSPEED
			|| rec_state == RECORDING_PLAY_CUSTOMSPEED) ? " (Custom Speed)" : "" );
		pD3DFont->PrintShadow( 99, 250, D3DCOLOR_ARGB(255, 0, 255, 0), buffer );

		// will need overtime variable for data row skipping
		float overtime = (TIME_TO_FLOAT(time_get()) - rec_playNext);

		// do nothing, if the planned next-frame time wasn't reached yet
		if ( overtime < 0.0f )
			return;
		
		vect3_copy( rec_pos[rec_index], &info->base.matrix[4*3+0] );

		vect3_copy( &rec_angle[rec_index][0], &info->base.matrix[4*0+0] );
		vect3_copy( &rec_angle[rec_index][3], &info->base.matrix[4*1+0] );

		vect3_copy( rec_spin[rec_index], set_spin );
		vect3_copy( rec_speed[rec_index], set_speed );		

		// multiply speed/spin (for ff mode) and set the playNextTick
		if ( rec_state == RECORDING_PLAY_CUSTOMSPEED || rec_state == RECORDING_PLAY_REV_CUSTOMSPEED )
		{
			vect3_mult( set_spin, set.recording_play_customSpeed, set_spin );
			vect3_mult( set_speed, set.recording_play_customSpeed, set_speed );

			// custom speed multiplier faster/higher than possible to play one by one?
			// if its not the first point (rec_playNext still default) skip a few 
			if ( overtime > 0.0f && rec_playNext != 0.0f )
			{
				// (now-plannedArrival) = overtime -> plannedArrival is way back in the past [so we gotta skip
				//   some of the rows to keep up with the recording/show it 'fluent' (or at least somehow timed correct)]

				// determine how many data rows we gotta skip ((now-plannedArrival)/timePerRow)
				float skipAble = overtime / (float)(TIME_TO_FLOAT((float)MSEC_TO_TIME(REC_DEFAULT_WAITTIME))/set.recording_play_customSpeed);
				if ( skipAble > 1.0f )
				{
					int skipAFew = ceil(skipAble);
					if ( skipAFew > 0 && rec_state >= RECORDING_PLAY_REV )
						rec_index -= skipAFew;
					else if ( skipAFew > 0 )
						rec_index += skipAFew;
				}
			}

			// calculate the time for the next data row
			rec_playNext = TIME_TO_FLOAT(time_get())
				+ (TIME_TO_FLOAT((float)MSEC_TO_TIME(REC_DEFAULT_WAITTIME))/set.recording_play_customSpeed );
		}
		else
		{
			// in case REC_DEFAULT_WAITTIME is too low, or this code is running on a slow computer
			// (or player tabbed/paused the game and refocuses the gta window)
			if ( overtime > 0.0f && rec_playNext != 0.0f )
			{
				// determine how many data rows we gotta skip
				float skipAble = overtime / (float)(TIME_TO_FLOAT(MSEC_TO_TIME(REC_DEFAULT_WAITTIME)));
				if ( skipAble > 1.0f )
				{
					int skipAFew = ceil(skipAble);
					if ( skipAFew > 0 && rec_state >= RECORDING_PLAY_REV )
						rec_index -= skipAFew;
					else if ( skipAFew > 0 )
						rec_index += skipAFew;
				}
			}

			rec_playNext = TIME_TO_FLOAT(time_get()) + TIME_TO_FLOAT(MSEC_TO_TIME(REC_DEFAULT_WAITTIME));
		}

		// inverse speed/spin (for rev mode) and set rec_index
		if ( rec_state >= RECORDING_PLAY_REV )
		{
			vect3_mult( set_spin, -1.0f, set_spin );
			vect3_mult( set_speed, -1.0f, set_speed );
			rec_index--;

			// reached end of recording
			if ( rec_index <= 0 )
			{
				if ( !rec_continueAfterFin )
					rec_state = RECORDING_OFF;
				else
				{
					if ( set.recording_maxDistToEntryPoint > 0.0f )
					{
						// deactivate, if new starting position is too far from this point
						if ( vect3_dist(rec_pos[rec_index], rec_pos[(rec_maxNum-1)]) > set.recording_maxDistToEntryPoint )
							rec_state = RECORDING_OFF;
					}
					rec_index = (rec_maxNum-1);
				}
			}
		}
		else
		{
			rec_index++;

			// reached end of recording
			if ( (rec_index >= (REC_ARRAYSIZE-1) || rec_index >= rec_maxNum) )
			{
				if ( !rec_continueAfterFin )
					rec_state = RECORDING_OFF;
				else
				{
					if ( set.recording_maxDistToEntryPoint > 0.0f )
					{
						// deactivate, if new starting position is too far from this point
						if ( vect3_dist(rec_pos[rec_index], rec_pos[0]) > set.recording_maxDistToEntryPoint )
							rec_state = RECORDING_OFF;
					}
					rec_index = 0;
				}
			}
		}	
		
		// copy new speed/spin after it has been adjusted for ff/rev mode
		vect3_copy( set_spin, info->spin );
		vect3_copy( set_speed, info->speed );			
	}
	else
	{
		rec_state = RECORDING_OFF;
	}
}
コード例 #3
0
ファイル: cheat_actor.cpp プロジェクト: mishannn/m0d_sa
void cheat_handle_actor_air_brake ( struct actor_info *info, double time_diff )
{
	traceLastFunc( "cheat_handle_actor_air_brake()" );

	static float	orig_pos[3];
	static float	fall_speed_mult;
	static int		was_enabled;

	if ( set.air_brake_toggle )
	{
		if ( KEY_PRESSED(set.key_air_brake_foot_mod) ) 
		{
			if(cheat_state->actor.air_brake) 
			{
				cheat_state->actor.air_brake = 0;
			}
			else
			{
				cheat_state->actor.air_brake = 1;
			}
		}

		if ( KEY_PRESSED(set.key_air_brake_mod2) && cheat_state->actor.air_brake )
		{
			if(cheat_state->actor.air_brake_slowmo) 
			{
				cheat_state->actor.air_brake_slowmo = 0;
			}
			else
			{
				cheat_state->actor.air_brake_slowmo = 1;
			}
		}
	}
	else
	{
		if ( KEY_PRESSED(set.key_air_brake_foot_mod) )
			cheat_state->actor.air_brake = 1;
		else if ( KEY_RELEASED(set.key_air_brake_foot_mod) )
			cheat_state->actor.air_brake = 0;

		if ( KEY_PRESSED(set.key_air_brake_mod2) && cheat_state->actor.air_brake )
			cheat_state->actor.air_brake_slowmo = 1;
		else if ( KEY_RELEASED(set.key_air_brake_mod2) && cheat_state->actor.air_brake )
			cheat_state->actor.air_brake_slowmo = 0;
	}

	if ( !was_enabled && cheat_state->actor.air_brake )
	{
		vect3_copy( &info->base.matrix[4 * 3], orig_pos );
		fall_speed_mult = 1.0f;
		was_enabled = 1;
	}

	if ( !cheat_state->actor.air_brake )
	{
		was_enabled = 0;
		cheat_state->actor.air_brake_slowmo = 0;
	}
	else
	{
		float	*matrix = info->base.matrix;

		// if there's no parachute
		if ( !(info->weapon_slot == 11 && info->weapon[11].id == 46) )
		{
			vect3_copy( orig_pos, &info->base.matrix[4 * 3] );
			vect3_zero( info->speed );

			// new pedFlags
			info->pedFlags.bIsStanding = true;
			info->pedFlags.bWasStanding = true;
			info->pedFlags.bStayInSamePlace = true;

			static uint32_t time_start;
			float			d[4] = { 0.0f, 0.0f, 0.0f, time_diff * set.air_brake_speed };

			if ( cheat_state->actor.air_brake_slowmo )
				d[3] /= 10.0f;

			if ( KEY_DOWN(set.key_air_brake_forward) )
				d[0] += 1.0f;
			if ( KEY_DOWN(set.key_air_brake_backward) )
				d[0] -= 1.0f;
			if ( KEY_DOWN(set.key_air_brake_left) )
				d[1] += 1.0f;
			if ( KEY_DOWN(set.key_air_brake_right) )
				d[1] -= 1.0f;
			if ( KEY_DOWN(set.key_air_brake_up) )
				d[2] += 1.0f;
			if ( KEY_DOWN(set.key_air_brake_down) )
				d[2] -= 1.0f;

			if ( !near_zero(set.air_brake_accel_time) )
			{
				if ( !vect3_near_zero(d) )
					time_start = ( time_start == 0 ) ? time_get() : time_start;
				else
					time_start = 0; /* no keys pressed */

				/* acceleration */
				if ( time_start != 0 )
				{
					float	t = TIME_TO_FLOAT( time_get() - time_start );
					if ( t < set.air_brake_accel_time )
						d[3] *= t / set.air_brake_accel_time;
				}
			}

			if ( !vect3_near_zero(d) )
			{
				float	vect[4] = { -d[1], d[0], d[2], 0.0f };
				float	out[4];

				/* out = matrix * norm(d) */
				vect3_normalize( vect, vect );
				matrix_vect4_mult( matrix, vect, out );

				matrix[4 * 3 + 0] += out[0] * d[3];
				matrix[4 * 3 + 1] += out[1] * d[3];
				matrix[4 * 3 + 2] += out[2] * d[3];
			}
		}

		// parachute
		else
		{
			if ( KEY_DOWN(set.key_air_brake_up) )
				fall_speed_mult += time_diff / 2.0f;
			if ( KEY_DOWN(set.key_air_brake_down) )
				fall_speed_mult -= time_diff / 2.0f;

			if ( fall_speed_mult < 0.0f )
				fall_speed_mult = 0.0f;
			else if ( fall_speed_mult > 2.0f )
				fall_speed_mult = 2.0f;

			matrix[4 * 3 + 0] += info->speed[0] * time_diff * set.air_brake_speed;
			matrix[4 * 3 + 1] += info->speed[1] * time_diff * set.air_brake_speed;
			matrix[4 * 3 + 2] -= ( matrix[4 * 3 + 2] - orig_pos[2] ) * fall_speed_mult;
		}

		vect3_copy( &matrix[4 * 3], orig_pos );

		// heh
		int		gonadsMult = 1000;
		float	strifeMult = 0.00001f;
		int		gonads = rand() % gonadsMult;
		float	strife = (double)gonads * strifeMult;
		if ( strife < strifeMult * gonadsMult / 2 )
			strife -= strifeMult * gonadsMult;
		info->m_SpeedVec.fX = strife;
		gonads = rand() % gonadsMult;
		strife = (double)gonads * strifeMult;
		if ( strife < strifeMult * gonadsMult / 2 )
			strife -= strifeMult * gonadsMult;
		info->m_SpeedVec.fY = strife;
	}
}