2023-06-13 18:41:39 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System;
|
2023-10-02 14:58:31 +08:00
|
|
|
using System.Collections.Generic;
|
2023-06-13 18:41:39 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Game.Beatmaps;
|
2023-10-02 14:58:31 +08:00
|
|
|
using osu.Game.Rulesets.Catch.Mods;
|
2023-06-13 18:41:39 +08:00
|
|
|
using osu.Game.Rulesets.Catch.Objects;
|
2023-12-20 19:23:43 +08:00
|
|
|
using osu.Game.Rulesets.Catch.Scoring;
|
2023-10-02 14:58:31 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2023-06-13 18:41:39 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
Fix incorrect score conversion on selected beatmaps due to incorrect `difficultyPeppyStars` rounding
Fixes issue that occurs on *about* 246 beatmaps and was first described
by me on discord:
https://discord.com/channels/188630481301012481/188630652340404224/1154367700378865715
and then rediscovered again during work on
https://github.com/ppy/osu/pull/26405:
https://gist.github.com/bdach/414d5289f65b0399fa8f9732245a4f7c#venenog-on-ultmate-end-by-blacky-overdose-631
It so happens that in stable, due to .NET Framework internals, float
math would be performed using x87 registers and opcodes.
.NET (Core) however uses SSE instructions on 32- and 64-bit words.
x87 registers are _80 bits_ wide. Which is notably wider than _both_
float and double. Therefore, on a significant number of beatmaps,
the rounding would not produce correct values due to insufficient
precision.
See following gist for corroboration of the above:
https://gist.github.com/bdach/dcde58d5a3607b0408faa3aa2b67bf10
Thus, to crudely - but, seemingly accurately, after checking across
all ranked maps - emulate this, use `decimal`, which is slow, but has
bigger precision than `double`. The single known exception beatmap
in whose case this results in an incorrect result is
https://osu.ppy.sh/beatmapsets/1156087#osu/2625853
which is considered an "acceptable casualty" of sorts.
Doing this requires some fooling of the compiler / runtime (see second
inline comment in new method). To corroborate that this is required,
you can try the following code snippet:
Console.WriteLine(string.Join(' ', BitConverter.GetBytes(1.3f).Select(x => x.ToString("X2"))));
Console.WriteLine(string.Join(' ', BitConverter.GetBytes(1.3).Select(x => x.ToString("X2"))));
Console.WriteLine();
decimal d1 = (decimal)1.3f;
decimal d2 = (decimal)1.3;
decimal d3 = (decimal)(double)1.3f;
Console.WriteLine(string.Join(' ', decimal.GetBits(d1).SelectMany(BitConverter.GetBytes).Select(x => x.ToString("X2"))));
Console.WriteLine(string.Join(' ', decimal.GetBits(d2).SelectMany(BitConverter.GetBytes).Select(x => x.ToString("X2"))));
Console.WriteLine(string.Join(' ', decimal.GetBits(d3).SelectMany(BitConverter.GetBytes).Select(x => x.ToString("X2"))));
which will print
66 66 A6 3F
CD CC CC CC CC CC F4 3F
0D 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00
0D 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00
8C 5D 89 FB 3B 76 00 00 00 00 00 00 00 00 0E 00
Note that despite `d1` being converted from a less-precise floating-
-point value than `d2`, it still is represented 100% accurately as
a decimal number.
After applying this change, recomputation of legacy scoring attributes
for *all* rulesets will be required.
2024-01-10 23:51:40 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Legacy;
|
2023-06-13 18:41:39 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2023-06-19 20:38:13 +08:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
2023-09-04 16:43:23 +08:00
|
|
|
using osu.Game.Rulesets.Scoring.Legacy;
|
2023-06-13 18:41:39 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.Difficulty
|
|
|
|
{
|
2023-07-04 16:32:54 +08:00
|
|
|
internal class CatchLegacyScoreSimulator : ILegacyScoreSimulator
|
2023-06-13 18:41:39 +08:00
|
|
|
{
|
2023-12-20 19:23:43 +08:00
|
|
|
private readonly ScoreProcessor scoreProcessor = new CatchScoreProcessor();
|
|
|
|
|
2023-06-19 20:38:13 +08:00
|
|
|
private int legacyBonusScore;
|
2023-09-04 16:43:23 +08:00
|
|
|
private int standardisedBonusScore;
|
2023-06-13 18:41:39 +08:00
|
|
|
private int combo;
|
|
|
|
|
2023-06-26 21:19:01 +08:00
|
|
|
private double scoreMultiplier;
|
2023-06-13 18:41:39 +08:00
|
|
|
|
2023-09-04 16:43:23 +08:00
|
|
|
public LegacyScoreAttributes Simulate(IWorkingBeatmap workingBeatmap, IBeatmap playableBeatmap)
|
2023-06-13 18:41:39 +08:00
|
|
|
{
|
2023-06-26 21:19:01 +08:00
|
|
|
IBeatmap baseBeatmap = workingBeatmap.Beatmap;
|
|
|
|
|
2023-06-13 18:41:39 +08:00
|
|
|
int countNormal = 0;
|
|
|
|
int countSlider = 0;
|
|
|
|
int countSpinner = 0;
|
|
|
|
|
|
|
|
foreach (HitObject obj in baseBeatmap.HitObjects)
|
|
|
|
{
|
|
|
|
switch (obj)
|
|
|
|
{
|
|
|
|
case IHasPath:
|
|
|
|
countSlider++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IHasDuration:
|
|
|
|
countSpinner++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
countNormal++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int objectCount = countNormal + countSlider + countSpinner;
|
|
|
|
|
2023-06-23 23:58:45 +08:00
|
|
|
int drainLength = 0;
|
|
|
|
|
|
|
|
if (baseBeatmap.HitObjects.Count > 0)
|
|
|
|
{
|
|
|
|
int breakLength = baseBeatmap.Breaks.Select(b => (int)Math.Round(b.EndTime) - (int)Math.Round(b.StartTime)).Sum();
|
|
|
|
drainLength = ((int)Math.Round(baseBeatmap.HitObjects[^1].StartTime) - (int)Math.Round(baseBeatmap.HitObjects[0].StartTime) - breakLength) / 1000;
|
|
|
|
}
|
|
|
|
|
Fix incorrect score conversion on selected beatmaps due to incorrect `difficultyPeppyStars` rounding
Fixes issue that occurs on *about* 246 beatmaps and was first described
by me on discord:
https://discord.com/channels/188630481301012481/188630652340404224/1154367700378865715
and then rediscovered again during work on
https://github.com/ppy/osu/pull/26405:
https://gist.github.com/bdach/414d5289f65b0399fa8f9732245a4f7c#venenog-on-ultmate-end-by-blacky-overdose-631
It so happens that in stable, due to .NET Framework internals, float
math would be performed using x87 registers and opcodes.
.NET (Core) however uses SSE instructions on 32- and 64-bit words.
x87 registers are _80 bits_ wide. Which is notably wider than _both_
float and double. Therefore, on a significant number of beatmaps,
the rounding would not produce correct values due to insufficient
precision.
See following gist for corroboration of the above:
https://gist.github.com/bdach/dcde58d5a3607b0408faa3aa2b67bf10
Thus, to crudely - but, seemingly accurately, after checking across
all ranked maps - emulate this, use `decimal`, which is slow, but has
bigger precision than `double`. The single known exception beatmap
in whose case this results in an incorrect result is
https://osu.ppy.sh/beatmapsets/1156087#osu/2625853
which is considered an "acceptable casualty" of sorts.
Doing this requires some fooling of the compiler / runtime (see second
inline comment in new method). To corroborate that this is required,
you can try the following code snippet:
Console.WriteLine(string.Join(' ', BitConverter.GetBytes(1.3f).Select(x => x.ToString("X2"))));
Console.WriteLine(string.Join(' ', BitConverter.GetBytes(1.3).Select(x => x.ToString("X2"))));
Console.WriteLine();
decimal d1 = (decimal)1.3f;
decimal d2 = (decimal)1.3;
decimal d3 = (decimal)(double)1.3f;
Console.WriteLine(string.Join(' ', decimal.GetBits(d1).SelectMany(BitConverter.GetBytes).Select(x => x.ToString("X2"))));
Console.WriteLine(string.Join(' ', decimal.GetBits(d2).SelectMany(BitConverter.GetBytes).Select(x => x.ToString("X2"))));
Console.WriteLine(string.Join(' ', decimal.GetBits(d3).SelectMany(BitConverter.GetBytes).Select(x => x.ToString("X2"))));
which will print
66 66 A6 3F
CD CC CC CC CC CC F4 3F
0D 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00
0D 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00
8C 5D 89 FB 3B 76 00 00 00 00 00 00 00 00 0E 00
Note that despite `d1` being converted from a less-precise floating-
-point value than `d2`, it still is represented 100% accurately as
a decimal number.
After applying this change, recomputation of legacy scoring attributes
for *all* rulesets will be required.
2024-01-10 23:51:40 +08:00
|
|
|
scoreMultiplier = LegacyRulesetExtensions.CalculateDifficultyPeppyStars(baseBeatmap.Difficulty, objectCount, drainLength);
|
2023-09-04 16:43:23 +08:00
|
|
|
|
|
|
|
LegacyScoreAttributes attributes = new LegacyScoreAttributes();
|
2023-06-13 18:41:39 +08:00
|
|
|
|
|
|
|
foreach (var obj in playableBeatmap.HitObjects)
|
2023-09-04 16:43:23 +08:00
|
|
|
simulateHit(obj, ref attributes);
|
|
|
|
|
|
|
|
attributes.BonusScoreRatio = legacyBonusScore == 0 ? 0 : (double)standardisedBonusScore / legacyBonusScore;
|
2023-11-25 06:07:27 +08:00
|
|
|
attributes.BonusScore = legacyBonusScore;
|
2023-12-18 11:01:51 +08:00
|
|
|
attributes.MaxCombo = combo;
|
2023-09-04 16:43:23 +08:00
|
|
|
|
|
|
|
return attributes;
|
2023-06-13 18:41:39 +08:00
|
|
|
}
|
|
|
|
|
2023-09-04 16:43:23 +08:00
|
|
|
private void simulateHit(HitObject hitObject, ref LegacyScoreAttributes attributes)
|
2023-06-13 18:41:39 +08:00
|
|
|
{
|
|
|
|
bool increaseCombo = true;
|
|
|
|
bool addScoreComboMultiplier = false;
|
2023-06-19 20:38:13 +08:00
|
|
|
|
2023-06-13 18:41:39 +08:00
|
|
|
bool isBonus = false;
|
2023-06-19 20:38:13 +08:00
|
|
|
HitResult bonusResult = HitResult.None;
|
2023-06-13 18:41:39 +08:00
|
|
|
|
|
|
|
int scoreIncrease = 0;
|
|
|
|
|
|
|
|
switch (hitObject)
|
|
|
|
{
|
|
|
|
case TinyDroplet:
|
|
|
|
scoreIncrease = 10;
|
|
|
|
increaseCombo = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Droplet:
|
|
|
|
scoreIncrease = 100;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Fruit:
|
|
|
|
scoreIncrease = 300;
|
|
|
|
addScoreComboMultiplier = true;
|
|
|
|
increaseCombo = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Banana:
|
|
|
|
scoreIncrease = 1100;
|
|
|
|
increaseCombo = false;
|
|
|
|
isBonus = true;
|
2023-06-19 20:38:13 +08:00
|
|
|
bonusResult = HitResult.LargeBonus;
|
2023-06-13 18:41:39 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case JuiceStream:
|
|
|
|
foreach (var nested in hitObject.NestedHitObjects)
|
2023-09-04 16:43:23 +08:00
|
|
|
simulateHit(nested, ref attributes);
|
2023-06-13 18:41:39 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
case BananaShower:
|
|
|
|
foreach (var nested in hitObject.NestedHitObjects)
|
2023-09-04 16:43:23 +08:00
|
|
|
simulateHit(nested, ref attributes);
|
2023-06-13 18:41:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addScoreComboMultiplier)
|
|
|
|
{
|
|
|
|
// ReSharper disable once PossibleLossOfFraction (intentional to match osu-stable...)
|
2023-09-04 16:43:23 +08:00
|
|
|
attributes.ComboScore += (int)(Math.Max(0, combo - 1) * (scoreIncrease / 25 * scoreMultiplier));
|
2023-06-13 18:41:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isBonus)
|
2023-06-19 20:38:13 +08:00
|
|
|
{
|
|
|
|
legacyBonusScore += scoreIncrease;
|
2023-12-21 13:58:23 +08:00
|
|
|
standardisedBonusScore += scoreProcessor.GetBaseScoreForResult(bonusResult);
|
2023-06-19 20:38:13 +08:00
|
|
|
}
|
2023-06-13 18:41:39 +08:00
|
|
|
else
|
2023-09-04 16:43:23 +08:00
|
|
|
attributes.AccuracyScore += scoreIncrease;
|
2023-06-13 18:41:39 +08:00
|
|
|
|
|
|
|
if (increaseCombo)
|
|
|
|
combo++;
|
|
|
|
}
|
2023-10-02 14:58:31 +08:00
|
|
|
|
|
|
|
public double GetLegacyScoreMultiplier(IReadOnlyList<Mod> mods, LegacyBeatmapConversionDifficultyInfo difficulty)
|
|
|
|
{
|
|
|
|
bool scoreV2 = mods.Any(m => m is ModScoreV2);
|
|
|
|
|
|
|
|
double multiplier = 1.0;
|
|
|
|
|
|
|
|
foreach (var mod in mods)
|
|
|
|
{
|
|
|
|
switch (mod)
|
|
|
|
{
|
|
|
|
case CatchModNoFail:
|
|
|
|
multiplier *= scoreV2 ? 1.0 : 0.5;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CatchModEasy:
|
|
|
|
multiplier *= 0.5;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CatchModHalfTime:
|
|
|
|
case CatchModDaycore:
|
|
|
|
multiplier *= 0.3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CatchModHidden:
|
|
|
|
multiplier *= scoreV2 ? 1.0 : 1.06;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CatchModHardRock:
|
|
|
|
multiplier *= 1.12;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CatchModDoubleTime:
|
|
|
|
case CatchModNightcore:
|
|
|
|
multiplier *= 1.06;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CatchModFlashlight:
|
|
|
|
multiplier *= 1.12;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CatchModRelax:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return multiplier;
|
|
|
|
}
|
2023-06-13 18:41:39 +08:00
|
|
|
}
|
|
|
|
}
|