Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/beatmap2.rs
Original file line number Diff line number Diff line change
@@ -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:?}"),
Expand Down
13 changes: 7 additions & 6 deletions examples/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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(),
}
}

Expand All @@ -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<bool, Error> {
if new_path != self.current_beatmap_path {
println!("Loading new beatmap: {new_path}");
fn update_beatmap<P: AsRef<Path>>(&mut self, new_path: P) -> Result<bool, Error> {
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)?;
Expand All @@ -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 {
Expand Down
72 changes: 43 additions & 29 deletions src/reader/beatmap/mod.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
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;

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<Self, Error> {
pub fn new(
p: &'a Process,
state: &'a mut State,
osu_type: OsuClientKind,
) -> Result<Self, Error> {
Ok(Self {
process: p,
state,
Expand All @@ -28,25 +34,25 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_info(&mut self) -> Result<BeatmapInfo, Error> {
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<String, Error> {
pub fn get_beatmap_path(&mut self) -> Result<PathBuf, Error> {
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<String, Error> {
pub fn get_audio_path(&mut self) -> Result<PathBuf, Error> {
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(),
)),
Expand All @@ -55,7 +61,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_md5(&mut self) -> Result<String, Error> {
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(),
)),
Expand All @@ -64,7 +70,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_id(&mut self) -> Result<i32, Error> {
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(),
)),
Expand All @@ -73,7 +79,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_set_id(&mut self) -> Result<i32, Error> {
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(),
)),
Expand All @@ -82,7 +88,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_mode(&mut self) -> Result<GameMode, Error> {
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(),
)),
Expand All @@ -91,7 +97,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_tags(&mut self) -> Result<String, Error> {
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(),
)),
Expand All @@ -100,7 +106,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_length(&mut self) -> Result<i32, Error> {
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(),
)),
Expand All @@ -109,7 +115,9 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_drain_time(&mut self) -> Result<i32, Error> {
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(),
)),
Expand All @@ -118,7 +126,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_status(&mut self) -> Result<BeatmapStatus, Error> {
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(),
)),
Expand All @@ -127,7 +135,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_author(&mut self) -> Result<String, Error> {
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(),
)),
Expand All @@ -136,7 +144,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_creator(&mut self) -> Result<String, Error> {
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(),
)),
Expand All @@ -145,7 +153,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_title_romanized(&mut self) -> Result<String, Error> {
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(),
)),
Expand All @@ -154,7 +162,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_title_original(&mut self) -> Result<String, Error> {
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(),
)),
Expand All @@ -163,7 +171,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_difficulty(&mut self) -> Result<String, Error> {
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(),
)),
Expand All @@ -172,7 +180,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_od(&mut self) -> Result<f32, Error> {
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(),
)),
Expand All @@ -181,7 +189,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_ar(&mut self) -> Result<f32, Error> {
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(),
)),
Expand All @@ -190,7 +198,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_cs(&mut self) -> Result<f32, Error> {
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(),
)),
Expand All @@ -199,7 +207,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_hp(&mut self) -> Result<f32, Error> {
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(),
)),
Expand All @@ -208,7 +216,9 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_object_count(&mut self) -> Result<u32, Error> {
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(),
)),
Expand All @@ -217,7 +227,9 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_slider_count(&mut self) -> Result<i32, Error> {
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(),
)),
Expand All @@ -226,7 +238,9 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_star_rating(&mut self) -> Result<BeatmapStarRating, Error> {
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(),
)),
Expand All @@ -235,7 +249,7 @@ impl<'a> BeatmapReader<'a> {

pub fn get_beatmap_stats(&mut self) -> Result<BeatmapStats, Error> {
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(),
)),
Expand Down
Loading
Loading