mirror of
https://github.com/ppy/osu
synced 2024-12-11 17:42:28 +00:00
Split helper method for populations from replay
This commit is contained in:
parent
e12255bbe5
commit
9e4ffc8c12
@ -26,7 +26,6 @@ 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;
|
||||
@ -914,31 +913,13 @@ namespace osu.Game.Database
|
||||
|
||||
foreach (var score in scores)
|
||||
{
|
||||
string? replayFilename = score.Files.FirstOrDefault(f => f.Filename.EndsWith(@".osr", StringComparison.InvariantCultureIgnoreCase))?.File.GetStoragePath();
|
||||
if (replayFilename == null)
|
||||
continue;
|
||||
|
||||
try
|
||||
score.PopulateFromReplay(files, sr =>
|
||||
{
|
||||
using (var stream = files.Store.GetStream(replayFilename))
|
||||
{
|
||||
if (stream == null)
|
||||
continue;
|
||||
|
||||
// Trimmed down logic from LegacyScoreDecoder to extract the version from replays.
|
||||
using (SerializationReader sr = new SerializationReader(stream))
|
||||
{
|
||||
sr.ReadByte(); // Ruleset.
|
||||
int version = sr.ReadInt32();
|
||||
if (version < LegacyScoreEncoder.FIRST_LAZER_VERSION)
|
||||
score.IsLegacyScore = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error(e, $"Failed to read replay {replayFilename} during score migration", LoggingTarget.Database);
|
||||
}
|
||||
sr.ReadByte(); // Ruleset.
|
||||
int version = sr.ReadInt32();
|
||||
if (version < LegacyScoreEncoder.FIRST_LAZER_VERSION)
|
||||
score.IsLegacyScore = true;
|
||||
});
|
||||
}
|
||||
|
||||
break;
|
||||
@ -999,52 +980,34 @@ namespace osu.Game.Database
|
||||
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
|
||||
score.PopulateFromReplay(files, sr =>
|
||||
{
|
||||
using (var stream = files.Store.GetStream(replayFilename))
|
||||
{
|
||||
if (stream == null)
|
||||
continue;
|
||||
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.
|
||||
|
||||
// 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();
|
||||
|
||||
// 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.
|
||||
|
||||
sr.ReadUInt16(); // Max combo.
|
||||
sr.ReadBoolean(); // Perfect.
|
||||
var legacyMods = (LegacyMods)sr.ReadInt32();
|
||||
|
||||
var legacyMods = (LegacyMods)sr.ReadInt32();
|
||||
if (!legacyMods.HasFlagFast(LegacyMods.ScoreV2) || score.APIMods.Any(mod => mod.Acronym == @"SV2"))
|
||||
return;
|
||||
|
||||
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);
|
||||
}
|
||||
score.APIMods = score.APIMods.Append(new APIMod(new ModScoreV2())).ToArray();
|
||||
score.LegacyTotalScore = score.TotalScore = totalScore;
|
||||
});
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -5,7 +5,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Extensions;
|
||||
using osu.Game.IO.Legacy;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
using osu.Game.Rulesets.Judgements;
|
||||
@ -287,6 +290,38 @@ namespace osu.Game.Database
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to populate the <paramref name="score"/> model using data parsed from its corresponding replay file.
|
||||
/// </summary>
|
||||
/// <param name="score">The score to run population from replay for.</param>
|
||||
/// <param name="files">A <see cref="RealmFileStore"/> instance to use for fetching replay.</param>
|
||||
/// <param name="populationFunc">
|
||||
/// Delegate describing the population to execute.
|
||||
/// The delegate's argument is a <see cref="SerializationReader"/> instance which permits to read data from the replay stream.
|
||||
/// </param>
|
||||
public static void PopulateFromReplay(this ScoreInfo score, RealmFileStore files, Action<SerializationReader> populationFunc)
|
||||
{
|
||||
string? replayFilename = score.Files.FirstOrDefault(f => f.Filename.EndsWith(@".osr", StringComparison.InvariantCultureIgnoreCase))?.File.GetStoragePath();
|
||||
if (replayFilename == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
using (var stream = files.Store.GetStream(replayFilename))
|
||||
{
|
||||
if (stream == null)
|
||||
return;
|
||||
|
||||
using (SerializationReader sr = new SerializationReader(stream))
|
||||
populationFunc.Invoke(sr);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error(e, $"Failed to read replay {replayFilename} during score migration", LoggingTarget.Database);
|
||||
}
|
||||
}
|
||||
|
||||
private class FakeHit : HitObject
|
||||
{
|
||||
private readonly Judgement judgement;
|
||||
|
Loading…
Reference in New Issue
Block a user