rosu_memory_lib/reader/
mod.rs

1pub mod beatmap;
2pub mod common;
3pub mod gameplay;
4pub mod helpers;
5pub mod resultscreen;
6pub mod user;
7pub mod overlay;
8
9use crate::reader::common::stable::memory::game_state;
10use crate::reader::common::GameState;
11use crate::reader::structs::State;
12use crate::reader::structs::StaticAddresses;
13use crate::Error;
14use rosu_mem::process::{Process, ProcessTraits};
15use std::time::Duration;
16pub mod structs;
17
18static EXCLUDE_WORDS: [&str; 2] = ["umu-run", "waitforexitandrun"];
19
20#[allow(dead_code)]
21// Use this function to make callback and get anything you need such as map info or user info or even submit shit
22pub fn waiting_for_gamestate<F>(
23    p: &Process,
24    state: &mut State,
25    g_state: GameState,
26    callback: Option<F>,
27) -> Result<(), Error>
28where
29    F: Fn(&Process, &mut State) -> Result<(), Error>,
30{
31    loop {
32        if game_state(p, state)? == g_state {
33            return Ok(());
34        }
35        if let Some(f) = &callback {
36            f(p, state)?;
37        }
38    }
39}
40
41#[allow(dead_code)]
42pub fn init_loop(sleep_duration: u64) -> Result<(State, Process), Error> {
43    let mut state = State {
44        addresses: StaticAddresses::default(),
45    };
46
47    loop {
48        match Process::initialize("osu!.exe", &EXCLUDE_WORDS) {
49            Ok(p) => {
50                println!("Found process, pid - {}", p.pid);
51
52                println!("Reading static signatures...");
53                match StaticAddresses::new(&p) {
54                    Ok(v) => {
55                        state.addresses = v;
56                        println!("Static addresses read successfully");
57                        return Ok((state, p));
58                    }
59                    Err(e) => {
60                        match e {
61                            Error::MemoryRead(msg) => {
62                                if msg.contains("Process not found") {
63                                    println!("Process not found, sleeping for {sleep_duration}ms");
64                                    std::thread::sleep(Duration::from_millis(sleep_duration));
65                                    continue;
66                                }
67                                #[cfg(target_os = "windows")]
68                                if msg.contains("OS error") {
69                                    println!("OS error, sleeping for {sleep_duration}ms");
70                                    std::thread::sleep(Duration::from_millis(sleep_duration));
71                                    continue;
72                                }
73                                println!("Unknown error, sleeping for {sleep_duration}ms");
74                                std::thread::sleep(Duration::from_millis(sleep_duration));
75                            }
76                            _ => {
77                                println!("Unknown error, sleeping for {sleep_duration}ms");
78                                std::thread::sleep(Duration::from_millis(sleep_duration));
79                            }
80                        }
81                        println!("Unknown error, sleeping for {sleep_duration}ms");
82                        std::thread::sleep(Duration::from_millis(sleep_duration));
83                    }
84                }
85            }
86            Err(_) => {
87                println!("Unknown process error, sleeping for {sleep_duration}ms");
88                std::thread::sleep(Duration::from_millis(sleep_duration));
89            }
90        }
91    }
92}
93
94// Exemple of playing loop
95// pub(crate) fn playing(p: &Process, state: &mut State) -> bool {
96//     let mode_list = get_mods(p, state);
97//     while (GameState::from(get_status(p, state)) == GameState::Playing) {
98//         cur_time = reader_gameplay::get_ig_time(p, state);
99//         if (cur_time - last_time < 20 && cur_time > 0 && last_time > 0 && last_paused != cur_time) {
100//             last_paused = cur_time;
101//         }
102//         last_time = cur_time;
103//         let status = get_status(p, state);
104//         let md5 = get_beatmap_md5(p, state);
105//         if (last_retries < get_retries(p, state)) {
106//             return false;
107//         }
108//     }
109//     true
110// }