Add support for mutable model behavior component

This commit is contained in:
lcdr
2021-03-02 14:21:24 +01:00
parent e68a233a98
commit 431b7cffce
8 changed files with 157 additions and 15 deletions

View File

@@ -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<u32> {
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<usize> {
&& !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<usize> {
&& !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 };

View File

@@ -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),
}
}

View File

@@ -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;

View File

@@ -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<ModelEditingInfo>,
}
#[derive(BitVariantTests, Debug, PartialEq, ReplicaSerde)]
pub struct MutableModelBehaviorConstruction {
pub model_behavior_info: Option<ModelBehaviorInfo>,
pub mutable_model_behavior_construction_info: Option<MutableModelBehaviorConstructionInfo>,
}
impl ComponentConstruction for MutableModelBehaviorConstruction {
fn ser(&self, writer: &mut BEBitWriter<Vec<u8>>) -> 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<ModelBehaviorInfo>,
pub mutable_model_behavior_serialization_info: Option<MutableModelBehaviorSerializationInfo>,
}
impl ComponentSerialization for MutableModelBehaviorSerialization {
fn ser(&self, writer: &mut BEBitWriter<Vec<u8>>) -> Res<()> {
self.serialize(writer)
}
}

View File

@@ -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,
}),
}),
}

View File

@@ -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,
}),
}