From a393e0a2f2c3678a3ea869dc1417fa269f2b1040 Mon Sep 17 00:00:00 2001 From: Filip Wandzio Date: Sat, 24 Jan 2026 08:29:14 +0100 Subject: Resolve audio not loading bug Ensure all assets are downloading for each version Temporarily disable minecraft versions older than 1.8 because of the asset/manifest loading issues Implement basic documentation of modules Implement basic async/multithreading for downloading assets --- src/minecraft/launcher.rs | 91 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 18 deletions(-) (limited to 'src/minecraft/launcher.rs') diff --git a/src/minecraft/launcher.rs b/src/minecraft/launcher.rs index f7e3ecc..cfd6c85 100644 --- a/src/minecraft/launcher.rs +++ b/src/minecraft/launcher.rs @@ -2,26 +2,39 @@ use std::process::Command; use log::{debug, info}; -use crate::{config::Config, errors::McError, minecraft::manifests::Version, platform::paths}; +use crate::{ + config::Config, + errors::McError, + minecraft::manifests::{Library, Version}, + platform::paths, +}; -/// Build the full classpath -fn build_classpath(config: &Config, version: &Version) -> Result { +/// Buduje classpath dla danej wersji Minecrafta +fn build_classpath( + config: &Config, + version: &Version, +) -> Result { let sep = if cfg!(windows) { ";" } else { ":" }; let mut entries = Vec::new(); - for lib in &version.libraries { - if let Some(artifact) = &lib.downloads.artifact { + for library in &version.libraries { + if !library_allowed(library) { + continue; + } + if let Some(artifact) = &library.downloads.artifact { let path = paths::library_file(config, &artifact.path)?; entries.push(path.to_string_lossy().to_string()); } } + // client.jar zawsze na końcu classpath let client_jar = paths::client_jar(config, &version.id)?; entries.push(client_jar.to_string_lossy().to_string()); + Ok(entries.join(sep)) } -/// Launch Minecraft +/// Uruchamia Minecraft pub fn launch(config: &Config, version: &Version) -> Result<(), McError> { let java = &config.java_path; let classpath = build_classpath(config, version)?; @@ -34,26 +47,46 @@ pub fn launch(config: &Config, version: &Version) -> Result<(), McError> { ))); } + let asset_index_id = version + .asset_index + .as_ref() + .ok_or_else(|| { + McError::Runtime("Missing assetIndex in version.json".into()) + })? + .id + .clone(); + info!("Launching Minecraft {}", version.id); debug!("Classpath: {}", classpath); debug!("Natives: {}", natives_dir.display()); + debug!("Asset index: {}", asset_index_id); + + let mut cmd = Command::new(java); + + // ===== JVM ARGUMENTS (muszą być na początku) ===== + cmd.arg(format!("-Xmx{}M", config.max_memory_mb)) + .arg(format!("-Djava.library.path={}", natives_dir.display())); - let status = Command::new(java) - .arg(format!("-Xmx{}M", config.max_memory_mb)) - .arg(format!("-Djava.library.path={}", natives_dir.display())) - .arg("-cp") + for arg in &config.jvm_args { + cmd.arg(arg); + } + + // ===== CLASSPATH + MAIN CLASS ===== + cmd.arg("-cp") .arg(classpath) - .arg(&version.main_class) - .arg("--username") + .arg(&version.main_class); + + // ===== ARGUMENTY GRY ===== + cmd.arg("--username") .arg(&config.username) .arg("--version") .arg(&version.id) .arg("--gameDir") - .arg(paths::minecraft_root(config)) + .arg(paths::game_dir(config)) .arg("--assetsDir") - .arg(paths::minecraft_root(config).join("assets")) + .arg(paths::assets_dir(config)) .arg("--assetIndex") - .arg(&version.id) + .arg(&asset_index_id) .arg("--uuid") .arg(&config.uuid) .arg("--userProperties") @@ -61,9 +94,9 @@ pub fn launch(config: &Config, version: &Version) -> Result<(), McError> { .arg("--accessToken") .arg("0") .arg("--userType") - .arg("legacy") - .args(&config.jvm_args) - .status()?; + .arg("legacy"); // legacy dla starych kont, można później zmienić + + let status = cmd.status()?; if !status.success() { return Err(McError::Process("Minecraft exited with error".into())); @@ -71,3 +104,25 @@ pub fn launch(config: &Config, version: &Version) -> Result<(), McError> { Ok(()) } + +/// Sprawdza reguły bibliotek tak jak robi Mojang +fn library_allowed(lib: &Library) -> bool { + let rules = match &lib.rules { + | Some(r) => r, + | None => return true, + }; + + let mut allowed = false; + + for rule in rules { + let os_match = match &rule.os { + | Some(os) => os.name == "linux", + | None => true, + }; + if os_match { + allowed = rule.action == "allow"; + } + } + + allowed +} -- cgit v1.2.3