From b317a8a652d2e3a48c8b9f4940c7933d3802cfc3 Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Mon, 20 Jan 2025 04:33:28 -0600 Subject: it runs the game --- src/launcher/runner.rs | 70 ++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 33 deletions(-) (limited to 'src/launcher/runner.rs') diff --git a/src/launcher/runner.rs b/src/launcher/runner.rs index 4d07f20..8c7af3d 100644 --- a/src/launcher/runner.rs +++ b/src/launcher/runner.rs @@ -1,13 +1,14 @@ use std::borrow::Cow; -use std::ffi::OsString; +use std::ffi::{OsStr, OsString}; use std::iter; -use crate::version::{CompleteVersion, FeatureMatcher}; +use std::process::Command; +use crate::version::{CompleteVersion, FeatureMatcher, OperatingSystem}; use super::rules::CompatCheck; use super::strsub::{self, SubFunc}; -use super::LaunchInfo; +use super::{Launch, LaunchInfo}; #[derive(Clone, Copy)] -struct LaunchArgSub<'a: 'l, 'l, F: FeatureMatcher>(&'a LaunchInfo<'l, F>); +struct LaunchArgSub<'a, 'l, F: FeatureMatcher>(&'a LaunchInfo<'l, F>); impl<'rep, 'l, F: FeatureMatcher> SubFunc<'rep> for LaunchArgSub<'rep, 'l, F> { fn substitute(&self, key: &str) -> Option> { @@ -59,32 +60,6 @@ pub enum ArgumentType { Game } -struct OptionalIterator -where - I: Iterator -{ - opt: Option -} - -impl Iterator for OptionalIterator { - type Item = I::Item; - - fn next(&mut self) -> Option { - match self.opt { - Some(ref mut i) => i.next(), - None => None - } - } -} - -impl From> for OptionalIterator { - fn from(opt: Option) -> Self { - OptionalIterator { - opt: opt.map(IntoIterator::into_iter) - } - } -} - pub fn build_arguments<'l, F: FeatureMatcher>(launch: &LaunchInfo<'l, F>, version: &CompleteVersion, arg_type: ArgumentType) -> Vec { let sub = LaunchArgSub(launch); let system_info = &launch.launcher.system_info; @@ -94,13 +69,31 @@ pub fn build_arguments<'l, F: FeatureMatcher>(launch: &LaunchInfo<'l, F>, versio ArgumentType::Game => args.game.as_ref() }) { arguments.iter() - .flat_map(|wa| OptionalIterator::from(wa.rules_apply(system_info, launch.feature_matcher).ok().map(|_| &wa.value))) + .filter(|wa| wa.rules_apply(system_info, launch.feature_matcher).is_ok()) + .flat_map(|wa| &wa.value) .map(|s| OsString::from(strsub::replace_string(s, &sub).into_owned())).collect() } else if let Some(arguments) = version.minecraft_arguments.as_ref() { match arg_type { ArgumentType::JVM => { - todo!() - } + [ + "-Djava.library.path=${natives_directory}", + "-Dminecraft.launcher.brand=${launcher_name}", + "-Dminecraft.launcher.version=${launcher_version}", + "-Dminecraft.client.jar=${primary_jar}", + "-cp", + "${classpath}" + ].into_iter() + .chain(iter::once("-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump") + .take_while(|_| system_info.os == OperatingSystem::Windows)) + .chain(iter::once(["-Dos.name=Windows 10", "-Dos.version=10.0"]) + .take_while(|_| launch.feature_matcher.matches("__ozone_win10_hack")) + .flatten()) + .chain(iter::once(["-Xdock:icon=${asset=icons/minecraft.icns}", "-Xdock:name=Minecraft"]) + .take_while(|_| system_info.os == OperatingSystem::MacOS) + .flatten()) + .map(|s| OsString::from(strsub::replace_string(s, &sub).into_owned())) + .collect() + }, ArgumentType::Game => { arguments.split(' ') .chain(iter::once("--demo") @@ -116,3 +109,14 @@ pub fn build_arguments<'l, F: FeatureMatcher>(launch: &LaunchInfo<'l, F>, versio Vec::default() } } + +pub fn run_the_game(launch: &Launch) -> Result<(), Box> { + Command::new("/usr/lib/jvm/java-8-openjdk-amd64/bin/java") + .args(launch.jvm_args.iter() + .map(|o| o.as_os_str()) + .chain(iter::once(OsStr::new(launch.main_class.as_str()))) + .chain(launch.game_args.iter().map(|o| o.as_os_str()))) + .current_dir(launch.instance_path.as_path()).spawn()?.wait()?; + + Ok(()) +} -- cgit v1.2.3-70-g09d2