From 81fee02c2bc90553093304cfc938abd883faad45 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Oct 2021 15:46:15 +0900 Subject: [PATCH 1/3] Fix slider paths being extended even when the last two points are equal --- osu.Game/Rulesets/Objects/SliderPath.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/osu.Game/Rulesets/Objects/SliderPath.cs b/osu.Game/Rulesets/Objects/SliderPath.cs index 9cc215589b..0dec0655b9 100644 --- a/osu.Game/Rulesets/Objects/SliderPath.cs +++ b/osu.Game/Rulesets/Objects/SliderPath.cs @@ -280,6 +280,13 @@ namespace osu.Game.Rulesets.Objects if (ExpectedDistance.Value is double expectedDistance && calculatedLength != expectedDistance) { + // In osu-stable, if the last two control points of a slider are equal, extension is not performed. + if (ControlPoints.Count >= 2 && ControlPoints[^1].Position == ControlPoints[^2].Position && expectedDistance > calculatedLength) + { + cumulativeLength.Add(calculatedLength); + return; + } + // The last length is always incorrect cumulativeLength.RemoveAt(cumulativeLength.Count - 1); From e92def0ba28ef701f576d83e1cf8cd32ee34319f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Oct 2021 17:19:29 +0900 Subject: [PATCH 2/3] Fix `LegacyBeatmapEncoder` using incorrect path length value --- osu.Game/Beatmaps/Formats/LegacyBeatmapEncoder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/Formats/LegacyBeatmapEncoder.cs b/osu.Game/Beatmaps/Formats/LegacyBeatmapEncoder.cs index 1dc270ee63..7cd4244cd0 100644 --- a/osu.Game/Beatmaps/Formats/LegacyBeatmapEncoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyBeatmapEncoder.cs @@ -460,7 +460,7 @@ namespace osu.Game.Beatmaps.Formats var curveData = pathData as IHasPathWithRepeats; writer.Write(FormattableString.Invariant($"{(curveData?.RepeatCount ?? 0) + 1},")); - writer.Write(FormattableString.Invariant($"{pathData.Path.Distance},")); + writer.Write(FormattableString.Invariant($"{pathData.Path.ExpectedDistance.Value ?? pathData.Path.Distance},")); if (curveData != null) { From aa0762ebe20a1153dfdbadc50f517ac5642ac995 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Oct 2021 17:35:03 +0900 Subject: [PATCH 3/3] Add test coverage for failing slider case --- .../Formats/LegacyBeatmapDecoderTest.cs | 17 +++++++++++++++++ .../duplicate-last-position-slider.osu | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 osu.Game.Tests/Resources/duplicate-last-position-slider.osu diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs index cb12d03620..d37e09aa29 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs @@ -775,5 +775,22 @@ namespace osu.Game.Tests.Beatmaps.Formats Assert.That(seventh.ControlPoints[4].Type == null); } } + + [Test] + public void TestSliderLengthExtensionEdgeCase() + { + var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false }; + + using (var resStream = TestResources.OpenResource("duplicate-last-position-slider.osu")) + using (var stream = new LineBufferedReader(resStream)) + { + var decoded = decoder.Decode(stream); + + var path = ((IHasPath)decoded.HitObjects[0]).Path; + + Assert.That(path.ExpectedDistance.Value, Is.EqualTo(2)); + Assert.That(path.Distance, Is.EqualTo(1)); + } + } } } diff --git a/osu.Game.Tests/Resources/duplicate-last-position-slider.osu b/osu.Game.Tests/Resources/duplicate-last-position-slider.osu new file mode 100644 index 0000000000..782dd4263e --- /dev/null +++ b/osu.Game.Tests/Resources/duplicate-last-position-slider.osu @@ -0,0 +1,19 @@ +osu file format v14 + +[Difficulty] +HPDrainRate:7 +CircleSize:10 +OverallDifficulty:9 +ApproachRate:10 +SliderMultiplier:0.4 +SliderTickRate:1 + +[TimingPoints] +382,923.076923076923,3,2,1,75,1,0 +382,-1000,3,2,1,75,0,0 + +[HitObjects] + +// Importantly, the last position is specified twice. +// In this case, osu-stable doesn't extend the slider length even when the "expected" length is higher than the actual. +261,171,25305,6,0,B|262:171|262:171|262:171,1,2,8|0,0:0|0:0,0:0:0:0: