Skip to content

Commit

Permalink
The generator doesn't calculate properly 10 bits vs 9 bits on byte ra…
Browse files Browse the repository at this point in the history
…nges

Signed-off-by: Seb Ospina <[email protected]>
  • Loading branch information
sebosp committed Sep 24, 2023
1 parent 87dd53b commit b46a3a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/versions/protocol87702/events/init_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ impl TryFrom<GameSLobbySyncState> for LobbySyncState {

impl TryFrom<SUserInitialData> for UserInitialData {
type Error = S2ProtocolError;
#[tracing::instrument(level = "debug")]
fn try_from(source: SUserInitialData) -> Result<Self, Self::Error> {
// tranforms from SUserInitialData into UserInitialData casting into internal types
let name = str::from_utf8(&source.m_name.value)?.to_string();
let clan_tag = match source.m_clan_tag {
Some(clan_tag) => Some(str::from_utf8(&clan_tag.value)?.to_string()),
None => None,
};
// Found some instances of non valid UTF8
let clan_logo = match source.m_clan_logo {
Some(clan_logo) => Some(str::from_utf8(&clan_logo.value)?.to_string()),
Some(clan_logo) => Some(clan_logo.value),
None => None,
};
let highest_league = source.m_highest_league.map(|v| v.into());
Expand Down Expand Up @@ -122,6 +124,7 @@ impl From<super::bit_packed::GameEGameType> for crate::init_data::GameType {

impl TryFrom<super::bit_packed::GameSGameDescription> for crate::init_data::GameDescription {
type Error = S2ProtocolError;
#[tracing::instrument(level = "debug")]
fn try_from(source: super::bit_packed::GameSGameDescription) -> Result<Self, Self::Error> {
let random_value = source.m_random_value.into();
let game_cache_name = str::from_utf8(&source.m_game_cache_name.value)?.to_string();
Expand Down Expand Up @@ -314,8 +317,8 @@ impl TryFrom<super::bit_packed::GameSLobbyState> for LobbyState {
let is_single_player = value.m_is_single_player;
let picked_map_tag = value.m_picked_map_tag.value as u8;
let game_duration = value.m_game_duration.value as u32;
let default_difficulty = value.m_default_difficulty.value.into();
let default_ai_build = value.m_default_ai_build.value.into();
let default_difficulty = value.m_default_difficulty.value;
let default_ai_build = value.m_default_ai_build.value;
Ok(Self {
phase,
max_users,
Expand Down Expand Up @@ -347,6 +350,7 @@ impl From<super::bit_packed::GameEPhase> for GamePhase {

impl TryFrom<super::bit_packed::GameSLobbySlot> for LobbySlot {
type Error = S2ProtocolError;
#[tracing::instrument(level = "debug")]
fn try_from(value: super::bit_packed::GameSLobbySlot) -> Result<Self, Self::Error> {
let control = value.m_control.value;
let user_id = value.m_user_id.map(|v| v.value);
Expand Down
15 changes: 9 additions & 6 deletions src/versions/protocol87702/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5257,7 +5257,10 @@ pub mod bit_packed {
#[tracing::instrument(name="87702::CCacheHandle::BlobType::Parse", level = "debug", skip(input), fields(peek = peek_bits(input)))]
pub fn parse(input: (&[u8], usize)) -> S2ProtoResult<(&[u8], usize), Self> {
let (tail, _) = byte_align(input)?;
let num_bits: usize = 6;
let num_bits: usize = 40 * 8;
// TODO: The generator for open_bit_packed_blob_main_parse_fn
// does not work for this case. It should literally 40 bits.
// Not 40 maximum integer value that fits in 6 bits
let (tail, value) = take_bit_array(tail, num_bits)?;
Ok((tail, Self { value }))
}
Expand Down Expand Up @@ -5300,7 +5303,7 @@ pub mod bit_packed {
impl CHeroHandle {
#[tracing::instrument(name="87702::CHeroHandle::StringType::Parse", level = "debug", skip(input), fields(peek = peek_bits(input)))]
pub fn parse(input: (&[u8], usize)) -> S2ProtoResult<(&[u8], usize), Self> {
let str_size_num_bits: usize = 10;
let str_size_num_bits: usize = 9;
let (tail, str_size) = parse_packed_int(input, 0, str_size_num_bits)?;
let (tail, _) = byte_align(tail)?;
let (tail, value) = take_bit_array(tail, str_size as usize * 8usize)?;
Expand All @@ -5315,7 +5318,7 @@ pub mod bit_packed {
impl CSkinHandle {
#[tracing::instrument(name="87702::CSkinHandle::StringType::Parse", level = "debug", skip(input), fields(peek = peek_bits(input)))]
pub fn parse(input: (&[u8], usize)) -> S2ProtoResult<(&[u8], usize), Self> {
let str_size_num_bits: usize = 10;
let str_size_num_bits: usize = 9;
let (tail, str_size) = parse_packed_int(input, 0, str_size_num_bits)?;
let (tail, _) = byte_align(tail)?;
let (tail, value) = take_bit_array(tail, str_size as usize * 8usize)?;
Expand All @@ -5330,7 +5333,7 @@ pub mod bit_packed {
impl CMountHandle {
#[tracing::instrument(name="87702::CMountHandle::StringType::Parse", level = "debug", skip(input), fields(peek = peek_bits(input)))]
pub fn parse(input: (&[u8], usize)) -> S2ProtoResult<(&[u8], usize), Self> {
let str_size_num_bits: usize = 10;
let str_size_num_bits: usize = 9;
let (tail, str_size) = parse_packed_int(input, 0, str_size_num_bits)?;
let (tail, _) = byte_align(tail)?;
let (tail, value) = take_bit_array(tail, str_size as usize * 8usize)?;
Expand All @@ -5345,7 +5348,7 @@ pub mod bit_packed {
impl CArtifactHandle {
#[tracing::instrument(name="87702::CArtifactHandle::StringType::Parse", level = "debug", skip(input), fields(peek = peek_bits(input)))]
pub fn parse(input: (&[u8], usize)) -> S2ProtoResult<(&[u8], usize), Self> {
let str_size_num_bits: usize = 10;
let str_size_num_bits: usize = 9;
let (tail, str_size) = parse_packed_int(input, 0, str_size_num_bits)?;
let (tail, _) = byte_align(tail)?;
let (tail, value) = take_bit_array(tail, str_size as usize * 8usize)?;
Expand Down Expand Up @@ -5375,7 +5378,7 @@ pub mod bit_packed {
impl CCommanderHandle {
#[tracing::instrument(name="87702::CCommanderHandle::StringType::Parse", level = "debug", skip(input), fields(peek = peek_bits(input)))]
pub fn parse(input: (&[u8], usize)) -> S2ProtoResult<(&[u8], usize), Self> {
let str_size_num_bits: usize = 10;
let str_size_num_bits: usize = 9;
let (tail, str_size) = parse_packed_int(input, 0, str_size_num_bits)?;
let (tail, _) = byte_align(tail)?;
let (tail, value) = take_bit_array(tail, str_size as usize * 8usize)?;
Expand Down

0 comments on commit b46a3a5

Please sign in to comment.