move debug viewport code to own module

This commit is contained in:
2025-04-19 06:48:56 +01:00
parent 4ed00e6ac3
commit 61de3aeee3
3 changed files with 90 additions and 74 deletions
+4 -74
View File
@@ -1,15 +1,7 @@
use crate::{ use crate::{
features, features,
gui::{settings::Settings, tools}, gui::{settings::Settings, tools},
util::{ util::{self, consts::game::WINDOW_TITLE, meta::Meta, persistent_state::PersistentState},
self,
consts::{
APP_STORAGE_PATH,
game::{EXE_ENHANCED, EXE_LEGACY, WINDOW_TITLE},
},
meta::Meta,
persistent_state::PersistentState,
},
}; };
use eframe::egui; use eframe::egui;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@@ -28,13 +20,13 @@ enum Stage {
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct Flags { pub struct Flags {
pub elevated: bool, pub elevated: bool,
debug: bool, pub debug: bool,
closing: bool, closing: bool,
} }
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct App { pub struct App {
meta: Meta, pub meta: Meta,
pub settings: Settings, pub settings: Settings,
stage: Stage, stage: Stage,
pub flags: Flags, pub flags: Flags,
@@ -43,7 +35,7 @@ pub struct App {
pub launch: features::launch::Launch, pub launch: features::launch::Launch,
force_close: features::force_close::ForceClose, force_close: features::force_close::ForceClose,
empty_session: features::empty_session::EmptySession, empty_session: features::empty_session::EmptySession,
anti_afk: features::anti_afk::AntiAfk, pub anti_afk: features::anti_afk::AntiAfk,
} }
impl eframe::App for App { 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 { impl Drop for App {
+85
View File
@@ -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:#?}")));
});
});
},
);
}
}
+1
View File
@@ -1,4 +1,5 @@
mod app; mod app;
mod debug;
pub mod run; pub mod run;
pub mod settings; pub mod settings;
mod tools; mod tools;