From f338530e6df32463a762c0ef90e90777e05be94e Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 8 May 2025 21:52:50 -0400 Subject: [PATCH] Fix rotations sent to other players There was two problems I was running into: 1. The move packet changed slightly, using a different way to encode the rotation. In hindsight, it should seem obvious they would encode it the same way for CommonSpawn and ActorMove. 2. write_quantized_rotation did it's order of operations wrong, and it would spit out nonsensical rotations. Both issues are fixed and you can see the other player's rotation correctly now! --- src/common/mod.rs | 16 +--------------- src/ipc/zone/move.rs | 15 ++++++--------- src/world/connection.rs | 6 ++---- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/common/mod.rs b/src/common/mod.rs index 999fcf1..3604ad1 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -82,7 +82,7 @@ pub(crate) fn write_quantized_rotation(quantized: &f32) -> u16 { let max = u16::MAX as f32; let pi = std::f32::consts::PI; - ((quantized + pi / (2.0 * pi)) * max) as u16 + (((quantized + pi) / (2.0 * pi)) * max) as u16 } pub(crate) fn read_packed_float(packed: u16) -> f32 { @@ -93,16 +93,6 @@ 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]), @@ -212,9 +202,5 @@ mod tests { fn packed_floats() { assert_eq!(read_packed_float(32931), 4.989685); 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/ipc/zone/move.rs b/src/ipc/zone/move.rs index 8b3ec81..ea2168a 100644 --- a/src/ipc/zone/move.rs +++ b/src/ipc/zone/move.rs @@ -1,21 +1,18 @@ use binrw::binrw; use crate::common::{ - Position, read_packed_position, read_packed_rotation_float, write_packed_position, - write_packed_rotation_float, + Position, read_packed_position, read_quantized_rotation, write_packed_position, + write_quantized_rotation, }; #[binrw] #[derive(Debug, Clone, Default)] pub struct Move { - #[bw(map = write_packed_rotation_float)] - #[br(map = read_packed_rotation_float)] + #[br(map = read_quantized_rotation)] + #[bw(map = write_quantized_rotation)] pub rotation: f32, - pub dir_before_slip: u8, - pub flag1: u8, - pub flag2: u8, - pub speed: u8, - #[brw(pad_before = 1)] // padding + pub flag1: u16, + pub flag2: u16, #[brw(pad_after = 4)] // empty #[br(map = read_packed_position)] #[bw(map = write_packed_position)] diff --git a/src/world/connection.rs b/src/world/connection.rs index d66cfd6..a2f9adf 100644 --- a/src/world/connection.rs +++ b/src/world/connection.rs @@ -259,10 +259,8 @@ impl ZoneConnection { timestamp: timestamp_secs(), data: ServerZoneIpcData::Move(Move { rotation, - dir_before_slip: 0x7F, - flag1: 0, - flag2: 0, - speed: 0x3C, + flag1: 128, + flag2: 60, position, }), ..Default::default()