numerous improvements in gui and feature code

This commit is contained in:
2025-04-19 04:28:24 +01:00
parent 0257834d04
commit 27524e855a
7 changed files with 176 additions and 218 deletions
+21 -7
View File
@@ -28,6 +28,20 @@ impl Default for EmptySession {
}
}
impl EmptySession {
pub fn run_timers(&mut self, game_handle: &mut HANDLE) {
if self.disabled {
self.countdown.count();
} else {
self.countdown.reset();
}
if self.interval.elapsed() >= INTERVAL {
deactivate(game_handle);
self.disabled = false;
}
}
}
#[link(name = "ntdll")]
unsafe extern "system" {
pub unsafe fn NtSuspendProcess(ProcessHandle: HANDLE) -> NTSTATUS;
@@ -46,22 +60,22 @@ fn get_gta_pid(sysinfo: &mut System) -> u32 {
u32::MAX
}
pub fn activate(handle: &mut HANDLE, sysinfo: &mut System) {
pub fn activate(game_handle: &mut HANDLE, sysinfo: &mut System) {
let pid = get_gta_pid(sysinfo);
if pid == u32::MAX {
return;
}
unsafe {
*handle = OpenProcess(PROCESS_SUSPEND_RESUME, false, pid).unwrap();
let _ = NtSuspendProcess(*handle);
*game_handle = OpenProcess(PROCESS_SUSPEND_RESUME, false, pid).unwrap();
let _ = NtSuspendProcess(*game_handle);
}
}
pub fn deactivate(handle: &mut HANDLE) {
pub fn deactivate(game_handle: &mut HANDLE) {
unsafe {
if !handle.is_invalid() {
let _ = NtResumeProcess(*handle);
let _ = CloseHandle(*handle);
if !game_handle.is_invalid() {
let _ = NtResumeProcess(*game_handle);
let _ = CloseHandle(*game_handle);
}
}
}
+25 -5
View File
@@ -1,12 +1,15 @@
use crate::util::consts::game::{EXE_ENHANCED, EXE_LEGACY};
use std::time::Instant;
use std::time::{Duration, Instant};
use sysinfo::System;
pub const INTERVAL: Duration = Duration::from_secs(3);
#[derive(Debug)]
pub struct ForceClose {
pub button_text: String,
pub prompting: bool,
pub interval: Instant,
current_frame: bool,
}
impl Default for ForceClose {
@@ -15,15 +18,32 @@ impl Default for ForceClose {
button_text: "Force close game".to_owned(),
prompting: false,
interval: Instant::now(),
current_frame: false,
}
}
}
impl ForceClose {
pub fn prompting(&mut self) {
self.button_text = "Are you sure?".to_owned();
self.prompting = true;
self.interval = Instant::now();
pub fn prompt(&mut self, force_close_button_clicked: bool, sysinfo: &mut System) {
if force_close_button_clicked && !self.prompting {
*self = Self {
button_text: "Are you sure?".to_owned(),
prompting: true,
interval: Instant::now(),
current_frame: true,
}
}
if self.prompting && self.interval.elapsed() <= INTERVAL {
if force_close_button_clicked && !self.current_frame {
activate(sysinfo);
*self = Self::default();
}
} else {
*self = Self::default();
}
if self.current_frame {
self.current_frame = false;
}
}
}
+5 -14
View File
@@ -1,27 +1,18 @@
use serde::{Deserialize, Serialize};
use std::{fmt::Display, path::PathBuf, process::Command};
use strum::EnumIter;
use std::{path::PathBuf, process::Command};
use strum::{Display, EnumIter};
use winreg::{RegKey, enums::HKEY_LOCAL_MACHINE};
#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, Serialize, Deserialize, EnumIter)]
#[derive(Clone, Copy, Default, Debug, Display, PartialEq, Eq, Serialize, Deserialize, EnumIter)]
pub enum Platform {
#[default]
Steam,
#[strum(to_string = "Rockstar Games")]
Rockstar,
#[strum(to_string = "Epic Games")]
Epic,
}
impl Display for Platform {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let x = match self {
Self::Steam => "Steam",
Self::Rockstar => "Rockstar Games",
Self::Epic => "Epic Games",
};
write!(f, "{x}")
}
}
#[derive(Debug, Default)]
pub struct Launch {
pub selected: Platform,