Skip to content

Commit

Permalink
compression fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaileke committed Jan 14, 2025
1 parent b75cbc3 commit 6e8ae22
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub struct Client {
target_address: String,
target_port: u16,
client_guid: i64,
client_version: String,
chain: Vec<String>,
ec_key: EcKey<Private>,
game: GamePacket,
Expand All @@ -64,14 +65,15 @@ pub struct Client {

pub async fn create(target_address: String, target_port: u16, client_version: String, debug: bool) -> Option<Client> {
//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{
socket: UdpSocket::bind("0.0.0.0:0").expect("Socket Bind Error"),
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),
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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<u8>): {:?}", 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);
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/game/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Login {
}
}

pub fn convert_login_chain(chain: &mut Vec<String>, pkey: PKey<Private>, target_address: String, target_port: u16, client_guid: i64) -> Vec<String> {
pub fn convert_login_chain(chain: &mut Vec<String>, pkey: PKey<Private>, target_address: String, target_port: u16, client_guid: i64, client_version: String) -> Vec<String> {
let chain_one: Vec<&str> = chain[0].split('.').collect();
let chain_two: Vec<&str> = chain[1].split('.').collect();

Expand Down Expand Up @@ -92,7 +92,7 @@ pub fn convert_login_chain(chain: &mut Vec<String>, pkey: PKey<Private>, 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",
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/game/resource_packs_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct ResourcePacksInfo {
pub must_accept: bool,
pub has_addons: bool,
pub has_scripts: bool,
pub world_template_id: Vec<u8>,
pub world_template_id: Uuid,
pub world_template_version: String,
pub resource_packs: Vec<ResourcePack>

Expand All @@ -31,7 +31,7 @@ pub fn decode(bytes: Vec<u8>) -> 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();

Expand Down

0 comments on commit 6e8ae22

Please sign in to comment.