mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 09:27:29 +08:00
Merge pull request #26579 from bdach/accuracy-rank-lazer-score-reimport
Fix incorrect accuracy and rank population when decoding lazer replays
This commit is contained in:
commit
0ddd89a5b8
@ -3,14 +3,18 @@
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
using osu.Game.Beatmaps.Legacy;
|
||||
using osu.Game.IO.Legacy;
|
||||
using osu.Game.Replays;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Catch;
|
||||
@ -247,6 +251,123 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AccuracyAndRankOfStableScorePreserved()
|
||||
{
|
||||
var memoryStream = new MemoryStream();
|
||||
|
||||
// local partial implementation of legacy score encoder
|
||||
// this is done half for readability, half because `LegacyScoreEncoder` forces `LATEST_VERSION`
|
||||
// and we want to emulate a stable score here
|
||||
using (var sw = new SerializationWriter(memoryStream, true))
|
||||
{
|
||||
sw.Write((byte)0); // ruleset id (osu!)
|
||||
sw.Write(20240116); // version (anything below `LegacyScoreEncoder.FIRST_LAZER_VERSION` is stable)
|
||||
sw.Write(string.Empty.ComputeMD5Hash()); // beatmap hash, irrelevant to this test
|
||||
sw.Write("username"); // irrelevant to this test
|
||||
sw.Write(string.Empty.ComputeMD5Hash()); // score hash, irrelevant to this test
|
||||
sw.Write((ushort)198); // count300
|
||||
sw.Write((ushort)1); // count100
|
||||
sw.Write((ushort)0); // count50
|
||||
sw.Write((ushort)0); // countGeki
|
||||
sw.Write((ushort)0); // countKatu
|
||||
sw.Write((ushort)1); // countMiss
|
||||
sw.Write(12345678); // total score, irrelevant to this test
|
||||
sw.Write((ushort)1000); // max combo, irrelevant to this test
|
||||
sw.Write(false); // full combo, irrelevant to this test
|
||||
sw.Write((int)LegacyMods.Hidden); // mods
|
||||
sw.Write(string.Empty); // hp graph, irrelevant
|
||||
sw.Write(DateTime.Now); // date, irrelevant
|
||||
sw.Write(Array.Empty<byte>()); // replay data, irrelevant
|
||||
sw.Write((long)1234); // legacy online ID, irrelevant
|
||||
}
|
||||
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
var decoded = new TestLegacyScoreDecoder().Parse(memoryStream);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(decoded.ScoreInfo.Accuracy, Is.EqualTo((double)(198 * 300 + 100) / (200 * 300)));
|
||||
Assert.That(decoded.ScoreInfo.Rank, Is.EqualTo(ScoreRank.A));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AccuracyAndRankOfLazerScorePreserved()
|
||||
{
|
||||
var ruleset = new OsuRuleset().RulesetInfo;
|
||||
|
||||
var scoreInfo = TestResources.CreateTestScoreInfo(ruleset);
|
||||
scoreInfo.Mods = new Mod[] { new OsuModFlashlight() };
|
||||
scoreInfo.Statistics = new Dictionary<HitResult, int>
|
||||
{
|
||||
[HitResult.Great] = 199,
|
||||
[HitResult.Miss] = 1,
|
||||
[HitResult.LargeTickHit] = 1,
|
||||
};
|
||||
scoreInfo.MaximumStatistics = new Dictionary<HitResult, int>
|
||||
{
|
||||
[HitResult.Great] = 200,
|
||||
[HitResult.LargeTickHit] = 1,
|
||||
};
|
||||
|
||||
var beatmap = new TestBeatmap(ruleset);
|
||||
var score = new Score
|
||||
{
|
||||
ScoreInfo = scoreInfo,
|
||||
};
|
||||
|
||||
var decodedAfterEncode = encodeThenDecode(LegacyBeatmapDecoder.LATEST_VERSION, score, beatmap);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(decodedAfterEncode.ScoreInfo.Accuracy, Is.EqualTo((double)(199 * 300 + 30) / (200 * 300 + 30)));
|
||||
Assert.That(decodedAfterEncode.ScoreInfo.Rank, Is.EqualTo(ScoreRank.SH));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AccuracyAndRankOfLazerScoreWithoutLegacyReplaySoloScoreInfoUsesBestEffortFallbackToLegacy()
|
||||
{
|
||||
var memoryStream = new MemoryStream();
|
||||
|
||||
// local partial implementation of legacy score encoder
|
||||
// this is done half for readability, half because we want to emulate an old lazer score here
|
||||
// that does not have everything that `LegacyScoreEncoder` now writes to the replay
|
||||
using (var sw = new SerializationWriter(memoryStream, true))
|
||||
{
|
||||
sw.Write((byte)0); // ruleset id (osu!)
|
||||
sw.Write(LegacyScoreEncoder.FIRST_LAZER_VERSION); // version
|
||||
sw.Write(string.Empty.ComputeMD5Hash()); // beatmap hash, irrelevant to this test
|
||||
sw.Write("username"); // irrelevant to this test
|
||||
sw.Write(string.Empty.ComputeMD5Hash()); // score hash, irrelevant to this test
|
||||
sw.Write((ushort)198); // count300
|
||||
sw.Write((ushort)0); // count100
|
||||
sw.Write((ushort)1); // count50
|
||||
sw.Write((ushort)0); // countGeki
|
||||
sw.Write((ushort)0); // countKatu
|
||||
sw.Write((ushort)1); // countMiss
|
||||
sw.Write(12345678); // total score, irrelevant to this test
|
||||
sw.Write((ushort)1000); // max combo, irrelevant to this test
|
||||
sw.Write(false); // full combo, irrelevant to this test
|
||||
sw.Write((int)LegacyMods.Hidden); // mods
|
||||
sw.Write(string.Empty); // hp graph, irrelevant
|
||||
sw.Write(DateTime.Now); // date, irrelevant
|
||||
sw.Write(Array.Empty<byte>()); // replay data, irrelevant
|
||||
sw.Write((long)1234); // legacy online ID, irrelevant
|
||||
// importantly, no compressed `LegacyReplaySoloScoreInfo` here
|
||||
}
|
||||
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
var decoded = new TestLegacyScoreDecoder().Parse(memoryStream);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(decoded.ScoreInfo.Accuracy, Is.EqualTo((double)(198 * 300 + 50) / (200 * 300)));
|
||||
Assert.That(decoded.ScoreInfo.Rank, Is.EqualTo(ScoreRank.A));
|
||||
});
|
||||
}
|
||||
|
||||
private static Score encodeThenDecode(int beatmapVersion, Score score, TestBeatmap beatmap)
|
||||
{
|
||||
var encodeStream = new MemoryStream();
|
||||
|
@ -11,6 +11,7 @@ using Newtonsoft.Json;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
using osu.Game.Beatmaps.Legacy;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.IO.Legacy;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Replays;
|
||||
@ -37,6 +38,7 @@ namespace osu.Game.Scoring.Legacy
|
||||
};
|
||||
|
||||
WorkingBeatmap workingBeatmap;
|
||||
byte[] compressedScoreInfo = null;
|
||||
|
||||
using (SerializationReader sr = new SerializationReader(stream))
|
||||
{
|
||||
@ -105,8 +107,6 @@ namespace osu.Game.Scoring.Legacy
|
||||
else if (version >= 20121008)
|
||||
scoreInfo.LegacyOnlineID = sr.ReadInt32();
|
||||
|
||||
byte[] compressedScoreInfo = null;
|
||||
|
||||
if (version >= 30000001)
|
||||
compressedScoreInfo = sr.ReadByteArray();
|
||||
|
||||
@ -130,7 +130,10 @@ namespace osu.Game.Scoring.Legacy
|
||||
}
|
||||
}
|
||||
|
||||
PopulateAccuracy(score.ScoreInfo);
|
||||
if (score.ScoreInfo.IsLegacyScore || compressedScoreInfo == null)
|
||||
PopulateLegacyAccuracyAndRank(score.ScoreInfo);
|
||||
else
|
||||
populateLazerAccuracyAndRank(score.ScoreInfo);
|
||||
|
||||
// before returning for database import, we must restore the database-sourced BeatmapInfo.
|
||||
// if not, the clone operation in GetPlayableBeatmap will cause a dereference and subsequent database exception.
|
||||
@ -174,7 +177,7 @@ namespace osu.Game.Scoring.Legacy
|
||||
/// Legacy use only.
|
||||
/// </remarks>
|
||||
/// <param name="score">The <see cref="ScoreInfo"/> to populate.</param>
|
||||
public static void PopulateAccuracy(ScoreInfo score)
|
||||
public static void PopulateLegacyAccuracyAndRank(ScoreInfo score)
|
||||
{
|
||||
int countMiss = score.GetCountMiss() ?? 0;
|
||||
int count50 = score.GetCount50() ?? 0;
|
||||
@ -273,6 +276,18 @@ namespace osu.Game.Scoring.Legacy
|
||||
}
|
||||
}
|
||||
|
||||
private void populateLazerAccuracyAndRank(ScoreInfo scoreInfo)
|
||||
{
|
||||
scoreInfo.Accuracy = StandardisedScoreMigrationTools.ComputeAccuracy(scoreInfo);
|
||||
|
||||
var rank = currentRuleset.CreateScoreProcessor().RankFromAccuracy(scoreInfo.Accuracy);
|
||||
|
||||
foreach (var mod in scoreInfo.Mods.OfType<IApplicableToScoreProcessor>())
|
||||
rank = mod.AdjustRank(rank, scoreInfo.Accuracy);
|
||||
|
||||
scoreInfo.Rank = rank;
|
||||
}
|
||||
|
||||
private void readLegacyReplay(Replay replay, StreamReader reader)
|
||||
{
|
||||
float lastTime = beatmapOffset;
|
||||
|
Loading…
Reference in New Issue
Block a user