diff --git a/src/common/mod.rs b/src/common/mod.rs index 4e17c78..5eb1187 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -89,10 +89,20 @@ pub(crate) fn read_packed_float(packed: u16) -> f32 { ((packed as f32 / 0.327675) / 100.0) - 1000.0 } -pub(crate) fn write_packed_float(float: f32) -> u16 { +pub(crate) fn write_packed_float(float: &f32) -> u16 { (((float + 1000.0) * 100.0) * 0.327675) as u16 } +pub(crate) fn write_packed_rotation_float(float: &f32) -> u8 { + let pi = std::f32::consts::PI; + + (0x80 as f32 * (float + pi) / pi) as u8 +} + +pub(crate) fn read_packed_rotation_float(packed: u8) -> f32 { + 0.0 +} + pub(crate) fn read_packed_position(packed: [u16; 3]) -> Position { Position { x: read_packed_float(packed[0]), @@ -103,9 +113,9 @@ pub(crate) fn read_packed_position(packed: [u16; 3]) -> Position { pub(crate) fn write_packed_position(pos: &Position) -> [u16; 3] { [ - write_packed_float(pos.x), - write_packed_float(pos.y), - write_packed_float(pos.z), + write_packed_float(&pos.x), + write_packed_float(&pos.y), + write_packed_float(&pos.z), ] } @@ -201,6 +211,10 @@ mod tests { #[test] fn packed_floats() { assert_eq!(read_packed_float(32931), 4.989685); - assert_eq!(write_packed_float(5.0), 32931); + assert_eq!(write_packed_float(&5.0), 32931); + + assert_eq!(write_packed_rotation_float(&0.0), 128); + assert_eq!(write_packed_rotation_float(&-2.7768986), 14); + assert_eq!(write_packed_rotation_float(&3.128286), 255); } } diff --git a/src/world/connection.rs b/src/world/connection.rs index 7bcf29a..bb7ba47 100644 --- a/src/world/connection.rs +++ b/src/world/connection.rs @@ -290,7 +290,12 @@ impl ZoneConnection { op_code: ServerZoneIpcType::ActorMove, timestamp: timestamp_secs(), data: ServerZoneIpcData::ActorMove(ActorMove { - speed: 24, + rotation, + dir_before_slip: 0x7F, + flag1: 0, + flag2: 0, + speed: 0x3C, + unk1: 0xEA, position, ..Default::default() }), diff --git a/src/world/ipc/actor_move.rs b/src/world/ipc/actor_move.rs index 55aac50..150f277 100644 --- a/src/world/ipc/actor_move.rs +++ b/src/world/ipc/actor_move.rs @@ -1,16 +1,22 @@ use binrw::binrw; -use crate::common::{Position, read_packed_position, write_packed_position}; +use crate::common::{ + Position, read_packed_position, read_packed_rotation_float, write_packed_position, + write_packed_rotation_float, +}; #[binrw] #[derive(Debug, Clone, Default)] pub struct ActorMove { - pub dir: u8, + #[bw(map = write_packed_rotation_float)] + #[br(map = read_packed_rotation_float)] + pub rotation: f32, pub dir_before_slip: u8, pub flag1: u8, - pub flat2: u8, + pub flag2: u8, pub speed: u8, - #[brw(pad_before = 1, pad_after = 4)] // empty + pub unk1: u8, + #[brw(pad_after = 4)] // empty #[br(map = read_packed_position)] #[bw(map = write_packed_position)] pub position: Position,