diff --git a/Cargo.lock b/Cargo.lock index a41b005..a1f8e8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -837,8 +837,7 @@ dependencies = [ "serde_json", "static_vcruntime", "strum", - "sysinfo", - "windows 0.62.0", + "windows", "winreg", "winresource", ] @@ -1263,15 +1262,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" -[[package]] -name = "ntapi" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" -dependencies = [ - "winapi", -] - [[package]] name = "num-traits" version = "0.2.19" @@ -1471,16 +1461,6 @@ dependencies = [ "objc2-core-foundation", ] -[[package]] -name = "objc2-io-kit" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71c1c64d6120e51cd86033f67176b1cb66780c2efe34dec55176f77befd93c0a" -dependencies = [ - "libc", - "objc2-core-foundation", -] - [[package]] name = "objc2-io-surface" version = "0.3.1" @@ -2130,20 +2110,6 @@ dependencies = [ "syn", ] -[[package]] -name = "sysinfo" -version = "0.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07cec4dc2d2e357ca1e610cfb07de2fa7a10fc3e9fe89f72545f3d244ea87753" -dependencies = [ - "libc", - "memchr", - "ntapi", - "objc2-core-foundation", - "objc2-io-kit", - "windows 0.61.3", -] - [[package]] name = "thiserror" version = "1.0.69" @@ -2595,39 +2561,17 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows" -version = "0.61.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" -dependencies = [ - "windows-collections 0.2.0", - "windows-core 0.61.2", - "windows-future 0.2.1", - "windows-link 0.1.3", - "windows-numerics 0.2.0", -] - [[package]] name = "windows" version = "0.62.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9579d0e6970fd5250aa29aba5994052385ff55cf7b28a059e484bb79ea842e42" dependencies = [ - "windows-collections 0.3.0", + "windows-collections", "windows-core 0.62.0", - "windows-future 0.3.0", + "windows-future", "windows-link 0.2.0", - "windows-numerics 0.3.0", -] - -[[package]] -name = "windows-collections" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" -dependencies = [ - "windows-core 0.61.2", + "windows-numerics", ] [[package]] @@ -2665,17 +2609,6 @@ dependencies = [ "windows-strings 0.5.0", ] -[[package]] -name = "windows-future" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" -dependencies = [ - "windows-core 0.61.2", - "windows-link 0.1.3", - "windows-threading 0.1.0", -] - [[package]] name = "windows-future" version = "0.3.0" @@ -2684,7 +2617,7 @@ checksum = "b2194dee901458cb79e1148a4e9aac2b164cc95fa431891e7b296ff0b2f1d8a6" dependencies = [ "windows-core 0.62.0", "windows-link 0.2.0", - "windows-threading 0.2.0", + "windows-threading", ] [[package]] @@ -2721,16 +2654,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65" -[[package]] -name = "windows-numerics" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" -dependencies = [ - "windows-core 0.61.2", - "windows-link 0.1.3", -] - [[package]] name = "windows-numerics" version = "0.3.0" @@ -2861,15 +2784,6 @@ dependencies = [ "windows_x86_64_msvc 0.53.0", ] -[[package]] -name = "windows-threading" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6" -dependencies = [ - "windows-link 0.1.3", -] - [[package]] name = "windows-threading" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 1ec3392..a2a947b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,6 @@ open = "5.3.2" serde = { version = "1.0.219", features = ["derive"] } serde_json = "1.0.143" strum = { version = "0.27.2", features = ["derive"] } -sysinfo = "0.37.0" windows = { version = "0.62.0", features = [ "Win32_NetworkManagement_WindowsFirewall", "Win32_Security", diff --git a/src/features/empty_session.rs b/src/features/empty_session.rs index 31c9e2e..15d2bee 100644 --- a/src/features/empty_session.rs +++ b/src/features/empty_session.rs @@ -2,9 +2,9 @@ use crate::util::{ consts::game::{EXE_ENHANCED, EXE_LEGACY}, countdown::Countdown, log, + system_info::SystemInfo, }; use std::time::{Duration, Instant}; -use sysinfo::System; use windows::Win32::{ Foundation::{CloseHandle, HANDLE, NTSTATUS}, System::Threading::{OpenProcess, PROCESS_SUSPEND_RESUME}, @@ -49,21 +49,21 @@ unsafe extern "system" { unsafe fn NtResumeProcess(ProcessHandle: HANDLE) -> NTSTATUS; } -fn get_gta_pid(sysinfo: &mut System) -> Option { - sysinfo.refresh_all(); - if let Some((pid, _)) = sysinfo +fn get_gta_pid(system_info: &mut SystemInfo) -> Option { + system_info.refresh(); + if let Some(p) = system_info .processes() .iter() - .find(|(_, p)| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY) + .find(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY) { - return Some(pid.as_u32()); + return Some(p.pid()); } else { return None; } } -pub fn activate(game_handle: &mut HANDLE, sysinfo: &mut System) -> Result<(), ()> { - let Some(pid) = get_gta_pid(sysinfo) else { +pub fn activate(game_handle: &mut HANDLE, system_info: &mut SystemInfo) -> Result<(), ()> { + let Some(pid) = get_gta_pid(system_info) else { return Err(()); }; unsafe { diff --git a/src/features/force_close.rs b/src/features/force_close.rs index 6f39a0a..2ee8a7d 100644 --- a/src/features/force_close.rs +++ b/src/features/force_close.rs @@ -1,9 +1,9 @@ use crate::util::{ consts::game::{EXE_ENHANCED, EXE_LEGACY}, log, + system_info::SystemInfo, }; use std::time::{Duration, Instant}; -use sysinfo::System; const INTERVAL: Duration = Duration::from_secs(3); @@ -27,7 +27,7 @@ impl Default for ForceClose { } impl ForceClose { - pub fn prompt(&mut self, force_close_button_clicked: bool, sysinfo: &mut System) { + pub fn prompt(&mut self, force_close_button_clicked: bool, system_info: &mut SystemInfo) { if force_close_button_clicked && !self.counting { self.button_text = "Are you sure?".to_owned(); self.timer = Instant::now(); @@ -37,7 +37,7 @@ impl ForceClose { if self.counting && self.timer.elapsed() >= INTERVAL { self.reset(); } else if force_close_button_clicked && !self.current_frame { - activate(sysinfo); + activate(system_info); self.reset(); } self.finish_current_frame(); @@ -54,13 +54,13 @@ impl ForceClose { } } -fn activate(sysinfo: &mut System) { - sysinfo.refresh_all(); - sysinfo +fn activate(system_info: &mut SystemInfo) { + system_info.refresh(); + system_info .processes() .iter() - .filter(|(_, p)| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY) - .for_each(|(_, p)| { + .filter(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY) + .for_each(|p| { if p.kill() == false { log::log( log::LogLevel::Error, @@ -68,5 +68,5 @@ fn activate(sysinfo: &mut System) { ); } }); - sysinfo.refresh_all(); + system_info.refresh(); } diff --git a/src/features/game_networking.rs b/src/features/game_networking.rs index 012ea63..399a470 100644 --- a/src/features/game_networking.rs +++ b/src/features/game_networking.rs @@ -1,10 +1,12 @@ -use crate::util::consts::game::{EXE_ENHANCED, EXE_LEGACY}; +use crate::util::{ + consts::game::{EXE_ENHANCED, EXE_LEGACY}, + system_info::SystemInfo, +}; use std::{ path::Path, time::{Duration, Instant}, }; use strum::{Display, EnumIter}; -use sysinfo::System; use windows::{ Win32::{ NetworkManagement::WindowsFirewall::{ @@ -71,8 +73,8 @@ impl Drop for GameNetworking { } impl GameNetworking { - pub fn block_all(&mut self, sysinfo: &mut System) { - let Some(exe_path) = get_game_exe_path(sysinfo) else { + pub fn block_all(&mut self, system_info: &mut SystemInfo) { + let Some(exe_path) = get_game_exe_path(system_info) else { self.blocked_status = BlockedStatus::Failed; return; }; @@ -133,12 +135,12 @@ impl GameNetworking { } } -fn get_game_exe_path(sysinfo: &mut System) -> Option<&Path> { - sysinfo.refresh_all(); - if let Some((_, process)) = sysinfo +fn get_game_exe_path(system_info: &mut SystemInfo) -> Option<&Path> { + system_info.refresh(); + if let Some(process) = system_info .processes() .iter() - .find(|(_, p)| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY) + .find(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY) { process.exe() } else { diff --git a/src/gui/app.rs b/src/gui/app.rs index ebc7e55..83ef721 100644 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -1,7 +1,9 @@ use crate::{ features, gui::{colours, settings::Settings, tools, ui_ext::UiExt}, - util::{consts::game::WINDOW_TITLE, persistent_state::PersistentState, win}, + util::{ + consts::game::WINDOW_TITLE, persistent_state::PersistentState, system_info::SystemInfo, win, + }, }; use eframe::egui; use std::time::{Duration, Instant}; @@ -39,7 +41,7 @@ pub struct App { pub settings: Settings, stage: Stage, pub flags: Flags, - pub sysinfo: sysinfo::System, + pub system_info: SystemInfo, game_handle: windows::Win32::Foundation::HANDLE, pub anti_afk: features::anti_afk::AntiAfk, empty_session: features::empty_session::EmptySession, @@ -108,7 +110,7 @@ impl App { egui::Button::new(&self.force_close.button_text), ); self.force_close - .prompt(force_close_button.clicked(), &mut self.sysinfo); + .prompt(force_close_button.clicked(), &mut self.system_info); } fn show_session_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) { @@ -116,8 +118,11 @@ impl App { ui.add_enabled_ui(!self.empty_session.disabled, |ui| { ui.horizontal(|ui| { if ui.button("Empty current session").clicked() { - if features::empty_session::activate(&mut self.game_handle, &mut self.sysinfo) - .is_ok() + if features::empty_session::activate( + &mut self.game_handle, + &mut self.system_info, + ) + .is_ok() { self.empty_session.interval = Instant::now(); self.empty_session.disabled = true; @@ -169,7 +174,7 @@ impl App { .add_sized([button_width, 18.0], egui::Button::new("Block")) .clicked() { - self.game_networking.block_all(&mut self.sysinfo); + self.game_networking.block_all(&mut self.system_info); } if ui .add_sized([button_width, 18.0], egui::Button::new("Unblock")) diff --git a/src/gui/debug.rs b/src/gui/debug.rs index 92bc4b5..11dcb0c 100644 --- a/src/gui/debug.rs +++ b/src/gui/debug.rs @@ -48,19 +48,16 @@ impl App { )); ui.label(format!("can activate: {}", self.anti_afk.can_activate())); }); - ui.collapsing("sysinfo", |ui| { - if ui.button("refresh all").clicked() { - self.sysinfo.refresh_all(); + ui.collapsing("system info", |ui| { + if ui.button("refresh").clicked() { + self.system_info.refresh(); } let pid = self - .sysinfo + .system_info .processes() .iter() - .find(|(_, p)| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY) - .map_or_else( - || "no pid found!".to_owned(), - |(pid, _)| pid.as_u32().to_string(), - ); + .find(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY) + .map_or_else(|| "no pid found!".to_owned(), |p| p.pid().to_string()); ui.label(format!("gta pid: {pid}")); }); ui.collapsing("app state", |ui| ui.label(format!("{self:#?}"))); diff --git a/src/gui/run.rs b/src/gui/run.rs index 3e32f82..f675e4a 100644 --- a/src/gui/run.rs +++ b/src/gui/run.rs @@ -21,8 +21,8 @@ fn app_creator( if !app.flags.elevated && app.settings.start_elevated { win::elevate(win::ElevationExitMethod::Forced); } - // refresh sysinfo because it initializes with nothing - app.sysinfo.refresh_all(); + // refresh system info because it initializes with nothing + app.system_info.refresh(); // enable image loading support in egui egui_extras::install_image_loaders(&cc.egui_ctx); // set our initial theme, from earlier loaded settings. we set the egui theme diff --git a/src/util/system_info.rs b/src/util/system_info.rs index 29ed1ca..c9c545a 100644 --- a/src/util/system_info.rs +++ b/src/util/system_info.rs @@ -18,26 +18,26 @@ use windows::{ }; #[derive(Clone, Debug)] -struct Process { +pub struct Process { pid: u32, name: String, exe: Option, } impl Process { - fn pid(&self) -> u32 { + pub fn pid(&self) -> u32 { self.pid } - fn name(&self) -> &str { + pub fn name(&self) -> &str { &self.name } - fn exe(&self) -> Option<&Path> { + pub fn exe(&self) -> Option<&Path> { self.exe.as_deref() } - fn kill(&self) -> bool { + pub fn kill(&self) -> bool { let mut taskkill = Command::new("taskkill.exe"); taskkill.creation_flags(CREATE_NO_WINDOW.0); taskkill.arg("/F").arg("/PID").arg(&self.pid.to_string()); @@ -48,20 +48,14 @@ impl Process { } } -#[derive(Debug)] -struct SystemInfo { +#[derive(Debug, Default)] +pub struct SystemInfo { processes: Vec, } impl SystemInfo { - fn new() -> Self { - Self { - processes: Vec::new(), - } - } - // TODO: unfuck this retarded function - fn refresh(&mut self) { + pub fn refresh(&mut self) { let mut processes = Vec::new(); let snapshot_handle = unsafe { CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0).unwrap() }; let mut process_entry = PROCESSENTRY32::default(); @@ -136,7 +130,7 @@ impl SystemInfo { self.processes = processes; } - fn processes(&self) -> &[Process] { + pub fn processes(&self) -> &[Process] { &self.processes } }