From 8ebeeaf26fac0b0c834f3c09c704040791b1b53e Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Sun, 13 Oct 2024 15:36:37 +0900 Subject: [PATCH] Remove filtering in all unnecessary cases --- .../LegacyScoreAttributesCommand.cs | 3 +- .../LegacyScoreConversionCommand.cs | 2 +- PerformanceCalculator/LegacyHelper.cs | 26 ----------- .../Performance/ReplayPerformanceCommand.cs | 1 - .../Performance/ScorePerformanceCommand.cs | 44 ++++++++++++++++++- 5 files changed, 45 insertions(+), 31 deletions(-) diff --git a/PerformanceCalculator/Difficulty/LegacyScoreAttributesCommand.cs b/PerformanceCalculator/Difficulty/LegacyScoreAttributesCommand.cs index 8f1971351..31ce58a30 100644 --- a/PerformanceCalculator/Difficulty/LegacyScoreAttributesCommand.cs +++ b/PerformanceCalculator/Difficulty/LegacyScoreAttributesCommand.cs @@ -116,8 +116,7 @@ public override void Execute() private Result processBeatmap(WorkingBeatmap beatmap) { var ruleset = LegacyHelper.GetRulesetFromLegacyID(Ruleset ?? beatmap.BeatmapInfo.Ruleset.OnlineID); - - var mods = LegacyHelper.FilterLegacyMods(beatmap.BeatmapInfo, ruleset, getMods(ruleset)); + var mods = getMods(ruleset); var legacyRuleset = (ILegacyRuleset)ruleset; var simulator = legacyRuleset.CreateLegacyScoreSimulator(); diff --git a/PerformanceCalculator/Difficulty/LegacyScoreConversionCommand.cs b/PerformanceCalculator/Difficulty/LegacyScoreConversionCommand.cs index 583d37d10..190baa3ef 100644 --- a/PerformanceCalculator/Difficulty/LegacyScoreConversionCommand.cs +++ b/PerformanceCalculator/Difficulty/LegacyScoreConversionCommand.cs @@ -66,7 +66,7 @@ public virtual void OnExecute(CommandLineApplication app, IConsole console) var ruleset = LegacyHelper.GetRulesetFromLegacyID(Ruleset); var workingBeatmap = ProcessorWorkingBeatmap.FromFileOrId(Beatmap); - Mod[] mods = [ruleset.CreateMod(), .. LegacyHelper.FilterLegacyMods(workingBeatmap.BeatmapInfo, ruleset, getMods(ruleset))]; + Mod[] mods = [ruleset.CreateMod(), .. getMods(ruleset)]; var beatmap = workingBeatmap.GetPlayableBeatmap(ruleset.RulesetInfo, mods); diff --git a/PerformanceCalculator/LegacyHelper.cs b/PerformanceCalculator/LegacyHelper.cs index 5ac06bb0f..0449f0d93 100644 --- a/PerformanceCalculator/LegacyHelper.cs +++ b/PerformanceCalculator/LegacyHelper.cs @@ -2,16 +2,12 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Linq; -using osu.Game.Beatmaps; -using osu.Game.Beatmaps.Legacy; using osu.Game.Rulesets; using osu.Game.Rulesets.Catch; using osu.Game.Rulesets.Catch.Difficulty; using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Mania; using osu.Game.Rulesets.Mania.Difficulty; -using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu.Difficulty; using osu.Game.Rulesets.Taiko; @@ -63,28 +59,6 @@ public static string GetRulesetShortNameFromId(int id) } } - /// - /// Transforms a given combination into one which is applicable to legacy scores. - /// This is used to match osu!stable/osu!web calculations for the time being, until such a point that these mods do get considered. - /// - public static LegacyMods ConvertToLegacyMods(BeatmapInfo beatmapInfo, Ruleset ruleset, Mod[] mods) - { - var legacyMods = ruleset.ConvertToLegacyMods(mods); - - // mods that are not represented in `LegacyMods` (but we can approximate them well enough with others) - if (mods.Any(mod => mod is ModDaycore)) - legacyMods |= LegacyMods.HalfTime; - - return legacyMods; - } - - /// - /// Transforms a given combination into one which is applicable to legacy scores. - /// This is used to match osu!stable/osu!web calculations for the time being, until such a point that these mods do get considered. - /// - public static Mod[] FilterLegacyMods(BeatmapInfo beatmapInfo, Ruleset ruleset, Mod[] mods) - => ruleset.ConvertFromLegacyMods(ConvertToLegacyMods(beatmapInfo, ruleset, mods)).ToArray(); - public static DifficultyAttributes CreateDifficultyAttributes(int legacyId) { switch (legacyId) diff --git a/PerformanceCalculator/Performance/ReplayPerformanceCommand.cs b/PerformanceCalculator/Performance/ReplayPerformanceCommand.cs index 51c381a22..082062ea1 100644 --- a/PerformanceCalculator/Performance/ReplayPerformanceCommand.cs +++ b/PerformanceCalculator/Performance/ReplayPerformanceCommand.cs @@ -42,7 +42,6 @@ public override void Execute() if (score.ScoreInfo.IsLegacyScore) { - difficultyMods = LegacyHelper.FilterLegacyMods(workingBeatmap.BeatmapInfo, ruleset, difficultyMods); score.ScoreInfo.LegacyTotalScore = (int)score.ScoreInfo.TotalScore; LegacyScoreDecoder.PopulateMaximumStatistics(score.ScoreInfo, workingBeatmap); StandardisedScoreMigrationTools.UpdateFromLegacy( diff --git a/PerformanceCalculator/Performance/ScorePerformanceCommand.cs b/PerformanceCalculator/Performance/ScorePerformanceCommand.cs index 76d2c3579..0bc18179b 100644 --- a/PerformanceCalculator/Performance/ScorePerformanceCommand.cs +++ b/PerformanceCalculator/Performance/ScorePerformanceCommand.cs @@ -16,6 +16,7 @@ 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.Taiko.Difficulty; using osu.Game.Scoring; @@ -46,7 +47,7 @@ public override void Execute() if (OnlineAttributes) { - LegacyMods legacyMods = LegacyHelper.ConvertToLegacyMods(workingBeatmap.BeatmapInfo, ruleset, score.Mods); + LegacyMods legacyMods = convertToLegacyMods(workingBeatmap.BeatmapInfo, ruleset, score.Mods); attributes = queryApiAttributes(apiScore.BeatmapID, apiScore.RulesetID, legacyMods); } else @@ -121,6 +122,47 @@ DifficultyAttributes getMergedAttributes(APIBeatmap apiBeatmap) } } + /// + /// Transforms a given combination into one which is applicable to legacy scores. + /// This should only be used to match performance calculations using databased attributes. + /// + private static LegacyMods convertToLegacyMods(BeatmapInfo beatmapInfo, Ruleset ruleset, Mod[] mods) + { + var legacyMods = ruleset.ConvertToLegacyMods(mods); + + // mods that are not represented in `LegacyMods` (but we can approximate them well enough with others) + if (mods.Any(mod => mod is ModDaycore)) + legacyMods |= LegacyMods.HalfTime; + + // See: https://github.com/ppy/osu-queue-score-statistics/blob/2264bfa68e14bb16ec71a7cac2072bdcfaf565b6/osu.Server.Queues.ScoreStatisticsProcessor/Helpers/LegacyModsHelper.cs + static LegacyMods maskRelevantMods(LegacyMods mods, bool isConvertedBeatmap, int rulesetId) + { + const LegacyMods key_mods = LegacyMods.Key1 | LegacyMods.Key2 | LegacyMods.Key3 | LegacyMods.Key4 | LegacyMods.Key5 | LegacyMods.Key6 | LegacyMods.Key7 | LegacyMods.Key8 + | LegacyMods.Key9 | LegacyMods.KeyCoop; + + LegacyMods relevantMods = LegacyMods.DoubleTime | LegacyMods.HalfTime | LegacyMods.HardRock | LegacyMods.Easy; + + switch (rulesetId) + { + case 0: + if ((mods & LegacyMods.Flashlight) > 0) + relevantMods |= LegacyMods.Flashlight | LegacyMods.Hidden | LegacyMods.TouchDevice; + else + relevantMods |= LegacyMods.Flashlight | LegacyMods.TouchDevice; + break; + + case 3: + if (isConvertedBeatmap) + relevantMods |= key_mods; + break; + } + + return mods & relevantMods; + } + + return maskRelevantMods(legacyMods, ruleset.RulesetInfo.OnlineID != beatmapInfo.Ruleset.OnlineID, ruleset.RulesetInfo.OnlineID); + } + [JsonObject(MemberSerialization.OptIn)] private class AttributesResponse where T : DifficultyAttributes