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