From 61de3aeee3c94a4468b5690d04dd89de029486fb Mon Sep 17 00:00:00 2001 From: futile Date: Sat, 19 Apr 2025 06:48:56 +0100 Subject: [PATCH] move debug viewport code to own module --- src/gui/app.rs | 78 +++----------------------------------------- src/gui/debug.rs | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ src/gui/mod.rs | 1 + 3 files changed, 90 insertions(+), 74 deletions(-) create mode 100644 src/gui/debug.rs diff --git a/src/gui/app.rs b/src/gui/app.rs index 3de48b7..f04f332 100644 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -1,15 +1,7 @@ use crate::{ features, gui::{settings::Settings, tools}, - util::{ - self, - consts::{ - APP_STORAGE_PATH, - game::{EXE_ENHANCED, EXE_LEGACY, WINDOW_TITLE}, - }, - meta::Meta, - persistent_state::PersistentState, - }, + util::{self, consts::game::WINDOW_TITLE, meta::Meta, persistent_state::PersistentState}, }; use eframe::egui; use std::time::{Duration, Instant}; @@ -28,13 +20,13 @@ enum Stage { #[derive(Debug, Default)] pub struct Flags { pub elevated: bool, - debug: bool, + pub debug: bool, closing: bool, } #[derive(Debug, Default)] pub struct App { - meta: Meta, + pub meta: Meta, pub settings: Settings, stage: Stage, pub flags: Flags, @@ -43,7 +35,7 @@ pub struct App { pub launch: features::launch::Launch, force_close: features::force_close::ForceClose, empty_session: features::empty_session::EmptySession, - anti_afk: features::anti_afk::AntiAfk, + pub anti_afk: features::anti_afk::AntiAfk, } impl eframe::App for App { @@ -230,68 +222,6 @@ impl App { ))); }); } - - fn show_debug_viewport(&mut self, ctx: &egui::Context) { - let main = ctx.input(|i| i.viewport().outer_rect.unwrap_or(egui::Rect::EVERYTHING)); - let builder = egui::ViewportBuilder::default() - .with_title("GTA Tools Debug") - .with_minimize_button(false) - .with_maximize_button(false) - .with_inner_size(WINDOW_SIZE) - .with_position([main.right() - 12.0, main.min.y]) - .with_icon(tools::load_icon()); - ctx.show_viewport_immediate( - egui::ViewportId::from_hash_of("debug_viewport"), - builder, - |ctx, _class| { - if tools::debug_keycombo_pressed(ctx) { - self.flags.debug = !self.flags.debug; - } - egui::CentralPanel::default().show(ctx, |ui| { - egui::ScrollArea::both() - .auto_shrink([false, true]) - .show(ui, |ui| { - if ui.button("open storage path").clicked() { - open::that_detached(APP_STORAGE_PATH.as_path()).unwrap(); - } - ui.collapsing("version", |ui| { - ui.checkbox( - &mut self.meta.newer_version_available, - "spoof new version available", - ) - .on_hover_text("(this could already be checked if\nthere actually IS a new version)"); - }); - ui.collapsing("anti afk", |ui| { - ui.label(format!( - "timer: {}", - self.anti_afk.interval.elapsed().as_secs() - )); - ui.label(format!( - "can activate: {}", - self.anti_afk.can_activate() - )); - }); - ui.collapsing("sysinfo", |ui| { - if ui.button("refresh all").clicked() { - self.sysinfo.refresh_all(); - } - let pid = self - .sysinfo - .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(), - ); - ui.label(format!("gta pid: {pid}")); - }); - ui.collapsing("app state", |ui| ui.label(format!("{self:#?}"))); - }); - }); - }, - ); - } } impl Drop for App { diff --git a/src/gui/debug.rs b/src/gui/debug.rs new file mode 100644 index 0000000..6431df4 --- /dev/null +++ b/src/gui/debug.rs @@ -0,0 +1,85 @@ +use crate::{ + gui::{ + app::{App, WINDOW_SIZE}, + tools, + }, + util::consts::{ + APP_STORAGE_PATH, + game::{EXE_ENHANCED, EXE_LEGACY}, + }, +}; +use eframe::egui; + +impl App { + pub fn show_debug_viewport(&mut self, ctx: &egui::Context) { + let main = ctx.input(|i| i.viewport().outer_rect.unwrap_or(egui::Rect::EVERYTHING)); + let builder = egui::ViewportBuilder::default() + .with_title("GTA Tools Debug") + .with_minimize_button(false) + .with_maximize_button(false) + .with_inner_size(WINDOW_SIZE) + .with_position([main.right() - 12.0, main.min.y]) + .with_icon(tools::load_icon()); + ctx.show_viewport_immediate( + egui::ViewportId::from_hash_of("debug_viewport"), + builder, + |ctx, _class| { + if tools::debug_keycombo_pressed(ctx) { + self.flags.debug = !self.flags.debug; + } + egui::CentralPanel::default().show(ctx, |ui| { + egui::ScrollArea::both() + .auto_shrink([false, true]) + .show(ui, |ui| { + ui.collapsing("misc", |ui| { + if ui.button("open storage path").clicked() { + open::that_detached(APP_STORAGE_PATH.as_path()).unwrap(); + } + ui.checkbox( + &mut self.meta.newer_version_available, + "spoof new version available", + ) + .on_hover_text("(this could already be checked if\nthere actually IS a new version)"); + ui.scope(|ui| { + use windows::Win32::UI::WindowsAndMessaging::{GetForegroundWindow, GetWindowTextW}; + let mut buffer = [0; 512]; + let current_title = unsafe { + let hwnd = GetForegroundWindow(); + let length = GetWindowTextW(hwnd, &mut buffer); + String::from_utf16_lossy(&buffer[..length as usize]) + }; + ui.label(format!("focused: \"{current_title}\"")); + }); + }); + ui.collapsing("anti afk", |ui| { + ui.label(format!( + "timer: {}", + self.anti_afk.interval.elapsed().as_secs() + )); + ui.label(format!( + "can activate: {}", + self.anti_afk.can_activate() + )); + }); + ui.collapsing("sysinfo", |ui| { + if ui.button("refresh all").clicked() { + self.sysinfo.refresh_all(); + } + let pid = self + .sysinfo + .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(), + ); + ui.label(format!("gta pid: {pid}")); + }); + ui.collapsing("app state", |ui| ui.label(format!("{self:#?}"))); + }); + }); + }, + ); + } +} diff --git a/src/gui/mod.rs b/src/gui/mod.rs index c8fc509..680f462 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -1,4 +1,5 @@ mod app; +mod debug; pub mod run; pub mod settings; mod tools;