rosu_memory_lib/reader/
mod.rs

1pub 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)]
19// Use this function to make callback and get anything you need such as map info or user info or even submit shit
20pub 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// Exemple of playing loop
93// pub(crate) fn playing(p: &Process, state: &mut State) -> bool {
94//     let mode_list = get_mods(p, state);
95//     while (GameState::from(get_status(p, state)) == GameState::Playing) {
96//         cur_time = reader_gameplay::get_ig_time(p, state);
97//         if (cur_time - last_time < 20 && cur_time > 0 && last_time > 0 && last_paused != cur_time) {
98//             last_paused = cur_time;
99//         }
100//         last_time = cur_time;
101//         let status = get_status(p, state);
102//         let md5 = get_beatmap_md5(p, state);
103//         if (last_retries < get_retries(p, state)) {
104//             return false;
105//         }
106//     }
107//     true
108// }