some little fixes
This commit is contained in:
@@ -6,7 +6,7 @@ use windows::Win32::{
|
|||||||
System::Threading::{OpenProcess, PROCESS_SUSPEND_RESUME},
|
System::Threading::{OpenProcess, PROCESS_SUSPEND_RESUME},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const INTERVAL: Duration = Duration::from_secs(10);
|
pub const INTERVAL: Duration = Duration::from_secs(8);
|
||||||
const ENHANCED: &str = "GTA5_Enhanced.exe";
|
const ENHANCED: &str = "GTA5_Enhanced.exe";
|
||||||
const LEGACY: &str = "GTA5.exe";
|
const LEGACY: &str = "GTA5.exe";
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
|
#![allow(clippy::zombie_processes)]
|
||||||
|
|
||||||
use crate::util::consts::{ENHANCED, LEGACY};
|
use crate::util::consts::{ENHANCED, LEGACY};
|
||||||
use std::{path::Path, process::Command};
|
use std::{os::windows::process::CommandExt, path::Path, process::Command};
|
||||||
use sysinfo::System;
|
use sysinfo::System;
|
||||||
|
|
||||||
const FILTER_NAME: &str = "[GTA Tools] Block all traffic for GTA V";
|
const FILTER_NAME: &str = "[GTA Tools] Block all traffic for GTA V";
|
||||||
|
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
|
||||||
|
|
||||||
fn get_game_exe_path(sysinfo: &mut System) -> Option<&Path> {
|
fn get_game_exe_path(sysinfo: &mut System) -> Option<&Path> {
|
||||||
sysinfo.refresh_all();
|
sysinfo.refresh_all();
|
||||||
@@ -34,6 +37,7 @@ pub fn block_all(sysinfo: &mut System) {
|
|||||||
"protocol=ANY",
|
"protocol=ANY",
|
||||||
&format!("program={exe_path}"),
|
&format!("program={exe_path}"),
|
||||||
])
|
])
|
||||||
|
.creation_flags(CREATE_NO_WINDOW)
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Command::new("netsh")
|
Command::new("netsh")
|
||||||
@@ -48,6 +52,7 @@ pub fn block_all(sysinfo: &mut System) {
|
|||||||
"protocol=ANY",
|
"protocol=ANY",
|
||||||
&format!("program={exe_path}"),
|
&format!("program={exe_path}"),
|
||||||
])
|
])
|
||||||
|
.creation_flags(CREATE_NO_WINDOW)
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
@@ -61,16 +66,7 @@ pub fn unblock_all() {
|
|||||||
"rule",
|
"rule",
|
||||||
&format!("name={FILTER_NAME}"),
|
&format!("name={FILTER_NAME}"),
|
||||||
])
|
])
|
||||||
.spawn()
|
.creation_flags(CREATE_NO_WINDOW)
|
||||||
.unwrap();
|
|
||||||
Command::new("netsh")
|
|
||||||
.args([
|
|
||||||
"advfirewall",
|
|
||||||
"firewall",
|
|
||||||
"delete",
|
|
||||||
"rule",
|
|
||||||
&format!("name={FILTER_NAME}"),
|
|
||||||
])
|
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-15
@@ -16,6 +16,8 @@ use std::time::{Duration, Instant};
|
|||||||
use sysinfo::System;
|
use sysinfo::System;
|
||||||
use windows::Win32::Foundation::HANDLE;
|
use windows::Win32::Foundation::HANDLE;
|
||||||
|
|
||||||
|
const THEME: catppuccin_egui::Theme = catppuccin_egui::MOCHA;
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Eq)]
|
#[derive(Default, PartialEq, Eq)]
|
||||||
pub enum Stage {
|
pub enum Stage {
|
||||||
#[default]
|
#[default]
|
||||||
@@ -24,6 +26,7 @@ pub enum Stage {
|
|||||||
Debug,
|
Debug,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::struct_excessive_bools)]
|
||||||
pub struct App {
|
pub struct App {
|
||||||
stage: Stage,
|
stage: Stage,
|
||||||
debug: bool,
|
debug: bool,
|
||||||
@@ -59,7 +62,7 @@ impl Default for App {
|
|||||||
impl eframe::App for App {
|
impl eframe::App for App {
|
||||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||||
if !self.initialized {
|
if !self.initialized {
|
||||||
catppuccin_egui::set_theme(ctx, catppuccin_egui::MOCHA);
|
catppuccin_egui::set_theme(ctx, THEME);
|
||||||
egui_extras::install_image_loaders(ctx);
|
egui_extras::install_image_loaders(ctx);
|
||||||
self.initialized = true;
|
self.initialized = true;
|
||||||
}
|
}
|
||||||
@@ -83,6 +86,7 @@ impl eframe::App for App {
|
|||||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||||
let button = ui
|
let button = ui
|
||||||
.add_enabled(!self.elevated, egui::Button::new("Elevate"))
|
.add_enabled(!self.elevated, egui::Button::new("Elevate"))
|
||||||
|
.on_hover_text("Relaunch ourselves as administrator.")
|
||||||
.on_disabled_hover_text("We are already running elevated.");
|
.on_disabled_hover_text("We are already running elevated.");
|
||||||
if button.clicked() {
|
if button.clicked() {
|
||||||
elevation::elevate();
|
elevation::elevate();
|
||||||
@@ -114,6 +118,7 @@ impl eframe::App for App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
|
#[allow(clippy::unused_self)]
|
||||||
fn header(&self, ui: &mut egui::Ui, text: &str) {
|
fn header(&self, ui: &mut egui::Ui, text: &str) {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label(text);
|
ui.label(text);
|
||||||
@@ -128,7 +133,7 @@ impl App {
|
|||||||
};
|
};
|
||||||
egui::ComboBox::from_label("")
|
egui::ComboBox::from_label("")
|
||||||
.selected_text(self.launch.selected.to_string())
|
.selected_text(self.launch.selected.to_string())
|
||||||
.width(125.0)
|
.width(120.0)
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
ui.selectable_value(
|
ui.selectable_value(
|
||||||
&mut self.launch.selected,
|
&mut self.launch.selected,
|
||||||
@@ -190,10 +195,10 @@ impl App {
|
|||||||
fn show_network(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
fn show_network(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
egui::Frame::new()
|
egui::Frame::new()
|
||||||
.inner_margin(egui::vec2(4.0, 4.0))
|
.inner_margin(egui::vec2(4.0, 4.0))
|
||||||
.stroke(egui::Stroke::new(1.0, catppuccin_egui::MOCHA.overlay1))
|
.stroke(egui::Stroke::new(1.0, THEME.overlay1))
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
let response = ui.add_enabled_ui(self.elevated, |ui| {
|
let response = ui.add_enabled_ui(self.elevated, |ui| {
|
||||||
ui.label("GTA's network access");
|
ui.label("Game's network access");
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Block").clicked() {
|
if ui.button("Block").clicked() {
|
||||||
features::game_networking::block_all(&mut self.sysinfo);
|
features::game_networking::block_all(&mut self.sysinfo);
|
||||||
@@ -203,12 +208,13 @@ impl App {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
response.response.on_disabled_hover_text(
|
response
|
||||||
"This requires you to be running as\nadministrator. Use the Elevate button.",
|
.response
|
||||||
)
|
.on_disabled_hover_text("This requires administrator.\nUse the Elevate button.")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::unused_self)]
|
||||||
fn show_about(&self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
fn show_about(&self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| {
|
ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
@@ -217,12 +223,13 @@ impl App {
|
|||||||
ui.label("with love from ");
|
ui.label("with love from ");
|
||||||
ui.hyperlink_to("futile", "http://futile.eu");
|
ui.hyperlink_to("futile", "http://futile.eu");
|
||||||
});
|
});
|
||||||
ui.separator();
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||||
ui.label(format!(
|
ui.label(format!(
|
||||||
"v{} {}",
|
"v{} {}",
|
||||||
env!("CARGO_PKG_VERSION"),
|
env!("CARGO_PKG_VERSION"),
|
||||||
if cfg!(debug_assertions) { "(dev)" } else { "" }
|
if cfg!(debug_assertions) { "(dev)" } else { "" }
|
||||||
));
|
));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
ui.add(egui::Image::new(egui::include_image!("../assets/icon.png")))
|
ui.add(egui::Image::new(egui::include_image!("../assets/icon.png")))
|
||||||
});
|
});
|
||||||
@@ -234,8 +241,10 @@ impl App {
|
|||||||
.processes()
|
.processes()
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(_, p)| p.name() == ENHANCED || p.name() == LEGACY)
|
.find(|(_, p)| p.name() == ENHANCED || p.name() == LEGACY)
|
||||||
.map(|(pid, _)| pid.as_u32().to_string())
|
.map_or_else(
|
||||||
.unwrap_or_else(|| "no pid found!".to_string());
|
|| "no pid found!".to_string(),
|
||||||
|
|(pid, _)| pid.as_u32().to_string(),
|
||||||
|
);
|
||||||
if ui.button("refresh sysinfo").clicked() {
|
if ui.button("refresh sysinfo").clicked() {
|
||||||
self.sysinfo.refresh_all();
|
self.sysinfo.refresh_all();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,12 +26,12 @@ pub fn is_elevated() -> bool {
|
|||||||
let mut token: HANDLE = HANDLE::default();
|
let mut token: HANDLE = HANDLE::default();
|
||||||
if OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token).is_ok() {
|
if OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token).is_ok() {
|
||||||
let mut elevation = TOKEN_ELEVATION::default();
|
let mut elevation = TOKEN_ELEVATION::default();
|
||||||
let size = std::mem::size_of::<TOKEN_ELEVATION>() as u32;
|
let size = u32::try_from(std::mem::size_of::<TOKEN_ELEVATION>()).unwrap();
|
||||||
let mut ret_size = size;
|
let mut ret_size = size;
|
||||||
let result = GetTokenInformation(
|
let result = GetTokenInformation(
|
||||||
token,
|
token,
|
||||||
TokenElevation,
|
TokenElevation,
|
||||||
Some(&mut elevation as *mut _ as *mut _),
|
Some((&raw mut elevation).cast()),
|
||||||
size,
|
size,
|
||||||
&mut ret_size,
|
&mut ret_size,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user