Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e33536dfe | ||
|
|
c36a41f919 | ||
|
|
660e7a874f | ||
|
|
72abda7352 | ||
|
|
ebf704c6f4 | ||
|
|
5c5e6d60a1 | ||
|
|
98a6545b27 | ||
|
|
a9a965462a | ||
|
|
81b4b26f96 | ||
|
|
06df466d24 | ||
|
|
b8c444dc5b | ||
|
|
e848ca8d79 | ||
|
|
0a831580e2 | ||
|
|
10e69eaac3 | ||
|
|
9dbfbc4419 | ||
|
|
ef0b6de6ba | ||
|
|
e7470bd694 | ||
|
|
936f683385 | ||
|
|
b3158f71fb | ||
|
|
070e477fd4 | ||
|
|
7745bba10e | ||
|
|
8d7a0d12b9 | ||
|
|
b325ebb03c | ||
|
|
38c6402a12 | ||
|
|
2d42c0c3c4 | ||
|
|
a423721aee | ||
|
|
f3436c8ddc | ||
|
|
afcf0a87c0 | ||
|
|
73d610949f | ||
|
|
7f358d9adb | ||
|
|
7caa5421f7 | ||
|
|
ecac0d54aa | ||
|
|
a84401ca33 | ||
|
|
1bcd6b2c7d | ||
|
|
1dbdc0e4cb | ||
|
|
3610e44a08 | ||
|
|
f5fd22d35c | ||
|
|
022828b802 | ||
|
|
262d2d0720 | ||
|
|
2326edf97b | ||
|
|
301be82837 | ||
|
|
0d7dde929d | ||
|
|
3ab802fd56 | ||
|
|
53030cc5f7 | ||
|
|
383224c2fa | ||
|
|
575a6a4f1d | ||
|
|
17579de277 | ||
|
|
00727b9913 | ||
|
|
1f6fc22525 | ||
|
|
27b09be76e | ||
|
|
6f15e8c348 | ||
|
|
d294aa9861 | ||
|
|
f688f1c3c4 | ||
|
|
58ec9f6567 | ||
|
|
1c9ce2a4d3 | ||
|
|
8a5d6cf38c | ||
|
|
d789b0f62d | ||
|
|
6079a72f47 | ||
|
|
914ffe46d2 | ||
|
|
935703e1ab | ||
|
|
202554e03b | ||
|
|
da2b15a0b6 | ||
|
|
ccc27b1944 | ||
|
|
10168e84d1 |
@@ -1,2 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
.vscode
|
.vscode
|
||||||
|
.idea
|
||||||
Generated
+731
-2026
File diff suppressed because it is too large
Load Diff
+23
-22
@@ -1,39 +1,40 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "gta-tools"
|
name = "gta-tools"
|
||||||
version = "0.5.0"
|
version = "0.7.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
catppuccin-egui = { version = "5.5.0", default-features = false, features = [
|
catppuccin-egui = { version = "5.6.0", default-features = false, features = [
|
||||||
"egui31",
|
"egui32",
|
||||||
] }
|
] }
|
||||||
chrono = "0.4.40"
|
chrono = { version = "0.4.41", default-features = false, features = ["clock"] }
|
||||||
dirs = "6.0.0"
|
eframe = { version = "0.32.2", default-features = false, features = [
|
||||||
eframe = "0.31.1"
|
"glow",
|
||||||
egui_extras = { version = "0.31.1", features = ["image", "svg"] }
|
"default_fonts",
|
||||||
image = { version = "0.25.6", default-features = false, features = ["png"] }
|
] }
|
||||||
|
egui_extras = { version = "0.32.2", default-features = false, features = [
|
||||||
|
"image",
|
||||||
|
"svg",
|
||||||
|
] }
|
||||||
|
image = { version = "0.25.8", default-features = false, features = ["png"] }
|
||||||
open = "5.3.2"
|
open = "5.3.2"
|
||||||
semver = "1.0.26"
|
semver = "1.0.26"
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.143"
|
||||||
strum = { version = "0.27.1", features = ["derive"] }
|
strum = { version = "0.27.2", features = ["derive"] }
|
||||||
sysinfo = { git = "https://github.com/GuillaumeGomez/sysinfo", rev = "bcbb7b2b389b8800ff457773f48b130e710458fc" }
|
sysinfo = "0.37.0"
|
||||||
ureq = { version = "3.0.11", features = ["json"] }
|
ureq = { version = "3.1.0", features = ["json"] }
|
||||||
windows = { version = "0.61.1", features = [
|
windows = { version = "0.62.0", features = [
|
||||||
"Win32_UI_Input_KeyboardAndMouse",
|
"Win32_NetworkManagement_WindowsFirewall",
|
||||||
|
"Win32_Security",
|
||||||
|
"Win32_System_Com",
|
||||||
"Win32_System_Threading",
|
"Win32_System_Threading",
|
||||||
|
"Win32_UI_Input_KeyboardAndMouse",
|
||||||
"Win32_UI_Shell",
|
"Win32_UI_Shell",
|
||||||
"Win32_UI_WindowsAndMessaging",
|
"Win32_UI_WindowsAndMessaging",
|
||||||
"Win32_Security",
|
|
||||||
"Win32_NetworkManagement_WindowsFirewall",
|
|
||||||
] }
|
] }
|
||||||
winreg = "0.55.0"
|
winreg = "0.55.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
static_vcruntime = "2.0.0"
|
static_vcruntime = "2.0.0"
|
||||||
winresource = "0.1.20"
|
winresource = "0.1.23"
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
strip = true
|
|
||||||
lto = true
|
|
||||||
codegen-units = 1
|
|
||||||
|
|||||||
@@ -1,4 +1,60 @@
|
|||||||
# GTA Tools
|
# GTA Tools
|
||||||
A toolset of convenient things for GTA 5 Online.
|
|
||||||
|
|
||||||

|
A toolset of convenient things for GTA V Online.
|
||||||
|
|
||||||
|
 
|
||||||
|
|
||||||
|
## Installing
|
||||||
|
|
||||||
|
**Option 1** — <ins>Download</ins>
|
||||||
|
Download the latest release [here](https://codeberg.org/futile/gta-tools/releases/download/latest/gta-tools.exe) and place it somewhere convenient for you, such as Documents. You could then make a shortcut titled "GTA Tools", and pin it to taskbar or Start.
|
||||||
|
|
||||||
|
**Option 2** — <ins>Build from source</ins>
|
||||||
|
You will need the Rust toolchain, which can be obtained [here](https://rustup.rs). Follow the instructions of its installer. Once you have Rust installed, clone this repo and navigate to it. At this point, you should probably `git checkout x.x.x`, where `x.x.x` is the latest tag. You can then run `cargo build --release`. Once you do that, you can use the binary located at `.\target\release\gta-tools.exe` in the same way as **Option 1**.
|
||||||
|
|
||||||
|
## Guide
|
||||||
|
|
||||||
|
Every feature of GTA Tools is Legacy/Enhanced-agnostic. Some functionality of GTA Tools requires administrator access. If necessary, GTA Tools can either be started as admin manually, or, the user can simply use the <kbd>Elevate</kbd> button to relaunch GTA Tools as admin.
|
||||||
|
|
||||||
|
It is recommended to use an up-to-date version of GTA Tools from [releases](https://codeberg.org/futile/gta-tools/releases). You can check for updates to your existing installation by going to the <kbd>About</kbd> page of GTA Tools and hovering the <kbd>↓</kbd> button near the version number.
|
||||||
|
|
||||||
|
#### Game
|
||||||
|
|
||||||
|
This section is quite simple.
|
||||||
|
|
||||||
|
There is a <kbd>Launch</kbd>[^1] feature, which will start your game on the chosen launcher and game version.
|
||||||
|
|
||||||
|
There is also a <kbd>Force close game</kbd> feature, which simply kills all game processes. This *does not* touch Rockstar Games Launcher or any other processes, only ones named `GTA5_Enhanced.exe` or `GTA5.exe`.
|
||||||
|
|
||||||
|
#### Session
|
||||||
|
|
||||||
|
This section also has two features.
|
||||||
|
|
||||||
|
The first being <kbd>Empty current session</kbd>, which "removes everyone" from your session by suspending your game for 10 seconds, and then resuming it. This method is exceedingly similar to the Resource Monitor method, but made convenient in one button. This can be useful in numerous ways:
|
||||||
|
* You are stuck loading into a session
|
||||||
|
* You are stuck loading into an interior
|
||||||
|
* You are about to get griefed while doing a freemode mission
|
||||||
|
* You want to quickly get a "new" session
|
||||||
|
|
||||||
|
The other feature is <kbd>Anti AFK</kbd>, which, when toggled, prevents you from getting kicked for idling by pressing keys on your keyboard every 60 seconds. At present, those keys are `VK_NUMPAD4` & `VK_NUMPAD6`, due to being a relatively good balance of keys that the game actually registers but don't interrupt gameplay too much if they activate while you're playing. You *must* be tabbed into GTA V for <kbd>Anti AFK</kbd> to work. While toggled, <kbd>Anti AFK</kbd> will only activate when all of the following conditions are true:
|
||||||
|
* The `Grand Theft Auto V` window is currently focused
|
||||||
|
* None of the designated keys are currently being pressed[^1]
|
||||||
|
* The mouse cursor is not currently visible[^2]
|
||||||
|
|
||||||
|
#### Network
|
||||||
|
|
||||||
|
The last section has a single feature, <kbd>Game's network access</kbd>, with two buttons, <kbd>Block</kbd> and <kbd>Unblock</kbd>, and a coloured indicator dot. This feature requires administrator, and blocks/unblocks GTA V's entire internet access using the Windows Firewall. The coloured indicator dot has these meanings:
|
||||||
|
* **Green** - the game is connected to the internet
|
||||||
|
* **Yellow** - the game could not be found running, and thus was not blocked
|
||||||
|
* **Red** - the game is blocked from the internet
|
||||||
|
|
||||||
|
This feature is primarily useful for **replay glitching**, which is an exploit that allows you to complete any heist/mission finale, get the money for it, and then be able to do it again right away. Here's how you can do a replay glitch:
|
||||||
|
1. Get to the finale of a heist/contract/mission series, such as **The Contract: Dr. Dre**
|
||||||
|
2. Complete the finale as normal
|
||||||
|
3. Right *after* the **HEIST/MISSION PASSED** screen you get when you complete a finale (basically, when your cut is being shown), <kbd>Block</kbd> the game's internet access
|
||||||
|
4. After a few seconds, you will be shown an error screen and kicked to the main menu
|
||||||
|
5. At this point, <kbd>Unblock</kbd> the game's internet access and load back into online
|
||||||
|
6. Finally, spend any amount of money, and you should receive the finale cut, but also be able to go play the finale again immediately
|
||||||
|
|
||||||
|
[^1]: Otherwise, if you are, for example, using those keys to fly a plane, <kbd>Anti AFK</kbd> activating could cancel the input.
|
||||||
|
[^2]: Specifically, the Windows mouse cursor, not the in-game mouse cursor. This check is mostly used to prevent typing while you are in the Rockstar overlay.
|
||||||
|
|||||||
+21
-24
@@ -1,8 +1,8 @@
|
|||||||
use crate::util::{self, consts::game::WINDOW_TITLE};
|
use crate::util::{self, consts::game::WINDOW_TITLE};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use windows::Win32::UI::Input::KeyboardAndMouse::{
|
use windows::Win32::UI::Input::KeyboardAndMouse::{
|
||||||
KEYBD_EVENT_FLAGS, MAP_VIRTUAL_KEY_TYPE, MapVirtualKeyW, VIRTUAL_KEY, VK_NUMPAD4, VK_NUMPAD6,
|
INPUT, INPUT_KEYBOARD, KEYBD_EVENT_FLAGS, KEYBDINPUT, KEYEVENTF_KEYUP, MAPVK_VK_TO_VSC,
|
||||||
keybd_event,
|
MapVirtualKeyW, SendInput, VIRTUAL_KEY, VK_NUMPAD4, VK_NUMPAD6,
|
||||||
};
|
};
|
||||||
|
|
||||||
const INTERVAL: Duration = Duration::from_secs(60);
|
const INTERVAL: Duration = Duration::from_secs(60);
|
||||||
@@ -40,26 +40,23 @@ impl AntiAfk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn send(vk_codes: &[VIRTUAL_KEY]) {
|
fn send(vk_codes: &[VIRTUAL_KEY]) {
|
||||||
vk_codes.iter().for_each(|vk_code| unsafe {
|
let mut inputs = Vec::new();
|
||||||
keybd_event(
|
for &vk_code in vk_codes {
|
||||||
vk_code.0 as u8,
|
let scan_code = unsafe { MapVirtualKeyW(u32::from(vk_code.0), MAPVK_VK_TO_VSC) as u16 };
|
||||||
u8::try_from(MapVirtualKeyW(
|
for event in [KEYBD_EVENT_FLAGS(0), KEYEVENTF_KEYUP] {
|
||||||
u32::from(vk_code.0),
|
let mut input = INPUT {
|
||||||
MAP_VIRTUAL_KEY_TYPE(0),
|
r#type: INPUT_KEYBOARD,
|
||||||
))
|
..Default::default()
|
||||||
.unwrap(),
|
};
|
||||||
KEYBD_EVENT_FLAGS(0),
|
input.Anonymous.ki = KEYBDINPUT {
|
||||||
0,
|
wVk: vk_code,
|
||||||
);
|
wScan: scan_code,
|
||||||
keybd_event(
|
dwFlags: event,
|
||||||
vk_code.0 as u8,
|
time: 0,
|
||||||
u8::try_from(MapVirtualKeyW(
|
dwExtraInfo: 0,
|
||||||
u32::from(vk_code.0),
|
};
|
||||||
MAP_VIRTUAL_KEY_TYPE(0),
|
inputs.push(input);
|
||||||
))
|
}
|
||||||
.unwrap(),
|
}
|
||||||
KEYBD_EVENT_FLAGS(2),
|
unsafe { SendInput(&inputs, size_of::<INPUT>() as i32) };
|
||||||
0,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-18
@@ -7,8 +7,8 @@ const INTERVAL: Duration = Duration::from_secs(3);
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ForceClose {
|
pub struct ForceClose {
|
||||||
pub button_text: String,
|
pub button_text: String,
|
||||||
prompting: bool,
|
timer: Instant,
|
||||||
interval: Instant,
|
counting: bool,
|
||||||
current_frame: bool,
|
current_frame: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,8 +16,8 @@ impl Default for ForceClose {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
button_text: "Force close game".to_owned(),
|
button_text: "Force close game".to_owned(),
|
||||||
prompting: false,
|
timer: Instant::now(),
|
||||||
interval: Instant::now(),
|
counting: false,
|
||||||
current_frame: false,
|
current_frame: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,22 +25,26 @@ impl Default for ForceClose {
|
|||||||
|
|
||||||
impl ForceClose {
|
impl ForceClose {
|
||||||
pub fn prompt(&mut self, force_close_button_clicked: bool, sysinfo: &mut System) {
|
pub fn prompt(&mut self, force_close_button_clicked: bool, sysinfo: &mut System) {
|
||||||
if force_close_button_clicked && !self.prompting {
|
if force_close_button_clicked && !self.counting {
|
||||||
*self = Self {
|
self.button_text = "Are you sure?".to_owned();
|
||||||
button_text: "Are you sure?".to_owned(),
|
self.timer = Instant::now();
|
||||||
prompting: true,
|
self.counting = true;
|
||||||
interval: Instant::now(),
|
self.current_frame = true;
|
||||||
current_frame: true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if self.prompting && self.interval.elapsed() <= INTERVAL {
|
if self.counting && self.timer.elapsed() >= INTERVAL {
|
||||||
if force_close_button_clicked && !self.current_frame {
|
self.reset();
|
||||||
activate(sysinfo);
|
} else if force_close_button_clicked && !self.current_frame {
|
||||||
*self = Self::default();
|
activate(sysinfo);
|
||||||
}
|
self.reset();
|
||||||
} else {
|
|
||||||
*self = Self::default();
|
|
||||||
}
|
}
|
||||||
|
self.finish_current_frame();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reset(&mut self) {
|
||||||
|
*self = Self::default();
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn finish_current_frame(&mut self) {
|
||||||
if self.current_frame {
|
if self.current_frame {
|
||||||
self.current_frame = false;
|
self.current_frame = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
use crate::util::consts::game::{EXE_ENHANCED, EXE_LEGACY};
|
use crate::util::consts::game::{EXE_ENHANCED, EXE_LEGACY};
|
||||||
use std::path::Path;
|
use std::{
|
||||||
|
path::Path,
|
||||||
|
time::{Duration, Instant},
|
||||||
|
};
|
||||||
|
use strum::{Display, EnumIter};
|
||||||
use sysinfo::System;
|
use sysinfo::System;
|
||||||
use windows::{
|
use windows::{
|
||||||
Win32::{
|
Win32::{
|
||||||
Foundation::E_INVALIDARG,
|
|
||||||
NetworkManagement::WindowsFirewall::{
|
NetworkManagement::WindowsFirewall::{
|
||||||
INetFwPolicy2, INetFwRule, NET_FW_ACTION_BLOCK, NET_FW_IP_PROTOCOL_ANY,
|
INetFwPolicy2, INetFwRule, NET_FW_ACTION_BLOCK, NET_FW_IP_PROTOCOL_ANY,
|
||||||
NET_FW_RULE_DIR_IN, NET_FW_RULE_DIR_OUT, NetFwPolicy2, NetFwRule,
|
NET_FW_RULE_DIR_IN, NET_FW_RULE_DIR_OUT, NetFwPolicy2, NetFwRule,
|
||||||
@@ -13,29 +16,47 @@ use windows::{
|
|||||||
CoUninitialize,
|
CoUninitialize,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
core::{BSTR, HRESULT},
|
core::BSTR,
|
||||||
};
|
};
|
||||||
|
|
||||||
const FILTER_NAME_IN: &str = "[GTA Tools] Block all inbound traffic for GTA V";
|
const FILTER_NAME_IN: &str = "[GTA Tools] Block all inbound traffic for GTA V";
|
||||||
const FILTER_NAME_OUT: &str = "[GTA Tools] Block all outbound traffic for GTA V";
|
const FILTER_NAME_OUT: &str = "[GTA Tools] Block all outbound traffic for GTA V";
|
||||||
|
|
||||||
|
const INTERVAL: Duration = Duration::from_secs(3);
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Display, PartialEq, Eq, EnumIter)]
|
||||||
|
pub enum BlockedStatus {
|
||||||
|
Blocked,
|
||||||
|
Failed,
|
||||||
|
Unblocked,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<bool> for BlockedStatus {
|
||||||
|
fn from(value: bool) -> Self {
|
||||||
|
if value {
|
||||||
|
Self::Blocked
|
||||||
|
} else {
|
||||||
|
Self::Unblocked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct GameNetworking {
|
pub struct GameNetworking {
|
||||||
pub is_blocked: bool,
|
|
||||||
com_initialized: bool,
|
com_initialized: bool,
|
||||||
policy: INetFwPolicy2,
|
pub blocked_status: BlockedStatus,
|
||||||
|
timer: Instant,
|
||||||
|
counting: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for GameNetworking {
|
impl Default for GameNetworking {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let result = unsafe { CoInitializeEx(None, COINIT_MULTITHREADED) };
|
Self {
|
||||||
let mut gn = Self {
|
blocked_status: Self::is_blocked().into(),
|
||||||
is_blocked: false,
|
com_initialized: unsafe { CoInitializeEx(None, COINIT_MULTITHREADED) }.is_ok(),
|
||||||
com_initialized: result != HRESULT(0x80010106u32 as i32),
|
timer: Instant::now(),
|
||||||
policy: unsafe { CoCreateInstance(&NetFwPolicy2, None, CLSCTX_INPROC_SERVER).unwrap() },
|
counting: false,
|
||||||
};
|
}
|
||||||
gn.is_blocked = gn.is_blocked();
|
|
||||||
gn
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,66 +73,64 @@ impl Drop for GameNetworking {
|
|||||||
impl GameNetworking {
|
impl GameNetworking {
|
||||||
pub fn block_all(&mut self, sysinfo: &mut System) {
|
pub fn block_all(&mut self, sysinfo: &mut System) {
|
||||||
let Some(exe_path) = get_game_exe_path(sysinfo) else {
|
let Some(exe_path) = get_game_exe_path(sysinfo) else {
|
||||||
|
self.blocked_status = BlockedStatus::Failed;
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let rules = unsafe { self.policy.Rules().unwrap() };
|
let policy: INetFwPolicy2 =
|
||||||
let filter_name_in = BSTR::from(FILTER_NAME_IN);
|
unsafe { CoCreateInstance(&NetFwPolicy2, None, CLSCTX_INPROC_SERVER).unwrap() };
|
||||||
let filter_name_out = BSTR::from(FILTER_NAME_OUT);
|
let rules = unsafe { policy.Rules().unwrap() };
|
||||||
unsafe {
|
|
||||||
let _ = rules.Remove(&filter_name_in);
|
|
||||||
let _ = rules.Remove(&filter_name_out);
|
|
||||||
}
|
|
||||||
let exe_path = BSTR::from(exe_path.to_string_lossy().to_string());
|
let exe_path = BSTR::from(exe_path.to_string_lossy().to_string());
|
||||||
unsafe {
|
for filter in [
|
||||||
let inbound_rule: INetFwRule =
|
(FILTER_NAME_IN, NET_FW_RULE_DIR_IN),
|
||||||
CoCreateInstance(&NetFwRule, None, CLSCTX_INPROC_SERVER).unwrap();
|
(FILTER_NAME_OUT, NET_FW_RULE_DIR_OUT),
|
||||||
inbound_rule.SetName(&filter_name_in).unwrap();
|
] {
|
||||||
inbound_rule.SetApplicationName(&exe_path).unwrap();
|
let _ = unsafe { rules.Remove(&BSTR::from(filter.0)) };
|
||||||
inbound_rule.SetDirection(NET_FW_RULE_DIR_IN).unwrap();
|
unsafe {
|
||||||
inbound_rule.SetEnabled(true.into()).unwrap();
|
let rule: INetFwRule =
|
||||||
inbound_rule.SetAction(NET_FW_ACTION_BLOCK).unwrap();
|
CoCreateInstance(&NetFwRule, None, CLSCTX_INPROC_SERVER).unwrap();
|
||||||
inbound_rule.SetProtocol(NET_FW_IP_PROTOCOL_ANY.0).unwrap();
|
rule.SetName(&BSTR::from(filter.0)).unwrap();
|
||||||
rules.Add(&inbound_rule).unwrap();
|
rule.SetApplicationName(&exe_path).unwrap();
|
||||||
|
rule.SetDirection(filter.1).unwrap();
|
||||||
|
rule.SetEnabled(true.into()).unwrap();
|
||||||
|
rule.SetAction(NET_FW_ACTION_BLOCK).unwrap();
|
||||||
|
rule.SetProtocol(NET_FW_IP_PROTOCOL_ANY.0).unwrap();
|
||||||
|
rules.Add(&rule).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
unsafe {
|
self.blocked_status = Self::is_blocked().into();
|
||||||
let outbound_rule: INetFwRule =
|
|
||||||
CoCreateInstance(&NetFwRule, None, CLSCTX_INPROC_SERVER).unwrap();
|
|
||||||
outbound_rule.SetName(&filter_name_out).unwrap();
|
|
||||||
outbound_rule.SetApplicationName(&exe_path).unwrap();
|
|
||||||
outbound_rule.SetDirection(NET_FW_RULE_DIR_OUT).unwrap();
|
|
||||||
outbound_rule.SetEnabled(true.into()).unwrap();
|
|
||||||
outbound_rule.SetAction(NET_FW_ACTION_BLOCK).unwrap();
|
|
||||||
outbound_rule.SetProtocol(NET_FW_IP_PROTOCOL_ANY.0).unwrap();
|
|
||||||
rules.Add(&outbound_rule).unwrap();
|
|
||||||
}
|
|
||||||
self.is_blocked = self.is_blocked();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unblock_all(&mut self) {
|
pub fn unblock_all(&mut self) {
|
||||||
let rules = unsafe { self.policy.Rules().unwrap() };
|
let policy: INetFwPolicy2 =
|
||||||
unsafe {
|
unsafe { CoCreateInstance(&NetFwPolicy2, None, CLSCTX_INPROC_SERVER).unwrap() };
|
||||||
let result = rules.Remove(&BSTR::from(FILTER_NAME_IN));
|
let rules = unsafe { policy.Rules().unwrap() };
|
||||||
if let Err(ref why) = result {
|
unsafe { rules.Remove(&BSTR::from(FILTER_NAME_IN)).unwrap() };
|
||||||
if why.code() != E_INVALIDARG {
|
unsafe { rules.Remove(&BSTR::from(FILTER_NAME_OUT)).unwrap() };
|
||||||
result.unwrap();
|
self.blocked_status = Self::is_blocked().into();
|
||||||
}
|
|
||||||
}
|
|
||||||
let result = rules.Remove(&BSTR::from(FILTER_NAME_OUT));
|
|
||||||
if let Err(ref why) = result {
|
|
||||||
if why.code() != E_INVALIDARG {
|
|
||||||
result.unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.is_blocked = self.is_blocked();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_blocked(&self) -> bool {
|
fn is_blocked() -> bool {
|
||||||
let rules = unsafe { self.policy.Rules().unwrap() };
|
let policy: INetFwPolicy2 =
|
||||||
|
unsafe { CoCreateInstance(&NetFwPolicy2, None, CLSCTX_INPROC_SERVER).unwrap() };
|
||||||
|
let rules = unsafe { policy.Rules().unwrap() };
|
||||||
let in_rule_exists = unsafe { rules.Item(&BSTR::from(FILTER_NAME_IN)).is_ok() };
|
let in_rule_exists = unsafe { rules.Item(&BSTR::from(FILTER_NAME_IN)).is_ok() };
|
||||||
let out_rule_exists = unsafe { rules.Item(&BSTR::from(FILTER_NAME_OUT)).is_ok() };
|
let out_rule_exists = unsafe { rules.Item(&BSTR::from(FILTER_NAME_OUT)).is_ok() };
|
||||||
in_rule_exists || out_rule_exists
|
in_rule_exists || out_rule_exists
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn if_failed_return_to_boolean(&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_blocked().into();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_game_exe_path(sysinfo: &mut System) -> Option<&Path> {
|
fn get_game_exe_path(sysinfo: &mut System) -> Option<&Path> {
|
||||||
|
|||||||
+20
-8
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::gui::settings::LaunchVersion;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{path::PathBuf, process::Command};
|
use std::{path::PathBuf, process::Command};
|
||||||
use strum::{Display, EnumIter};
|
use strum::{Display, EnumIter};
|
||||||
@@ -18,16 +19,24 @@ pub struct Launch {
|
|||||||
pub selected: Platform,
|
pub selected: Platform,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn launch(platform: &Platform) {
|
pub fn launch(platform: &Platform, version: &LaunchVersion) {
|
||||||
match platform {
|
match platform {
|
||||||
Platform::Steam => {
|
Platform::Steam => {
|
||||||
let _ = open::that_detached("steam://run/3240220");
|
let steam_url = if *version == LaunchVersion::Enhanced {
|
||||||
|
"steam://run/3240220"
|
||||||
|
} else {
|
||||||
|
"steam://run/271590"
|
||||||
|
};
|
||||||
|
let _ = open::that_detached(steam_url);
|
||||||
}
|
}
|
||||||
Platform::Rockstar => {
|
Platform::Rockstar => {
|
||||||
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
|
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
|
||||||
let Ok(gta_v_enhanced) =
|
let rockstar_url = if *version == LaunchVersion::Enhanced {
|
||||||
hklm.open_subkey(r"SOFTWARE\WOW6432Node\Rockstar Games\GTAV Enhanced")
|
r"SOFTWARE\WOW6432Node\Rockstar Games\GTAV Enhanced"
|
||||||
else {
|
} else {
|
||||||
|
r"SOFTWARE\WOW6432Node\Rockstar Games\Grand Theft Auto V"
|
||||||
|
};
|
||||||
|
let Ok(gta_v_enhanced) = hklm.open_subkey(rockstar_url) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let Ok(install_folder): Result<String, std::io::Error> =
|
let Ok(install_folder): Result<String, std::io::Error> =
|
||||||
@@ -40,9 +49,12 @@ pub fn launch(platform: &Platform) {
|
|||||||
let _ = Command::new(play_gtav_path).spawn();
|
let _ = Command::new(play_gtav_path).spawn();
|
||||||
}
|
}
|
||||||
Platform::Epic => {
|
Platform::Epic => {
|
||||||
let _ = open::that_detached(
|
let epic_url = if *version == LaunchVersion::Enhanced {
|
||||||
"com.epicgames.launcher://apps/331226ba7c944720baa99103cb1fe80c?action=launch&silent=true",
|
"com.epicgames.launcher://apps/8769e24080ea413b8ebca3f1b8c50951?action=launch&silent=true"
|
||||||
);
|
} else {
|
||||||
|
"com.epicgames.launcher://apps/9d2d0eb64d5c44529cece33fe2a46482?action=launch&silent=true"
|
||||||
|
};
|
||||||
|
let _ = open::that_detached(epic_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
mod app;
|
mod app;
|
||||||
|
mod colours;
|
||||||
mod debug;
|
mod debug;
|
||||||
pub mod run;
|
pub mod run;
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
mod tools;
|
mod tools;
|
||||||
|
mod ui_ext;
|
||||||
+43
-22
@@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
features,
|
features,
|
||||||
gui::{settings::Settings, tools},
|
gui::{colours, settings::Settings, tools, ui_ext::UiExt},
|
||||||
util::{consts::game::WINDOW_TITLE, meta::Meta, persistent_state::PersistentState, win},
|
util::{consts::game::WINDOW_TITLE, meta::Meta, persistent_state::PersistentState, win},
|
||||||
};
|
};
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
@@ -17,13 +17,23 @@ enum Stage {
|
|||||||
About,
|
About,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug)]
|
||||||
pub struct Flags {
|
pub struct Flags {
|
||||||
pub elevated: bool,
|
pub elevated: bool,
|
||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
closing: bool,
|
closing: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Flags {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
elevated: win::is_elevated(),
|
||||||
|
debug: false,
|
||||||
|
closing: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct App {
|
pub struct App {
|
||||||
pub meta: Meta,
|
pub meta: Meta,
|
||||||
@@ -35,7 +45,7 @@ pub struct App {
|
|||||||
pub anti_afk: features::anti_afk::AntiAfk,
|
pub anti_afk: features::anti_afk::AntiAfk,
|
||||||
empty_session: features::empty_session::EmptySession,
|
empty_session: features::empty_session::EmptySession,
|
||||||
force_close: features::force_close::ForceClose,
|
force_close: features::force_close::ForceClose,
|
||||||
game_networking: features::game_networking::GameNetworking,
|
pub game_networking: features::game_networking::GameNetworking,
|
||||||
pub launch: features::launch::Launch,
|
pub launch: features::launch::Launch,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +57,7 @@ impl eframe::App for App {
|
|||||||
.exact_height(25.0)
|
.exact_height(25.0)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
|
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
|
||||||
tools::build_menu::<Stage>(ui, &mut self.stage);
|
ui.build_menu(&mut self.stage);
|
||||||
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.flags.elevated, egui::Button::new("Elevate"))
|
.add_enabled(!self.flags.elevated, egui::Button::new("Elevate"))
|
||||||
@@ -82,16 +92,16 @@ impl eframe::App for App {
|
|||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
fn show_game_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
fn show_game_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
tools::header(ui, "Game");
|
ui.header("Game");
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Launch").clicked() {
|
if ui.button("Launch").clicked() {
|
||||||
features::launch::launch(&self.launch.selected);
|
features::launch::launch(&self.launch.selected, &self.settings.launch_version);
|
||||||
}
|
}
|
||||||
egui::ComboBox::from_id_salt("Launch")
|
egui::ComboBox::from_id_salt("Launch")
|
||||||
.selected_text(self.launch.selected.to_string())
|
.selected_text(self.launch.selected.to_string())
|
||||||
.width(120.0)
|
.width(120.0)
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
tools::build_menu(ui, &mut self.launch.selected);
|
ui.build_menu(&mut self.launch.selected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
let force_close_button = ui.add_sized(
|
let force_close_button = ui.add_sized(
|
||||||
@@ -103,7 +113,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show_session_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
fn show_session_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
tools::header(ui, "Session");
|
ui.header("Session");
|
||||||
ui.add_enabled_ui(!self.empty_session.disabled, |ui| {
|
ui.add_enabled_ui(!self.empty_session.disabled, |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Empty current session").clicked() {
|
if ui.button("Empty current session").clicked() {
|
||||||
@@ -134,14 +144,23 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show_network_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
fn show_network_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
tools::header(ui, "Network");
|
ui.header("Network");
|
||||||
egui::Frame::new()
|
egui::Frame::new()
|
||||||
.outer_margin(egui::vec2(0.0, -2.0))
|
.outer_margin(egui::vec2(0.0, -2.0))
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
let response = ui.add_enabled_ui(self.flags.elevated, |ui| {
|
let response = ui.add_enabled_ui(self.flags.elevated, |ui| {
|
||||||
let label = ui.label("Game's network access");
|
let label = ui.horizontal(|ui| {
|
||||||
|
let label = ui.label("Game's network access");
|
||||||
|
ui.add_space(1.0);
|
||||||
|
ui.create_indicator_dot(self.game_networking.blocked_status)
|
||||||
|
.on_hover_text(
|
||||||
|
"This turns yellow if GTA Tools\ncannot find your game.",
|
||||||
|
);
|
||||||
|
self.game_networking.if_failed_return_to_boolean();
|
||||||
|
label
|
||||||
|
});
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let available_width = label.rect.width();
|
let available_width = label.inner.rect.width();
|
||||||
let spacing = ui.spacing().item_spacing.x;
|
let spacing = ui.spacing().item_spacing.x;
|
||||||
let button_width = (available_width - spacing) / 2.0;
|
let button_width = (available_width - spacing) / 2.0;
|
||||||
if ui
|
if ui
|
||||||
@@ -156,15 +175,6 @@ impl App {
|
|||||||
{
|
{
|
||||||
self.game_networking.unblock_all();
|
self.game_networking.unblock_all();
|
||||||
}
|
}
|
||||||
let tint = match self.game_networking.is_blocked {
|
|
||||||
true => egui::Color32::from_hex("#f96554").unwrap(),
|
|
||||||
false => egui::Color32::from_hex("#68f954").unwrap(),
|
|
||||||
};
|
|
||||||
ui.add(
|
|
||||||
egui::Image::new(egui::include_image!("../../assets/circle.svg"))
|
|
||||||
.max_size([4.0, 4.0].into())
|
|
||||||
.tint(tint),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
response.response.on_disabled_hover_text(
|
response.response.on_disabled_hover_text(
|
||||||
@@ -180,13 +190,21 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show_settings_stage(&mut self, ctx: &egui::Context, ui: &mut egui::Ui) {
|
fn show_settings_stage(&mut self, ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.label("Launch version");
|
||||||
|
egui::ComboBox::from_id_salt("Launch version")
|
||||||
|
.selected_text(self.settings.launch_version.to_string())
|
||||||
|
.show_ui(ui, |ui| {
|
||||||
|
ui.build_menu(&mut self.settings.launch_version);
|
||||||
|
});
|
||||||
|
});
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let selection = self.settings.theme;
|
let selection = self.settings.theme;
|
||||||
ui.label("Theme");
|
ui.label("Theme");
|
||||||
egui::ComboBox::from_id_salt("Theme")
|
egui::ComboBox::from_id_salt("Theme")
|
||||||
.selected_text(self.settings.theme.to_string())
|
.selected_text(self.settings.theme.to_string())
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
tools::build_menu(ui, &mut self.settings.theme);
|
ui.build_menu(&mut self.settings.theme);
|
||||||
});
|
});
|
||||||
if selection != self.settings.theme {
|
if selection != self.settings.theme {
|
||||||
catppuccin_egui::set_theme(ctx, self.settings.theme.into());
|
catppuccin_egui::set_theme(ctx, self.settings.theme.into());
|
||||||
@@ -201,9 +219,12 @@ impl App {
|
|||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.spacing_mut().item_spacing.x = 0.0;
|
ui.spacing_mut().item_spacing.x = 0.0;
|
||||||
ui.label("with ");
|
ui.label("with ");
|
||||||
|
ui.style_mut().visuals.hyperlink_color = colours::RED;
|
||||||
ui.hyperlink_to("❤", "https://codeberg.org/futile/gta-tools");
|
ui.hyperlink_to("❤", "https://codeberg.org/futile/gta-tools");
|
||||||
ui.label(" from ");
|
ui.label(" from ");
|
||||||
ui.hyperlink_to("futile", "http://futile.eu");
|
ui.style_mut().visuals.hyperlink_color =
|
||||||
|
catppuccin_egui::Theme::from(self.settings.theme).text;
|
||||||
|
ui.hyperlink_to("futile", "https://futile.eu");
|
||||||
});
|
});
|
||||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||||
ui.label(format!(
|
ui.label(format!(
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
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<BlockedStatus> for egui::Color32 {
|
||||||
|
fn from(value: BlockedStatus) -> Self {
|
||||||
|
match value {
|
||||||
|
BlockedStatus::Blocked => RED,
|
||||||
|
BlockedStatus::Failed => YELLOW,
|
||||||
|
BlockedStatus::Unblocked => GREEN,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+65
-49
@@ -2,15 +2,78 @@ use crate::{
|
|||||||
gui::{
|
gui::{
|
||||||
app::{App, WINDOW_SIZE},
|
app::{App, WINDOW_SIZE},
|
||||||
tools,
|
tools,
|
||||||
|
ui_ext::UiExt,
|
||||||
},
|
},
|
||||||
util::consts::{
|
util::consts::{
|
||||||
APP_STORAGE_PATH,
|
|
||||||
game::{EXE_ENHANCED, EXE_LEGACY},
|
game::{EXE_ENHANCED, EXE_LEGACY},
|
||||||
|
path,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
|
fn add_debug_viewport_contents(&mut self, ui: &mut egui::Ui) {
|
||||||
|
ui.collapsing("misc", |ui| {
|
||||||
|
if ui.button("open storage path").clicked() {
|
||||||
|
open::that_detached(path::APP_STORAGE.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.horizontal(|ui| {
|
||||||
|
ui.label("blocked_status");
|
||||||
|
egui::ComboBox::from_id_salt("blocked_status")
|
||||||
|
.selected_text(self.game_networking.blocked_status.to_string())
|
||||||
|
.show_ui(ui, |ui| {
|
||||||
|
ui.build_menu(&mut self.game_networking.blocked_status);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
if ui
|
||||||
|
.add(egui::Button::new("force refresh theme"))
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
catppuccin_egui::set_theme(ui.ctx(), self.settings.theme.into());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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:#?}")));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn show_debug_viewport(&mut self, ctx: &egui::Context) {
|
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 main = ctx.input(|i| i.viewport().outer_rect.unwrap_or(egui::Rect::EVERYTHING));
|
||||||
let builder = egui::ViewportBuilder::default()
|
let builder = egui::ViewportBuilder::default()
|
||||||
@@ -30,54 +93,7 @@ impl App {
|
|||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
egui::ScrollArea::both()
|
egui::ScrollArea::both()
|
||||||
.auto_shrink([false, true])
|
.auto_shrink([false, true])
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| self.add_debug_viewport_contents(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:#?}")));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
+8
-24
@@ -3,50 +3,34 @@ use crate::{
|
|||||||
app::{App, WINDOW_SIZE},
|
app::{App, WINDOW_SIZE},
|
||||||
tools,
|
tools,
|
||||||
},
|
},
|
||||||
util::{self, consts::APP_STORAGE_PATH, persistent_state::PersistentState},
|
util::{persistent_state::PersistentState, win},
|
||||||
};
|
};
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use std::{fs::File, io::Write};
|
|
||||||
|
|
||||||
fn panic_hook(panic_info: &std::panic::PanicHookInfo<'_>) {
|
|
||||||
let log_path = APP_STORAGE_PATH.join("panic.log");
|
|
||||||
let mut file = File::options()
|
|
||||||
.create(true)
|
|
||||||
.append(true)
|
|
||||||
.open(log_path)
|
|
||||||
.unwrap();
|
|
||||||
let timestamp = chrono::Local::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, false);
|
|
||||||
let backtrace = std::backtrace::Backtrace::force_capture();
|
|
||||||
let message = format!("[{timestamp}]\n{panic_info}\nstack backtrace:\n{backtrace}\n");
|
|
||||||
file.write_all(message.as_bytes()).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn app_creator(
|
fn app_creator(
|
||||||
cc: &eframe::CreationContext<'_>,
|
cc: &eframe::CreationContext<'_>,
|
||||||
) -> Result<Box<dyn eframe::App>, Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<Box<dyn eframe::App>, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
// use our own panic hook which logs all panics to a file
|
|
||||||
std::panic::set_hook(Box::new(panic_hook));
|
|
||||||
// initialize App early to modify some things before returning it
|
// initialize App early to modify some things before returning it
|
||||||
let mut app = Box::<App>::default();
|
let mut app = Box::new(App::default());
|
||||||
// load previously selected launch platform & settings from persistent state
|
// load previously selected launch platform & settings from persistent state
|
||||||
if let Some(persistent_state) = PersistentState::get() {
|
if let Some(persistent_state) = PersistentState::get() {
|
||||||
app.launch.selected = persistent_state.launcher;
|
app.launch.selected = persistent_state.launcher;
|
||||||
app.settings = persistent_state.settings;
|
app.settings = persistent_state.settings;
|
||||||
}
|
}
|
||||||
// check if we're elevated. if not, and the user wants an elevated launch - relaunch elevated
|
// check if we're elevated. if not, and the user wants an elevated launch - relaunch elevated
|
||||||
let elevated = util::win::is_elevated();
|
if !app.flags.elevated && app.settings.start_elevated {
|
||||||
if app.settings.start_elevated && !elevated {
|
win::elevate(win::ElevationExitMethod::Forced);
|
||||||
util::win::elevate(util::win::ElevationExitMethod::Forced);
|
|
||||||
}
|
}
|
||||||
app.flags.elevated = elevated;
|
|
||||||
// refresh sysinfo because it initializes with nothing
|
// refresh sysinfo because it initializes with nothing
|
||||||
app.sysinfo.refresh_all();
|
app.sysinfo.refresh_all();
|
||||||
// enable image loading support in egui
|
// enable image loading support in egui
|
||||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||||
// set our initial theme, from earlier loaded settings
|
// set our initial theme, from earlier loaded settings. we set the egui theme
|
||||||
|
// to dark here to work around system theme based switching of the egui style
|
||||||
|
cc.egui_ctx.set_theme(egui::Theme::Dark);
|
||||||
catppuccin_egui::set_theme(&cc.egui_ctx, app.settings.theme.into());
|
catppuccin_egui::set_theme(&cc.egui_ctx, app.settings.theme.into());
|
||||||
// apply some global styling that we like
|
// apply some global styling that we like
|
||||||
cc.egui_ctx.style_mut(|style| {
|
cc.egui_ctx.all_styles_mut(|style| {
|
||||||
style.spacing.item_spacing = egui::vec2(4.0, 4.0);
|
style.spacing.item_spacing = egui::vec2(4.0, 4.0);
|
||||||
style.interaction.selectable_labels = false;
|
style.interaction.selectable_labels = false;
|
||||||
});
|
});
|
||||||
|
|||||||
+21
-11
@@ -1,8 +1,19 @@
|
|||||||
|
use crate::util::win;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum::{Display, EnumIter};
|
use strum::{Display, EnumIter};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Display, PartialEq, Eq, Serialize, Deserialize, EnumIter)]
|
#[derive(Clone, Copy, Debug, Default, Display, PartialEq, Eq, Serialize, Deserialize, EnumIter)]
|
||||||
|
pub enum LaunchVersion {
|
||||||
|
#[default]
|
||||||
|
Enhanced,
|
||||||
|
Legacy,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Default, Display, PartialEq, Eq, Serialize, Deserialize, EnumIter)]
|
||||||
pub enum Theme {
|
pub enum Theme {
|
||||||
|
#[default]
|
||||||
|
#[strum(to_string = "Auto")]
|
||||||
|
Auto,
|
||||||
#[strum(to_string = "Catppuccin Latte")]
|
#[strum(to_string = "Catppuccin Latte")]
|
||||||
CatppuccinLatte,
|
CatppuccinLatte,
|
||||||
#[strum(to_string = "Catppuccin Frappe")]
|
#[strum(to_string = "Catppuccin Frappe")]
|
||||||
@@ -16,6 +27,13 @@ pub enum Theme {
|
|||||||
impl From<Theme> for catppuccin_egui::Theme {
|
impl From<Theme> for catppuccin_egui::Theme {
|
||||||
fn from(val: Theme) -> Self {
|
fn from(val: Theme) -> Self {
|
||||||
match val {
|
match val {
|
||||||
|
Theme::Auto => {
|
||||||
|
if win::is_system_theme_dark() {
|
||||||
|
catppuccin_egui::MOCHA
|
||||||
|
} else {
|
||||||
|
catppuccin_egui::LATTE
|
||||||
|
}
|
||||||
|
}
|
||||||
Theme::CatppuccinLatte => catppuccin_egui::LATTE,
|
Theme::CatppuccinLatte => catppuccin_egui::LATTE,
|
||||||
Theme::CatppuccinFrappe => catppuccin_egui::FRAPPE,
|
Theme::CatppuccinFrappe => catppuccin_egui::FRAPPE,
|
||||||
Theme::CatppuccinMacchiato => catppuccin_egui::MACCHIATO,
|
Theme::CatppuccinMacchiato => catppuccin_egui::MACCHIATO,
|
||||||
@@ -24,17 +42,9 @@ impl From<Theme> for catppuccin_egui::Theme {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
|
pub launch_version: LaunchVersion,
|
||||||
pub theme: Theme,
|
pub theme: Theme,
|
||||||
pub start_elevated: bool,
|
pub start_elevated: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
theme: Theme::CatppuccinMocha,
|
|
||||||
start_elevated: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,25 +11,6 @@ pub fn load_icon() -> egui::IconData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub 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());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build_menu<E>(ui: &mut egui::Ui, current_value: &mut E)
|
|
||||||
where
|
|
||||||
E: strum::IntoEnumIterator + std::fmt::Display + std::cmp::PartialEq + Copy,
|
|
||||||
{
|
|
||||||
E::iter().for_each(|variant| {
|
|
||||||
ui.selectable_value(current_value, variant, variant.to_string());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn debug_keycombo_pressed(ctx: &egui::Context) -> bool {
|
pub fn debug_keycombo_pressed(ctx: &egui::Context) -> bool {
|
||||||
ctx.input(|i| i.modifiers.all() && i.key_pressed(egui::Key::D))
|
ctx.input(|i| i.modifiers.all() && i.key_pressed(egui::Key::D))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
use eframe::egui;
|
||||||
|
|
||||||
|
pub trait UiExt {
|
||||||
|
fn header(&mut self, text: &str);
|
||||||
|
fn build_menu<E>(&mut self, current_value: &mut E)
|
||||||
|
where
|
||||||
|
E: strum::IntoEnumIterator + std::fmt::Display + std::cmp::PartialEq + Copy;
|
||||||
|
fn create_indicator_dot(&mut self, colour: impl Into<egui::Color32>) -> egui::Response;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UiExt for egui::Ui {
|
||||||
|
fn header(&mut self, text: &str) {
|
||||||
|
self.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_menu<E>(&mut self, current_value: &mut E)
|
||||||
|
where
|
||||||
|
E: strum::IntoEnumIterator + std::fmt::Display + std::cmp::PartialEq + Copy,
|
||||||
|
{
|
||||||
|
E::iter().for_each(|variant| {
|
||||||
|
self.selectable_value(current_value, variant, variant.to_string());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_indicator_dot(&mut self, colour: impl Into<egui::Color32>) -> egui::Response {
|
||||||
|
self.add(
|
||||||
|
egui::Image::new(egui::include_image!("../../assets/circle.svg"))
|
||||||
|
.max_size([4.0, 4.0].into())
|
||||||
|
.tint(colour),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
@@ -1,9 +1,26 @@
|
|||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
compile_error!("This application must be compiled for Windows.");
|
||||||
|
|
||||||
mod features;
|
mod features;
|
||||||
mod gui;
|
mod gui;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
|
fn init_storage() {
|
||||||
|
if !crate::util::consts::path::APP_STORAGE.exists() {
|
||||||
|
std::fs::create_dir(crate::util::consts::path::APP_STORAGE.as_path()).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn panic_hook(panic_info: &std::panic::PanicHookInfo<'_>) {
|
||||||
|
let backtrace = std::backtrace::Backtrace::capture();
|
||||||
|
let message = format!("{panic_info}\nstack backtrace:\n{backtrace}\n");
|
||||||
|
crate::util::log::log(crate::util::log::LogLevel::Panic, &message);
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
init_storage();
|
||||||
|
std::panic::set_hook(Box::new(panic_hook));
|
||||||
gui::run::run();
|
gui::run::run();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
mod codeberg;
|
mod codeberg;
|
||||||
pub mod consts;
|
pub mod consts;
|
||||||
pub mod countdown;
|
pub mod countdown;
|
||||||
|
pub mod log;
|
||||||
pub mod meta;
|
pub mod meta;
|
||||||
pub mod persistent_state;
|
pub mod persistent_state;
|
||||||
pub mod win;
|
pub mod win;
|
||||||
+26
-11
@@ -1,4 +1,6 @@
|
|||||||
use semver::Version;
|
use semver::Version;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
const APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
const APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
||||||
const CODEBERG_ENDPOINT_ROOT: &str = "https://codeberg.org/api/v1";
|
const CODEBERG_ENDPOINT_ROOT: &str = "https://codeberg.org/api/v1";
|
||||||
@@ -12,24 +14,37 @@ pub struct Release {
|
|||||||
impl Default for Release {
|
impl Default for Release {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
version: Version::parse(env!("CARGO_PKG_VERSION")).unwrap(),
|
version: Version::new(0, 0, 0),
|
||||||
download_url: String::new(),
|
download_url: String::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_latest_release() -> Option<Release> {
|
#[derive(Deserialize)]
|
||||||
|
struct LatestRelease {
|
||||||
|
tag_name: String,
|
||||||
|
assets: Vec<Asset>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct Asset {
|
||||||
|
browser_download_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_latest_release() -> Result<Release, Box<dyn std::error::Error>> {
|
||||||
let request_url = format!("{CODEBERG_ENDPOINT_ROOT}/repos/futile/gta-tools/releases/latest");
|
let request_url = format!("{CODEBERG_ENDPOINT_ROOT}/repos/futile/gta-tools/releases/latest");
|
||||||
let ureq: ureq::Agent = ureq::Agent::config_builder()
|
let mut response = ureq::get(request_url)
|
||||||
|
.config()
|
||||||
|
.timeout_global(Some(Duration::from_secs(10)))
|
||||||
.user_agent(APP_USER_AGENT)
|
.user_agent(APP_USER_AGENT)
|
||||||
.build()
|
.build()
|
||||||
.into();
|
.call()?;
|
||||||
let mut response = ureq.get(request_url).call().ok()?;
|
let body = response.body_mut();
|
||||||
let json = response.body_mut().read_json::<serde_json::Value>().ok()?;
|
let json = body.read_json::<LatestRelease>()?;
|
||||||
let tag_name = json["tag_name"].as_str()?;
|
let tag_name = json.tag_name;
|
||||||
let browser_download_url = json["assets"][0]["browser_download_url"].as_str()?;
|
let browser_download_url = &json.assets[0].browser_download_url;
|
||||||
Some(Release {
|
Ok(Release {
|
||||||
version: Version::parse(tag_name).expect("expected a valid semver pattern"),
|
version: Version::parse(&tag_name)?,
|
||||||
download_url: String::from(browser_download_url),
|
download_url: browser_download_url.to_owned(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-4
@@ -1,7 +1,12 @@
|
|||||||
use std::{path::PathBuf, sync::LazyLock};
|
pub mod path {
|
||||||
|
use std::{env, path::PathBuf, sync::LazyLock};
|
||||||
pub static APP_STORAGE_PATH: LazyLock<PathBuf> =
|
pub static APP_STORAGE: LazyLock<PathBuf> = LazyLock::new(|| {
|
||||||
LazyLock::new(|| dirs::config_local_dir().unwrap().join("GTA Tools"));
|
PathBuf::from(env::var("LOCALAPPDATA").unwrap_or_else(|_| String::from(".")))
|
||||||
|
.join("GTA Tools")
|
||||||
|
});
|
||||||
|
pub static APP_CONFIG: LazyLock<PathBuf> = LazyLock::new(|| APP_STORAGE.join("config.json"));
|
||||||
|
pub static APP_LOG: LazyLock<PathBuf> = LazyLock::new(|| APP_STORAGE.join("gta-tools.log"));
|
||||||
|
}
|
||||||
|
|
||||||
pub mod game {
|
pub mod game {
|
||||||
pub const EXE_ENHANCED: &str = "GTA5_Enhanced.exe";
|
pub const EXE_ENHANCED: &str = "GTA5_Enhanced.exe";
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
use crate::util::consts::path;
|
||||||
|
use std::{fs::File, io::Write};
|
||||||
|
use strum::Display;
|
||||||
|
|
||||||
|
#[derive(Display)]
|
||||||
|
pub enum LogLevel {
|
||||||
|
Error,
|
||||||
|
Panic,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn log(level: LogLevel, message: &str) {
|
||||||
|
let mut file = File::options()
|
||||||
|
.create(true)
|
||||||
|
.append(true)
|
||||||
|
.open(path::APP_LOG.as_path())
|
||||||
|
.unwrap();
|
||||||
|
let timestamp = chrono::Local::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, false);
|
||||||
|
let message = format!("[{timestamp}] [{level}]\n{message}\n\n");
|
||||||
|
file.write_all(message.as_bytes()).unwrap();
|
||||||
|
}
|
||||||
+6
-2
@@ -1,4 +1,4 @@
|
|||||||
use crate::util::codeberg;
|
use crate::{util::codeberg, util::log};
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -11,7 +11,11 @@ pub struct Meta {
|
|||||||
impl Default for Meta {
|
impl Default for Meta {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let current_version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
let current_version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||||
let latest_release = codeberg::get_latest_release().unwrap_or_default();
|
let latest_release = codeberg::get_latest_release().unwrap_or_else(|why| {
|
||||||
|
let message = format!("failed to get latest codeberg release:\n{why}");
|
||||||
|
log::log(log::LogLevel::Error, &message);
|
||||||
|
codeberg::Release::default()
|
||||||
|
});
|
||||||
let newer_version_available = matches!(
|
let newer_version_available = matches!(
|
||||||
¤t_version.cmp_precedence(&latest_release.version),
|
¤t_version.cmp_precedence(&latest_release.version),
|
||||||
std::cmp::Ordering::Less
|
std::cmp::Ordering::Less
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
use crate::{features::launch::Platform, gui::settings::Settings, util::consts::APP_STORAGE_PATH};
|
use crate::{features::launch::Platform, gui::settings::Settings, util::consts::path};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
io::Write,
|
io::Write,
|
||||||
path::PathBuf,
|
|
||||||
sync::LazyLock,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static CONFIG_PATH: LazyLock<PathBuf> = LazyLock::new(|| APP_STORAGE_PATH.join("config.json"));
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct PersistentState {
|
pub struct PersistentState {
|
||||||
pub launcher: Platform,
|
pub launcher: Platform,
|
||||||
@@ -17,18 +13,13 @@ pub struct PersistentState {
|
|||||||
|
|
||||||
impl PersistentState {
|
impl PersistentState {
|
||||||
pub fn get() -> Option<Self> {
|
pub fn get() -> Option<Self> {
|
||||||
fs::read_to_string(CONFIG_PATH.as_path())
|
fs::read_to_string(path::APP_CONFIG.as_path())
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|config| serde_json::from_str::<Self>(&config).ok())
|
.and_then(|config| serde_json::from_str::<Self>(&config).ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set(&self) {
|
pub fn set(&self) {
|
||||||
let config_path = CONFIG_PATH.as_path();
|
let mut config_file = File::create(path::APP_CONFIG.as_path()).unwrap();
|
||||||
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();
|
let json = serde_json::to_string_pretty(&self).unwrap();
|
||||||
config_file.write_all(json.as_bytes()).unwrap();
|
config_file.write_all(json.as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,3 +83,17 @@ pub fn is_elevated() -> bool {
|
|||||||
result.is_ok() && elevation.TokenIsElevated != 0
|
result.is_ok() && elevation.TokenIsElevated != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_system_theme_dark() -> bool {
|
||||||
|
use winreg::RegKey;
|
||||||
|
let hkcu = RegKey::predef(winreg::enums::HKEY_CURRENT_USER);
|
||||||
|
let Ok(subkey) =
|
||||||
|
hkcu.open_subkey("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize")
|
||||||
|
else {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
let Ok(dword): Result<u32, std::io::Error> = subkey.get_value("AppsUseLightTheme") else {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
dword != 1
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user