From 3fee9e5e5f925220b4a70c349abefd2292d5fbd8 Mon Sep 17 00:00:00 2001 From: kokosha Date: Sat, 28 Dec 2024 10:12:12 -0300 Subject: [PATCH] Even more fixes --- ragnarok_packets/src/position.rs | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/ragnarok_packets/src/position.rs b/ragnarok_packets/src/position.rs index 8dd75071..d05213bd 100644 --- a/ragnarok_packets/src/position.rs +++ b/ragnarok_packets/src/position.rs @@ -48,7 +48,7 @@ impl From<&[isize; 2]> for Direction { [-1, -1] => Direction::SW, [-1, 0] => Direction::W, [-1, 1] => Direction::NW, - _ => unreachable!(), + _ => panic!("impossible direction"), } } } @@ -118,11 +118,20 @@ pub struct WorldPosition2 { pub y1: usize, pub x2: usize, pub y2: usize, + pub shift_x: isize, + pub shift_y: isize, } impl WorldPosition2 { pub fn new(x1: usize, y1: usize, x2: usize, y2: usize) -> Self { - Self { x1, y1, x2, y2 } + Self { + x1, + y1, + x2, + y2, + shift_x: 0, + shift_y: 0, + } } pub fn to_origin_destination(self) -> (WorldPosition, WorldPosition) { @@ -149,11 +158,17 @@ impl FromBytes for WorldPosition2 { let y1 = (coordinates[2] >> 4) | ((coordinates[1] & 0b111111) << 4); let x2 = (coordinates[3] >> 2) | ((coordinates[2] & 0b1111) << 6); let y2 = coordinates[4] | ((coordinates[3] & 0b11) << 8); - /* Not related with direction at all is bigger than 7, it seems to be always 8. - let reserved1 = coordinates[5] >> 4; - let reserved2 = coordinates[5] & 0b1111;*/ + let shift_x = (coordinates[5] >> 4) as isize - 8; + let shift_y = (coordinates[5] & 0b1111) as isize - 8; - Ok(Self { x1, y1, x2, y2 }) + Ok(Self { + x1, + y1, + x2, + y2, + shift_x, + shift_y, + }) } } @@ -166,8 +181,7 @@ impl ToBytes for WorldPosition2 { bytes[2] = ((self.y1 << 4) as u8) | ((self.x2 >> 6) as u8); bytes[3] = ((self.x2 << 2) as u8) | ((self.y2 >> 8) as u8); bytes[4] = self.y2 as u8; - /* Not related with direction at all is bigger than 7, it seems to be always 8. - bytes[5] = ((self.reserved1 << 4) as u8) || ((self.reserved2 & 0xF) as u8);*/ + bytes[5] = (((self.shift_x + 8) << 4) as u8) | ((((self.shift_y + 8) as usize) & 0xF) as u8); Ok(bytes) } @@ -206,6 +220,7 @@ mod conversion { [0, 0, 255, 0, 0, 0], [0, 0, 0, 255, 0, 0], [0, 0, 0, 0, 255, 0], + [0, 0, 0, 0, 0, 255], ]; for case in cases {