Skip to content

Commit

Permalink
Tweak messaging a bit, correct deserialization when having people in …
Browse files Browse the repository at this point in the history
…your lobby (sponsored by @ClayAmore)
  • Loading branch information
vswarte committed Aug 24, 2024
1 parent 2b86cb2 commit 52c5c9a
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 97 deletions.
2 changes: 2 additions & 0 deletions crates/message/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub(crate) mod request;
pub(crate) mod response;
pub(crate) mod push;
pub(crate) mod payload;
pub(crate) mod log;

pub use player::*;
pub use shared::*;
Expand All @@ -37,3 +38,4 @@ pub use request::*;
pub use response::*;
pub use push::*;
pub use payload::*;
pub use log::*;
65 changes: 65 additions & 0 deletions crates/message/src/log.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use serde::{Deserialize, Serialize};

use crate::Location;

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RequestUseItemLogParams {
pub used_items: Vec<RequestUseItemLogParamsEntry>,
pub location: Location,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RequestUseItemLogParamsEntry {
pub item_id: u32,
pub times_used: u32,
pub unk3: u32,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RequestGetItemLogParams {
pub acquired_items: Vec<RequestGetItemLogParamsEntry>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RequestGetItemLogParamsEntry {
pub location: Location,
pub item_category: u32,
pub item_id: u32,
pub quantity: u32,
pub unk1: u32,
pub unk2: u32,
pub unk3: u32,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RequestKillEnemyLogParams {
pub killed_enemies: Vec<RequestKillEnemyLogParamsEntry>,
pub location: Location,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RequestKillEnemyLogParamsEntry {
pub npc_param: u32,
pub killed_count: u32,
}
#[cfg(test)]
mod test {
use waygate_wire::deserialize;
use crate::RequestUseItemLogParams;

#[test]
fn deserialize_use_item_log() {
let deserialized: RequestUseItemLogParams = deserialize(
include_bytes!("../test/data/RequestUseItemLog.bin"),
).unwrap();

assert_eq!(deserialized.used_items.len(), 1);
assert_eq!(deserialized.used_items[0].item_id, 101);
assert_eq!(deserialized.used_items[0].times_used, 1);
assert_eq!(deserialized.used_items[0].unk3, 1);
assert_eq!(deserialized.location.map, 60423600);
assert_eq!(deserialized.location.x, -45.939575);
assert_eq!(deserialized.location.y, 92.36392);
assert_eq!(deserialized.location.z, 79.65545);
}
}
114 changes: 21 additions & 93 deletions crates/message/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RequestUpdatePlayerStatusParams {
pub unk1: u32,
pub map_id: u32,
pub play_region: u32,
pub unk2: u32,
pub death_count: u32,
pub total_summon_count: u32,
Expand Down Expand Up @@ -57,20 +57,13 @@ pub struct CharacterData {
pub max_reinforce_level: u32,
pub unk20: u32,

// This is cursed. Apparently serde only takes u8 arrays of size n % 8
//pub unk21: [u8; 0x27],
pub unk21: [u8; 0x20],
pub wtf1: u8,
pub wtf2: u8,
pub wtf3: u8,
pub wtf4: u8,
pub wtf5: u8,
pub wtf6: u8,
pub wtf7: u8,
pub unk21: [u8; 0x1b],
pub unk_vec: Vec<u32>,
pub unk22: u32,

pub password: String,
pub group_passwords: Vec<String>,
pub unk22: u16,
pub unk23: u16,
pub unk24: u8,
pub unk25: u8,
pub sites_of_grace: Vec<SiteOfGrace>,
Expand Down Expand Up @@ -106,12 +99,12 @@ pub struct CharacterDataAttributes {

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CharacterDataAttack {
pub right_armament_primary: u32,
pub right_armament_secondary: u32,
pub right_armament_tertiary: u32,
pub left_armament_primary: u32,
pub left_armament_secondary: u32,
pub left_armament_tertiary: u32,
pub right_armament_primary: i32,
pub right_armament_secondary: i32,
pub right_armament_tertiary: i32,
pub left_armament_primary: i32,
pub left_armament_secondary: i32,
pub left_armament_tertiary: i32,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -154,73 +147,30 @@ pub struct SiteOfGrace {

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct EquippedWeapon {
pub weapon: u32,
pub ash_of_war: u32,
pub weapon: i32,
pub ash_of_war: i32,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct EquippedProtector {
pub protector: u32,
pub unk: u32,
pub protector: i32,
pub unk: i32,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CharacterEquipment {
pub weapons_left_hand: Vec<EquippedWeapon>,
pub weapons_right_hand: Vec<EquippedWeapon>,

pub head: EquippedProtector,
pub chest: EquippedProtector,
pub arms: EquippedProtector,
pub legs: EquippedProtector,

pub accessories: Vec<u32>,
pub quickslots: Vec<u32>,
pub menuslots: Vec<u32>,
pub arrows: Vec<u32>,
pub bolts: Vec<u32>,
pub spells: Vec<u32>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RequestUseItemLogParams {
pub used_items: Vec<RequestUseItemLogParamsEntry>,
pub location: Location,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RequestUseItemLogParamsEntry {
pub item_id: u32,
pub times_used: u32,
pub unk3: u32,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RequestGetItemLogParams {
pub acquired_items: Vec<RequestGetItemLogParamsEntry>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RequestGetItemLogParamsEntry {
pub location: Location,
pub item_category: u32,
pub item_id: u32,
pub quantity: u32,
pub unk1: u32,
pub unk2: u32,
pub unk3: u32,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RequestKillEnemyLogParams {
pub killed_enemies: Vec<RequestKillEnemyLogParamsEntry>,
pub location: Location,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RequestKillEnemyLogParamsEntry {
pub npc_param: u32,
pub killed_count: u32,
pub accessories: Vec<i32>,
pub quickslots: Vec<i32>,
pub pouchslots: Vec<i32>,
pub arrows: Vec<i32>,
pub bolts: Vec<i32>,
pub spells: Vec<i32>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand All @@ -232,25 +182,3 @@ pub struct RequestJoinMultiplayParams {
pub unk5: u32,
pub unk6: u32,
}

#[cfg(test)]
mod test {
use waygate_wire::deserialize;
use crate::{ObjectIdentifier, RequestUpdateSignParams, RequestUseItemLogParams};

#[test]
fn deserialize_use_item_log() {
let deserialized: RequestUseItemLogParams = deserialize(
include_bytes!("../test/data/RequestUseItemLog.bin"),
).unwrap();

assert_eq!(deserialized.used_items.len(), 1);
assert_eq!(deserialized.used_items[0].item_id, 101);
assert_eq!(deserialized.used_items[0].times_used, 1);
assert_eq!(deserialized.used_items[0].unk3, 1);
assert_eq!(deserialized.location.map, 60423600);
assert_eq!(deserialized.location.x, -45.939575);
assert_eq!(deserialized.location.y, 92.36392);
assert_eq!(deserialized.location.z, 79.65545);
}
}
6 changes: 3 additions & 3 deletions crates/message/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ pub enum RequestParams {
DieLog,
UseMagicLog,
UseGestureLog,
UseItemLog(Box<player::RequestUseItemLogParams>),
UseItemLog(Box<log::RequestUseItemLogParams>),
PurchaseItemLog,
GetItemLog(Box<player::RequestGetItemLogParams>),
GetItemLog(Box<log::RequestGetItemLogParams>),
DropItemLog,
LeaveItemLog,
SaleItemLog,
CreateItemLog,
SummonBuddyLog,
KillEnemyLog(Box<player::RequestKillEnemyLogParams>),
KillEnemyLog(Box<log::RequestKillEnemyLogParams>),
KillBossLog,
GlobalEventLog,
DiscoverMapPointLog,
Expand Down
1 change: 0 additions & 1 deletion crates/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,3 @@ async fn handle_connection(
client.serve().await?;
}
}

0 comments on commit 52c5c9a

Please sign in to comment.