From 614e470669c26faa968c6b29235ef3321cfae5ee Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 30 Apr 2025 22:37:57 -0400 Subject: [PATCH] Add an option to enable packet obsfucation for the World server There's no point in doing this yet: 1. This *crashes* the client, nice. Most likely because we're not actually obsfucating anything, only tricking the client into thinking we were. Why this can crash the client is beyond me? 2. Obsfucation is still optional. --- src/config.rs | 8 ++++++++ src/lib.rs | 3 +++ src/world/connection.rs | 9 +++++++++ src/world/ipc/init_zone.rs | 4 +++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index cba59fa..40ba4cf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -204,6 +204,9 @@ pub struct WorldConfig { /// Password of the RCON server, if left blank (the default) RCON is disabled. #[serde(default = "WorldConfig::default_rcon_password")] pub rcon_password: String, + /// Enable packet obsfucation. There's literally no reason to do this! + #[serde(default = "WorldConfig::default_packet_obsfucation")] + pub enable_packet_obsfucation: bool, } impl Default for WorldConfig { @@ -215,6 +218,7 @@ impl Default for WorldConfig { scripts_location: Self::default_scripts_location(), rcon_port: Self::default_rcon_port(), rcon_password: Self::default_rcon_password(), + enable_packet_obsfucation: Self::default_packet_obsfucation(), } } } @@ -243,6 +247,10 @@ impl WorldConfig { fn default_rcon_password() -> String { String::default() } + + fn default_packet_obsfucation() -> bool { + false + } } impl WorldConfig { diff --git a/src/lib.rs b/src/lib.rs index 9b432e8..6df41f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,3 +59,6 @@ const SUPPORTED_EXPAC_VERSIONS: [(&str, Version); 5] = [ pub fn get_supported_expac_versions() -> HashMap<&'static str, Version<'static>> { HashMap::from(SUPPORTED_EXPAC_VERSIONS) } + +/// Constant to enable packet obsfucation. Changes every patch. +pub const OBFUSCATION_ENABLED_MODE: u8 = 41; diff --git a/src/world/connection.rs b/src/world/connection.rs index 9839125..15a2f35 100644 --- a/src/world/connection.rs +++ b/src/world/connection.rs @@ -9,7 +9,9 @@ use std::{ use tokio::{net::TcpStream, sync::mpsc::Sender}; use crate::{ + OBFUSCATION_ENABLED_MODE, common::{GameData, ObjectId, Position, timestamp_secs}, + config::get_config, opcodes::ServerZoneIpcType, packet::{ CompressionType, ConnectionType, PacketSegment, PacketState, SegmentType, parse_packet, @@ -433,6 +435,8 @@ impl ZoneConnection { // Init Zone { + let config = get_config(); + let ipc = ServerZoneIpcSegment { op_code: ServerZoneIpcType::InitZone, timestamp: timestamp_secs(), @@ -440,6 +444,11 @@ impl ZoneConnection { server_id: 0, zone_id: self.zone.as_ref().unwrap().id, weather_id: 1, + obsfucation_mode: if config.world.enable_packet_obsfucation { + OBFUSCATION_ENABLED_MODE + } else { + 0 + }, ..Default::default() }), ..Default::default() diff --git a/src/world/ipc/init_zone.rs b/src/world/ipc/init_zone.rs index 5ebd019..f79e9d0 100644 --- a/src/world/ipc/init_zone.rs +++ b/src/world/ipc/init_zone.rs @@ -14,7 +14,9 @@ pub struct InitZone { pub weather_id: u16, // index into Weather sheet probably? pub unk_really: u16, pub unk_bitmask1: u8, - pub unk_bitmask2: u8, + /// Zero means "no obsfucation" (not really, but functionally yes.) + /// To enable obsfucation, you need to set this to a constant that changes every patch. See lib.rs for the constant. + pub obsfucation_mode: u8, pub unk1: u8, pub unk2: u32, pub festival_id: u16,