diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index b423c6b1..98d36884 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1864,6 +1864,26 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "gumdrop" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bc700f989d2f6f0248546222d9b4258f5b02a171a431f8285a81c08142629e3" +dependencies = [ + "gumdrop_derive", +] + +[[package]] +name = "gumdrop_derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "729f9bd3449d77e7831a18abfb7ba2f99ee813dfd15b8c2167c9a54ba20aa99d" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "h2" version = "0.3.26" @@ -2127,7 +2147,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2821,11 +2841,11 @@ dependencies = [ "chardet", "chardetng", "charset-normalizer-rs", - "clap", "dirs-next", "discord-rich-presence", "dll-syringe", "encoding_rs", + "gumdrop", "log", "md5", "regex", @@ -2841,6 +2861,7 @@ dependencies = [ "tauri-plugin-upload", "tokio", "winapi", + "windows 0.58.0", "winreg 0.52.0", ] @@ -4299,7 +4320,7 @@ dependencies = [ "unicode-segmentation", "uuid 1.10.0", "windows 0.39.0", - "windows-implement", + "windows-implement 0.39.0", "x11-dl", ] @@ -5538,7 +5559,7 @@ dependencies = [ "webview2-com-macros", "webview2-com-sys", "windows 0.39.0", - "windows-implement", + "windows-implement 0.39.0", ] [[package]] @@ -5635,7 +5656,7 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1c4bd0a50ac6020f65184721f758dba47bb9fbc2133df715ec74a237b26794a" dependencies = [ - "windows-implement", + "windows-implement 0.39.0", "windows_aarch64_msvc 0.39.0", "windows_i686_gnu 0.39.0", "windows_i686_msvc 0.39.0", @@ -5658,7 +5679,17 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" dependencies = [ - "windows-core", + "windows-core 0.52.0", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core 0.58.0", "windows-targets 0.52.6", ] @@ -5681,6 +5712,19 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement 0.58.0", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + [[package]] name = "windows-implement" version = "0.39.0" @@ -5691,12 +5735,53 @@ dependencies = [ "windows-tokens", ] +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.71", +] + +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.71", +] + [[package]] name = "windows-metadata" version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ee5e275231f07c6e240d14f34e1b635bf1faa1c76c57cfd59a5cdb9848e4278" +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.42.0" @@ -6065,7 +6150,7 @@ dependencies = [ "webkit2gtk-sys", "webview2-com", "windows 0.39.0", - "windows-implement", + "windows-implement 0.39.0", ] [[package]] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 8b14c3f0..c0141824 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -35,14 +35,17 @@ md5 = "0.7" actix-web = "4" actix-rt = "2" actix-cors = "0.7" -clap = "4" winapi = "0.3" tauri-plugin-deep-link = "0.1.2" +gumdrop = "0.8.1" [target.'cfg(target_os = "windows")'.dependencies] dll-syringe = "0.15" winreg = "0.52" +[target."cfg(windows)".dependencies] +windows = { version = "0.58.0", features = ["Win32_System_Console", "Win32_Foundation"] } + [features] # this feature is used for production builds or when `devPath` points to the filesystem # DO NOT REMOVE!! diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 0cd25145..08085541 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -8,37 +8,31 @@ mod query; mod rpcs; mod samp; +use std::env; use std::process::exit; -use clap::Parser; +use gumdrop::Options; use injector::run_samp; use log::{error, LevelFilter}; use tauri::Manager; use tauri::PhysicalSize; -/// Simple program to greet a person -#[derive(Parser, Debug)] -#[command(version, about, long_about = None)] -#[clap(disable_help_flag = true)] -struct Args { - #[clap(long, action = clap::ArgAction::HelpLong)] - help: Option, +#[derive(Debug, Options)] +struct CliArgs { + #[options(no_short, help = "print help message")] + help: bool, - /// Server IP - #[arg(short, long, default_value_t = String::new())] - host: String, + #[options(help = "target server IP address")] + host: Option, - /// Server port - #[arg(short, long, default_value_t = 0)] - port: i32, + #[options(help = "target server port")] + port: Option, - /// Nickname - #[arg(short, long, default_value_t = String::new())] - name: String, + #[options(help = "nickname to join server with")] + name: Option, - /// Game path - #[arg(short, long, default_value_t = String::new())] - gamepath: String, + #[options(help = "game path to use for both game executable and samp.dll")] + gamepath: Option, } // Learn more about Tauri commands at https://tauri.app/v1/guides/features/command @@ -88,28 +82,66 @@ async fn main() { tauri_plugin_deep_link::prepare("com.open.mp"); simple_logging::log_to_file("omp-launcher.log", LevelFilter::Info).unwrap(); - let args = Args::parse(); - if args.host.len() > 0 && args.name.len() > 0 && args.port > 0 { - if args.gamepath.len() > 0 { - let _ = run_samp( - args.name.as_str(), - args.host.as_str(), - args.port, - args.gamepath.as_str(), - format!("{}/samp.dll", args.gamepath).as_str(), - format!( - "{}/com.open.mp/omp/omp-client.dll", - dirs_next::data_local_dir().unwrap().to_str().unwrap() - ) - .as_str(), - "", - ) - .await; - exit(0) - } else { - println!("You must provide game path using --game or -g. Read more about arguments in --help"); - exit(0) + #[cfg(windows)] + { + use windows::Win32::System::Console::{AttachConsole, ATTACH_PARENT_PROCESS}; + let _ = unsafe { AttachConsole(ATTACH_PARENT_PROCESS) }; + } + + let raw_args: Vec = env::args().collect(); + let parse_args_result = CliArgs::parse_args_default::(&raw_args[1..]); + match parse_args_result { + Ok(args) => { + if args.help { + println!( + "Open Multiplayer Launcher + +Usage: {} [OPTIONS] + +Options: + --help + -h, --host Server IP + -p, --port Server port + -n, --name Nickname + -g, --gamepath Game path + ", + raw_args[0] + ); + exit(0) + } + + if args.host.is_some() && args.name.is_some() && args.port.is_some() { + if args.gamepath.is_some() && args.gamepath.as_ref().unwrap().len() > 0 { + let _ = run_samp( + args.name.unwrap().as_str(), + args.host.unwrap().as_str(), + args.port.unwrap(), + args.gamepath.as_ref().unwrap().as_str(), + format!("{}/samp.dll", args.gamepath.as_ref().unwrap()).as_str(), + format!( + "{}/com.open.mp/omp/omp-client.dll", + dirs_next::data_local_dir().unwrap().to_str().unwrap() + ) + .as_str(), + "", + ) + .await; + exit(0) + } else { + println!("You must provide game path using --game or -g. Read more about arguments in --help"); + exit(0) + } + } } + Err(e) => { + println!("{}", e); + } + }; + + #[cfg(windows)] + { + use windows::Win32::System::Console::FreeConsole; + let _ = unsafe { FreeConsole() }; } std::thread::spawn(move || {