mirror of
https://github.com/maciejpedzich/f1-game-packet-parser.git
synced 2025-04-19 03:01:10 +02:00
feat: add 2022 spec car damage packet parser
This commit is contained in:
parent
6c9dd17282
commit
d880590e8b
13
src/lib.rs
13
src/lib.rs
@ -3,9 +3,10 @@ pub mod packets;
|
|||||||
|
|
||||||
use crate::constants::PacketId;
|
use crate::constants::PacketId;
|
||||||
use crate::packets::{
|
use crate::packets::{
|
||||||
F1PacketCarSetups, F1PacketCarStatus, F1PacketCarTelemetry, F1PacketEvent,
|
F1PacketCarDamage, F1PacketCarSetups, F1PacketCarStatus,
|
||||||
F1PacketFinalClassification, F1PacketLap, F1PacketMotion,
|
F1PacketCarTelemetry, F1PacketEvent, F1PacketFinalClassification,
|
||||||
F1PacketParticipants, F1PacketSession,
|
F1PacketLap, F1PacketLobbyInfo, F1PacketMotion, F1PacketParticipants,
|
||||||
|
F1PacketSession,
|
||||||
};
|
};
|
||||||
|
|
||||||
use binrw::io::Cursor;
|
use binrw::io::Cursor;
|
||||||
@ -100,4 +101,10 @@ pub struct F1PacketBody {
|
|||||||
/// Final classification confirmation at the end of a race.
|
/// Final classification confirmation at the end of a race.
|
||||||
#[br(if(packet_id == PacketId::FinalClassification), args(packet_format))]
|
#[br(if(packet_id == PacketId::FinalClassification), args(packet_format))]
|
||||||
pub final_classification: Option<F1PacketFinalClassification>,
|
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
62
src/packets/car_damage.rs
Normal 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,
|
||||||
|
}
|
@ -1,13 +1,14 @@
|
|||||||
|
mod car_damage;
|
||||||
pub mod car_setups;
|
pub mod car_setups;
|
||||||
pub mod car_status;
|
pub mod car_status;
|
||||||
pub mod car_telemetry;
|
pub mod car_telemetry;
|
||||||
pub mod event;
|
pub mod event;
|
||||||
pub mod final_classification;
|
pub mod final_classification;
|
||||||
pub mod lap;
|
pub mod lap;
|
||||||
|
mod lobby;
|
||||||
pub mod motion;
|
pub mod motion;
|
||||||
pub mod participants;
|
pub mod participants;
|
||||||
pub mod session;
|
pub mod session;
|
||||||
mod lobby;
|
|
||||||
|
|
||||||
use crate::constants::{
|
use crate::constants::{
|
||||||
BrakingAssist, DynamicRacingLine, DynamicRacingLineType, ForecastAccuracy,
|
BrakingAssist, DynamicRacingLine, DynamicRacingLineType, ForecastAccuracy,
|
||||||
@ -25,6 +26,7 @@ use crate::packets::motion::CarMotionData;
|
|||||||
use crate::packets::participants::ParticipantsData;
|
use crate::packets::participants::ParticipantsData;
|
||||||
use crate::packets::session::{MarshalZone, WeatherForecastSample};
|
use crate::packets::session::{MarshalZone, WeatherForecastSample};
|
||||||
|
|
||||||
|
use crate::packets::car_damage::CarDamageData;
|
||||||
use binrw::BinRead;
|
use binrw::BinRead;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::string::FromUtf8Error;
|
use std::string::FromUtf8Error;
|
||||||
@ -315,6 +317,7 @@ pub struct F1PacketFinalClassification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Packet detailing all the players that are currently in a multiplayer lobby.
|
/// Packet detailing all the players that are currently in a multiplayer lobby.
|
||||||
|
#[non_exhaustive]
|
||||||
#[derive(
|
#[derive(
|
||||||
BinRead, PartialEq, PartialOrd, Clone, Debug, Serialize, Deserialize,
|
BinRead, PartialEq, PartialOrd, Clone, Debug, Serialize, Deserialize,
|
||||||
)]
|
)]
|
||||||
@ -327,7 +330,7 @@ pub struct F1PacketFinalClassification {
|
|||||||
num_players
|
num_players
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
pub struct F1PacketLobbyInfoData {
|
pub struct F1PacketLobbyInfo {
|
||||||
/// Number of players in the lobby (no greater than 22).
|
/// Number of players in the lobby (no greater than 22).
|
||||||
#[br(map(u8_to_usize))]
|
#[br(map(u8_to_usize))]
|
||||||
pub num_players: usize,
|
pub num_players: usize,
|
||||||
@ -338,6 +341,18 @@ pub struct F1PacketLobbyInfoData {
|
|||||||
pub lobby_info_data: Vec<LobbyInfoData>,
|
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:
|
/// Extended motion data for player's car. Available as a:
|
||||||
/// - part of [`F1PacketMotion`] in the 2022 format
|
/// - part of [`F1PacketMotion`] in the 2022 format
|
||||||
/// - standalone packet from the 2023 format onwards
|
/// - standalone packet from the 2023 format onwards
|
||||||
|
Loading…
x
Reference in New Issue
Block a user