From 52cc066b095471f8b7ab3c8bcf78d8d0141e5c89 Mon Sep 17 00:00:00 2001 From: 486c Date: Sat, 12 Jul 2025 19:54:15 +0300 Subject: [PATCH] fix: get rid of unwrap's 1. Get rid of unwrap's 2. Minor naming changes 3. Minor style changes --- examples/beatmap2.rs | 4 +- examples/pp.rs | 13 ++--- src/reader/beatmap/mod.rs | 72 +++++++++++++++++----------- src/reader/beatmap/stable/file.rs | 35 +++++++++----- src/reader/common/mod.rs | 22 +++++---- src/reader/common/stable/memory.rs | 25 ++++++---- src/reader/gameplay/mod.rs | 38 +++++++-------- src/reader/gameplay/stable/memory.rs | 8 ++-- src/reader/resultscreen/mod.rs | 34 ++++++------- src/reader/user/mod.rs | 34 +++++++------ 10 files changed, 166 insertions(+), 119 deletions(-) diff --git a/examples/beatmap2.rs b/examples/beatmap2.rs index 194f5c7..c1e2b7a 100644 --- a/examples/beatmap2.rs +++ b/examples/beatmap2.rs @@ -1,11 +1,11 @@ use rosu_memory_lib::init_loop; use rosu_memory_lib::reader::beatmap::BeatmapReader; -use rosu_memory_lib::reader::common::OsuType; +use rosu_memory_lib::reader::common::OsuClientKind; use rosu_memory_lib::Error; fn main() -> Result<(), Error> { let (mut state, process) = init_loop(500)?; - let mut beatmap_reader = BeatmapReader::new(&process, &mut state, OsuType::Stable)?; + let mut beatmap_reader = BeatmapReader::new(&process, &mut state, OsuClientKind::Stable)?; loop { match beatmap_reader.get_beatmap_info() { Ok(beatmap_info) => println!("Current beatmap info: {beatmap_info:?}"), diff --git a/examples/pp.rs b/examples/pp.rs index 76b3d5e..f0e21e4 100644 --- a/examples/pp.rs +++ b/examples/pp.rs @@ -7,6 +7,7 @@ use rosu_memory_lib::Error; use rosu_mods::GameModsLegacy; use rosu_pp::Beatmap; use rosu_pp::{Difficulty, Performance}; +use std::path::{Path, PathBuf}; use std::time::Duration; /// This example demonstrates how to calculate PP (Performance Points) in real-time @@ -27,7 +28,7 @@ struct CalculatorState { current_pp: f64, current_mods: i32, current_beatmap: Beatmap, - current_beatmap_path: String, + current_beatmap_path: PathBuf, } impl CalculatorState { @@ -37,7 +38,7 @@ impl CalculatorState { current_pp: 0.0, current_mods: 0, current_beatmap: Beatmap::default(), - current_beatmap_path: String::new(), + current_beatmap_path: PathBuf::new(), } } @@ -56,9 +57,9 @@ impl CalculatorState { } /// Attempts to load a new beatmap if the path has changed - fn update_beatmap(&mut self, new_path: String) -> Result { - if new_path != self.current_beatmap_path { - println!("Loading new beatmap: {new_path}"); + fn update_beatmap>(&mut self, new_path: P) -> Result { + if new_path.as_ref() != self.current_beatmap_path { + println!("Loading new beatmap: {}", new_path.as_ref().display()); // Load and validate the new beatmap let beatmap = Beatmap::from_path(&new_path)?; @@ -69,7 +70,7 @@ impl CalculatorState { // Update cached beatmap self.current_beatmap = beatmap; - self.current_beatmap_path = new_path; + self.current_beatmap_path = new_path.as_ref().to_path_buf(); println!("Beatmap loaded successfully!"); Ok(true) } else { diff --git a/src/reader/beatmap/mod.rs b/src/reader/beatmap/mod.rs index 84961de..44898d7 100644 --- a/src/reader/beatmap/mod.rs +++ b/src/reader/beatmap/mod.rs @@ -1,12 +1,14 @@ pub mod common; pub mod stable; +use std::path::PathBuf; + use crate::reader::beatmap::common::BeatmapInfo; use crate::reader::beatmap::common::BeatmapStarRating; use crate::reader::beatmap::common::BeatmapStats; use crate::reader::beatmap::common::BeatmapStatus; use crate::reader::common::GameMode; -use crate::reader::common::OsuType; +use crate::reader::common::OsuClientKind; use crate::reader::structs::State; use crate::Error; use rosu_mem::process::Process; @@ -14,11 +16,15 @@ use rosu_mem::process::Process; pub struct BeatmapReader<'a> { pub process: &'a Process, pub state: &'a mut State, - pub osu_type: OsuType, + pub osu_type: OsuClientKind, } impl<'a> BeatmapReader<'a> { - pub fn new(p: &'a Process, state: &'a mut State, osu_type: OsuType) -> Result { + pub fn new( + p: &'a Process, + state: &'a mut State, + osu_type: OsuClientKind, + ) -> Result { Ok(Self { process: p, state, @@ -28,25 +34,25 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_info(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_info(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_beatmap_info(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), } } - pub fn get_beatmap_path(&mut self) -> Result { + pub fn get_beatmap_path(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::file::get_beatmap_path(self.process, self.state), + OsuClientKind::Stable => stable::file::get_beatmap_path(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), } } - pub fn get_audio_path(&mut self) -> Result { + pub fn get_audio_path(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::file::get_audio_path(self.process, self.state), + OsuClientKind::Stable => stable::file::get_audio_path(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -55,7 +61,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_md5(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_md5(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_beatmap_md5(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -64,7 +70,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_id(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_id(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_beatmap_id(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -73,7 +79,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_set_id(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_set_id(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_beatmap_set_id(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -82,7 +88,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_mode(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_mode(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_beatmap_mode(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -91,7 +97,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_tags(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_tags(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_beatmap_tags(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -100,7 +106,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_length(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_length(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_beatmap_length(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -109,7 +115,9 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_drain_time(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_drain_time(self.process, self.state), + OsuClientKind::Stable => { + stable::memory::get_beatmap_drain_time(self.process, self.state) + } _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -118,7 +126,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_status(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_status(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_beatmap_status(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -127,7 +135,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_author(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_author(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_author(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -136,7 +144,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_creator(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_creator(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_creator(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -145,7 +153,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_title_romanized(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_title_romanized(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_title_romanized(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -154,7 +162,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_title_original(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_title_original(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_title_original(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -163,7 +171,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_difficulty(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_difficulty(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_difficulty(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -172,7 +180,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_od(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_od(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_beatmap_od(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -181,7 +189,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_ar(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_ar(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_beatmap_ar(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -190,7 +198,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_cs(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_cs(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_beatmap_cs(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -199,7 +207,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_hp(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_hp(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_beatmap_hp(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -208,7 +216,9 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_object_count(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_object_count(self.process, self.state), + OsuClientKind::Stable => { + stable::memory::get_beatmap_object_count(self.process, self.state) + } _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -217,7 +227,9 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_slider_count(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_slider_count(self.process, self.state), + OsuClientKind::Stable => { + stable::memory::get_beatmap_slider_count(self.process, self.state) + } _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -226,7 +238,9 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_star_rating(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::file::get_beatmap_star_rating(self.process, self.state), + OsuClientKind::Stable => { + stable::file::get_beatmap_star_rating(self.process, self.state) + } _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -235,7 +249,7 @@ impl<'a> BeatmapReader<'a> { pub fn get_beatmap_stats(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_beatmap_stats(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_beatmap_stats(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), diff --git a/src/reader/beatmap/stable/file.rs b/src/reader/beatmap/stable/file.rs index 2feeb7d..f67b44b 100644 --- a/src/reader/beatmap/stable/file.rs +++ b/src/reader/beatmap/stable/file.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use crate::common::GameMode; use crate::reader::beatmap::common::{ BeatmapInfo, BeatmapLocation, BeatmapMetadata, BeatmapStarRating, BeatmapStats, BeatmapStatus, @@ -12,18 +14,20 @@ use rosu_map::section::hit_objects::HitObjectKind; use rosu_map::Beatmap as RmBeatmap; use rosu_mem::process::{Process, ProcessTraits}; -pub fn get_beatmap_path(p: &Process, state: &mut State) -> Result { +pub fn get_beatmap_path(p: &Process, state: &mut State) -> Result { let folder = get_folder(p, state)?; let filename = get_filename(p, state)?; - let song_path = get_path_folder(p, state)?; - Ok(format!("{song_path}/{folder}/{filename}")) + let songs_path = get_path_folder(p, state)?; + + Ok(songs_path.join(folder).join(filename)) } -pub fn get_audio_path(p: &Process, state: &mut State) -> Result { +pub fn get_audio_path(p: &Process, state: &mut State) -> Result { let folder = get_folder(p, state)?; let audio = get_audio(p, state)?; - let song_path = get_path_folder(p, state)?; - Ok(format!("{song_path}/{folder}/{audio}")) + let songs_path = get_path_folder(p, state)?; + + Ok(songs_path.join(folder).join(audio)) } pub fn get_beatmap_md5(p: &Process, state: &mut State) -> Result { @@ -63,8 +67,17 @@ pub fn get_beatmap_length(p: &Process, state: &mut State) -> Result pub fn get_beatmap_drain_time(p: &Process, state: &mut State) -> Result { let path = get_beatmap_path(p, state)?; let b = RmBeatmap::from_path(path)?; + + if b.hit_objects.is_empty() { + return Ok(0); + } + + // SAFETY: Checked bounds above + // TODO: That's misleading because last note can be LN or slider + // which have duration beyond start_time let drain_time = b.hit_objects.last().unwrap().start_time - b.hit_objects.first().unwrap().start_time; + Ok(drain_time as i32) } @@ -145,8 +158,8 @@ pub fn get_beatmap_slider_count(p: &Process, state: &mut State) -> Result Result { let folder = get_folder(p, state)?; let filename = get_filename(p, state)?; - let song_path = get_path_folder(p, state)?; - let path = format!("{song_path}/{folder}/{filename}"); + let songs_path = get_path_folder(p, state)?; + let path = songs_path.join(folder).join(filename); let b = rosu_pp::Beatmap::from_path(path)?; let diff_attrs = rosu_pp::Difficulty::new().calculate(&b); let diff_dt = rosu_pp::Difficulty::new().mods(64).calculate(&b); @@ -165,8 +178,7 @@ pub fn get_beatmap_stats(p: &Process, state: &mut State) -> Result Result for GameMode { fn from(value: u32) -> Self { match value { @@ -36,6 +39,7 @@ impl From for GameMode { Self::from(value as u32) } } + impl GameMode { #[allow(clippy::inherent_to_string)] pub fn to_string(&self) -> String { @@ -104,11 +108,11 @@ impl From for GameState { pub struct CommonReader<'a> { pub process: &'a Process, pub state: &'a mut State, - pub osu_type: OsuType, + pub osu_type: OsuClientKind, } impl<'a> CommonReader<'a> { - pub fn new(p: &'a Process, state: &'a mut State, osu_type: OsuType) -> Self { + pub fn new(p: &'a Process, state: &'a mut State, osu_type: OsuClientKind) -> Self { Self { process: p, state, @@ -118,7 +122,7 @@ impl<'a> CommonReader<'a> { pub fn get_game_state(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_game_state(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_game_state(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -127,16 +131,16 @@ impl<'a> CommonReader<'a> { pub fn get_menu_mods(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_menu_mods(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_menu_mods(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), } } - pub fn get_path_folder(&mut self) -> Result { + pub fn get_path_folder(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_path_folder(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_path_folder(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -145,7 +149,9 @@ impl<'a> CommonReader<'a> { pub fn check_game_state(&mut self, g_state: GameState) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::check_game_state(self.process, self.state, g_state), + OsuClientKind::Stable => { + stable::memory::check_game_state(self.process, self.state, g_state) + } _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), diff --git a/src/reader/common/stable/memory.rs b/src/reader/common/stable/memory.rs index f70e179..021d077 100644 --- a/src/reader/common/stable/memory.rs +++ b/src/reader/common/stable/memory.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use crate::reader::common::stable::offset::COMMON_OFFSET; use crate::reader::common::GameState; use crate::reader::structs::State; @@ -13,19 +15,26 @@ pub fn check_game_state(p: &Process, state: &mut State, g_state: GameState) -> R Ok(get_game_state(p, state)? == g_state) } -pub(crate) fn get_path_folder(p: &Process, state: &mut State) -> Result { +/// Returns a path to the `Songs` folder +/// +/// **Platform-specific** +/// - Windows: Will return full absolute path to the `Songs` folder +/// - Linux: Might return relative path, carefully check by yourself +pub(crate) fn get_path_folder(p: &Process, state: &mut State) -> Result { let settings_ptr = p.read_i32(state.addresses.settings + COMMON_OFFSET.settings_ptr)?; let settings_addr = p.read_i32(settings_ptr + COMMON_OFFSET.settings_addr)?; let path = p.read_string(settings_addr + COMMON_OFFSET.path)?; - // default (relative path) + + // Attempt to construct a absolute path from executable path if path == "Songs" { - return Ok(format!( - "{}/Songs", - p.executable_dir.clone().unwrap().display() - )); + if let Some(executable_dir) = &p.executable_dir { + let path = executable_dir.clone().join("Songs"); + + return Ok(path); + } } - // custom user path (absolute path) - Ok(path) + + Ok(PathBuf::from(path)) } pub fn get_menu_mods(p: &Process, state: &mut State) -> Result { diff --git a/src/reader/gameplay/mod.rs b/src/reader/gameplay/mod.rs index 2ca51af..391ef0c 100644 --- a/src/reader/gameplay/mod.rs +++ b/src/reader/gameplay/mod.rs @@ -1,7 +1,7 @@ pub mod common; pub mod stable; -use crate::reader::common::OsuType; +use crate::reader::common::OsuClientKind; use crate::reader::gameplay::common::GameplayInfo; use crate::reader::structs::Hit; use crate::reader::structs::State; @@ -10,11 +10,11 @@ use rosu_mem::process::Process; pub struct GameplayReader<'a> { pub process: &'a Process, pub state: &'a mut State, - pub osu_type: OsuType, + pub osu_type: OsuClientKind, } impl<'a> GameplayReader<'a> { - pub fn new(p: &'a Process, state: &'a mut State, osu_type: OsuType) -> Self { + pub fn new(p: &'a Process, state: &'a mut State, osu_type: OsuClientKind) -> Self { Self { process: p, state, @@ -24,7 +24,7 @@ impl<'a> GameplayReader<'a> { pub fn get_score_gameplay(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_score_gameplay(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_score_gameplay(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -33,7 +33,7 @@ impl<'a> GameplayReader<'a> { pub fn get_mods(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_mods(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_mods(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -42,7 +42,7 @@ impl<'a> GameplayReader<'a> { pub fn get_combo(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_combo(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_combo(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -51,7 +51,7 @@ impl<'a> GameplayReader<'a> { pub fn get_max_combo(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_max_combo(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_max_combo(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -60,7 +60,7 @@ impl<'a> GameplayReader<'a> { pub fn get_current_hp(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_current_hp(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_current_hp(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -69,7 +69,7 @@ impl<'a> GameplayReader<'a> { pub fn get_username(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_username(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_username(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -78,7 +78,7 @@ impl<'a> GameplayReader<'a> { pub fn get_ig_time(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_ig_time(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_ig_time(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -87,7 +87,7 @@ impl<'a> GameplayReader<'a> { pub fn get_retries(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_retries(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_retries(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -96,7 +96,7 @@ impl<'a> GameplayReader<'a> { pub fn get_hits_300(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_hits_300(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_hits_300(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -105,7 +105,7 @@ impl<'a> GameplayReader<'a> { pub fn get_hits_100(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_hits_100(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_hits_100(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -114,7 +114,7 @@ impl<'a> GameplayReader<'a> { pub fn get_hits_50(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_hits_50(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_hits_50(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -123,7 +123,7 @@ impl<'a> GameplayReader<'a> { pub fn get_hits_miss(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_hits_miss(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_hits_miss(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -132,7 +132,7 @@ impl<'a> GameplayReader<'a> { pub fn get_hits_geki(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_hits_geki(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_hits_geki(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -141,7 +141,7 @@ impl<'a> GameplayReader<'a> { pub fn get_hits_katu(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_hits_katu(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_hits_katu(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -150,7 +150,7 @@ impl<'a> GameplayReader<'a> { pub fn get_hits(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_hits(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_hits(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -159,7 +159,7 @@ impl<'a> GameplayReader<'a> { pub fn get_gameplay_info(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_gameplay_info(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_gameplay_info(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), diff --git a/src/reader/gameplay/stable/memory.rs b/src/reader/gameplay/stable/memory.rs index e59a44c..e9acbab 100644 --- a/src/reader/gameplay/stable/memory.rs +++ b/src/reader/gameplay/stable/memory.rs @@ -143,12 +143,12 @@ pub fn get_gameplay_info(p: &Process, state: &mut State) -> Result { pub process: &'a Process, pub state: &'a mut State, - pub osu_type: OsuType, + pub osu_type: OsuClientKind, } impl<'a> ResultScreenReader<'a> { - pub fn new(p: &'a Process, state: &'a mut State, osu_type: OsuType) -> Self { + pub fn new(p: &'a Process, state: &'a mut State, osu_type: OsuClientKind) -> Self { Self { process: p, state, @@ -25,7 +25,9 @@ impl<'a> ResultScreenReader<'a> { pub fn get_result_screen_info(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_result_screen_info(self.process, self.state), + OsuClientKind::Stable => { + stable::memory::get_result_screen_info(self.process, self.state) + } _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -34,7 +36,7 @@ impl<'a> ResultScreenReader<'a> { pub fn get_result_username(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_result_username(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_result_username(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -43,7 +45,7 @@ impl<'a> ResultScreenReader<'a> { pub fn get_result_score(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_result_score(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_result_score(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -52,7 +54,7 @@ impl<'a> ResultScreenReader<'a> { pub fn get_result_mode(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_result_mode(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_result_mode(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -61,7 +63,7 @@ impl<'a> ResultScreenReader<'a> { pub fn get_result_hit_300(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_result_hit_300(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_result_hit_300(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -70,7 +72,7 @@ impl<'a> ResultScreenReader<'a> { pub fn get_result_hit_100(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_result_hit_100(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_result_hit_100(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -79,7 +81,7 @@ impl<'a> ResultScreenReader<'a> { pub fn get_result_hit_50(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_result_hit_50(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_result_hit_50(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -88,7 +90,7 @@ impl<'a> ResultScreenReader<'a> { pub fn get_result_hit_miss(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_result_hit_miss(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_result_hit_miss(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -97,7 +99,7 @@ impl<'a> ResultScreenReader<'a> { pub fn get_result_hit_geki(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_result_hit_geki(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_result_hit_geki(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -106,7 +108,7 @@ impl<'a> ResultScreenReader<'a> { pub fn get_result_hit_katu(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_result_hit_katu(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_result_hit_katu(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -115,7 +117,7 @@ impl<'a> ResultScreenReader<'a> { pub fn get_result_hits(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_result_hits(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_result_hits(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -124,7 +126,7 @@ impl<'a> ResultScreenReader<'a> { pub fn get_result_accuracy(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_result_accuracy(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_result_accuracy(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -133,7 +135,7 @@ impl<'a> ResultScreenReader<'a> { pub fn get_result_max_combo(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_result_max_combo(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_result_max_combo(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), diff --git a/src/reader/user/mod.rs b/src/reader/user/mod.rs index 5e7aa78..01d00e6 100644 --- a/src/reader/user/mod.rs +++ b/src/reader/user/mod.rs @@ -1,6 +1,6 @@ pub mod common; pub mod stable; -use crate::reader::common::OsuType; +use crate::reader::common::OsuClientKind; use crate::reader::structs::State; use crate::reader::user::common::UserInfo; use crate::Error; @@ -9,11 +9,11 @@ use rosu_mem::process::Process; pub struct UserReader<'a> { pub process: &'a Process, pub state: &'a mut State, - pub osu_type: OsuType, + pub osu_type: OsuClientKind, } impl<'a> UserReader<'a> { - pub fn new(p: &'a Process, state: &'a mut State, osu_type: OsuType) -> Self { + pub fn new(p: &'a Process, state: &'a mut State, osu_type: OsuClientKind) -> Self { Self { process: p, state, @@ -23,7 +23,7 @@ impl<'a> UserReader<'a> { pub fn get_user_info(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_user_info(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_user_info(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -32,7 +32,7 @@ impl<'a> UserReader<'a> { pub fn get_user_id(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_user_id(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_user_id(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -41,7 +41,9 @@ impl<'a> UserReader<'a> { pub fn get_user_bancho_status(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_user_bancho_status(self.process, self.state), + OsuClientKind::Stable => { + stable::memory::get_user_bancho_status(self.process, self.state) + } _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -50,7 +52,9 @@ impl<'a> UserReader<'a> { pub fn get_user_country_code(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_user_country_code(self.process, self.state), + OsuClientKind::Stable => { + stable::memory::get_user_country_code(self.process, self.state) + } _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -59,7 +63,7 @@ impl<'a> UserReader<'a> { pub fn get_user_username(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_user_username(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_user_username(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -68,7 +72,7 @@ impl<'a> UserReader<'a> { pub fn get_user_pp(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_user_pp(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_user_pp(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -77,7 +81,7 @@ impl<'a> UserReader<'a> { pub fn get_user_rankedscore(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_user_rankedscore(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_user_rankedscore(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -86,7 +90,7 @@ impl<'a> UserReader<'a> { pub fn get_user_level(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_user_level(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_user_level(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -95,7 +99,7 @@ impl<'a> UserReader<'a> { pub fn get_user_playcount(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_user_playcount(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_user_playcount(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -104,7 +108,7 @@ impl<'a> UserReader<'a> { pub fn get_user_rank(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_user_rank(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_user_rank(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -113,7 +117,7 @@ impl<'a> UserReader<'a> { pub fn get_user_playmode(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_user_playmode(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_user_playmode(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )), @@ -122,7 +126,7 @@ impl<'a> UserReader<'a> { pub fn get_user_accuracy(&mut self) -> Result { match self.osu_type { - OsuType::Stable => stable::memory::get_user_accuracy(self.process, self.state), + OsuClientKind::Stable => stable::memory::get_user_accuracy(self.process, self.state), _ => Err(Error::Unsupported( "Unsupported osu type for now".to_string(), )),