public void trigger(Object lastStateObj, Object currentStateObj) { if (paused) { return; } RaceRoomShared lastState = ((CrewChiefV4.RaceRoom.R3ESharedMemoryReader.R3EStructWrapper)lastStateObj).data; RaceRoomShared currentState = ((CrewChiefV4.RaceRoom.R3ESharedMemoryReader.R3EStructWrapper)currentStateObj).data; if (!enabled || currentState.Player.GameSimulationTime < timeAfterRaceStartToActivate || currentState.ControlType != (int)RaceRoomConstant.Control.Player || ((int)RaceRoomConstant.Session.Qualify == currentState.SessionType && (currentState.NumCars == 1 || currentState.NumCars == 2))) { return; } DateTime now = DateTime.Now; DriverData currentPlayerData; DriverData previousPlayerData; float timeDiffSeconds; try { currentPlayerData = getDriverData(currentState, currentState.slot_id); previousPlayerData = getDriverData(lastState, currentState.slot_id); timeDiffSeconds = ((float)(now - previousTime).TotalMilliseconds) / 1000f; previousTime = now; if (timeDiffSeconds <= 0) { // WTF? return; } } catch (Exception) { return; } float[] currentPlayerPosition = new float[] { currentPlayerData.position.X, currentPlayerData.position.Z }; if (currentPlayerData.in_pitlane == 0) { List <float[]> currentOpponentPositions = new List <float[]>(); float[] playerVelocityData = new float[3]; playerVelocityData[0] = currentState.CarSpeed; playerVelocityData[1] = (currentPlayerData.position.X - previousPlayerData.position.X) / timeDiffSeconds; playerVelocityData[2] = (currentPlayerData.position.Z - previousPlayerData.position.Z) / timeDiffSeconds; foreach (DriverData driverData in currentState.all_drivers_data) { if (driverData.driver_info.slot_id == currentState.slot_id || driverData.driver_info.slot_id == -1 || driverData.in_pitlane == 1) { continue; } currentOpponentPositions.Add(new float[] { driverData.position.X, driverData.position.Z }); } float playerRotation = currentState.CarOrientation.Yaw; if (playerRotation < 0) { playerRotation = (float)(2 * Math.PI) + playerRotation; } playerRotation = (float)(2 * Math.PI) - playerRotation; internalSpotter.triggerInternal(playerRotation, currentPlayerPosition, playerVelocityData, currentOpponentPositions); } }
public void trigger(Object lastStateObj, Object currentStateObj, GameStateData currentGameState) { if (paused) { return; } rfShared lastState = ((CrewChiefV4.rFactor1.RF1SharedMemoryReader.RF1StructWrapper)lastStateObj).data; rfShared currentState = ((CrewChiefV4.rFactor1.RF1SharedMemoryReader.RF1StructWrapper)currentStateObj).data; if (!enabled || currentState.currentET < timeAfterRaceStartToActivate || currentState.inRealtime == 0 || (currentState.numVehicles <= 2)) { return; } DateTime now = DateTime.Now; rfVehicleInfo currentPlayerData; rfVehicleInfo previousPlayerData; float timeDiffSeconds; try { currentPlayerData = getVehicleInfo(currentState); previousPlayerData = getVehicleInfo(lastState); timeDiffSeconds = ((float)(now - previousTime).TotalMilliseconds) / 1000f; previousTime = now; if (timeDiffSeconds <= 0) { // WTF? return; } } catch (Exception) { return; } if (currentGameState != null) { var carClass = currentGameState.carClass; if (carClass != null && !String.Equals(currentPlayerCarClassID, carClass.getClassIdentifier())) { // Retrieve and use user overridable spotter car length/width. currentPlayerCarClassID = carClass.getClassIdentifier(); var preferences = carClass.getPreferences(); this.internalSpotter.setCarDimensions(preferences.spotterVehicleLength, preferences.spotterVehicleWidth); } } float[] currentPlayerPosition = new float[] { currentPlayerData.pos.x, currentPlayerData.pos.z }; if (currentPlayerData.inPits == 0 && currentPlayerData.control == (int)rFactor1Constant.rfControl.player && // turn off spotter for formation lap before going green !(currentState.gamePhase == (int)rFactor1Constant.rfGamePhase.formation)) { List <float[]> currentOpponentPositions = new List <float[]>(); float[] playerVelocityData = new float[3]; playerVelocityData[0] = currentState.speed; playerVelocityData[1] = (currentPlayerData.pos.x - previousPlayerData.pos.x) / timeDiffSeconds; playerVelocityData[2] = (currentPlayerData.pos.z - previousPlayerData.pos.z) / timeDiffSeconds; for (int i = 0; i < currentState.numVehicles; i++) { rfVehicleInfo vehicle = currentState.vehicle[i]; if (vehicle.isPlayer == 1 || vehicle.inPits == 1 || vehicle.lapDist < 0) { continue; } currentOpponentPositions.Add(new float[] { vehicle.pos.x, vehicle.pos.z }); } float playerRotation = (float)(Math.Atan2((double)(currentState.oriZ.x), (double)(currentState.oriZ.z))); if (playerRotation < 0) { playerRotation = (float)(2 * Math.PI) + playerRotation; } internalSpotter.triggerInternal(playerRotation, currentPlayerPosition, playerVelocityData, currentOpponentPositions); } }
public void trigger(Object lastStateObj, Object currentStateObj) { if (paused) { return; } CrewChiefV4.PCars.PCarsSharedMemoryReader.PCarsStructWrapper currentWrapper = (CrewChiefV4.PCars.PCarsSharedMemoryReader.PCarsStructWrapper)currentStateObj; pCarsAPIStruct currentState = currentWrapper.data; // game state is 3 for paused, 5 for replay. No idea what 4 is... if (currentState.mGameState == (uint)eGameState.GAME_FRONT_END || (currentState.mGameState == (uint)eGameState.GAME_INGAME_PAUSED && !System.Diagnostics.Debugger.IsAttached) || currentState.mGameState == (uint)eGameState.GAME_VIEWING_REPLAY || currentState.mGameState == (uint)eGameState.GAME_EXITED) { // don't ignore the paused game updates if we're in debug mode return; } CrewChiefV4.PCars.PCarsSharedMemoryReader.PCarsStructWrapper previousWrapper = (CrewChiefV4.PCars.PCarsSharedMemoryReader.PCarsStructWrapper)lastStateObj; pCarsAPIStruct lastState = previousWrapper.data; DateTime now = new DateTime(currentWrapper.ticksWhenRead); float interval = (float)(((double)currentWrapper.ticksWhenRead - (double)previousWrapper.ticksWhenRead) / (double)TimeSpan.TicksPerSecond); if (currentState.mRaceState == (int)eRaceState.RACESTATE_RACING && lastState.mRaceState != (int)eRaceState.RACESTATE_RACING) { timeToStartSpotting = now.Add(TimeSpan.FromSeconds(timeAfterRaceStartToActivate)); } // this check looks a bit funky... whe we start a practice session, the raceState is not_started // until we cross the line for the first time. Which is retarded really. if (currentState.mRaceState == (int)eRaceState.RACESTATE_INVALID || now < timeToStartSpotting || (currentState.mSessionState == (int)eSessionState.SESSION_RACE && currentState.mRaceState == (int) eRaceState.RACESTATE_NOT_STARTED)) { return; } if (enabled && currentState.mNumParticipants > 1 && (enableSpotterInTimetrial || currentState.mSessionState != (uint)eSessionState.SESSION_TIME_ATTACK)) { Tuple<int, pCarsAPIParticipantStruct> playerDataWithIndex = PCarsGameStateMapper.getPlayerDataStruct(currentState.mParticipantData, currentState.mViewedParticipantIndex); int playerIndex = playerDataWithIndex.Item1; pCarsAPIParticipantStruct playerData = playerDataWithIndex.Item2; float[] currentPlayerPosition = new float[] { playerData.mWorldPosition[0], playerData.mWorldPosition[2] }; if (currentState.mPitMode == (uint)ePitMode.PIT_MODE_NONE) { List<float[]> currentOpponentPositions = new List<float[]>(); float[] playerVelocityData = new float[3]; playerVelocityData[0] = currentState.mSpeed; playerVelocityData[1] = currentState.mWorldVelocity[0]; playerVelocityData[2] = currentState.mWorldVelocity[2]; for (int i = 0; i < currentState.mParticipantData.Count(); i++) { if (i == playerIndex) { continue; } pCarsAPIParticipantStruct opponentData = currentState.mParticipantData[i]; if (opponentData.mIsActive) { float[] currentPositions = new float[] { opponentData.mWorldPosition[0], opponentData.mWorldPosition[2] }; currentOpponentPositions.Add(currentPositions); } } if (currentOpponentPositions.Count() > 0) { float playerRotation = currentState.mOrientation[1]; if (playerRotation < 0) { playerRotation = (float)(2 * Math.PI) + playerRotation; } playerRotation = (float)(2 * Math.PI) - playerRotation; internalSpotter.triggerInternal(playerRotation, currentPlayerPosition, playerVelocityData, currentOpponentPositions); } } } }
public void trigger(Object lastStateObj, Object currentStateObj, GameStateData currentGameState) { if (paused) { return; } AssettoCorsaShared lastState = ((ACSSharedMemoryReader.ACSStructWrapper)lastStateObj).data; AssettoCorsaShared currentState = ((ACSSharedMemoryReader.ACSStructWrapper)currentStateObj).data; if (!enabled || currentState.acsChief.numVehicles <= 1 || (mapToFloatTime(currentState.acsChief.vehicle[0].currentLapTimeMS) < timeAfterRaceStartToActivate && currentState.acsChief.vehicle[0].lapCount <= 0)) { return; } DateTime now = DateTime.Now; acsVehicleInfo currentPlayerData; acsVehicleInfo previousPlayerData; float timeDiffSeconds; try { currentPlayerData = currentState.acsChief.vehicle[0]; previousPlayerData = lastState.acsChief.vehicle[0]; timeDiffSeconds = ((float)(now - previousTime).TotalMilliseconds) / 1000f; previousTime = now; if (timeDiffSeconds <= 0) { return; } } catch (Exception) { return; } if (currentGameState != null) { var carClass = currentGameState.carClass; if (carClass != null && !String.Equals(currentPlayerCarClassID, carClass.getClassIdentifier())) { // Retrieve and use user overridable spotter car length/width. currentPlayerCarClassID = carClass.getClassIdentifier(); var preferences = carClass.getPreferences(); this.internalSpotter.setCarDimensions(preferences.spotterVehicleLength, preferences.spotterVehicleWidth); } } float[] currentPlayerPosition = new float[] { currentPlayerData.worldPosition.x, currentPlayerData.worldPosition.z }; if (currentPlayerData.isCarInPitline == 0 || currentPlayerData.isCarInPit == 0) { List <float[]> currentOpponentPositions = new List <float[]>(); float[] playerVelocityData = new float[3]; playerVelocityData[0] = currentPlayerData.speedMS; playerVelocityData[1] = (currentPlayerData.worldPosition.x - previousPlayerData.worldPosition.x) / timeDiffSeconds; playerVelocityData[2] = (currentPlayerData.worldPosition.z - previousPlayerData.worldPosition.z) / timeDiffSeconds; for (int i = 0; i < currentState.acsChief.numVehicles; i++) { acsVehicleInfo vehicle = currentState.acsChief.vehicle[i]; if (vehicle.carId == 0 || vehicle.isCarInPit == 1 || vehicle.isCarInPitline == 1 || vehicle.isConnected != 1) { continue; } currentOpponentPositions.Add(new float[] { vehicle.worldPosition.x, vehicle.worldPosition.z }); } float playerRotation = currentState.acsPhysics.heading; if (playerRotation < 0) { playerRotation = (float)(2 * Math.PI) + playerRotation; } internalSpotter.triggerInternal(playerRotation, currentPlayerPosition, playerVelocityData, currentOpponentPositions); } }
public void trigger(Object lastStateObj, Object currentStateObj, GameStateData currentGameState) { if (paused) { return; } RaceRoomShared lastState = ((CrewChiefV4.RaceRoom.R3ESharedMemoryReader.R3EStructWrapper)lastStateObj).data; RaceRoomShared currentState = ((CrewChiefV4.RaceRoom.R3ESharedMemoryReader.R3EStructWrapper)currentStateObj).data; if (!enabled || currentState.Player.GameSimulationTime < timeAfterRaceStartToActivate || currentState.ControlType != (int)RaceRoomConstant.Control.Player || ((int)RaceRoomConstant.Session.Qualify == currentState.SessionType && (currentState.NumCars == 1 || currentState.NumCars == 2))) { return; } DateTime now = DateTime.Now; DriverData currentPlayerData; DriverData previousPlayerData; float timeDiffSeconds; try { currentPlayerData = getDriverData(currentState, currentState.VehicleInfo.SlotId); previousPlayerData = getDriverData(lastState, currentState.VehicleInfo.SlotId); timeDiffSeconds = ((float)(now - previousTime).TotalMilliseconds) / 1000f; previousTime = now; if (timeDiffSeconds <= 0) { // WTF? return; } } catch (Exception) { return; } if (currentGameState != null) { var carClass = currentGameState.carClass; if (carClass != null && !String.Equals(currentPlayerCarClassID, carClass.getClassIdentifier())) { // Retrieve and use user overridable spotter car length/width. currentPlayerCarClassID = carClass.getClassIdentifier(); var preferences = carClass.getPreferences(); this.internalSpotter.setCarDimensions(preferences.spotterVehicleLength, preferences.spotterVehicleWidth); } } float[] currentPlayerPosition = new float[] { currentPlayerData.Position.X, currentPlayerData.Position.Z }; if (currentPlayerData.InPitlane == 0) { List <float[]> currentOpponentPositions = new List <float[]>(); float[] playerVelocityData = new float[3]; playerVelocityData[0] = currentState.CarSpeed; playerVelocityData[1] = (currentPlayerData.Position.X - previousPlayerData.Position.X) / timeDiffSeconds; playerVelocityData[2] = (currentPlayerData.Position.Z - previousPlayerData.Position.Z) / timeDiffSeconds; foreach (DriverData driverData in currentState.DriverData) { if (driverData.DriverInfo.SlotId == currentState.VehicleInfo.SlotId || driverData.DriverInfo.SlotId == -1 || driverData.InPitlane == 1) { continue; } currentOpponentPositions.Add(new float[] { driverData.Position.X, driverData.Position.Z }); } float playerRotation = currentState.CarOrientation.Yaw; if (playerRotation < 0) { playerRotation = (float)(2 * Math.PI) + playerRotation; } playerRotation = (float)(2 * Math.PI) - playerRotation; internalSpotter.triggerInternal(playerRotation, currentPlayerPosition, playerVelocityData, currentOpponentPositions); } }