rosu_memory_lib/reader/common/
mod.rs1pub mod stable;
2use serde::{Deserialize, Serialize};
3use crate::reader::structs::{State};
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, Serialize, Deserialize)]
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
77
78impl From<u32> for GameState {
79 fn from(value: u32) -> Self {
80 match value {
81 0 => Self::MainMenu,
82 1 => Self::Editor,
83 2 => Self::Playing,
84 3 => Self::Exit, 4 => Self::EditorSongSelect,
86 5 => Self::SongSelect,
87 6 => Self::SelectDrawing, 7 => Self::ResultScreen,
89 8 => Self::Update, 9 => Self::Busy, 10 => Self::Unknown, 11 => Self::MultiplayerLobbySelect,
93 12 => Self::MultiplayerLobby,
94 13 => Self::MultiplayerSongSelect,
95 14 => Self::MultiplayerResultScreen,
96 16 => Self::OffsetWizard,
97 17 => Self::MultiplayerResultScreenTagCoop,
98 18 => Self::MultiplayerResultScreenTeamVs,
99 19 => Self::SongImport,
100 _ => Self::Unknown,
101 }
102 }
103}
104
105
106#[derive(Debug, Clone)]
107pub enum Error {
108 NotAvailable(String),
109}
110
111impl std::fmt::Display for Error {
112 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
113 match self {
114 Error::NotAvailable(msg) => write!(f, "{msg}"),
115 }
116 }
117}
118
119
120pub struct CommonReader<'a> { pub process : &'a Process, pub state : &'a mut State, pub osu_type : OsuType}
121
122impl<'a> CommonReader<'a> {
123 pub fn new(p: &'a Process, state: &'a mut State, osu_type: OsuType) -> Self {
124 Self { process: p, state, osu_type }
125 }
126
127 pub fn get_game_state(&mut self) -> eyre::Result<GameState> {
128 match self.osu_type {
129 OsuType::Stable => stable::memory::get_game_state(self.process, self.state),
130 _ => Err(eyre::eyre!("Unsupported osu type for now")),
131 }
132 }
133
134 pub fn get_menu_mods(&mut self) -> eyre::Result<i32> {
135 match self.osu_type {
136 OsuType::Stable => stable::memory::get_menu_mods(self.process, self.state),
137 _ => Err(eyre::eyre!("Unsupported osu type for now")),
138 }
139 }
140
141 pub fn get_path_folder(&mut self) -> eyre::Result<String> {
142 match self.osu_type {
143 OsuType::Stable => stable::memory::get_path_folder(self.process, self.state),
144 _ => Err(eyre::eyre!("Unsupported osu type for now")),
145 }
146 }
147
148 pub fn check_game_state(&mut self, g_state: GameState) -> eyre::Result<bool> {
149 match self.osu_type {
150 OsuType::Stable => stable::memory::check_game_state(self.process, self.state, g_state),
151 _ => Err(eyre::eyre!("Unsupported osu type for now")),
152 }
153 }
154}
155