do so many things
This commit is contained in:
@@ -21,7 +21,7 @@ impl Default for EmptySession {
|
||||
Self {
|
||||
disabled: false,
|
||||
interval: Instant::now(),
|
||||
countdown: Countdown::new(features::empty_session::INTERVAL.as_secs() as usize),
|
||||
countdown: Countdown::new(features::empty_session::INTERVAL.as_secs()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
use crate::util::consts::{ENHANCED, LEGACY};
|
||||
use std::time::Instant;
|
||||
use sysinfo::System;
|
||||
|
||||
const ENHANCED: &str = "GTA5_Enhanced.exe";
|
||||
const LEGACY: &str = "GTA5.exe";
|
||||
|
||||
pub struct ForceClose {
|
||||
pub button_text: String,
|
||||
pub prompting: bool,
|
||||
@@ -20,6 +18,14 @@ impl Default for ForceClose {
|
||||
}
|
||||
}
|
||||
|
||||
impl ForceClose {
|
||||
pub fn prompting(&mut self) {
|
||||
self.button_text = "Are you sure?".to_string();
|
||||
self.prompting = true;
|
||||
self.interval = Instant::now();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn activate(sysinfo: &mut System) {
|
||||
sysinfo.refresh_all();
|
||||
sysinfo
|
||||
@@ -29,4 +35,5 @@ pub fn activate(sysinfo: &mut System) {
|
||||
.for_each(|(_, p)| {
|
||||
p.kill();
|
||||
});
|
||||
sysinfo.refresh_all();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
use crate::util::consts::{ENHANCED, LEGACY};
|
||||
use std::{path::Path, process::Command};
|
||||
use sysinfo::System;
|
||||
|
||||
const FILTER_NAME: &str = "[GTA Tools] Block all traffic for GTA V";
|
||||
|
||||
fn get_game_exe_path(sysinfo: &mut System) -> Option<&Path> {
|
||||
sysinfo.refresh_all();
|
||||
if let Some((_, process)) = sysinfo
|
||||
.processes()
|
||||
.iter()
|
||||
.find(|(_, p)| p.name() == ENHANCED || p.name() == LEGACY)
|
||||
{
|
||||
process.exe()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn block_all(sysinfo: &mut System) {
|
||||
let Some(exe_path) = get_game_exe_path(sysinfo) else {
|
||||
return;
|
||||
};
|
||||
let exe_path = exe_path.display().to_string();
|
||||
Command::new("netsh")
|
||||
.args([
|
||||
"advfirewall",
|
||||
"firewall",
|
||||
"add",
|
||||
"rule",
|
||||
&format!("name={FILTER_NAME}"),
|
||||
"dir=out",
|
||||
"action=block",
|
||||
"protocol=ANY",
|
||||
&format!("program={exe_path}"),
|
||||
])
|
||||
.spawn()
|
||||
.unwrap();
|
||||
Command::new("netsh")
|
||||
.args([
|
||||
"advfirewall",
|
||||
"firewall",
|
||||
"add",
|
||||
"rule",
|
||||
&format!("name={FILTER_NAME}"),
|
||||
"dir=in",
|
||||
"action=block",
|
||||
"protocol=ANY",
|
||||
&format!("program={exe_path}"),
|
||||
])
|
||||
.spawn()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn unblock_all() {
|
||||
Command::new("netsh")
|
||||
.args([
|
||||
"advfirewall",
|
||||
"firewall",
|
||||
"delete",
|
||||
"rule",
|
||||
&format!("name={FILTER_NAME}"),
|
||||
])
|
||||
.spawn()
|
||||
.unwrap();
|
||||
Command::new("netsh")
|
||||
.args([
|
||||
"advfirewall",
|
||||
"firewall",
|
||||
"delete",
|
||||
"rule",
|
||||
&format!("name={FILTER_NAME}"),
|
||||
])
|
||||
.spawn()
|
||||
.unwrap();
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod anti_afk;
|
||||
pub mod empty_session;
|
||||
pub mod force_close;
|
||||
pub mod game_networking;
|
||||
pub mod launch;
|
||||
|
||||
Reference in New Issue
Block a user