Skip to content

Commit

Permalink
same anti-afk without unminimizing but for bf1
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed May 7, 2022
1 parent d3c1db4 commit 787bc0e
Showing 1 changed file with 11 additions and 38 deletions.
49 changes: 11 additions & 38 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<u16> = OsStr::new("Battlefield™ 1")
Expand All @@ -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>();
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::<INPUT>() 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::<INPUT>() as i32);
}

unsafe fn key_enter(key_code: u16) {
key_down(key_code);
sleep(Duration::from_millis(154));
key_up(key_code);
}
}

0 comments on commit 787bc0e

Please sign in to comment.