fix: changed portablemc's client id to mcl's that now got approved

This commit is contained in:
objz committed 2026-04-22 20:08:17 +02:00
1 parent 462645f2e7
commit 4d055a58e9
4 files changed
+189 -26

No files matched your search

+2 -6
View File
@@ -42,13 +42,9 @@ it does everything you'd expect from a launcher. multiple instances, mod loaders
## authentication
mcl currently uses the Microsoft client ID from [portablemc](https://github.com/mindstorm38/portablemc) for Minecraft account authentication.
mcl uses its own Microsoft client ID for Minecraft account authentication.
this is temporary while mcl is going through the official Microsoft/Minecraft app approval process. once approved, mcl will switch to its own client ID.
authentication still happens through Microsoft’s official services.
---
Authentication is performed through Microsoft’s official services.
## installation
+1 -1
View File
@@ -14,7 +14,7 @@ use serde::Deserialize;
use super::accounts::{Account, AccountType, AuthResult};
const CLIENT_ID: &str = "708e91b5-99f8-4a1d-80ec-e746cbb24771";
const CLIENT_ID: &str = "cc1b2d89-8d8b-439f-94e6-4a7fc484f672";
const DEVICE_CODE_URL: &str = "https://login.microsoftonline.com/consumers/oauth2/v2.0/devicecode";
const MSA_AUTHORIZE_URL: &str = "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize";
const MSA_TOKEN_URL: &str = "https://login.microsoftonline.com/consumers/oauth2/v2.0/token";
+125 -12
View File
@@ -67,6 +67,8 @@ struct MetaOsRule {
struct LoaderProfileJson {
main_class: String,
libraries: Vec<LoaderLibrary>,
#[serde(default)]
game_arguments: Vec<String>,
}
#[derive(serde::Deserialize)]
@@ -146,9 +148,9 @@ pub async fn launch(
ModLoader::NeoForge => Some(format!("neoforge-{}.json", lv)),
};
// if there's a mod loader, read its profile to get the real main class
// and extra libraries it needs on the classpath
let main_class = if let Some(filename) = profile_filename {
// if there's a mod loader, read its profile to get the real main class,
// extra libraries, and any additional game arguments (e.g. --tweakClass)
let (main_class, loader_game_args) = if let Some(filename) = profile_filename {
let profile_path = meta_dir.join("loader-profiles").join(&filename);
if !profile_path.exists() {
return Err(LaunchError::MetaNotFound(
@@ -158,29 +160,30 @@ pub async fn launch(
let profile: LoaderProfileJson =
serde_json::from_slice(&tokio::fs::read(&profile_path).await?)?;
// forge/neoforge install some libs locally in the instance dir, so
// both locations need to be checked
// forge/neoforge install some libs locally in the instance dir.
// local libs take priority so modpacks can ship patched versions
// (e.g. GTNH's launchwrapper patched for java 9+ compatibility)
let has_local_libs = matches!(config.loader, ModLoader::Forge | ModLoader::NeoForge);
let local_lib_dir = minecraft_dir.join("libraries");
for lib in &profile.libraries {
if let Some(p) = crate::net::maven_coord_to_path(&lib.name) {
if has_local_libs {
let in_meta = lib_dir.join(&p);
let in_local = local_lib_dir.join(&p);
if in_meta.exists() {
classpath.push(in_meta);
} else if in_local.exists() {
let in_meta = lib_dir.join(&p);
if in_local.exists() {
classpath.push(in_local);
} else if in_meta.exists() {
classpath.push(in_meta);
}
} else {
classpath.push(lib_dir.join(p));
}
}
}
profile.main_class
(profile.main_class, profile.game_arguments)
} else {
meta.main_class.clone()
(meta.main_class.clone(), Vec::new())
};
classpath.push(
@@ -190,6 +193,17 @@ pub async fn launch(
.join(format!("{}.jar", config.game_version)),
);
// lwjgl3ify ships a patched launchwrapper and retrofuturabootstrap for
// java 9+ compat. if present, prepend its patches to the classpath,
// override the main class to use RFB's bootstrap, and add the required
// --add-opens and system classloader flags.
let (lwjgl3ify_jvm_args, main_class) = if matches!(config.loader, ModLoader::Forge) {
let (jvm_args, override_main) = apply_lwjgl3ify_patches(&minecraft_dir, &mut classpath);
(jvm_args, override_main.unwrap_or(main_class))
} else {
(Vec::new(), main_class)
};
let sep = if cfg!(windows) { ";" } else { ":" };
let cp_str = classpath
.iter()
@@ -213,6 +227,7 @@ pub async fn launch(
format!("-Xms{}", config.memory_min.as_deref().unwrap_or("512M")),
format!("-Xmx{}", config.memory_max.as_deref().unwrap_or("2G")),
];
jvm.extend(lwjgl3ify_jvm_args);
jvm.extend(config.jvm_args.clone());
// resolve auth credentials, refreshing the microsoft token if needed.
@@ -262,7 +277,7 @@ pub async fn launch(
),
};
let game_args = vec![
let mut game_args = vec![
"--username".to_string(),
mc_username,
"--version".to_string(),
@@ -280,6 +295,7 @@ pub async fn launch(
"--userType".to_string(),
mc_user_type,
];
game_args.extend(loader_game_args);
let (kill_tx, kill_rx) = tokio::sync::oneshot::channel::<()>();
crate::running::register_kill(&name, kill_tx);
@@ -394,3 +410,100 @@ pub async fn launch(
Ok(())
}
// lwjgl3ify (used by GTNH and other old forge modpacks) bundles a
// forgePatches.zip with patched launchwrapper classes that fix the
// URLClassLoader cast on java 9+. if we find it, extract the patches
// and prepend them to the classpath so they shadow the vanilla classes.
// also parses Add-Opens from the zip's manifest for the required
// --add-opens flags.
fn apply_lwjgl3ify_patches(
minecraft_dir: &Path,
classpath: &mut Vec<PathBuf>,
) -> (Vec<String>, Option<String>) {
let mods_dir = minecraft_dir.join("mods");
let lwjgl3ify_jar = match find_lwjgl3ify_jar(&mods_dir) {
Some(p) => p,
None => return (Vec::new(), None),
};
let patches_dest = minecraft_dir.join(".forge-patches.zip");
if let Err(e) = extract_forge_patches(&lwjgl3ify_jar, &patches_dest) {
tracing::warn!("Failed to extract lwjgl3ify forge patches: {e}");
return (Vec::new(), None);
}
// prepend so patched classes shadow vanilla launchwrapper
classpath.insert(0, patches_dest.clone());
let mut jvm_args = parse_add_opens(&patches_dest).unwrap_or_default();
// RFB requires its own classloader to be the system classloader, and
// its Main class handles bootstrapping into launchwrapper.
// the other flags match lwjgl3ify's java9args.txt.
jvm_args.extend([
"-Djava.system.class.loader=com.gtnewhorizons.retrofuturabootstrap.RfbSystemClassLoader".to_string(),
"-Dfile.encoding=UTF-8".to_string(),
"--enable-native-access".to_string(),
"ALL-UNNAMED".to_string(),
]);
// also prepend the lwjgl3ify jar itself so RFB can find its plugin classes
classpath.insert(1, lwjgl3ify_jar);
let main_class = "com.gtnewhorizons.retrofuturabootstrap.Main".to_string();
(jvm_args, Some(main_class))
}
fn find_lwjgl3ify_jar(mods_dir: &Path) -> Option<PathBuf> {
let entries = std::fs::read_dir(mods_dir).ok()?;
for entry in entries.flatten() {
let name = entry.file_name();
let name = name.to_string_lossy();
if name.starts_with("lwjgl3ify") && name.ends_with(".jar") {
return Some(entry.path());
}
}
None
}
fn extract_forge_patches(lwjgl3ify_jar: &Path, dest: &Path) -> Result<(), std::io::Error> {
use std::io::Read;
let file = std::fs::File::open(lwjgl3ify_jar)?;
let mut archive = zip::ZipArchive::new(file)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
let mut entry = archive
.by_name("me/eigenraven/lwjgl3ify/relauncher/forgePatches.zip")
.map_err(|e| std::io::Error::new(std::io::ErrorKind::NotFound, e))?;
let mut buf = Vec::new();
entry.read_to_end(&mut buf)?;
std::fs::write(dest, &buf)
}
fn parse_add_opens(patches_zip: &Path) -> Option<Vec<String>> {
use std::io::Read;
let file = std::fs::File::open(patches_zip).ok()?;
let mut archive = zip::ZipArchive::new(file).ok()?;
let mut entry = archive.by_name("META-INF/MANIFEST.MF").ok()?;
let mut manifest = String::new();
entry.read_to_string(&mut manifest).ok()?;
// manifest continuation lines start with a single space
let manifest = manifest.replace("\r\n ", "").replace("\n ", "");
let mut args = Vec::new();
for line in manifest.lines() {
if let Some(value) = line.strip_prefix("Add-Opens: ") {
for module_package in value.split_whitespace() {
args.push("--add-opens".to_string());
args.push(format!("{module_package}=ALL-UNNAMED"));
}
}
}
Some(args)
}
+61 -7
View File
@@ -241,15 +241,13 @@ pub(crate) async fn install_forge_from_profile(
std::fs::write(&universal_dest, &buf)?;
}
// download libraries that have a url field (forge-hosted ones).
// libs without url are from mojang and already handled elsewhere.
// download libraries needed by this forge version. libs with a url field
// are forge-hosted, libs without one are typically from mojang's library
// server. old forge versions reference libs like launchwrapper that aren't
// in mojang's modern version metadata, so we fetch those too.
let libraries_dir = meta_dir.join("libraries");
for lib in libraries {
let name = lib.get("name").and_then(|v| v.as_str()).unwrap_or_default();
let url = match lib.get("url").and_then(|v| v.as_str()) {
Some(u) => u,
None => continue,
};
let maven_path = match crate::net::maven_coord_to_path(name) {
Some(p) => p,
@@ -265,13 +263,25 @@ pub(crate) async fn install_forge_from_profile(
continue;
}
let base_url = url.trim_end_matches('/');
let base_url = lib
.get("url")
.and_then(|v| v.as_str())
.unwrap_or("https://libraries.minecraft.net/")
.trim_end_matches('/');
let download_url = format!("{base_url}/{maven_path}");
set_sub_action(name);
download_file(client, &download_url, &dest, |_, _| {}).await?;
}
// old forge profiles store game arguments (like --tweakClass) in
// minecraftArguments. extract non-template args to pass at launch.
let game_arguments: Vec<String> = version_info
.get("minecraftArguments")
.and_then(|v| v.as_str())
.map(extract_extra_game_args)
.unwrap_or_default();
set_action("Saving Forge profile...");
let lib_entries: Vec<serde_json::Value> = libraries
.iter()
@@ -285,6 +295,7 @@ pub(crate) async fn install_forge_from_profile(
let profile_json = serde_json::json!({
"mainClass": main_class,
"libraries": lib_entries,
"gameArguments": game_arguments,
});
crate::instance::loader::save_profile_json(meta_dir, profile_filename, &profile_json)?;
@@ -292,6 +303,49 @@ pub(crate) async fn install_forge_from_profile(
Ok(())
}
// pulls out game arguments from old forge's minecraftArguments string that
// the launcher doesn't already handle. skips template variables (${...})
// and standard args like --username that we build ourselves.
fn extract_extra_game_args(minecraft_arguments: &str) -> Vec<String> {
let handled = [
"--username",
"--version",
"--gameDir",
"--assetsDir",
"--assetIndex",
"--uuid",
"--accessToken",
"--userProperties",
"--userType",
];
let tokens: Vec<&str> = minecraft_arguments.split_whitespace().collect();
let mut result = Vec::new();
let mut i = 0;
while i < tokens.len() {
let token = tokens[i];
if token.starts_with("--") {
if handled.contains(&token) {
// skip the flag and its value
i += 2;
continue;
}
result.push(token.to_string());
// if the next token is a value (not a flag or template), include it
if i + 1 < tokens.len() && !tokens[i + 1].starts_with("--") {
let val = tokens[i + 1];
if !val.starts_with("${") {
result.push(val.to_string());
}
i += 2;
continue;
}
}
i += 1;
}
result
}
#[cfg(test)]
mod tests {
use super::*;