diff --git a/Cargo.toml b/Cargo.toml index c3afeac..7285e3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,8 @@ sysinfo = "0.33.1" windows = { version = "0.61.1", features = [ "Win32_UI_Input_KeyboardAndMouse", "Win32_System_Threading", + "Win32_UI_Shell", + "Win32_UI_WindowsAndMessaging", ] } winreg = "0.55.0" diff --git a/src/features/empty_session.rs b/src/features/empty_session.rs index 353733f..2386c22 100644 --- a/src/features/empty_session.rs +++ b/src/features/empty_session.rs @@ -11,7 +11,7 @@ const ENHANCED: &str = "GTA5_Enhanced.exe"; const LEGACY: &str = "GTA5.exe"; pub struct EmptySession { - pub enabled: bool, + pub disabled: bool, pub interval: Instant, pub countdown: Countdown, } @@ -19,7 +19,7 @@ pub struct EmptySession { impl Default for EmptySession { fn default() -> Self { Self { - enabled: true, + disabled: false, interval: Instant::now(), countdown: Countdown::new(features::empty_session::INTERVAL.as_secs() as usize), } diff --git a/src/gui.rs b/src/gui.rs index c932c1b..3cbec90 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -1,9 +1,12 @@ -use crate::features::{ - self, - anti_afk::AntiAfk, - empty_session::EmptySession, - force_close::ForceClose, - launch::{Launch, Platform}, +use crate::{ + features::{ + self, + anti_afk::AntiAfk, + empty_session::EmptySession, + force_close::ForceClose, + launch::{Launch, Platform}, + }, + util::elevate, }; use eframe::egui; use std::time::{Duration, Instant}; @@ -92,21 +95,21 @@ impl eframe::App for App { ui.label("Session"); ui.add(egui::Separator::default().horizontal()); }); - ui.add_enabled_ui(self.empty_session.enabled, |ui| { + ui.add_enabled_ui(!self.empty_session.disabled, |ui| { ui.horizontal(|ui| { if ui.button("Empty current session").clicked() { self.empty_session.interval = Instant::now(); - self.empty_session.enabled = false; + self.empty_session.disabled = true; features::empty_session::activate(self); } - if !self.empty_session.enabled { + if self.empty_session.disabled { self.empty_session.countdown.count(); } else { self.empty_session.countdown.reset(); } if self.empty_session.interval.elapsed() >= features::empty_session::INTERVAL { features::empty_session::deactivate(self); - self.empty_session.enabled = true; + self.empty_session.disabled = false; } ui.label(&self.empty_session.countdown.i_string); }); @@ -119,6 +122,14 @@ impl eframe::App for App { features::anti_afk::activate(); self.anti_afk.interval = Instant::now(); } + // ui.horizontal(|ui| { + // ui.label("Network"); + // ui.add(egui::Separator::default().horizontal()); + // }); + // if ui.button("Elevate").clicked() { + // elevate::elevate(); + // } + // ui.checkbox(&mut false, "Block connections to Rockstar"); ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| { ui.horizontal(|ui| { ui.horizontal(|ui| { @@ -127,7 +138,11 @@ impl eframe::App for App { ui.hyperlink_to("futile", "http://futile.eu"); }); ui.separator(); - ui.label(format!("v{}", env!("CARGO_PKG_VERSION"))); + ui.label(format!( + "v{} {}", + env!("CARGO_PKG_VERSION"), + if cfg!(debug_assertions) { "(dev)" } else { "" } + )); }); // ui.separator(); }); @@ -156,7 +171,7 @@ pub fn run() { viewport: egui::ViewportBuilder::default() .with_resizable(false) .with_maximize_button(false) - .with_inner_size([250.0, 180.0]) + .with_inner_size([250.0, 225.0]) .with_icon(load_icon()), centered: true, ..Default::default() diff --git a/src/util/elevate.rs b/src/util/elevate.rs new file mode 100644 index 0000000..94047fc --- /dev/null +++ b/src/util/elevate.rs @@ -0,0 +1,19 @@ +use windows::{ + Win32::UI::{Shell::ShellExecuteW, WindowsAndMessaging::SW_HIDE}, + core::{HSTRING, PCWSTR}, +}; + +pub fn elevate() { + let exe = std::env::current_exe().unwrap(); + unsafe { + ShellExecuteW( + None, + &HSTRING::from("runas"), + &HSTRING::from(exe.as_path()), + PCWSTR::null(), + PCWSTR::null(), + SW_HIDE, + ); + } + std::process::exit(0); +} diff --git a/src/util/mod.rs b/src/util/mod.rs index 6fc213d..b4bdd24 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1 +1,2 @@ pub mod countdown; +pub mod elevate;