From 88d07a1ff1112e5e0b960389cd95a68f6c002a1d Mon Sep 17 00:00:00 2001 From: Ray Koopa Date: Sat, 27 Jun 2020 16:30:49 +0200 Subject: [PATCH] Fix remaining Scheme bugs. - Implement IEquatable. - Fix RoundTimeSeconds not properly being parsed. - Uniquely throw ArgumentOutOfRangeException even for rounding properties. - Fix FallDamage not being stored properly. - Add tests for rounding properties and local scheme test files. - Implement equality operations for SchemeWeapon. --- .../Syroot.Worms.Armageddon.ProjectX.csproj | 2 +- src/library/Syroot.Worms.Armageddon/Scheme.cs | 143 ++++++++++--- .../Syroot.Worms.Armageddon/SchemeWeapon.cs | 66 ++++-- .../Syroot.Worms.Armageddon.csproj | 2 +- .../Syroot.Worms.Mgame.csproj | 2 +- .../Syroot.Worms.WorldParty.csproj | 2 +- .../Syroot.Worms.Worms2.csproj | 2 +- src/library/Syroot.Worms/Syroot.Worms.csproj | 5 +- .../LibraryTests.cs | 5 +- .../SchemeTests.cs | 5 +- .../Files/Schemes/WA/Custom/Armageddon.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Banana Joe.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Battle Race.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WA/Custom/BnG.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Bow & Arrow.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Bridge.wsc | Bin 0 -> 297 bytes .../Schemes/WA/Custom/Earthquake Tower.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Fort.wsc | Bin 0 -> 221 bytes .../Schemes/WA/Custom/Full Wormage Rubber.wsc | Bin 0 -> 297 bytes .../Schemes/WA/Custom/Holy War (Big).wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Holy War.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Kaos.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Mole Shopper.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Nanageddon.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/PX Sandbox.wsc | Bin 0 -> 297 bytes .../Schemes/WA/Custom/Pachaotic 3.6.31.0.wsc | Bin 0 -> 297 bytes .../Schemes/WA/Custom/Pachaotic 3.7.2.1.wsc | Bin 0 -> 297 bytes .../Schemes/WA/Custom/Plop Your Worm.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Prod Wars.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Professional.wsc | Bin 0 -> 297 bytes .../Schemes/WA/Custom/RescueYourself.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Roperace.wsc | Bin 0 -> 297 bytes .../Schemes/WA/Custom/Russian Roulette.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Shopper.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Supersheeper.wsc | Bin 0 -> 297 bytes .../Schemes/WA/Custom/Superspeedsheeper.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/TnTower.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Towerrace.wsc | Bin 0 -> 297 bytes .../Schemes/WA/Custom/Ultimate Wormage.wsc | Bin 0 -> 297 bytes .../Schemes/WA/Custom/Walk For Weapons.wsc | Bin 0 -> 297 bytes .../Schemes/WA/Custom/WeaponSexpress.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/WeaponXpress.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Weird Shoppa.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Windy Tower.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/Custom/Worms 2.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WA/{{01}} Beginner.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/{{02}} Intermediate.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/{{03}} Pro.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/{{04}} Tournament.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/{{05}} Classic.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WA/{{06}} Retro.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WA/{{07}} Artillery.wsc | Bin 0 -> 297 bytes .../Schemes/WA/{{08}} Sudden Sinking.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/{{09}} Strategic.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/{{10}} The Darkside.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/{{11}} Armageddon.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WA/{{12}} Blast Zone.wsc | Bin 0 -> 297 bytes .../Schemes/WA/{{13}} The Full Wormage.wsc | Bin 0 -> 297 bytes .../Files/Schemes/WWP/Armageddon.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/Artillery.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/Beginner.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/Blast Zone.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/Classic.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/Intermediate.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/Intermediate_2.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/Intermediate_3.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/Intermediate_4.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/Intermediate_5.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/Pro.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/Retro.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/Strategic.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/Sudden Sinking.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/The Darkside.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/The Full Wormage.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/Tournament.wsc | Bin 0 -> 221 bytes .../Files/Schemes/WWP/Unused_343.wsc | Bin 0 -> 221 bytes .../GeneratedMapTests.cs | 5 +- .../LandDataTests.cs | 5 +- .../SchemeTests.cs | 103 +++++++--- .../Syroot.Worms.Armageddon.Test.csproj | 31 +-- .../TeamContainerTests.cs | 5 +- src/test/Syroot.Worms.Test/ArchiveTests.cs | 5 +- src/test/Syroot.Worms.Test/Core/FileTester.cs | 192 ++++++++++-------- src/test/Syroot.Worms.Test/ImageTests.cs | 5 +- src/test/Syroot.Worms.Test/PaletteTests.cs | 2 +- .../LandDataTests.cs | 5 +- .../TeamContainerTests.cs | 5 +- .../Syroot.Worms.Worms2.Test/LandDataTests.cs | 5 +- .../SchemeOptionsTests.cs | 5 +- .../SchemeWeaponsTests.cs | 5 +- .../TeamContainerTests.cs | 5 +- src/tool/Syroot.Worms.Scratchpad/Program.cs | 29 +-- 92 files changed, 389 insertions(+), 257 deletions(-) create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Armageddon.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Banana Joe.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Battle Race.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/BnG.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Bow & Arrow.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Bridge.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Earthquake Tower.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Fort.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Full Wormage Rubber.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Holy War (Big).wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Holy War.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Kaos.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Mole Shopper.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Nanageddon.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/PX Sandbox.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Pachaotic 3.6.31.0.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Pachaotic 3.7.2.1.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Plop Your Worm.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Prod Wars.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Professional.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/RescueYourself.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Roperace.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Russian Roulette.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Shopper.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Supersheeper.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Superspeedsheeper.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/TnTower.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Towerrace.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Ultimate Wormage.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Walk For Weapons.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/WeaponSexpress.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/WeaponXpress.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Weird Shoppa.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Windy Tower.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Worms 2.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{01}} Beginner.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{02}} Intermediate.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{03}} Pro.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{04}} Tournament.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{05}} Classic.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{06}} Retro.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{07}} Artillery.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{08}} Sudden Sinking.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{09}} Strategic.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{10}} The Darkside.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{11}} Armageddon.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{12}} Blast Zone.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{13}} The Full Wormage.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Armageddon.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Artillery.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Beginner.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Blast Zone.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Classic.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Intermediate.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Intermediate_2.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Intermediate_3.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Intermediate_4.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Intermediate_5.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Pro.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Retro.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Strategic.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Sudden Sinking.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/The Darkside.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/The Full Wormage.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Tournament.wsc create mode 100644 src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Unused_343.wsc diff --git a/src/library/Syroot.Worms.Armageddon.ProjectX/Syroot.Worms.Armageddon.ProjectX.csproj b/src/library/Syroot.Worms.Armageddon.ProjectX/Syroot.Worms.Armageddon.ProjectX.csproj index 7f24235..a1eb6cf 100644 --- a/src/library/Syroot.Worms.Armageddon.ProjectX/Syroot.Worms.Armageddon.ProjectX.csproj +++ b/src/library/Syroot.Worms.Armageddon.ProjectX/Syroot.Worms.Armageddon.ProjectX.csproj @@ -5,7 +5,7 @@ .NET library for loading and modifying files of Worms Armageddon ProjectX. Fix saving files. Uniquely leave open Stream instances when saving into them. $(PackageTags);project x;worms armageddon - 3.0.1 + 3.1.1 diff --git a/src/library/Syroot.Worms.Armageddon/Scheme.cs b/src/library/Syroot.Worms.Armageddon/Scheme.cs index 80c48da..ec064bb 100644 --- a/src/library/Syroot.Worms.Armageddon/Scheme.cs +++ b/src/library/Syroot.Worms.Armageddon/Scheme.cs @@ -14,7 +14,7 @@ namespace Syroot.Worms.Armageddon /// RubberWorm settings encoded in those. /// Used by WA and WWP. S. https://worms2d.info/Game_scheme_file. /// - public class Scheme : ILoadableFile, ISaveableFile + public class Scheme : IEquatable, ILoadableFile, ISaveableFile { // ---- CONSTANTS ---------------------------------------------------------------------------------------------- @@ -28,7 +28,7 @@ namespace Syroot.Worms.Armageddon private static readonly byte[] _waterRiseRates; - private byte _fallDamage; + private int _fallDamage; private byte _waterRiseIndex; private byte _objectCount; private byte _mineDelay; @@ -147,8 +147,8 @@ namespace Syroot.Worms.Armageddon /// values lie between 0-508, at a granularity of 4. Note that changing this value rounds it down to a valid /// granularity. /// - /// Valid settings can be enumerated through . /// The value is not between 0-508. + /// Valid settings can be enumerated through . public int FallDamage { get => _fallDamage; @@ -156,7 +156,8 @@ namespace Syroot.Worms.Armageddon { if (value < 0 || value > 508) throw new ArgumentOutOfRangeException(nameof(value), "Fall damage must be between 0-508."); - _fallDamage = (byte)(value >> 2 << 2); + + _fallDamage = value >> 2 << 2; } } @@ -191,16 +192,20 @@ namespace Syroot.Worms.Armageddon /// Gets or sets the amount in pixels which the water will rise between turns after Sudden Death was triggered. /// Note that changing this value rounds it down to a valid setting. /// + /// The value is not between 0-253. /// Valid settings can be enumerated through . public byte WaterRiseRate { get => _waterRiseRates[_waterRiseIndex]; set { + if (value > 253) + throw new ArgumentOutOfRangeException(nameof(value), "Water rise rate must be between 0-253."); + int smallestDeviation = Int32.MaxValue; for (int i = 0; i < _waterRiseRates.Length; i++) { - int deviation = Math.Abs(value - _waterRiseRates[i]); + int deviation = value - _waterRiseRates[i]; if (deviation >= 0 && smallestDeviation > deviation) { smallestDeviation = deviation; @@ -247,12 +252,16 @@ namespace Syroot.Worms.Armageddon /// Gets or sets the maximum number of objects (mines or oil drums) on the map. Note that changing this value /// rounds it down to a valid setting. /// + /// The value is not between 1-250. /// Valid settings can be enumerated through . public byte ObjectCount { get => _objectCount; set { + if (value < 1 || value > 250) + throw new ArgumentOutOfRangeException(nameof(value), "Object count must be between 1-250."); + if (value > 100) _objectCount = (byte)(value - value % 10); else if (value > 30) @@ -651,10 +660,10 @@ namespace Syroot.Worms.Armageddon // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - /// - /// Loads the data from the given . - /// - /// The to load the data from. + /// + public override bool Equals(object obj) => Equals(obj as Scheme); + + /// public void Load(Stream stream) { using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true); @@ -714,20 +723,14 @@ namespace Syroot.Worms.Armageddon LoadRubberWormSettings(); } - /// - /// Loads the data from the given file. - /// - /// The name of the file to load the data from. + /// public void Load(string fileName) { using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); Load(stream); } - /// - /// Saves the data into the given . - /// - /// The to save the data to. + /// public void Save(Stream stream) => Save(stream, SchemeSaveFormat.ExtendedWithObjectCount); /// @@ -790,10 +793,7 @@ namespace Syroot.Worms.Armageddon writer.WriteStruct(weapon); } - /// - /// Saves the data in the given file. - /// - /// The name of the file to save the data in. + /// public void Save(string fileName) => Save(fileName, SchemeSaveFormat.ExtendedWithObjectCount); /// @@ -809,6 +809,101 @@ namespace Syroot.Worms.Armageddon // ---- METHODS (PRIVATE) -------------------------------------------------------------------------------------- + /// + public bool Equals(Scheme other) + => other != null + && Version == other.Version + && HotSeatDelay == other.HotSeatDelay + && RetreatTime == other.RetreatTime + && RetreatTimeRope == other.RetreatTimeRope + && ShowRoundTime == other.ShowRoundTime + && AutomaticReplays == other.AutomaticReplays + && FallDamage == other.FallDamage + && ArtilleryMode == other.ArtilleryMode + && SchemeEditor == other.SchemeEditor + && StockpilingMode == other.StockpilingMode + && WormSelectMode == other.WormSelectMode + && SuddenDeathEvent == other.SuddenDeathEvent + && WaterRiseRate == other.WaterRiseRate + && WeaponCrateProbability == other.WeaponCrateProbability + && DonorCards == other.DonorCards + && HealthCrateProbability == other.HealthCrateProbability + && HealthCrateEnergy == other.HealthCrateEnergy + && UtilityCrateProbability == other.UtilityCrateProbability + && ObjectTypes == other.ObjectTypes + && ObjectCount == other.ObjectCount + && MineDelay == other.MineDelay + && MineDelayRandom == other.MineDelayRandom + && DudMines == other.DudMines + && ManualWormPlacement == other.ManualWormPlacement + && WormEnergy == other.WormEnergy + && TurnTime == other.TurnTime + && TurnTimeInfinite == other.TurnTimeInfinite + && RoundTimeMinutes == other.RoundTimeMinutes + && RoundTimeSeconds == other.RoundTimeSeconds + && NumberOfWins == other.NumberOfWins + && Blood == other.Blood + && AquaSheep == other.AquaSheep + && SheepHeaven == other.SheepHeaven + && GodWorms == other.GodWorms + && IndestructibleLand == other.IndestructibleLand + && UpgradedGrenade == other.UpgradedGrenade + && UpgradedShotgun == other.UpgradedShotgun + && UpgradedCluster == other.UpgradedCluster + && UpgradedLongbow == other.UpgradedLongbow + && EnableTeamWeapons == other.EnableTeamWeapons + && EnableSuperWeapons == other.EnableSuperWeapons + && Weapons.SequenceEqual(other.Weapons); + + /// + public override int GetHashCode() + { + HashCode hash = new HashCode(); + hash.Add(Version); + hash.Add(HotSeatDelay); + hash.Add(RetreatTime); + hash.Add(RetreatTimeRope); + hash.Add(ShowRoundTime); + hash.Add(AutomaticReplays); + hash.Add(FallDamage); + hash.Add(ArtilleryMode); + hash.Add(SchemeEditor); + hash.Add(StockpilingMode); + hash.Add(WormSelectMode); + hash.Add(SuddenDeathEvent); + hash.Add(WaterRiseRate); + hash.Add(WeaponCrateProbability); + hash.Add(DonorCards); + hash.Add(HealthCrateProbability); + hash.Add(HealthCrateEnergy); + hash.Add(UtilityCrateProbability); + hash.Add(ObjectTypes); + hash.Add(ObjectCount); + hash.Add(MineDelay); + hash.Add(MineDelayRandom); + hash.Add(DudMines); + hash.Add(ManualWormPlacement); + hash.Add(WormEnergy); + hash.Add(TurnTime); + hash.Add(TurnTimeInfinite); + hash.Add(RoundTimeMinutes); + hash.Add(RoundTimeSeconds); + hash.Add(NumberOfWins); + hash.Add(Blood); + hash.Add(AquaSheep); + hash.Add(SheepHeaven); + hash.Add(GodWorms); + hash.Add(IndestructibleLand); + hash.Add(UpgradedGrenade); + hash.Add(UpgradedShotgun); + hash.Add(UpgradedCluster); + hash.Add(UpgradedLongbow); + hash.Add(EnableTeamWeapons); + hash.Add(EnableSuperWeapons); + hash.Add(Weapons); + return hash.ToHashCode(); + } + private int GetWeaponCount() => Version == SchemeVersion.Extended ? 64 : 45; private void LoadObjectTypesAndCount(BinaryStream reader) @@ -851,10 +946,10 @@ namespace Syroot.Worms.Armageddon private void LoadRoundTimeConfig(BinaryStream reader) { byte raw = reader.Read1Byte(); - if (raw > 0x7F) + if (raw > 127) { RoundTimeMinutes = 0; - RoundTimeSeconds = (byte)(raw - 0x7F); + RoundTimeSeconds = (byte)(256 - raw); } else { @@ -941,7 +1036,7 @@ namespace Syroot.Worms.Armageddon private void SaveTurnTimeConfig(BinaryStream writer) => writer.Write(TurnTimeInfinite ? (byte)0xFF : TurnTime); private void SaveRoundTimeConfig(BinaryStream writer) => writer.Write(RoundTimeSeconds > 0 - ? (byte)(0xFF - (RoundTimeSeconds - 1)) + ? (byte)(256 - RoundTimeSeconds) : RoundTimeMinutes); private void SaveRubberWormSettings() diff --git a/src/library/Syroot.Worms.Armageddon/SchemeWeapon.cs b/src/library/Syroot.Worms.Armageddon/SchemeWeapon.cs index abab23b..5c2e16e 100644 --- a/src/library/Syroot.Worms.Armageddon/SchemeWeapon.cs +++ b/src/library/Syroot.Worms.Armageddon/SchemeWeapon.cs @@ -1,25 +1,47 @@ -using System.Diagnostics; -using System.Runtime.InteropServices; - -namespace Syroot.Worms.Armageddon -{ - /// - /// Represents the configuration of a weapon. - /// - [DebuggerDisplay("Ammo={Ammunition} Power={Power} Delay={Delay} Prob={Probability}")] - [StructLayout(LayoutKind.Sequential)] - public struct SchemeWeapon +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace Syroot.Worms.Armageddon +{ + /// + /// Represents the configuration of a weapon. + /// + [DebuggerDisplay("Ammo={Ammunition} Power={Power} Delay={Delay} Prob={Probability}")] + [StructLayout(LayoutKind.Sequential)] + public struct SchemeWeapon : IEquatable { // ---- FIELDS ------------------------------------------------------------------------------------------------- - - /// Amount with which a team is equipped at game start. 10 and negative values represent infinity. - public sbyte Ammunition; - /// Power of this weapon. - public byte Power; + + /// Amount with which a team is equipped at game start. 10 and negative values represent infinity. + public sbyte Ammunition; + /// Power of this weapon. + public byte Power; /// Number of turns required to be taken by each team before this weapon becomes available. Negative - /// values represent infinity. - public sbyte Delay; - /// Percentual chance of this weapon to appear in crates. Has no effect for super weapons. - public sbyte Probability; - } -} + /// values represent infinity. + public sbyte Delay; + /// Percentual chance of this weapon to appear in crates. Has no effect for super weapons. + public sbyte Probability; + + // ---- OPERATORS ---------------------------------------------------------------------------------------------- + + public static bool operator ==(SchemeWeapon left, SchemeWeapon right) => left.Equals(right); + + public static bool operator !=(SchemeWeapon left, SchemeWeapon right) => !(left == right); + + // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- + + /// + public override bool Equals(object obj) => obj is SchemeWeapon weapon && Equals(weapon); + + /// + public bool Equals(SchemeWeapon other) + => Ammunition == other.Ammunition + && Power == other.Power + && Delay == other.Delay + && Probability == other.Probability; + + /// + public override int GetHashCode() => HashCode.Combine(Ammunition, Power, Delay, Probability); + } +} diff --git a/src/library/Syroot.Worms.Armageddon/Syroot.Worms.Armageddon.csproj b/src/library/Syroot.Worms.Armageddon/Syroot.Worms.Armageddon.csproj index 4f441e6..a0e1285 100644 --- a/src/library/Syroot.Worms.Armageddon/Syroot.Worms.Armageddon.csproj +++ b/src/library/Syroot.Worms.Armageddon/Syroot.Worms.Armageddon.csproj @@ -5,7 +5,7 @@ .NET library for loading and modifying files of Team17's Worms Armageddon. Simplify scheme fall damage and water rise usage. $(PackageTags);worms armageddon - 3.1.0 + 3.1.1 diff --git a/src/library/Syroot.Worms.Mgame/Syroot.Worms.Mgame.csproj b/src/library/Syroot.Worms.Mgame/Syroot.Worms.Mgame.csproj index f80068b..1f2c6e2 100644 --- a/src/library/Syroot.Worms.Mgame/Syroot.Worms.Mgame.csproj +++ b/src/library/Syroot.Worms.Mgame/Syroot.Worms.Mgame.csproj @@ -5,7 +5,7 @@ .NET library for loading and modifying files of Mgame Worms clients. Fix saving files. Uniquely leave open Stream instances when saving into them. $(PackageTags);online worms;worms world party aqua - 3.0.1 + 3.1.1 diff --git a/src/library/Syroot.Worms.WorldParty/Syroot.Worms.WorldParty.csproj b/src/library/Syroot.Worms.WorldParty/Syroot.Worms.WorldParty.csproj index a428607..ca92142 100644 --- a/src/library/Syroot.Worms.WorldParty/Syroot.Worms.WorldParty.csproj +++ b/src/library/Syroot.Worms.WorldParty/Syroot.Worms.WorldParty.csproj @@ -5,7 +5,7 @@ .NET library for loading and modifying files of Team17's Worms World Party. Fix saving files. Uniquely leave open Stream instances when saving into them. $(PackageTags);worms world party - 3.0.1 + 3.1.1 diff --git a/src/library/Syroot.Worms.Worms2/Syroot.Worms.Worms2.csproj b/src/library/Syroot.Worms.Worms2/Syroot.Worms.Worms2.csproj index 94773c8..e5e4b8f 100644 --- a/src/library/Syroot.Worms.Worms2/Syroot.Worms.Worms2.csproj +++ b/src/library/Syroot.Worms.Worms2/Syroot.Worms.Worms2.csproj @@ -5,7 +5,7 @@ .NET library for loading and modifying files of Team17's Worms 2. Fix saving files. Uniquely leave open Stream instances when saving into them. $(PackageTags);worms 2 - 3.0.1 + 3.1.1 diff --git a/src/library/Syroot.Worms/Syroot.Worms.csproj b/src/library/Syroot.Worms/Syroot.Worms.csproj index 7846c5f..c349022 100644 --- a/src/library/Syroot.Worms/Syroot.Worms.csproj +++ b/src/library/Syroot.Worms/Syroot.Worms.csproj @@ -5,7 +5,7 @@ Syroot.Worms .NET library for loading and modifying files of Team17 Worms games. Fix saving files. Uniquely leave open Stream instances when saving into them. - 3.0.1 + 3.1.1 @@ -13,4 +13,7 @@ + + + \ No newline at end of file diff --git a/src/test/Syroot.Worms.Armageddon.ProjectX.Test/LibraryTests.cs b/src/test/Syroot.Worms.Armageddon.ProjectX.Test/LibraryTests.cs index 1b277b0..ff2662f 100644 --- a/src/test/Syroot.Worms.Armageddon.ProjectX.Test/LibraryTests.cs +++ b/src/test/Syroot.Worms.Armageddon.ProjectX.Test/LibraryTests.cs @@ -16,9 +16,6 @@ namespace Syroot.Worms.Test.Armageddon.ProjectX /// Loads all files found in any game directories. /// [TestMethod] - public void LoadLibraries() - { - FileTester.LoadFiles(Game.Armageddon, "*.pxl"); - } + public void LoadLibraries() => FileTester.Run(Game.Armageddon, "*.pxl"); } } diff --git a/src/test/Syroot.Worms.Armageddon.ProjectX.Test/SchemeTests.cs b/src/test/Syroot.Worms.Armageddon.ProjectX.Test/SchemeTests.cs index d7a7ed9..c889aaa 100644 --- a/src/test/Syroot.Worms.Armageddon.ProjectX.Test/SchemeTests.cs +++ b/src/test/Syroot.Worms.Armageddon.ProjectX.Test/SchemeTests.cs @@ -16,9 +16,6 @@ namespace Syroot.Worms.Test.Armageddon.ProjectX /// Loads all files found in any game directories. /// [TestMethod] - public void LoadSchemes() - { - FileTester.LoadFiles(Game.Armageddon, "*.pxs"); - } + public void LoadSchemes() => FileTester.Run(Game.Armageddon, "*.pxs"); } } diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Armageddon.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Armageddon.wsc new file mode 100644 index 0000000000000000000000000000000000000000..078c30c75edc1698d89ec52eaeb3a690170f541b GIT binary patch literal 297 zcmWG`_V8t5Wo2b#U}OLSX666}qhCf0%!~}bZ1^E!AaNjIq6~9E^)oUtFvHj!Obo0b k%*w>T!py|Lgk%LHvGxJ=GK1YmfMCTVk53MyjSFZ601ej!>i_@% literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Banana Joe.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Banana Joe.wsc new file mode 100644 index 0000000000000000000000000000000000000000..f95aa771cd76f2a1dd683a6176f19276ef50bcf4 GIT binary patch literal 297 zcmWG`_V8t5Wnf@rWB?Kj%uFc^Mn*seBf|++MzA1I94y5IBynIaCI(hqa!BHgFg8#< jcC#3O<^TaR$SJtgU=xQL2hxiS7=gxt{6z?Wj3fjAbkPG$ literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Battle Race.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Battle Race.wsc new file mode 100644 index 0000000000000000000000000000000000000000..2da7553b99d72e6bf194ac1ff33bf8c1193078f0 GIT binary patch literal 221 zcmWG`_V8uoVrF1qU<6@i1{($jNf6DLA}PlR6a!%}U;>g%Kn{>*Vgiz2K1d9Kjeu+r kMiv9HLF$p^u&Dv-0cwQg%!E7bZrDZ89 xjw)|*MWFLkNRQ^({qQ6TA2gaNJ@tXAT}~$_{zY@a6&?d2_yuP0AUb^1k6Q(T9~=y=)tC!5$tfF Hd#MNjS6c)o literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Bridge.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Bridge.wsc new file mode 100644 index 0000000000000000000000000000000000000000..d3d6d5bdcd420f0745437a08a3d16a9dd22142c3 GIT binary patch literal 297 zcmaJ+NeX~444fp!Lwtc3KjX!VAow2tZl+LZRU8-+W+~~pZo9g>Kmds8ftYiHT+1ZX zh@4?L^`BAwA@k07mXv(;yw%L%!OlAe9#+2m)WDky>D1kD E11dZNJOBUy literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Earthquake Tower.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Earthquake Tower.wsc new file mode 100644 index 0000000000000000000000000000000000000000..8e91b876fc4b35c08a7ff7552bde3ca220af4917 GIT binary patch literal 297 zcmWG`_V8um;^JZe14d>D{hfh rF%-32EDQ`>P<>DuWG1pc5FZ;xw+q4tIsxh{APWM}`Gmw_@*o-j3h@LC literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Fort.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Fort.wsc new file mode 100644 index 0000000000000000000000000000000000000000..b865aa939bbee79fa595f15ecdd098ee07acc5ed GIT binary patch literal 221 zcmY*S$qj%o40F;NRULv2n1T-|AC`E+(QC})R4!t&^`vRI1R1Gv~yF9l)c8|lHKdJQ36Db-%{x2IFW}qMxFfuSPu;RoFc;xWuLzaV@!3A;+ hvN*YHn9EUV0U(zjNhk%#=0f7LgVDY5A+O>eC3*z`)YU1 S?ODB}bYw5b=q+x#{XGHj<^&r6 literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Nanageddon.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Nanageddon.wsc new file mode 100644 index 0000000000000000000000000000000000000000..d3fa4040f20efa7537eabb3921b747f3664adda4 GIT binary patch literal 297 zcmWG`_V8umVr69jf=&iTW@`|G;R_I_=rS;Z0GMQ85D>0%`->4H5gt1+jwzs4fLrEgCx? JnUAEO5di)149frj literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/PX Sandbox.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/PX Sandbox.wsc new file mode 100644 index 0000000000000000000000000000000000000000..a9ece1e23480c16e58b338e91242c661adff28c8 GIT binary patch literal 297 zcmWG`_V8umVr69j14d?MFwFxbQ*5{x85tOW2m~0pm>3vnj)4|&!7wTI!So=}KqkU0 URQ7+k9SHFyP_YMSa*QxO02HqWMF0Q* literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Pachaotic 3.6.31.0.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Pachaotic 3.6.31.0.wsc new file mode 100644 index 0000000000000000000000000000000000000000..dd732f817c2d19f43e47bd27a3f165eac2c49782 GIT binary patch literal 297 zcmWG`_V8umVr6AyU|{HEU}OZ*3=Cg@I3raEDRh#vHwWoFf~h{;_sny IjA&{Y0X8fUkpKVy literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Pachaotic 3.7.2.1.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Pachaotic 3.7.2.1.wsc new file mode 100644 index 0000000000000000000000000000000000000000..7297fd900ae9fe3f9cad6dd128088401a7d59ffc GIT binary patch literal 297 zcmZ{fJq~~{2!$VpF2uNa3eVx<;^gM+Wjw8mvlR>^^{>eb<&p1|PW>=ek`e(}L1Y!! zRm&{e`TO3CLoCmgOuTtLx{7&)Nmoh l;AVovxWHC{31ZBH>jfDHbthOe%p67rR)mRoSRnm`002Su11JCh literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Professional.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Professional.wsc new file mode 100644 index 0000000000000000000000000000000000000000..c09bea012c74953c83bedc8557de335abc5d4d4f GIT binary patch literal 297 zcmWG`_V8t5Wo2e$WMp7qWMF3IVqlPD@MK_MNYUj2i9rD)7ZZ>L!K_?N%pf)^ln)c9 SoQBy3q7n8HW+UsP5gP#Hv;w#Q literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/RescueYourself.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/RescueYourself.wsc new file mode 100644 index 0000000000000000000000000000000000000000..008b06a056ee11f24c35f7e1545508deac115be9 GIT binary patch literal 297 zcmZurK@NZ*3@cM&;1PbrqZcop{DPnH!QO2NAQ+d7c3rn|tlMtUdpL&+umy@64(BZG z4I?!Q3B{Fsy1M8EJ^NGgMEaESwe=M{uJSg`I9p=aoXruggW HhN8g-X&MAv literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Roperace.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Roperace.wsc new file mode 100644 index 0000000000000000000000000000000000000000..e2fa163d75a690288056787b7af3f00ed7f062c0 GIT binary patch literal 297 zcmb_Vu?>JQ40DoBxrQHDSeST$BlsR{wUMaANF>*Z9jC{-?Vgzi17N|2wQxM|%Zw~X to~(cqHduYv3~luCYWL0Yp-;QnfOKXH!JGO)_oVe%+KlomSIo$t^#CzA1RnqZ literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Russian Roulette.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Russian Roulette.wsc new file mode 100644 index 0000000000000000000000000000000000000000..6387a492b536af50ffbaf52fb18e09d16b45daa6 GIT binary patch literal 297 zcmWG`_V8umXJBAtU}R)qU|<4bAkY8`IC61;g&-n~ASo^uAP1ymATX(RL)=X@5&%O< B0x19h literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Shopper.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Shopper.wsc new file mode 100644 index 0000000000000000000000000000000000000000..373bca2335dd93917dc16af6688d15733b879801 GIT binary patch literal 297 zcmWG`_V8umV&`IHU}OLSX2ui{WeDU(+8u0TBr#CdOZVf literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Supersheeper.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Supersheeper.wsc new file mode 100644 index 0000000000000000000000000000000000000000..e237fbc892a5cf1a47819fd35bb27cfc0ae54c10 GIT binary patch literal 297 zcmWG`_V8t500Krv#!dzXX66(IBO?YzpujW{IYtl-10YpQKmjlfV$%Ra?P3AZ5c65_ P*~7)e0Fj64qa_6Z?$`sg literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Superspeedsheeper.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Superspeedsheeper.wsc new file mode 100644 index 0000000000000000000000000000000000000000..ffd98731f8979277ea07cc943706731a583893dd GIT binary patch literal 297 zcmWG`_V8t500Krv#!dzXX66(IqZEd(K!Itja*T`&j37BM0I6aEa=|o+O#=+Jh=G9x UL_^GH#b*x}69YsZs*jcw032fk%m4rY literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/TnTower.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/TnTower.wsc new file mode 100644 index 0000000000000000000000000000000000000000..6db49d033b5c1f394fbd120640a6268b056756bf GIT binary patch literal 297 ycmWG`_V8umVt@ihW(dQ8k%2Kqw}O$8fdPcUfC)&_5Oc90%;%zpJrGw@jRXJ%Is)kc literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Towerrace.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Towerrace.wsc new file mode 100644 index 0000000000000000000000000000000000000000..8bb80a52005cb9e7afbcd03ea1638e88eb11f878 GIT binary patch literal 297 zcmWG`_V8um;^JZe14d>DZNSLDm||1G$jHC|!eGDzB$>dF5lVx2U@=xneg4gy&Z4kZi#ja~!3 literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/WeaponSexpress.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/WeaponSexpress.wsc new file mode 100644 index 0000000000000000000000000000000000000000..dce2d07d2f90300c91c7ee802b6f88040f8fc29d GIT binary patch literal 297 zcmZ`zI|_hM3`^xbkPa>$$;HLVD|i|2;r(3PYb!0(--D36q$!<;aca0$0KWuGvySD@ZuH!T^}`EJ9VE^D$38tb_fZ6V_vE^ GXgUGnkr6Wh literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/WeaponXpress.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/WeaponXpress.wsc new file mode 100644 index 0000000000000000000000000000000000000000..baa94342602f7dc93a3f1f84d837ea2c17cb7b68 GIT binary patch literal 297 zcmZusu?>JQ40BLfGQhwCyn(BMDu0T`_b8vpDZNSLDm||1G$jHC|!eGDzB$>dF5lVx2U@Y^rQmWFyAu(0Adyc$^ZZW literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Worms 2.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/Custom/Worms 2.wsc new file mode 100644 index 0000000000000000000000000000000000000000..2c8c14822044add697814f5da22553297f52fc4f GIT binary patch literal 221 zcmWG`_V8t7WoBhyWMlvWCMF;u$-v6Y$dF>g1rmV*MlO&H6oc3>J|mFL$ixblgQ+2h W1{n_mU>ZbV!Hi6tnBrhvm;?al2m*)z literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{01}} Beginner.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{01}} Beginner.wsc new file mode 100644 index 0000000000000000000000000000000000000000..84e74406ed63e064c14ac7ac328505a314453cb1 GIT binary patch literal 297 zcmb`BAr8Y(3`1k5AN1pocZlJ#l9Hm{ZRg#~s)Ch_ERki&v8^2Iw!60`MTC@ks6PiB zuVonR9H}RFhdbg0*-kVzKN_CmQeca#+;Dy8%0rhLd|{sO5G_nJaL+kZuL1Lyz% literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{02}} Intermediate.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{02}} Intermediate.wsc new file mode 100644 index 0000000000000000000000000000000000000000..f4e961a61e13b81c1ff878811e21e3c56493730a GIT binary patch literal 297 zcmbVIu?>JQ42xYwNL^T1ID#u!SeST$|8F1;1u-B7(zvMBd9#Gd1md`%d|xXYXr2DK L%FCx5$AdorEoK8U literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{03}} Pro.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{03}} Pro.wsc new file mode 100644 index 0000000000000000000000000000000000000000..163a7fa017540305c1c7d6e708ed02580668cd18 GIT binary patch literal 297 zcma)1y9$6n3`<&y(AmYspK)<<@)!L7Z?HYChd79ZlH}6Yo!fqhseuFplo`Ib0lZch zR1hgBLJM>Sv}*}YYV)(EHRYi6X(Xq{%VV!e%o!sYJ+ZDb1oNQW2?_O;b!K3EW5kn> J$Dicgdjk#-0}ucJ literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{04}} Tournament.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{04}} Tournament.wsc new file mode 100644 index 0000000000000000000000000000000000000000..44d9ac4fe2af143b9691d5b7f38b4f0c7a5bdee9 GIT binary patch literal 297 zcmb79u?>JQ42zR?>CD2yGb}7jyuklAU{eJl1Ot}bq_N|w+q|q^qZ(l5h8V1ktrlRP znp*;<3lOL@wV;s|?r`>6l%C|AkRGRoo6f#xai)x9fl0ck9p(1QlTUq7#st6d8}YL7 G%sBuVi31=2 literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{05}} Classic.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{05}} Classic.wsc new file mode 100644 index 0000000000000000000000000000000000000000..661afc656246bd50af4a8ea419b84641179212b4 GIT binary patch literal 221 zcmZvWF%E!G2t(T<%U@hvyo;NQi<4LI{$~*Wm&HiZ6ds}B+K-d&4iW&R1#Jb5xVKq> z-eQYEqIr1s>FBJxB`YOQQ6|bILA5K-eP-B@e2VyS)?+DHDj=bFE|NYf7FYlE06pLX AH2?qr literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{06}} Retro.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{06}} Retro.wsc new file mode 100644 index 0000000000000000000000000000000000000000..b19394bfd81c8e17cdb705a8acf5b78e239d4250 GIT binary patch literal 221 zcmZurF%p0<2n+PObaD1CZZ0lPe!>60!6ekJy$b|FpwD^T(E$VjBnGg%c#kdJt1wt( uqHzS`J;^jsFjrr&!W>Blv*NE!-9GL>D}?vas=vq*b<6kW4GT+7&+2^$a01i- literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{07}} Artillery.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{07}} Artillery.wsc new file mode 100644 index 0000000000000000000000000000000000000000..9786eb9dede465924f3e29a316c679c60d564e41 GIT binary patch literal 297 zcma(~xeJQ42#{u(3yo_*jQMYc!B?Kz)1_LKq8fuIB}i!Sht-e4F;GZak4TOX4ttH zy;TE6gai@|gWwqr62{y$4sq6bmSzNB^Xg^D>buVGho^}PvUt3Ghx`4VFt}gZ<@i$L Necef-)Xq=5^%pMQ12zBv literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{09}} Strategic.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{09}} Strategic.wsc new file mode 100644 index 0000000000000000000000000000000000000000..1a468e02da16f294f41a9101c05094b559892bb5 GIT binary patch literal 297 zcmaKmF%E?=3`1jA9q7XH=YNPlv$3!+aRu&w2JC(!A%sX}CFzT!Z1b|Rl?ot&L444D z-&z9uG%_*}%?*LdfNB(pBxLF`PkE7fGOA97bIyE_ywBMZLOG?T`|b6<*Qe8Teviy< OuJxZj|J8(-eD@xAVgr2u literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{10}} The Darkside.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{10}} The Darkside.wsc new file mode 100644 index 0000000000000000000000000000000000000000..95d30e97ec1cdc9e6fd1acb8401e112a05060ef7 GIT binary patch literal 297 zcmaJ+F%p0<2qV;>$Am%s6w{7XS6<{j@S LK|sbwN`Dd;Q2hg2 literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{11}} Armageddon.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WA/{{11}} Armageddon.wsc new file mode 100644 index 0000000000000000000000000000000000000000..599f0ace52fe013473c2f49f37895baca4f706a0 GIT binary patch literal 297 zcmb79F%rWt3<4Z2p0i}hXS!tR)W7w;0q2~dm!un1W<>V~aLnO>NZWiN%0sZL+oDkv=27Dq97XGSh01{nYV literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Armageddon.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Armageddon.wsc new file mode 100644 index 0000000000000000000000000000000000000000..783515256f796a19379ab61067c0029a0b85ed13 GIT binary patch literal 221 zcmZ8bF%HBq3<6RwnY(nk&)m|bQ~%cY79u6mT`YtHHp%@xFIE*uK%{o|qt^yJ9|-HP z`$AD=P9LTqnLXH|O;}SKzPzy+(DWu-8yT51lB;r5U@1E-NPhDEE1C2w!&~3{ZC+Dl B16lw8 literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Artillery.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Artillery.wsc new file mode 100644 index 0000000000000000000000000000000000000000..710e604a3d3219cb7c944e51867f0e50e718a080 GIT binary patch literal 221 zcmZuqu?>JQ42x4`>B7>PBY1&@g^3sV|AyKT1qq01*>URRShpQf!T<n8wjYRE0W$*}Gh%6CyVgc& y{Q=?fX$*-2AnDRH{%Fc1ry?fgf>o(^FEhG@Djt}MGO8wuF39&pc7LaT^0RNVc?07B literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Blast Zone.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Blast Zone.wsc new file mode 100644 index 0000000000000000000000000000000000000000..6b9cd94ba79ba69e44107d56fb27299dcab819bc GIT binary patch literal 221 zcmZ9Gu@QhU3w!i5|1``N_Y( Dtm*^K literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Classic.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Classic.wsc new file mode 100644 index 0000000000000000000000000000000000000000..661afc656246bd50af4a8ea419b84641179212b4 GIT binary patch literal 221 zcmZvWF%E!G2t(T<%U@hvyo;NQi<4LI{$~*Wm&HiZ6ds}B+K-d&4iW&R1#Jb5xVKq> z-eQYEqIr1s>FBJxB`YOQQ6|bILA5K-eP-B@e2VyS)?+DHDj=bFE|NYf7FYlE06pLX AH2?qr literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Intermediate.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Intermediate.wsc new file mode 100644 index 0000000000000000000000000000000000000000..f66758c9d9ca9ec4126a55a9b934a2086817fc9c GIT binary patch literal 221 zcmaKmu@QhU3p-pvPx&S%? B11SIi literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Intermediate_2.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Intermediate_2.wsc new file mode 100644 index 0000000000000000000000000000000000000000..ea54492798a4262eb819d06783a75cd51cf852e5 GIT binary patch literal 221 zcmWG`_V8uoVrOM!WMp7qU}OdoAex1dAw^dXBm@PF3`{^4Eiud{7)^>@Fg<8A0K!!Q AM*si- literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Intermediate_3.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Intermediate_3.wsc new file mode 100644 index 0000000000000000000000000000000000000000..ea54492798a4262eb819d06783a75cd51cf852e5 GIT binary patch literal 221 zcmWG`_V8uoVrOM!WMp7qU}OdoAex1dAw^dXBm@PF3`{^4Eiud{7)^>@Fg<8A0K!!Q AM*si- literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Intermediate_4.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Intermediate_4.wsc new file mode 100644 index 0000000000000000000000000000000000000000..6a10b208b422243bf509c41ce3c7665c5e2e41a2 GIT binary patch literal 221 zcmZ8bF%HBq3<8`inY-L_pSh(=r+%UTe?y@sFO7sC*dU+3{UEA90s{5r`m8y?Ygp4Avi?u~n}dI4YXeRI literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Pro.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Pro.wsc new file mode 100644 index 0000000000000000000000000000000000000000..63030abe6625edd622873a17fcf9289836418c0e GIT binary patch literal 221 zcmaKmF%E!G2t)fI#N^K|E?&mP#mOsp|1$_beg_9hn$na4=e8e&hd?r6v)a-^;#!+& y6e@ukk=$JJM_cyb-LIJ*szv1!z|{NU@yrz0ju&Jm&kdxY9;%zNRDT$6e)t9?m;(#| literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Retro.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Retro.wsc new file mode 100644 index 0000000000000000000000000000000000000000..b19394bfd81c8e17cdb705a8acf5b78e239d4250 GIT binary patch literal 221 zcmZurF%p0<2n+PObaD1CZZ0lPe!>60!6ekJy$b|FpwD^T(E$VjBnGg%c#kdJt1wt( uqHzS`J;^jsFjrr&!W>Blv*NE!-9GL>D}?vas=vq*b<6kW4GT+7&+2^$a01i- literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Strategic.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Strategic.wsc new file mode 100644 index 0000000000000000000000000000000000000000..305d231cbb99d094c39b79c1f5bd835010a829f5 GIT binary patch literal 221 zcmaKmArgQv3$p60!QusDOeE=*qfj{3ZD)9Z1Pt^EeeTi7bLoZ( xB0r=v)YM&#Vw%yE=V0mu)fK7xt?{KRA6}}ZN1+iZJ;<5#9jsTYeo<$B_yQ}10~Y`Q literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Unused_343.wsc b/src/test/Syroot.Worms.Armageddon.Test/Files/Schemes/WWP/Unused_343.wsc new file mode 100644 index 0000000000000000000000000000000000000000..9346cb9ccf82792c7e3a022fb62210b9e7b0709c GIT binary patch literal 221 zcmZupI|_hM3`_EO2yb?A@g#08E>2#-`=7zI`VhgEK%3vOZaZtKAQ7XPZ5k`db7?n~ zJemNCsDk1yLZL(ogb`eae_6NRMH*~-HT%@) literal 0 HcmV?d00001 diff --git a/src/test/Syroot.Worms.Armageddon.Test/GeneratedMapTests.cs b/src/test/Syroot.Worms.Armageddon.Test/GeneratedMapTests.cs index 265ec33..e9ca419 100644 --- a/src/test/Syroot.Worms.Armageddon.Test/GeneratedMapTests.cs +++ b/src/test/Syroot.Worms.Armageddon.Test/GeneratedMapTests.cs @@ -16,9 +16,6 @@ namespace Syroot.Worms.Test.Armageddon /// Loads all files found in any game directories. /// [TestMethod] - public void LoadGeneratedMaps() - { - FileTester.LoadFiles(Game.Armageddon | Game.WorldParty, "*.lev"); - } + public void LoadGeneratedMaps() => FileTester.Run(Game.Armageddon | Game.WorldParty, "*.lev"); } } diff --git a/src/test/Syroot.Worms.Armageddon.Test/LandDataTests.cs b/src/test/Syroot.Worms.Armageddon.Test/LandDataTests.cs index 2a5648a..691b436 100644 --- a/src/test/Syroot.Worms.Armageddon.Test/LandDataTests.cs +++ b/src/test/Syroot.Worms.Armageddon.Test/LandDataTests.cs @@ -16,9 +16,6 @@ namespace Syroot.Worms.Test.Armageddon /// Loads all files found in any game directories. /// [TestMethod] - public void LoadLandData() - { - FileTester.LoadFiles(Game.Armageddon, "land.dat"); - } + public void LoadLandData() => FileTester.Run(Game.Armageddon, "land.dat"); } } diff --git a/src/test/Syroot.Worms.Armageddon.Test/SchemeTests.cs b/src/test/Syroot.Worms.Armageddon.Test/SchemeTests.cs index bac8250..6df55f8 100644 --- a/src/test/Syroot.Worms.Armageddon.Test/SchemeTests.cs +++ b/src/test/Syroot.Worms.Armageddon.Test/SchemeTests.cs @@ -1,24 +1,79 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Syroot.Worms.Armageddon; -using Syroot.Worms.Test.Core; - -namespace Syroot.Worms.Test.Armageddon -{ - /// - /// Represents a collection of tests for the class. - /// - [TestClass] - public class SchemeTests - { - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads all files found in any game directories. - /// - [TestMethod] - public void LoadSchemes() - { - FileTester.LoadFiles(Game.Armageddon | Game.WorldParty, "*.wsc"); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Syroot.Worms.Armageddon; +using Syroot.Worms.Test.Core; + +namespace Syroot.Worms.Test.Armageddon +{ + /// + /// Represents a collection of tests for the class. + /// + [TestClass] + public class SchemeTests + { + // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- + + /// + /// Loads all files found in the test directory. + /// + [TestMethod] + public void TestFiles() => FileTester.Run(Game.Test, "*.wsc"); + + /// + /// Tests rounding down to the nearest valid fall damage value. + /// + [TestMethod] + public void RoundFallDamage() + { + Scheme scheme = new Scheme(); + Assert.ThrowsException(() => scheme.FallDamage = -1); + scheme.FallDamage = 0; Assert.AreEqual(0, scheme.FallDamage); + scheme.FallDamage = 1; Assert.AreEqual(0, scheme.FallDamage); + scheme.FallDamage = 3; Assert.AreEqual(0, scheme.FallDamage); + scheme.FallDamage = 4; Assert.AreEqual(4, scheme.FallDamage); + scheme.FallDamage = 507; Assert.AreEqual(504, scheme.FallDamage); + scheme.FallDamage = 508; Assert.AreEqual(508, scheme.FallDamage); + Assert.ThrowsException(() => scheme.FallDamage = 509); + } + + /// + /// Tests rounding down to the nearest valid water rise rate value. + /// + [TestMethod] + public void RoundWaterRiseRate() + { + Scheme scheme = new Scheme(); + scheme.WaterRiseRate = 0; Assert.AreEqual(0, scheme.WaterRiseRate); + scheme.WaterRiseRate = 1; Assert.AreEqual(0, scheme.WaterRiseRate); + scheme.WaterRiseRate = 4; Assert.AreEqual(0, scheme.WaterRiseRate); + scheme.WaterRiseRate = 5; Assert.AreEqual(5, scheme.WaterRiseRate); + scheme.WaterRiseRate = 252; Assert.AreEqual(245, scheme.WaterRiseRate); + scheme.WaterRiseRate = 253; Assert.AreEqual(253, scheme.WaterRiseRate); + Assert.ThrowsException(() => scheme.WaterRiseRate = 254); + } + + /// + /// Tests rounding down to the nearest valid fall damage value. + /// + [TestMethod] + public void RoundObjectCount() + { + Scheme scheme = new Scheme(); + Assert.ThrowsException(() => scheme.ObjectCount = 0); + scheme.ObjectCount = 1; Assert.AreEqual(1, scheme.ObjectCount); + scheme.ObjectCount = 2; Assert.AreEqual(2, scheme.ObjectCount); + scheme.ObjectCount = 30; Assert.AreEqual(30, scheme.ObjectCount); + scheme.ObjectCount = 31; Assert.AreEqual(30, scheme.ObjectCount); + scheme.ObjectCount = 34; Assert.AreEqual(30, scheme.ObjectCount); + scheme.ObjectCount = 35; Assert.AreEqual(35, scheme.ObjectCount); + scheme.ObjectCount = 99; Assert.AreEqual(95, scheme.ObjectCount); + scheme.ObjectCount = 100; Assert.AreEqual(100, scheme.ObjectCount); + scheme.ObjectCount = 101; Assert.AreEqual(100, scheme.ObjectCount); + scheme.ObjectCount = 109; Assert.AreEqual(100, scheme.ObjectCount); + scheme.ObjectCount = 110; Assert.AreEqual(110, scheme.ObjectCount); + scheme.ObjectCount = 249; Assert.AreEqual(240, scheme.ObjectCount); + scheme.ObjectCount = 250; Assert.AreEqual(250, scheme.ObjectCount); + Assert.ThrowsException(() => scheme.ObjectCount = 251); + } + } +} diff --git a/src/test/Syroot.Worms.Armageddon.Test/Syroot.Worms.Armageddon.Test.csproj b/src/test/Syroot.Worms.Armageddon.Test/Syroot.Worms.Armageddon.Test.csproj index 5b80c4e..33aca73 100644 --- a/src/test/Syroot.Worms.Armageddon.Test/Syroot.Worms.Armageddon.Test.csproj +++ b/src/test/Syroot.Worms.Armageddon.Test/Syroot.Worms.Armageddon.Test.csproj @@ -1,13 +1,18 @@ - - - netcoreapp3 - false - - - - - - - - - + + + netcoreapp3 + false + + + + + + + + + + + PreserveNewest + + + diff --git a/src/test/Syroot.Worms.Armageddon.Test/TeamContainerTests.cs b/src/test/Syroot.Worms.Armageddon.Test/TeamContainerTests.cs index 5ba76d4..c2bb7c8 100644 --- a/src/test/Syroot.Worms.Armageddon.Test/TeamContainerTests.cs +++ b/src/test/Syroot.Worms.Armageddon.Test/TeamContainerTests.cs @@ -16,9 +16,6 @@ namespace Syroot.Worms.Test.Armageddon /// Loads all files found in any game directories. /// [TestMethod] - public void LoadTeamContainers() - { - FileTester.LoadFiles(Game.Armageddon, "*.wgt"); - } + public void LoadTeamContainers() => FileTester.Run(Game.Armageddon, "*.wgt"); } } diff --git a/src/test/Syroot.Worms.Test/ArchiveTests.cs b/src/test/Syroot.Worms.Test/ArchiveTests.cs index 60f2623..345e5f7 100644 --- a/src/test/Syroot.Worms.Test/ArchiveTests.cs +++ b/src/test/Syroot.Worms.Test/ArchiveTests.cs @@ -15,9 +15,6 @@ namespace Syroot.Worms.Test /// Loads all files found in any game directories. /// [TestMethod] - public void LoadArchives() - { - FileTester.LoadFiles(Game.Team17, "*.dir"); - } + public void LoadArchives() => FileTester.Run(Game.Team17, "*.dir"); } } diff --git a/src/test/Syroot.Worms.Test/Core/FileTester.cs b/src/test/Syroot.Worms.Test/Core/FileTester.cs index 15ec16f..0ea2f08 100644 --- a/src/test/Syroot.Worms.Test/Core/FileTester.cs +++ b/src/test/Syroot.Worms.Test/Core/FileTester.cs @@ -1,87 +1,105 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using Syroot.Worms.Core.IO; - -namespace Syroot.Worms.Test.Core -{ - /// - /// Represents methods helping in executing file-based tests. - /// - public static class FileTester - { - // ---- CONSTANTS ---------------------------------------------------------------------------------------------- - - private static readonly Dictionary _gamePaths = new Dictionary - { - [Game.Worms2] = @"C:\Games\Worms2", - [Game.Armageddon] = @"C:\Games\Worms Armageddon 3.6.31.0", - [Game.WorldParty] = @"C:\Games\Worms World Party", - [Game.OnlineWorms] = @"C:\Games\Online Worms", - [Game.WorldPartyAqua] = @"C:\Games\WWP Aqua" - }; - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the files found with the given . Excludes file names specified in the - /// optional array . - /// - /// The type of the files to load. - /// The games to test. - /// The wildcard to match. - /// Optionally, the files to exclude. - public static void LoadFiles(Game games, string wildcard, string[] excludedFiles = null) - where T : ILoadableFile, new() - { - foreach (string fileName in FindFiles(games, wildcard)) - { - if (excludedFiles?.Contains(Path.GetFileName(fileName), StringComparer.OrdinalIgnoreCase) == true) - { - Debug.WriteLine($"Skipping {fileName}"); - continue; - } - Debug.Write($"Loading {fileName}..."); - T instance = new T(); - instance.Load(fileName); - Debug.WriteLine($" ok"); - } - } - - // ---- METHODS (PRIVATE) -------------------------------------------------------------------------------------- - - private static List FindFiles(Game games, string wildcard) - { - List files = new List(); - foreach (string path in GetGamePaths(games)) - { - if (Directory.Exists(path)) - files.AddRange(Directory.GetFiles(path, wildcard, SearchOption.AllDirectories)); - } - if (files.Count == 0) - throw new InvalidOperationException("No files found to test."); - return files; - } - - private static IEnumerable GetGamePaths(Game game) - { - return _gamePaths.Where(x => game.HasFlag(x.Key)).Select(x => x.Value); - } - } - - [Flags] - public enum Game - { - Worms2 = 1 << 0, - Armageddon = 1 << 1, - WorldParty = 1 << 2, - OnlineWorms = 1 << 3, - WorldPartyAqua = 1 << 4, - - Team17 = Worms2 | Armageddon | WorldParty, - Mgame = OnlineWorms | WorldPartyAqua, - All = -1 - } -} +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Syroot.Worms.Core.IO; + +namespace Syroot.Worms.Test.Core +{ + /// + /// Represents methods helping in executing file-based tests. + /// + public static class FileTester + { + // ---- CONSTANTS ---------------------------------------------------------------------------------------------- + + private static readonly Dictionary _gamePaths = new Dictionary + { + [Game.Worms2] = @"C:\Games\Worms2", + [Game.Armageddon] = @"C:\Games\Worms Armageddon 3.6.31.0", + [Game.WorldParty] = @"C:\Games\Worms World Party", + [Game.OnlineWorms] = @"C:\Games\Online Worms", + [Game.WorldPartyAqua] = @"C:\Games\WWP Aqua", + [Game.Test] = "Files" + }; + + // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- + + /// + /// Loads, saves, reloads, and compares the files found with the given , as long as + /// each operation is supported. Excludes file names specified in the optional array + /// . + /// + /// The type of the files to load. + /// The games to test. + /// The wildcard to match. + /// Optionally, the files to exclude. + public static void Run(Game games, string wildcard, string[] excludedFiles = null) + where T : ILoadableFile, new() + { + foreach (string fileName in FindFiles(games, wildcard)) + { + if (excludedFiles?.Contains(Path.GetFileName(fileName), StringComparer.OrdinalIgnoreCase) == true) + { + Debug.WriteLine($"Skipping {fileName}"); + continue; + } + + Debug.Write($"\"{fileName}\" load"); + T instance = new T(); + instance.Load(fileName); + + if (instance is ISaveableFile saveable) + { + Debug.Write($" save"); + using MemoryStream stream = new MemoryStream(); + saveable.Save(stream); + + Debug.Write($" reload"); + stream.Position = 0; + T newInstance = new T(); + newInstance.Load(stream); + + Debug.Write($" compare"); + Assert.IsTrue(newInstance.Equals(instance)); + } + Debug.WriteLine($" OK"); + } + } + + // ---- METHODS (PRIVATE) -------------------------------------------------------------------------------------- + + private static List FindFiles(Game games, string wildcard) + { + List files = new List(); + foreach (string path in GetGamePaths(games)) + if (Directory.Exists(path)) + files.AddRange(Directory.GetFiles(path, wildcard, SearchOption.AllDirectories)); + if (files.Count == 0) + throw new InvalidOperationException("No files found to test."); + return files; + } + + private static IEnumerable GetGamePaths(Game game) + { + return _gamePaths.Where(x => game.HasFlag(x.Key)).Select(x => x.Value); + } + } + + [Flags] + public enum Game + { + Worms2 = 1 << 0, + Armageddon = 1 << 1, + WorldParty = 1 << 2, + OnlineWorms = 1 << 3, + WorldPartyAqua = 1 << 4, + Test = 1 << 32, + + Team17 = Worms2 | Armageddon | WorldParty, + Mgame = OnlineWorms | WorldPartyAqua, + All = -1 + } +} diff --git a/src/test/Syroot.Worms.Test/ImageTests.cs b/src/test/Syroot.Worms.Test/ImageTests.cs index 4fb4915..6465656 100644 --- a/src/test/Syroot.Worms.Test/ImageTests.cs +++ b/src/test/Syroot.Worms.Test/ImageTests.cs @@ -15,9 +15,6 @@ namespace Syroot.Worms.Test /// Loads all files found in any game directories. /// [TestMethod] - public void LoadImages() - { - FileTester.LoadFiles(Game.All, "*.img"); - } + public void LoadImages() => FileTester.Run(Game.All, "*.img"); } } diff --git a/src/test/Syroot.Worms.Test/PaletteTests.cs b/src/test/Syroot.Worms.Test/PaletteTests.cs index 4dcdc97..7602507 100644 --- a/src/test/Syroot.Worms.Test/PaletteTests.cs +++ b/src/test/Syroot.Worms.Test/PaletteTests.cs @@ -17,7 +17,7 @@ namespace Syroot.Worms.Test [TestMethod] public void LoadPalettes() { - FileTester.LoadFiles(Game.Team17, "*.pal", new string[] + FileTester.Run(Game.Team17, "*.pal", new string[] { "wwp.pal", // Contains 4 bytes of trash after the data chunk. "wwpmaped.pal" // Contains 4 bytes of trash after the data chunk. diff --git a/src/test/Syroot.Worms.WorldParty.Test/LandDataTests.cs b/src/test/Syroot.Worms.WorldParty.Test/LandDataTests.cs index 1b84038..5794770 100644 --- a/src/test/Syroot.Worms.WorldParty.Test/LandDataTests.cs +++ b/src/test/Syroot.Worms.WorldParty.Test/LandDataTests.cs @@ -16,9 +16,6 @@ namespace Syroot.Worms.Test.WorldParty /// Loads all files found in any game directories. /// [TestMethod] - public void LoadLandData() - { - FileTester.LoadFiles(Game.WorldParty, "land.dat"); - } + public void LoadLandData() => FileTester.Run(Game.WorldParty, "land.dat"); } } diff --git a/src/test/Syroot.Worms.WorldParty.Test/TeamContainerTests.cs b/src/test/Syroot.Worms.WorldParty.Test/TeamContainerTests.cs index 93d4019..2641804 100644 --- a/src/test/Syroot.Worms.WorldParty.Test/TeamContainerTests.cs +++ b/src/test/Syroot.Worms.WorldParty.Test/TeamContainerTests.cs @@ -16,9 +16,6 @@ namespace Syroot.Worms.Test.WorldParty /// Loads all files found in any game directories. /// [TestMethod] - public void LoadTeamContainers() - { - FileTester.LoadFiles(Game.WorldParty, "*.wwp"); - } + public void LoadTeamContainers() => FileTester.Run(Game.WorldParty, "*.wwp"); } } diff --git a/src/test/Syroot.Worms.Worms2.Test/LandDataTests.cs b/src/test/Syroot.Worms.Worms2.Test/LandDataTests.cs index 1b3052e..1add726 100644 --- a/src/test/Syroot.Worms.Worms2.Test/LandDataTests.cs +++ b/src/test/Syroot.Worms.Worms2.Test/LandDataTests.cs @@ -16,9 +16,6 @@ namespace Syroot.Worms.Test.Worms2 /// Loads all files found in any game directories. /// [TestMethod] - public void LoadLandData() - { - FileTester.LoadFiles(Game.Worms2, "land.dat"); - } + public void LoadLandData() => FileTester.Run(Game.Worms2, "land.dat"); } } diff --git a/src/test/Syroot.Worms.Worms2.Test/SchemeOptionsTests.cs b/src/test/Syroot.Worms.Worms2.Test/SchemeOptionsTests.cs index ec4e0f0..cd0ac72 100644 --- a/src/test/Syroot.Worms.Worms2.Test/SchemeOptionsTests.cs +++ b/src/test/Syroot.Worms.Worms2.Test/SchemeOptionsTests.cs @@ -16,9 +16,6 @@ namespace Syroot.Worms.Test.Worms2 /// Loads all files found in any game directories. /// [TestMethod] - public void LoadSchemeOptions() - { - FileTester.LoadFiles(Game.Worms2, "*.opt"); - } + public void LoadSchemeOptions() => FileTester.Run(Game.Worms2, "*.opt"); } } diff --git a/src/test/Syroot.Worms.Worms2.Test/SchemeWeaponsTests.cs b/src/test/Syroot.Worms.Worms2.Test/SchemeWeaponsTests.cs index aa49f8c..5f0c4d3 100644 --- a/src/test/Syroot.Worms.Worms2.Test/SchemeWeaponsTests.cs +++ b/src/test/Syroot.Worms.Worms2.Test/SchemeWeaponsTests.cs @@ -16,9 +16,6 @@ namespace Syroot.Worms.Test.Worms2 /// Loads all files found in any game directories. /// [TestMethod] - public void LoadSchemeWeapons() - { - FileTester.LoadFiles(Game.Worms2, "*.wep"); - } + public void LoadSchemeWeapons() => FileTester.Run(Game.Worms2, "*.wep"); } } diff --git a/src/test/Syroot.Worms.Worms2.Test/TeamContainerTests.cs b/src/test/Syroot.Worms.Worms2.Test/TeamContainerTests.cs index 00bac68..9736d62 100644 --- a/src/test/Syroot.Worms.Worms2.Test/TeamContainerTests.cs +++ b/src/test/Syroot.Worms.Worms2.Test/TeamContainerTests.cs @@ -16,9 +16,6 @@ namespace Syroot.Worms.Test.Worms2 /// Loads all files found in any game directories. /// [TestMethod] - public void LoadTeamContainers() - { - FileTester.LoadFiles(Game.Worms2, "*.st1"); - } + public void LoadTeamContainers() => FileTester.Run(Game.Worms2, "*.st1"); } } diff --git a/src/tool/Syroot.Worms.Scratchpad/Program.cs b/src/tool/Syroot.Worms.Scratchpad/Program.cs index 6a7775d..0f643e7 100644 --- a/src/tool/Syroot.Worms.Scratchpad/Program.cs +++ b/src/tool/Syroot.Worms.Scratchpad/Program.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; using System.Drawing.Imaging; using System.IO; -using Syroot.Worms.Armageddon; using Syroot.Worms.Mgame; namespace Syroot.Worms.Scratchpad @@ -11,31 +8,7 @@ namespace Syroot.Worms.Scratchpad { // ---- METHODS (PRIVATE) -------------------------------------------------------------------------------------- - private static void Main() - { - IEnumerable fileNames = Directory.EnumerateFiles( - @"C:\Games\Worms Armageddon 3.7.2.1\User\Schemes", "*.wsc", SearchOption.AllDirectories); - - foreach (string fileName in fileNames) - { - string tempFile = Path.GetTempFileName(); - using (Stream tempStream = new FileStream(tempFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) - { - // Load the scheme and save it to temp file. - Scheme origScheme = new Scheme(fileName); - tempStream.Position = 0; - origScheme.Save(tempStream); - - // Load the temp file. - tempStream.Position = 0; - Scheme newScheme = new Scheme(tempStream); - - if (origScheme.ObjectCount != newScheme.ObjectCount || origScheme.ObjectTypes != newScheme.ObjectTypes) - throw new InvalidOperationException("mismatch"); - } - File.Delete(tempFile); - } - } + private static void Main() { } private static void ConvertIgdImages() {