rosu_memory_lib/reader/
mod.rs1pub mod beatmap;
2pub mod common;
3pub mod gameplay;
4pub mod resultscreen;
5pub mod user;
6
7use crate::reader::common::stable::memory::get_game_state;
8use crate::reader::common::GameState;
9use crate::reader::structs::State;
10use crate::reader::structs::StaticAddresses;
11use crate::Error;
12use rosu_mem::process::{Process, ProcessTraits};
13use std::time::Duration;
14pub mod structs;
15
16static EXCLUDE_WORDS: [&str; 2] = ["umu-run", "waitforexitandrun"];
17
18#[allow(dead_code)]
19pub fn waiting_for_gamestate<F>(
21 p: &Process,
22 state: &mut State,
23 g_state: GameState,
24 callback: Option<F>,
25) -> Result<(), Error>
26where
27 F: Fn(&Process, &mut State) -> Result<(), Error>,
28{
29 loop {
30 if get_game_state(p, state)? == g_state {
31 return Ok(());
32 }
33 if let Some(f) = &callback {
34 f(p, state)?;
35 }
36 }
37}
38
39#[allow(dead_code)]
40pub fn init_loop(sleep_duration: u64) -> Result<(State, Process), Error> {
41 let mut state = State {
42 addresses: StaticAddresses::default(),
43 };
44
45 loop {
46 match Process::initialize("osu!.exe", &EXCLUDE_WORDS) {
47 Ok(p) => {
48 println!("Found process, pid - {}", p.pid);
49
50 println!("Reading static signatures...");
51 match StaticAddresses::new(&p) {
52 Ok(v) => {
53 state.addresses = v;
54 println!("Static addresses read successfully");
55 return Ok((state, p));
56 }
57 Err(e) => {
58 match e {
59 Error::MemoryRead(msg) => {
60 if msg.contains("Process not found") {
61 println!("Process not found, sleeping for {sleep_duration}ms");
62 std::thread::sleep(Duration::from_millis(sleep_duration));
63 continue;
64 }
65 #[cfg(target_os = "windows")]
66 if msg.contains("OS error") {
67 println!("OS error, sleeping for {sleep_duration}ms");
68 std::thread::sleep(Duration::from_millis(sleep_duration));
69 continue;
70 }
71 println!("Unknown error, sleeping for {sleep_duration}ms");
72 std::thread::sleep(Duration::from_millis(sleep_duration));
73 }
74 _ => {
75 println!("Unknown error, sleeping for {sleep_duration}ms");
76 std::thread::sleep(Duration::from_millis(sleep_duration));
77 }
78 }
79 println!("Unknown error, sleeping for {sleep_duration}ms");
80 std::thread::sleep(Duration::from_millis(sleep_duration));
81 }
82 }
83 }
84 Err(_) => {
85 println!("Unknown process error, sleeping for {sleep_duration}ms");
86 std::thread::sleep(Duration::from_millis(sleep_duration));
87 }
88 }
89 }
90}
91
92