From 431b7cffce907eb61a3c6f4123abc689938d430e Mon Sep 17 00:00:00 2001 From: lcdr Date: Tue, 2 Mar 2021 14:21:24 +0100 Subject: [PATCH] Add support for mutable model behavior component --- examples/capture_parser/main.rs | 47 ++++++++---- examples/capture_parser/zip_context.rs | 7 +- src/raknet/client/replica/mod.rs | 1 + .../client/replica/mutable_model_behavior.rs | 71 ++++++++++++++++++ .../MutableModelBehaviorConstruction.bin | Bin 0 -> 53 bytes .../tests/MutableModelBehaviorConstruction.rs | 25 ++++++ .../MutableModelBehaviorSerialization.bin | Bin 0 -> 37 bytes .../MutableModelBehaviorSerialization.rs | 21 ++++++ 8 files changed, 157 insertions(+), 15 deletions(-) create mode 100644 src/raknet/client/replica/mutable_model_behavior.rs create mode 100644 src/raknet/client/replica/tests/MutableModelBehaviorConstruction.bin create mode 100644 src/raknet/client/replica/tests/MutableModelBehaviorConstruction.rs create mode 100644 src/raknet/client/replica/tests/MutableModelBehaviorSerialization.bin create mode 100644 src/raknet/client/replica/tests/MutableModelBehaviorSerialization.rs diff --git a/examples/capture_parser/main.rs b/examples/capture_parser/main.rs index 71f874b..fc7a994 100644 --- a/examples/capture_parser/main.rs +++ b/examples/capture_parser/main.rs @@ -20,7 +20,7 @@ use self::zip_context::ZipContext; static mut PRINT_PACKETS: bool = false; -const COMP_ORDER : [u32; 27] = [108, 1, 3, 40, 98, 7, 23, 110, 109, 106, 4, 26, 17, 5, 9, 60, 11, 48, 25, 16, 100, 39, 6, 49, 2, 44, 107]; +const COMP_ORDER : [u32; 28] = [108, 1, 3, 40, 98, 7, 23, 110, 109, 106, 4, 26, 17, 5, 9, 60, 11, 48, 25, 16, 100, 39, 42, 6, 49, 2, 44, 107]; pub struct Cdclient { conn: Connection, @@ -31,28 +31,29 @@ impl Cdclient { fn get_comps(&mut self, lot: Lot) -> &Vec { if !self.comp_cache.contains_key(&lot) { let mut stmt = self.conn.prepare("select component_type from componentsregistry where id = ?").unwrap(); - let rows = stmt.query_map(params![lot], |row| row.get(0)).unwrap(); + let mut rows: Vec<_> = stmt.query_map(params![lot], |row| row.get(0)).unwrap().map(|x| x.unwrap()).collect(); + rows.sort_by_key(|x| COMP_ORDER.iter().position(|y| y == x).unwrap_or(usize::MAX)); let mut comps = vec![]; for row in rows { - let value = row.unwrap(); - comps.push(value); - // special case: implied components - match value { + // special case: utter bodge + match row { 2 => { comps.push(44); } 4 => { comps.push(110); comps.push(109); comps.push(106); } 7 => { comps.push(98); } - 23 => { comps.push(7); } - 48 => { comps.push(7); } + 23 | 48 => { + if !comps.contains(&7) { + comps.push(7); + } + } _ => {}, } + comps.push(row); } // special case: utter bodge if comps.contains(&26) { - comps.swap_remove(comps.iter().position(|&x| x == 11).unwrap()); + comps.remove(comps.iter().position(|&x| x == 11).unwrap()); + comps.remove(comps.iter().position(|&x| x == 42).unwrap()); } - comps.sort(); - comps.dedup(); - comps.sort_by_key(|x| COMP_ORDER.iter().position(|y| y == x).unwrap_or(usize::MAX)); dbg!(&comps); self.comp_cache.insert(lot, comps); } @@ -159,20 +160,31 @@ fn parse(path: &Path, cdclient: &mut Cdclient) -> Res { && !file.name().contains("(2365)") && !file.name().contains("(4734)") && !file.name().contains("(4930)") + && !file.name().contains("(4955)") + && !file.name().contains("(4967)") + && !file.name().contains("(4990)") && !file.name().contains("(5635)") && !file.name().contains("(5651)") && !file.name().contains("(5652)") + && !file.name().contains("(5903)") + && !file.name().contains("(5904)") && !file.name().contains("(5958)") && !file.name().contains("(6007)") && !file.name().contains("(6010)") + && !file.name().contains("(6097)") && !file.name().contains("(6209)") && !file.name().contains("(6267)") && !file.name().contains("(6289)") + && !file.name().contains("(6290)") && !file.name().contains("(6319)") + && !file.name().contains("(7001)") && !file.name().contains("(7282)") && !file.name().contains("(7796)") && !file.name().contains("(8304)") + && !file.name().contains("(9741)") && !file.name().contains("(10042)") + && !file.name().contains("(10046)") + && !file.name().contains("(10055)") && !file.name().contains("(10097)") && !file.name().contains("(13773)") && !file.name().contains("(14376)") @@ -180,8 +192,17 @@ fn parse(path: &Path, cdclient: &mut Cdclient) -> Res { && !file.name().contains("(14449)") && !file.name().contains("(14476)") && !file.name().contains("(14477)") + && !file.name().contains("(14505)") && !file.name().contains("(14510)") - && !file.name().contains("(14539)")) + && !file.name().contains("(14539)") + && !file.name().contains("(14540)") + && !file.name().contains("(14541)") + && !file.name().contains("(14542)") + && !file.name().contains("(14543)") + && !file.name().contains("(14544)") + && !file.name().contains("(14545)") + && !file.name().contains("(14546)") + && !file.name().contains("(14547)")) || file.name().contains("[27]") { let mut ctx = ZipContext { zip: file, lots: &mut lots, cdclient, assert_fully_read: true }; diff --git a/examples/capture_parser/zip_context.rs b/examples/capture_parser/zip_context.rs index e5bfc7d..725f66d 100644 --- a/examples/capture_parser/zip_context.rs +++ b/examples/capture_parser/zip_context.rs @@ -19,6 +19,7 @@ use lu_packets::{ item::{ItemConstruction, ItemSerialization}, level_progression::{LevelProgressionConstruction, LevelProgressionSerialization}, moving_platform::{MovingPlatformConstruction, MovingPlatformSerialization}, + mutable_model_behavior::{MutableModelBehaviorConstruction, MutableModelBehaviorSerialization}, phantom_physics::{PhantomPhysicsConstruction, PhantomPhysicsSerialization}, player_forced_movement::{PlayerForcedMovementConstruction, PlayerForcedMovementSerialization}, pet::{PetConstruction, PetSerialization}, @@ -76,6 +77,7 @@ impl ReplicaContext for ZipContext<'_> { 26 => { constrs.push(|x| Ok(Box::new(PetConstruction::deserialize(x)?))); } 39 => { constrs.push(|x| Ok(Box::new(ScriptedActivityConstruction::deserialize(x)?))); } 40 => { constrs.push(|x| Ok(Box::new(PhantomPhysicsConstruction::deserialize(x)?))); } + 42 => { constrs.push(|x| Ok(Box::new(MutableModelBehaviorConstruction::deserialize(x)?))); } 44 => { constrs.push(|x| Ok(Box::new(FxConstruction::deserialize(x)?))); } 48 => { constrs.push(|x| Ok(Box::new(QuickbuildConstruction::deserialize(x)?))); } 49 => { constrs.push(|x| Ok(Box::new(SwitchConstruction::deserialize(x)?))); } @@ -87,7 +89,7 @@ impl ReplicaContext for ZipContext<'_> { 108 => { constrs.push(|x| Ok(Box::new(PossessableConstruction::deserialize(x)?))); } 109 => { constrs.push(|x| Ok(Box::new(LevelProgressionConstruction::deserialize(x)?))); } 110 => { constrs.push(|x| Ok(Box::new(PossessionControlConstruction::deserialize(x)?))); } - 2 | 12 | 27 | 31 | 35 | 36 | 42 | 45 | 55 | 56 | 64 | 68 | 95 | 73 | 104 | 113 | 114 => {}, + 2 | 12 | 27 | 31 | 35 | 36 | 43 | 45 | 55 | 56 | 57 | 64 | 65 | 67 | 68 | 73 | 78 | 95 | 104 | 113 | 114 => {}, x => panic!("{}", x), } } @@ -116,6 +118,7 @@ impl ReplicaContext for ZipContext<'_> { 26 => { sers.push(|x| Ok(Box::new(PetSerialization::deserialize(x)?))); } 39 => { sers.push(|x| Ok(Box::new(ScriptedActivitySerialization::deserialize(x)?))); } 40 => { sers.push(|x| Ok(Box::new(PhantomPhysicsSerialization::deserialize(x)?))); } + 42 => { sers.push(|x| Ok(Box::new(MutableModelBehaviorSerialization::deserialize(x)?))); } 48 => { sers.push(|x| Ok(Box::new(QuickbuildSerialization::deserialize(x)?))); } 49 => { sers.push(|x| Ok(Box::new(SwitchSerialization::deserialize(x)?))); } 60 => { sers.push(|x| Ok(Box::new(BaseCombatAiSerialization::deserialize(x)?))); } @@ -125,7 +128,7 @@ impl ReplicaContext for ZipContext<'_> { 108 => { sers.push(|x| Ok(Box::new(PossessableSerialization::deserialize(x)?))); } 109 => { sers.push(|x| Ok(Box::new(LevelProgressionSerialization::deserialize(x)?))); } 110 => { sers.push(|x| Ok(Box::new(PossessionControlSerialization::deserialize(x)?))); } - 2 | 5 | 9 | 12 | 27 | 31 | 35 | 36 | 42 | 44 | 45 | 55 | 56 | 64 | 68 | 73 | 95 | 98 | 104 | 113 | 114 => {}, + 2 | 5 | 9 | 12 | 27 | 31 | 35 | 36 | 43 | 44 | 45 | 55 | 56 | 57 | 64 | 65 | 67 | 68 | 73 | 78 | 95 | 98 | 104 | 113 | 114 => {}, x => panic!("{}", x), } } diff --git a/src/raknet/client/replica/mod.rs b/src/raknet/client/replica/mod.rs index e107304..788e6b2 100644 --- a/src/raknet/client/replica/mod.rs +++ b/src/raknet/client/replica/mod.rs @@ -11,6 +11,7 @@ pub mod fx; pub mod inventory; pub mod item; pub mod level_progression; +pub mod mutable_model_behavior; pub mod moving_platform; pub mod phantom_physics; pub mod player_forced_movement; diff --git a/src/raknet/client/replica/mutable_model_behavior.rs b/src/raknet/client/replica/mutable_model_behavior.rs new file mode 100644 index 0000000..7c6005f --- /dev/null +++ b/src/raknet/client/replica/mutable_model_behavior.rs @@ -0,0 +1,71 @@ +use std::io::Result as Res; + +use endio::{Deserialize, Serialize}; +use endio_bit::BEBitWriter; +use lu_packets_derive::{BitVariantTests, ReplicaSerde}; + +use crate::common::ObjId; +use crate::world::{Vector3, Quaternion}; +use super::{ComponentConstruction, ComponentSerialization}; + +#[derive(Debug, Deserialize, PartialEq, Serialize)] +#[repr(i32)] +pub enum PhysicsBehaviorType { + /// todo: option + Invalid = -1, + Ground, + Flying, + Standard, + Dynamic, +} + +#[derive(Debug, PartialEq, ReplicaSerde)] +pub struct ModelBehaviorInfo { + pub is_pickable: bool, + pub physics_behavior_type: PhysicsBehaviorType, + pub original_position: Vector3, + pub original_rotation: Quaternion, +} + +#[derive(Debug, PartialEq, ReplicaSerde)] +pub struct ModelEditingInfo { + pub old_object_id: ObjId, + pub player_editing_model: ObjId, +} + +#[derive(Debug, PartialEq, ReplicaSerde)] +pub struct MutableModelBehaviorConstructionInfo { + pub behavior_count: u32, + pub is_paused: bool, + pub model_editing_info: Option, +} + +#[derive(BitVariantTests, Debug, PartialEq, ReplicaSerde)] +pub struct MutableModelBehaviorConstruction { + pub model_behavior_info: Option, + pub mutable_model_behavior_construction_info: Option, +} + +impl ComponentConstruction for MutableModelBehaviorConstruction { + fn ser(&self, writer: &mut BEBitWriter>) -> Res<()> { + self.serialize(writer) + } +} + +#[derive(Debug, PartialEq, ReplicaSerde)] +pub struct MutableModelBehaviorSerializationInfo { + pub behavior_count: u32, + pub is_paused: bool, +} + +#[derive(BitVariantTests, Debug, PartialEq, ReplicaSerde)] +pub struct MutableModelBehaviorSerialization { + pub model_behavior_info: Option, + pub mutable_model_behavior_serialization_info: Option, +} + +impl ComponentSerialization for MutableModelBehaviorSerialization { + fn ser(&self, writer: &mut BEBitWriter>) -> Res<()> { + self.serialize(writer) + } +} diff --git a/src/raknet/client/replica/tests/MutableModelBehaviorConstruction.bin b/src/raknet/client/replica/tests/MutableModelBehaviorConstruction.bin new file mode 100644 index 0000000000000000000000000000000000000000..87870288d33a5cd7b79f1c1f100630b9c7b88683 GIT binary patch literal 53 tcmX@mzyJga{0A5q1b_&L6@XX+hz)?)LO>BHE4lO7I}0G)co0H2007XE3Ecny literal 0 HcmV?d00001 diff --git a/src/raknet/client/replica/tests/MutableModelBehaviorConstruction.rs b/src/raknet/client/replica/tests/MutableModelBehaviorConstruction.rs new file mode 100644 index 0000000..db820bc --- /dev/null +++ b/src/raknet/client/replica/tests/MutableModelBehaviorConstruction.rs @@ -0,0 +1,25 @@ +MutableModelBehaviorConstruction { + model_behavior_info: Some(ModelBehaviorInfo { + is_pickable: true, + physics_behavior_type: PhysicsBehaviorType::Standard, + original_position: Vector3 { + x: 1.0, + y: 2.0, + z: 3.0, + }, + original_rotation: Quaternion { + x: 4.0, + y: 5.0, + z: 6.0, + w: 7.0, + }, + }), + mutable_model_behavior_construction_info: Some(MutableModelBehaviorConstructionInfo { + behavior_count: 8, + is_paused: true, + model_editing_info: Some(ModelEditingInfo { + old_object_id: 1152921507960010807, + player_editing_model: 1152921507960010808, + }), + }), +} diff --git a/src/raknet/client/replica/tests/MutableModelBehaviorSerialization.bin b/src/raknet/client/replica/tests/MutableModelBehaviorSerialization.bin new file mode 100644 index 0000000000000000000000000000000000000000..3622d7805d5b1802d4fecbbbcd26dbcda0be9b72 GIT binary patch literal 37 icmX@mzyJga{0A5q1b_&L6@XX+hz)?)LO>BHD*ymlyaRy% literal 0 HcmV?d00001 diff --git a/src/raknet/client/replica/tests/MutableModelBehaviorSerialization.rs b/src/raknet/client/replica/tests/MutableModelBehaviorSerialization.rs new file mode 100644 index 0000000..516bb84 --- /dev/null +++ b/src/raknet/client/replica/tests/MutableModelBehaviorSerialization.rs @@ -0,0 +1,21 @@ +MutableModelBehaviorSerialization { + model_behavior_info: Some(ModelBehaviorInfo { + is_pickable: true, + physics_behavior_type: PhysicsBehaviorType::Standard, + original_position: Vector3 { + x: 1.0, + y: 2.0, + z: 3.0, + }, + original_rotation: Quaternion { + x: 4.0, + y: 5.0, + z: 6.0, + w: 7.0, + }, + }), + mutable_model_behavior_serialization_info: Some(MutableModelBehaviorSerializationInfo { + behavior_count: 8, + is_paused: true, + }), +}