initial commit

This commit is contained in:
2025-03-26 11:02:25 +00:00
commit 4bc0d697dc
14 changed files with 4691 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
use std::time::{Duration, Instant};
use windows::Win32::UI::Input::KeyboardAndMouse::{
KEYBD_EVENT_FLAGS, MAP_VIRTUAL_KEY_TYPE, MapVirtualKeyW, keybd_event,
};
pub const INTERVAL: Duration = Duration::from_secs(60);
const VK_SHIFT: u8 = 16;
pub struct AntiAfk {
pub enabled: bool,
pub interval: Instant,
}
impl Default for AntiAfk {
fn default() -> Self {
Self {
enabled: false,
interval: Instant::now(),
}
}
}
pub fn send(vk_code: u8) {
unsafe {
keybd_event(
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(),
KEYBD_EVENT_FLAGS(2),
0,
);
}
}
pub fn activate() {
send(VK_SHIFT);
}
+60
View File
@@ -0,0 +1,60 @@
use crate::gui::App;
use std::time::{Duration, Instant};
use sysinfo::System;
use windows::Win32::{
Foundation::{HANDLE, NTSTATUS},
System::Threading::{OpenProcess, PROCESS_SUSPEND_RESUME},
};
pub const INTERVAL: Duration = Duration::from_secs(10);
const ENHANCED: &str = "GTA5_Enhanced.exe";
const LEGACY: &str = "GTA5.exe";
pub struct EmptySession {
pub enabled: bool,
pub interval: Instant,
}
impl Default for EmptySession {
fn default() -> Self {
Self {
enabled: true,
interval: Instant::now(),
}
}
}
#[link(name = "ntdll")]
unsafe extern "system" {
pub unsafe fn NtSuspendProcess(ProcessHandle: HANDLE) -> NTSTATUS;
pub unsafe fn NtResumeProcess(ProcessHandle: HANDLE) -> NTSTATUS;
}
fn get_gta_pid(sysinfo: &mut System) -> u32 {
sysinfo.refresh_all();
if let Some((pid, _)) = sysinfo
.processes()
.iter()
.find(|(_, p)| p.name() == ENHANCED || p.name() == LEGACY)
{
return pid.as_u32();
};
u32::MAX
}
pub fn activate(app: &mut App) {
let pid = get_gta_pid(&mut app.sysinfo);
if pid == u32::MAX {
return;
}
unsafe {
app.game_handle = OpenProcess(PROCESS_SUSPEND_RESUME, false, pid).unwrap();
let _ = NtSuspendProcess(app.game_handle);
}
}
pub fn deactivate(app: &mut App) {
unsafe {
let _ = NtResumeProcess(app.game_handle);
}
}
+32
View File
@@ -0,0 +1,32 @@
use std::time::Instant;
use sysinfo::System;
const ENHANCED: &str = "GTA5_Enhanced.exe";
const LEGACY: &str = "GTA5.exe";
pub struct ForceClose {
pub button_text: String,
pub prompting: bool,
pub interval: Instant,
}
impl Default for ForceClose {
fn default() -> Self {
Self {
button_text: "Force close game".to_string(),
prompting: false,
interval: Instant::now(),
}
}
}
pub fn activate(sysinfo: &mut System) {
sysinfo.refresh_all();
sysinfo
.processes()
.iter()
.filter(|(_, p)| p.name() == ENHANCED || p.name() == LEGACY)
.for_each(|(_, p)| {
p.kill();
});
}
+55
View File
@@ -0,0 +1,55 @@
use std::{fmt::Display, path::PathBuf, process::Command};
use winreg::{RegKey, enums::HKEY_LOCAL_MACHINE};
#[derive(Default, Debug, PartialEq, Eq)]
pub enum Platform {
#[default]
Steam,
Rockstar,
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(Default)]
pub struct Launch {
pub selected: Platform,
}
pub fn launch(platform: &Platform) {
match platform {
Platform::Steam => {
let _ = open::that_detached("steam://run/3240220");
}
Platform::Rockstar => {
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let Ok(gta_v_enhanced) =
hklm.open_subkey(r"SOFTWARE\WOW6432Node\Rockstar Games\GTA V Enhanced")
else {
return;
};
let Ok(install_folder): Result<String, std::io::Error> =
gta_v_enhanced.get_value("InstallFolder")
else {
return;
};
let mut play_gtav_path = PathBuf::from(install_folder);
play_gtav_path.push("PlayGTAV.exe");
let _ = Command::new(play_gtav_path).spawn();
}
Platform::Epic => {
let _ = open::that_detached(
"com.epicgames.launcher://apps/331226ba7c944720baa99103cb1fe80c?action=launch&silent=true",
);
}
}
}
+4
View File
@@ -0,0 +1,4 @@
pub mod anti_afk;
pub mod empty_session;
pub mod force_close;
pub mod launch;