215 lines
5.6 KiB
Rust
215 lines
5.6 KiB
Rust
use std::mem;
|
|
|
|
use crate::rfactor_structs::*;
|
|
|
|
pub const MM_TELEMETRY_FILE_NAME: &str = "$rFactor2SMMP_Telemetry$";
|
|
pub const MM_SCORING_FILE_NAME: &str = "$rFactor2SMMP_Scoring$";
|
|
pub const MM_EXTENDED_FILE_NAME: &str = "$rFactor2SMMP_Extended$";
|
|
pub const MM_PITINFO_FILE_NAME: &str = "$rFactor2SMMP_PitInfo$";
|
|
pub const MM_WEATHER_FILE_NAME: &str = "$rFactor2SMMP_Weather$";
|
|
pub const MM_RULES_CONTROL_FILE_NAME: &str = "$rFactor2SMMP_RulesControl$";
|
|
|
|
pub const MAX_MAPPED_VEHICLES: usize = 128;
|
|
pub const MAX_MAPPED_IDS: usize = 512;
|
|
|
|
#[repr(C, packed(4))]
|
|
#[derive(Debug, Copy, Clone)]
|
|
pub struct rF2Telemetry {
|
|
pub version_update_begin: u32,
|
|
pub version_update_end: u32,
|
|
pub bytes_update_hint: i32,
|
|
|
|
pub num_vehicles: i32,
|
|
pub vehicle_telemetry: [rF2VehicleTelemetry; MAX_MAPPED_VEHICLES],
|
|
}
|
|
|
|
impl rF2Telemetry {
|
|
pub const SIZE: usize = mem::size_of::<Self>();
|
|
|
|
pub fn vehicles(&self) -> &[rF2VehicleTelemetry] {
|
|
&self.vehicle_telemetry[0..self.num_vehicles as usize]
|
|
}
|
|
}
|
|
|
|
impl From<&[u8]> for rF2Telemetry {
|
|
fn from(value: &[u8]) -> Self {
|
|
debug_assert!(value.len() == Self::SIZE);
|
|
let fixed_size: [u8; Self::SIZE] = value.try_into().unwrap();
|
|
|
|
unsafe { mem::transmute(fixed_size) }
|
|
}
|
|
}
|
|
|
|
#[repr(C, packed(4))]
|
|
#[derive(Debug, Copy, Clone)]
|
|
pub struct rF2Scoring {
|
|
pub version_update_begin: u32,
|
|
pub version_update_end: u32,
|
|
pub bytes_update_hint: i32,
|
|
|
|
pub scoring_info: ScoringInfoV01,
|
|
pub vehicles: [VehicleScoringInfoV01; MAX_MAPPED_VEHICLES],
|
|
}
|
|
|
|
impl rF2Scoring {
|
|
pub const SIZE: usize = mem::size_of::<Self>();
|
|
|
|
pub fn vehicles(&self) -> &[VehicleScoringInfoV01] {
|
|
&self.vehicles[0..self.scoring_info.mNumVehicles as usize]
|
|
}
|
|
}
|
|
|
|
impl From<&[u8]> for rF2Scoring {
|
|
fn from(value: &[u8]) -> Self {
|
|
debug_assert!(value.len() == Self::SIZE);
|
|
let fixed_size: [u8; Self::SIZE] = value.try_into().unwrap();
|
|
|
|
unsafe { mem::transmute(fixed_size) }
|
|
}
|
|
}
|
|
|
|
#[repr(C, packed(4))]
|
|
#[derive(Debug, Copy, Clone)]
|
|
pub struct rF2Vec3 {
|
|
pub x: f64,
|
|
pub y: f64,
|
|
pub z: f64,
|
|
}
|
|
|
|
#[repr(C, packed(4))]
|
|
#[derive(Debug, Copy, Clone)]
|
|
pub struct rF2VehicleTelemetry {
|
|
// Time
|
|
pub id: i32,
|
|
pub delta_time: f64,
|
|
pub elapsed_time: f64,
|
|
pub lap_number: i32,
|
|
pub lap_start_et: f64,
|
|
pub vehicle_name: [u8; 64],
|
|
pub track_name: [u8; 64],
|
|
|
|
// Position and derivatives
|
|
pub position: rF2Vec3,
|
|
pub local_velocity: rF2Vec3,
|
|
pub local_acceleration: rF2Vec3,
|
|
|
|
// Orientation and derivatives
|
|
pub orientation: [rF2Vec3; 3],
|
|
pub local_rotation: rF2Vec3,
|
|
pub local_rotational_acceleration: rF2Vec3,
|
|
|
|
// Vehicle status
|
|
pub gear: i32,
|
|
pub engine_rpm: f64,
|
|
pub engine_water_temp: f64,
|
|
pub engine_oil_temp: f64,
|
|
pub clutch_rpm: f64,
|
|
|
|
// Driver input
|
|
pub unfiltered_throttle: f64,
|
|
pub unfiltered_brake: f64,
|
|
pub unfiltered_steering: f64,
|
|
pub unfiltered_clutch: f64,
|
|
|
|
// Filtered input (various adjustments for rev or speed limiting, TC, ABS?, speed sensitive steering, clutch work for semi-automatic shifting, etc.)
|
|
pub filtered_throttle: f64,
|
|
pub filtered_brake: f64,
|
|
pub filtered_steering: f64,
|
|
pub filtered_clutch: f64,
|
|
|
|
// Misc
|
|
pub steering_shaft_torque: f64,
|
|
pub front_3rd_deflection: f64,
|
|
pub rear_3rd_deflection: f64,
|
|
|
|
// Aerodynamics
|
|
pub front_wing_height: f64,
|
|
pub front_ride_height: f64,
|
|
pub rear_ride_height: f64,
|
|
pub drag: f64,
|
|
pub front_downforce: f64,
|
|
pub rear_downforce: f64,
|
|
|
|
// State/damage info
|
|
pub fuel: f64,
|
|
pub engine_max_rpm: f64,
|
|
pub scheduled_stops: u8,
|
|
pub overheating: u8,
|
|
pub detached: u8,
|
|
pub headlights: u8,
|
|
pub dent_severity: [u8; 8],
|
|
pub last_impact_et: f64,
|
|
pub last_impact_magnitude: f64,
|
|
pub last_impact_position: rF2Vec3,
|
|
|
|
// Expanded
|
|
pub engine_torque: f64,
|
|
pub current_sector: i32,
|
|
pub speed_limiter: u8,
|
|
pub max_gears: u8,
|
|
pub front_tire_compound_index: u8,
|
|
pub rear_tire_compound_index: u8,
|
|
pub fuel_capacity: f64,
|
|
pub front_flap_activated: u8,
|
|
pub read_flap_activated: u8,
|
|
pub rear_flap_legal_status: u8,
|
|
pub ignition_start: u8,
|
|
|
|
pub front_tire_compound_name: [u8; 18],
|
|
pub rear_tire_compound_name: [u8; 18],
|
|
|
|
pub speed_limier_available: u8,
|
|
pub anti_stall_activated: u8,
|
|
unused: [u8; 2],
|
|
pub visual_steering_wheel_range: f32,
|
|
|
|
pub rear_brake_bias: f64,
|
|
pub turbo_boot_pressure: f64,
|
|
pub physics_to_graphics_offset: [f32; 3],
|
|
pub physical_steering_wheel_range: f32,
|
|
|
|
// Future use
|
|
expansion: [u8; 152],
|
|
|
|
// keeping this at the end of the structure to make it easier to replace in future versions
|
|
pub wheels: [rF2Wheel; 4],
|
|
}
|
|
|
|
#[repr(C, packed(4))]
|
|
#[derive(Debug, Copy, Clone)]
|
|
pub struct rF2Wheel {
|
|
pub suspension_deflection: f64,
|
|
pub ride_height: f64,
|
|
pub susp_force: f64,
|
|
pub brake_temp: f64,
|
|
pub brake_pressure: f64,
|
|
|
|
pub rotation: f64,
|
|
pub lateral_patch_vel: f64,
|
|
pub longitudinal_patch_vel: f64,
|
|
pub lateral_ground_vel: f64,
|
|
pub longitudinal_ground_vel: f64,
|
|
pub camber: f64,
|
|
pub lateral_force: f64,
|
|
pub longitudinal_force: f64,
|
|
pub tire_load: f64,
|
|
|
|
pub grip_fract: f64,
|
|
pub pressure: f64,
|
|
pub temperature: [f64; 3],
|
|
pub wear: f64,
|
|
pub terrain_name: [u8; 16],
|
|
pub surface_type: u8,
|
|
pub flat: u8,
|
|
pub detached: u8,
|
|
pub static_undeflected_radius: u8,
|
|
|
|
pub vertical_tire_deflection: f64,
|
|
pub wheel_y_location: f64,
|
|
pub toe: f64,
|
|
|
|
pub tire_carcass_temperature: f64,
|
|
pub tire_inner_layer_temperature: [f64; 3],
|
|
|
|
expansion: [::std::os::raw::c_uchar; 24],
|
|
}
|