1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
use crateGameMode;
use crateHit;
use crateState;
use crateError;
use ;
/// Generates standardized memory reading functions.
///
/// This macro creates functions that read specific data types from process memory
/// using a base address and offset common usage for base types to not do getbaseaddr everytime.
///
/// # Syntax
///
/// ```rust
/// generate_reader_fn! {
/// function_name, return_type, read_method
/// }
/// ```
///
/// # Arguments
///
/// * `function_name` - Name of the generated function most likely read_<type>
/// * `return_type` - Rust type to return (e.g., `i32`, `String`, `f64`)
/// * `read_method` - Method name on Process trait (e.g., `read_i32`, `read_string`) most of the time from rosu_mem
///
/// # Examples
///
/// ```rust
/// generate_reader_fn! {
/// read_score, i32, read_i32
/// }
///
/// ```
/// Generates offset-based getter functions for memory access.
///
/// This macro creates functions that read data from specific memory offsets
/// using a base address getter function.
///
/// # Syntax
///
/// ```rust
/// generate_offset_getter! {
/// function_name: return_type = read_method(offset, base_getter);
/// another_function: another_type = another_read_method(another_offset, another_base);
/// }
/// ```
///
/// # Arguments
///
/// Each getter definition consists of:
/// * `function_name` - Name of the generated function
/// * `return_type` - Rust type to return
/// * `read_method` - Memory reading method to use
/// * `offset` - Memory offset from base address
/// * `base_getter` - Function that returns the base address (most of the time from generate_reader_fn)
///
/// # Examples
///
/// ```rust
/// generate_offset_getter! {
/// score: i32 = read_i32(0x10, score_base),
/// combo: i16 = read_i16(0x14, score_base),
/// username: String = read_string(0x20, score_base),
/// hp: f64 = read_f64(0x30, hp_base),
/// }
///
/// // Generates functions like:
/// // pub fn score(p: &Process, state: &mut State) -> Result<i32, Error> {
/// // Ok(<i32>::from(read_i32(p, state, 0x10, score_base)?))
/// // }
/// ```
///
/// # Generated Functions
///
/// Each definition generates a function with signature:
/// ```rust
/// pub fn function_name(p: &Process, state: &mut State) -> Result<return_type, Error>
/// ```
///
/// # Memory Safety
///
/// The generated functions assume the offsets are valid and the base address
/// getter returns a valid memory address.
)*
};
}
/// Generates OSU memory accessor methods with automatic client dispatching.
///
/// This macro eliminates boilerplate code by automatically generating
/// client-specific accessor methods that handle different OSU client types
/// (Stable, Lazer) with consistent error handling.
///
/// # Syntax
///
/// ```rust
/// impl_osu_accessor! {
/// fn method_name() -> return_type => implementation_path,
/// fn another_method() -> another_type => another_implementation,
/// }
/// ```
///
/// # Arguments
///
/// * `method_name` - Name of the generated method (e.g., `game_state`, `score`)
/// * `return_type` - Rust type to return (e.g., `GameState`, `i32`, `String`)
/// * `implementation_path` - Path to the actual implementation (e.g., `stable::memory::game_state`)
///
/// # Examples
///
/// ```rust
/// impl<'a> CommonReader<'a> {
/// impl_osu_accessor! {
/// fn game_state() -> GameState => stable::memory::game_state,
/// fn menu_game_mode() -> GameMode => stable::memory::menu_game_mode,
/// fn path_folder() -> PathBuf => stable::memory::path_folder,
/// }
/// }
/// ```
///
/// # Generated Methods
///
/// For each definition, generates a method like:
/// ```rust
/// pub fn method_name(&mut self) -> Result<return_type, Error> {
/// match self.osu_type {
/// OsuClientKind::Stable => implementation_path(self.process, self.state),
/// _ => Err(Error::Unsupported("Unsupported osu type for now".to_string())),
/// }
/// }
/// ```
///
/// # Benefits
///
/// * **Reduces code duplication** - ~1000+ lines eliminated across the project
/// * **Consistent API** - All accessors follow the same pattern
/// * **Type safety** - Compile-time guarantees for return types
/// * **Future-proof** - Easy to add new client types
/// * **Maintainable** - Changes only need to be made in one place
///
/// # Errors
///
/// Generated methods return `Error::Unsupported` for client types that don't
/// have implementations yet (currently only Stable is supported).
///
/// # Performance
///
/// No runtime overhead - all dispatching is done at compile time.
}
)*
};
}
// TODO : idk where to put this
// Macro usage
generate_reader_fn!;
generate_reader_fn!;
generate_reader_fn!;
generate_reader_fn!;
generate_reader_fn!;
generate_reader_fn!;
generate_reader_fn!;
generate_reader_fn!;