rosu_memory_lib/reader/
mod.rs

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