adapt codebase to own, new system info impl
This commit is contained in:
@@ -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<u32> {
|
||||
sysinfo.refresh_all();
|
||||
if let Some((pid, _)) = sysinfo
|
||||
fn get_gta_pid(system_info: &mut SystemInfo) -> Option<u32> {
|
||||
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 {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+11
-6
@@ -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"))
|
||||
|
||||
+6
-9
@@ -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:#?}")));
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+9
-15
@@ -18,26 +18,26 @@ use windows::{
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Process {
|
||||
pub struct Process {
|
||||
pid: u32,
|
||||
name: String,
|
||||
exe: Option<PathBuf>,
|
||||
}
|
||||
|
||||
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<Process>,
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user