Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fe697223c | ||
|
|
33fbbc7fc0 | ||
|
|
5bcdccdfea | ||
|
|
31ac09cd25 | ||
|
|
1283f34174 | ||
|
|
072c8ae406 | ||
|
|
e283393889 | ||
|
|
cf5c37c7dc | ||
|
|
c6cd0cf2f9 | ||
|
|
d182ca5318 | ||
|
|
42ee688639 | ||
|
|
ba49ed0e67 | ||
|
|
f9f326904e | ||
|
|
c3a1e864a7 | ||
|
|
7f795ba52e | ||
|
|
62efe3f411 | ||
|
|
4bb0f151a9 | ||
|
|
1aebc6b17c | ||
|
|
861ebe97d6 | ||
|
|
53b20a437a | ||
|
|
03ca861a09 | ||
|
|
a4ebfc515c | ||
|
|
52ffb34d83 | ||
|
|
6248e8379f | ||
|
|
99bc15b5ed | ||
|
|
e84d1347fd | ||
|
|
f49bb56398 | ||
|
|
99b6519ffb | ||
|
|
807cb5242f | ||
|
|
c1c1547e4d | ||
|
|
6e3aa70398 | ||
|
|
9331f79038 |
Generated
+91
-3
@@ -734,6 +734,27 @@ dependencies = [
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"option-ext",
|
||||
"redox_users",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dispatch"
|
||||
version = "0.2.0"
|
||||
@@ -1345,14 +1366,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gta-tools"
|
||||
version = "0.2.0"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"catppuccin-egui",
|
||||
"dirs",
|
||||
"eframe",
|
||||
"egui_extras",
|
||||
"image",
|
||||
"open",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"static_vcruntime",
|
||||
"strum 0.27.1",
|
||||
"sysinfo",
|
||||
"windows 0.61.1",
|
||||
"winreg",
|
||||
@@ -1591,6 +1616,12 @@ dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "jni"
|
||||
version = "0.21.1"
|
||||
@@ -1815,7 +1846,7 @@ dependencies = [
|
||||
"log",
|
||||
"rustc-hash",
|
||||
"spirv",
|
||||
"strum",
|
||||
"strum 0.26.3",
|
||||
"termcolor",
|
||||
"thiserror 2.0.12",
|
||||
"unicode-xid",
|
||||
@@ -2212,6 +2243,12 @@ dependencies = [
|
||||
"pathdiff",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "option-ext"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
|
||||
|
||||
[[package]]
|
||||
name = "orbclient"
|
||||
version = "0.3.48"
|
||||
@@ -2538,6 +2575,17 @@ dependencies = [
|
||||
"bitflags 2.9.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b"
|
||||
dependencies = [
|
||||
"getrandom 0.2.15",
|
||||
"libredox",
|
||||
"thiserror 2.0.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "renderdoc-sys"
|
||||
version = "1.1.0"
|
||||
@@ -2582,6 +2630,12 @@ version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
@@ -2636,6 +2690,18 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.140"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_repr"
|
||||
version = "0.1.20"
|
||||
@@ -2802,7 +2868,16 @@ version = "0.26.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06"
|
||||
dependencies = [
|
||||
"strum_macros",
|
||||
"strum_macros 0.26.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strum"
|
||||
version = "0.27.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f64def088c51c9510a8579e3c5d67c65349dcf755e5479ad3d010aa6454e2c32"
|
||||
dependencies = [
|
||||
"strum_macros 0.27.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2818,6 +2893,19 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.27.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c77a8c5abcaf0f9ce05d62342b7d298c346515365c36b673df4ebe3ced01fde8"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.100"
|
||||
|
||||
+5
-1
@@ -1,16 +1,20 @@
|
||||
[package]
|
||||
name = "gta-tools"
|
||||
version = "0.2.0"
|
||||
version = "0.4.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
catppuccin-egui = { version = "5.5.0", default-features = false, features = [
|
||||
"egui31",
|
||||
] }
|
||||
dirs = "6.0.0"
|
||||
eframe = "0.31.1"
|
||||
egui_extras = { version = "0.31.1", features = ["image"] }
|
||||
image = { version = "0.25.6", default-features = false, features = ["png"] }
|
||||
open = "5.3.2"
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
serde_json = "1.0.140"
|
||||
strum = { version = "0.27.1", features = ["derive"] }
|
||||
sysinfo = "0.34.2"
|
||||
windows = { version = "0.61.1", features = [
|
||||
"Win32_UI_Input_KeyboardAndMouse",
|
||||
|
||||
Binary file not shown.
@@ -1,6 +1,9 @@
|
||||
set windows-shell := ["pwsh", "-NoLogo", "-NoProfileLoadTime", "-Command"]
|
||||
|
||||
install:
|
||||
build:
|
||||
cargo build --release
|
||||
upx .\target\release\gta-tools.exe --best
|
||||
cp .\target\release\gta-tools.exe ~\.cargo\bin\
|
||||
|
||||
install: build
|
||||
cp .\target\release\gta-tools.exe ~\.cargo\bin
|
||||
cp .\target\release\gta-tools.exe ~\Documents
|
||||
|
||||
+24
-13
@@ -1,11 +1,15 @@
|
||||
#![allow(clippy::cast_possible_truncation)]
|
||||
|
||||
use crate::util::{self, consts::GTA_WINDOW_TITLE};
|
||||
use std::time::{Duration, Instant};
|
||||
use windows::Win32::UI::Input::KeyboardAndMouse::{
|
||||
KEYBD_EVENT_FLAGS, MAP_VIRTUAL_KEY_TYPE, MapVirtualKeyW, keybd_event,
|
||||
KEYBD_EVENT_FLAGS, MAP_VIRTUAL_KEY_TYPE, MapVirtualKeyW, VK_NUMPAD4, VK_NUMPAD6, keybd_event,
|
||||
};
|
||||
|
||||
pub const INTERVAL: Duration = Duration::from_secs(60);
|
||||
const VK_SHIFT: u8 = 16;
|
||||
const PRESS_KEYS: [u8; 2] = [VK_NUMPAD4.0 as u8, VK_NUMPAD6.0 as u8];
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AntiAfk {
|
||||
pub enabled: bool,
|
||||
pub interval: Instant,
|
||||
@@ -20,23 +24,30 @@ impl Default for AntiAfk {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send(vk_code: u8) {
|
||||
unsafe {
|
||||
impl AntiAfk {
|
||||
pub fn activate(&mut self) {
|
||||
if util::win::is_window_focused(GTA_WINDOW_TITLE)
|
||||
&& !util::win::is_any_key_pressed(&PRESS_KEYS)
|
||||
{
|
||||
send(&PRESS_KEYS);
|
||||
}
|
||||
self.interval = Instant::now();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send(vk_codes: &[u8]) {
|
||||
vk_codes.iter().for_each(|vk_code: &u8| unsafe {
|
||||
keybd_event(
|
||||
vk_code,
|
||||
u8::try_from(MapVirtualKeyW(u32::from(vk_code), MAP_VIRTUAL_KEY_TYPE(0))).unwrap(),
|
||||
*vk_code,
|
||||
u8::try_from(MapVirtualKeyW(u32::from(*vk_code), MAP_VIRTUAL_KEY_TYPE(0))).unwrap(),
|
||||
KEYBD_EVENT_FLAGS(0),
|
||||
0,
|
||||
);
|
||||
keybd_event(
|
||||
vk_code,
|
||||
u8::try_from(MapVirtualKeyW(u32::from(vk_code), MAP_VIRTUAL_KEY_TYPE(0))).unwrap(),
|
||||
*vk_code,
|
||||
u8::try_from(MapVirtualKeyW(u32::from(*vk_code), MAP_VIRTUAL_KEY_TYPE(0))).unwrap(),
|
||||
KEYBD_EVENT_FLAGS(2),
|
||||
0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn activate() {
|
||||
send(VK_SHIFT);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,10 +6,11 @@ use windows::Win32::{
|
||||
System::Threading::{OpenProcess, PROCESS_SUSPEND_RESUME},
|
||||
};
|
||||
|
||||
pub const INTERVAL: Duration = Duration::from_secs(8);
|
||||
pub const INTERVAL: Duration = Duration::from_secs(10);
|
||||
const ENHANCED: &str = "GTA5_Enhanced.exe";
|
||||
const LEGACY: &str = "GTA5.exe";
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EmptySession {
|
||||
pub disabled: bool,
|
||||
pub interval: Instant,
|
||||
@@ -57,7 +58,9 @@ pub fn activate(app: &mut App) {
|
||||
|
||||
pub fn deactivate(app: &mut App) {
|
||||
unsafe {
|
||||
let _ = NtResumeProcess(app.game_handle);
|
||||
let _ = CloseHandle(app.game_handle);
|
||||
if !app.game_handle.is_invalid() {
|
||||
let _ = NtResumeProcess(app.game_handle);
|
||||
let _ = CloseHandle(app.game_handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::util::consts::{ENHANCED, LEGACY};
|
||||
use std::time::Instant;
|
||||
use sysinfo::System;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ForceClose {
|
||||
pub button_text: String,
|
||||
pub prompting: bool,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{fmt::Display, path::PathBuf, process::Command};
|
||||
use strum::EnumIter;
|
||||
use winreg::{RegKey, enums::HKEY_LOCAL_MACHINE};
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, Serialize, Deserialize, EnumIter)]
|
||||
pub enum Platform {
|
||||
#[default]
|
||||
Steam,
|
||||
@@ -20,7 +22,7 @@ impl Display for Platform {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Launch {
|
||||
pub selected: Platform,
|
||||
}
|
||||
|
||||
-298
@@ -1,298 +0,0 @@
|
||||
use crate::{
|
||||
features::{
|
||||
self,
|
||||
anti_afk::AntiAfk,
|
||||
empty_session::EmptySession,
|
||||
force_close::ForceClose,
|
||||
launch::{Launch, Platform},
|
||||
},
|
||||
util::{
|
||||
consts::{ENHANCED, LEGACY},
|
||||
elevation,
|
||||
},
|
||||
};
|
||||
use eframe::egui;
|
||||
use std::time::{Duration, Instant};
|
||||
use sysinfo::System;
|
||||
use windows::Win32::Foundation::HANDLE;
|
||||
|
||||
const THEME: catppuccin_egui::Theme = catppuccin_egui::MOCHA;
|
||||
|
||||
#[derive(Default, PartialEq, Eq)]
|
||||
pub enum Stage {
|
||||
#[default]
|
||||
Main,
|
||||
About,
|
||||
Debug,
|
||||
}
|
||||
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
pub struct App {
|
||||
stage: Stage,
|
||||
debug: bool,
|
||||
initialized: bool,
|
||||
elevated: bool,
|
||||
current_frame: bool,
|
||||
pub sysinfo: System,
|
||||
pub game_handle: HANDLE,
|
||||
launch: Launch,
|
||||
force_close: ForceClose,
|
||||
empty_session: EmptySession,
|
||||
anti_afk: AntiAfk,
|
||||
}
|
||||
|
||||
impl Default for App {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
stage: Stage::default(),
|
||||
initialized: false,
|
||||
debug: false,
|
||||
elevated: elevation::is_elevated(),
|
||||
current_frame: false,
|
||||
sysinfo: System::new_all(),
|
||||
game_handle: HANDLE::default(),
|
||||
launch: Launch::default(),
|
||||
force_close: ForceClose::default(),
|
||||
empty_session: EmptySession::default(),
|
||||
anti_afk: AntiAfk::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for App {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
if !self.initialized {
|
||||
catppuccin_egui::set_theme(ctx, THEME);
|
||||
egui_extras::install_image_loaders(ctx);
|
||||
self.initialized = true;
|
||||
}
|
||||
ctx.request_repaint_after(Duration::from_millis(100));
|
||||
ctx.input(|i| {
|
||||
if i.modifiers.all() && i.key_pressed(egui::Key::D) {
|
||||
self.debug = !self.debug;
|
||||
if !self.debug && self.stage == Stage::Debug {
|
||||
self.stage = Stage::Main;
|
||||
}
|
||||
}
|
||||
});
|
||||
self.run_timers();
|
||||
egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.selectable_value(&mut self.stage, Stage::Main, "Main");
|
||||
ui.selectable_value(&mut self.stage, Stage::About, "About");
|
||||
if self.debug {
|
||||
ui.selectable_value(&mut self.stage, Stage::Debug, "Debug");
|
||||
}
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let button = ui
|
||||
.add_enabled(!self.elevated, egui::Button::new("Elevate"))
|
||||
.on_hover_text("Relaunch ourselves as administrator.")
|
||||
.on_disabled_hover_text("We are already running elevated.");
|
||||
if button.clicked() {
|
||||
elevation::elevate();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
egui::ScrollArea::both()
|
||||
.auto_shrink([false, false])
|
||||
.show(ui, |ui| match self.stage {
|
||||
Stage::Main => {
|
||||
self.header(ui, "Game");
|
||||
self.show_game(ctx, ui);
|
||||
self.header(ui, "Session");
|
||||
self.show_session(ctx, ui);
|
||||
self.header(ui, "Network");
|
||||
self.show_network(ctx, ui);
|
||||
}
|
||||
Stage::About => {
|
||||
self.show_about(ctx, ui);
|
||||
}
|
||||
Stage::Debug => {
|
||||
self.show_debug(ctx, ui);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl App {
|
||||
#[allow(clippy::unused_self)]
|
||||
fn header(&self, ui: &mut egui::Ui, text: &str) {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(text);
|
||||
ui.add(egui::Separator::default().horizontal());
|
||||
});
|
||||
}
|
||||
|
||||
fn show_game(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Launch").clicked() {
|
||||
features::launch::launch(&self.launch.selected);
|
||||
};
|
||||
egui::ComboBox::from_label("")
|
||||
.selected_text(self.launch.selected.to_string())
|
||||
.width(120.0)
|
||||
.show_ui(ui, |ui| {
|
||||
ui.selectable_value(
|
||||
&mut self.launch.selected,
|
||||
Platform::Steam,
|
||||
Platform::Steam.to_string(),
|
||||
);
|
||||
ui.selectable_value(
|
||||
&mut self.launch.selected,
|
||||
Platform::Rockstar,
|
||||
Platform::Rockstar.to_string(),
|
||||
);
|
||||
ui.selectable_value(
|
||||
&mut self.launch.selected,
|
||||
Platform::Epic,
|
||||
Platform::Epic.to_string(),
|
||||
);
|
||||
});
|
||||
});
|
||||
let force_close_button = ui.button(&self.force_close.button_text);
|
||||
if force_close_button.clicked() && !self.force_close.prompting {
|
||||
self.force_close.prompting();
|
||||
self.current_frame = true;
|
||||
};
|
||||
if self.force_close.prompting
|
||||
&& self.force_close.interval.elapsed() <= Duration::from_secs(3)
|
||||
{
|
||||
if force_close_button.clicked() && !self.current_frame {
|
||||
features::force_close::activate(&mut self.sysinfo);
|
||||
self.force_close = ForceClose::default();
|
||||
}
|
||||
} else {
|
||||
self.force_close = ForceClose::default();
|
||||
}
|
||||
if self.current_frame {
|
||||
self.current_frame = false;
|
||||
}
|
||||
}
|
||||
|
||||
fn show_session(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
ui.add_enabled_ui(!self.empty_session.disabled, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Empty current session").clicked() {
|
||||
self.empty_session.interval = Instant::now();
|
||||
self.empty_session.disabled = true;
|
||||
features::empty_session::activate(self);
|
||||
}
|
||||
ui.label(&self.empty_session.countdown.i_string);
|
||||
});
|
||||
});
|
||||
ui.checkbox(&mut self.anti_afk.enabled, "Anti AFK")
|
||||
.on_hover_text("You should be tabbed in\nwhile this is enabled.");
|
||||
if self.anti_afk.enabled && self.anti_afk.interval.elapsed() >= features::anti_afk::INTERVAL
|
||||
{
|
||||
features::anti_afk::activate();
|
||||
self.anti_afk.interval = Instant::now();
|
||||
}
|
||||
}
|
||||
|
||||
fn show_network(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
egui::Frame::new()
|
||||
.inner_margin(egui::vec2(4.0, 4.0))
|
||||
.stroke(egui::Stroke::new(1.0, THEME.overlay1))
|
||||
.show(ui, |ui| {
|
||||
let response = ui.add_enabled_ui(self.elevated, |ui| {
|
||||
ui.label("Game's network access");
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Block").clicked() {
|
||||
features::game_networking::block_all(&mut self.sysinfo);
|
||||
};
|
||||
if ui.button("Unblock").clicked() {
|
||||
features::game_networking::unblock_all();
|
||||
};
|
||||
});
|
||||
});
|
||||
response
|
||||
.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) {
|
||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 0.0;
|
||||
ui.label("with love from ");
|
||||
ui.hyperlink_to("futile", "http://futile.eu");
|
||||
});
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.label(format!(
|
||||
"v{} {}",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
if cfg!(debug_assertions) { "(dev)" } else { "" }
|
||||
));
|
||||
});
|
||||
});
|
||||
ui.add(egui::Image::new(egui::include_image!("../assets/icon.png")))
|
||||
});
|
||||
}
|
||||
|
||||
fn show_debug(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
let pid = self
|
||||
.sysinfo
|
||||
.processes()
|
||||
.iter()
|
||||
.find(|(_, p)| p.name() == ENHANCED || p.name() == LEGACY)
|
||||
.map_or_else(
|
||||
|| "no pid found!".to_string(),
|
||||
|(pid, _)| pid.as_u32().to_string(),
|
||||
);
|
||||
if ui.button("refresh sysinfo").clicked() {
|
||||
self.sysinfo.refresh_all();
|
||||
}
|
||||
ui.label(format!("gta pid: {pid}"));
|
||||
}
|
||||
|
||||
fn run_timers(&mut self) {
|
||||
if self.empty_session.disabled {
|
||||
self.empty_session.countdown.count();
|
||||
} else {
|
||||
self.empty_session.countdown.reset();
|
||||
}
|
||||
if self.empty_session.interval.elapsed() >= features::empty_session::INTERVAL {
|
||||
features::empty_session::deactivate(self);
|
||||
self.empty_session.disabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn load_icon() -> eframe::egui::IconData {
|
||||
let (icon_rgba, icon_width, icon_height) = {
|
||||
let icon = include_bytes!("../assets/icon.png");
|
||||
let image = image::load_from_memory(icon).unwrap().into_rgba8();
|
||||
let (width, height) = image.dimensions();
|
||||
let rgba = image.into_raw();
|
||||
(rgba, width, height)
|
||||
};
|
||||
eframe::egui::IconData {
|
||||
rgba: icon_rgba,
|
||||
width: icon_width,
|
||||
height: icon_height,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run() {
|
||||
let options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default()
|
||||
.with_resizable(false)
|
||||
.with_maximize_button(false)
|
||||
.with_inner_size([256.0, 232.0])
|
||||
.with_icon(load_icon()),
|
||||
centered: true,
|
||||
..Default::default()
|
||||
};
|
||||
eframe::run_native(
|
||||
"GTA Tools",
|
||||
options,
|
||||
Box::new(|_cc| Ok(Box::<App>::default())),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
+415
@@ -0,0 +1,415 @@
|
||||
mod persistent_state;
|
||||
mod settings;
|
||||
|
||||
use crate::{
|
||||
features::{
|
||||
self, anti_afk::AntiAfk, empty_session::EmptySession, force_close::ForceClose,
|
||||
launch::Launch,
|
||||
},
|
||||
gui::{persistent_state::PersistentState, settings::Settings},
|
||||
util::{
|
||||
self,
|
||||
consts::{ENHANCED, GTA_WINDOW_TITLE, LEGACY},
|
||||
},
|
||||
};
|
||||
use eframe::egui;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
const WINDOW_SIZE: [f32; 2] = [240.0, 245.0];
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Eq)]
|
||||
pub enum Stage {
|
||||
#[default]
|
||||
Main,
|
||||
Settings,
|
||||
About,
|
||||
}
|
||||
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Flags {
|
||||
elevated: bool,
|
||||
debug: bool,
|
||||
closing: bool,
|
||||
current_frame: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct App {
|
||||
settings: Settings,
|
||||
stage: Stage,
|
||||
flags: Flags,
|
||||
pub sysinfo: sysinfo::System,
|
||||
pub game_handle: windows::Win32::Foundation::HANDLE,
|
||||
launch: Launch,
|
||||
force_close: ForceClose,
|
||||
empty_session: EmptySession,
|
||||
anti_afk: AntiAfk,
|
||||
}
|
||||
|
||||
impl Default for App {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
settings: Settings::default(),
|
||||
stage: Stage::default(),
|
||||
flags: Flags::default(),
|
||||
sysinfo: sysinfo::System::new_all(),
|
||||
game_handle: windows::Win32::Foundation::HANDLE::default(),
|
||||
launch: Launch::default(),
|
||||
force_close: ForceClose::default(),
|
||||
empty_session: EmptySession::default(),
|
||||
anti_afk: AntiAfk::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for App {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
catppuccin_egui::set_theme(ctx, self.settings.theme.into());
|
||||
self.run_timers();
|
||||
egui::TopBottomPanel::bottom("bottom_panel")
|
||||
.exact_height(25.0)
|
||||
.show(ctx, |ui| {
|
||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
|
||||
ui.selectable_value(&mut self.stage, Stage::Main, "Main");
|
||||
ui.selectable_value(&mut self.stage, Stage::Settings, "Settings");
|
||||
ui.selectable_value(&mut self.stage, Stage::About, "About");
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let button = ui
|
||||
.add_enabled(!self.flags.elevated, egui::Button::new("Elevate"))
|
||||
.on_hover_text("Relaunch ourselves as administrator.")
|
||||
.on_disabled_hover_text("We are already running elevated.");
|
||||
if button.clicked() {
|
||||
util::win::elevate(util::win::ElevationExitMethod::Gentle(
|
||||
&mut self.flags.closing,
|
||||
));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
egui::ScrollArea::vertical()
|
||||
.auto_shrink([false, true])
|
||||
.show(ui, |ui| match self.stage {
|
||||
Stage::Main => {
|
||||
self.show_game(ctx, ui);
|
||||
self.show_session(ctx, ui);
|
||||
self.show_network(ctx, ui);
|
||||
}
|
||||
Stage::Settings => self.show_settings(ctx, ui),
|
||||
Stage::About => self.show_about(ctx, ui),
|
||||
});
|
||||
});
|
||||
if check_debug_keycombo_pressed(ctx) {
|
||||
self.flags.debug = !self.flags.debug;
|
||||
}
|
||||
if check_debug_viewport_close_button_pressed(ctx) {
|
||||
self.flags.debug = false;
|
||||
}
|
||||
if self.flags.debug {
|
||||
let main_rect = ctx.input(|i| {
|
||||
i.viewport()
|
||||
.clone()
|
||||
.outer_rect
|
||||
.unwrap_or(egui::Rect::EVERYTHING)
|
||||
});
|
||||
let position = [main_rect.right(), main_rect.min.y];
|
||||
ctx.show_viewport_immediate(
|
||||
egui::ViewportId::from_hash_of("debug_viewport"),
|
||||
egui::ViewportBuilder::default()
|
||||
.with_title("GTA Tools Debug")
|
||||
.with_minimize_button(false)
|
||||
.with_maximize_button(false)
|
||||
.with_inner_size(WINDOW_SIZE)
|
||||
.with_position(position)
|
||||
.with_icon(load_icon()),
|
||||
|ctx, _class| {
|
||||
if check_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| {
|
||||
self.show_debug(ctx, ui);
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
ctx.request_repaint_after(Duration::from_millis(100));
|
||||
if self.flags.closing {
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl App {
|
||||
fn show_game(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
header(ui, "Game");
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Launch").clicked() {
|
||||
features::launch::launch(&self.launch.selected);
|
||||
};
|
||||
build_combo_box::<features::launch::Platform>(ui, &mut self.launch.selected, "Launch");
|
||||
});
|
||||
let force_close_button = ui.add_sized(
|
||||
[104.0, 0.0],
|
||||
egui::Button::new(&self.force_close.button_text),
|
||||
);
|
||||
if force_close_button.clicked() && !self.force_close.prompting {
|
||||
self.force_close.prompting();
|
||||
self.flags.current_frame = true;
|
||||
};
|
||||
if self.force_close.prompting
|
||||
&& self.force_close.interval.elapsed() <= Duration::from_secs(3)
|
||||
{
|
||||
if force_close_button.clicked() && !self.flags.current_frame {
|
||||
features::force_close::activate(&mut self.sysinfo);
|
||||
self.force_close = ForceClose::default();
|
||||
}
|
||||
} else {
|
||||
self.force_close = ForceClose::default();
|
||||
}
|
||||
if self.flags.current_frame {
|
||||
self.flags.current_frame = false;
|
||||
}
|
||||
}
|
||||
|
||||
fn show_session(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
header(ui, "Session");
|
||||
ui.add_enabled_ui(!self.empty_session.disabled, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Empty current session").clicked() {
|
||||
self.empty_session.interval = Instant::now();
|
||||
self.empty_session.disabled = true;
|
||||
features::empty_session::activate(self);
|
||||
}
|
||||
ui.label(&self.empty_session.countdown.i_string);
|
||||
});
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.checkbox(&mut self.anti_afk.enabled, "Anti AFK")
|
||||
.on_hover_text("You should be tabbed in\nfor this to work.");
|
||||
if self.anti_afk.enabled {
|
||||
ui.add_space(8.0);
|
||||
ui.add_enabled_ui(false, |ui| {
|
||||
ui.label(if util::win::is_window_focused(GTA_WINDOW_TITLE) {
|
||||
"GTA is focused."
|
||||
} else {
|
||||
"GTA is not focused!"
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
if self.anti_afk.enabled && self.anti_afk.interval.elapsed() >= features::anti_afk::INTERVAL
|
||||
{
|
||||
self.anti_afk.activate();
|
||||
}
|
||||
}
|
||||
|
||||
fn show_network(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
header(ui, "Network");
|
||||
egui::Frame::new()
|
||||
.outer_margin(egui::vec2(0.0, -2.0))
|
||||
.show(ui, |ui| {
|
||||
let response = ui.add_enabled_ui(self.flags.elevated, |ui| {
|
||||
let label = ui.label("Game's network access");
|
||||
ui.horizontal(|ui| {
|
||||
let available_width = label.rect.width();
|
||||
let spacing = ui.spacing().item_spacing.x;
|
||||
let button_width = (available_width - spacing) / 2.0;
|
||||
if ui
|
||||
.add_sized([button_width, 18.0], egui::Button::new("Block"))
|
||||
.clicked()
|
||||
{
|
||||
features::game_networking::block_all(&mut self.sysinfo);
|
||||
};
|
||||
if ui
|
||||
.add_sized([button_width, 18.0], egui::Button::new("Unblock"))
|
||||
.clicked()
|
||||
{
|
||||
features::game_networking::unblock_all();
|
||||
};
|
||||
});
|
||||
});
|
||||
response.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) {
|
||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 0.0;
|
||||
ui.label("with love from ");
|
||||
ui.hyperlink_to("futile", "http://futile.eu");
|
||||
});
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.label(format!(
|
||||
"v{} {}",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
if cfg!(debug_assertions) { "(dev)" } else { "" }
|
||||
));
|
||||
});
|
||||
});
|
||||
ui.add(egui::Image::new(egui::include_image!(
|
||||
"../../assets/icon.png"
|
||||
)));
|
||||
});
|
||||
}
|
||||
|
||||
fn show_settings(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Theme");
|
||||
build_combo_box::<settings::Theme>(ui, &mut self.settings.theme, "Theme");
|
||||
});
|
||||
ui.checkbox(&mut self.settings.start_elevated, "Always start elevated");
|
||||
}
|
||||
|
||||
fn show_debug(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
ui.collapsing("times", |ui| {
|
||||
ui.label(format!(
|
||||
"anti afk timer: {}",
|
||||
self.anti_afk.interval.elapsed().as_secs()
|
||||
))
|
||||
});
|
||||
ui.collapsing("sysinfo", |ui| {
|
||||
if ui.button("refresh all").clicked() {
|
||||
self.sysinfo.refresh_all();
|
||||
}
|
||||
let pid = self
|
||||
.sysinfo
|
||||
.processes()
|
||||
.iter()
|
||||
.find(|(_, p)| p.name() == ENHANCED || p.name() == LEGACY)
|
||||
.map_or_else(
|
||||
|| "no pid found!".to_string(),
|
||||
|(pid, _)| pid.as_u32().to_string(),
|
||||
);
|
||||
ui.label(format!("gta pid: {pid}"));
|
||||
});
|
||||
ui.collapsing("app state", |ui| ui.label(format!("{self:#?}")));
|
||||
}
|
||||
|
||||
fn run_timers(&mut self) {
|
||||
if self.empty_session.disabled {
|
||||
self.empty_session.countdown.count();
|
||||
} else {
|
||||
self.empty_session.countdown.reset();
|
||||
}
|
||||
if self.empty_session.interval.elapsed() >= features::empty_session::INTERVAL {
|
||||
features::empty_session::deactivate(self);
|
||||
self.empty_session.disabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for App {
|
||||
fn drop(&mut self) {
|
||||
// save any persistent state to config file
|
||||
let persistent_state = PersistentState {
|
||||
launcher: self.launch.selected,
|
||||
settings: self.settings.clone(),
|
||||
};
|
||||
persistent_state.set();
|
||||
// make sure we are not suspending game
|
||||
features::empty_session::deactivate(self);
|
||||
}
|
||||
}
|
||||
|
||||
fn header(ui: &mut egui::Ui, text: &str) {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(egui::RichText::new(text).font(egui::FontId::new(
|
||||
12.5,
|
||||
egui::FontFamily::Name("Ubuntu-Regular".into()),
|
||||
)));
|
||||
ui.add(egui::Separator::default().horizontal());
|
||||
});
|
||||
}
|
||||
|
||||
fn build_combo_box<E>(ui: &mut egui::Ui, current_value: &mut E, label: impl std::hash::Hash)
|
||||
where
|
||||
E: strum::IntoEnumIterator + std::fmt::Display + std::cmp::PartialEq + Copy,
|
||||
{
|
||||
egui::ComboBox::from_id_salt(label)
|
||||
.selected_text(current_value.to_string())
|
||||
.show_ui(ui, |ui| {
|
||||
for v in E::iter() {
|
||||
ui.selectable_value(current_value, v, v.to_string());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn check_debug_keycombo_pressed(ctx: &egui::Context) -> bool {
|
||||
ctx.input(|i| i.modifiers.all() && i.key_pressed(egui::Key::D))
|
||||
}
|
||||
|
||||
fn check_debug_viewport_close_button_pressed(ctx: &egui::Context) -> bool {
|
||||
ctx.input(|i| {
|
||||
i.raw
|
||||
.viewports
|
||||
.get(&egui::ViewportId::from_hash_of("debug_viewport"))
|
||||
.filter(|vp| vp.close_requested())
|
||||
.is_some()
|
||||
})
|
||||
}
|
||||
|
||||
fn load_icon() -> egui::IconData {
|
||||
let icon = include_bytes!("../../assets/icon.png");
|
||||
let image = image::load_from_memory(icon).unwrap().into_rgba8();
|
||||
let (width, height) = image.dimensions();
|
||||
egui::IconData {
|
||||
rgba: image.into_raw(),
|
||||
width,
|
||||
height,
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn app_creator(
|
||||
cc: &eframe::CreationContext<'_>,
|
||||
) -> Result<Box<dyn eframe::App>, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let mut app = Box::<App>::default();
|
||||
if let Some(persistent_state) = PersistentState::get() {
|
||||
app.launch.selected = persistent_state.launcher;
|
||||
app.settings = persistent_state.settings;
|
||||
};
|
||||
let elevated = util::win::is_elevated();
|
||||
if app.settings.start_elevated && !elevated {
|
||||
util::win::elevate(util::win::ElevationExitMethod::Forced);
|
||||
}
|
||||
app.flags.elevated = elevated;
|
||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||
cc.egui_ctx.style_mut(|style| {
|
||||
style.spacing.item_spacing = egui::vec2(4.0, 4.0);
|
||||
style.interaction.selectable_labels = false;
|
||||
});
|
||||
let mut fonts = egui::FontDefinitions::default();
|
||||
fonts.font_data.insert(
|
||||
"Ubuntu-Regular".to_string(),
|
||||
egui::FontData::from_static(include_bytes!("../../assets/Ubuntu-Regular.ttf")).into(),
|
||||
);
|
||||
fonts.families.insert(
|
||||
egui::FontFamily::Name("Ubuntu-Regular".into()),
|
||||
vec!["Ubuntu-Regular".to_string()],
|
||||
);
|
||||
cc.egui_ctx.set_fonts(fonts);
|
||||
Ok(app)
|
||||
}
|
||||
|
||||
pub fn run() {
|
||||
let options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default()
|
||||
.with_resizable(false)
|
||||
.with_maximize_button(false)
|
||||
.with_inner_size(WINDOW_SIZE)
|
||||
.with_icon(load_icon()),
|
||||
centered: true,
|
||||
..Default::default()
|
||||
};
|
||||
eframe::run_native("GTA Tools", options, Box::new(app_creator)).unwrap();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
use crate::{features::launch::Platform, gui::settings::Settings};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
fs::{self, File},
|
||||
io::Write,
|
||||
path::PathBuf,
|
||||
sync::LazyLock,
|
||||
};
|
||||
|
||||
static CONFIG_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
|
||||
dirs::config_local_dir()
|
||||
.unwrap()
|
||||
.join("GTA Tools")
|
||||
.join("config.json")
|
||||
});
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct PersistentState {
|
||||
pub launcher: Platform,
|
||||
pub settings: Settings,
|
||||
}
|
||||
|
||||
impl PersistentState {
|
||||
pub fn get() -> Option<Self> {
|
||||
fs::read_to_string(CONFIG_PATH.as_path())
|
||||
.ok()
|
||||
.and_then(|config| serde_json::from_str::<Self>(&config).ok())
|
||||
}
|
||||
|
||||
pub fn set(&self) {
|
||||
let config_path = CONFIG_PATH.as_path();
|
||||
let config_path_parent = config_path.parent().unwrap();
|
||||
if !config_path_parent.exists() {
|
||||
fs::create_dir(config_path_parent).unwrap();
|
||||
}
|
||||
let mut config_file = File::create(config_path).unwrap();
|
||||
let json = serde_json::to_string_pretty(&self).unwrap();
|
||||
config_file.write_all(json.as_bytes()).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Display;
|
||||
use strum::EnumIter;
|
||||
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, EnumIter)]
|
||||
pub enum Theme {
|
||||
CatppuccinLatte,
|
||||
CatppuccinFrappe,
|
||||
CatppuccinMacchiato,
|
||||
CatppuccinMocha,
|
||||
}
|
||||
|
||||
impl From<Theme> for catppuccin_egui::Theme {
|
||||
fn from(val: Theme) -> Self {
|
||||
match val {
|
||||
Theme::CatppuccinLatte => catppuccin_egui::LATTE,
|
||||
Theme::CatppuccinFrappe => catppuccin_egui::FRAPPE,
|
||||
Theme::CatppuccinMacchiato => catppuccin_egui::MACCHIATO,
|
||||
Theme::CatppuccinMocha => catppuccin_egui::MOCHA,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Theme {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let x = match self {
|
||||
Self::CatppuccinLatte => "Catppuccin Latte",
|
||||
Self::CatppuccinFrappe => "Catppuccin Frappe",
|
||||
Self::CatppuccinMacchiato => "Catppuccin Macchiato",
|
||||
Self::CatppuccinMocha => "Catppuccin Mocha",
|
||||
};
|
||||
write!(f, "{x}")
|
||||
}
|
||||
}
|
||||
|
||||
impl Theme {
|
||||
pub fn to_catppuccin(self) -> catppuccin_egui::Theme {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Settings {
|
||||
pub theme: Theme,
|
||||
pub start_elevated: bool,
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
theme: Theme::CatppuccinMocha,
|
||||
start_elevated: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
#![windows_subsystem = "windows"]
|
||||
|
||||
mod features;
|
||||
mod gui;
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
pub const ENHANCED: &str = "GTA5_Enhanced.exe";
|
||||
pub const LEGACY: &str = "GTA5.exe";
|
||||
|
||||
pub const GTA_WINDOW_TITLE: &str = "Grand Theft Auto V";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Countdown {
|
||||
pub i: u64,
|
||||
pub i_original: u64,
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
use windows::{
|
||||
Win32::Foundation::{CloseHandle, HANDLE},
|
||||
Win32::Security::{GetTokenInformation, TOKEN_ELEVATION, TOKEN_QUERY, TokenElevation},
|
||||
Win32::System::Threading::{GetCurrentProcess, OpenProcessToken},
|
||||
Win32::UI::{Shell::ShellExecuteW, WindowsAndMessaging::SW_HIDE},
|
||||
core::{HSTRING, PCWSTR},
|
||||
};
|
||||
|
||||
pub fn elevate() {
|
||||
let exe = std::env::current_exe().unwrap();
|
||||
unsafe {
|
||||
ShellExecuteW(
|
||||
None,
|
||||
&HSTRING::from("runas"),
|
||||
&HSTRING::from(exe.as_path()),
|
||||
PCWSTR::null(),
|
||||
PCWSTR::null(),
|
||||
SW_HIDE,
|
||||
);
|
||||
}
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
pub fn is_elevated() -> bool {
|
||||
unsafe {
|
||||
let mut token: HANDLE = HANDLE::default();
|
||||
if OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token).is_ok() {
|
||||
let mut elevation = TOKEN_ELEVATION::default();
|
||||
let size = u32::try_from(std::mem::size_of::<TOKEN_ELEVATION>()).unwrap();
|
||||
let mut ret_size = size;
|
||||
let result = GetTokenInformation(
|
||||
token,
|
||||
TokenElevation,
|
||||
Some((&raw mut elevation).cast()),
|
||||
size,
|
||||
&mut ret_size,
|
||||
);
|
||||
CloseHandle(token).unwrap();
|
||||
if result.is_ok() && elevation.TokenIsElevated != 0 {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
pub mod consts;
|
||||
pub mod countdown;
|
||||
pub mod elevation;
|
||||
pub mod win;
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
use windows::{
|
||||
Win32::{
|
||||
Foundation::{CloseHandle, HANDLE},
|
||||
Security::{GetTokenInformation, TOKEN_ELEVATION, TOKEN_QUERY, TokenElevation},
|
||||
System::Threading::{GetCurrentProcess, OpenProcessToken},
|
||||
UI::{
|
||||
Input::KeyboardAndMouse::GetAsyncKeyState,
|
||||
Shell::ShellExecuteW,
|
||||
WindowsAndMessaging::{GetForegroundWindow, GetWindowTextW, SW_NORMAL},
|
||||
},
|
||||
},
|
||||
core::{HSTRING, PCWSTR},
|
||||
};
|
||||
|
||||
pub enum ElevationExitMethod<'a> {
|
||||
Gentle(&'a mut bool),
|
||||
Forced,
|
||||
}
|
||||
|
||||
#[allow(clippy::cast_sign_loss)]
|
||||
pub fn is_window_focused(target_title: &str) -> bool {
|
||||
unsafe {
|
||||
let hwnd = GetForegroundWindow();
|
||||
let mut buffer: [u16; 512] = [0; 512];
|
||||
let length = GetWindowTextW(hwnd, &mut buffer);
|
||||
let current_title = String::from_utf16_lossy(&buffer[..length as usize]);
|
||||
current_title == target_title
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_any_key_pressed(keys: &[u8]) -> bool {
|
||||
keys.iter()
|
||||
.any(|&key| unsafe { (i32::from(GetAsyncKeyState(i32::from(key))) & 0x8000) != 0 })
|
||||
}
|
||||
|
||||
pub fn elevate(closing: ElevationExitMethod) {
|
||||
let exe = std::env::current_exe().unwrap();
|
||||
unsafe {
|
||||
ShellExecuteW(
|
||||
None,
|
||||
&HSTRING::from("runas"),
|
||||
&HSTRING::from(exe.as_path()),
|
||||
PCWSTR::null(),
|
||||
PCWSTR::null(),
|
||||
SW_NORMAL,
|
||||
);
|
||||
}
|
||||
match closing {
|
||||
ElevationExitMethod::Gentle(closing) => *closing = true,
|
||||
ElevationExitMethod::Forced => std::process::exit(0),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_elevated() -> bool {
|
||||
unsafe {
|
||||
let mut token: HANDLE = HANDLE::default();
|
||||
if OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token).is_ok() {
|
||||
let mut elevation = TOKEN_ELEVATION::default();
|
||||
let size = u32::try_from(std::mem::size_of::<TOKEN_ELEVATION>()).unwrap();
|
||||
let mut ret_size = size;
|
||||
let result = GetTokenInformation(
|
||||
token,
|
||||
TokenElevation,
|
||||
Some((&raw mut elevation).cast()),
|
||||
size,
|
||||
&mut ret_size,
|
||||
);
|
||||
CloseHandle(token).unwrap();
|
||||
if result.is_ok() && elevation.TokenIsElevated != 0 {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user