Skip to content

Commit

Permalink
Remove incorrect decompressed_size from non compressed endless arrays
Browse files Browse the repository at this point in the history
Works on
#77, still needs a wowm
test to ensure no regressions.
  • Loading branch information
Gtker committed Oct 1, 2023
1 parent 009948f commit 58aa564
Show file tree
Hide file tree
Showing 19 changed files with 24 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ fn print_read_array(
}

print_size_before_variable(s, e, d.name());
s.wln(format!(
"current_size += 4; // {name}_decompressed_size: u32"
));

if array.compressed() {
s.wln(format!(
"current_size += 4; // {name}_decompressed_size: u32"
));
}

let use_decoder = array.compressed() || e.tags().compressed() && array.is_endless();
let loop_condition = if use_decoder {
Expand Down
1 change: 0 additions & 1 deletion wow_message_parser/tests/cmsg_test_endless_u8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ impl CMSG_TEST_ENDLESS_U8 {
c_string.len() + 1 // c_string: CString
+ 1 // b_u8: u8
};
current_size += 4; // endless_decompressed_size: u32
let mut endless = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
endless.push(crate::util::read_u8_le(&mut r)?);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ impl CMSG_WARDEN_DATA {
let mut current_size = {
0
};
current_size += 4; // encrypted_data_decompressed_size: u32
let mut encrypted_data = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
encrypted_data.push(crate::util::read_u8_le(&mut r)?);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ impl SMSG_DISPEL_FAILED {
8 // caster: Guid
+ 8 // target: Guid
};
current_size += 4; // spells_decompressed_size: u32
let mut spells = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
spells.push(crate::util::read_u32_le(&mut r)?);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ impl SMSG_SHOWTAXINODES {
+ 8 // guid: Guid
+ 4 // nearest_node: u32
};
current_size += 4; // nodes_decompressed_size: u32
let mut nodes = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
nodes.push(crate::util::read_u32_le(&mut r)?);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ impl SMSG_SPELL_COOLDOWN {
8 // guid: Guid
+ 1 // flags: u8
};
current_size += 4; // cooldowns_decompressed_size: u32
let mut cooldowns = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
cooldowns.push(SpellCooldownStatus::read(&mut r)?);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ impl SMSG_UPDATE_ACCOUNT_DATA {
4 // data_type: u32
+ 4 // decompressed_size: u32
};
current_size += 4; // compressed_data_decompressed_size: u32
let mut compressed_data = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
compressed_data.push(crate::util::read_u8_le(&mut r)?);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ impl SMSG_WARDEN_DATA {
let mut current_size = {
0
};
current_size += 4; // encrypted_data_decompressed_size: u32
let mut encrypted_data = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
encrypted_data.push(crate::util::read_u8_le(&mut r)?);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ impl CMSG_GUILD_BANK_SWAP_ITEMS {
8 // bank: Guid
+ 1 // source: CMSG_GUILD_BANK_SWAP_ITEMS_BankSwapSource
};
current_size += 4; // unknown5_decompressed_size: u32
let mut unknown5 = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
unknown5.push(crate::util::read_u8_le(&mut r)?);
Expand Down
1 change: 0 additions & 1 deletion wow_world_messages/src/world/tbc/smsg_inspect_talent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ impl SMSG_INSPECT_TALENT {
let mut current_size = {
crate::util::packed_guid_size(&player) // player: PackedGuid
};
current_size += 4; // talent_data_decompressed_size: u32
let mut talent_data = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
talent_data.push(crate::util::read_u8_le(&mut r)?);
Expand Down
1 change: 0 additions & 1 deletion wow_world_messages/src/world/vanilla/smsg_addon_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ impl SMSG_ADDON_INFO {
let mut current_size = {
0
};
current_size += 4; // addons_decompressed_size: u32
let mut addons = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
let a = Addon::read(&mut r)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ impl SMSG_COMPRESSED_MOVES {
let mut current_size = {
0
};
current_size += 4; // moves_decompressed_size: u32
let mut moves = Vec::with_capacity(body_size as usize - current_size);
while !r.is_empty() {
let a = CompressedMove::read(&mut r)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ impl SMSG_SPELL_COOLDOWN {
let mut current_size = {
8 // guid: Guid
};
current_size += 4; // cooldowns_decompressed_size: u32
let mut cooldowns = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
cooldowns.push(SpellCooldownStatus::read(&mut r)?);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ impl CMSG_GUILD_BANK_SWAP_ITEMS {
8 // bank: Guid
+ 1 // source: CMSG_GUILD_BANK_SWAP_ITEMS_BankSwapSource
};
current_size += 4; // unknown5_decompressed_size: u32
let mut unknown5 = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
unknown5.push(crate::util::read_u8_le(&mut r)?);
Expand Down
28 changes: 18 additions & 10 deletions wow_world_messages/src/world/wrath/smsg_account_data_times.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ pub struct SMSG_ACCOUNT_DATA_TIMES {

impl crate::private::Sealed for SMSG_ACCOUNT_DATA_TIMES {}
impl SMSG_ACCOUNT_DATA_TIMES {
fn read_inner(mut r: &mut &[u8], body_size: u32) -> Result<Self, crate::errors::ParseErrorKind> {
fn read_inner(
mut r: &mut &[u8],
body_size: u32,
) -> Result<Self, crate::errors::ParseErrorKind> {
if !(9..=65544).contains(&body_size) {
return Err(crate::errors::ParseErrorKind::InvalidSize);
}
Expand All @@ -46,7 +49,6 @@ impl SMSG_ACCOUNT_DATA_TIMES {
+ 1 // unknown1: u8
+ 4 // mask: CacheMask
};
current_size += 4; // data_decompressed_size: u32
let mut data = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
data.push(crate::util::read_u32_le(&mut r)?);
Expand All @@ -62,7 +64,6 @@ impl SMSG_ACCOUNT_DATA_TIMES {
data,
})
}

}

impl crate::Message for SMSG_ACCOUNT_DATA_TIMES {
Expand All @@ -75,8 +76,8 @@ impl crate::Message for SMSG_ACCOUNT_DATA_TIMES {

#[cfg(feature = "print-testcase")]
fn to_test_case_string(&self) -> Option<String> {
use std::fmt::Write;
use crate::traits::Message;
use std::fmt::Write;

let mut s = String::new();

Expand Down Expand Up @@ -112,9 +113,13 @@ impl crate::Message for SMSG_ACCOUNT_DATA_TIMES {
writeln!(s, " /* data: u32[-] end */").unwrap();
}


writeln!(s, "] {{").unwrap();
writeln!(s, " versions = \"{}\";", std::env::var("WOWM_TEST_CASE_WORLD_VERSION").unwrap_or("3.3.5".to_string())).unwrap();
writeln!(
s,
" versions = \"{}\";",
std::env::var("WOWM_TEST_CASE_WORLD_VERSION").unwrap_or("3.3.5".to_string())
)
.unwrap();
writeln!(s, "}}\n").unwrap();

Some(s)
Expand Down Expand Up @@ -142,10 +147,14 @@ impl crate::Message for SMSG_ACCOUNT_DATA_TIMES {
Ok(())
}

fn read_body<S: crate::private::Sealed>(r: &mut &[u8], body_size: u32) -> Result<Self, crate::errors::ParseError> {
Self::read_inner(r, body_size).map_err(|a| crate::errors::ParseError::new(521, "SMSG_ACCOUNT_DATA_TIMES", body_size, a))
fn read_body<S: crate::private::Sealed>(
r: &mut &[u8],
body_size: u32,
) -> Result<Self, crate::errors::ParseError> {
Self::read_inner(r, body_size).map_err(|a| {
crate::errors::ParseError::new(521, "SMSG_ACCOUNT_DATA_TIMES", body_size, a)
})
}

}

#[cfg(feature = "wrath")]
Expand All @@ -159,4 +168,3 @@ impl SMSG_ACCOUNT_DATA_TIMES {
+ self.data.len() * core::mem::size_of::<u32>() // data: u32[-]
}
}

1 change: 0 additions & 1 deletion wow_world_messages/src/world/wrath/smsg_aura_update_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ impl SMSG_AURA_UPDATE_ALL {
let mut current_size = {
crate::util::packed_guid_size(&unit) // unit: PackedGuid
};
current_size += 4; // aura_updates_decompressed_size: u32
let mut aura_updates = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
let a = AuraUpdate::read(&mut r)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ impl SMSG_COMPRESSED_MOVES {
let mut current_size = {
4 // size: u32
};
current_size += 4; // moves_decompressed_size: u32
let mut moves = Vec::with_capacity(body_size as usize - current_size);
while !r.is_empty() {
let a = MiniMoveMessage::read(&mut r)?;
Expand Down
1 change: 0 additions & 1 deletion wow_world_messages/src/world/wrath/smsg_lfg_join_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ impl SMSG_LFG_JOIN_RESULT {
4 // result: u32
+ 4 // state: u32
};
current_size += 4; // players_decompressed_size: u32
let mut players = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
let a = LfgJoinPlayer::read(&mut r)?;
Expand Down
1 change: 0 additions & 1 deletion wow_world_messages/src/world/wrath/smsg_multiple_moves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ impl SMSG_MULTIPLE_MOVES {
let mut current_size = {
4 // size: u32
};
current_size += 4; // moves_decompressed_size: u32
let mut moves = Vec::with_capacity(body_size as usize - current_size);
while current_size < (body_size as usize) {
let a = MiniMoveMessage::read(&mut r)?;
Expand Down

0 comments on commit 58aa564

Please sign in to comment.