From 660a478fbb1041c2305c29fccafb889d9bb04184 Mon Sep 17 00:00:00 2001 From: futile Date: Sat, 22 Nov 2025 09:06:17 +0000 Subject: [PATCH] greatly simplify blocked status by removing temporary failure state --- src/features/game_networking.rs | 60 ++++++--------------------------- src/gui/app.rs | 7 ++-- src/gui/debug.rs | 10 +++--- src/util/consts.rs | 12 ------- 4 files changed, 20 insertions(+), 69 deletions(-) diff --git a/src/features/game_networking.rs b/src/features/game_networking.rs index e5015f7..e404af3 100644 --- a/src/features/game_networking.rs +++ b/src/features/game_networking.rs @@ -8,9 +8,7 @@ use crate::{ use std::{ error::Error, path::{Path, PathBuf}, - time::{Duration, Instant}, }; -use strum::{Display, EnumIter}; use windows::{ Win32::{ NetworkManagement::WindowsFirewall::{ @@ -28,44 +26,21 @@ use windows::{ const FILTER_NAME_EXE: &str = "[GTA Tools] Block outbound traffic for all of GTA V"; const FILTER_NAME_SAVE_SERVER: &str = "[GTA Tools] Block outbound traffic to Rockstar save server"; -const INTERVAL: Duration = Duration::from_secs(3); - -#[derive(Clone, Copy, Debug, Display, PartialEq, Eq, EnumIter)] -pub enum BlockedStatus { - Blocked, - Failed, - Unblocked, -} - -impl From for BlockedStatus { - fn from(value: bool) -> Self { - if value { - Self::Blocked - } else { - Self::Unblocked - } - } -} - #[derive(Debug)] pub struct GameNetworking { com_initialized: bool, - pub blocked_status: BlockedStatus, - timer: Instant, - counting: bool, + pub blocked: bool, } impl Default for GameNetworking { fn default() -> Self { Self { - blocked_status: if Self::is_save_server_blocked().unwrap() { - Self::is_save_server_blocked().unwrap().into() + blocked: if Self::is_save_server_blocked().unwrap() { + Self::is_save_server_blocked().unwrap() } else { - Self::is_exe_blocked().unwrap().into() + Self::is_exe_blocked().unwrap() }, com_initialized: unsafe { CoInitializeEx(None, COINIT_MULTITHREADED) }.is_ok(), - timer: Instant::now(), - counting: false, } } } @@ -130,17 +105,16 @@ impl GameNetworking { pub fn block_exe(&mut self, system_info: &mut SystemInfo) -> Result<(), Box> { let Some(exe_path) = get_game_exe_path(system_info) else { - self.blocked_status = BlockedStatus::Failed; return Ok(()); }; self.block_generic(Mode::EntireGame(exe_path.to_path_buf()))?; - self.blocked_status = Self::is_exe_blocked()?.into(); + self.blocked = Self::is_exe_blocked()?; Ok(()) } pub fn unblock_exe(&mut self) -> Result<(), Box> { self.unblock_generic(FILTER_NAME_EXE)?; - self.blocked_status = Self::is_exe_blocked()?.into(); + self.blocked = Self::is_exe_blocked()?; Ok(()) } @@ -150,13 +124,13 @@ impl GameNetworking { pub fn block_save_server(&mut self, save_server_ip: &str) -> Result<(), Box> { self.block_generic(Mode::SaveServer(save_server_ip.to_owned()))?; - self.blocked_status = Self::is_save_server_blocked()?.into(); + self.blocked = Self::is_save_server_blocked()?; Ok(()) } pub fn unblock_save_server(&mut self) -> Result<(), Box> { self.unblock_generic(FILTER_NAME_SAVE_SERVER)?; - self.blocked_status = Self::is_save_server_blocked()?.into(); + self.blocked = Self::is_save_server_blocked()?; Ok(()) } @@ -164,34 +138,20 @@ impl GameNetworking { Self::is_blocked_generic(FILTER_NAME_SAVE_SERVER) } - pub fn reset_indicator_if_failed(&mut self) { - if self.blocked_status == BlockedStatus::Failed && !self.counting { - self.counting = true; - self.timer = Instant::now(); - } - if self.blocked_status == BlockedStatus::Failed - && self.counting - && self.timer.elapsed() >= INTERVAL - { - self.counting = false; - self.blocked_status = Self::is_exe_blocked().unwrap().into(); - } - } - pub fn ensure_not_both_blocked_simultaneously(&mut self, block_method: BlockMethod) { match block_method { BlockMethod::EntireGame => { if Self::is_save_server_blocked().unwrap() { // ignoring the return because if this is an error the user can just thug it out at that point let _ = self.unblock_save_server(); - self.blocked_status = Self::is_exe_blocked().unwrap().into(); + self.blocked = Self::is_exe_blocked().unwrap(); } } BlockMethod::SaveServer => { if Self::is_exe_blocked().unwrap() { // ignoring the return because if this is an error the user can just thug it out at that point let _ = self.unblock_exe(); - self.blocked_status = Self::is_save_server_blocked().unwrap().into(); + self.blocked = Self::is_save_server_blocked().unwrap(); } } } diff --git a/src/gui/app.rs b/src/gui/app.rs index ee7f964..67a94fe 100644 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -164,8 +164,11 @@ impl App { BlockMethod::SaveServer => ui.label("Rockstar save server access"), }; ui.add_space(1.0); - ui.create_indicator_dot(self.game_networking.blocked_status); - self.game_networking.reset_indicator_if_failed(); + ui.create_indicator_dot(if self.game_networking.blocked { + colours::RED + } else { + colours::GREEN + }); label }); ui.allocate_ui_with_layout( diff --git a/src/gui/debug.rs b/src/gui/debug.rs index 588d7c9..11096ca 100644 --- a/src/gui/debug.rs +++ b/src/gui/debug.rs @@ -2,7 +2,6 @@ use crate::{ gui::{ app::{App, WINDOW_SIZE}, tools, - ui_ext::UiExt, }, util::consts::{ game::{EXE_ENHANCED, EXE_LEGACY}, @@ -30,11 +29,12 @@ impl App { ui.label(format!("focused: \"{current_title}\"")); }); ui.horizontal(|ui| { - ui.label("blocked_status"); - egui::ComboBox::from_id_salt("blocked_status") - .selected_text(self.game_networking.blocked_status.to_string()) + ui.label("blocked"); + egui::ComboBox::from_id_salt("blocked") + .selected_text(self.game_networking.blocked.to_string()) .show_ui(ui, |ui| { - ui.build_menu(&mut self.game_networking.blocked_status); + ui.selectable_value(&mut self.game_networking.blocked, true, "true"); + ui.selectable_value(&mut self.game_networking.blocked, false, "false"); }); }); if ui.add(egui::Button::new("force refresh theme")).clicked() { diff --git a/src/util/consts.rs b/src/util/consts.rs index b8d0950..cd88f43 100644 --- a/src/util/consts.rs +++ b/src/util/consts.rs @@ -15,20 +15,8 @@ pub mod game { } pub mod colours { - use crate::features::game_networking::BlockedStatus; use eframe::egui; pub const RED: egui::Color32 = egui::Color32::from_rgb(255, 96, 96); - pub const YELLOW: egui::Color32 = egui::Color32::from_rgb(255, 255, 96); pub const GREEN: egui::Color32 = egui::Color32::from_rgb(96, 255, 96); - - impl From for egui::Color32 { - fn from(value: BlockedStatus) -> Self { - match value { - BlockedStatus::Blocked => RED, - BlockedStatus::Failed => YELLOW, - BlockedStatus::Unblocked => GREEN, - } - } - } }