Skip to content

Commit

Permalink
Fix querying imported legacy scores having duplicate stats
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Feb 7, 2024
1 parent cb60951 commit 408b127
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 27 deletions.
25 changes: 25 additions & 0 deletions PerformanceCalculator/Performance/LegacyScorePerformanceCommand.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Linq;
using McMaster.Extensions.CommandLineUtils;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring.Legacy;
using osu.Game.Scoring;
using osu.Game.Scoring.Legacy;

namespace PerformanceCalculator.Performance
{
Expand All @@ -13,5 +21,22 @@ public class LegacyScorePerformanceCommand : ScorePerformanceCommand
public int RulesetId { get; set; }

protected override SoloScoreInfo QueryScore() => GetJsonFromApi<SoloScoreInfo>($"scores/{LegacyHelper.GetRulesetShortNameFromId(RulesetId)}/{ScoreId}");

protected override ScoreInfo CreateScore(SoloScoreInfo apiScore, Ruleset ruleset, APIBeatmap apiBeatmap, WorkingBeatmap workingBeatmap)
{
var score = base.CreateScore(apiScore, ruleset, apiBeatmap, workingBeatmap);

score.Mods = score.Mods.Append(ruleset.CreateMod<ModClassic>()).ToArray();
score.IsLegacyScore = true;
score.LegacyTotalScore = (int)score.TotalScore;
LegacyScoreDecoder.PopulateMaximumStatistics(score, workingBeatmap);
StandardisedScoreMigrationTools.UpdateFromLegacy(
score,
ruleset,
LegacyBeatmapConversionDifficultyInfo.FromAPIBeatmap(apiBeatmap),
((ILegacyRuleset)ruleset).CreateLegacyScoreSimulator().Simulate(workingBeatmap, workingBeatmap.GetPlayableBeatmap(ruleset.RulesetInfo, score.Mods)));

return score;
}
}
}
44 changes: 17 additions & 27 deletions PerformanceCalculator/Performance/ScorePerformanceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@
using Newtonsoft.Json;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Legacy;
using osu.Game.Database;
using osu.Game.Models;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch.Difficulty;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Mania.Difficulty;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Difficulty;
using osu.Game.Rulesets.Scoring.Legacy;
using osu.Game.Rulesets.Taiko.Difficulty;
using osu.Game.Scoring.Legacy;
using osu.Game.Scoring;

namespace PerformanceCalculator.Performance
{
Expand All @@ -42,29 +39,8 @@ public override void Execute()
APIBeatmap apiBeatmap = GetJsonFromApi<APIBeatmap>($"beatmaps/lookup?id={apiScore.BeatmapID}");

var ruleset = LegacyHelper.GetRulesetFromLegacyID(apiScore.RulesetID);
var score = apiScore.ToScoreInfo(apiScore.Mods.Select(m => m.ToMod(ruleset)).ToArray(), apiBeatmap);
score.Ruleset = ruleset.RulesetInfo;
score.BeatmapInfo!.Metadata = new BeatmapMetadata
{
Title = apiBeatmap.Metadata.Title,
Artist = apiBeatmap.Metadata.Artist,
Author = new RealmUser { Username = apiBeatmap.Metadata.Author.Username },
};

var workingBeatmap = ProcessorWorkingBeatmap.FromFileOrId(score.BeatmapInfo!.OnlineID.ToString());

if (apiScore.BuildID == null)
{
score.Mods = score.Mods.Append(ruleset.CreateMod<ModClassic>()).ToArray();
score.IsLegacyScore = true;
score.LegacyTotalScore = (int)score.TotalScore;
LegacyScoreDecoder.PopulateMaximumStatistics(score, workingBeatmap);
StandardisedScoreMigrationTools.UpdateFromLegacy(
score,
ruleset,
LegacyBeatmapConversionDifficultyInfo.FromAPIBeatmap(apiBeatmap),
((ILegacyRuleset)ruleset).CreateLegacyScoreSimulator().Simulate(workingBeatmap, workingBeatmap.GetPlayableBeatmap(ruleset.RulesetInfo, score.Mods)));
}
var workingBeatmap = ProcessorWorkingBeatmap.FromFileOrId(apiScore.BeatmapID.ToString());
var score = CreateScore(apiScore, ruleset, apiBeatmap, workingBeatmap);

DifficultyAttributes attributes;

Expand All @@ -87,6 +63,20 @@ public override void Execute()

protected virtual SoloScoreInfo QueryScore() => GetJsonFromApi<SoloScoreInfo>($"scores/{ScoreId}");

protected virtual ScoreInfo CreateScore(SoloScoreInfo apiScore, Ruleset ruleset, APIBeatmap apiBeatmap, WorkingBeatmap workingBeatmap)
{
var score = apiScore.ToScoreInfo(apiScore.Mods.Select(m => m.ToMod(ruleset)).ToArray(), apiBeatmap);
score.Ruleset = ruleset.RulesetInfo;
score.BeatmapInfo!.Metadata = new BeatmapMetadata
{
Title = apiBeatmap.Metadata.Title,
Artist = apiBeatmap.Metadata.Artist,
Author = new RealmUser { Username = apiBeatmap.Metadata.Author.Username },
};

return score;
}

private DifficultyAttributes queryApiAttributes(int beatmapId, int rulesetId, LegacyMods mods)
{
Dictionary<string, string> parameters = new Dictionary<string, string>
Expand Down

0 comments on commit 408b127

Please sign in to comment.