Skip to content

Commit

Permalink
add message system
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed Dec 22, 2022
1 parent 8fcbb87 commit 9b3fdfc
Show file tree
Hide file tree
Showing 11 changed files with 500 additions and 53 deletions.
123 changes: 120 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ authors = ["iiTzArcur <[email protected]>"]

[dependencies]
serde = "1.0.130"
serde_derive = "1.0.130"
winapi = { version = "0.3.9", features = ["winuser"] }
log = "0.4"
env_logger = "0.10.0"
chrono = "*"
confy = "0.4.0"


[[bin]]
Expand Down
9 changes: 5 additions & 4 deletions config.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
group_id = '0fda8e4c-5be3-11eb-b1da-cd4ff7dab605'
game_location = 'F:\Program Files (x86)\Origin Games\Battlefield V\bfv.exe'
hostname = 'Jobse-Laptop'
allow_shutdown = false
send_messages = false
message = 'Join our discord, we are always recruiting: discord.gg/BoB'
message_start_time_utc = '12:00'
message_stop_time_utc = '23:00'
message_timeout_mins = 8
141 changes: 141 additions & 0 deletions src/actions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
use std::ffi::OsStr;
use std::iter::once;
use std::os::windows::prelude::OsStrExt;
use std::ptr;
use std::thread::sleep;
use std::time::Duration;
use winapi::shared::windef::HWND__;
use winapi::um::winuser::{FindWindowW, SetForegroundWindow, ShowWindow, SendMessageW, GetForegroundWindow};

use crate::{send_keys, structs};
use crate::chars::{DXCode, char_to_dxcodes};

fn make_l_param(lo_word: i32, hi_word: i32) -> i32 {
return (hi_word << 16) | (lo_word & 0xffff);
}

pub fn anti_afk(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);
SetForegroundWindow(current_forground_window);
// reset no game check
run_once_no_game = true;
}
log::info!("Running anti-idle for {}.", game_name);
} else {
if run_once_no_game {
log::info!("No game found, idleing...");
run_once_no_game = false;
}
}
return run_once_no_game;
}

fn message_action(cfg: &structs::SeederConfig) {
unsafe {
send_keys::key_enter(0x24, 8);
sleep(Duration::from_millis(800));
let mut message: Vec<DXCode> = Vec::new();
for char in cfg.message.chars() {
match char_to_dxcodes(char) {
Some(dx) => message.push(dx),
None => {},
}
}
send_keys::send_string(message);
sleep(Duration::from_millis(100));
send_keys::key_enter(0x1C, 8);
sleep(Duration::from_millis(100));
}
}

fn bf2042_message_action(cfg: &structs::SeederConfig) {
unsafe {
// println!("Open pause menu");
send_keys::key_enter(0x01, 80); // ESC
sleep(Duration::from_millis(800));
// println!("Most left menu");
send_keys::spam_keys(0x10, 80, 3); // Q
sleep(Duration::from_millis(800));
// println!("Top of list");
send_keys::spam_keys(0xD0, 80, 5); // DOWN
sleep(Duration::from_millis(800));
// println!("from bottom second item");
send_keys::key_enter(0xC8, 80); // UP
sleep(Duration::from_millis(800));
// println!("Click!");
send_keys::key_enter(0x39, 80); // SPACE
sleep(Duration::from_millis(800));
// println!("broadcast menu");
send_keys::key_enter(0x39, 80); // SPACE
sleep(Duration::from_millis(800));

// println!("fill in");
send_keys::spam_keys(0xC8, 8, 2); // UP
sleep(Duration::from_millis(800));
// println!("fill mode");
send_keys::key_enter(0x39, 80); // SPACE
sleep(Duration::from_millis(800));
let mut message: Vec<DXCode> = Vec::new();
for char in cfg.message.chars() {
match char_to_dxcodes(char) {
Some(dx) => message.push(dx),
None => {},
}
}
send_keys::send_string(message);
sleep(Duration::from_millis(800));
// println!("done with message");
send_keys::key_enter(0x1C, 80); // ENTER
sleep(Duration::from_millis(800));
// println!("done button");
send_keys::key_enter(0xD0, 80); // DOWN
sleep(Duration::from_millis(800));
// println!("broadcast!");
send_keys::key_enter(0x39, 80); // SPACE
sleep(Duration::from_millis(800));

// println!("Back to spawn screen");
send_keys::spam_keys(0x01, 8, 2); // ESC
sleep(Duration::from_millis(800));
}
}

// https://gist.github.com/dretax/fe37b8baf55bc30e9d63
pub fn send_message(cfg: &structs::SeederConfig, game_name: &str) {
let game_info = is_running(game_name);
if game_info.is_running {
unsafe {
SetForegroundWindow(game_info.game_process);
ShowWindow(game_info.game_process, 9);
sleep(Duration::from_millis(1808));
if game_name == "" {
bf2042_message_action(cfg);
} else {
message_action(cfg);
}
ShowWindow(game_info.game_process, 6);
}
}
}


pub fn is_running(game_name: &str) -> structs::GameInfo {
unsafe {
let window: Vec<u16> = OsStr::new(game_name)
.encode_wide()
.chain(once(0))
.collect();
let window_handle = FindWindowW(std::ptr::null_mut(), window.as_ptr());
let no_game: *mut HWND__ = ptr::null_mut();
structs::GameInfo {
is_running: window_handle != no_game,
game_process: window_handle,
}
}
}
4 changes: 4 additions & 0 deletions src/bf1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
mod shared_main;
mod chars;
mod send_keys;
mod actions;
mod structs;

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

fn main() {
shared_main::anti_afk_runner("Battlefield™ 1");
shared_main::anti_afk_runner("Battlefield™ 2042");
}
Loading

0 comments on commit 9b3fdfc

Please sign in to comment.