Fix IPC on Forge 1.17.1 - 1.20.1 (#4187)

* Reapply "Implement a more robust IPC system between the launcher and client (#4159)"

This reverts commit e25d726da4.

* Put game JAR and theseus JAR ahead of other JARs in classpath

* Fix 1.17-1.20 Forge by forcefully removing Multi-Release manifest entry

* Fix formatting

---------

Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
This commit is contained in:
Josiah Glosson
2025-08-18 13:32:17 -07:00
committed by GitHub
parent d19bf82cb1
commit 805c0b86a5
18 changed files with 643 additions and 97 deletions

View File

@@ -14,8 +14,9 @@ use daedalus::{
modded::SidedDataEntry,
};
use dunce::canonicalize;
use hashlink::LinkedHashSet;
use itertools::Itertools;
use std::io::{BufRead, BufReader};
use std::net::SocketAddr;
use std::{collections::HashMap, path::Path};
use uuid::Uuid;
@@ -29,9 +30,21 @@ pub fn get_class_paths(
java_arch: &str,
minecraft_updated: bool,
) -> crate::Result<String> {
let mut cps = libraries
launcher_class_path
.iter()
.filter_map(|library| {
.map(|path| {
Ok(canonicalize(path)
.map_err(|_| {
crate::ErrorKind::LauncherError(format!(
"Specified class path {} does not exist",
path.to_string_lossy()
))
.as_error()
})?
.to_string_lossy()
.to_string())
})
.chain(libraries.iter().filter_map(|library| {
if let Some(rules) = &library.rules
&& !parse_rules(
rules,
@@ -48,28 +61,10 @@ pub fn get_class_paths(
}
Some(get_lib_path(libraries_path, &library.name, false))
}))
.process_results(|iter| {
iter.unique().join(classpath_separator(java_arch))
})
.collect::<Result<LinkedHashSet<_>, _>>()?;
for launcher_path in launcher_class_path {
cps.insert(
canonicalize(launcher_path)
.map_err(|_| {
crate::ErrorKind::LauncherError(format!(
"Specified class path {} does not exist",
launcher_path.to_string_lossy()
))
.as_error()
})?
.to_string_lossy()
.to_string(),
);
}
Ok(cps
.into_iter()
.collect::<Vec<_>>()
.join(classpath_separator(java_arch)))
}
pub fn get_class_paths_jar<T: AsRef<str>>(
@@ -124,6 +119,7 @@ pub fn get_jvm_arguments(
quick_play_type: &QuickPlayType,
quick_play_version: QuickPlayVersion,
log_config: Option<&LoggingConfiguration>,
ipc_addr: SocketAddr,
) -> crate::Result<Vec<String>> {
let mut parsed_arguments = Vec::new();
@@ -181,6 +177,11 @@ pub fn get_jvm_arguments(
.to_string_lossy()
));
parsed_arguments
.push(format!("-Dmodrinth.internal.ipc.host={}", ipc_addr.ip()));
parsed_arguments
.push(format!("-Dmodrinth.internal.ipc.port={}", ipc_addr.port()));
parsed_arguments.push(format!(
"-Dmodrinth.internal.quickPlay.serverVersion={}",
serde_json::to_value(quick_play_version.server)?

View File

@@ -12,6 +12,7 @@ use crate::state::{
Credentials, JavaVersion, ProcessMetadata, ProfileInstallStage,
};
use crate::util::io;
use crate::util::rpc::RpcServerBuilder;
use crate::{State, get_resource_file, process, state as st};
use chrono::Utc;
use daedalus as d;
@@ -22,7 +23,6 @@ use serde::Deserialize;
use st::Profile;
use std::fmt::Write;
use std::path::PathBuf;
use tokio::io::AsyncWriteExt;
use tokio::process::Command;
mod args;
@@ -608,6 +608,8 @@ pub async fn launch_minecraft(
let (main_class_keep_alive, main_class_path) =
get_resource_file!(env "JAVA_JARS_DIR" / "theseus.jar")?;
let rpc_server = RpcServerBuilder::new().launch().await?;
command.args(
args::get_jvm_arguments(
args.get(&d::minecraft::ArgumentType::Jvm)
@@ -633,6 +635,7 @@ pub async fn launch_minecraft(
.logging
.as_ref()
.and_then(|x| x.get(&LoggingSide::Client)),
rpc_server.address(),
)?
.into_iter(),
);
@@ -767,7 +770,8 @@ pub async fn launch_minecraft(
state.directories.profile_logs_dir(&profile.path),
version_info.logging.is_some(),
main_class_keep_alive,
async |process: &ProcessMetadata, stdin| {
rpc_server,
async |process: &ProcessMetadata, rpc_server| {
let process_start_time = process.start_time.to_rfc3339();
let profile_created_time = profile.created.to_rfc3339();
let profile_modified_time = profile.modified.to_rfc3339();
@@ -790,14 +794,11 @@ pub async fn launch_minecraft(
let Some(value) = value else {
continue;
};
stdin.write_all(b"property\t").await?;
stdin.write_all(key.as_bytes()).await?;
stdin.write_u8(b'\t').await?;
stdin.write_all(value.as_bytes()).await?;
stdin.write_u8(b'\n').await?;
rpc_server
.call_method_2::<()>("set_system_property", key, value)
.await?;
}
stdin.write_all(b"launch\n").await?;
stdin.flush().await?;
rpc_server.call_method::<()>("launch").await?;
Ok(())
},
)