mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 15:43:22 +08:00
Add backwards migration to populate ScoreV2 mod for already-imported scores
This commit is contained in:
parent
7be5e0e978
commit
9377622cd4
@ -15,17 +15,20 @@ using osu.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Development;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Extensions.EnumExtensions;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Statistics;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.Legacy;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Extensions;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.IO.Legacy;
|
||||
using osu.Game.Models;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
@ -79,8 +82,9 @@ namespace osu.Game.Database
|
||||
/// 29 2023-06-12 Run migration of old lazer scores to be best-effort in the new scoring number space. No actual realm changes.
|
||||
/// 30 2023-06-16 Run migration of old lazer scores again. This time with more correct rounding considerations.
|
||||
/// 31 2023-06-26 Add Version and LegacyTotalScore to ScoreInfo, set Version to 30000002 and copy TotalScore into LegacyTotalScore for legacy scores.
|
||||
/// 32 2023-07-09 Populate legacy scores with the ScoreV2 mod (and restore TotalScore to the legacy total for such scores) using replay files.
|
||||
/// </summary>
|
||||
private const int schema_version = 31;
|
||||
private const int schema_version = 32;
|
||||
|
||||
/// <summary>
|
||||
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking realm retrieval during blocking periods.
|
||||
@ -730,6 +734,8 @@ namespace osu.Game.Database
|
||||
Logger.Log($"Running realm migration to version {targetVersion}...");
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
|
||||
var files = new RealmFileStore(this, storage);
|
||||
|
||||
stopwatch.Start();
|
||||
|
||||
switch (targetVersion)
|
||||
@ -904,7 +910,6 @@ namespace osu.Game.Database
|
||||
|
||||
case 28:
|
||||
{
|
||||
var files = new RealmFileStore(this, storage);
|
||||
var scores = migration.NewRealm.All<ScoreInfo>();
|
||||
|
||||
foreach (var score in scores)
|
||||
@ -986,6 +991,64 @@ namespace osu.Game.Database
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 32:
|
||||
{
|
||||
foreach (var score in migration.NewRealm.All<ScoreInfo>())
|
||||
{
|
||||
if (!score.IsLegacyScore || !score.Ruleset.IsLegacyRuleset())
|
||||
continue;
|
||||
|
||||
string? replayFilename = score.Files.FirstOrDefault(f => f.Filename.EndsWith(@".osr", StringComparison.InvariantCultureIgnoreCase))?.File.GetStoragePath();
|
||||
if (replayFilename == null)
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
using (var stream = files.Store.GetStream(replayFilename))
|
||||
{
|
||||
if (stream == null)
|
||||
continue;
|
||||
|
||||
// Trimmed down logic from LegacyScoreDecoder to extract the mods bitmask.
|
||||
using (SerializationReader sr = new SerializationReader(stream))
|
||||
{
|
||||
sr.ReadByte(); // Ruleset.
|
||||
sr.ReadInt32(); // Version.
|
||||
sr.ReadString(); // Beatmap hash.
|
||||
sr.ReadString(); // Username.
|
||||
sr.ReadString(); // MD5Hash.
|
||||
sr.ReadUInt16(); // Count300.
|
||||
sr.ReadUInt16(); // Count100.
|
||||
sr.ReadUInt16(); // Count50.
|
||||
sr.ReadUInt16(); // CountGeki.
|
||||
sr.ReadUInt16(); // CountKatu.
|
||||
sr.ReadUInt16(); // CountMiss.
|
||||
|
||||
// we should have this in LegacyTotalScore already, but if we're reading through this anyways...
|
||||
int totalScore = sr.ReadInt32();
|
||||
|
||||
sr.ReadUInt16(); // Max combo.
|
||||
sr.ReadBoolean(); // Perfect.
|
||||
|
||||
var legacyMods = (LegacyMods)sr.ReadInt32();
|
||||
|
||||
if (!legacyMods.HasFlagFast(LegacyMods.ScoreV2) || score.APIMods.Any(mod => mod.Acronym == @"SV2"))
|
||||
continue;
|
||||
|
||||
score.APIMods = score.APIMods.Append(new APIMod(new ModScoreV2())).ToArray();
|
||||
score.LegacyTotalScore = score.TotalScore = totalScore;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error(e, $"Failed to read replay {replayFilename} during score migration", LoggingTarget.Database);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.Log($"Migration completed in {stopwatch.ElapsedMilliseconds}ms");
|
||||
|
Loading…
Reference in New Issue
Block a user