pub mod beatmap;
pub mod common;
pub mod gameplay;
pub mod helpers;
pub mod overlay;
pub mod resultscreen;
pub mod user;
use crate::reader::common::stable::memory::game_state;
use crate::reader::common::GameState;
use crate::reader::structs::State;
use crate::reader::structs::StaticAddresses;
use crate::Error;
use rosu_mem::process::{Process, ProcessTraits};
use std::time::Duration;
pub mod structs;
static EXCLUDE_WORDS: [&str; 2] = ["umu-run", "waitforexitandrun"];
#[allow(dead_code)]
pub fn waiting_for_gamestate<F>(
p: &Process,
state: &mut State,
g_state: GameState,
callback: Option<F>,
) -> Result<(), Error>
where
F: Fn(&Process, &mut State) -> Result<(), Error>,
{
loop {
if game_state(p, state)? == g_state {
return Ok(());
}
if let Some(f) = &callback {
f(p, state)?;
}
}
}
#[allow(dead_code)]
pub fn init_loop(sleep_duration: u64) -> Result<(State, Process), Error> {
let mut state = State {
addresses: StaticAddresses::default(),
};
loop {
match Process::initialize("osu!.exe", &EXCLUDE_WORDS) {
Ok(p) => {
println!("Found process, pid - {}", p.pid);
println!("Reading static signatures...");
match StaticAddresses::new(&p) {
Ok(v) => {
state.addresses = v;
println!("Static addresses read successfully");
return Ok((state, p));
}
Err(e) => {
match e {
Error::MemoryRead(msg) => {
if msg.contains("Process not found") {
println!("Process not found, sleeping for {sleep_duration}ms");
std::thread::sleep(Duration::from_millis(sleep_duration));
continue;
}
#[cfg(target_os = "windows")]
if msg.contains("OS error") {
println!("OS error, sleeping for {sleep_duration}ms");
std::thread::sleep(Duration::from_millis(sleep_duration));
continue;
}
println!("Unknown error, sleeping for {sleep_duration}ms");
std::thread::sleep(Duration::from_millis(sleep_duration));
}
_ => {
println!("Unknown error, sleeping for {sleep_duration}ms");
std::thread::sleep(Duration::from_millis(sleep_duration));
}
}
println!("Unknown error, sleeping for {sleep_duration}ms");
std::thread::sleep(Duration::from_millis(sleep_duration));
}
}
}
Err(_) => {
println!("Unknown process error, sleeping for {sleep_duration}ms");
std::thread::sleep(Duration::from_millis(sleep_duration));
}
}
}
}