rosu_memory_lib/reader/beatmap/
common.rs

1use serde::{Deserialize, Serialize};
2
3use crate::common::GameMode;
4
5
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct BeatmapInfo {
9    pub metadata: BeatmapMetadata,
10    pub location: BeatmapLocation,
11    pub stats: BeatmapStats,
12    pub technical: BeatmapTechnicalInfo,
13}
14
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct BeatmapMetadata{
18    pub author: String,
19    pub creator: String,
20    pub title_romanized: String,
21    pub title_original: String,
22    pub difficulty: String,
23    pub tags: String,
24}
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct BeatmapTechnicalInfo{
27    pub md5: String,
28    pub id: i32,
29    pub set_id: i32,
30    pub mode: GameMode,
31    pub ranked_status: BeatmapStatus,
32}
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct BeatmapLocation {
35    pub folder: String,
36    pub filename: String,
37    pub audio: String,
38    pub cover: String,
39}
40
41impl BeatmapLocation {
42    pub fn get_file_path(&self) -> String {
43        format!("{}/{}", self.folder, self.filename)
44    }
45    pub fn get_audio_path(&self) -> String {
46        format!("{}/{}", self.folder, self.audio)
47    }
48    pub fn get_cover_path(&self) -> String {
49        format!("{}/{}", self.folder, self.cover)
50    }
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct BeatmapStarRating{
55    pub no_mod: f64,
56    pub dt: f64,
57    pub ht: f64,
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct BeatmapStats{
62    pub ar: f32,
63    pub od: f32,
64    pub cs: f32,
65    pub hp: f32,
66    pub total_length: i32,
67    pub star_rating: BeatmapStarRating,
68    pub object_count: i32,
69    pub slider_count: i32,
70}
71
72
73
74
75#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Serialize, Deserialize)]
76#[repr(i16)]
77pub enum BeatmapStatus {
78    #[default]
79    Unknown = 0,
80    Unsubmitted = 1,
81    Unranked = 2,
82    Unused = 3,
83    Ranked = 4,
84    Approved = 5,
85    Qualified = 6,
86    Loved = 7,
87}
88
89impl BeatmapStatus {
90    #[allow(clippy::inherent_to_string)]
91    pub fn to_string(&self) -> String {
92        match self {
93            BeatmapStatus::Unknown => "unknown".to_string(),
94            BeatmapStatus::Unsubmitted => "unsubmitted".to_string(),
95            BeatmapStatus::Unranked => "unranked".to_string(),
96            BeatmapStatus::Unused => "unused".to_string(),
97            BeatmapStatus::Ranked => "ranked".to_string(),
98            BeatmapStatus::Approved => "approved".to_string(),
99            BeatmapStatus::Qualified => "qualified".to_string(),
100            BeatmapStatus::Loved => "loved".to_string(),
101        }
102    }
103}
104
105
106
107
108impl From<i16> for BeatmapStatus {
109    fn from(value: i16) -> Self {
110        match value {
111            1 => Self::Unsubmitted,
112            2 => Self::Unranked,
113            3 => Self::Unused,
114            4 => Self::Ranked,
115            5 => Self::Approved,
116            6 => Self::Qualified,
117            7 => Self::Loved,
118            _ => Self::Unknown,
119        }
120    }
121}
122
123impl From<i32> for BeatmapStatus {
124    fn from(value: i32) -> Self {
125        Self::from(value as i16)
126    }
127}
128
129
130
131pub(crate) struct BeatmapOffset {
132    pub ptr: i32,
133    pub metadata: BeatmapMetadataOffset,
134    pub location: BeatmapLocationOffset,
135    pub stats: BeatmapStatsOffset,
136    pub technical: BeatmapTechnicalOffset,
137}
138
139pub struct BeatmapStatsOffset{
140    pub ar: i32,
141    pub od: i32,
142    pub cs: i32,
143    pub hp: i32,
144    pub object_count: i32,
145    pub total_length: i32,
146    pub drain_time: i32,
147    pub star_rating: i32,
148    pub slider_count: i32,
149}
150
151pub struct BeatmapLocationOffset{
152    pub folder: i32,
153    pub filename: i32,
154    pub audio: i32,
155    pub cover: i32,
156}
157
158pub struct BeatmapTechnicalOffset{
159    pub md5: i32,
160    pub id: i32,
161    pub set_id: i32,
162    pub mode: i32,
163    pub ranked_status: i32,
164}
165
166pub struct BeatmapMetadataOffset{
167    pub author: i32,
168    pub creator: i32,
169    pub title_romanized: i32,
170    pub title_original: i32,
171    pub difficulty: i32,
172    pub tags: i32,
173}