rosu-pp 4.0.1

Difficulty and performance calculation for osu!
Documentation
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
use std::{cmp, f64::consts::PI};

use crate::{
    GameMods,
    osu::{
        OsuDifficultyAttributes, OsuPerformanceAttributes, OsuScoreState,
        difficulty::{
            rating::OsuRatingCalculator,
            skills::{aim::Aim, flashlight::Flashlight, speed::Speed, strain::OsuStrainSkill},
        },
        legacy_score_miss_calc::OsuLegacyScoreMissCalculator,
    },
    util::{
        difficulty::{erf, erf_inv, logistic, reverse_lerp, smoothstep},
        float_ext::FloatExt,
    },
};

// * This is being adjusted to keep the final pp value scaled around what it used to be when changing things.
pub const PERFORMANCE_BASE_MULTIPLIER: f64 = 1.14;

pub(super) struct OsuPerformanceCalculator<'mods> {
    attrs: OsuDifficultyAttributes,
    mods: &'mods GameMods,
    acc: f64,
    state: OsuScoreState,
    using_classic_slider_acc: bool,
}

impl<'a> OsuPerformanceCalculator<'a> {
    pub const fn new(
        attrs: OsuDifficultyAttributes,
        mods: &'a GameMods,
        acc: f64,
        state: OsuScoreState,
        using_classic_slider_acc: bool,
    ) -> Self {
        Self {
            attrs,
            mods,
            acc,
            state,
            using_classic_slider_acc,
        }
    }
}

impl OsuPerformanceCalculator<'_> {
    pub fn calculate(self) -> OsuPerformanceAttributes {
        let total_hits = self.state.hitresults.total_hits();

        if total_hits == 0 {
            return OsuPerformanceAttributes {
                difficulty: self.attrs,
                ..Default::default()
            };
        }

        let acc = self.acc;
        let state = &self.state;
        let attrs = &self.attrs;
        let mods = self.mods;
        let using_classic_slider_acc = self.using_classic_slider_acc;

        let combo_based_estimated_miss_count = self.calculate_combo_based_estimated_miss_count();
        let mut score_based_estimated_miss_count = None;

        let mut effective_miss_count = if using_classic_slider_acc
            && state.legacy_total_score.is_some()
        {
            let legacy_score_miss_calc = OsuLegacyScoreMissCalculator::new(state, acc, mods, attrs);

            *score_based_estimated_miss_count.insert(legacy_score_miss_calc.calculate())
        } else {
            // * Use combo-based miss count if this isn't a legacy score
            combo_based_estimated_miss_count
        };

        effective_miss_count = effective_miss_count.max(f64::from(state.hitresults.misses));
        effective_miss_count = effective_miss_count.min(f64::from(state.hitresults.total_hits()));

        let total_hits = f64::from(total_hits);

        let mut multiplier = PERFORMANCE_BASE_MULTIPLIER;

        if self.mods.nf() {
            multiplier *= (1.0 - 0.02 * effective_miss_count).max(0.9);
        }

        if self.mods.so() && total_hits > 0.0 {
            multiplier *= 1.0 - (f64::from(self.attrs.n_spinners) / total_hits).powf(0.85);
        }

        if self.mods.rx() {
            let od = self.attrs.od();

            // * https://www.desmos.com/calculator/vspzsop6td
            // * we use OD13.3 as maximum since it's the value at which great hitwidow becomes 0
            // * this is well beyond currently maximum achievable OD which is 12.17 (DTx2 + DA with OD11)
            let (n100_mult, n50_mult) = if od > 0.0 {
                (
                    0.75 * (1.0 - od / 13.33).max(0.0),
                    (1.0 - (od / 13.33).powf(5.0)).max(0.0),
                )
            } else {
                (1.0, 1.0)
            };

            // * As we're adding Oks and Mehs to an approximated number of combo breaks the result can be
            // * higher than total hits in specific scenarios (which breaks some calculations) so we need to clamp it.
            effective_miss_count = (effective_miss_count
                + f64::from(self.state.hitresults.n100) * n100_mult
                + f64::from(self.state.hitresults.n50) * n50_mult)
                .min(total_hits);
        }

        let speed_deviation = self.calculate_speed_deviation();

        let mut aim_estimated_slider_breaks = 0.0;
        let mut speed_estimated_slider_breaks = 0.0;

        let aim_value =
            self.compute_aim_value(effective_miss_count, &mut aim_estimated_slider_breaks);
        let speed_value = self.compute_speed_value(
            speed_deviation,
            effective_miss_count,
            &mut speed_estimated_slider_breaks,
        );
        let acc_value = self.compute_accuracy_value();
        let flashlight_value = self.compute_flashlight_value(effective_miss_count);

        let pp = (aim_value.powf(1.1)
            + speed_value.powf(1.1)
            + acc_value.powf(1.1)
            + flashlight_value.powf(1.1))
        .powf(1.0 / 1.1)
            * multiplier;

        OsuPerformanceAttributes {
            difficulty: self.attrs,
            pp_acc: acc_value,
            pp_aim: aim_value,
            pp_flashlight: flashlight_value,
            pp_speed: speed_value,
            pp,
            effective_miss_count,
            speed_deviation,
            combo_based_estimated_miss_count,
            score_based_estimated_miss_count,
            aim_estimated_slider_breaks,
            speed_estimated_slider_breaks,
        }
    }

    fn compute_aim_value(
        &self,
        effective_miss_count: f64,
        aim_estimated_slider_breaks: &mut f64,
    ) -> f64 {
        if self.mods.ap() {
            return 0.0;
        }

        let mut aim_difficulty = self.attrs.aim;

        if self.attrs.n_sliders > 0 && self.attrs.aim_difficult_slider_count > 0.0 {
            let estimate_improperly_followed_difficult_sliders = if self.using_classic_slider_acc {
                // * When the score is considered classic (regardless if it was made on old client or not)
                // * we consider all missing combo to be dropped difficult sliders
                let maximum_possible_dropped_sliders = self.total_imperfect_hits();

                f64::clamp(
                    f64::min(
                        maximum_possible_dropped_sliders,
                        f64::from(self.attrs.max_combo - self.state.max_combo),
                    ),
                    0.0,
                    self.attrs.aim_difficult_slider_count,
                )
            } else {
                // * We add tick misses here since they too mean that the player didn't follow the slider properly
                // * We however aren't adding misses here because missing slider heads has a harsh penalty
                // * by itself and doesn't mean that the rest of the slider wasn't followed properly
                f64::clamp(
                    f64::from(self.n_slider_ends_dropped() + self.n_large_tick_miss()),
                    0.0,
                    self.attrs.aim_difficult_slider_count,
                )
            };

            let slider_nerf_factor = (1.0 - self.attrs.slider_factor)
                * f64::powf(
                    1.0 - estimate_improperly_followed_difficult_sliders
                        / self.attrs.aim_difficult_slider_count,
                    3.0,
                )
                + self.attrs.slider_factor;
            aim_difficulty *= slider_nerf_factor;
        }

        let mut aim_value = Aim::difficulty_to_performance(aim_difficulty);

        let total_hits = self.total_hits();

        let len_bonus = 0.95
            + 0.4 * (total_hits / 2000.0).min(1.0)
            + f64::from(u8::from(total_hits > 2000.0)) * (total_hits / 2000.0).log10() * 0.5;

        aim_value *= len_bonus;

        if effective_miss_count > 0.0 {
            *aim_estimated_slider_breaks = self.calculate_estimated_slider_breaks(
                self.attrs.aim_top_weighted_slider_factor,
                effective_miss_count,
            );

            let relevant_miss_count = (effective_miss_count + *aim_estimated_slider_breaks)
                .min(self.total_imperfect_hits() + f64::from(self.n_large_tick_miss()));

            aim_value *= Self::calculate_miss_penalty(
                relevant_miss_count,
                self.attrs.aim_difficult_strain_count,
            );
        }

        // * TC bonuses are excluded when blinds is present as the increased visual difficulty is unimportant when notes cannot be seen.
        if self.mods.bl() {
            aim_value *= 1.3
                + (total_hits
                    * (0.0016 / (1.0 + 2.0 * effective_miss_count))
                    * self.acc.powf(16.0))
                    * (1.0 - 0.003 * self.attrs.hp * self.attrs.hp);
        } else if self.mods.tc() {
            aim_value *= 1.0
                + OsuRatingCalculator::calculate_visibility_bonus(
                    self.mods,
                    self.attrs.ar,
                    Some(self.attrs.slider_factor),
                    None,
                );
        }

        aim_value *= self.acc;

        aim_value
    }

    fn compute_speed_value(
        &self,
        speed_deviation: Option<f64>,
        effective_miss_count: f64,
        speed_estimated_slider_breaks: &mut f64,
    ) -> f64 {
        let Some(speed_deviation) = speed_deviation.filter(|_| !self.mods.rx()) else {
            return 0.0;
        };

        let mut speed_value = Speed::difficulty_to_performance(self.attrs.speed);

        let total_hits = self.total_hits();

        let len_bonus = 0.95
            + 0.4 * (total_hits / 2000.0).min(1.0)
            + f64::from(u8::from(total_hits > 2000.0)) * (total_hits / 2000.0).log10() * 0.5;

        speed_value *= len_bonus;

        if effective_miss_count > 0.0 {
            *speed_estimated_slider_breaks = self.calculate_estimated_slider_breaks(
                self.attrs.speed_top_weighted_slider_factor,
                effective_miss_count,
            );

            let relevant_miss_count = (effective_miss_count + *speed_estimated_slider_breaks)
                .min(self.total_imperfect_hits() + f64::from(self.n_large_tick_miss()));

            speed_value *= Self::calculate_miss_penalty(
                relevant_miss_count,
                self.attrs.speed_difficult_strain_count,
            );
        }

        // * TC bonuses are excluded when blinds is present as the increased visual difficulty is unimportant when notes cannot be seen.
        if self.mods.bl() {
            // * Increasing the speed value by object count for Blinds isn't
            // * ideal, so the minimum buff is given.
            speed_value *= 1.12;
        } else if self.mods.tc() {
            speed_value *= 1.0
                + OsuRatingCalculator::calculate_visibility_bonus(
                    self.mods,
                    self.attrs.ar,
                    None,
                    None,
                );
        }

        let speed_high_deviation_mult = self.calculate_speed_high_deviation_nerf(speed_deviation);
        speed_value *= speed_high_deviation_mult;

        // * Calculate accuracy assuming the worst case scenario
        let relevant_total_diff = f64::max(0.0, total_hits - self.attrs.speed_note_count);
        let hitresults = &self.state.hitresults;
        let relevant_n300 = (f64::from(hitresults.n300) - relevant_total_diff).max(0.0);
        let relevant_n100 = (f64::from(hitresults.n100)
            - (relevant_total_diff - f64::from(hitresults.n300)).max(0.0))
        .max(0.0);
        let relevant_n50 = (f64::from(hitresults.n50)
            - (relevant_total_diff - f64::from(hitresults.n300 + hitresults.n100)).max(0.0))
        .max(0.0);

        let relevant_acc = if self.attrs.speed_note_count.eq(0.0) {
            0.0
        } else {
            (relevant_n300 * 6.0 + relevant_n100 * 2.0 + relevant_n50)
                / (self.attrs.speed_note_count * 6.0)
        };

        let od = self.attrs.od();

        // * Scale the speed value with accuracy and OD.
        speed_value *= f64::powf((self.acc + relevant_acc) / 2.0, (14.5 - od) / 2.0);

        speed_value
    }

    fn compute_accuracy_value(&self) -> f64 {
        if self.mods.rx() {
            return 0.0;
        }

        // * This percentage only considers HitCircles of any value - in this part
        // * of the calculation we focus on hitting the timing hit window.
        let mut amount_hit_objects_with_acc = self.attrs.n_circles;

        if !self.using_classic_slider_acc {
            amount_hit_objects_with_acc += self.attrs.n_sliders;
        }

        let hitresults = &self.state.hitresults;

        let mut better_acc_percentage = if amount_hit_objects_with_acc > 0 {
            f64::from(
                (hitresults.n300 as i32
                    - (cmp::max(
                        hitresults.total_hits() as i32 - amount_hit_objects_with_acc as i32,
                        0,
                    )))
                    * 6
                    + hitresults.n100 as i32 * 2
                    + hitresults.n50 as i32,
            ) / f64::from(amount_hit_objects_with_acc * 6)
        } else {
            0.0
        };

        // * It is possible to reach a negative accuracy with this formula. Cap it at zero - zero points.
        if better_acc_percentage < 0.0 {
            better_acc_percentage = 0.0;
        }

        // * Lots of arbitrary values from testing.
        // * Considering to use derivation from perfect accuracy in a probabilistic manner - assume normal distribution.
        let mut acc_value =
            1.52163_f64.powf(self.attrs.od()) * better_acc_percentage.powf(24.0) * 2.83;

        // * Bonus for many hitcircles - it's harder to keep good accuracy up for longer.
        acc_value *= (f64::from(amount_hit_objects_with_acc) / 1000.0)
            .powf(0.3)
            .min(1.15);

        // * Increasing the accuracy value by object count for Blinds isn't
        // * ideal, so the minimum buff is given.
        if self.mods.bl() {
            acc_value *= 1.14;
        } else if self.mods.hd() || self.mods.tc() {
            // * Decrease bonus for AR > 10
            acc_value *= 1.0 + 0.08 * reverse_lerp(self.attrs.ar, 11.5, 10.0);
        }

        if self.mods.fl() {
            acc_value *= 1.02;
        }

        acc_value
    }

    fn compute_flashlight_value(&self, effective_miss_count: f64) -> f64 {
        if !self.mods.fl() {
            return 0.0;
        }

        let mut flashlight_value = Flashlight::difficulty_to_performance(self.attrs.flashlight);

        let total_hits = self.total_hits();

        // * Penalize misses by assessing # of misses relative to the total # of objects. Default a 3% reduction for any # of misses.
        if effective_miss_count > 0.0 {
            flashlight_value *= 0.97
                * (1.0 - (effective_miss_count / total_hits).powf(0.775))
                    .powf(effective_miss_count.powf(0.875));
        }

        flashlight_value *= self.get_combo_scaling_factor();

        // * Scale the flashlight value with accuracy _slightly_.
        flashlight_value *= 0.5 + self.acc / 2.0;

        flashlight_value
    }

    fn calculate_combo_based_estimated_miss_count(&self) -> f64 {
        let Self {
            state,
            attrs,
            using_classic_slider_acc,
            ..
        } = self;

        if attrs.n_sliders == 0 {
            return f64::from(state.hitresults.misses);
        }

        let mut miss_count = f64::from(state.hitresults.misses);

        if *using_classic_slider_acc {
            // * Consider that full combo is maximum combo minus dropped slider tails since they don't contribute to combo but also don't break it
            // * In classic scores we can't know the amount of dropped sliders so we estimate to 10% of all sliders on the map
            let full_combo_threshold =
                f64::from(attrs.max_combo) - 0.1 * f64::from(attrs.n_sliders);

            if f64::from(state.max_combo) < full_combo_threshold {
                miss_count = full_combo_threshold / f64::from(state.max_combo).max(1.0);
            }

            // * In classic scores there can't be more misses than a sum of all non-perfect judgements
            miss_count = miss_count.min(self.total_imperfect_hits());

            // * Every slider has *at least* 2 combo attributed in classic mechanics.
            // * If they broke on a slider with a tick, then this still works since they would have lost at least 2 combo (the tick and the end)
            // * Using this as a max means a score that loses 1 combo on a map can't possibly have been a slider break.
            // * It must have been a slider end.
            let max_possible_slider_breaks = cmp::min(
                attrs.n_sliders,
                (attrs.max_combo.saturating_sub(state.max_combo)) / 2,
            );

            let slider_breaks = miss_count - f64::from(state.hitresults.misses);

            if slider_breaks > f64::from(max_possible_slider_breaks) {
                miss_count = f64::from(state.hitresults.misses + max_possible_slider_breaks);
            }
        } else {
            let full_combo_threshold = f64::from(attrs.max_combo - self.n_slider_ends_dropped());

            if f64::from(state.max_combo) < full_combo_threshold {
                miss_count = full_combo_threshold / f64::from(state.max_combo).max(1.0);
            }

            // * Combine regular misses with tick misses since tick misses break combo as well
            miss_count = miss_count.min(f64::from(
                self.n_large_tick_miss() + state.hitresults.misses,
            ));
        }

        miss_count
    }

    fn calculate_estimated_slider_breaks(
        &self,
        top_weighted_slider_factor: f64,
        effective_miss_count: f64,
    ) -> f64 {
        let Self {
            attrs,
            state,
            using_classic_slider_acc,
            ..
        } = self;

        if !using_classic_slider_acc || state.hitresults.n100 == 0 {
            return 0.0;
        }

        let missed_combo_percent = 1.0 - f64::from(state.max_combo) / f64::from(attrs.max_combo);
        let mut estimated_slider_breaks = (effective_miss_count * top_weighted_slider_factor)
            .min(f64::from(state.hitresults.n100));

        // * Scores with more Oks are more likely to have slider breaks.
        let ok_adjustment = ((f64::from(state.hitresults.n100) - estimated_slider_breaks) + 0.5)
            / f64::from(state.hitresults.n100);

        // * There is a low probability of extra slider breaks on effective miss counts close to 1, as score based calculations are good at indicating if only a single break occurred.
        estimated_slider_breaks *= smoothstep(effective_miss_count, 1.0, 2.0);

        estimated_slider_breaks * ok_adjustment * logistic(missed_combo_percent, 0.33, 15.0, None)
    }

    fn calculate_speed_deviation(&self) -> Option<f64> {
        if self.total_successful_hits() == 0 {
            return None;
        }

        let hitresults = &self.state.hitresults;

        // * Calculate accuracy assuming the worst case scenario
        let mut speed_note_count = self.attrs.speed_note_count;
        speed_note_count +=
            (f64::from(hitresults.total_hits()) - self.attrs.speed_note_count) * 0.1;

        // * Assume worst case: all mistakes were on speed notes
        let relevant_count_miss = f64::min(f64::from(hitresults.misses), speed_note_count);
        let relevant_count_meh = f64::min(
            f64::from(hitresults.n50),
            speed_note_count - relevant_count_miss,
        );
        let relevant_count_ok = f64::min(
            f64::from(hitresults.n100),
            speed_note_count - relevant_count_miss - relevant_count_meh,
        );
        let relevant_count_great = f64::max(
            0.0,
            speed_note_count - relevant_count_miss - relevant_count_meh - relevant_count_ok,
        );

        self.calculate_deviation(relevant_count_great, relevant_count_ok, relevant_count_meh)
    }

    fn calculate_deviation(
        &self,
        relevant_count_great: f64,
        relevant_count_ok: f64,
        relevant_count_meh: f64,
    ) -> Option<f64> {
        if relevant_count_great + relevant_count_ok + relevant_count_meh <= 0.0 {
            return None;
        }

        // * The sample proportion of successful hits.
        let n = f64::max(1.0, relevant_count_great + relevant_count_ok);
        let p = relevant_count_great / n;

        #[expect(
            clippy::items_after_statements,
            clippy::unreadable_literal,
            reason = "staying in-sync with lazer"
        )]
        // * 99% critical value for the normal distribution (one-tailed).
        const Z: f64 = 2.32634787404;

        // * We can be 99% confident that the population proportion is at least this value.
        let p_lower_bound = ((n * p + Z * Z / 2.0) / (n + Z * Z)
            - Z / (n + Z * Z) * f64::sqrt(n * p * (1.0 - p) + Z * Z / 4.0))
        .min(p);

        let great_hit_window: f64 = self.attrs.great_hit_window;
        let ok_hit_window: f64 = self.attrs.ok_hit_window;
        let meh_hit_window: f64 = self.attrs.meh_hit_window;

        let mut deviation;

        if p_lower_bound > 0.01 {
            deviation = great_hit_window / (f64::sqrt(2.0) * erf_inv(p_lower_bound));

            // * Subtract the deviation provided by tails that land outside the ok hit window from the deviation computed above.
            // * This is equivalent to calculating the deviation of a normal distribution truncated at +-okHitWindow.
            let ok_hit_window_tail_amount = f64::sqrt(2.0 / PI)
                * ok_hit_window
                * f64::exp(-0.5 * f64::powf(ok_hit_window / deviation, 2.0))
                / (deviation * erf(ok_hit_window / (f64::sqrt(2.0) * deviation)));

            deviation *= f64::sqrt(1.0 - ok_hit_window_tail_amount);
        } else {
            // * A tested limit value for the case of a score only containing oks.
            deviation = ok_hit_window / f64::sqrt(3.0);
        }

        // * Compute and add the variance for mehs, assuming that they are uniformly distributed.
        let meh_variance = (meh_hit_window * meh_hit_window
            + ok_hit_window * meh_hit_window
            + ok_hit_window * ok_hit_window)
            / 3.0;

        let deviation = f64::sqrt(
            ((relevant_count_great + relevant_count_ok) * f64::powf(deviation, 2.0)
                + relevant_count_meh * meh_variance)
                / (relevant_count_great + relevant_count_ok + relevant_count_meh),
        );

        Some(deviation)
    }

    fn calculate_speed_high_deviation_nerf(&self, speed_deviation: f64) -> f64 {
        let speed_value = Speed::difficulty_to_performance(self.attrs.speed);

        // * Decides a point where the PP value achieved compared to the speed deviation is assumed to be tapped improperly. Any PP above this point is considered "excess" speed difficulty.
        // * This is used to cause PP above the cutoff to scale logarithmically towards the original speed value thus nerfing the value.
        let excess_speed_difficulty_cutoff = 100.0 + 220.0 * f64::powf(22.0 / speed_deviation, 6.5);

        if speed_value <= excess_speed_difficulty_cutoff {
            return 1.0;
        }

        #[expect(clippy::items_after_statements, reason = "staying in-sync with lazer")]
        const SCALE: f64 = 50.0;

        let mut adjusted_speed_value = SCALE
            * (f64::ln((speed_value - excess_speed_difficulty_cutoff) / SCALE + 1.0)
                + excess_speed_difficulty_cutoff / SCALE);

        // * 220 UR and less are considered tapped correctly to ensure that normal scores will be punished as little as possible
        let lerp = 1.0 - reverse_lerp(speed_deviation, 22.0, 27.0);
        adjusted_speed_value = f64::lerp(adjusted_speed_value, speed_value, lerp);

        adjusted_speed_value / speed_value
    }

    // * Miss penalty assumes that a player will miss on the hardest parts of a map,
    // * so we use the amount of relatively difficult sections to adjust miss penalty
    // * to make it more punishing on maps with lower amount of hard sections.
    fn calculate_miss_penalty(miss_count: f64, diff_strain_count: f64) -> f64 {
        0.96 / ((miss_count / (4.0 * diff_strain_count.ln().powf(0.94))) + 1.0)
    }

    fn get_combo_scaling_factor(&self) -> f64 {
        if self.attrs.max_combo == 0 {
            1.0
        } else {
            (f64::from(self.state.max_combo).powf(0.8) / f64::from(self.attrs.max_combo).powf(0.8))
                .min(1.0)
        }
    }

    const fn total_hits(&self) -> f64 {
        self.state.hitresults.total_hits() as f64
    }

    const fn total_successful_hits(&self) -> u32 {
        self.state.hitresults.n300 + self.state.hitresults.n100 + self.state.hitresults.n50
    }

    fn total_imperfect_hits(&self) -> f64 {
        f64::from(
            self.state.hitresults.n100 + self.state.hitresults.n50 + self.state.hitresults.misses,
        )
    }

    const fn n_slider_ends_dropped(&self) -> u32 {
        self.attrs.n_sliders - self.state.hitresults.slider_end_hits
    }

    const fn n_large_tick_miss(&self) -> u32 {
        // Lazer unconditionally uses the "large tick miss" hitresult and
        // relies on this value being correctly provided by the caller / user.
        // On stable, this value should always be 0.
        //
        // This is a best-effort workaround to achieve the same behavior.
        if self.using_classic_slider_acc {
            0
        } else {
            self.attrs.n_large_ticks - self.state.hitresults.large_tick_hits
        }
    }
}