Skip to content

Commit

Permalink
Add extra safety against returning negative total score in conversion…
Browse files Browse the repository at this point in the history
… operation
  • Loading branch information
bdach committed Dec 23, 2023
1 parent fc56188 commit 007ea51
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions osu.Game/Database/StandardisedScoreMigrationTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ private static long convertFromLegacyTotalScore(ScoreInfo score, LegacyBeatmapCo

double modMultiplier = score.Mods.Select(m => m.ScoreMultiplier).Aggregate(1.0, (c, n) => c * n);

long convertedTotalScore;

switch (score.Ruleset.OnlineID)
{
case 0:
Expand Down Expand Up @@ -417,32 +419,42 @@ private static long convertFromLegacyTotalScore(ScoreInfo score, LegacyBeatmapCo

double newComboScoreProportion = estimatedComboPortionInStandardisedScore / maximumAchievableComboPortionInStandardisedScore;

return (long)Math.Round((
convertedTotalScore = (long)Math.Round((
500000 * newComboScoreProportion * score.Accuracy
+ 500000 * Math.Pow(score.Accuracy, 5)
+ bonusProportion) * modMultiplier);
break;

case 1:
return (long)Math.Round((
convertedTotalScore = (long)Math.Round((
250000 * comboProportion
+ 750000 * Math.Pow(score.Accuracy, 3.6)
+ bonusProportion) * modMultiplier);
break;

case 2:
return (long)Math.Round((
convertedTotalScore = (long)Math.Round((
600000 * comboProportion
+ 400000 * score.Accuracy
+ bonusProportion) * modMultiplier);
break;

case 3:
return (long)Math.Round((
convertedTotalScore = (long)Math.Round((
850000 * comboProportion
+ 150000 * Math.Pow(score.Accuracy, 2 + 2 * score.Accuracy)
+ bonusProportion) * modMultiplier);
break;

default:
return score.TotalScore;
convertedTotalScore = score.TotalScore;
break;
}

if (convertedTotalScore < 0)
throw new InvalidOperationException($"Total score conversion operation returned invalid total of {convertedTotalScore}");

return convertedTotalScore;
}

public static double ComputeAccuracy(ScoreInfo scoreInfo)
Expand Down

0 comments on commit 007ea51

Please sign in to comment.