From 787bc0e664ebdd4efb0707a8132dc3f134fb4834 Mon Sep 17 00:00:00 2001 From: Zefanja Jobse Date: Sat, 7 May 2022 17:35:04 +0200 Subject: [PATCH] same anti-afk without unminimizing but for bf1 --- src/main.rs | 49 +++++++++++-------------------------------------- 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3295f69..69fbfdb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,12 +3,11 @@ use std::iter::once; use std::os::windows::prelude::OsStrExt; use std::ptr; use std::{ - mem, thread::sleep, time::Duration, }; use winapi::shared::windef::HWND__; -use winapi::um::winuser::{FindWindowW, INPUT, INPUT_KEYBOARD, KEYEVENTF_SCANCODE, KEYEVENTF_KEYUP, SendInput, SetForegroundWindow, ShowWindow}; +use winapi::um::winuser::{FindWindowW, SetForegroundWindow, SendMessageW, GetForegroundWindow}; struct GameInfo { is_running: bool, @@ -20,19 +19,21 @@ fn main() { let game_info = is_running(); if game_info.is_running { unsafe { - // if game is not running - SetForegroundWindow(game_info.game_process); - ShowWindow(game_info.game_process, 9); - sleep(Duration::from_millis(1808)); - key_enter(0x12); - sleep(Duration::from_millis(100)); - ShowWindow(game_info.game_process, 6); + let current_forground_window = GetForegroundWindow(); + let l_param = make_l_param(20, 20); + SendMessageW(game_info.game_process, 0x201, 0, l_param as isize); + SendMessageW(game_info.game_process, 0x202, 0, l_param as isize); + SetForegroundWindow(current_forground_window); } } sleep(Duration::from_secs(120)); }; } +fn make_l_param(lo_word: i32, hi_word: i32) -> i32 { + return (hi_word << 16) | (lo_word & 0xffff); +} + fn is_running() -> GameInfo { unsafe { let window: Vec = OsStr::new("Battlefield™ 1") @@ -43,32 +44,4 @@ fn is_running() -> GameInfo { let no_game: *mut HWND__ = ptr::null_mut(); GameInfo{ is_running: window_handle != no_game, game_process: window_handle } } -} - -unsafe fn create_input(key_code: u16, flags: u32) -> INPUT { - let mut input = mem::zeroed::(); - input.type_ = INPUT_KEYBOARD; - let mut ki = input.u.ki_mut(); - ki.wVk = 0; - ki.wScan = key_code; - ki.dwExtraInfo = 0; - ki.dwFlags = flags; - ki.time = 0; - input -} - -unsafe fn key_down(key_code: u16) { - let mut input = create_input(key_code, KEYEVENTF_SCANCODE); - SendInput(1, &mut input, mem::size_of::() as i32); -} - -unsafe fn key_up(key_code: u16) { - let mut input = create_input(key_code, KEYEVENTF_KEYUP); - SendInput(1, &mut input, mem::size_of::() as i32); -} - -unsafe fn key_enter(key_code: u16) { - key_down(key_code); - sleep(Duration::from_millis(154)); - key_up(key_code); -} +} \ No newline at end of file