Skip to content

Commit

Permalink
add a anti-cheat start waittimer, so it only restarts the process aft…
Browse files Browse the repository at this point in the history
…er a failed launch
  • Loading branch information
zefanjajobse committed Oct 30, 2024
1 parent 5ff7f0a commit ce12690
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 26 deletions.
11 changes: 7 additions & 4 deletions src/actions/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,18 @@ pub fn send_message(to_send: String, cfg: &structs::SeederConfig) {

pub fn is_running(cfg: &structs::SeederConfig) -> structs::GameInfo {
unsafe {
let window: Vec<u16> = OsStr::new(cfg.game.window_name())
let game_window: Vec<u16> = OsStr::new(cfg.game.window_name())
.encode_wide()
.chain(once(0))
.collect();
let window_handle = FindWindowW(std::ptr::null_mut(), window.as_ptr());
let game_window_handle = FindWindowW(std::ptr::null_mut(), game_window.as_ptr());
let anticheat_process = winproc::Process::from_name("EAAntiCheat.GameServiceLauncher.exe");

let no_game: *mut HWND__ = ptr::null_mut();
structs::GameInfo {
is_running: window_handle != no_game,
game_process: window_handle,
is_running: game_window_handle != no_game,
game_process: game_window_handle,
anticheat_launcher_running: anticheat_process.is_ok(),
}
}
}
Expand Down
55 changes: 35 additions & 20 deletions src/actions/launchers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::structs;
use crate::structs::{self, Games};
use directories::BaseDirs;
use ini::Ini;
use regex::Regex;
Expand Down Expand Up @@ -44,6 +44,32 @@ pub fn find_link2ea() -> String {
}
}

pub fn start_wait_timer(cfg: &structs::SeederConfig) {
let mut timeout = 0;
let mut anticheat_running = false;
let mut running = false;
while !running {
if timeout > 10 {
// give up on to many tries waiting and continue anyway
log::warn!("waiting to long, continueing..");
break;
}

log::debug!("Testing if the game started");

let start_info = super::game::is_running(cfg);
running = start_info.is_running;
if cfg.game == Games::Bf1 && start_info.anticheat_launcher_running && !anticheat_running {
log::info!("Anticheat is running");
timeout = 0;
anticheat_running = true;
}
sleep(Duration::from_secs(5));
timeout += 1;
}
log::info!("Game started");
}

pub fn launch_game_ea_desktop(cfg: &structs::SeederConfig, game_id: &str, role: &str) {
// it needs to restart launcher
stop_ea_desktop();
Expand Down Expand Up @@ -78,19 +104,7 @@ pub fn launch_game_ea_desktop(cfg: &structs::SeederConfig, game_id: &str, role:
Err(e) => log::error!("failed to launch game: {}", e),
}

let mut timeout = 0;
let mut not_running = true;
while not_running {
if timeout > 10 {
// give up on to many tries waiting and continue anyway
log::warn!("waiting to long, continueing..");
break;
}

not_running = !super::game::is_running(cfg).is_running;
sleep(Duration::from_secs(5));
timeout += 1;
}
start_wait_timer(cfg);

// reset config after gamelaunch
edit_ea_desktop(cfg, "".to_string());
Expand Down Expand Up @@ -180,6 +194,7 @@ pub fn launch_game_origin(cfg: &structs::SeederConfig, game_id: &str, role: &str
Ok(_) => log::info!("game launched"),
Err(e) => log::error!("failed to launch game: {}", e),
}
start_wait_timer(cfg);
}

pub fn launch_game_steam(cfg: &structs::SeederConfig, game_id: &str, role: &str) {
Expand Down Expand Up @@ -271,21 +286,21 @@ pub fn launch_game_steam(cfg: &structs::SeederConfig, game_id: &str, role: &str)
Ok(_) => log::info!("game launched"),
Err(e) => log::error!("failed to launch game: {}", e),
}
// bit slower than origin version
sleep(Duration::from_secs(10));
start_wait_timer(cfg);
}

pub fn is_launcher_running(cfg: &structs::SeederConfig) -> structs::GameInfo {
unsafe {
let window: Vec<u16> = OsStr::new(cfg.launcher.window_name())
let launcher_window: Vec<u16> = OsStr::new(cfg.launcher.window_name())
.encode_wide()
.chain(once(0))
.collect();
let window_handle = FindWindowW(std::ptr::null_mut(), window.as_ptr());
let launcher_window_handle = FindWindowW(std::ptr::null_mut(), launcher_window.as_ptr());
let no_game: *mut HWND__ = ptr::null_mut();
structs::GameInfo {
is_running: window_handle != no_game,
game_process: window_handle,
is_running: launcher_window_handle != no_game,
game_process: launcher_window_handle,
anticheat_launcher_running: false,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/steam_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ fn main() {
log::info!("{}", cfg.link2ea_location);
log::info!("{}", cfg.game_location);

actions::launchers::launch_game_steam(&cfg, "9654542690814", "soldier");
actions::launchers::launch_game_steam(&cfg, "9660974470904", "soldier");
}
3 changes: 2 additions & 1 deletion src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub struct Error {
pub struct GameInfo {
pub is_running: bool,
pub game_process: *mut HWND__,
pub anticheat_launcher_running: bool,
}

/// `SeederConfig` implements `Default`
Expand Down Expand Up @@ -132,7 +133,7 @@ impl Launchers {
}
}

#[derive(Serialize, Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone, PartialEq)]
pub enum Games {
Bf4,
Bf1,
Expand Down

0 comments on commit ce12690

Please sign in to comment.