From ff042f1fc20405c6517b4c6b86697220b178c328 Mon Sep 17 00:00:00 2001 From: Ray Koopa Date: Mon, 1 May 2017 19:55:14 +0200 Subject: [PATCH] Use BinaryData 2.0.0 RC to load ProjectX data more automatically. --- src/Syroot.Worms.Test/Program.cs | 10 +- .../Core/BinaryReaderExtensions.cs | 2 +- .../Core/BinaryWriterExtensions.cs | 2 +- src/Syroot.Worms/Core/RiffFile.cs | 2 +- src/Syroot.Worms/Gen2/Archive.cs | 2 +- .../Gen2/Armageddon/GeneratedMap.cs | 2 +- src/Syroot.Worms/Gen2/Armageddon/LandData.cs | 2 +- .../Armageddon/ProjectX/Actions/ActionBase.cs | 22 ---- .../ProjectX/Actions/ActionConverter.cs | 44 +++++++ .../ProjectX/Actions/BounceAction.cs | 52 +------- .../Armageddon/ProjectX/Actions/DigAction.cs | 44 +------ .../Armageddon/ProjectX/Actions/HomeAction.cs | 42 +----- .../Armageddon/ProjectX/Actions/IAction.cs | 6 + .../Armageddon/ProjectX/Actions/RoamAction.cs | 67 +--------- .../Armageddon/ProjectX/CollisionFlags.cs | 2 +- .../Gen2/Armageddon/ProjectX/Library.cs | 2 +- .../Gen2/Armageddon/ProjectX/Mine.cs | 1 - .../Gen2/Armageddon/ProjectX/Scheme.cs | 2 +- .../Gen2/Armageddon/ProjectX/Sound.cs | 18 +-- .../Gen2/Armageddon/ProjectX/Sprite.cs | 1 - .../ProjectX/Styles/AirstrikeStyle.cs | 66 +--------- .../Styles/AirstrikeSubstyleConverter.cs | 37 ++++++ .../ProjectX/Styles/BaseballBatStyle.cs | 36 +----- .../ProjectX/Styles/BattleAxeStyle.cs | 34 +---- .../ProjectX/Styles/BlowtorchStyle.cs | 40 +----- .../Armageddon/ProjectX/Styles/BowStyle.cs | 32 +---- .../ProjectX/Styles/CanisterStyle.cs | 38 +----- .../ProjectX/Styles/DragonballStyle.cs | 46 +------ .../ProjectX/Styles/FirepunchStyle.cs | 38 +----- .../ProjectX/Styles/FlamethrowerStyle.cs | 41 +----- .../Armageddon/ProjectX/Styles/GunStyle.cs | 59 +-------- .../Gen2/Armageddon/ProjectX/Styles/IStyle.cs | 6 + .../ProjectX/Styles/JetpackStyle.cs | 34 +---- .../ProjectX/Styles/KamikazeStyle.cs | 44 +------ .../ProjectX/Styles/LauncherStyle.cs | 122 ++---------------- .../Armageddon/ProjectX/Styles/MineStyle.cs | 33 +---- .../ProjectX/Styles/NinjaRopeStyle.cs | 38 +----- .../ProjectX/Styles/NuclearTestStyle.cs | 36 +----- .../ProjectX/Styles/ParachuteStyle.cs | 34 +---- .../ProjectX/Styles/PneumaticDrillStyle.cs | 40 +----- .../Armageddon/ProjectX/Styles/ProdStyle.cs | 38 +----- .../Armageddon/ProjectX/Styles/StyleBase.cs | 17 --- .../ProjectX/Styles/SuicideBomberStyle.cs | 36 +----- .../ProjectX/Targets/ClusterTarget.cs | 95 +------------- .../Armageddon/ProjectX/Targets/FireTarget.cs | 39 +----- .../Armageddon/ProjectX/Targets/ITarget.cs | 6 + .../Armageddon/ProjectX/Targets/TargetBase.cs | 22 ---- .../ProjectX/Targets/TargetConverter.cs | 37 ++++++ .../Gen2/Armageddon/ProjectX/Weapon.cs | 62 ++++----- src/Syroot.Worms/Gen2/Armageddon/Scheme.cs | 2 +- src/Syroot.Worms/Gen2/Armageddon/Team.cs | 2 +- .../Gen2/Armageddon/TeamContainer.cs | 2 +- src/Syroot.Worms/Gen2/Image.cs | 2 +- src/Syroot.Worms/Gen2/Palette.cs | 2 +- src/Syroot.Worms/Gen2/WorldParty/LandData.cs | 2 +- src/Syroot.Worms/Gen2/WorldParty/Team.cs | 2 +- .../Gen2/WorldParty/TeamContainer.cs | 2 +- src/Syroot.Worms/Gen2/Worms2/LandData.cs | 2 +- src/Syroot.Worms/Gen2/Worms2/SchemeOptions.cs | 2 +- src/Syroot.Worms/Gen2/Worms2/SchemeWeapons.cs | 2 +- src/Syroot.Worms/Gen2/Worms2/Team.cs | 2 +- src/Syroot.Worms/Gen2/Worms2/TeamContainer.cs | 2 +- src/Syroot.Worms/Syroot.Worms.csproj | 2 +- 63 files changed, 249 insertions(+), 1310 deletions(-) delete mode 100644 src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/ActionBase.cs create mode 100644 src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/ActionConverter.cs create mode 100644 src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/IAction.cs create mode 100644 src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/AirstrikeSubstyleConverter.cs create mode 100644 src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/IStyle.cs delete mode 100644 src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/StyleBase.cs create mode 100644 src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/ITarget.cs delete mode 100644 src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/TargetBase.cs create mode 100644 src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/TargetConverter.cs diff --git a/src/Syroot.Worms.Test/Program.cs b/src/Syroot.Worms.Test/Program.cs index 5d1400c..47a845f 100644 --- a/src/Syroot.Worms.Test/Program.cs +++ b/src/Syroot.Worms.Test/Program.cs @@ -1,6 +1,3 @@ -using System; -using System.IO; -using System.Collections.Generic; using Syroot.Worms.Gen2.Armageddon.ProjectX; namespace Syroot.Worms.Test @@ -14,13 +11,8 @@ namespace Syroot.Worms.Test private static void Main(string[] args) { - Library library = new Library(@"D:\Archive\Games\Worms\Worms Armageddon\3.6.31.0\Libs\cnades.pxl"); + Library library = new Library(@"D:\Pictures\loadme.pxl"); library.Save(@"D:\Pictures\saved.pxl"); - - //Scheme pxScheme = new Scheme(@"D:\Archive\Games\Worms\Worms Armageddon\3.6.31.0\PXSchemes\PacStruction.pxs"); - - Console.WriteLine("Done."); - Console.ReadLine(); } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Core/BinaryReaderExtensions.cs b/src/Syroot.Worms/Core/BinaryReaderExtensions.cs index 9283639..97c3579 100644 --- a/src/Syroot.Worms/Core/BinaryReaderExtensions.cs +++ b/src/Syroot.Worms/Core/BinaryReaderExtensions.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.InteropServices; -using Syroot.IO; +using Syroot.BinaryData; namespace Syroot.Worms.Core { diff --git a/src/Syroot.Worms/Core/BinaryWriterExtensions.cs b/src/Syroot.Worms/Core/BinaryWriterExtensions.cs index 538695b..6c72d9d 100644 --- a/src/Syroot.Worms/Core/BinaryWriterExtensions.cs +++ b/src/Syroot.Worms/Core/BinaryWriterExtensions.cs @@ -1,7 +1,7 @@ using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; -using Syroot.IO; +using Syroot.BinaryData; namespace Syroot.Worms.Core { diff --git a/src/Syroot.Worms/Core/RiffFile.cs b/src/Syroot.Worms/Core/RiffFile.cs index b907680..7a3cfdc 100644 --- a/src/Syroot.Worms/Core/RiffFile.cs +++ b/src/Syroot.Worms/Core/RiffFile.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Reflection; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; namespace Syroot.Worms.Core { diff --git a/src/Syroot.Worms/Gen2/Archive.cs b/src/Syroot.Worms/Gen2/Archive.cs index 6b8e49c..f2cf39d 100644 --- a/src/Syroot.Worms/Gen2/Archive.cs +++ b/src/Syroot.Worms/Gen2/Archive.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Worms.Core; namespace Syroot.Worms.Gen2 diff --git a/src/Syroot.Worms/Gen2/Armageddon/GeneratedMap.cs b/src/Syroot.Worms/Gen2/Armageddon/GeneratedMap.cs index a28e892..512e0e9 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/GeneratedMap.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/GeneratedMap.cs @@ -1,6 +1,6 @@ using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Worms.Core; namespace Syroot.Worms.Gen2.Armageddon diff --git a/src/Syroot.Worms/Gen2/Armageddon/LandData.cs b/src/Syroot.Worms/Gen2/Armageddon/LandData.cs index fc95815..bd749f3 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/LandData.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/LandData.cs @@ -1,6 +1,6 @@ using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Maths; using Syroot.Worms.Core; diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/ActionBase.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/ActionBase.cs deleted file mode 100644 index 6e6d0ab..0000000 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/ActionBase.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.IO; -using Syroot.Worms.Core; - -namespace Syroot.Worms.Gen2.Armageddon.ProjectX -{ - public abstract class ActionBase : ILoadable, ISaveable - { - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public abstract void Load(Stream stream); - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public abstract void Save(Stream stream); - } -} diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/ActionConverter.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/ActionConverter.cs new file mode 100644 index 0000000..ee90c29 --- /dev/null +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/ActionConverter.cs @@ -0,0 +1,44 @@ +using System; +using Syroot.BinaryData; + +namespace Syroot.Worms.Gen2.Armageddon.ProjectX +{ + internal class ActionConverter : IBinaryConverter + { + // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- + + public object Read(BinaryDataReader reader, object instance, BinaryMemberAttribute memberAttribute) + { + ExplosionAction explosionAction; + switch (instance) + { + case LauncherStyle launcherStyle: + explosionAction = launcherStyle.ExplosionAction; + break; + case ClusterTarget clusterTarget: + explosionAction = clusterTarget.ExplosionAction; + break; + default: + throw new NotImplementedException(); + } + + switch (explosionAction) + { + case ExplosionAction.Bounce: + return reader.ReadObject(); + case ExplosionAction.Dig: + return reader.ReadObject(); + case ExplosionAction.Home: + return reader.ReadObject(); + case ExplosionAction.Roam: + return reader.ReadObject(); + } + return null; + } + + public void Write(BinaryDataWriter writer, object instance, BinaryMemberAttribute memberAttribute, object value) + { + writer.WriteObject(value); + } + } +} diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/BounceAction.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/BounceAction.cs index ea73a35..dc38ae7 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/BounceAction.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/BounceAction.cs @@ -1,10 +1,6 @@ -using System.IO; -using System.Text; -using Syroot.IO; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class BounceAction : ActionBase + public class BounceAction : IAction { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -29,51 +25,5 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int DamageRandomness { get; set; } public int BounceCount { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - Collisions = reader.ReadEnum(false); - Bounciness = reader.ReadInt32(); - Acceleration = reader.ReadInt32(); - Sound = reader.ReadInt32(); - Unknown1 = reader.ReadInt32(); - Unknown2 = reader.ReadInt32(); - ExplosionBias = reader.ReadInt32(); - ExplosionPower = reader.ReadInt32(); - ExplosionDamage = reader.ReadInt32(); - DamageRandomness = reader.ReadInt32(); - BounceCount = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(Collisions, true); - writer.Write(Bounciness); - writer.Write(Acceleration); - writer.Write(Sound); - writer.Write(Unknown1); - writer.Write(Unknown2); - writer.Write(ExplosionBias); - writer.Write(ExplosionPower); - writer.Write(ExplosionDamage); - writer.Write(DamageRandomness); - writer.Write(BounceCount); - } - } } } diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/DigAction.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/DigAction.cs index 3ee898e..639d1ad 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/DigAction.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/DigAction.cs @@ -1,10 +1,6 @@ -using System.IO; -using System.Text; -using Syroot.IO; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class DigAction : ActionBase + public class DigAction : IAction { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -21,43 +17,5 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int Sprite2 { get; set; } public int Sprite3 { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - Unknown1 = reader.ReadInt32(); - Unknown2 = reader.ReadInt32(); - DiggingSound = reader.ReadInt32(); - SpriteJumping = reader.ReadInt32(); - Sprite1 = reader.ReadInt32(); - Sprite2 = reader.ReadInt32(); - Sprite3 = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(Unknown1); - writer.Write(Unknown2); - writer.Write(DiggingSound); - writer.Write(SpriteJumping); - writer.Write(Sprite1); - writer.Write(Sprite2); - writer.Write(Sprite3); - } - } } } diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/HomeAction.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/HomeAction.cs index 3f3e65e..0f7d72e 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/HomeAction.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/HomeAction.cs @@ -1,14 +1,12 @@ -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; +using Syroot.BinaryData; namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class HomeAction : ActionBase + public class HomeAction : IAction { // ---- PROPERTIES --------------------------------------------------------------------------------------------- + [BinaryMember(Offset = 4)] public Sprite Sprite { get; set; } public HomeStyle HomeStyle { get; set; } @@ -16,40 +14,6 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int Delay { get; set; } public int Duration { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - reader.Seek(4); - Sprite = reader.ReadStruct(); - HomeStyle = reader.ReadEnum(false); - Delay = reader.ReadInt32(); - Duration = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(0); - writer.Write(Sprite); - writer.Write(HomeStyle); - writer.Write(Delay); - writer.Write(Duration); - } - } } public enum HomeStyle diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/IAction.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/IAction.cs new file mode 100644 index 0000000..96243f1 --- /dev/null +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/IAction.cs @@ -0,0 +1,6 @@ +namespace Syroot.Worms.Gen2.Armageddon.ProjectX +{ + public interface IAction + { + } +} diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/RoamAction.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/RoamAction.cs index e50659a..bf320c7 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/RoamAction.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Actions/RoamAction.cs @@ -1,10 +1,8 @@ -using System.IO; -using System.Text; -using Syroot.IO; +using Syroot.BinaryData; namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class RoamAction : ActionBase + public class RoamAction : IAction { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -30,6 +28,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int TerrainOffset { get; set; } + [BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroDword)] public bool Fart { get; set; } public int DiseasePower { get; set; } @@ -43,65 +42,5 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int SpriteTakeOff { get; set; } public int SpriteDuringFlight { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - RoamCollisions = reader.ReadEnum(false); - ExplosionCollisions = reader.ReadEnum(false); - WalkSpeed = reader.ReadInt32(); - Unknown = reader.ReadInt32(); - JumpAngleEdge = reader.ReadInt32(); - JumpVelocityEdge = reader.ReadInt32(); - JumpSoundEdge = reader.ReadInt32(); - JumpAngle = reader.ReadInt32(); - JumpVelocity = reader.ReadInt32(); - JumpSound = reader.ReadInt32(); - TerrainOffset = reader.ReadInt32(); - Fart = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword); - DiseasePower = reader.ReadInt32(); - SpriteFarting = reader.ReadInt32(); - SpriteFlying = reader.ReadInt32(); - SpriteFlying2 = reader.ReadInt32(); - SpriteTakeOff = reader.ReadInt32(); - SpriteDuringFlight = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(RoamCollisions, true); - writer.Write(ExplosionCollisions, true); - writer.Write(WalkSpeed); - writer.Write(Unknown); - writer.Write(JumpAngleEdge); - writer.Write(JumpVelocityEdge); - writer.Write(JumpSoundEdge); - writer.Write(JumpAngle); - writer.Write(JumpVelocity); - writer.Write(JumpSound); - writer.Write(TerrainOffset); - writer.Write(Fart, BinaryBooleanFormat.NonZeroDword); - writer.Write(DiseasePower); - writer.Write(SpriteFarting); - writer.Write(SpriteFlying); - writer.Write(SpriteFlying2); - writer.Write(SpriteTakeOff); - writer.Write(SpriteDuringFlight); - } - } } } diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/CollisionFlags.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/CollisionFlags.cs index e2f26a4..3a0a993 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/CollisionFlags.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/CollisionFlags.cs @@ -1,5 +1,5 @@ using System; -using Syroot.IO; +using Syroot.BinaryData; namespace Syroot.Worms.Gen2.Armageddon.ProjectX { diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Library.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Library.cs index 5d0a6f6..f79fbf8 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Library.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Library.cs @@ -4,7 +4,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Worms.Core; namespace Syroot.Worms.Gen2.Armageddon.ProjectX diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Mine.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Mine.cs index 0d4ce50..31da5fb 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Mine.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Mine.cs @@ -2,7 +2,6 @@ using System.Runtime.InteropServices; namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - [StructLayout(LayoutKind.Sequential)] public struct Mine { public int Sensitivity; diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Scheme.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Scheme.cs index 72a5dc6..6fd7ac8 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Scheme.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Scheme.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Worms.Core; namespace Syroot.Worms.Gen2.Armageddon.ProjectX diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Sound.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Sound.cs index 90cd540..d7f2e58 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Sound.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Sound.cs @@ -1,25 +1,19 @@ -using System.Runtime.InteropServices; +using Syroot.BinaryData; namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - [StructLayout(LayoutKind.Explicit)] public struct Sound { - [FieldOffset(0)] public short SoundIndex; - - // One byte goes unused here as marshalling does not support 2-byte booleans. - - [FieldOffset(3)] + + [BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroWord)] public bool RepeatSound; - [FieldOffset(4)] + [BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroDword)] public bool UseExplosionSound; - - [FieldOffset(8)] + public int SoundBeforeExplosion; - - [FieldOffset(12)] + public int DelayBeforeExplosion; } } diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Sprite.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Sprite.cs index cf99e18..885a989 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Sprite.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Sprite.cs @@ -2,7 +2,6 @@ using System.Runtime.InteropServices; namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - [StructLayout(LayoutKind.Sequential)] public struct Sprite { public int SpriteNumber; diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/AirstrikeStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/AirstrikeStyle.cs index bcb6cfa..1256410 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/AirstrikeStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/AirstrikeStyle.cs @@ -1,12 +1,8 @@ -using System; -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; +using Syroot.BinaryData; namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class AirstrikeStyle : StyleBase + public class AirstrikeStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -20,63 +16,13 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int Sound; - public WeaponAirstrikeAction Action; + public WeaponAirstrikeSubstyle AirstrikeSubstyle; - public StyleBase Style; - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - PlaneSprite = reader.ReadInt32(); - BombsCount = reader.ReadInt32(); - DropDistance = reader.ReadInt32(); - HorizontalSpeed = reader.ReadInt32(); - Sound = reader.ReadInt32(); - - Action = reader.ReadEnum(false); - switch (Action) - { - case WeaponAirstrikeAction.Launcher: - Style = reader.Load(); - break; - case WeaponAirstrikeAction.Mines: - Style = reader.Load(); - break; - } - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(PlaneSprite); - writer.Write(BombsCount); - writer.Write(DropDistance); - writer.Write(HorizontalSpeed); - writer.Write(Sound); - - writer.Write(Action, true); - if (Action != WeaponAirstrikeAction.Worms) - { - writer.Save(Style); - } - } - } + [BinaryMember(Converter = typeof(AirstrikeSubstyleConverter))] + public IStyle Style; } - public enum WeaponAirstrikeAction : int + public enum WeaponAirstrikeSubstyle : int { Mines, Worms, diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/AirstrikeSubstyleConverter.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/AirstrikeSubstyleConverter.cs new file mode 100644 index 0000000..eca70b7 --- /dev/null +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/AirstrikeSubstyleConverter.cs @@ -0,0 +1,37 @@ +using System; +using Syroot.BinaryData; + +namespace Syroot.Worms.Gen2.Armageddon.ProjectX +{ + public class AirstrikeSubstyleConverter : IBinaryConverter + { + // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- + + public object Read(BinaryDataReader reader, object instance, BinaryMemberAttribute memberAttribute) + { + WeaponAirstrikeSubstyle airstrikeSubstyle; + switch (instance) + { + case AirstrikeStyle airstrikeStyle: + airstrikeSubstyle = airstrikeStyle.AirstrikeSubstyle; + break; + default: + throw new NotImplementedException(); + } + + switch (airstrikeSubstyle) + { + case WeaponAirstrikeSubstyle.Launcher: + return reader.ReadObject(); + case WeaponAirstrikeSubstyle.Mines: + return reader.ReadObject(); + } + return null; + } + + public void Write(BinaryDataWriter writer, object instance, BinaryMemberAttribute memberAttribute, object value) + { + writer.WriteObject(value); + } + } +} \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BaseballBatStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BaseballBatStyle.cs index d8ff3b5..246a3a8 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BaseballBatStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BaseballBatStyle.cs @@ -1,45 +1,11 @@ -using System; -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class BaseballBatStyle : StyleBase + public class BaseballBatStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- public int Damage { get; set; } public int PushPower { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - Damage = reader.ReadInt32(); - PushPower = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(Damage); - writer.Write(PushPower); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BattleAxeStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BattleAxeStyle.cs index 972b9ad..d91b6ca 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BattleAxeStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BattleAxeStyle.cs @@ -1,41 +1,9 @@ -using System; -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class BattleAxeStyle : StyleBase + public class BattleAxeStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- public int PercentualDamage { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - PercentualDamage = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(PercentualDamage); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BlowtorchStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BlowtorchStyle.cs index 828373f..383b8c9 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BlowtorchStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BlowtorchStyle.cs @@ -1,12 +1,6 @@ -using System; -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class BlowtorchStyle : StyleBase + public class BlowtorchStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -17,37 +11,5 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int ImpactAngle { get; set; } public int TunellingTime { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - Damage = reader.ReadInt32(); - PushPower = reader.ReadInt32(); - ImpactAngle = reader.ReadInt32(); - TunellingTime = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(Damage); - writer.Write(PushPower); - writer.Write(ImpactAngle); - writer.Write(TunellingTime); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BowStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BowStyle.cs index 1a4477a..f51a403 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BowStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/BowStyle.cs @@ -1,39 +1,9 @@ -using System.IO; -using System.Text; -using Syroot.IO; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class BowStyle : StyleBase + public class BowStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- public int Damage { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - Damage = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(Damage); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/CanisterStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/CanisterStyle.cs index 8fdaa97..40e30c9 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/CanisterStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/CanisterStyle.cs @@ -1,10 +1,6 @@ -using System.IO; -using System.Text; -using Syroot.IO; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class CanisterStyle : StyleBase + public class CanisterStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -15,37 +11,5 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int DiseasePoints { get; set; } public int MaxDamage { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - SpriteInactive = reader.ReadInt32(); - SpriteActive = reader.ReadInt32(); - DiseasePoints = reader.ReadInt32(); - MaxDamage = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(SpriteInactive); - writer.Write(SpriteActive); - writer.Write(DiseasePoints); - writer.Write(MaxDamage); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/DragonballStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/DragonballStyle.cs index 153d344..adf1cd6 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/DragonballStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/DragonballStyle.cs @@ -1,12 +1,6 @@ -using System; -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class DragonballStyle : StyleBase + public class DragonballStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -23,43 +17,5 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int Force { get; set; } public int BallTime { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - FiringSound = reader.ReadInt32(); - ImpactSound = reader.ReadInt32(); - BallSprite = reader.ReadInt32(); - Damage = reader.ReadInt32(); - Angle = reader.ReadInt32(); - Force = reader.ReadInt32(); - BallTime = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(FiringSound); - writer.Write(ImpactSound); - writer.Write(BallSprite); - writer.Write(Damage); - writer.Write(Angle); - writer.Write(Force); - writer.Write(BallTime); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/FirepunchStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/FirepunchStyle.cs index b4b89a8..a0d7174 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/FirepunchStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/FirepunchStyle.cs @@ -1,10 +1,6 @@ -using System.IO; -using System.Text; -using Syroot.IO; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class FirepunchStyle : StyleBase + public class FirepunchStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -15,37 +11,5 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int PushPower { get; set; } public int JumpHeight { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - Damage = reader.ReadInt32(); - Angle = reader.ReadInt32(); - PushPower = reader.ReadInt32(); - JumpHeight = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(Damage); - writer.Write(Angle); - writer.Write(PushPower); - writer.Write(JumpHeight); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/FlamethrowerStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/FlamethrowerStyle.cs index 4242547..cbc87b1 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/FlamethrowerStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/FlamethrowerStyle.cs @@ -1,10 +1,8 @@ -using System.IO; -using System.Text; -using Syroot.IO; +using Syroot.BinaryData; namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class FlamethrowerStyle : StyleBase + public class FlamethrowerStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -16,40 +14,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int FireBurnTime { get; set; } + [BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroDword)] public bool RemainOnTerrain { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - FuelAmount = reader.ReadInt32(); - FireIntensity = reader.ReadInt32(); - FireAmount = reader.ReadInt32(); - FireBurnTime = reader.ReadInt32(); - RemainOnTerrain = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(FuelAmount); - writer.Write(FireIntensity); - writer.Write(FireAmount); - writer.Write(FireBurnTime); - writer.Write(RemainOnTerrain, BinaryBooleanFormat.NonZeroDword); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/GunStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/GunStyle.cs index ee9a305..fee5a01 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/GunStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/GunStyle.cs @@ -1,11 +1,6 @@ -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class GunStyle : StyleBase + public class GunStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -36,57 +31,5 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int Range2 { get; set; } public int Range3 { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - BulletCount = reader.ReadInt32(); - ReloadTime = reader.ReadInt32(); - BulletSpread = reader.ReadInt32(); - Burst = reader.ReadInt32(); - BurstSpread = reader.ReadInt32(); - Collisions = reader.ReadEnum(false); - ExplosionBias = reader.ReadInt32(); - ExplosionPower = reader.ReadInt32(); - MaxDamage = reader.ReadInt32(); - DamageSpread = reader.ReadInt32(); - ExpEffect = reader.ReadInt32(); - Range1 = reader.ReadInt32(); - Range2 = reader.ReadInt32(); - Range3 = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(BulletCount); - writer.Write(ReloadTime); - writer.Write(BulletSpread); - writer.Write(Burst); - writer.Write(BurstSpread); - writer.Write(Collisions, true); - writer.Write(ExplosionBias); - writer.Write(ExplosionPower); - writer.Write(MaxDamage); - writer.Write(DamageSpread); - writer.Write(ExpEffect); - writer.Write(Range1); - writer.Write(Range2); - writer.Write(Range3); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/IStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/IStyle.cs new file mode 100644 index 0000000..67e7fd1 --- /dev/null +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/IStyle.cs @@ -0,0 +1,6 @@ +namespace Syroot.Worms.Gen2.Armageddon.ProjectX +{ + public interface IStyle + { + } +} diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/JetpackStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/JetpackStyle.cs index 0f478c4..5bdb398 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/JetpackStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/JetpackStyle.cs @@ -1,41 +1,9 @@ -using System; -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class JetpackStyle : StyleBase + public class JetpackStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- public int Fuel { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - Fuel = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(Fuel); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/KamikazeStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/KamikazeStyle.cs index db7cf9e..1def304 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/KamikazeStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/KamikazeStyle.cs @@ -1,12 +1,6 @@ -using System; -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class KamikazeStyle : StyleBase + public class KamikazeStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -21,41 +15,5 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int ImpactForce { get; set; } public int ImpactAngle { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - FlyingTime = reader.ReadInt32(); - ExplosionDamage = reader.ReadInt32(); - FireSound = reader.ReadInt32(); - Damage = reader.ReadInt32(); - ImpactForce = reader.ReadInt32(); - ImpactAngle = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(FlyingTime); - writer.Write(ExplosionDamage); - writer.Write(FireSound); - writer.Write(Damage); - writer.Write(ImpactForce); - writer.Write(ImpactAngle); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/LauncherStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/LauncherStyle.cs index 97a3a64..3775c4f 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/LauncherStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/LauncherStyle.cs @@ -1,12 +1,8 @@ -using System; -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; +using Syroot.BinaryData; namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class LauncherStyle : StyleBase + public class LauncherStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -14,6 +10,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int FixedSpeed { get; set; } + [BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroDword)] public bool RunAway { get; set; } public CollisionFlags Collisions { get; set; } @@ -44,120 +41,19 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public Sound Sound { get; set; } + [BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroDword)] public bool ExplodeOnSpace { get; set; } public ExplosionAction ExplosionAction { get; set; } - public ActionBase Action { get; set; } + [BinaryMember(Converter = typeof(ActionConverter))] + public IAction Action { get; set; } + [BinaryMember(OffsetOrigin = OffsetOrigin.Begin, Offset = 180)] public ExplosionTarget ExplosionTarget { get; set; } - public TargetBase Target { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - long offset = reader.Position; - - SpriteSize = reader.ReadInt32(); - FixedSpeed = reader.ReadInt32(); - RunAway = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword); - Collisions = reader.ReadEnum(false); - ExplosionBias = reader.ReadInt32(); - ExplosionPushPower = reader.ReadInt32(); - ExplosionDamage = reader.ReadInt32(); - ExplosionDamageVariation = reader.ReadInt32(); - ExplosionUnknown = reader.ReadInt32(); - Sprite = reader.ReadStruct(); - VariableSpeed = reader.ReadInt32(); - WindFactor = reader.ReadInt32(); - MotionRandomness = reader.ReadInt32(); - GravityFactor = reader.ReadInt32(); - ExplosionCountdown = reader.ReadInt32(); - ExplosionTimer = reader.ReadInt32(); - Sound = reader.ReadStruct(); - ExplodeOnSpace = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword); - - ExplosionAction = reader.ReadEnum(false); - switch (ExplosionAction) - { - case ExplosionAction.Bounce: - Action = reader.Load(); - break; - case ExplosionAction.Dig: - Action = reader.Load(); - break; - case ExplosionAction.Home: - Action = reader.Load(); - break; - case ExplosionAction.Roam: - Action = reader.Load(); - break; - } - - reader.Position = offset + 180; - ExplosionTarget = reader.ReadEnum(false); - reader.Seek(sizeof(int)); - switch (ExplosionTarget) - { - case ExplosionTarget.Clusters: - Target = reader.Load(); - break; - case ExplosionTarget.Fire: - Target = reader.Load(); - break; - } - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - long offset = writer.Position; - - writer.Write(SpriteSize); - writer.Write(FixedSpeed); - writer.Write(RunAway, BinaryBooleanFormat.NonZeroDword); - writer.Write(Collisions, true); - writer.Write(ExplosionBias); - writer.Write(ExplosionPushPower); - writer.Write(ExplosionDamage); - writer.Write(ExplosionDamageVariation); - writer.Write(ExplosionUnknown); - writer.Write(Sprite); - writer.Write(VariableSpeed); - writer.Write(WindFactor); - writer.Write(MotionRandomness); - writer.Write(GravityFactor); - writer.Write(ExplosionCountdown); - writer.Write(ExplosionTimer); - writer.Write(Sound); - writer.Write(ExplodeOnSpace, BinaryBooleanFormat.NonZeroDword); - - writer.Write(ExplosionAction, true); - writer.Save(Action); - - writer.Position = offset + 180; - writer.Write(ExplosionTarget, true); - writer.Seek(sizeof(int)); - if (ExplosionTarget != ExplosionTarget.None) - { - writer.Save(Target); - } - } - } + [BinaryMember(Offset = sizeof(int), Converter = typeof(TargetConverter))] + public ITarget Target { get; set; } } public enum ExplosionAction : int diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/MineStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/MineStyle.cs index 5c9f931..e8d6ebd 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/MineStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/MineStyle.cs @@ -1,40 +1,9 @@ -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class MineStyle : StyleBase + public class MineStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- public Mine Mine; - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - Mine = reader.ReadStruct(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(Mine); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/NinjaRopeStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/NinjaRopeStyle.cs index 0fd7be5..c0c35a9 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/NinjaRopeStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/NinjaRopeStyle.cs @@ -1,12 +1,6 @@ -using System; -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class NinjaRopeStyle : StyleBase + public class NinjaRopeStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -15,35 +9,5 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int Length { get; set; } public int AngleRestriction { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - ShotCount = reader.ReadInt32(); - Length = reader.ReadInt32(); - AngleRestriction = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(ShotCount); - writer.Write(Length); - writer.Write(AngleRestriction); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/NuclearTestStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/NuclearTestStyle.cs index b2d1715..98bf85a 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/NuclearTestStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/NuclearTestStyle.cs @@ -1,45 +1,11 @@ -using System; -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class NuclearTestStyle : StyleBase + public class NuclearTestStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- public int WaterRise { get; set; } public int DiseasePoints { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - WaterRise = reader.ReadInt32(); - DiseasePoints = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(WaterRise); - writer.Write(DiseasePoints); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/ParachuteStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/ParachuteStyle.cs index 4474000..f0f43ab 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/ParachuteStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/ParachuteStyle.cs @@ -1,41 +1,9 @@ -using System; -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class ParachuteStyle : StyleBase + public class ParachuteStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- public int WindResponse { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - WindResponse = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(WindResponse); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/PneumaticDrillStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/PneumaticDrillStyle.cs index 7b9191e..0c0f187 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/PneumaticDrillStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/PneumaticDrillStyle.cs @@ -1,12 +1,6 @@ -using System; -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class PneumaticDrillStyle : StyleBase + public class PneumaticDrillStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -17,37 +11,5 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int ImpactAngle { get; set; } public int TunellingTime { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - Damage = reader.ReadInt32(); - PushPower = reader.ReadInt32(); - ImpactAngle = reader.ReadInt32(); - TunellingTime = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(Damage); - writer.Write(PushPower); - writer.Write(ImpactAngle); - writer.Write(TunellingTime); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/ProdStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/ProdStyle.cs index e7b05b1..a972ea7 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/ProdStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/ProdStyle.cs @@ -1,12 +1,6 @@ -using System; -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class ProdStyle : StyleBase + public class ProdStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -15,35 +9,5 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int Force { get; set; } public int Angle { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - Damage = reader.ReadInt32(); - Force = reader.ReadInt32(); - Angle = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(Damage); - writer.Write(Force); - writer.Write(Angle); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/StyleBase.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/StyleBase.cs deleted file mode 100644 index 8380447..0000000 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/StyleBase.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Syroot.Worms.Core; - -namespace Syroot.Worms.Gen2.Armageddon.ProjectX -{ - public abstract class StyleBase : ILoadable, ISaveable - { - public abstract void Load(Stream stream); - - public abstract void Save(Stream stream); - } -} diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/SuicideBomberStyle.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/SuicideBomberStyle.cs index 1d52099..590d4bb 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/SuicideBomberStyle.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Styles/SuicideBomberStyle.cs @@ -1,45 +1,11 @@ -using System; -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; - namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class SuicideBomberStyle : StyleBase + public class SuicideBomberStyle : IStyle { // ---- PROPERTIES --------------------------------------------------------------------------------------------- public int DiseasePoints { get; set; } public int Damage { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - DiseasePoints = reader.ReadInt32(); - Damage = reader.ReadInt32(); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(DiseasePoints); - writer.Write(Damage); - } - } } } \ No newline at end of file diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/ClusterTarget.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/ClusterTarget.cs index 8d2215a..77f5082 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/ClusterTarget.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/ClusterTarget.cs @@ -1,11 +1,8 @@ -using System.IO; -using System.Text; -using Syroot.IO; -using Syroot.Worms.Core; +using Syroot.BinaryData; namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class ClusterTarget : TargetBase + public class ClusterTarget : ITarget { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -47,94 +44,12 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public Sound Sound { get; set; } + [BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroDword)] public bool ExplodeOnSpace { get; set; } public ExplosionAction ExplosionAction { get; set; } - public ActionBase Action { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - ClusterCount = reader.ReadInt32(); - DispersionPower = reader.ReadInt32(); - Speed = reader.ReadInt32(); - EjectionAngle = reader.ReadInt32(); - DispersionAngle = reader.ReadInt32(); - Collisions = reader.ReadEnum(false); - ExplosionBias = reader.ReadInt32(); - ExplosionPushPower = reader.ReadInt32(); - ExplosionDamage = reader.ReadInt32(); - ExplosionDamageVariation = reader.ReadInt32(); - SpriteCount = reader.ReadInt32(); - Sprite = reader.ReadStruct(); - Acceleration = reader.ReadInt32(); - WindResponse = reader.ReadInt32(); - MotionRandomness = reader.ReadInt32(); - GravityFactor = reader.ReadInt32(); - Unused1 = reader.ReadInt32(); - Unused2 = reader.ReadInt32(); - Sound = reader.ReadStruct(); - ExplodeOnSpace = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword); - - ExplosionAction = reader.ReadEnum(false); - switch (ExplosionAction) - { - case ExplosionAction.Bounce: - Action = reader.Load(); - break; - case ExplosionAction.Dig: - Action = reader.Load(); - break; - case ExplosionAction.Home: - Action = reader.Load(); - break; - case ExplosionAction.Roam: - Action = reader.Load(); - break; - } - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(ClusterCount); - writer.Write(DispersionPower); - writer.Write(Speed); - writer.Write(EjectionAngle); - writer.Write(DispersionAngle); - writer.Write(Collisions, true); - writer.Write(ExplosionBias); - writer.Write(ExplosionPushPower); - writer.Write(ExplosionDamage); - writer.Write(ExplosionDamageVariation); - writer.Write(SpriteCount); - writer.Write(Sprite); - writer.Write(Acceleration); - writer.Write(WindResponse); - writer.Write(MotionRandomness); - writer.Write(GravityFactor); - writer.Write(Unused1); - writer.Write(Unused2); - writer.Write(Sound); - writer.Write(ExplodeOnSpace, BinaryBooleanFormat.NonZeroDword); - - writer.Write(ExplosionAction, true); - writer.Save(Action); - } - } + [BinaryMember(Converter = typeof(ActionConverter))] + public IAction Action { get; set; } } } diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/FireTarget.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/FireTarget.cs index e94b91d..67858c1 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/FireTarget.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/FireTarget.cs @@ -1,10 +1,8 @@ -using System.IO; -using System.Text; -using Syroot.IO; +using Syroot.BinaryData; namespace Syroot.Worms.Gen2.Armageddon.ProjectX { - public class FireTarget : TargetBase + public class FireTarget : ITarget { // ---- PROPERTIES --------------------------------------------------------------------------------------------- @@ -14,38 +12,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public int Time { get; set; } + [BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroDword)] public bool StayBetweenTurns { get; set; } - - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public override void Load(Stream stream) - { - using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true)) - { - Power = reader.ReadInt32(); - Spread = reader.ReadInt32(); - Time = reader.ReadInt32(); - StayBetweenTurns = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword); - } - } - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public override void Save(Stream stream) - { - using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true)) - { - writer.Write(Power); - writer.Write(Spread); - writer.Write(Time); - writer.Write(StayBetweenTurns, BinaryBooleanFormat.NonZeroDword); - } - } } } diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/ITarget.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/ITarget.cs new file mode 100644 index 0000000..7e29790 --- /dev/null +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/ITarget.cs @@ -0,0 +1,6 @@ +namespace Syroot.Worms.Gen2.Armageddon.ProjectX +{ + public interface ITarget + { + } +} diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/TargetBase.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/TargetBase.cs deleted file mode 100644 index 44bd76c..0000000 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/TargetBase.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.IO; -using Syroot.Worms.Core; - -namespace Syroot.Worms.Gen2.Armageddon.ProjectX -{ - public abstract class TargetBase : ILoadable, ISaveable - { - // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- - - /// - /// Loads the data from the given . - /// - /// The to load the data from. - public abstract void Load(Stream stream); - - /// - /// Saves the data into the given . - /// - /// The to save the data to. - public abstract void Save(Stream stream); - } -} diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/TargetConverter.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/TargetConverter.cs new file mode 100644 index 0000000..8abd0df --- /dev/null +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Targets/TargetConverter.cs @@ -0,0 +1,37 @@ +using System; +using Syroot.BinaryData; + +namespace Syroot.Worms.Gen2.Armageddon.ProjectX +{ + internal class TargetConverter : IBinaryConverter + { + // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- + + public object Read(BinaryDataReader reader, object instance, BinaryMemberAttribute memberAttribute) + { + ExplosionTarget explosionTarget; + switch (instance) + { + case LauncherStyle launcherStyle: + explosionTarget = launcherStyle.ExplosionTarget; + break; + default: + throw new NotImplementedException(); + } + + switch (explosionTarget) + { + case ExplosionTarget.Clusters: + return reader.ReadObject(); + case ExplosionTarget.Fire: + return reader.ReadObject(); + } + return null; + } + + public void Write(BinaryDataWriter writer, object instance, BinaryMemberAttribute memberAttribute, object value) + { + writer.WriteObject(value); + } + } +} diff --git a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Weapon.cs b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Weapon.cs index 8762678..b1083c2 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Weapon.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/ProjectX/Weapon.cs @@ -1,7 +1,7 @@ using System.Diagnostics; using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Worms.Core; namespace Syroot.Worms.Gen2.Armageddon.ProjectX @@ -37,6 +37,8 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public WeaponActivation Activation { get; set; } + public int NotUsed { get; set; } + public int ThrowHerdCount { get; set; } public int AirstrikeSubtype { get; set; } @@ -47,7 +49,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX public WeaponThrowAction ThrowAction { get; set; } - public StyleBase Style { get; set; } + public IStyle Style { get; set; } public bool AmmunitionOverride { get; set; } @@ -136,24 +138,24 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX { case WeaponActivation.Airstrike: AirstrikeSubtype = reader.ReadInt32(); - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponActivation.Crosshair: - reader.Seek(sizeof(int)); + NotUsed = reader.ReadInt32(); CrosshairAction = reader.ReadEnum(false); switch (CrosshairAction) { case WeaponCrosshairAction.Bow: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponCrosshairAction.Flamethrower: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponCrosshairAction.Gun: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponCrosshairAction.Launcher: - Style = reader.Load(); + Style = reader.ReadObject(); break; } break; @@ -162,46 +164,46 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX switch (SpacebarAction) { case WeaponSpacebarAction.Armageddon: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponSpacebarAction.BaseballBat: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponSpacebarAction.BattleAxe: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponSpacebarAction.Blowtorch: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponSpacebarAction.Dragonball: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponSpacebarAction.Firepunch: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponSpacebarAction.Jetpack: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponSpacebarAction.Kamikaze: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponSpacebarAction.NinjaRope: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponSpacebarAction.NuclearTest: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponSpacebarAction.Parachute: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponSpacebarAction.PneumaticDrill: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponSpacebarAction.Prod: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponSpacebarAction.SuicideBomber: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponSpacebarAction.Bungee: case WeaponSpacebarAction.Earthquake: @@ -223,13 +225,13 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX switch (ThrowAction) { case WeaponThrowAction.Canister: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponThrowAction.Launcher: - Style = reader.Load(); + Style = reader.ReadObject(); break; case WeaponThrowAction.Mine: - Style = reader.Load(); + Style = reader.ReadObject(); break; } break; @@ -306,14 +308,14 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX { case WeaponActivation.Airstrike: writer.Write(AirstrikeSubtype); - writer.Save(Style); + writer.WriteObject(Style); break; case WeaponActivation.Crosshair: - writer.Seek(sizeof(int)); + writer.Write(NotUsed); writer.Write(CrosshairAction, true); if (CrosshairAction != WeaponCrosshairAction.None) { - writer.Save(Style); + writer.WriteObject(Style); } break; case WeaponActivation.Spacebar: @@ -334,7 +336,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX case WeaponSpacebarAction.PneumaticDrill: case WeaponSpacebarAction.Prod: case WeaponSpacebarAction.SuicideBomber: - writer.Save(Style); + writer.WriteObject(Style); break; } break; @@ -343,7 +345,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX writer.Write(ThrowAction, true); if (ThrowAction != WeaponThrowAction.None) { - writer.Save(Style); + writer.WriteObject(Style); } break; } diff --git a/src/Syroot.Worms/Gen2/Armageddon/Scheme.cs b/src/Syroot.Worms/Gen2/Armageddon/Scheme.cs index f503af7..a61f289 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/Scheme.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/Scheme.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Worms.Core; namespace Syroot.Worms.Gen2.Armageddon diff --git a/src/Syroot.Worms/Gen2/Armageddon/Team.cs b/src/Syroot.Worms/Gen2/Armageddon/Team.cs index dd3e670..fab4939 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/Team.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/Team.cs @@ -1,7 +1,7 @@ using System.Diagnostics; using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Maths; using Syroot.Worms.Core; diff --git a/src/Syroot.Worms/Gen2/Armageddon/TeamContainer.cs b/src/Syroot.Worms/Gen2/Armageddon/TeamContainer.cs index 4bed234..38d79d7 100644 --- a/src/Syroot.Worms/Gen2/Armageddon/TeamContainer.cs +++ b/src/Syroot.Worms/Gen2/Armageddon/TeamContainer.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Worms.Core; namespace Syroot.Worms.Gen2.Armageddon diff --git a/src/Syroot.Worms/Gen2/Image.cs b/src/Syroot.Worms/Gen2/Image.cs index 88570a7..2c58b96 100644 --- a/src/Syroot.Worms/Gen2/Image.cs +++ b/src/Syroot.Worms/Gen2/Image.cs @@ -1,7 +1,7 @@ using System; using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Maths; using Syroot.Worms.Core; diff --git a/src/Syroot.Worms/Gen2/Palette.cs b/src/Syroot.Worms/Gen2/Palette.cs index 74f8114..307cb42 100644 --- a/src/Syroot.Worms/Gen2/Palette.cs +++ b/src/Syroot.Worms/Gen2/Palette.cs @@ -1,5 +1,5 @@ using System.IO; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Maths; using Syroot.Worms.Core; diff --git a/src/Syroot.Worms/Gen2/WorldParty/LandData.cs b/src/Syroot.Worms/Gen2/WorldParty/LandData.cs index 8a0574e..249f521 100644 --- a/src/Syroot.Worms/Gen2/WorldParty/LandData.cs +++ b/src/Syroot.Worms/Gen2/WorldParty/LandData.cs @@ -1,7 +1,7 @@ using System; using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Maths; using Syroot.Worms.Core; diff --git a/src/Syroot.Worms/Gen2/WorldParty/Team.cs b/src/Syroot.Worms/Gen2/WorldParty/Team.cs index 28cbe46..b7c040f 100644 --- a/src/Syroot.Worms/Gen2/WorldParty/Team.cs +++ b/src/Syroot.Worms/Gen2/WorldParty/Team.cs @@ -1,7 +1,7 @@ using System.Diagnostics; using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Maths; using Syroot.Worms.Core; diff --git a/src/Syroot.Worms/Gen2/WorldParty/TeamContainer.cs b/src/Syroot.Worms/Gen2/WorldParty/TeamContainer.cs index 3ef1377..9233062 100644 --- a/src/Syroot.Worms/Gen2/WorldParty/TeamContainer.cs +++ b/src/Syroot.Worms/Gen2/WorldParty/TeamContainer.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Worms.Core; namespace Syroot.Worms.Gen2.WorldParty diff --git a/src/Syroot.Worms/Gen2/Worms2/LandData.cs b/src/Syroot.Worms/Gen2/Worms2/LandData.cs index 2ac3372..23e487a 100644 --- a/src/Syroot.Worms/Gen2/Worms2/LandData.cs +++ b/src/Syroot.Worms/Gen2/Worms2/LandData.cs @@ -1,6 +1,6 @@ using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Maths; using Syroot.Worms.Core; diff --git a/src/Syroot.Worms/Gen2/Worms2/SchemeOptions.cs b/src/Syroot.Worms/Gen2/Worms2/SchemeOptions.cs index 225da7d..44e3df2 100644 --- a/src/Syroot.Worms/Gen2/Worms2/SchemeOptions.cs +++ b/src/Syroot.Worms/Gen2/Worms2/SchemeOptions.cs @@ -1,6 +1,6 @@ using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Worms.Core; namespace Syroot.Worms.Gen2.Worms2 diff --git a/src/Syroot.Worms/Gen2/Worms2/SchemeWeapons.cs b/src/Syroot.Worms/Gen2/Worms2/SchemeWeapons.cs index 8c6e795..3319619 100644 --- a/src/Syroot.Worms/Gen2/Worms2/SchemeWeapons.cs +++ b/src/Syroot.Worms/Gen2/Worms2/SchemeWeapons.cs @@ -1,6 +1,6 @@ using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Worms.Core; namespace Syroot.Worms.Gen2.Worms2 diff --git a/src/Syroot.Worms/Gen2/Worms2/Team.cs b/src/Syroot.Worms/Gen2/Worms2/Team.cs index c5ff4b8..7c3b94a 100644 --- a/src/Syroot.Worms/Gen2/Worms2/Team.cs +++ b/src/Syroot.Worms/Gen2/Worms2/Team.cs @@ -1,7 +1,7 @@ using System; using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Worms.Core; namespace Syroot.Worms.Gen2.Worms2 diff --git a/src/Syroot.Worms/Gen2/Worms2/TeamContainer.cs b/src/Syroot.Worms/Gen2/Worms2/TeamContainer.cs index c222bfc..e184faa 100644 --- a/src/Syroot.Worms/Gen2/Worms2/TeamContainer.cs +++ b/src/Syroot.Worms/Gen2/Worms2/TeamContainer.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Text; -using Syroot.IO; +using Syroot.BinaryData; using Syroot.Worms.Core; namespace Syroot.Worms.Gen2.Worms2 diff --git a/src/Syroot.Worms/Syroot.Worms.csproj b/src/Syroot.Worms/Syroot.Worms.csproj index 527284d..c9c92a4 100644 --- a/src/Syroot.Worms/Syroot.Worms.csproj +++ b/src/Syroot.Worms/Syroot.Worms.csproj @@ -22,7 +22,7 @@ - +