From 6e8ae22027b1fd4ded12cd953be6b4d6d4552073 Mon Sep 17 00:00:00 2001 From: ismaileke Date: Tue, 14 Jan 2025 10:42:05 +0300 Subject: [PATCH] compression fix --- src/client.rs | 12 ++++++++---- src/protocol/game/login.rs | 4 ++-- src/protocol/game/resource_packs_info.rs | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/client.rs b/src/client.rs index cb4ce03..141d3fd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -49,6 +49,7 @@ pub struct Client { target_address: String, target_port: u16, client_guid: i64, + client_version: String, chain: Vec, ec_key: EcKey, game: GamePacket, @@ -64,7 +65,7 @@ pub struct Client { pub async fn create(target_address: String, target_port: u16, client_version: String, debug: bool) -> Option { //block::vanilla_block_map(false, &vec![]); - let mut bedrock = bedrock::new(client_version, false); + let mut bedrock = bedrock::new(client_version.clone(), false); if !bedrock.auth().await { return None; } let mut rng = rand::thread_rng(); Option::from(Client{ @@ -72,6 +73,7 @@ pub async fn create(target_address: String, target_port: u16, client_version: St target_address, target_port, client_guid: rng.gen_range(10000..100000), + client_version, chain: bedrock.get_chain_data(), ec_key: bedrock.get_ec_key()?, game: GamePacket::new(None, false), @@ -261,11 +263,13 @@ impl Client { println!("Enable Client Throttling: {}", network_settings.enable_client_throttling); println!("Client Throttle Threshold: {}", network_settings.client_throttle_threshold); println!("Client Throttle Scalar: {}", network_settings.client_throttle_scalar); + + self.game = GamePacket::new(None, true); self.compression_enabled = true; // LOGIN PACKET let pkey = PKey::from_ec_key(self.ec_key.clone()).expect("PKey Error"); - let login_data_detail = login::convert_login_chain(&mut self.chain, pkey, self.target_address.clone(), self.target_port, self.client_guid); + let login_data_detail = login::convert_login_chain(&mut self.chain, pkey, self.target_address.clone(), self.target_port, self.client_guid, self.client_version.clone()); let login = login::new(BEDROCK_PROTOCOL_VERSION, login_data_detail[0].clone(), login_data_detail[1].clone()).encode(); let datagrams = Datagram::split_packet(login, &mut self.frame_number_cache); @@ -277,7 +281,7 @@ impl Client { BedrockPacketType::ServerToClientHandshake => { let s_to_c_handshake = server_to_client_handshake::decode(packet_stream.get_remaining().unwrap()); let jwt = String::from_utf8(s_to_c_handshake.jwt).unwrap(); - println!("JWT: {:?}", jwt); + println!("JWT: {}", jwt); let jwt_split: Vec<&str> = jwt.split('.').collect(); let jwt_header = Encryption::b64_url_decode(jwt_split[0]).unwrap(); @@ -315,7 +319,7 @@ impl Client { println!("Must Accept: {}", resource_packs_info.must_accept); println!("Has Addons: {}", resource_packs_info.has_addons); println!("Has Scripts: {}", resource_packs_info.has_scripts); - println!("World Template ID (Vec): {:?}", resource_packs_info.world_template_id); + println!("World Template ID: {}", resource_packs_info.world_template_id); println!("World Template Version: {}", resource_packs_info.world_template_version); let resource_pack_count = resource_packs_info.resource_packs.len(); println!("Resource Pack Count: {}", resource_pack_count); diff --git a/src/protocol/game/login.rs b/src/protocol/game/login.rs index 616ef74..f943558 100644 --- a/src/protocol/game/login.rs +++ b/src/protocol/game/login.rs @@ -46,7 +46,7 @@ impl Login { } } -pub fn convert_login_chain(chain: &mut Vec, pkey: PKey, target_address: String, target_port: u16, client_guid: i64) -> Vec { +pub fn convert_login_chain(chain: &mut Vec, pkey: PKey, target_address: String, target_port: u16, client_guid: i64, client_version: String) -> Vec { let chain_one: Vec<&str> = chain[0].split('.').collect(); let chain_two: Vec<&str> = chain[1].split('.').collect(); @@ -92,7 +92,7 @@ pub fn convert_login_chain(chain: &mut Vec, pkey: PKey, target_ "DeviceId": "ebc40067-bfdb-3ad0-af9d-65248592acf1", "DeviceModel": "System Product Name ASUS", "DeviceOS": 1, //:D - "GameVersion": "1.21.40", + "GameVersion": client_version, "GuiScale": -1, "IsEditorMode": false, "LanguageCode": "en_US", diff --git a/src/protocol/game/resource_packs_info.rs b/src/protocol/game/resource_packs_info.rs index b50bd19..40ea204 100644 --- a/src/protocol/game/resource_packs_info.rs +++ b/src/protocol/game/resource_packs_info.rs @@ -5,7 +5,7 @@ pub struct ResourcePacksInfo { pub must_accept: bool, pub has_addons: bool, pub has_scripts: bool, - pub world_template_id: Vec, + pub world_template_id: Uuid, pub world_template_version: String, pub resource_packs: Vec @@ -31,7 +31,7 @@ pub fn decode(bytes: Vec) -> ResourcePacksInfo { let has_addons = stream.get_bool(); let has_scripts = stream.get_bool(); - let world_template_id = stream.get(16).unwrap(); + let world_template_id = Uuid::from_slice(&stream.get(16).unwrap()).unwrap(); let length = stream.get_unsigned_var_int(); let world_template_version = String::from_utf8(stream.get(length).unwrap()).unwrap();