示例#1
0
void CRemotePlayer::UpdateSurfing()
{
	if ( m_ofSync.wSurfInfo > MAX_VEHICLES ) { // its an object

			m_ofSync.wSurfInfo -= MAX_VEHICLES; // derive proper object id
			CObjectPool* pObjectPool = pNetGame->GetObjectPool();
			CObject* pObject = pObjectPool->GetAt((BYTE)m_ofSync.wSurfInfo);

			if (pObject) {
				MATRIX4X4 objMat;
				pObject->GetMatrix(&objMat);
				objMat.pos.X += m_ofSync.vecSurfOffsets.X;
				objMat.pos.Y += m_ofSync.vecSurfOffsets.Y;
				objMat.pos.Z += m_ofSync.vecSurfOffsets.Z;
				m_pPlayerPed->SetMatrix(objMat);
			}

	} else { // must be a vehicle

		CVehiclePool* pVehiclePool = pNetGame->GetVehiclePool();
		CVehicle* pVehicle = pVehiclePool->GetAt(m_ofSync.wSurfInfo);

		if (pVehicle) {
			MATRIX4X4 matPlayer, matVehicle;
			VECTOR vecMoveSpeed,vecTurnSpeed;

			pVehicle->GetMatrix(&matVehicle);
			pVehicle->GetMoveSpeedVector(&vecMoveSpeed);
			pVehicle->GetTurnSpeedVector(&vecTurnSpeed);

			m_pPlayerPed->GetMatrix(&matPlayer);
		
			matPlayer.pos.X = matVehicle.pos.X + m_ofSync.vecSurfOffsets.X;
			matPlayer.pos.Y = matVehicle.pos.Y + m_ofSync.vecSurfOffsets.Y;
			matPlayer.pos.Z = matVehicle.pos.Z + m_ofSync.vecSurfOffsets.Z;

			m_pPlayerPed->SetMatrix(matPlayer);
			m_pPlayerPed->SetMoveSpeedVector(vecMoveSpeed);
			//m_pPlayerPed->SetTurnSpeedVector(vecTurnSpeed);
		}
	}
}
示例#2
0
void CLocalPlayer::SendInCarFullSyncData()
{
	if(m_pPlayerPed)
	{
		RakNet::BitStream bsVehicleSync;
		VEHICLE_SYNC_DATA vehicleSyncData;
		MATRIX4X4 matVehicle;
		CVehicleManager * pVehicleManager = pNetowkManager->GetVehicleManager();
		CVehicle * pGameVehicle = NULL;

		// write packet id
		bsVehicleSync.Write((MessageID)ID_VEHICLE_SYNC);

		vehicleSyncData.vehicleID = pVehicleManager->FindIDFromGtaPtr(m_pPlayerPed->GetGtaVehicle());

		// make sure we have a valid vehicle
		if(vehicleSyncData.vehicleID == INVALID_ENTITY_ID)
		{
			return;
		}

		// get the player keys
		vehicleSyncData.wKeys = m_pPlayerPed->GetKeys();

		// get the vehicle pointer
		pGameVehicle = pVehicleManager->GetAt(vehicleSyncData.vehicleID);

		// make sure the vehicle pointer is valid
		if(!pGameVehicle)
		{
			return;
		}

		// get the vehicle matrix
		pGameVehicle->GetMatrix(&matVehicle);

		// copy the roll and direction vectors
		memcpy(&vehicleSyncData.vecRoll, &matVehicle.vLookRight, sizeof(Vector3));
		memcpy(&vehicleSyncData.vecDirection, &matVehicle.vLookUp, sizeof(Vector3));
		// pack the roll and direction vectors
		//CompressVector1(&matVehicle.vLookRight, &vehicleSyncData.cvecRoll);
		//CompressVector1(&matVehicle.vLookUp, &vehicleSyncData.cvecDirection);

		// copy the vehicle position
		memcpy(&vehicleSyncData.vecPos, &matVehicle.vPos, sizeof(Vector3));

		// get the vehicle move speed
		pGameVehicle->GetMoveSpeed(&vehicleSyncData.vecMoveSpeed);

		// get the vehicle turn speed
		pGameVehicle->GetTurnSpeed(&vehicleSyncData.vecTurnSpeed);

		// pack the vehicle health
		vehicleSyncData.byteVehicleHealth = PACK_VEHICLE_HEALTH(pGameVehicle->GetHealth());

		// get the player health (casted to a byte to save space)
		vehicleSyncData.bytePlayerHealth = (BYTE)m_pPlayerPed->GetHealth();

		// get the player armour (casted to a byte to save space)
		vehicleSyncData.bytePlayerArmour = (BYTE)m_pPlayerPed->GetArmour();

		// write vehicle sync struct to bit stream
		bsVehicleSync.Write((char *)&vehicleSyncData, sizeof(VEHICLE_SYNC_DATA));

		// send sync data
		pNetowkManager->GetRakPeer()->Send(&bsVehicleSync,HIGH_PRIORITY,UNRELIABLE_SEQUENCED,0,UNASSIGNED_SYSTEM_ADDRESS,TRUE);
	}
}
bool ProcessVehicleSirenPosition ( )
{
    // Valid interface
    if ( pVehicleWithTheSiren )
    {
        // Grab our vehicle from the interface
        CVehicle * pVehicle = pGameInterface->GetPools ()->GetVehicle ( (DWORD *)pVehicleWithTheSiren );
        // Valid - Wait this seems familiar
        if ( pVehicle )
        {    
            // Disable our original siren based vehicles from this hook
            if ( DoesVehicleHaveSiren ( ) && pVehicle->DoesVehicleHaveSirens ( ) == false )
            {
                ucSirenCount = 0;
                // Set our time based alpha to 10% of the current time float
                fTime = *((float*)0xB7C4E4) * 0.1f;
                // Get our minimum alpha
                DWORD dwMinimumAlpha = pVehicle->GetVehicleSirenMinimumAlpha ( ucSirenCount );
                // Times the min alpha (255) by a multiplier to get it 0.0f-1.0f this multiplier was gained by doing 1.0 / 255.
                float fMinimumAlpha =  dwMinimumAlpha * 0.003921568627451f;
                // if our time is less than or equal to the minimum alpha
                if ( fTime <= dwMinimumAlpha )
                {
                    // Set it to the minimum
                    fTime = fMinimumAlpha;
                }
                // Set our red based on 255 and our blue based on 255 and green based on 0.. default SA values of course.
                /*if ( dwRed > 0 )
                    dwRed = (DWORD)( dwRed * fTime );
                if ( dwBlue > 0 )
                    dwBlue = (DWORD)( dwBlue * fTime );
                if ( dwGreen > 0 )
                    dwGreen = (DWORD)( dwGreen * fTime );*/
                bPointLights = false;
                // return false so our hook knows we decided not to edit anything
                return false;
            }
            // Does the vehicle have sirens and is the siren count greater than 0 
            if ( pVehicle->DoesVehicleHaveSirens ( ) && pVehicle->GetVehicleSirenCount ( ) > 0 )
            {
                // Get our siren count
                unsigned char ucVehicleSirenCount = pVehicle->GetVehicleSirenCount ( );
                // Get our current Siren ID
                ucSirenCount = pVehicle->GetVehicleCurrentSirenID ( );

                // Get our randomiser
                ucRandomiser = pVehicle->GetSirenRandomiser ( );

                if ( pVehicle->IsSirenRandomiserEnabled ( ) )
                {
                    // Make sure we aren't beyond our limit
                    if ( ucSirenCount > ucVehicleSirenCount )
                    {
                        // if we have more than 1 sirens
                        if ( ucVehicleSirenCount > 0 )
                            // Set our Randomiser
                            ucRandomiser = rand () % ucVehicleSirenCount;
                        else
                            // Set our Randomiser
                            ucRandomiser = 0;

                        if ( bPointLights == false )
                        {
                            // Update our stored Randomiser
                            pVehicle->SetSirenRandomiser ( ucRandomiser );
                        }
                    }
                    else
                    {
                        // Set our Randomiser
                        ucRandomiser = rand () % ucVehicleSirenCount;
                        if ( bPointLights == false )
                        {
                            // Update our stored Randomiser
                            pVehicle->SetSirenRandomiser ( ucRandomiser );
                        }
                    }
                }
                else
                {
                    ucRandomiser++;
                    if ( ucRandomiser >= ucVehicleSirenCount )
                    {
                        ucRandomiser = 0;
                    }
                    if ( bPointLights == false )
                    {
                        // Update our stored Randomiser
                        pVehicle->SetSirenRandomiser ( ucRandomiser );
                    }
                }
                ucSirenCount = ucRandomiser;

                if ( bPointLights == false )
                {
                    // Gete our siren position for this siren count
                    pVehicle->GetVehicleSirenPosition ( ucSirenCount, *vecRelativeSirenPosition );
                }

                if ( bPointLights == false )
                {
                    // Are we skipping LOS Checks?
                    if ( pVehicle->IsSirenLOSCheckEnabled ( ) )
                    {
                        // Storage 'n stuff
                        CMatrix matCamera;
                        CMatrix matVehicle;
                        // Grab our vehicle matrix
                        pVehicle->GetMatrix( &matVehicle );

                        // Get our Camera
                        CCamera* pCamera = pGameInterface->GetCamera ();
                        // Get the Camera Matrix
                        pCamera->GetMatrix( &matCamera );

                        // Get our sirens ACTUAL position from the relative value
                        CVector vecSirenPosition = matVehicle.TransformVector ( *vecRelativeSirenPosition );

                        // Setup our LOS flags
                        SLineOfSightFlags flags;
                        flags.bCheckBuildings = false;
                        flags.bCheckDummies = false;
                        flags.bCheckObjects = false;
                        flags.bCheckPeds = false;
                        flags.bCheckVehicles = true;
                        flags.bIgnoreSomeObjectsForCamera = false;
                        flags.bSeeThroughStuff = false;
                        flags.bShootThroughStuff = false;
                        // Ignore nothing
                        pGameInterface->GetWorld()->IgnoreEntity ( NULL );
                        // Variables 'n tings
                        CColPoint* pColPoint = NULL;
                        CEntity* pGameEntity = NULL;
                        // Check if we can see it
                        if ( pGameInterface->GetWorld()->IsLineOfSightClear ( &matCamera.vPos, &vecSirenPosition, flags ) == false )
                        {
                            // Nope? Invisible
                            dwRed = 0;
                            dwGreen = 0;
                            dwBlue = 0;
                        }
                        else
                        {
                            // Yep?
                            SetupSirenColour ( pVehicle );
                        }
                    }
                    else
                    {
                        // Skip LOS Checks.
                        SetupSirenColour ( pVehicle ); 
                    }
                    // Set our current Siren ID after we increment it
                    pVehicle->SetVehicleCurrentSirenID ( ++ucSirenCount );
                }
                bPointLights = false;
                // Return true
                return true;
            }
        }
    }
    bPointLights = false;
    // Return false
    return false;
}
示例#4
0
void CRemotePlayer::StoreUnoccupiedSyncData(UNOCCUPIED_SYNC_DATA * unocSync)
{

	VEHICLEID UnocID = unocSync->VehicleID;
	if (!UnocID || UnocID == INVALID_VEHICLE_ID) return;
	
	CVehiclePool *pVehiclePool = pNetGame->GetVehiclePool();
	CVehicle *pVehicle = NULL;
	if (pVehiclePool) {
		pVehicle = pVehiclePool->GetAt(UnocID);
		pVehiclePool->SetLastUndrivenID(UnocID, m_PlayerID);
	}

	if(pVehicle && !pVehicle->HasADriver()) 
	{
		MATRIX4X4 matWorld;

		pVehicle->GetMatrix(&matWorld);

		DecompressNormalVector(&matWorld.up, &unocSync->cvecDirection);
		DecompressNormalVector(&matWorld.right, &unocSync->cvecRoll);

		// if we're pretty already there.. no translation. 
		if( (FloatOffset(unocSync->vecPos.X,matWorld.pos.X) <= 0.1f) &&
			(FloatOffset(unocSync->vecPos.Y,matWorld.pos.Y) <= 0.1f) &&
			(FloatOffset(unocSync->vecPos.Z,matWorld.pos.Z) <= 0.1f) )
		{
			return;
		}

		// if difference is over 8 units, direct translation
		if( !pVehicle->IsAdded() ||
			(FloatOffset(unocSync->vecPos.X,matWorld.pos.X) > 8.0f) ||
			(FloatOffset(unocSync->vecPos.Y,matWorld.pos.Y) > 8.0f) ||
			(FloatOffset(unocSync->vecPos.Z,matWorld.pos.Z) > 8.0f) ) {

			matWorld.pos.X = unocSync->vecPos.X;
			matWorld.pos.Y = unocSync->vecPos.Y;
			matWorld.pos.Z = unocSync->vecPos.Z;

			pVehicle->SetMatrix(matWorld);
			pVehicle->SetMoveSpeedVector(unocSync->vecMoveSpeed);
			pVehicle->SetTurnSpeedVector(unocSync->vecTurnSpeed);
			return;
		}

		// gradually increase/decrease velocities towards the target								
		pVehicle->SetMatrix(matWorld);							// rotation
		pVehicle->SetMoveSpeedVector(unocSync->vecMoveSpeed);	// move velocity
		pVehicle->SetTurnSpeedVector(unocSync->vecTurnSpeed);	// turn velocity

		VECTOR vec = {0.0f, 0.0f, 0.0f};		
		pVehicle->GetMoveSpeedVector(&vec);

		if( FloatOffset(unocSync->vecPos.X,matWorld.pos.X) > 0.05 ) {
			vec.X += (unocSync->vecPos.X - matWorld.pos.X) * 0.05f;
		}
		if( FloatOffset(unocSync->vecPos.Y,matWorld.pos.Y) > 0.05 ) {
			vec.Y += (unocSync->vecPos.Y - matWorld.pos.Y) * 0.05f;
		}
		if( FloatOffset(unocSync->vecPos.Z,matWorld.pos.Z) > 0.05 ) {
			vec.Z += (unocSync->vecPos.Z - matWorld.pos.Z) * 0.05f;
		}

		pVehicle->SetMoveSpeedVector(vec);				
		pVehicle->m_bRemoteUnocSync = true;
	}
}
void cheat_handle_quickwarp(struct vehicle_info *vehicle_info, struct actor_info *actor_info)
{
	if (KEYCOMBO_PRESSED(set.key_quickwarp))
	{
		CCam *pCam = pGame->GetCamera()->GetCam(pGame->GetCamera()->GetActiveCam());
		CVector camsrc(*pCam->GetSource()), src, target, tppos;
		CColPoint *pCollision = nullptr;
		CEntitySAInterface *pEntity = nullptr;

		if (pCam->GetMode() == MODE_AIMWEAPON || pCam->GetMode() == MODE_AIMWEAPON_ATTACHED || pCam->GetMode() == MODE_AIMWEAPON_FROMCAR)
		{
			// calculate target position by aim vector
			pGame->GetCamera()->Find3rdPersonCamTargetVector(700.0f, &camsrc, &src, &target);
		}
		else
		{
			// else by camera vector
			target = camsrc + *pCam->GetFront() * 700.0f;
		}

		// ignore self vehicle
		if (vehicle_info != nullptr)
		{
			*(::vehicle_info **)VAR_IgnoredEntity = vehicle_info;
		}

		if (GTAfunc_ProcessLineOfSight(&camsrc, &target, &pCollision, &pEntity, true, true, false, true, true, false, false, false))
		{
			tppos = *pCollision->GetPosition();
			tppos -= (*pCollision->GetNormal()) * 0.5f;
			
			if (pCollision->GetNormal()->fZ >= 0.5f || pPedSelf->GetAreaCode() != 0)
			{
				tppos.fZ += 1.0f;
				tppos.fZ = pGameInterface->GetWorld()->FindGroundZFor3DPosition(&tppos);
			}
			else
			{
				tppos.fZ = pGameInterface->GetWorld()->FindGroundZForPosition(tppos.fX, tppos.fY);
			}

			if (vehicle_info != nullptr)
			{
				// check for collision
				CVehicle *vehSelf = pPedSelf->GetVehicle();
				if (vehSelf)
				{
					pCollision->Destroy();
					// check for collision
					CVector vecVehicleGravity;
					vehSelf->GetGravity(&vecVehicleGravity);
					CVector vecVehicleAbove = (-vecVehicleGravity * 5.0f) + tppos;
					CVector vecVehicleBelow = (vecVehicleGravity * 5.0f) + tppos;
					bool bCollision = GTAfunc_ProcessLineOfSight(&vecVehicleAbove, &vecVehicleBelow, &pCollision, &pEntity,
																 true, false, false, true, true, false, false, false); // not checking for vehicle collisions
					if (bCollision && pCollision)
					{
						// set vehicle to same Up position has surface normal
						CMatrix matVehicleSelf;
						vehSelf->GetMatrix(&matVehicleSelf);
						CVector vecCollisionNormal = *pCollision->GetNormal();

						// get "down" from vehicle model
						CVector rotationAxis = matVehicleSelf.vUp;

						// normalize our vectors
						vecCollisionNormal.Normalize();
						rotationAxis.Normalize();

						// axis and rotation for gravity
						float	theta = acos(rotationAxis.DotProduct(&vecCollisionNormal));
						if (!near_zero(theta))
						{
							rotationAxis.CrossProduct(&vecCollisionNormal);
							rotationAxis.Normalize();
							rotationAxis.ZeroNearZero();
							matVehicleSelf = matVehicleSelf.Rotate(&rotationAxis, -theta);
						}

						// set the new matrix
						vehSelf->SetMatrix(&matVehicleSelf);

						// set pos floats for actual teleporting
						tppos.fX = pCollision->GetPosition()->fX;
						tppos.fY = pCollision->GetPosition()->fY;
						tppos.fZ = pCollision->GetPosition()->fZ + 1.0f; // should be enough to stay above the ground properly
					}
					else
					{
						tppos.fZ += 0.5f;
					}
					cheat_vehicle_teleport(vehicle_info, &tppos.fX, gta_interior_id_get(), true);
				}
			}
			else if (actor_info != nullptr)
			{
				tppos.fZ += 1.0f;
				cheat_actor_teleport(actor_info, &tppos.fX, gta_interior_id_get());
			}
			GTAfunc_TogglePlayerControllable(0);
			GTAfunc_LockActor(0);
		}
		if (pCollision != nullptr)
		{
			pCollision->Destroy();
		}
	}
}