From e96220ea0bde3798173c4266efd52640e47446f9 Mon Sep 17 00:00:00 2001 From: p0358 Date: Mon, 26 Jan 2026 20:43:12 +0100 Subject: [PATCH] Don't reject external LSX connections --- maxima-lib/src/lsx/connection.rs | 77 ++++++++++++++++---------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/maxima-lib/src/lsx/connection.rs b/maxima-lib/src/lsx/connection.rs index ec7b683..22ae4fd 100644 --- a/maxima-lib/src/lsx/connection.rs +++ b/maxima-lib/src/lsx/connection.rs @@ -209,48 +209,49 @@ impl Connection { stream.set_nonblocking(true)?; stream.set_read_timeout(Some(Duration::from_secs(1)))?; + let mut pid: Result = Ok(0); + let maxima: MutexGuard<'_, Maxima> = maxima_arc.lock().await; - let context: &ActiveGameContext = match maxima.playing() { - Some(context) => context, + match maxima.playing() { None => { - stream.shutdown(std::net::Shutdown::Both)?; - return Err(LSXConnectionError::GameContext); - } - }; - - // The PID system is mainly for Kyber injection - let mut pid = get_os_pid(context); - if cfg!(unix) { - if let Ok(os_pid) = pid { - let sys = System::new_all(); - if let Some(process) = sys.process(Pid::from_u32(os_pid)) { - let filename = PathBuf::from( - process.cmd()[0] - .to_owned() - .replace("Z:", "") - .replace('\\', "/"), - ) - .file_name() - .ok_or(NativeError::FileName)? - .to_str() - .ok_or(NativeError::Stringify)? - .to_owned(); - - pid = get_wine_pid(&context.launch_id(), &filename).await; - } else { - warn!( - "Failed to find game process while looking for PID {}", - os_pid - ); + warn!("External LSX connection (the game was not started through Maxima)"); + }, + Some(context) => { + // The PID system is mainly for Kyber injection + pid = get_os_pid(context); + if cfg!(unix) { + if let Ok(os_pid) = pid { + let sys = System::new_all(); + if let Some(process) = sys.process(Pid::from_u32(os_pid)) { + let filename = PathBuf::from( + process.cmd()[0] + .to_owned() + .replace("Z:", "") + .replace('\\', "/"), + ) + .file_name() + .ok_or(NativeError::FileName)? + .to_str() + .ok_or(NativeError::Stringify)? + .to_owned(); + + pid = get_wine_pid(&context.launch_id(), &filename).await; + } else { + warn!( + "Failed to find game process while looking for PID {}", + os_pid + ); + } + } } - } - } - if let Err(ref err) = pid { - warn!("Error while finding game PID: {}", err); - } else if pid.as_ref().unwrap() == &0 { - warn!("Failed to find PID through launch ID, things may not work!"); - } + if let Err(ref err) = pid { + warn!("Error while finding game PID: {}", err); + } else if pid.as_ref().unwrap() == &0 { + warn!("Failed to find PID through launch ID, things may not work!"); + } + }, + }; let state = Arc::new(RwLock::new(ConnectionState { maxima: maxima_arc.clone(),