Skip to content

Commit

Permalink
add keypress mode as requested by squatch_
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed Aug 13, 2023
1 parent d3c3a31 commit b33eea3
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 206 deletions.
9 changes: 9 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Config file

# It will send messages based on timeout when set to true
send_messages = false
# minize the game after it has send the message or keypress mode
minimize_after_action = true
# Message it will send
messages = [
'test1',
Expand All @@ -27,4 +29,11 @@ message_start_time_utc = '12:00'
message_stop_time_utc = '23:00'
# Timeout used when sending messages
message_timeout_mins = 8

# Press a key for anti-afk instead (will requires the game to go unminimized)
keypress_mode = false
# which key to press (keypress_mode)
key = ' '
# how many millisecond to hold the key down (keypress_mode)
key_hold_time = 80
```
11 changes: 7 additions & 4 deletions config.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
minimize_after_message = false
send_messages = true
messages = ['t']
send_messages = false
minimize_after_action = true
messages = ['Join our discord, we are always recruiting: discord.gg/BoB']
chat_type = 'Public'
message_start_time_utc = '12:00'
message_stop_time_utc = '23:00'
message_timeout_mins = 0
message_timeout_mins = 8
keypress_mode = false
key = ' '
key_hold_time = 80
29 changes: 24 additions & 5 deletions src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,33 @@ fn make_l_param(lo_word: i32, hi_word: i32) -> i32 {
(hi_word << 16) | (lo_word & 0xffff)
}

pub fn anti_afk(game_name: &str, mut run_once_no_game: bool) -> bool {
pub fn anti_afk(cfg: &structs::SeederConfig, game_name: &str, mut run_once_no_game: bool) -> bool {
let game_info = is_running(game_name);
if game_info.is_running {
unsafe {
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);

if cfg.keypress_mode {
ShowWindow(game_info.game_process, 9);
SetForegroundWindow(game_info.game_process);
sleep(Duration::from_millis(1808));

if cfg.key == "tab" {
send_keys::key_enter(0x0F, cfg.key_hold_time);
} else {
send_keys::send_key(&cfg.key, cfg.key_hold_time);
}
sleep(Duration::from_secs(1));

if cfg.minimize_after_action {
ShowWindow(game_info.game_process, 6);
}
} else {
// use mousebutton
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);
// reset no game check
run_once_no_game = true;
Expand Down Expand Up @@ -188,7 +207,7 @@ pub fn send_message(
structs::ChatType::Squad => message_action(current_message, squad_key),
}

if cfg.minimize_after_message {
if cfg.minimize_after_action {
ShowWindow(game_info.game_process, 6);
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/bf1.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod shared_main;
mod chars;
mod send_keys;
mod actions;
mod structs;

fn main() {
shared_main::anti_afk_runner("Battlefield™ 1");
}
mod actions;
mod chars;
mod send_keys;
mod shared_main;
mod structs;

fn main() {
shared_main::anti_afk_runner("Battlefield™ 1");
}
18 changes: 9 additions & 9 deletions src/bf2042.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod shared_main;
mod chars;
mod send_keys;
mod actions;
mod structs;

fn main() {
shared_main::anti_afk_runner("Battlefield™ 2042");
}
mod actions;
mod chars;
mod send_keys;
mod shared_main;
mod structs;

fn main() {
shared_main::anti_afk_runner("Battlefield™ 2042");
}
18 changes: 9 additions & 9 deletions src/bf4.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod shared_main;
mod chars;
mod send_keys;
mod actions;
mod structs;

fn main() {
shared_main::anti_afk_runner("Battlefield 4");
}
mod actions;
mod chars;
mod send_keys;
mod shared_main;
mod structs;

fn main() {
shared_main::anti_afk_runner("Battlefield 4");
}
16 changes: 8 additions & 8 deletions src/bfv.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod shared_main;
mod chars;
mod send_keys;
mod actions;
mod structs;

fn main() {
shared_main::anti_afk_runner("Battlefield™ V");
mod shared_main;
mod chars;
mod send_keys;
mod actions;
mod structs;

fn main() {
shared_main::anti_afk_runner("Battlefield™ V");
}
175 changes: 85 additions & 90 deletions src/chars.rs
Original file line number Diff line number Diff line change
@@ -1,90 +1,85 @@
const CHAR_MAPPING: [u16; 47] = [
0x33, //,
0x0C, //-
0x34, //.
0x35, //\/
0x0B, //0
0x02, //1
0x03, //2
0x04, //3
0x05, //4
0x06, //5
0x07, //6
0x08, //7
0x09, //8
0x0A, //9
0x0,
0x27, //;
0x0,
0x0D, //=
0x0,
0x0,
0x0,
0x1E, //A
0x30, //B
0x2E, //C
0x20, //D
0x12, //E
0x21, //F
0x22, //G
0x23, //H
0x17, //I
0x24, //J
0x25, //K
0x26, //L
0x32, //M
0x31, //N
0x18, //O
0x19, //P
0x10, //Q
0x13, //R
0x1F, //S
0x14, //T
0x16, //U
0x2F, //V
0x11, //W
0x2D, //X
0x15, //Y
0x2C, //Z
];

#[derive(Debug)]
pub enum DXCode {
Symbol(u16),
Shifted(u16)
}

/**
Convert ASCII char into DirectX key code
*/
pub fn char_to_dxcodes(c: char) -> Option<DXCode> {
let mut c_u8 = c as u8;

if c.is_ascii_lowercase() {
c_u8 &= 0xdf;
}

if c.is_ascii_whitespace() {
return Some(DXCode::Symbol(0x39));
}

if c == ":".chars().next().unwrap() {
return Some(DXCode::Shifted(0x27));
}

if c_u8 < 0x5B && c_u8 > 0x2B {
let index = c_u8 - 0x2C;
let code = CHAR_MAPPING[index as usize];
// println!("{} {}", index, code);
if code == 0x0 {
None
} else if c.is_ascii_uppercase() {
// Press SHIFT
Some(DXCode::Shifted(code))
} else {
Some(DXCode::Symbol(code))
}
} else {
None
}
}
const CHAR_MAPPING: [u16; 47] = [
0x33, //,
0x0C, //-
0x34, //.
0x35, //\/
0x0B, //0
0x02, //1
0x03, //2
0x04, //3
0x05, //4
0x06, //5
0x07, //6
0x08, //7
0x09, //8
0x0A, //9
0x0, 0x27, //;
0x0, 0x0D, //=
0x0, 0x0, 0x0, 0x1E, //A
0x30, //B
0x2E, //C
0x20, //D
0x12, //E
0x21, //F
0x22, //G
0x23, //H
0x17, //I
0x24, //J
0x25, //K
0x26, //L
0x32, //M
0x31, //N
0x18, //O
0x19, //P
0x10, //Q
0x13, //R
0x1F, //S
0x14, //T
0x16, //U
0x2F, //V
0x11, //W
0x2D, //X
0x15, //Y
0x2C, //Z
];

#[derive(Debug)]
pub enum DXCode {
Symbol(u16),
Shifted(u16),
}

/**
Convert ASCII char into DirectX key code
*/
pub fn char_to_dxcodes(c: char) -> Option<DXCode> {
let mut c_u8 = c as u8;

if c.is_ascii_lowercase() {
c_u8 &= 0xdf;
}

if c.is_ascii_whitespace() {
return Some(DXCode::Symbol(0x39));
}

if c == ":".chars().next().unwrap() {
return Some(DXCode::Shifted(0x27));
}

if c_u8 < 0x5B && c_u8 > 0x2B {
let index = c_u8 - 0x2C;
let code = CHAR_MAPPING[index as usize];
// println!("{} {}", index, code);
if code == 0x0 {
None
} else if c.is_ascii_uppercase() {
// Press SHIFT
Some(DXCode::Shifted(code))
} else {
Some(DXCode::Symbol(code))
}
} else {
None
}
}
Loading

0 comments on commit b33eea3

Please sign in to comment.