rosu_memory_lib/reader/
mod.rs

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