From f48e2d232b867295b5116c6d4e74c902aa0409ac Mon Sep 17 00:00:00 2001 From: Maple Nebel Date: Tue, 28 Apr 2026 13:23:26 +0200 Subject: [PATCH] change how Any is deserialized --- rnex-core/src/rmc/structures/any.rs | 59 +++++++++++++++++++++-- rnex-core/src/rmc/structures/matchmake.rs | 4 +- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/rnex-core/src/rmc/structures/any.rs b/rnex-core/src/rmc/structures/any.rs index 0f531d8..53e12d5 100644 --- a/rnex-core/src/rmc/structures/any.rs +++ b/rnex-core/src/rmc/structures/any.rs @@ -1,3 +1,4 @@ +use log::warn; use rnex_core::rmc::structures::{Result, RmcSerialize}; use std::io::{Cursor, Read, Write}; use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions}; @@ -21,11 +22,23 @@ impl RmcSerialize for Any { fn deserialize(reader: &mut impl Read) -> Result { let name = String::deserialize(reader)?; - // also length ? - let _len2: u32 = reader.read_struct(IS_BIG_ENDIAN)?; let data = Vec::deserialize(reader)?; + let mut cursor = Cursor::new(&data); + // also length ? + let len2: u32 = cursor.read_struct(IS_BIG_ENDIAN)?; - Ok(Any { name, data }) + if len2 as usize != data.len().overflowing_sub(4).0 { + warn!( + "mismatched sizes on any: {} vs {}", + data.len().overflowing_sub(4).0, + len2 + ); + } + + Ok(Any { + name, + data: (&data[4..]).to_owned(), + }) } } @@ -43,3 +56,43 @@ impl Any { }); } } + +#[cfg(test)] +mod test { + use crate::rmc::structures::{ + any::Any, + matchmake::{Gathering, MatchmakeSession}, + }; + + #[test] + fn test() { + let sess = MatchmakeSession { + gathering: Gathering { + self_gid: 0, + owner_pid: 0, + host_pid: 0, + minimum_participants: 2, + maximum_participants: 2, + participant_policy: 98, + policy_argument: 0, + flags: 32, + state: 0, + description: "Doors Friend Invite".into(), + }, + gamemode: 0, + attributes: [2, 3, 0, 0, 0, 0].into(), + open_participation: false, + matchmake_system_type: 2, + application_buffer: [1, 2, 3].into(), + participation_count: 0, + progress_score: 0, + session_key: [].into(), + }; + + let any = Any::new(&sess).unwrap(); + + let sess2: MatchmakeSession = any.try_get().unwrap().unwrap(); + + assert_eq!(sess, sess2); + } +} diff --git a/rnex-core/src/rmc/structures/matchmake.rs b/rnex-core/src/rmc/structures/matchmake.rs index ffe4d7f..52af790 100644 --- a/rnex-core/src/rmc/structures/matchmake.rs +++ b/rnex-core/src/rmc/structures/matchmake.rs @@ -6,7 +6,7 @@ use rnex_core::rmc::structures::variant::Variant; use rnex_core::PID; // rmc structure -#[derive(RmcSerialize, Debug, Clone, Default)] +#[derive(RmcSerialize, Debug, Clone, Default, PartialEq)] #[rmc_struct(0)] pub struct Gathering { pub self_gid: u32, @@ -54,7 +54,7 @@ cfg_if! { pub system_password_enabled: bool, } } else { - #[derive(RmcSerialize, Debug, Clone, Default)] + #[derive(RmcSerialize, Debug, Clone, Default, PartialEq)] #[rmc_struct(0)] pub struct MatchmakeSession { //inherits from