feat: add 2022 spec car damage packet parser

This commit is contained in:
Maciej Pędzich 2025-02-19 12:41:49 +01:00
parent 6c9dd17282
commit d880590e8b
Signed by: maciejpedzich
GPG Key ID: CE4A303D84882F0D
3 changed files with 89 additions and 5 deletions

View File

@ -3,9 +3,10 @@ pub mod packets;
use crate::constants::PacketId;
use crate::packets::{
F1PacketCarSetups, F1PacketCarStatus, F1PacketCarTelemetry, F1PacketEvent,
F1PacketFinalClassification, F1PacketLap, F1PacketMotion,
F1PacketParticipants, F1PacketSession,
F1PacketCarDamage, F1PacketCarSetups, F1PacketCarStatus,
F1PacketCarTelemetry, F1PacketEvent, F1PacketFinalClassification,
F1PacketLap, F1PacketLobbyInfo, F1PacketMotion, F1PacketParticipants,
F1PacketSession,
};
use binrw::io::Cursor;
@ -100,4 +101,10 @@ pub struct F1PacketBody {
/// Final classification confirmation at the end of a race.
#[br(if(packet_id == PacketId::FinalClassification), args(packet_format))]
pub final_classification: Option<F1PacketFinalClassification>,
/// Details of players in a multiplayer lobby.
#[br(if(packet_id == PacketId::LobbyInfo), args(packet_format))]
pub lobby_info: Option<F1PacketLobbyInfo>,
/// Car damage parameters for all cars in the session.
#[br(if(packet_id == PacketId::CarDamage), args(packet_format))]
pub car_damage: Option<F1PacketCarDamage>,
}

62
src/packets/car_damage.rs Normal file
View File

@ -0,0 +1,62 @@
use super::u8_to_bool;
use binrw::BinRead;
use serde::{Deserialize, Serialize};
#[derive(
BinRead, PartialEq, PartialOrd, Copy, Clone, Debug, Serialize, Deserialize,
)]
#[br(little, import(_packet_format: u16))]
pub struct CarDamageData {
/// Tyre wear percentage for all wheels.
/// See [`wheel_index`](mod@crate::constants::wheel_index)
/// for wheel order.
pub tyres_wear: [f32; 4],
/// Tyre damage percentage for all wheels.
/// See [`wheel_index`](mod@crate::constants::wheel_index)
/// for wheel order.
pub tyres_damage: [u8; 4],
/// Brake damage percentage for all wheels.
/// See [`wheel_index`](mod@crate::constants::wheel_index)
/// for wheel order.
pub brakes_damage: [u8; 4],
/// Front left wing damage (percentage)
pub front_left_wing_damage: u8,
/// Front right wing damage (percentage)
pub front_right_wing_damage: u8,
/// Rear wing damage (percentage)
pub rear_wing_damage: u8,
/// Floor damage (percentage)
pub floor_damage: u8,
/// Diffuser damage (percentage)
pub diffuser_damage: u8,
/// Sidepod damage (percentage)
pub sidepod_damage: u8,
/// Whether DRS has failed
#[br(map(u8_to_bool))]
pub drs_fault: bool,
/// Whether ERS has failed
#[br(map(u8_to_bool))]
pub ers_fault: bool,
/// Gearbox damage (percentage)
pub gearbox_damage: u8,
/// Engine damage (percentage)
pub engine_damage: u8,
/// Engine MGU-H wear (percentage)
pub engine_mguh_wear: u8,
/// Engine ES wear (percentage)
pub engine_es_wear: u8,
/// Engine CE wear (percentage)
pub engine_ce_wear: u8,
/// Engine ICE wear (percentage)
pub engine_ice_wear: u8,
/// Engine MGU-K wear (percentage)
pub engine_mguk_wear: u8,
/// Engine TC wear (percentage)
pub engine_tc_wear: u8,
/// Whether the engine has blown
#[br(map(u8_to_bool))]
pub engine_blown: bool,
/// Whether the engine has seized
#[br(map(u8_to_bool))]
pub engine_seized: bool,
}

View File

@ -1,13 +1,14 @@
mod car_damage;
pub mod car_setups;
pub mod car_status;
pub mod car_telemetry;
pub mod event;
pub mod final_classification;
pub mod lap;
mod lobby;
pub mod motion;
pub mod participants;
pub mod session;
mod lobby;
use crate::constants::{
BrakingAssist, DynamicRacingLine, DynamicRacingLineType, ForecastAccuracy,
@ -25,6 +26,7 @@ use crate::packets::motion::CarMotionData;
use crate::packets::participants::ParticipantsData;
use crate::packets::session::{MarshalZone, WeatherForecastSample};
use crate::packets::car_damage::CarDamageData;
use binrw::BinRead;
use serde::{Deserialize, Serialize};
use std::string::FromUtf8Error;
@ -315,6 +317,7 @@ pub struct F1PacketFinalClassification {
}
/// Packet detailing all the players that are currently in a multiplayer lobby.
#[non_exhaustive]
#[derive(
BinRead, PartialEq, PartialOrd, Clone, Debug, Serialize, Deserialize,
)]
@ -327,7 +330,7 @@ pub struct F1PacketFinalClassification {
num_players
)
)]
pub struct F1PacketLobbyInfoData {
pub struct F1PacketLobbyInfo {
/// Number of players in the lobby (no greater than 22).
#[br(map(u8_to_usize))]
pub num_players: usize,
@ -338,6 +341,18 @@ pub struct F1PacketLobbyInfoData {
pub lobby_info_data: Vec<LobbyInfoData>,
}
/// Car damage parameters for all cars in the session.
#[non_exhaustive]
#[derive(
BinRead, PartialEq, PartialOrd, Clone, Debug, Serialize, Deserialize,
)]
#[br(little, import(packet_format: u16))]
pub struct F1PacketCarDamage {
/// Car damage data. Should have a size of 22.
#[br(count(MAX_NUM_CARS), args{ inner: (packet_format,) })]
pub car_damage_data: Vec<CarDamageData>,
}
/// Extended motion data for player's car. Available as a:
/// - part of [`F1PacketMotion`] in the 2022 format
/// - standalone packet from the 2023 format onwards