Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 39 additions & 38 deletions maxima-lib/src/lsx/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,48 +209,49 @@ impl Connection {
stream.set_nonblocking(true)?;
stream.set_read_timeout(Some(Duration::from_secs(1)))?;

let mut pid: Result<u32, NativeError> = 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(),
Expand Down