Skip to content

Commit

Permalink
Add ShipDestroyedPacket.
Browse files Browse the repository at this point in the history
  • Loading branch information
lkolbly committed Aug 29, 2020
1 parent baffaad commit 4b3ea52
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ The following packets are parsed at least partially:
- DamageReceived: Emitted whenever damage is dealt to a ship.
- ArtilleryHit: Emitted whenever either the player's guns hit a ship or whenever the player's ship is hit by shells. This packet has many unknown fields.
- Banner: Emitted when the player receives a banner.
- ShipDestroyed: Emitted when a ship kills another, contains both victim and perpetrator IDs as well as cause (e.g. artillery, fire, ramming).

Packet wishlist
===============
Expand All @@ -78,7 +79,6 @@ The following information is not yet extracted from replays, but is information
- Torpedoes.
- Planes.
- Ship visibility/hidden status (and the player's "detected" status)
- Ship destruction.
- Incapacitation type.
- Consumable usage.
- Smoke.
Expand Down
58 changes: 58 additions & 0 deletions parser/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,28 @@ pub struct ArtilleryHitPacket<'a> {
pub raw: &'a [u8],
}

#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Serialize)]
pub enum DeathCause {
Secondaries,
Artillery,
Fire,
Flooding,
Torpedo,
DiveBomber,
AerialRocket,
AerialTorpedo,
Detonation,
Ramming,
}

#[derive(Debug, Serialize)]
pub struct ShipDestroyedPacket {
pub victim: u32,
pub killer: u32,
pub death_cause: DeathCause,
pub unknown: u32,
}

#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Serialize)]
pub enum Banner {
PlaneShotDown,
Expand Down Expand Up @@ -154,6 +176,7 @@ pub enum PacketType<'a> {
PlayerOrientation(PlayerOrientationPacket),
Type8_79(Vec<(u32, u32)>),
Setup(SetupPacket),
ShipDestroyed(ShipDestroyedPacket),
Unknown(&'a [u8]),

/// These are packets which we thought we understood, but couldn't parse
Expand All @@ -169,6 +192,40 @@ pub struct Packet<'a> {
pub raw: &'a [u8],
}

fn parse_ship_destroyed_packet(
_entity_id: u32,
_supertype: u32,
_subtype: u32,
payload: &[u8],
) -> IResult<&[u8], PacketType> {
let (i, victim) = le_u32(payload)?;
let (i, killer) = le_u32(i)?;
let (i, unknown) = le_u32(i)?;
let death_cause = match unknown {
2 => DeathCause::Secondaries,
3 => DeathCause::Torpedo,
4 => DeathCause::DiveBomber,
5 => DeathCause::AerialTorpedo,
6 => DeathCause::Fire,
7 => DeathCause::Ramming,
9 => DeathCause::Flooding,
14 => DeathCause::AerialRocket,
15 => DeathCause::Detonation,
17 => DeathCause::Artillery,
18 => DeathCause::Artillery,
19 => DeathCause::Artillery,
_ => {
panic!(format!("Found unknown death_cause {}", unknown));
}
};
Ok((
i,
PacketType::ShipDestroyed(ShipDestroyedPacket {
victim, killer, death_cause, unknown
})
))
}

fn parse_player_orientation_packet(i: &[u8]) -> IResult<&[u8], PacketType> {
assert!(i.len() == 0x20);
let (i, pid) = le_u32(i)?;
Expand Down Expand Up @@ -552,6 +609,7 @@ fn lookup_entity_fn(
(0x8, 0x64) => parse_artillery_hit_packet,
(0x8, 0xc) => parse_banner_packet,
(0x8, 0x35) => parse_damage_received_packet, // TODO: This needs better verification
(0x8, 0x53) => parse_ship_destroyed_packet,
_ => parse_unknown_entity_packet,
}
};
Expand Down

0 comments on commit 4b3ea52

Please sign in to comment.