Skip to content

Commit b33eea3

Browse files
committed
add keypress mode as requested by squatch_
1 parent d3c3a31 commit b33eea3

File tree

12 files changed

+256
-206
lines changed

12 files changed

+256
-206
lines changed

Readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Config file
1212

1313
# It will send messages based on timeout when set to true
1414
send_messages = false
15+
# minize the game after it has send the message or keypress mode
16+
minimize_after_action = true
1517
# Message it will send
1618
messages = [
1719
'test1',
@@ -27,4 +29,11 @@ message_start_time_utc = '12:00'
2729
message_stop_time_utc = '23:00'
2830
# Timeout used when sending messages
2931
message_timeout_mins = 8
32+
33+
# Press a key for anti-afk instead (will requires the game to go unminimized)
34+
keypress_mode = false
35+
# which key to press (keypress_mode)
36+
key = ' '
37+
# how many millisecond to hold the key down (keypress_mode)
38+
key_hold_time = 80
3039
```

config.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
minimize_after_message = false
2-
send_messages = true
3-
messages = ['t']
1+
send_messages = false
2+
minimize_after_action = true
3+
messages = ['Join our discord, we are always recruiting: discord.gg/BoB']
44
chat_type = 'Public'
55
message_start_time_utc = '12:00'
66
message_stop_time_utc = '23:00'
7-
message_timeout_mins = 0
7+
message_timeout_mins = 8
8+
keypress_mode = false
9+
key = ' '
10+
key_hold_time = 80

src/actions.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,33 @@ fn make_l_param(lo_word: i32, hi_word: i32) -> i32 {
2020
(hi_word << 16) | (lo_word & 0xffff)
2121
}
2222

23-
pub fn anti_afk(game_name: &str, mut run_once_no_game: bool) -> bool {
23+
pub fn anti_afk(cfg: &structs::SeederConfig, game_name: &str, mut run_once_no_game: bool) -> bool {
2424
let game_info = is_running(game_name);
2525
if game_info.is_running {
2626
unsafe {
2727
let current_forground_window = GetForegroundWindow();
28-
let l_param = make_l_param(20, 20);
29-
SendMessageW(game_info.game_process, 0x201, 0, l_param as isize);
30-
SendMessageW(game_info.game_process, 0x202, 0, l_param as isize);
28+
29+
if cfg.keypress_mode {
30+
ShowWindow(game_info.game_process, 9);
31+
SetForegroundWindow(game_info.game_process);
32+
sleep(Duration::from_millis(1808));
33+
34+
if cfg.key == "tab" {
35+
send_keys::key_enter(0x0F, cfg.key_hold_time);
36+
} else {
37+
send_keys::send_key(&cfg.key, cfg.key_hold_time);
38+
}
39+
sleep(Duration::from_secs(1));
40+
41+
if cfg.minimize_after_action {
42+
ShowWindow(game_info.game_process, 6);
43+
}
44+
} else {
45+
// use mousebutton
46+
let l_param = make_l_param(20, 20);
47+
SendMessageW(game_info.game_process, 0x201, 0, l_param as isize);
48+
SendMessageW(game_info.game_process, 0x202, 0, l_param as isize);
49+
}
3150
SetForegroundWindow(current_forground_window);
3251
// reset no game check
3352
run_once_no_game = true;
@@ -188,7 +207,7 @@ pub fn send_message(
188207
structs::ChatType::Squad => message_action(current_message, squad_key),
189208
}
190209

191-
if cfg.minimize_after_message {
210+
if cfg.minimize_after_action {
192211
ShowWindow(game_info.game_process, 6);
193212
}
194213
}

src/bf1.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
mod shared_main;
2-
mod chars;
3-
mod send_keys;
4-
mod actions;
5-
mod structs;
6-
7-
fn main() {
8-
shared_main::anti_afk_runner("Battlefield™ 1");
9-
}
1+
mod actions;
2+
mod chars;
3+
mod send_keys;
4+
mod shared_main;
5+
mod structs;
6+
7+
fn main() {
8+
shared_main::anti_afk_runner("Battlefield™ 1");
9+
}

src/bf2042.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
mod shared_main;
2-
mod chars;
3-
mod send_keys;
4-
mod actions;
5-
mod structs;
6-
7-
fn main() {
8-
shared_main::anti_afk_runner("Battlefield™ 2042");
9-
}
1+
mod actions;
2+
mod chars;
3+
mod send_keys;
4+
mod shared_main;
5+
mod structs;
6+
7+
fn main() {
8+
shared_main::anti_afk_runner("Battlefield™ 2042");
9+
}

src/bf4.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
mod shared_main;
2-
mod chars;
3-
mod send_keys;
4-
mod actions;
5-
mod structs;
6-
7-
fn main() {
8-
shared_main::anti_afk_runner("Battlefield 4");
9-
}
1+
mod actions;
2+
mod chars;
3+
mod send_keys;
4+
mod shared_main;
5+
mod structs;
6+
7+
fn main() {
8+
shared_main::anti_afk_runner("Battlefield 4");
9+
}

src/bfv.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
mod shared_main;
2-
mod chars;
3-
mod send_keys;
4-
mod actions;
5-
mod structs;
6-
7-
fn main() {
8-
shared_main::anti_afk_runner("Battlefield™ V");
1+
mod shared_main;
2+
mod chars;
3+
mod send_keys;
4+
mod actions;
5+
mod structs;
6+
7+
fn main() {
8+
shared_main::anti_afk_runner("Battlefield™ V");
99
}

src/chars.rs

Lines changed: 85 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,85 @@
1-
const CHAR_MAPPING: [u16; 47] = [
2-
0x33, //,
3-
0x0C, //-
4-
0x34, //.
5-
0x35, //\/
6-
0x0B, //0
7-
0x02, //1
8-
0x03, //2
9-
0x04, //3
10-
0x05, //4
11-
0x06, //5
12-
0x07, //6
13-
0x08, //7
14-
0x09, //8
15-
0x0A, //9
16-
0x0,
17-
0x27, //;
18-
0x0,
19-
0x0D, //=
20-
0x0,
21-
0x0,
22-
0x0,
23-
0x1E, //A
24-
0x30, //B
25-
0x2E, //C
26-
0x20, //D
27-
0x12, //E
28-
0x21, //F
29-
0x22, //G
30-
0x23, //H
31-
0x17, //I
32-
0x24, //J
33-
0x25, //K
34-
0x26, //L
35-
0x32, //M
36-
0x31, //N
37-
0x18, //O
38-
0x19, //P
39-
0x10, //Q
40-
0x13, //R
41-
0x1F, //S
42-
0x14, //T
43-
0x16, //U
44-
0x2F, //V
45-
0x11, //W
46-
0x2D, //X
47-
0x15, //Y
48-
0x2C, //Z
49-
];
50-
51-
#[derive(Debug)]
52-
pub enum DXCode {
53-
Symbol(u16),
54-
Shifted(u16)
55-
}
56-
57-
/**
58-
Convert ASCII char into DirectX key code
59-
*/
60-
pub fn char_to_dxcodes(c: char) -> Option<DXCode> {
61-
let mut c_u8 = c as u8;
62-
63-
if c.is_ascii_lowercase() {
64-
c_u8 &= 0xdf;
65-
}
66-
67-
if c.is_ascii_whitespace() {
68-
return Some(DXCode::Symbol(0x39));
69-
}
70-
71-
if c == ":".chars().next().unwrap() {
72-
return Some(DXCode::Shifted(0x27));
73-
}
74-
75-
if c_u8 < 0x5B && c_u8 > 0x2B {
76-
let index = c_u8 - 0x2C;
77-
let code = CHAR_MAPPING[index as usize];
78-
// println!("{} {}", index, code);
79-
if code == 0x0 {
80-
None
81-
} else if c.is_ascii_uppercase() {
82-
// Press SHIFT
83-
Some(DXCode::Shifted(code))
84-
} else {
85-
Some(DXCode::Symbol(code))
86-
}
87-
} else {
88-
None
89-
}
90-
}
1+
const CHAR_MAPPING: [u16; 47] = [
2+
0x33, //,
3+
0x0C, //-
4+
0x34, //.
5+
0x35, //\/
6+
0x0B, //0
7+
0x02, //1
8+
0x03, //2
9+
0x04, //3
10+
0x05, //4
11+
0x06, //5
12+
0x07, //6
13+
0x08, //7
14+
0x09, //8
15+
0x0A, //9
16+
0x0, 0x27, //;
17+
0x0, 0x0D, //=
18+
0x0, 0x0, 0x0, 0x1E, //A
19+
0x30, //B
20+
0x2E, //C
21+
0x20, //D
22+
0x12, //E
23+
0x21, //F
24+
0x22, //G
25+
0x23, //H
26+
0x17, //I
27+
0x24, //J
28+
0x25, //K
29+
0x26, //L
30+
0x32, //M
31+
0x31, //N
32+
0x18, //O
33+
0x19, //P
34+
0x10, //Q
35+
0x13, //R
36+
0x1F, //S
37+
0x14, //T
38+
0x16, //U
39+
0x2F, //V
40+
0x11, //W
41+
0x2D, //X
42+
0x15, //Y
43+
0x2C, //Z
44+
];
45+
46+
#[derive(Debug)]
47+
pub enum DXCode {
48+
Symbol(u16),
49+
Shifted(u16),
50+
}
51+
52+
/**
53+
Convert ASCII char into DirectX key code
54+
*/
55+
pub fn char_to_dxcodes(c: char) -> Option<DXCode> {
56+
let mut c_u8 = c as u8;
57+
58+
if c.is_ascii_lowercase() {
59+
c_u8 &= 0xdf;
60+
}
61+
62+
if c.is_ascii_whitespace() {
63+
return Some(DXCode::Symbol(0x39));
64+
}
65+
66+
if c == ":".chars().next().unwrap() {
67+
return Some(DXCode::Shifted(0x27));
68+
}
69+
70+
if c_u8 < 0x5B && c_u8 > 0x2B {
71+
let index = c_u8 - 0x2C;
72+
let code = CHAR_MAPPING[index as usize];
73+
// println!("{} {}", index, code);
74+
if code == 0x0 {
75+
None
76+
} else if c.is_ascii_uppercase() {
77+
// Press SHIFT
78+
Some(DXCode::Shifted(code))
79+
} else {
80+
Some(DXCode::Symbol(code))
81+
}
82+
} else {
83+
None
84+
}
85+
}

0 commit comments

Comments
 (0)