rosu_memory_lib/reader/
mod.rs1pub mod beatmap;
2pub mod common;
3pub mod gameplay;
4pub mod helpers;
5pub mod overlay;
6pub mod resultscreen;
7pub mod user;
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)]
21pub 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