From 5b2af7f264cba42dbb4ad4dababb38a48eff2cf9 Mon Sep 17 00:00:00 2001 From: sw1tchbl4d3 Date: Wed, 13 Sep 2023 12:44:00 +0200 Subject: [PATCH 1/4] Default to none bank if invalid samplebank is specified --- osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs index 3dbe7b6519..339e9bb5bc 100644 --- a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs +++ b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs @@ -193,10 +193,10 @@ namespace osu.Game.Rulesets.Objects.Legacy var addBank = (LegacySampleBank)Parsing.ParseInt(split[1]); string stringBank = bank.ToString().ToLowerInvariant(); - if (stringBank == @"none") + if (stringBank == @"none" || !Enum.IsDefined(bank)) stringBank = null; string stringAddBank = addBank.ToString().ToLowerInvariant(); - if (stringAddBank == @"none") + if (stringAddBank == @"none" || !Enum.IsDefined(addBank)) stringAddBank = null; bankInfo.BankForNormal = stringBank; From 8f9cde01aae3ea874a8225c40fedacd637ec0c2e Mon Sep 17 00:00:00 2001 From: sw1tchbl4d3 Date: Wed, 13 Sep 2023 13:38:13 +0200 Subject: [PATCH 2/4] Add test --- .../Formats/LegacyBeatmapDecoderTest.cs | 27 +++++++++++++++++++ osu.Game.Tests/Resources/invalid-bank.osu | 11 ++++++++ 2 files changed, 38 insertions(+) create mode 100644 osu.Game.Tests/Resources/invalid-bank.osu diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs index 970b6aaf60..6fe9c902bb 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs @@ -621,6 +621,33 @@ namespace osu.Game.Tests.Beatmaps.Formats } } + [Test] + public void TestInvalidBankDefaultsToNone() + { + var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false }; + + using (var resStream = TestResources.OpenResource("invalid-bank.osu")) + using (var stream = new LineBufferedReader(resStream)) + { + var hitObjects = decoder.Decode(stream).HitObjects; + + Assert.AreEqual(HitSampleInfo.BANK_NORMAL, hitObjects[0].Samples[0].Bank); + Assert.AreEqual(HitSampleInfo.BANK_NORMAL, hitObjects[0].Samples[1].Bank); + + Assert.AreEqual(HitSampleInfo.BANK_NORMAL, hitObjects[1].Samples[0].Bank); + Assert.AreEqual(HitSampleInfo.BANK_SOFT, hitObjects[1].Samples[1].Bank); + + Assert.AreEqual(HitSampleInfo.BANK_SOFT, hitObjects[2].Samples[0].Bank); + Assert.AreEqual(HitSampleInfo.BANK_SOFT, hitObjects[2].Samples[1].Bank); + + Assert.AreEqual(HitSampleInfo.BANK_NORMAL, hitObjects[3].Samples[0].Bank); + Assert.AreEqual(HitSampleInfo.BANK_SOFT, hitObjects[3].Samples[1].Bank); + + Assert.AreEqual(HitSampleInfo.BANK_NORMAL, hitObjects[4].Samples[0].Bank); + Assert.AreEqual(HitSampleInfo.BANK_NORMAL, hitObjects[4].Samples[1].Bank); + } + } + [Test] public void TestFallbackDecoderForCorruptedHeader() { diff --git a/osu.Game.Tests/Resources/invalid-bank.osu b/osu.Game.Tests/Resources/invalid-bank.osu new file mode 100644 index 0000000000..fb54a61fd3 --- /dev/null +++ b/osu.Game.Tests/Resources/invalid-bank.osu @@ -0,0 +1,11 @@ +osu file format v14 + +[General] +SampleSet: Normal + +[HitObjects] +256,192,1000,1,8,0:0:0:0: +256,192,2000,1,8,1:2:0:0: +256,192,3000,1,8,2:62:0:0: +256,192,4000,1,8,41:2:0:0: +256,192,5000,1,8,41:62:0:0: From 320a9fc17169c81b082c42d16fb750b9fc7e6026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 19 Sep 2023 13:47:46 +0200 Subject: [PATCH 3/4] Replace test with better test --- .../Formats/LegacyBeatmapDecoderTest.cs | 29 +++++++++++-------- osu.Game.Tests/Resources/invalid-bank.osu | 18 ++++++++---- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs index 6fe9c902bb..1ba63f4037 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs @@ -622,7 +622,7 @@ namespace osu.Game.Tests.Beatmaps.Formats } [Test] - public void TestInvalidBankDefaultsToNone() + public void TestInvalidBankDefaultsToNormal() { var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false }; @@ -631,20 +631,25 @@ namespace osu.Game.Tests.Beatmaps.Formats { var hitObjects = decoder.Decode(stream).HitObjects; - Assert.AreEqual(HitSampleInfo.BANK_NORMAL, hitObjects[0].Samples[0].Bank); - Assert.AreEqual(HitSampleInfo.BANK_NORMAL, hitObjects[0].Samples[1].Bank); + assertObjectHasBanks(hitObjects[0], HitSampleInfo.BANK_DRUM); + assertObjectHasBanks(hitObjects[1], HitSampleInfo.BANK_NORMAL); + assertObjectHasBanks(hitObjects[2], HitSampleInfo.BANK_SOFT); + assertObjectHasBanks(hitObjects[3], HitSampleInfo.BANK_DRUM); + assertObjectHasBanks(hitObjects[4], HitSampleInfo.BANK_NORMAL); - Assert.AreEqual(HitSampleInfo.BANK_NORMAL, hitObjects[1].Samples[0].Bank); - Assert.AreEqual(HitSampleInfo.BANK_SOFT, hitObjects[1].Samples[1].Bank); + assertObjectHasBanks(hitObjects[5], HitSampleInfo.BANK_DRUM, HitSampleInfo.BANK_DRUM); + assertObjectHasBanks(hitObjects[6], HitSampleInfo.BANK_DRUM, HitSampleInfo.BANK_NORMAL); + assertObjectHasBanks(hitObjects[7], HitSampleInfo.BANK_DRUM, HitSampleInfo.BANK_SOFT); + assertObjectHasBanks(hitObjects[8], HitSampleInfo.BANK_DRUM, HitSampleInfo.BANK_DRUM); + assertObjectHasBanks(hitObjects[9], HitSampleInfo.BANK_DRUM, HitSampleInfo.BANK_NORMAL); + } - Assert.AreEqual(HitSampleInfo.BANK_SOFT, hitObjects[2].Samples[0].Bank); - Assert.AreEqual(HitSampleInfo.BANK_SOFT, hitObjects[2].Samples[1].Bank); + void assertObjectHasBanks(HitObject hitObject, string normalBank, string? additionsBank = null) + { + Assert.AreEqual(normalBank, hitObject.Samples[0].Bank); - Assert.AreEqual(HitSampleInfo.BANK_NORMAL, hitObjects[3].Samples[0].Bank); - Assert.AreEqual(HitSampleInfo.BANK_SOFT, hitObjects[3].Samples[1].Bank); - - Assert.AreEqual(HitSampleInfo.BANK_NORMAL, hitObjects[4].Samples[0].Bank); - Assert.AreEqual(HitSampleInfo.BANK_NORMAL, hitObjects[4].Samples[1].Bank); + if (additionsBank != null) + Assert.AreEqual(additionsBank, hitObject.Samples[1].Bank); } } diff --git a/osu.Game.Tests/Resources/invalid-bank.osu b/osu.Game.Tests/Resources/invalid-bank.osu index fb54a61fd3..8c554cc17f 100644 --- a/osu.Game.Tests/Resources/invalid-bank.osu +++ b/osu.Game.Tests/Resources/invalid-bank.osu @@ -3,9 +3,17 @@ osu file format v14 [General] SampleSet: Normal +[TimingPoints] +0,500,4,3,0,100,1,0 + [HitObjects] -256,192,1000,1,8,0:0:0:0: -256,192,2000,1,8,1:2:0:0: -256,192,3000,1,8,2:62:0:0: -256,192,4000,1,8,41:2:0:0: -256,192,5000,1,8,41:62:0:0: +256,192,1000,5,0,0:0:0:0: +256,192,2000,1,0,1:0:0:0: +256,192,3000,1,0,2:0:0:0: +256,192,4000,1,0,3:0:0:0: +256,192,5000,1,0,42:0:0:0: +256,192,6000,5,4,0:0:0:0: +256,192,7000,1,4,0:1:0:0: +256,192,8000,1,4,0:2:0:0: +256,192,9000,1,4,0:3:0:0: +256,192,10000,1,4,0:42:0:0: From c4a0ca326ed5e02a9219dee579cb9a01c554960b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 19 Sep 2023 13:53:49 +0200 Subject: [PATCH 4/4] Replace sample bank fix with more correct fix stable does not treat unknown enum members as `None` / `Auto`, it treats them as `Normal`: switch (sampleSet) { case SampleSet.Normal: default: sample = 0; break; case SampleSet.None: case SampleSet.Soft: sample = 1; break; case SampleSet.Drum: sample = 2; break; } (from https://github.com/peppy/osu-stable-reference/blob/1531237b63392e82c003c712faa028406073aa8f/osu!/Audio/AudioEngine.cs#L1158-L1171). --- .../Rulesets/Objects/Legacy/ConvertHitObjectParser.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs index 339e9bb5bc..d20f2d31bb 100644 --- a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs +++ b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs @@ -190,13 +190,18 @@ namespace osu.Game.Rulesets.Objects.Legacy string[] split = str.Split(':'); var bank = (LegacySampleBank)Parsing.ParseInt(split[0]); + if (!Enum.IsDefined(bank)) + bank = LegacySampleBank.Normal; + var addBank = (LegacySampleBank)Parsing.ParseInt(split[1]); + if (!Enum.IsDefined(addBank)) + addBank = LegacySampleBank.Normal; string stringBank = bank.ToString().ToLowerInvariant(); - if (stringBank == @"none" || !Enum.IsDefined(bank)) + if (stringBank == @"none") stringBank = null; string stringAddBank = addBank.ToString().ToLowerInvariant(); - if (stringAddBank == @"none" || !Enum.IsDefined(addBank)) + if (stringAddBank == @"none") stringAddBank = null; bankInfo.BankForNormal = stringBank;