rosu_memory_lib/reader/common/
mod.rs1pub mod stable;
2use std::path::PathBuf;
3
4use crate::impl_osu_accessor;
5use crate::reader::structs::State;
6use crate::Error;
7use rosu_mem::process::Process;
8
9#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
10pub enum OsuClientKind {
11 #[default]
12 Stable,
13 Lazer,
14}
15
16#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
17pub enum GameMode {
18 Osu,
19 Taiko,
20 Catch,
21 Mania,
22 #[default]
23 Unknown,
24}
25
26impl From<u32> for GameMode {
27 fn from(value: u32) -> Self {
28 match value {
29 0 => Self::Osu,
30 1 => Self::Taiko,
31 2 => Self::Catch,
32 3 => Self::Mania,
33 _ => Self::Unknown,
34 }
35 }
36}
37
38impl From<i32> for GameMode {
39 fn from(value: i32) -> Self {
40 Self::from(value as u32)
41 }
42}
43
44impl GameMode {
45 #[allow(clippy::inherent_to_string)]
46 pub fn to_string(&self) -> String {
47 match self {
48 GameMode::Osu => "std".to_string(),
49 GameMode::Taiko => "taiko".to_string(),
50 GameMode::Catch => "catch".to_string(),
51 GameMode::Mania => "mania".to_string(),
52 GameMode::Unknown => "unknown".to_string(),
53 }
54 }
55}
56
57#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)]
58#[repr(u32)]
59pub enum GameState {
60 MainMenu = 0,
61 Editor = 1,
62 Playing = 2,
63 Exit = 3,
64 EditorSongSelect = 4,
65 SongSelect = 5,
66 SelectDrawing = 6,
67 ResultScreen = 7,
68 Update = 8,
69 Busy = 9,
70 MultiplayerLobbySelect = 11,
71 MultiplayerLobby = 12,
72 MultiplayerSongSelect = 13,
73 MultiplayerResultScreen = 14,
74 OffsetWizard = 16,
75 MultiplayerResultScreenTagCoop = 17,
76 MultiplayerResultScreenTeamVs = 18,
77 SongImport = 19,
78 #[default]
79 Unknown,
80}
81
82impl From<u32> for GameState {
83 fn from(value: u32) -> Self {
84 match value {
85 0 => Self::MainMenu,
86 1 => Self::Editor,
87 2 => Self::Playing,
88 3 => Self::Exit, 4 => Self::EditorSongSelect,
90 5 => Self::SongSelect,
91 6 => Self::SelectDrawing, 7 => Self::ResultScreen,
93 8 => Self::Update, 9 => Self::Busy, 10 => Self::Unknown, 11 => Self::MultiplayerLobbySelect,
97 12 => Self::MultiplayerLobby,
98 13 => Self::MultiplayerSongSelect,
99 14 => Self::MultiplayerResultScreen,
100 16 => Self::OffsetWizard,
101 17 => Self::MultiplayerResultScreenTagCoop,
102 18 => Self::MultiplayerResultScreenTeamVs,
103 19 => Self::SongImport,
104 _ => Self::Unknown,
105 }
106 }
107}
108
109pub struct CommonReader<'a> {
110 pub process: &'a Process,
111 pub state: &'a mut State,
112 pub osu_type: OsuClientKind,
113}
114
115impl<'a> CommonReader<'a> {
116 pub fn new(p: &'a Process, state: &'a mut State, osu_type: OsuClientKind) -> Self {
117 Self {
118 process: p,
119 state,
120 osu_type,
121 }
122 }
123
124 impl_osu_accessor! {
125 fn game_state() -> GameState => stable::memory::game_state,
126 fn menu_game_mode() -> u32 => stable::memory::menu_game_mode,
127 fn path_folder() -> PathBuf => stable::memory::path_folder,
128 }
129
130 pub fn check_game_state(&mut self, g_state: GameState) -> Result<bool, Error> {
131 match self.osu_type {
132 OsuClientKind::Stable => {
133 stable::memory::check_game_state(self.process, self.state, g_state)
134 }
135 _ => Err(Error::Unsupported(
136 "Unsupported osu type for now".to_string(),
137 )),
138 }
139 }
140}