diff --git a/Cargo.lock b/Cargo.lock index eb4e1f5..e6ea446 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,7 @@ dependencies = [ "toml", "winit", "wry", + "zip-extract", ] [[package]] @@ -67,7 +68,18 @@ checksum = "884391ef1066acaa41e766ba8f596341b96e93ce34f9a43e7d24bf0a0eaf0561" dependencies = [ "aes-soft", "aesni", - "cipher", + "cipher 0.2.5", +] + +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if 1.0.0", + "cipher 0.4.4", + "cpufeatures", ] [[package]] @@ -77,8 +89,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5278b5fabbb9bd46e24aa69b2fdea62c99088e0a950a9be40e3e0101298f88da" dependencies = [ "aead", - "aes", - "cipher", + "aes 0.6.0", + "cipher 0.2.5", "ctr", "ghash", "subtle", @@ -90,7 +102,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be14c7498ea50828a38d0e24a765ed2effe92a705885b57d029cd67d45744072" dependencies = [ - "cipher", + "cipher 0.2.5", "opaque-debug", ] @@ -100,7 +112,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea2e11f5e94c2f7d386164cc2aa1f97823fed6f259e486940a71c174dd01b0ce" dependencies = [ - "cipher", + "cipher 0.2.5", "opaque-debug", ] @@ -150,6 +162,15 @@ version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" +[[package]] +name = "arbitrary" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dde20b3d026af13f561bdd0f15edf01fc734f0dafcedbaf42bba506a9517f223" +dependencies = [ + "derive_arbitrary", +] + [[package]] name = "arrayref" version = "0.3.9" @@ -452,6 +473,25 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" +[[package]] +name = "bzip2" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49ecfb22d906f800d4fe833b6282cf4dc1c298f5057ca0b5445e5c209735ca47" +dependencies = [ + "bzip2-sys", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.13+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225bff33b2141874fe80d71e07d6eec4f85c5c216453dd96388240f96e1acc14" +dependencies = [ + "cc", + "pkg-config", +] + [[package]] name = "cairo-rs" version = "0.18.5" @@ -557,6 +597,16 @@ dependencies = [ "generic-array", ] +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + [[package]] name = "combine" version = "4.6.7" @@ -582,6 +632,12 @@ version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f8a2ca5ac02d09563609681103aada9e1777d54fc57a5acd7a41404f9c93b6e" +[[package]] +name = "constant_time_eq" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" + [[package]] name = "convert_case" version = "0.4.0" @@ -597,7 +653,7 @@ dependencies = [ "aes-gcm", "base64 0.13.1", "hkdf", - "hmac", + "hmac 0.10.1", "percent-encoding", "rand 0.8.5", "sha2 0.9.9", @@ -670,6 +726,30 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba" +[[package]] +name = "crc" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "crossbeam-channel" version = "0.5.14" @@ -738,7 +818,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb4a30d54f7443bf3d6191dcd486aca19e67cb3c49fa7a06a319966346707e7f" dependencies = [ - "cipher", + "cipher 0.2.5", ] [[package]] @@ -778,6 +858,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991" +[[package]] +name = "deflate64" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da692b8d1080ea3045efaab14434d40468c3d8657e42abddfffca87b428f4c1b" + [[package]] name = "deranged" version = "0.3.11" @@ -787,6 +873,17 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "derive_arbitrary" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30542c1ad912e0e3d22a1935c290e12e8a29d704a420177a31faad4a601a0800" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", +] + [[package]] name = "derive_more" version = "0.99.19" @@ -817,6 +914,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", "crypto-common", + "subtle", ] [[package]] @@ -982,6 +1080,16 @@ dependencies = [ "rustc_version 0.4.1", ] +[[package]] +name = "flate2" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11faaf5a5236997af9848be0bef4db95824b1d534ebc64d0f0c6cf3e67bd38dc" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "flume" version = "0.9.2" @@ -1568,7 +1676,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f" dependencies = [ "digest 0.9.0", - "hmac", + "hmac 0.10.1", ] [[package]] @@ -1581,6 +1689,15 @@ dependencies = [ "digest 0.9.0", ] +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "html5ever" version = "0.26.0" @@ -1882,6 +1999,15 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64e9829a50b42bb782c1df523f78d332fe371b10c661e78b7a3c34b0198e9fac" +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", +] + [[package]] name = "instant" version = "0.1.13" @@ -2114,6 +2240,12 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "lockfree-object-pool" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9374ef4228402d4b7e403e5838cb880d9ee663314b0a900d5a6aabf0c213552e" + [[package]] name = "log" version = "0.4.26" @@ -2123,6 +2255,16 @@ dependencies = [ "value-bag", ] +[[package]] +name = "lzma-rs" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "297e814c836ae64db86b36cf2a557ba54368d03f6afcd7d947c266692f71115e" +dependencies = [ + "byteorder", + "crc", +] + [[package]] name = "mac" version = "0.1.1" @@ -2761,6 +2903,16 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "pbkdf2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" +dependencies = [ + "digest 0.10.7", + "hmac 0.12.1", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -3454,6 +3606,17 @@ dependencies = [ "sha1_smol", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.7", +] + [[package]] name = "sha1_smol" version = "1.0.1" @@ -3499,6 +3662,12 @@ dependencies = [ "libc", ] +[[package]] +name = "simd-adler32" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" + [[package]] name = "siphasher" version = "0.3.11" @@ -3681,7 +3850,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "sha1", + "sha1 0.6.1", "syn 1.0.109", ] @@ -5244,6 +5413,26 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", +] + [[package]] name = "zerovec" version = "0.10.4" @@ -5265,3 +5454,85 @@ dependencies = [ "quote", "syn 2.0.100", ] + +[[package]] +name = "zip" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b280484c454e74e5fff658bbf7df8fdbe7a07c6b2de4a53def232c15ef138f3a" +dependencies = [ + "aes 0.8.4", + "arbitrary", + "bzip2", + "constant_time_eq", + "crc32fast", + "crossbeam-utils", + "deflate64", + "displaydoc", + "flate2", + "hmac 0.12.1", + "indexmap 2.8.0", + "lzma-rs", + "memchr", + "pbkdf2", + "rand 0.8.5", + "sha1 0.10.6", + "thiserror 2.0.12", + "time 0.3.39", + "zeroize", + "zopfli", + "zstd", +] + +[[package]] +name = "zip-extract" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a8c9e90f27d1435088a7b540b6cc8ae6ee525d992a695f16012d2f365b3d3c" +dependencies = [ + "log", + "thiserror 1.0.69", + "zip", +] + +[[package]] +name = "zopfli" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5019f391bac5cf252e93bbcc53d039ffd62c7bfb7c150414d61369afe57e946" +dependencies = [ + "bumpalo", + "crc32fast", + "lockfree-object-pool", + "log", + "once_cell", + "simd-adler32", +] + +[[package]] +name = "zstd" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3051792fbdc2e1e143244dc28c60f73d8470e93f3f9cbd0ead44da5ed802722" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.14+zstd.1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fb060d4926e4ac3a3ad15d864e99ceb5f343c6b34f5bd6d81ae6ed417311be5" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml index 7708d96..570e3bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,5 @@ serde = { version = "1.0.219", features = ["derive"] } serde_json = "1.0" toml = "0.8.20" surf = { version = "2.3.2", features = ["hyper-client"] } -base64 = "0.22.1" \ No newline at end of file +base64 = "0.22.1" +zip-extract = "0.2.1" \ No newline at end of file diff --git a/src/launcher.rs b/src/launcher.rs index 7da06a8..60e3428 100644 --- a/src/launcher.rs +++ b/src/launcher.rs @@ -1,12 +1,32 @@ use core::str; +use std::io::Cursor; use base64::{encode, Engine}; use base64::prelude::BASE64_STANDARD; use tokio::fs::File; +use tokio::process::Command; use tokio::sync::mpsc; use tokio::sync::mpsc::UnboundedSender; use crate::minecraft::versions::Version; use crate::{config::LauncherConfig, minecraft::versions::VersionConfig, util}; +const JAVA_ARGS: [&str; 23] = ["-Xms1024M", +"-XX:+UnlockExperimentalVMOptions", +"-XX:+DisableExplicitGC", +"-XX:MaxGCPauseMillis=200", +"-XX:+AlwaysPreTouch", +"-XX:+ParallelRefProcEnabled", +"-XX:+UseG1GC", +"-XX:G1NewSizePercent=30", +"-XX:G1MaxNewSizePercent=40", +"-XX:G1HeapRegionSize=8M", +"-XX:G1ReservePercent=20", +"-XX:InitiatingHeapOccupancyPercent=15", +"-XX:G1HeapWastePercent=5", +"-XX:G1MixedGCCountTarget=4", +"-XX:G1MixedGCLiveThresholdPercent=90", +"-XX:G1RSetUpdatingPauseTimePercent=5", +"-XX:+UseStringDeduplication", "-Xmx1024M", "-Dfile.encoding=UTF-8", "-Dfml.ignoreInvalidMinecraftCertificates=true", "-Dfml.ignorePatchDiscrepancies=true", "-Djava.net.useSystemProxies=true", "-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump"]; + #[derive(Default)] pub struct Launcher { pub config: LauncherConfig, @@ -60,6 +80,68 @@ impl Launcher { v } + pub async fn launch_instance(&self, instance_name: String) { + let mut instances = self.config.launcher_dir(); + instances.push("instances"); + instances.push(&instance_name); + instances.push("client.json"); + + let mut client_jar = self.config.launcher_dir(); + client_jar.push("instances"); + client_jar.push(&instance_name); + client_jar.push("client.jar"); + + let mut cmd = Vec::new(); + //cmd.push("java".to_string()); + + for arg in JAVA_ARGS { + cmd.push(arg.to_string()); + } + + let mut natives_path = self.config.launcher_dir(); + natives_path.push("instances"); + natives_path.push(&instance_name); + natives_path.push("natives"); + + cmd.push(["-Djava.library.path=", natives_path.to_str().unwrap() ].concat()); + cmd.push(["-Dminecraft.client.jar=", client_jar.to_str().unwrap()].concat()); + cmd.push("-cp".to_string()); + + if let Ok(data) = std::fs::read(&instances) { + let config: VersionConfig = serde_json::from_slice(&data).unwrap(); + let mut libraries_cmd = Vec::new(); + for library in config.libraries { + if let Some(classifier) = &library.downloads.classifiers { + if let Some(natives) = &classifier.natives { + let rel_path = &natives.path; + let mut libs = self.config.launcher_dir(); + libs.push("libraries"); + let rel_path = [libs.to_str().unwrap(), "\\", &rel_path.replace("/", "\\")].concat(); + let data = std::fs::read(rel_path).unwrap(); + + zip_extract::extract(Cursor::new(data), &natives_path, true); + } + } else { + let mut libs = self.config.launcher_dir(); + libs.push("libraries"); + libs.push(library.to_pathbuf_file()); + libraries_cmd.push([libs.to_str().unwrap(), ";"].concat()); + } + } + libraries_cmd.push(client_jar.to_str().unwrap().to_string()); + cmd.push(libraries_cmd.concat()); + cmd.push(config.mainClass.clone()); + } + + let mut game_dir = self.config.launcher_dir(); + game_dir.push("instances"); + game_dir.push(&instance_name); + game_dir.push("data"); + + cmd.push(["--username", "getter", "--version", "1.9.4", "--gameDir", game_dir.to_str().unwrap(), "--assetsDir", "D:\\Documents\\RustroverProjects\\XCraft\\xcraft\\assets", "--assetIndex", "1.9", "--uuid", "51820246d9fe372b81592602a5239ad9", "--accessToken", "51820246d9fe372b81592602a5239ad9", "--userProperties", "{}", "--userType", "legacy", "--width", "925", "--height", "530"].join(" ")); + } + + pub async fn new_vanilla_instance(&mut self, config: VersionConfig, version_object: &Version, sender: UnboundedSender<(u8, String)>) { let (sx, mut rx) = mpsc::unbounded_channel(); diff --git a/src/main.rs b/src/main.rs index 567dd6c..d0be580 100644 --- a/src/main.rs +++ b/src/main.rs @@ -156,6 +156,10 @@ async fn main() { responder.respond(Response::new(vec![])); } } + "run_instance" => { + let instance_name = params.unwrap().params[0].clone(); + launcher.launch_instance(instance_name).await; + } _ => {} } } diff --git a/src/www/portable.html b/src/www/portable.html index d334126..7726c8c 100644 --- a/src/www/portable.html +++ b/src/www/portable.html @@ -437,6 +437,10 @@ $.post({url: "fetch_instances_list" }, processParams); } + function runInstance(version) { + $.post({url: "run_instance", data: JSON.stringify({ params: [version] })}, processParams); + } + function downloadSelectedVersion() { let version = $('#mc-version :selected').text(); $.post({url: "download_vanilla", data: JSON.stringify({ params: [version] })}, processParams);