diff --git a/AnimationEditor/MainWindow.xaml b/AnimationEditor/MainWindow.xaml index 8bb1a4c..7b8a287 100644 --- a/AnimationEditor/MainWindow.xaml +++ b/AnimationEditor/MainWindow.xaml @@ -225,27 +225,27 @@ diff --git a/AnimationEditor/ViewModels/HitboxViewModel.cs b/AnimationEditor/ViewModels/HitboxViewModel.cs index cfaa206..8d682d7 100644 --- a/AnimationEditor/ViewModels/HitboxViewModel.cs +++ b/AnimationEditor/ViewModels/HitboxViewModel.cs @@ -31,7 +31,7 @@ namespace AnimationEditor.ViewModels { public class HitboxViewModel { - public Hitbox Hitbox { get; set; } + public IHitbox Hitbox { get; set; } public override string ToString() { diff --git a/AnimationEditor/ViewModels/MainViewModel.cs b/AnimationEditor/ViewModels/MainViewModel.cs index 9c18b3e..4933d90 100644 --- a/AnimationEditor/ViewModels/MainViewModel.cs +++ b/AnimationEditor/ViewModels/MainViewModel.cs @@ -53,7 +53,7 @@ public IAnimation AnimationData Textures = new ObservableCollection(_animationData.SpriteSheets); Animations = new ObservableCollection(_animationData.GetAnimations()); - Hitboxes = _animationData.GetHitboxes().Select(x => new HitboxViewModel() { Hitbox = x.Floor }).ToList() ?? new List(); + Hitboxes = _animationData.GetHitboxes()?.Select(x => new HitboxViewModel() { Hitbox = x.Floor }).ToList() ?? new List(); _animService = new AnimationService(_animationData); _animService.OnFrameChanged += OnFrameChanged; _spriteService = new SpriteService(_animationData, basePath); diff --git a/RSDK/IAnimation.cs b/RSDK/IAnimation.cs index 6009de7..c2755d3 100644 --- a/RSDK/IAnimation.cs +++ b/RSDK/IAnimation.cs @@ -29,35 +29,6 @@ namespace RSDK { - public class Hitbox - { - public int Left { get; set; } - - public int Top { get; set; } - - public int Right { get; set; } - - public int Bottom { get; set; } - - public Hitbox() { } - - public Hitbox(BinaryReader reader) - { - Left = reader.ReadSByte(); - Top = reader.ReadSByte(); - Right = reader.ReadSByte(); - Bottom = reader.ReadSByte(); - } - - public void SaveChanges(BinaryWriter writer) - { - writer.Write((sbyte)Left); - writer.Write((sbyte)Top); - writer.Write((sbyte)Right); - writer.Write((sbyte)Bottom); - } - } - public interface IFrame { int SpriteSheet { get; set; } @@ -94,14 +65,14 @@ public interface IAnimationEntry public interface IHitboxEntry { - Hitbox Floor { get; set; } - Hitbox Ceiling { get; set; } - Hitbox WallLeft { get; set; } - Hitbox WallRight { get; set; } - Hitbox Unk04 { get; set; } - Hitbox Unk05 { get; set; } - Hitbox Unk06 { get; set; } - Hitbox Unk07 { get; set; } + IHitbox Floor { get; set; } + IHitbox Ceiling { get; set; } + IHitbox WallLeft { get; set; } + IHitbox WallRight { get; set; } + IHitbox Unk04 { get; set; } + IHitbox Unk05 { get; set; } + IHitbox Unk06 { get; set; } + IHitbox Unk07 { get; set; } } public interface IAnimation diff --git a/RSDK/IHitbox.cs b/RSDK/IHitbox.cs new file mode 100644 index 0000000..bace4e4 --- /dev/null +++ b/RSDK/IHitbox.cs @@ -0,0 +1,17 @@ +using System.IO; + +namespace RSDK +{ + public interface IHitbox + { + int Left { get; set; } + + int Top { get; set; } + + int Right { get; set; } + + int Bottom { get; set; } + + void SaveChanges(BinaryWriter writer); + } +} diff --git a/RSDK/RSDK.csproj b/RSDK/RSDK.csproj index a787a9c..5c330d1 100644 --- a/RSDK/RSDK.csproj +++ b/RSDK/RSDK.csproj @@ -31,6 +31,7 @@ + diff --git a/RSDK/StringEncoding.cs b/RSDK/StringEncoding.cs index aa67da5..f57bf16 100644 --- a/RSDK/StringEncoding.cs +++ b/RSDK/StringEncoding.cs @@ -52,6 +52,8 @@ public static string GetString(BinaryReader reader) public static string GetString(byte[] data) { int length = data.Length; + if (length == 0) + return string.Empty; if (data[length - 1] == '\0') length--; return Encoding.UTF8.GetString(data, 0, length); diff --git a/RSDK3/Animation.HitboxEntry.cs b/RSDK3/Animation.HitboxEntry.cs index df3d7b8..a6f7b87 100644 --- a/RSDK3/Animation.HitboxEntry.cs +++ b/RSDK3/Animation.HitboxEntry.cs @@ -27,14 +27,14 @@ namespace RSDK3 { public class HitboxEntry : IHitboxEntry { - public Hitbox Floor { get; set; } - public Hitbox Ceiling { get; set; } - public Hitbox WallLeft { get; set; } - public Hitbox WallRight { get; set; } - public Hitbox Unk04 { get; set; } - public Hitbox Unk05 { get; set; } - public Hitbox Unk06 { get; set; } - public Hitbox Unk07 { get; set; } + public IHitbox Floor { get; set; } + public IHitbox Ceiling { get; set; } + public IHitbox WallLeft { get; set; } + public IHitbox WallRight { get; set; } + public IHitbox Unk04 { get; set; } + public IHitbox Unk05 { get; set; } + public IHitbox Unk06 { get; set; } + public IHitbox Unk07 { get; set; } public HitboxEntry() { diff --git a/RSDK3/Hitbox.cs b/RSDK3/Hitbox.cs new file mode 100644 index 0000000..1d838db --- /dev/null +++ b/RSDK3/Hitbox.cs @@ -0,0 +1,34 @@ +using RSDK; +using System.IO; + +namespace RSDK3 +{ + public class Hitbox : IHitbox + { + public int Left { get; set; } + + public int Top { get; set; } + + public int Right { get; set; } + + public int Bottom { get; set; } + + public Hitbox() { } + + public Hitbox(BinaryReader reader) + { + Left = reader.ReadSByte(); + Top = reader.ReadSByte(); + Right = reader.ReadSByte(); + Bottom = reader.ReadSByte(); + } + + public void SaveChanges(BinaryWriter writer) + { + writer.Write((sbyte)Left); + writer.Write((sbyte)Top); + writer.Write((sbyte)Right); + writer.Write((sbyte)Bottom); + } + } +} diff --git a/RSDK3/RSDK3.csproj b/RSDK3/RSDK3.csproj index 1fb6068..c07e5c4 100644 --- a/RSDK3/RSDK3.csproj +++ b/RSDK3/RSDK3.csproj @@ -33,6 +33,7 @@ + diff --git a/RSDK5/Animation.AnimationEntry.cs b/RSDK5/Animation.AnimationEntry.cs index 2736d54..f6ca852 100644 --- a/RSDK5/Animation.AnimationEntry.cs +++ b/RSDK5/Animation.AnimationEntry.cs @@ -43,7 +43,7 @@ public AnimationEntry() { } - public AnimationEntry(BinaryReader reader) + public AnimationEntry(BinaryReader reader, int collisionBoxesCount) { Name = StringEncoding.GetString(reader); @@ -53,7 +53,7 @@ public AnimationEntry(BinaryReader reader) Flags = 0; for (int i = 0; i < framesCount; i++) { - Frames.Add(new Frame() + var frame = new Frame(collisionBoxesCount) { SpriteSheet = reader.ReadByte(), CollisionBox = 0, @@ -65,15 +65,10 @@ public AnimationEntry(BinaryReader reader) Height = reader.ReadInt16(), CenterX = reader.ReadInt16(), CenterY = reader.ReadInt16(), - HitboxLeft = reader.ReadInt16(), - HitboxTop = reader.ReadInt16(), - HitboxRight = reader.ReadInt16(), - HitboxBottom = reader.ReadInt16(), - Hitbox2Left = reader.ReadInt16(), - Hitbox2Top = reader.ReadInt16(), - Hitbox2Right = reader.ReadInt16(), - Hitbox2Bottom = reader.ReadInt16(), - }); + }; + for (int j = 0; j < collisionBoxesCount; j++) + frame.Hitboxes[j] = new Hitbox(reader); + Frames.Add(frame); } } diff --git a/RSDK5/Animation.Frame.cs b/RSDK5/Animation.Frame.cs index 30718ac..81157bc 100644 --- a/RSDK5/Animation.Frame.cs +++ b/RSDK5/Animation.Frame.cs @@ -46,20 +46,11 @@ public class Frame : IFrame public int CenterY { get; set; } - public int HitboxLeft { get; set; } - - public int HitboxTop { get; set; } - - public int HitboxRight { get; set; } - - public int HitboxBottom { get; set; } - - public int Hitbox2Left { get; set; } - - public int Hitbox2Top { get; set; } - - public int Hitbox2Right { get; set; } - - public int Hitbox2Bottom { get; set; } + public Hitbox[] Hitboxes { get; set; } + + public Frame(int hitboxesCount = 0) + { + Hitboxes = new Hitbox[hitboxesCount]; + } } } diff --git a/RSDK5/Animation.HitboxEntry.cs b/RSDK5/Animation.HitboxEntry.cs deleted file mode 100644 index 2d52454..0000000 --- a/RSDK5/Animation.HitboxEntry.cs +++ /dev/null @@ -1,75 +0,0 @@ -// MIT License -// -// Copyright(c) 2017 Luciano (Xeeynamo) Ciccariello -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using RSDK; -using System.IO; - -namespace RSDK5 -{ - public class HitboxEntry : IHitboxEntry - { - public Hitbox Floor { get; set; } - public Hitbox Ceiling { get; set; } - public Hitbox WallLeft { get; set; } - public Hitbox WallRight { get; set; } - public Hitbox Unk04 { get; set; } - public Hitbox Unk05 { get; set; } - public Hitbox Unk06 { get; set; } - public Hitbox Unk07 { get; set; } - - public HitboxEntry() - { - Floor = new Hitbox(); - Ceiling = new Hitbox(); - WallLeft = new Hitbox(); - WallRight = new Hitbox(); - Unk04 = new Hitbox(); - Unk05 = new Hitbox(); - Unk06 = new Hitbox(); - Unk07 = new Hitbox(); - } - - public HitboxEntry(BinaryReader reader) - { - Floor = new Hitbox(reader); - Ceiling = new Hitbox(reader); - WallLeft = new Hitbox(reader); - WallRight = new Hitbox(reader); - Unk04 = new Hitbox(reader); - Unk05 = new Hitbox(reader); - Unk06 = new Hitbox(reader); - Unk07 = new Hitbox(reader); - } - - public void SaveChanges(BinaryWriter writer) - { - Floor.SaveChanges(writer); - Ceiling.SaveChanges(writer); - WallLeft.SaveChanges(writer); - WallRight.SaveChanges(writer); - Unk04.SaveChanges(writer); - Unk05.SaveChanges(writer); - Unk06.SaveChanges(writer); - Unk07.SaveChanges(writer); - } - } -} diff --git a/RSDK5/Animation.cs b/RSDK5/Animation.cs index 221cccc..46e8d90 100644 --- a/RSDK5/Animation.cs +++ b/RSDK5/Animation.cs @@ -34,12 +34,10 @@ public class Animation : IAnimation public List SpriteSheets { get; } - public List UnknownList { get; } + public List CollisionBoxes { get; } public List Animations { get; } - public List Hitboxes { get; } - public Animation(BinaryReader reader) { int magicCode; @@ -53,20 +51,20 @@ public Animation(BinaryReader reader) while (spriteSheetsCount-- > 0) SpriteSheets.Add(StringEncoding.GetString(reader)); - int unknownListCount = reader.ReadByte(); - UnknownList = new List(unknownListCount); - while (unknownListCount-- > 0) - UnknownList.Add(StringEncoding.GetString(reader)); + int collisionBoxesCount = reader.ReadByte(); + CollisionBoxes = new List(collisionBoxesCount); + while (collisionBoxesCount-- > 0) + CollisionBoxes.Add(StringEncoding.GetString(reader)); var animationsCount = reader.ReadInt16(); Animations = new List(animationsCount); while (animationsCount-- > 0) - Animations.Add(new AnimationEntry(reader)); + Animations.Add(new AnimationEntry(reader, CollisionBoxes.Count)); } public void Factory(out IAnimationEntry o) { o = new AnimationEntry(); } public void Factory(out IFrame o) { o = new Frame(); } - public void Factory(out IHitboxEntry o) { o = new HitboxEntry(); } + public void Factory(out IHitboxEntry o) { o = null; } public IEnumerable GetAnimations() { @@ -81,18 +79,9 @@ public void SetAnimations(IEnumerable animations) .Where(x => x != null)); } - public IEnumerable GetHitboxes() - { - return Hitboxes?.Select(x => (IHitboxEntry)x) ?? new HitboxEntry[0]; - } + public IEnumerable GetHitboxes() { return null; } - public void SetHitboxes(IEnumerable hitboxes) - { - Hitboxes.Clear(); - Hitboxes.AddRange(hitboxes - .Select(x => x as HitboxEntry) - .Where(x => x != null)); - } + public void SetHitboxes(IEnumerable hitboxes) { } public void SaveChanges(BinaryWriter writer) @@ -111,13 +100,6 @@ public void SaveChanges(BinaryWriter writer) { Animations[i].SaveChanges(writer); } - - var collisionBoxesCount = (byte)Math.Min(Hitboxes.Count, byte.MaxValue); - writer.Write(collisionBoxesCount); - for (int i = 0; i < collisionBoxesCount; i++) - { - Hitboxes[i].SaveChanges(writer); - } } } } diff --git a/RSDK5/Hitbox.cs b/RSDK5/Hitbox.cs new file mode 100644 index 0000000..c0ecf2d --- /dev/null +++ b/RSDK5/Hitbox.cs @@ -0,0 +1,34 @@ +using RSDK; +using System.IO; + +namespace RSDK5 +{ + public class Hitbox : IHitbox + { + public int Left { get; set; } + + public int Top { get; set; } + + public int Right { get; set; } + + public int Bottom { get; set; } + + public Hitbox() { } + + public Hitbox(BinaryReader reader) + { + Left = reader.ReadInt16(); + Top = reader.ReadInt16(); + Right = reader.ReadInt16(); + Bottom = reader.ReadInt16(); + } + + public void SaveChanges(BinaryWriter writer) + { + writer.Write((short)Left); + writer.Write((short)Top); + writer.Write((short)Right); + writer.Write((short)Bottom); + } + } +} diff --git a/RSDK5/RSDK5.csproj b/RSDK5/RSDK5.csproj index e81c6b3..b68b2e1 100644 --- a/RSDK5/RSDK5.csproj +++ b/RSDK5/RSDK5.csproj @@ -33,7 +33,7 @@ - +