mirror of
https://github.com/lcdr/lu_packets.git
synced 2026-01-06 00:50:29 -06:00
Add support for simple physics component
This commit is contained in:
@@ -22,6 +22,7 @@ use lu_packets::{
|
||||
phantom_physics::{PhantomPhysicsConstruction, PhantomPhysicsSerialization},
|
||||
player_forced_movement::{PlayerForcedMovementConstruction, PlayerForcedMovementSerialization},
|
||||
possession_control::{PossessionControlConstruction, PossessionControlSerialization},
|
||||
simple_physics::{SimplePhysicsConstruction, SimplePhysicsSerialization},
|
||||
skill::SkillConstruction,
|
||||
},
|
||||
world::Lot,
|
||||
@@ -33,7 +34,7 @@ use zip::{ZipArchive, read::ZipFile};
|
||||
|
||||
static mut PRINT_PACKETS: bool = false;
|
||||
|
||||
const COMP_ORDER : [u32; 8] = [1, 40, 7, 4, 17, 9, 2, 107];
|
||||
const COMP_ORDER : [u32; 9] = [1, 3, 40, 7, 4, 17, 9, 2, 107];
|
||||
|
||||
struct Cdclient {
|
||||
conn: Connection,
|
||||
@@ -87,6 +88,9 @@ impl ReplicaContext for ZipContext<'_> {
|
||||
2 => {
|
||||
constrs.push(|x| Ok(Box::new(FxConstruction::deserialize(x)?)));
|
||||
}
|
||||
3 => {
|
||||
constrs.push(|x| Ok(Box::new(SimplePhysicsConstruction::deserialize(x)?)));
|
||||
}
|
||||
4 => {
|
||||
constrs.push(|x| Ok(Box::new(PossessionControlConstruction::deserialize(x)?)));
|
||||
constrs.push(|x| Ok(Box::new(LevelProgressionConstruction::deserialize(x)?)));
|
||||
@@ -109,7 +113,7 @@ impl ReplicaContext for ZipContext<'_> {
|
||||
107 => {
|
||||
constrs.push(|x| Ok(Box::new(BbbConstruction::deserialize(x)?)));
|
||||
}
|
||||
55 | 68 => {},
|
||||
55 | 56 | 68 => {},
|
||||
x => panic!("{}", x),
|
||||
}
|
||||
}
|
||||
@@ -128,6 +132,9 @@ impl ReplicaContext for ZipContext<'_> {
|
||||
1 => {
|
||||
sers.push(|x| Ok(Box::new(ControllablePhysicsSerialization::deserialize(x)?)));
|
||||
}
|
||||
3 => {
|
||||
sers.push(|x| Ok(Box::new(SimplePhysicsSerialization::deserialize(x)?)));
|
||||
}
|
||||
4 => {
|
||||
sers.push(|x| Ok(Box::new(PossessionControlSerialization::deserialize(x)?)));
|
||||
sers.push(|x| Ok(Box::new(LevelProgressionSerialization::deserialize(x)?)));
|
||||
@@ -146,7 +153,7 @@ impl ReplicaContext for ZipContext<'_> {
|
||||
107 => {
|
||||
sers.push(|x| Ok(Box::new(BbbSerialization::deserialize(x)?)));
|
||||
}
|
||||
2 | 9 | 55 | 68 => {},
|
||||
2 | 9 | 55 | 56 | 68 => {},
|
||||
x => panic!("{}", x),
|
||||
}
|
||||
}
|
||||
@@ -252,7 +259,9 @@ fn parse(path: &Path, cdclient: &mut Cdclient) -> Res<usize> {
|
||||
&& !file.name().contains("[1564]")
|
||||
&& !file.name().contains("[1647]")
|
||||
&& !file.name().contains("[1648]"))
|
||||
|| (file.name().contains("[24]") && !file.name().contains("(5958)"))
|
||||
|| (file.name().contains("[24]")
|
||||
&& !file.name().contains("(5958)")
|
||||
&& !file.name().contains("(8304)"))
|
||||
|| file.name().contains("[27]")
|
||||
{
|
||||
let mut ctx = ZipContext { zip: file, lots: &mut lots, cdclient, assert_fully_read: true };
|
||||
|
||||
@@ -9,6 +9,7 @@ pub mod level_progression;
|
||||
pub mod phantom_physics;
|
||||
pub mod player_forced_movement;
|
||||
pub mod possession_control;
|
||||
pub mod simple_physics;
|
||||
pub mod skill;
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
@@ -4,14 +4,9 @@ use endio::{Deserialize, Serialize};
|
||||
use endio_bit::BEBitWriter;
|
||||
use lu_packets_derive::{BitVariantTests, ReplicaSerde};
|
||||
|
||||
use crate::world::{Vector3, Quaternion};
|
||||
use crate::world::Vector3;
|
||||
use super::{ComponentConstruction, ComponentSerialization};
|
||||
|
||||
#[derive(Debug, PartialEq, ReplicaSerde)]
|
||||
pub struct PositionRotationInfo {
|
||||
pub position: Vector3,
|
||||
pub rotation: Quaternion,
|
||||
}
|
||||
use super::simple_physics::PositionRotationInfo;
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[repr(u32)]
|
||||
|
||||
102
src/raknet/client/replica/simple_physics.rs
Normal file
102
src/raknet/client/replica/simple_physics.rs
Normal file
@@ -0,0 +1,102 @@
|
||||
use std::io::{Read, Result as Res, Write};
|
||||
|
||||
use endio::{Deserialize, LE, LERead, LEWrite, Serialize};
|
||||
use endio_bit::{BEBitReader, BEBitWriter};
|
||||
use lu_packets_derive::{BitVariantTests, ReplicaSerde};
|
||||
|
||||
use crate::world::{Vector3, Quaternion};
|
||||
use super::{ReplicaD, ReplicaS, ComponentConstruction, ComponentSerialization};
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[repr(u32)]
|
||||
pub enum ClimbingProperty {
|
||||
Ladder = 1,
|
||||
ClimbWall,
|
||||
ClimbWallStick,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, ReplicaSerde)]
|
||||
pub struct VelocityInfo {
|
||||
pub linear_velocity: Vector3,
|
||||
pub angular_velocity: Vector3,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[repr(u32)]
|
||||
pub enum MotionType {
|
||||
Dynamic = 1,
|
||||
SphereInertia,
|
||||
BoxInertia,
|
||||
Keyframed,
|
||||
Fixed,
|
||||
ThinBoxInertia,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, ReplicaSerde)]
|
||||
pub struct PositionRotationInfo {
|
||||
pub position: Vector3,
|
||||
pub rotation: Quaternion,
|
||||
}
|
||||
|
||||
#[derive(BitVariantTests, Debug, PartialEq)]
|
||||
pub struct SimplePhysicsConstruction {
|
||||
pub climbing_property: Option<ClimbingProperty>,
|
||||
pub velocity_info: Option<VelocityInfo>,
|
||||
pub motion_type: Option<MotionType>,
|
||||
pub position_rotation_info: Option<PositionRotationInfo>,
|
||||
}
|
||||
|
||||
impl<R: Read> Deserialize<LE, BEBitReader<R>> for SimplePhysicsConstruction {
|
||||
fn deserialize(reader: &mut BEBitReader<R>) -> Res<Self> {
|
||||
let is_climbable = reader.read_bit()?;
|
||||
let climbing_property = if is_climbable {
|
||||
Some(LERead::read(reader)?)
|
||||
} else {
|
||||
let prop: u32 = LERead::read(reader)?;
|
||||
assert_eq!(prop, 0);
|
||||
None
|
||||
};
|
||||
let velocity_info = ReplicaD::deserialize(reader)?;
|
||||
let motion_type = ReplicaD::deserialize(reader)?;
|
||||
let position_rotation_info = ReplicaD::deserialize(reader)?;
|
||||
Ok(Self {
|
||||
climbing_property,
|
||||
velocity_info,
|
||||
motion_type,
|
||||
position_rotation_info,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, W: Write> Serialize<LE, BEBitWriter<W>> for &'a SimplePhysicsConstruction {
|
||||
fn serialize(self, writer: &mut BEBitWriter<W>) -> Res<()> {
|
||||
writer.write_bit(self.climbing_property.is_some())?;
|
||||
match &self.climbing_property {
|
||||
Some(x) => LEWrite::write(writer, x)?,
|
||||
None => LEWrite::write(writer, 0u32)?,
|
||||
}
|
||||
ReplicaS::serialize(&self.velocity_info, writer)?;
|
||||
ReplicaS::serialize(&self.motion_type, writer)?;
|
||||
ReplicaS::serialize(&self.position_rotation_info, writer)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(BitVariantTests, Debug, PartialEq, ReplicaSerde)]
|
||||
pub struct SimplePhysicsSerialization {
|
||||
pub velocity_info: Option<VelocityInfo>,
|
||||
pub motion_type: Option<MotionType>,
|
||||
pub position_rotation_info: Option<PositionRotationInfo>,
|
||||
}
|
||||
|
||||
impl ComponentConstruction for SimplePhysicsConstruction {
|
||||
fn ser(&self, writer: &mut BEBitWriter<Vec<u8>>) -> Res<()> {
|
||||
Serialize::serialize(self, writer)
|
||||
}
|
||||
}
|
||||
|
||||
impl ComponentSerialization for SimplePhysicsSerialization {
|
||||
fn ser(&self, writer: &mut BEBitWriter<Vec<u8>>) -> Res<()> {
|
||||
Serialize::serialize(self, writer)
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -2,11 +2,11 @@ PhantomPhysicsConstruction {
|
||||
position_rotation_info: Some(
|
||||
PositionRotationInfo {
|
||||
position: Vector3 {
|
||||
x: -106.229836,
|
||||
y: 361.1013,
|
||||
z: -125.43403,
|
||||
x: 0.0,
|
||||
y: 1.0,
|
||||
z: 2.0,
|
||||
},
|
||||
rotation: Quaternion {
|
||||
rotation: crate::world::Quaternion {
|
||||
x: -0.703031,
|
||||
y: 0.07643375,
|
||||
z: 0.07637292,
|
||||
@@ -20,12 +20,17 @@ PhantomPhysicsConstruction {
|
||||
PhysicsEffectInfo {
|
||||
effect_type: PhysicsEffectType::Push,
|
||||
amount: 35.0,
|
||||
distance_info: None,
|
||||
distance_info: Some(
|
||||
DistanceInfo {
|
||||
min_distance: 3.0,
|
||||
max_distance: 4.0,
|
||||
}
|
||||
),
|
||||
impulse_velocity: Some(
|
||||
Vector3 {
|
||||
x: 28.299416,
|
||||
y: -19.879036,
|
||||
z: -5.3820977,
|
||||
x: 5.0,
|
||||
y: 6.0,
|
||||
z: 7.0,
|
||||
},
|
||||
),
|
||||
},
|
||||
|
||||
BIN
src/raknet/client/replica/tests/SimplePhysicsConstruction.bin
Normal file
BIN
src/raknet/client/replica/tests/SimplePhysicsConstruction.bin
Normal file
Binary file not shown.
35
src/raknet/client/replica/tests/SimplePhysicsConstruction.rs
Normal file
35
src/raknet/client/replica/tests/SimplePhysicsConstruction.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
SimplePhysicsConstruction {
|
||||
climbing_property: Some(ClimbingProperty::ClimbWallStick),
|
||||
velocity_info: Some(
|
||||
VelocityInfo {
|
||||
linear_velocity: Vector3 {
|
||||
x: 0.0,
|
||||
y: 1.0,
|
||||
z: 2.0,
|
||||
},
|
||||
angular_velocity: Vector3 {
|
||||
x: 3.0,
|
||||
y: 4.0,
|
||||
z: 5.0,
|
||||
},
|
||||
},
|
||||
),
|
||||
motion_type: Some(
|
||||
MotionType::Fixed,
|
||||
),
|
||||
position_rotation_info: Some(
|
||||
PositionRotationInfo {
|
||||
position: Vector3 {
|
||||
x: 6.0,
|
||||
y: 7.0,
|
||||
z: 8.0,
|
||||
},
|
||||
rotation: Quaternion {
|
||||
x: 0.0,
|
||||
y: 0.53361946,
|
||||
z: 0.0,
|
||||
w: 0.8457247,
|
||||
},
|
||||
},
|
||||
),
|
||||
}
|
||||
BIN
src/raknet/client/replica/tests/SimplePhysicsSerialization.bin
Normal file
BIN
src/raknet/client/replica/tests/SimplePhysicsSerialization.bin
Normal file
Binary file not shown.
@@ -0,0 +1,34 @@
|
||||
SimplePhysicsSerialization {
|
||||
velocity_info: Some(
|
||||
VelocityInfo {
|
||||
linear_velocity: Vector3 {
|
||||
x: 0.0,
|
||||
y: 1.0,
|
||||
z: 2.0,
|
||||
},
|
||||
angular_velocity: Vector3 {
|
||||
x: 3.0,
|
||||
y: 4.0,
|
||||
z: 5.0,
|
||||
},
|
||||
},
|
||||
),
|
||||
motion_type: Some(
|
||||
MotionType::Fixed,
|
||||
),
|
||||
position_rotation_info: Some(
|
||||
PositionRotationInfo {
|
||||
position: Vector3 {
|
||||
x: 6.0,
|
||||
y: 7.0,
|
||||
z: 8.0,
|
||||
},
|
||||
rotation: Quaternion {
|
||||
x: 0.0,
|
||||
y: 0.53361946,
|
||||
z: 0.0,
|
||||
w: 0.8457247,
|
||||
},
|
||||
},
|
||||
),
|
||||
}
|
||||
Reference in New Issue
Block a user