From f9c08efa84f8abd6431efa65ec2a3e37f199f79c Mon Sep 17 00:00:00 2001 From: gulasch7742 Date: Fri, 9 Aug 2024 14:35:07 +0200 Subject: [PATCH 01/15] Added Physics and other Chunks --- Warcraft.NET.Docs/ChunkAvailability.cs | 26 ++++ Warcraft.NET.Docs/Program.cs | 44 +++++-- Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs | 71 ++++++++++ Warcraft.NET/Files/M2/Chunks/Legion/LDV1.cs | 71 ++++++++++ Warcraft.NET/Files/M2/Chunks/Legion/PGD1.cs | 72 ++++++++++ Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs | 59 +++++++++ Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs | 71 ++++++++++ Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs | 71 ++++++++++ Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs | 63 +++++++++ Warcraft.NET/Files/M2/Entries/AFIDEntry.cs | 2 +- Warcraft.NET/Files/M2/Entries/DBOCEntry.cs | 62 +++++++++ Warcraft.NET/Files/M2/Entries/EDGFEntry.cs | 62 +++++++++ Warcraft.NET/Files/M2/Entries/EXPTEntry.cs | 59 +++++++++ Warcraft.NET/Files/M2/Entries/LDV1Entry.cs | 66 ++++++++++ Warcraft.NET/Files/M2/Model.cs | 87 ++++++++---- Warcraft.NET/Files/SKIN/Skin.cs | 52 ++++++++ Warcraft.NET/Files/Structures/C3Vector.cs | 54 ++++++++ Warcraft.NET/Files/Structures/Mat3x4.cs | 54 ++++++++ Warcraft.NET/Files/phys/Chunks/BDY4.cs | 69 ++++++++++ Warcraft.NET/Files/phys/Chunks/BOXS.cs | 69 ++++++++++ Warcraft.NET/Files/phys/Chunks/CAPS.cs | 70 ++++++++++ Warcraft.NET/Files/phys/Chunks/DSTJ.cs | 69 ++++++++++ Warcraft.NET/Files/phys/Chunks/JOIN.cs | 69 ++++++++++ Warcraft.NET/Files/phys/Chunks/PHYS.cs | 58 ++++++++ Warcraft.NET/Files/phys/Chunks/PHYT.cs | 58 ++++++++ Warcraft.NET/Files/phys/Chunks/PHYV.cs | 74 +++++++++++ Warcraft.NET/Files/phys/Chunks/PLYT.cs | 121 +++++++++++++++++ Warcraft.NET/Files/phys/Chunks/PRS2.cs | 69 ++++++++++ Warcraft.NET/Files/phys/Chunks/REV2.cs | 69 ++++++++++ Warcraft.NET/Files/phys/Chunks/SHJ2.cs | 69 ++++++++++ Warcraft.NET/Files/phys/Chunks/SHOJ.cs | 69 ++++++++++ Warcraft.NET/Files/phys/Chunks/SHP2.cs | 69 ++++++++++ Warcraft.NET/Files/phys/Chunks/SPHJ.cs | 69 ++++++++++ Warcraft.NET/Files/phys/Chunks/SPHS.cs | 67 ++++++++++ Warcraft.NET/Files/phys/Chunks/WLJ3.cs | 69 ++++++++++ Warcraft.NET/Files/phys/Entries/BDY4Entry.cs | 92 +++++++++++++ Warcraft.NET/Files/phys/Entries/BOXSEntry.cs | 53 ++++++++ Warcraft.NET/Files/phys/Entries/CAPSEntry.cs | 57 ++++++++ Warcraft.NET/Files/phys/Entries/DSTJEntry.cs | 62 +++++++++ Warcraft.NET/Files/phys/Entries/JOINEntry.cs | 68 ++++++++++ Warcraft.NET/Files/phys/Entries/PLYTEntry.cs | 132 +++++++++++++++++++ Warcraft.NET/Files/phys/Entries/PRS2Entry.cs | 83 ++++++++++++ Warcraft.NET/Files/phys/Entries/REV2Entry.cs | 76 +++++++++++ Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs | 80 +++++++++++ Warcraft.NET/Files/phys/Entries/SHOJEntry.cs | 73 ++++++++++ Warcraft.NET/Files/phys/Entries/SHP2Entry.cs | 93 +++++++++++++ Warcraft.NET/Files/phys/Entries/SPHJEntry.cs | 59 +++++++++ Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs | 73 ++++++++++ Warcraft.NET/Files/phys/Physics.cs | 87 ++++++++++++ 49 files changed, 3304 insertions(+), 37 deletions(-) create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/LDV1.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/PGD1.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs create mode 100644 Warcraft.NET/Files/M2/Entries/DBOCEntry.cs create mode 100644 Warcraft.NET/Files/M2/Entries/EDGFEntry.cs create mode 100644 Warcraft.NET/Files/M2/Entries/EXPTEntry.cs create mode 100644 Warcraft.NET/Files/M2/Entries/LDV1Entry.cs create mode 100644 Warcraft.NET/Files/SKIN/Skin.cs create mode 100644 Warcraft.NET/Files/Structures/C3Vector.cs create mode 100644 Warcraft.NET/Files/Structures/Mat3x4.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/BDY4.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/BOXS.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/CAPS.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/DSTJ.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/JOIN.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/PHYS.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/PHYT.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/PHYV.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/PLYT.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/PRS2.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/REV2.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/SHJ2.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/SHOJ.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/SHP2.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/SPHJ.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/SPHS.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/WLJ3.cs create mode 100644 Warcraft.NET/Files/phys/Entries/BDY4Entry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/BOXSEntry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/CAPSEntry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/DSTJEntry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/JOINEntry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/PLYTEntry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/PRS2Entry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/REV2Entry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/SHOJEntry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/SHP2Entry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/SPHJEntry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs create mode 100644 Warcraft.NET/Files/phys/Physics.cs diff --git a/Warcraft.NET.Docs/ChunkAvailability.cs b/Warcraft.NET.Docs/ChunkAvailability.cs index f3d2d31..67c5085 100644 --- a/Warcraft.NET.Docs/ChunkAvailability.cs +++ b/Warcraft.NET.Docs/ChunkAvailability.cs @@ -136,6 +136,32 @@ internal static class ChunkAvailability } }, } + },{ + "phys", new () + { + { + "PHYS", new() + { + "PHYS", + "PHYT", + "BDY4", + "SHP2", + "BOXS", + "CAPS", + "SPHS", + "PLYT", + "JOIN", + "WLJ3", + "SPHJ", + "SHJ2", + "PRS2", + "REV2", + "DSTJ", + "SHOJ", + "PHYV", + } + }, + } }, { "tex", new () diff --git a/Warcraft.NET.Docs/Program.cs b/Warcraft.NET.Docs/Program.cs index ce9d6ff..867c66f 100644 --- a/Warcraft.NET.Docs/Program.cs +++ b/Warcraft.NET.Docs/Program.cs @@ -1,4 +1,6 @@ using Warcraft.NET.Docs.Steps; +using Warcraft.NET.Files.M2; +using Warcraft.NET.Files.phys; namespace Warcraft.NET.Docs { @@ -10,24 +12,40 @@ internal class Program /// static void Main(string[] args) { - Console.WriteLine($"BaseDirectory: {AppDomain.CurrentDomain.BaseDirectory}"); + string iripath = "C:\\Users\\marce\\Desktop\\WoWStuff\\wow.export\\creature\\iridikron\\"; + byte[] data = File.ReadAllBytes(iripath+"iridikron.m2"); + Model m = new Model(data); - if (args.Length == 0) - throw new System.Exception("Please provide an output folder"); + byte[] phys_test = File.ReadAllBytes("D:\\Unity Projects\\M2Tool\\M2Godot\\buckle_panstart_a_01.phys"); + Physics phys = new Physics(phys_test); - string outputFolder = Path.GetFullPath(args[0]); - if (!Directory.Exists(outputFolder)) - throw new Exception("Output folder does not exist"); + File.WriteAllBytes(iripath+"iridikron_output.m2", m.Serialize()); + File.WriteAllBytes("D:\\Unity Projects\\M2Tool\\M2Godot\\buckle_panstart_a_01_output.phys", phys.Serialize()); - Console.WriteLine($"Output folder: {outputFolder}"); - Console.WriteLine("Generating documentation..."); - var autoDocData = GenerateAutoDocDataStep.Process(); - Console.WriteLine("Converting to markdown..."); - ConvertToMarkdownStep.Process(autoDocData, outputFolder); + if (1==2) { - Console.WriteLine("Done!"); - } + + Console.WriteLine($"BaseDirectory: {AppDomain.CurrentDomain.BaseDirectory}"); + + if (args.Length == 0) + throw new System.Exception("Please provide an output folder"); + + string outputFolder = Path.GetFullPath(args[0]); + if (!Directory.Exists(outputFolder)) + throw new Exception("Output folder does not exist"); + + Console.WriteLine($"Output folder: {outputFolder}"); + + Console.WriteLine("Generating documentation..."); + var autoDocData = GenerateAutoDocDataStep.Process(); + + Console.WriteLine("Converting to markdown..."); + ConvertToMarkdownStep.Process(autoDocData, outputFolder); + + Console.WriteLine("Done!"); + } + } } } \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs b/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs new file mode 100644 index 0000000..6483a5a --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs @@ -0,0 +1,71 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class EXPT : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "EXP2"; + + /// + /// Gets or sets the Skin FileDataId + /// + public List EXP2Entries = new(); + + /// + /// Initializes a new instance of + /// + public EXPT() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public EXPT(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var exp2count = br.BaseStream.Length / EXPTEntry.GetSize(); + for (var i = 0; i < exp2count; ++i) + { + EXP2Entries.Add(new EXPTEntry(br.ReadBytes(EXPTEntry.GetSize()))); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (EXPTEntry obj in EXP2Entries) + { + bw.Write(obj.Serialize()); + } + + return ms.ToArray(); + } + } + + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/LDV1.cs b/Warcraft.NET/Files/M2/Chunks/Legion/LDV1.cs new file mode 100644 index 0000000..92eb4eb --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/LDV1.cs @@ -0,0 +1,71 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class LDV1 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "LDV1"; + + /// + /// Gets or sets the Skin FileDataId + /// + public List LDV1Entries = new(); + + /// + /// Initializes a new instance of + /// + public LDV1() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public LDV1(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var LDV1count = br.BaseStream.Length / LDV1Entry.GetSize(); + for (var i = 0; i < LDV1count; ++i) + { + LDV1Entries.Add(new LDV1Entry(br.ReadBytes(LDV1Entry.GetSize()))); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (LDV1Entry obj in LDV1Entries) + { + bw.Write(obj.Serialize()); + } + + return ms.ToArray(); + } + } + + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PGD1.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PGD1.cs new file mode 100644 index 0000000..5502817 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PGD1.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class PGD1 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PGD1"; + + /// + /// Gets or sets the Skin FileDataId + /// + public List PGD1Entries = new(); + + /// + /// Initializes a new instance of + /// + public PGD1() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PGD1(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var PGD1count = br.BaseStream.Length / 2; + for (var i = 0; i < PGD1count; ++i) + { + PGD1Entries.Add(br.ReadUInt16()); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (UInt16 obj in PGD1Entries) + { + bw.Write(obj); + } + + return ms.ToArray(); + } + } + + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs new file mode 100644 index 0000000..a4bcd8e --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs @@ -0,0 +1,59 @@ +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class TXAC : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "TXAC"; + + /// + /// Gets or sets the Skin FileDataId + /// + public byte[] unk; + + /// + /// Initializes a new instance of + /// + public TXAC() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public TXAC(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + unk = br.ReadBytes((int)br.BaseStream.Length); + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(unk); + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs b/Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs new file mode 100644 index 0000000..cccf08c --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs @@ -0,0 +1,71 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class DBOC : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "DBOC"; + + /// + /// Gets or sets the Skin FileDataId + /// + public List DBOCEntries = new(); + + /// + /// Initializes a new instance of + /// + public DBOC() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public DBOC(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var DBOCcount = br.BaseStream.Length / DBOCEntry.GetSize(); + for (var i = 0; i < DBOCcount; ++i) + { + DBOCEntries.Add(new DBOCEntry(br.ReadBytes(DBOCEntry.GetSize()))); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (DBOCEntry obj in DBOCEntries) + { + bw.Write(obj.Serialize()); + } + + return ms.ToArray(); + } + } + + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs b/Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs new file mode 100644 index 0000000..311763c --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs @@ -0,0 +1,71 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class EDGF : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "EDGF"; + + /// + /// Gets or sets the Skin FileDataId + /// + public List EDGFEntries = new(); + + /// + /// Initializes a new instance of + /// + public EDGF() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public EDGF(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var EDGFcount = br.BaseStream.Length / EDGFEntry.GetSize(); + for (var i = 0; i < EDGFcount; ++i) + { + EDGFEntries.Add(new EDGFEntry(br.ReadBytes(EDGFEntry.GetSize()))); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (EDGFEntry obj in EDGFEntries) + { + bw.Write(obj.Serialize()); + } + + return ms.ToArray(); + } + } + + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs b/Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs new file mode 100644 index 0000000..f6ff583 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs @@ -0,0 +1,63 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; +using Warcraft.NET.Files.phys; + +namespace Warcraft.NET.Files.M2.Chunks.SL +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class PFDC : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PFDC"; + + /// + /// Gets or sets the Physics of the chunk + /// + public Physics physics { get; set; } = null; + + /// + /// Initializes a new instance of + /// + public PFDC() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PFDC(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + physics = new Physics(inData); + //convert inData into >physics< + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(physics.Serialize()); + //convert >physics< into byte[] + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/AFIDEntry.cs b/Warcraft.NET/Files/M2/Entries/AFIDEntry.cs index 45bb227..31a0080 100644 --- a/Warcraft.NET/Files/M2/Entries/AFIDEntry.cs +++ b/Warcraft.NET/Files/M2/Entries/AFIDEntry.cs @@ -49,7 +49,7 @@ public AFIDEntry(byte[] data) /// The size. public static int GetSize() { - return 16; + return 8; } /// diff --git a/Warcraft.NET/Files/M2/Entries/DBOCEntry.cs b/Warcraft.NET/Files/M2/Entries/DBOCEntry.cs new file mode 100644 index 0000000..c8c04a1 --- /dev/null +++ b/Warcraft.NET/Files/M2/Entries/DBOCEntry.cs @@ -0,0 +1,62 @@ +using System; +using System.IO; + +namespace Warcraft.NET.Files.M2.Entries +{ + public class DBOCEntry + { + public float unk_float1; + public float unk_float2; + public UInt32 unk_int1; + public UInt32 unk_int2; + + /// + /// Initializes a new instance of the class. + /// + public DBOCEntry() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public DBOCEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + unk_float1 = br.ReadSingle(); + unk_float2 = br.ReadSingle(); + unk_int1 = br.ReadUInt32(); + unk_int2 = br.ReadUInt32(); + } + } + + /// + /// Gets the size of a DBOC Entry + /// + /// The size. + public static int GetSize() + { + return 16; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(unk_float1); + bw.Write(unk_float2); + bw.Write(unk_int1); + bw.Write(unk_int2); + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/M2/Entries/EDGFEntry.cs b/Warcraft.NET/Files/M2/Entries/EDGFEntry.cs new file mode 100644 index 0000000..5238753 --- /dev/null +++ b/Warcraft.NET/Files/M2/Entries/EDGFEntry.cs @@ -0,0 +1,62 @@ +using System; +using System.IO; + +namespace Warcraft.NET.Files.M2.Entries +{ + public class EDGFEntry + { + public float[] _0x0; + public float _0x8; + public byte[] _0xC; + + /// + /// Initializes a new instance of the class. + /// + public EDGFEntry() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public EDGFEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + _0x0 = new float[2]; + _0x0[0] = br.ReadSingle(); + _0x0[1] = br.ReadSingle(); + _0x8 = br.ReadSingle(); + _0xC = br.ReadBytes(4); + } + } + + /// + /// Gets the size of a EDGF Entry + /// + /// The size. + public static int GetSize() + { + return 16; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(_0x0[0]); + bw.Write(_0x0[1]); + bw.Write(_0x8); + bw.Write(_0xC); + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/M2/Entries/EXPTEntry.cs b/Warcraft.NET/Files/M2/Entries/EXPTEntry.cs new file mode 100644 index 0000000..858929b --- /dev/null +++ b/Warcraft.NET/Files/M2/Entries/EXPTEntry.cs @@ -0,0 +1,59 @@ +using System.IO; + +namespace Warcraft.NET.Files.M2.Entries +{ + public class EXPTEntry + { + public float zSource; + public float colorMult; + public float alphaMult; + + + /// + /// Initializes a new instance of the class. + /// + public EXPTEntry() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public EXPTEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + zSource = br.ReadSingle(); + colorMult = br.ReadSingle(); + alphaMult = br.ReadSingle(); + } + } + + /// + /// Gets the size of a animation file id entry. + /// + /// The size. + public static int GetSize() + { + return 12; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(zSource); + bw.Write(colorMult); + bw.Write(alphaMult); + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/M2/Entries/LDV1Entry.cs b/Warcraft.NET/Files/M2/Entries/LDV1Entry.cs new file mode 100644 index 0000000..e502496 --- /dev/null +++ b/Warcraft.NET/Files/M2/Entries/LDV1Entry.cs @@ -0,0 +1,66 @@ +using System; +using System.IO; + +namespace Warcraft.NET.Files.M2.Entries +{ + public class LDV1Entry + { + public UInt16 unk0; + public UInt16 lodCount; //maxLod = lodCount-1; + float unk2_f; + public byte[] particleBoneLod; //lod serves as indes into this array + public UInt32 unk4; + + + /// + /// Initializes a new instance of the class. + /// + public LDV1Entry() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public LDV1Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + unk0 = br.ReadUInt16(); + lodCount = br.ReadUInt16(); + unk2_f = br.ReadSingle(); + particleBoneLod = br.ReadBytes(4); + unk4 = br.ReadUInt32(); + } + } + + /// + /// Gets the size of a LDV1 Entry + /// + /// The size. + public static int GetSize() + { + return 16; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(unk0); + bw.Write(lodCount); + bw.Write(unk2_f); + bw.Write(particleBoneLod); + bw.Write(unk4); + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/M2/Model.cs b/Warcraft.NET/Files/M2/Model.cs index 9c251bf..61b8a5d 100644 --- a/Warcraft.NET/Files/M2/Model.cs +++ b/Warcraft.NET/Files/M2/Model.cs @@ -2,6 +2,7 @@ using Warcraft.NET.Files.M2.Chunks; using Warcraft.NET.Files.M2.Chunks.BfA; using Warcraft.NET.Files.M2.Chunks.Legion; +using Warcraft.NET.Files.M2.Chunks.SL; namespace Warcraft.NET.Files.M2 { @@ -12,61 +13,100 @@ public class Model : ChunkedFile /// Gets or sets the model information /// [ChunkOrder(1)] - public MD21 ModelInformation { get; set; } + public MD21 ModelInformation { get; set; } + + [ChunkOptional] + public TXAC TXAC { get; set; } + + //[ChunkOptional] + //public PEDC PEDC { get; set; } + + + [ChunkOptional] + public EXPT EXP2 { get; set; } + [ChunkOptional] + public PGD1 PGD1 { get; set; } + /// - /// Gets or sets the model phys file ids + /// Gets or sets the model anim file ids /// - [ChunkOrder(2), ChunkOptional] - public PFID PhysFileIds { get; set; } + [ChunkOptional] + public AFID AnimFileIds { get; set; } + + /// + /// Gets or sets the model bone file ids + /// + [ChunkOptional] + public BFID BoneFileIds { get; set; } + + [ChunkOptional] + public LDV1 LDV1 { get; set; } + + [ChunkOptional] + public EDGF EDGF { get; set; } + + /// + /// Gets or sets the model physics + /// + [ChunkOptional] + public PFDC ModelPhysics { get; set; } + + [ChunkOptional] + public DBOC DBOC { get; set; } + + /// + /// Gets or sets the model skeleton file ids + /// + [ChunkOptional] + public SKID SkeletonFileIds { get; set; } /// /// Gets or sets the model skin file ids /// - [ChunkOrder(3), ChunkOptional] + [ChunkOptional] public SFID SkinFileIds { get; set; } /// - /// Gets or sets the model anim file ids + /// Gets or sets the model phys file ids /// - [ChunkOrder(4), ChunkOptional] - public AFID AnimFileIds { get; set; } + [ChunkOptional] + public PFID PhysFileIds { get; set; } /// - /// Gets or sets the model bone file ids + /// Gets or sets the texture file ids /// - [ChunkOrder(5), ChunkOptional] - public BFID BoneFileIds { get; set; } + [ChunkOptional] + public TXID TextureFileIds { get; set; } + + + //[ChunkOptional] + //public PSBC PSBC { get; set; } + + /// /// Gets or sets the model recursive particle file ids /// - [ChunkOrder(6), ChunkOptional] + [ChunkOptional] public RPID RecursiveParticleFileIds { get; set; } /// /// Gets or sets the model geometry particle file ids /// - [ChunkOrder(7), ChunkOptional] + [ChunkOptional] public GPID GeometryParticleFileIds { get; set; } - /// - /// Gets or sets the model skeleton file ids - /// - [ChunkOrder(8), ChunkOptional] - public SKID SkeletonFileIds { get; set; } - /// - /// Gets or sets the model texture file ids - /// - [ChunkOrder(9), ChunkOptional] - public TXID TextureFileIds { get; set; } + + /// /// Initializes a new instance of the class. /// public Model() { + } /// @@ -75,6 +115,7 @@ public Model() /// The binary data. public Model(byte[] inData) : base(inData) { + } public override bool IsReverseSignature() diff --git a/Warcraft.NET/Files/SKIN/Skin.cs b/Warcraft.NET/Files/SKIN/Skin.cs new file mode 100644 index 0000000..42f6f6f --- /dev/null +++ b/Warcraft.NET/Files/SKIN/Skin.cs @@ -0,0 +1,52 @@ +using System; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.phys.Chunks; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys +{ + [AutoDocFile("skin")] + public class Skin + { + + public UInt32 magic; + + public M2Array vertices; + public M2Array indices; + public M2Array bones; + public M2Array submeshes; + public M2Array batches; + public UInt32 globalVertexOffset; + public M2Array shadow_batches; + + public UInt32 unk0; + public UInt32 unk1; + + + + public Skin(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + magic = br.ReadUInt32(); + vertices = new M2Array(br.ReadUInt32(),br.ReadUInt32()); + indices = new M2Array(br.ReadUInt32(), br.ReadUInt32()); + bones = new M2Array(br.ReadUInt32(), br.ReadUInt32()); + submeshes = new M2Array(br.ReadUInt32(), br.ReadUInt32()); + batches = new M2Array(br.ReadUInt32(), br.ReadUInt32()); + globalVertexOffset = br.ReadUInt32(); + shadow_batches = new M2Array(br.ReadUInt32(), br.ReadUInt32()); + unk0 = br.ReadUInt32(); + unk1 = br.ReadUInt32(); + } + } + + byte[] Serialize() + { + + } + } + +} diff --git a/Warcraft.NET/Files/Structures/C3Vector.cs b/Warcraft.NET/Files/Structures/C3Vector.cs new file mode 100644 index 0000000..5f925ec --- /dev/null +++ b/Warcraft.NET/Files/Structures/C3Vector.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.Structures +{ + /// + /// A structure representing a 3D vector of floats. + /// + public struct C3Vector : IFlattenableData + { + public float X { get; set; } + public float Y { get; set; } + public float Z { get; set; } + + public C3Vector(float inX, float inY, float inZ) + { + X = inX; + Y = inY; + Z = inZ; + } + + public Vector3 asVec3(){ + return new Vector3(X,Y,Z); + } + + public byte[] asBytes(){ + return BitConverter.GetBytes(X).Concat(BitConverter.GetBytes(Y)).Concat(BitConverter.GetBytes(Z)).ToArray(); + } + + public C3Vector(byte[] input) + { + if (input.Length == 12) + { + X = BitConverter.ToSingle(input,0); + Y = BitConverter.ToSingle(input,4); + Z = BitConverter.ToSingle(input,8); + } + } + + /// + public override string ToString() + { + return $"{X}, {Y}, {Z}"; + } + + public IReadOnlyCollection Flatten() + { + return new[] { X, Y, Z }; + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/Structures/Mat3x4.cs b/Warcraft.NET/Files/Structures/Mat3x4.cs new file mode 100644 index 0000000..0b28133 --- /dev/null +++ b/Warcraft.NET/Files/Structures/Mat3x4.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Structures; +using System.Numerics; + +public class Mat3x4 : IFlattenableData +{ + + public C3Vector a { get; set; } + public C3Vector b { get; set; } + public C3Vector c { get; set; } + public C3Vector d { get; set; } + + public Mat3x4(byte[] input) + { + if (input.Length == 48) + { + a = new C3Vector(input.Take(12).ToArray()); + b = new C3Vector(input.Skip(12).Take(12).ToArray()); + c = new C3Vector(input.Skip(24).Take(12).ToArray()); + d = new C3Vector(input.Skip(36).Take(12).ToArray()); + + } + } + + public Mat3x4(float[] input) + { + if (input.Length == 12) + { + a = new C3Vector(input[0], input[1], input[2]); + b = new C3Vector(input[3], input[4], input[5]); + c = new C3Vector(input[6], input[7], input[8]); + d = new C3Vector(input[9], input[10], input[11]); + } + } + public Mat3x4(C3Vector _a, C3Vector _b, C3Vector _c, C3Vector _d) + { + a = _a; + b = _b; + c = _c; + d = _d; + } + + public byte[] asBytes(){ + return a.asBytes().Concat(b.asBytes()).Concat(c.asBytes()).Concat(d.asBytes()).ToArray(); + } + + public IReadOnlyCollection Flatten() + { + return new[] { a.X, a.Y, a.Z, b.X, b.Y, b.Z, c.X, c.Y, c.Z, d.X, d.Y, d.Z }; + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Chunks/BDY4.cs b/Warcraft.NET/Files/phys/Chunks/BDY4.cs new file mode 100644 index 0000000..ef7a3bd --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/BDY4.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.phys.Entries; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class BDY4 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "BDY4"; + + /// + /// Gets or Sets the version of the physics + /// + public List bdy4Entries = new(); + + /// + /// Initializes a new instance of + /// + public BDY4() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public BDY4(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var bdy4count = br.BaseStream.Length / BDY4Entry.GetSize(); + + for (var i = 0; i < bdy4count; ++i) + { + bdy4Entries.Add(new BDY4Entry(br.ReadBytes(BDY4Entry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (BDY4Entry obj in bdy4Entries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/BOXS.cs b/Warcraft.NET/Files/phys/Chunks/BOXS.cs new file mode 100644 index 0000000..b4e2c87 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/BOXS.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class BOXS : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "BOXS"; + + public List BOXSEntries = new(); + + + /// + /// Initializes a new instance of + /// + public BOXS() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public BOXS(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var boxscount = br.BaseStream.Length / BOXSEntry.GetSize(); + + for (var i = 0; i < boxscount; ++i) + { + BOXSEntries.Add(new BOXSEntry(br.ReadBytes(BOXSEntry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (BOXSEntry obj in BOXSEntries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/CAPS.cs b/Warcraft.NET/Files/phys/Chunks/CAPS.cs new file mode 100644 index 0000000..d7286e4 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/CAPS.cs @@ -0,0 +1,70 @@ +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Structures; +using System.Collections.Generic; +using Warcraft.NET.Files.phys.Entries; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class CAPS : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "CAPS"; + + public List CAPSEntries = new(); + + + /// + /// Initializes a new instance of + /// + public CAPS() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public CAPS(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var capscount = br.BaseStream.Length / CAPSEntry.GetSize(); + + for (var i = 0; i < capscount; ++i) + { + CAPSEntries.Add(new CAPSEntry(br.ReadBytes(CAPSEntry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (CAPSEntry obj in CAPSEntries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + + + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/DSTJ.cs b/Warcraft.NET/Files/phys/Chunks/DSTJ.cs new file mode 100644 index 0000000..63731a9 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/DSTJ.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class DSTJ : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "DSTJ"; + + public List DSTJEntries = new(); + + /// + /// Initializes a new instance of + /// + public DSTJ() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public DSTJ(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var DSTJcount = br.BaseStream.Length / DSTJEntry.GetSize(); + + for (var i = 0; i < DSTJcount; ++i) + { + DSTJEntries.Add(new DSTJEntry(br.ReadBytes(DSTJEntry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (DSTJEntry obj in DSTJEntries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + + + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/JOIN.cs b/Warcraft.NET/Files/phys/Chunks/JOIN.cs new file mode 100644 index 0000000..94330a0 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/JOIN.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class JOIN : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "JOIN"; + + public List JOINEntries = new(); + + /// + /// Initializes a new instance of + /// + public JOIN() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public JOIN(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var JOINcount = br.BaseStream.Length / JOINEntry.GetSize(); + + for (var i = 0; i < JOINcount; ++i) + { + JOINEntries.Add(new JOINEntry(br.ReadBytes(JOINEntry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (JOINEntry obj in JOINEntries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + + + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/PHYS.cs b/Warcraft.NET/Files/phys/Chunks/PHYS.cs new file mode 100644 index 0000000..4f98688 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/PHYS.cs @@ -0,0 +1,58 @@ +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class PHYS : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PHYS"; + + /// + /// Gets or Sets the version of the physics + /// + public ushort version; + + /// + /// Initializes a new instance of + /// + public PHYS() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PHYS(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + version = br.ReadUInt16(); + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(version); + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/PHYT.cs b/Warcraft.NET/Files/phys/Chunks/PHYT.cs new file mode 100644 index 0000000..9d0e48e --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/PHYT.cs @@ -0,0 +1,58 @@ +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class PHYT : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PHYT"; + + /// + /// Gets or Sets the version of the physics + /// + public uint phyt; + + /// + /// Initializes a new instance of + /// + public PHYT() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PHYT(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + phyt = br.ReadUInt32(); + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(phyt); + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/PHYV.cs b/Warcraft.NET/Files/phys/Chunks/PHYV.cs new file mode 100644 index 0000000..5d22e0b --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/PHYV.cs @@ -0,0 +1,74 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.phys.Entries; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class PHYV : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PHYV"; + + /// + /// Gets or Sets the version of the physics + /// + public float[] values; + + /// + /// Initializes a new instance of + /// + public PHYV() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PHYV(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var PHYVcount = br.BaseStream.Length / 24; + values = new float[PHYVcount * 6]; + for (var i = 0; i < PHYVcount; ++i) + { + values[i] = br.ReadSingle(); + values[i+1] = br.ReadSingle(); + values[i+2] = br.ReadSingle(); + values[i+3] = br.ReadSingle(); + values[i+4] = br.ReadSingle(); + values[i+5] = br.ReadSingle(); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (float f in values) + { + bw.Write(f); + } + return ms.ToArray(); + } + } + + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/PLYT.cs b/Warcraft.NET/Files/phys/Chunks/PLYT.cs new file mode 100644 index 0000000..d3d9418 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/PLYT.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class PLYT : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PLYT"; + + public List PLYTEntries = new(); + + /// + /// Initializes a new instance of + /// + public PLYT() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PLYT(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + + var PLYTcount = br.ReadUInt32(); + + for (var i = 0; i < PLYTcount; ++i) + { + PLYTEntry plyt_entry = new PLYTEntry + { + header = new PLYTEntry.PLYT_HEADER + { + vertexCount = br.ReadUInt32(), + unk_04 = br.ReadBytes(4), + RUNTIME_08_ptr_data_0 = br.ReadUInt64(), + count_10 = br.ReadUInt32(), + unk_14 = br.ReadBytes(4), + RUNTIME_18_ptr_data_1 = br.ReadUInt64(), + RUNTIME_20_ptr_data_2 = br.ReadUInt64(), + nodeCount = br.ReadUInt32(), + unk_2C = br.ReadBytes(4), + RUNTIME_30_ptr_data_3 = br.ReadUInt64(), + unk_38 = new float[6] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle() } + } + }; + + PLYTEntries.Add(plyt_entry); + } + for (var j = 0; j < PLYTcount; j++) + { + PLYTEntry entry = PLYTEntries[j]; + uint vcount = entry.header.vertexCount; + uint count_10 = entry.header.count_10; + uint nodeCount = entry.header.nodeCount; + + entry.data.vertices = new C3Vector[vcount]; + for (int v = 0; v < vcount; v++) + { + entry.data.vertices[v] = new C3Vector(br.ReadBytes(12)); + } + entry.data.unk1 = br.ReadBytes((int)count_10 * 16); + entry.data.unk2 = br.ReadBytes((int)count_10); + entry.data.nodes = new PLYTEntry.NODE[nodeCount]; + for (int n = 0; n < nodeCount; n++) + { + PLYTEntry.NODE node = new PLYTEntry.NODE(); + node.unk = br.ReadByte(); + node.vertexIndex = br.ReadByte(); + node.unkIndex0 = br.ReadByte(); + node.unkIndex1 = br.ReadByte(); + entry.data.nodes[n] = node; + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write((UInt32)PLYTEntries.Count); + foreach (PLYTEntry obj in PLYTEntries) + { + Console.WriteLine("Writing Plyt Header Length: "+ obj.SerializeHeader().Length); + bw.Write(obj.SerializeHeader()); + } + foreach (PLYTEntry obj in PLYTEntries) + { + bw.Write(obj.SerializeData()); + Console.WriteLine("Writing Plyt Data Length:" + obj.SerializeData().Length); + } + return ms.ToArray(); + } + + + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/PRS2.cs b/Warcraft.NET/Files/phys/Chunks/PRS2.cs new file mode 100644 index 0000000..1c4feb3 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/PRS2.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class PRS2 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PRS2"; + + public List PRS2Entries = new(); + + /// + /// Initializes a new instance of + /// + public PRS2() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PRS2(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var PRS2count = br.BaseStream.Length / PRS2Entry.GetSize(); + + for (var i = 0; i < PRS2count; ++i) + { + PRS2Entries.Add(new PRS2Entry(br.ReadBytes(PRS2Entry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (PRS2Entry obj in PRS2Entries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + + + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/REV2.cs b/Warcraft.NET/Files/phys/Chunks/REV2.cs new file mode 100644 index 0000000..2024f40 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/REV2.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class REV2 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "REV2"; + + public List REV2Entries = new(); + + /// + /// Initializes a new instance of + /// + public REV2() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public REV2(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var REV2count = br.BaseStream.Length / REV2Entry.GetSize(); + + for (var i = 0; i < REV2count; ++i) + { + REV2Entries.Add(new REV2Entry(br.ReadBytes(REV2Entry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (REV2Entry obj in REV2Entries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + + + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/SHJ2.cs b/Warcraft.NET/Files/phys/Chunks/SHJ2.cs new file mode 100644 index 0000000..757a5ad --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/SHJ2.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class SHJ2 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "SHJ2"; + + public List SHJ2Entries = new(); + + /// + /// Initializes a new instance of + /// + public SHJ2() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public SHJ2(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var SHJ2count = br.BaseStream.Length / SHJ2Entry.GetSize(); + + for (var i = 0; i < SHJ2count; ++i) + { + SHJ2Entries.Add(new SHJ2Entry(br.ReadBytes(SHJ2Entry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (SHJ2Entry obj in SHJ2Entries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + + + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/SHOJ.cs b/Warcraft.NET/Files/phys/Chunks/SHOJ.cs new file mode 100644 index 0000000..4adde28 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/SHOJ.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class SHOJ : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "SHOJ"; + + public List SHOJEntries = new(); + + /// + /// Initializes a new instance of + /// + public SHOJ() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public SHOJ(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var SHOJcount = br.BaseStream.Length / SHOJEntry.GetSize(); + + for (var i = 0; i < SHOJcount; ++i) + { + SHOJEntries.Add(new SHOJEntry(br.ReadBytes(SHOJEntry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (SHOJEntry obj in SHOJEntries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + + + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/SHP2.cs b/Warcraft.NET/Files/phys/Chunks/SHP2.cs new file mode 100644 index 0000000..948105c --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/SHP2.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class SHP2 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "SHP2"; + + public List SHP2Entries = new(); + + /// + /// Initializes a new instance of + /// + public SHP2() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public SHP2(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var SHP2count = br.BaseStream.Length / SHP2Entry.GetSize(); + + for (var i = 0; i < SHP2count; ++i) + { + SHP2Entries.Add(new SHP2Entry(br.ReadBytes(SHP2Entry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (SHP2Entry obj in SHP2Entries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + + + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/SPHJ.cs b/Warcraft.NET/Files/phys/Chunks/SPHJ.cs new file mode 100644 index 0000000..2f8fa97 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/SPHJ.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class SPHJ : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "SPHJ"; + + public List SPHJEntries = new(); + + /// + /// Initializes a new instance of + /// + public SPHJ() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public SPHJ(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var SPHJcount = br.BaseStream.Length / SPHJEntry.GetSize(); + + for (var i = 0; i < SPHJcount; ++i) + { + SPHJEntries.Add(new SPHJEntry(br.ReadBytes(SPHJEntry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (SPHJEntry obj in SPHJEntries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + + + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/SPHS.cs b/Warcraft.NET/Files/phys/Chunks/SPHS.cs new file mode 100644 index 0000000..4798579 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/SPHS.cs @@ -0,0 +1,67 @@ +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class SPHS : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "SPHS"; + + /// + /// Gets or Sets the local position of the Sphere shape + /// + public C3Vector localPosition; + + /// + /// Gets or Sets the radius of the Sphere shape + /// + public float radius; + + /// + /// Initializes a new instance of + /// + public SPHS() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public SPHS(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + localPosition = new C3Vector(br.ReadBytes(12)); + radius = br.ReadSingle(); + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(localPosition.asBytes()); + bw.Write(radius); + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/WLJ3.cs b/Warcraft.NET/Files/phys/Chunks/WLJ3.cs new file mode 100644 index 0000000..086d177 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/WLJ3.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class WLJ3 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "WLJ3"; + + public List WLJ3Entries = new(); + + /// + /// Initializes a new instance of + /// + public WLJ3() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public WLJ3(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var WLJ3count = br.BaseStream.Length / WLJ3Entry.GetSize(); + + for (var i = 0; i < WLJ3count; ++i) + { + WLJ3Entries.Add(new WLJ3Entry(br.ReadBytes(WLJ3Entry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (WLJ3Entry obj in WLJ3Entries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + + + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs b/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs new file mode 100644 index 0000000..e147c77 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs @@ -0,0 +1,92 @@ +using System.IO; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Entries +{ + public class BDY4Entry + { + + public ushort type { get; set; } // maps to dmBodyDef type enum. 0 -> 1, 1 -> 0 = dm_dynamicBody, * -> 2. Only one should be of type 0 (root). possibly only 0 and 1. + public ushort boneIndex { get; set; } + public C3Vector position { get; set; } + public ushort shapeIndex { get; set; } + public byte[] PADDING { get; set; } + public int shapesCount { get; set; } // shapes_count shapes are in this body. + public float unk0 { get; set; } + //#if version >= 3 // BDY3 + public float _x1c { get; set; } // default 1.0 + public float drag { get; set; } // default 0, maybe incorrect + public float unk1; // default 0, seems to be some sort of weight. + // If version >= 3 and unk1 == 0 the body will be non kinematic even if the flag is set, it needs to get its transform from the parent bone. + // See offhand_1h_artifactskulloferedar_d_06 where all the bodies have the kinematic flag + public float _x28 { get; set; } // default 0.89999998 + + public byte[] x2c { get; set; }// default 0x00000000 + + + /// + /// Initializes a new instance of the class. + /// + public BDY4Entry(){} + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public BDY4Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + type = br.ReadUInt16(); + boneIndex = br.ReadUInt16(); + position = new C3Vector(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); + shapeIndex = br.ReadUInt16(); + PADDING = br.ReadBytes(2); + shapesCount = br.ReadInt32(); + unk0 = br.ReadSingle(); + _x1c = br.ReadSingle(); + drag = br.ReadSingle(); + unk1 = br.ReadSingle(); + _x28 = br.ReadSingle(); + x2c = br.ReadBytes(4); + } + } + + /// + /// Gets the size of a bdy4 entry. + /// + /// The size. + public static int GetSize() + { + return 48; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(type); + bw.Write(boneIndex); + bw.Write(position.X); + bw.Write(position.Y); + bw.Write(position.Z); + bw.Write(shapeIndex); + bw.Write(PADDING); + bw.Write(shapesCount); + bw.Write(unk0); + bw.Write(_x1c); + bw.Write(drag); + bw.Write(unk1); + bw.Write(_x28); + bw.Write(x2c); + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/BOXSEntry.cs b/Warcraft.NET/Files/phys/Entries/BOXSEntry.cs new file mode 100644 index 0000000..cc0b3fc --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/BOXSEntry.cs @@ -0,0 +1,53 @@ +using System.IO; +using Warcraft.NET.Files.phys.Chunks; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Entries +{ + public class BOXSEntry + { + /// + /// Gets or Sets the matrix of the box shape + /// + public Mat3x4 a; + + /// + /// Gets or Sets the local position of the box shape + /// + public C3Vector c; + + public BOXSEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + a = new Mat3x4(br.ReadBytes(48)); + c = new C3Vector(br.ReadBytes(12)); + } + } + /// + /// Gets the size of a box entry. + /// + /// The size. + public static int GetSize() + { + return 60; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(a.asBytes()); + bw.Write(c.asBytes()); + } + + return ms.ToArray(); + } + } + + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/CAPSEntry.cs b/Warcraft.NET/Files/phys/Entries/CAPSEntry.cs new file mode 100644 index 0000000..05e86db --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/CAPSEntry.cs @@ -0,0 +1,57 @@ +using System.IO; +using Warcraft.NET.Files.phys.Chunks; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Entries +{ + public class CAPSEntry + { + + /// + /// Gets or Sets the local start position of the capsule shape + /// + public C3Vector localPosition1; + + /// + /// Gets or Sets the local end position of the capsule shape + /// + public C3Vector localPosition2; + + /// + /// Gets or Sets the radius of the capsule shape + /// + public float radius; + + public CAPSEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + localPosition1 = new C3Vector(br.ReadBytes(12)); + localPosition2 = new C3Vector(br.ReadBytes(12)); + radius = br.ReadSingle(); + } + } + /// + /// Gets the size of a caps entry. + /// + /// The size. + public static int GetSize() + { + return 28; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(localPosition1.asBytes()); + bw.Write(localPosition2.asBytes()); + bw.Write(radius); + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/DSTJEntry.cs b/Warcraft.NET/Files/phys/Entries/DSTJEntry.cs new file mode 100644 index 0000000..add4cee --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/DSTJEntry.cs @@ -0,0 +1,62 @@ +using System; +using System.IO; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Entries +{ + public class DSTJEntry + { + + + public C3Vector localAnchorA; + public C3Vector localAnchorB; + + public float some_distance_factor; + + + /// + /// Initializes a new instance of the class. + /// + public DSTJEntry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public DSTJEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + localAnchorA = new C3Vector(br.ReadBytes(12)); + localAnchorB = new C3Vector(br.ReadBytes(12)); + some_distance_factor = br.ReadSingle(); + } + } + + /// + /// Gets the size of a DSTJ entry. + /// + /// The size. + public static int GetSize() + { + return 28; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(localAnchorA.asBytes()); + bw.Write(localAnchorB.asBytes()); + bw.Write(some_distance_factor); + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/JOINEntry.cs b/Warcraft.NET/Files/phys/Entries/JOINEntry.cs new file mode 100644 index 0000000..6df6551 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/JOINEntry.cs @@ -0,0 +1,68 @@ +using System; +using System.IO; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Entries +{ + public class JOINEntry + { + + + public uint bodyAIdx; + public uint bodyBIdx; + public byte[] unk; + + public ushort jointType; + public ushort jointId; + + /// + /// Initializes a new instance of the class. + /// + public JOINEntry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public JOINEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + bodyAIdx = br.ReadUInt32(); + bodyBIdx = br.ReadUInt32(); + unk = br.ReadBytes(4); + jointType = br.ReadUInt16(); + jointId = br.ReadUInt16(); + } + } + + /// + /// Gets the size of a JOIN entry. + /// + /// The size. + public static int GetSize() + { + return 16; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(bodyAIdx); + bw.Write(bodyBIdx); + bw.Write(unk); + bw.Write(jointType); + bw.Write(jointId); + + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs b/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs new file mode 100644 index 0000000..0f784c3 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs @@ -0,0 +1,132 @@ +using System; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Entries +{ + public class PLYTEntry + { + public PLYT_HEADER header; + public PLYT_DATA data; + + [Serializable] + public struct PLYT_HEADER + { + public UInt32 vertexCount; // Mostly 8 + public byte[] unk_04; + public UInt64 RUNTIME_08_ptr_data_0; // = &data[i].unk_0 + public UInt32 count_10; // Mostly 6 + public byte[] unk_14; + public UInt64 RUNTIME_18_ptr_data_1; // = &data[i].unk_1 + public UInt64 RUNTIME_20_ptr_data_2; // = &data[i].unk_2 + public UInt32 nodeCount; // Mostly 24 + public byte[] unk_2C; + public UInt64 RUNTIME_30_ptr_data_3; // = &data[i].unk_3 + public float[] unk_38; // not sure if floats: has e-08 values + } + + [Serializable] + public struct PLYT_DATA + { + public C3Vector[] vertices; //amount = vertexCount in header + public byte[] unk1; //multiple of 16 -> amount = count_10 in header + public byte[] unk2; //amount = count_10 in header + public NODE[] nodes;//amount = node_count in header + } + + [Serializable] + public struct NODE + { + public byte unk; // 1 or -1 + public byte vertexIndex; // index in vertex list + public byte unkIndex0; // index into the nodes + public byte unkIndex1; // index into the nodes + } + + /// + /// Initializes a new instance of the class. + /// + public PLYTEntry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public PLYTEntry(byte[] data) + { + + } + + /// + /// Gets the size of a PLYT entry. + /// + /// The size. + public static int GetSize() + { + return 0; + } + + /// + public byte[] SerializeHeader(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + + bw.Write(header.vertexCount); + bw.Write(header.unk_04); + + bw.Write(header.RUNTIME_08_ptr_data_0); + + bw.Write(header.count_10); + bw.Write(header.unk_14); + + bw.Write(header.RUNTIME_18_ptr_data_1); + + bw.Write(header.RUNTIME_20_ptr_data_2); + + bw.Write(header.nodeCount); + + bw.Write(header.unk_2C); + + bw.Write(header.RUNTIME_30_ptr_data_3); + foreach (float f in header.unk_38) + { + bw.Write(f); + } + + + } + return ms.ToArray(); + } + } + public byte[] SerializeData(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + foreach (var vertex in data.vertices) + { + bw.Write(vertex.asBytes()); + } + bw.Write(data.unk1); + bw.Write(data.unk2); + foreach (var node in data.nodes) + { + bw.Write(node.unk); + bw.Write(node.vertexIndex); + bw.Write(node.unkIndex0); + bw.Write(node.unkIndex1); + } + } + return ms.ToArray(); + } + } + + + } +} diff --git a/Warcraft.NET/Files/phys/Entries/PRS2Entry.cs b/Warcraft.NET/Files/phys/Entries/PRS2Entry.cs new file mode 100644 index 0000000..de4420c --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/PRS2Entry.cs @@ -0,0 +1,83 @@ +using System; +using System.IO; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Entries +{ + public class PRS2Entry + { + + + public Mat3x4 frameA; + public Mat3x4 frameB; + public float lowerLimit; + public float upperLimit; + public float _68; + public float maxMotorForce; + public float _70; + public UInt32 motorMode; + + public float motorFrequencyHz; + public float motorDampingRatio; + + + /// + /// Initializes a new instance of the class. + /// + public PRS2Entry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public PRS2Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + frameA = new Mat3x4(br.ReadBytes(48)); + frameB = new Mat3x4(br.ReadBytes(48)); + lowerLimit = br.ReadSingle(); + upperLimit = br.ReadSingle(); + _68 = br.ReadSingle(); + maxMotorForce = br.ReadSingle(); + _70 = br.ReadSingle(); + motorMode = br.ReadUInt32(); + motorFrequencyHz = br.ReadSingle(); + motorDampingRatio = br.ReadSingle(); + } + } + + /// + /// Gets the size of a PRS2 entry. + /// + /// The size. + public static int GetSize() + { + return 128; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(frameA.asBytes()); + bw.Write(frameB.asBytes()); + bw.Write(lowerLimit); + bw.Write(upperLimit); + bw.Write(_68); + bw.Write(maxMotorForce); + bw.Write(_70); + bw.Write(motorMode); + bw.Write(motorFrequencyHz); + bw.Write(motorDampingRatio); + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/REV2Entry.cs b/Warcraft.NET/Files/phys/Entries/REV2Entry.cs new file mode 100644 index 0000000..b1ef402 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/REV2Entry.cs @@ -0,0 +1,76 @@ +using System; +using System.IO; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Entries +{ + public class REV2Entry + { + public Mat3x4 frameA; + public Mat3x4 frameB; + public float lowerAngle; + public float upperAngle; + + public float maxMotorTorque; + public UInt32 motorMode; // 1: motorPositionMode → frequency > 0, 2: motorVelocityMode + + public float motorFrequencyHz; + public float motorDampingRatio; + + + /// + /// Initializes a new instance of the class. + /// + public REV2Entry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public REV2Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + frameA = new Mat3x4(br.ReadBytes(48)); + frameB = new Mat3x4(br.ReadBytes(48)); + lowerAngle = br.ReadSingle(); + upperAngle = br.ReadSingle(); + maxMotorTorque = br.ReadSingle(); + motorMode = br.ReadUInt32(); + motorFrequencyHz = br.ReadSingle(); + motorDampingRatio = br.ReadSingle(); + } + } + + /// + /// Gets the size of a REV2 entry. + /// + /// The size. + public static int GetSize() + { + return 120; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(frameA.asBytes()); + bw.Write(frameB.asBytes()); + bw.Write(lowerAngle); + bw.Write(upperAngle); + bw.Write(maxMotorTorque); + bw.Write(motorMode); + bw.Write(motorFrequencyHz); + bw.Write(motorDampingRatio); + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs b/Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs new file mode 100644 index 0000000..cdd41f5 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs @@ -0,0 +1,80 @@ +using System; +using System.IO; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Entries +{ + public class SHJ2Entry + { + + + public Mat3x4 frameA; + public Mat3x4 frameB; + public float lowerTwistAngle; + public float upperTwistAngle; + public float coneAngle; + public float maxMotorTorque; + public UInt32 motorMode; // NO BACKWARDS COMPATIBILITY as of Legion (7.0.1.20979) and Legion (7.3.0.24931)! client always assumes new size! + + public float motorFrequencyHz; + public float motorDampingRatio; + + + /// + /// Initializes a new instance of the class. + /// + public SHJ2Entry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public SHJ2Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + frameA = new Mat3x4(br.ReadBytes(48)); + frameB = new Mat3x4(br.ReadBytes(48)); + lowerTwistAngle = br.ReadSingle(); + upperTwistAngle = br.ReadSingle(); + coneAngle = br.ReadSingle(); + maxMotorTorque = br.ReadSingle(); + motorMode = br.ReadUInt32(); + motorFrequencyHz = br.ReadSingle(); + motorDampingRatio = br.ReadSingle(); + } + } + + /// + /// Gets the size of a SHJ2 entry. + /// + /// The size. + public static int GetSize() + { + return 124; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(frameA.asBytes()); + bw.Write(frameB.asBytes()); + bw.Write(lowerTwistAngle); + bw.Write(upperTwistAngle); + bw.Write(coneAngle); + bw.Write(maxMotorTorque); + bw.Write(motorMode); + bw.Write(motorFrequencyHz); + bw.Write(motorDampingRatio); + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/SHOJEntry.cs b/Warcraft.NET/Files/phys/Entries/SHOJEntry.cs new file mode 100644 index 0000000..5218b7a --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/SHOJEntry.cs @@ -0,0 +1,73 @@ +using System; +using System.IO; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Entries +{ + public class SHOJEntry + { + + + public Mat3x4 frameA; + public Mat3x4 frameB; + public float lowerTwistAngle; + public float upperTwistAngle; + public float coneAngle; + public float maxMotorTorque; + public UInt32 motorMode; // NO BACKWARDS COMPATIBILITY as of Legion (7.0.1.20979) and Legion (7.3.0.24931)! client always assumes new size! + + + /// + /// Initializes a new instance of the class. + /// + public SHOJEntry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public SHOJEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + frameA = new Mat3x4(br.ReadBytes(48)); + frameB = new Mat3x4(br.ReadBytes(48)); + lowerTwistAngle = br.ReadSingle(); + upperTwistAngle = br.ReadSingle(); + coneAngle = br.ReadSingle(); + maxMotorTorque = br.ReadSingle(); + motorMode = br.ReadUInt32(); + } + } + + /// + /// Gets the size of a SHOJ entry. + /// + /// The size. + public static int GetSize() + { + return 116; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(frameA.asBytes()); + bw.Write(frameB.asBytes()); + bw.Write(lowerTwistAngle); + bw.Write(upperTwistAngle); + bw.Write(coneAngle); + bw.Write(maxMotorTorque); + bw.Write(motorMode); + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/SHP2Entry.cs b/Warcraft.NET/Files/phys/Entries/SHP2Entry.cs new file mode 100644 index 0000000..a3f8057 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/SHP2Entry.cs @@ -0,0 +1,93 @@ +using System; +using System.IO; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Entries +{ + public class SHP2Entry + { + + + /*0x00*/ + public ushort shapeType; + /*0x02*/ + public ushort shapeIndex; // into the corresponding chunk + /*0x04*/ + public byte[] unk; + /*0x08*/ + public float friction; + /*0x0c*/ + public float restitution; + /*0x10*/ + public float density; + /*0x14*/ + public UInt32 _x14; // default 0 + /*0x18*/ + public float _x18; // default 1.0 + /*0x1c*/ + public UInt16 _x1c; // default 0 + /*0x1e*/ + public UInt16 _x1e; // no default, padding? + + + + /// + /// Initializes a new instance of the class. + /// + public SHP2Entry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public SHP2Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + shapeType = br.ReadUInt16(); + shapeIndex = br.ReadUInt16(); + unk = br.ReadBytes(4); + friction = br.ReadSingle(); + restitution = br.ReadSingle(); + density = br.ReadSingle(); + _x14 = br.ReadUInt32(); + _x18 = br.ReadSingle(); + _x1c = br.ReadUInt16(); + _x1e = br.ReadUInt16(); + } + } + + /// + /// Gets the size of a SHP2 entry. + /// + /// The size. + public static int GetSize() + { + return 32; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(shapeType); + bw.Write(shapeIndex); + bw.Write(unk); + bw.Write(friction); + bw.Write(restitution); + bw.Write(density); + bw.Write(_x14); + bw.Write(_x18); + bw.Write(_x1c); + bw.Write(_x1e); + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/SPHJEntry.cs b/Warcraft.NET/Files/phys/Entries/SPHJEntry.cs new file mode 100644 index 0000000..a2a428d --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/SPHJEntry.cs @@ -0,0 +1,59 @@ +using System; +using System.IO; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Entries +{ + public class SPHJEntry + { + public C3Vector anchorA; + public C3Vector anchorB; + public float frictionTorque; + + + /// + /// Initializes a new instance of the class. + /// + public SPHJEntry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public SPHJEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + anchorA = new C3Vector(br.ReadBytes(12)); + anchorB = new C3Vector(br.ReadBytes(12)); + frictionTorque = br.ReadSingle(); + } + } + + /// + /// Gets the size of a SPHJ entry. + /// + /// The size. + public static int GetSize() + { + return 28; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(anchorA.asBytes()); + bw.Write(anchorB.asBytes()); + bw.Write(frictionTorque); + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs b/Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs new file mode 100644 index 0000000..56be673 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs @@ -0,0 +1,73 @@ +using System; +using System.IO; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.phys.Entries +{ + public class WLJ3Entry + { + public Mat3x4 frameA; + public Mat3x4 frameB; + public float angularFrequencyHz; + public float angularDampingRatio; + + public float linearFrequencyHz; // default 0 + public float linearDampingRatio; // default 0 + + public float unk70; + + + /// + /// Initializes a new instance of the class. + /// + public WLJ3Entry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public WLJ3Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + frameA = new Mat3x4(br.ReadBytes(48)); + frameB = new Mat3x4(br.ReadBytes(48)); + angularFrequencyHz = br.ReadSingle(); + angularDampingRatio = br.ReadSingle(); + linearFrequencyHz = br.ReadSingle(); + linearDampingRatio = br.ReadSingle(); + unk70 = br.ReadSingle(); + } + } + + /// + /// Gets the size of a WLJ3 entry. + /// + /// The size. + public static int GetSize() + { + return 116; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(frameA.asBytes()); + bw.Write(frameB.asBytes()); + bw.Write(angularFrequencyHz); + bw.Write(angularDampingRatio); + bw.Write(linearFrequencyHz); + bw.Write(linearDampingRatio); + bw.Write(unk70); + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Physics.cs b/Warcraft.NET/Files/phys/Physics.cs new file mode 100644 index 0000000..ee27189 --- /dev/null +++ b/Warcraft.NET/Files/phys/Physics.cs @@ -0,0 +1,87 @@ +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.phys.Chunks; + +namespace Warcraft.NET.Files.phys +{ + [AutoDocFile("phys")] + public class Physics : ChunkedFile + { + [ChunkOrder(1)] + public PHYS phys{get; set;} + + [ChunkOrder(2)] + public PHYT phyt{get; set;} + + [ChunkOptional] + public BOXS boxs{get;set;} + + [ChunkOptional] + public SPHS sphs{get;set;} + + [ChunkOptional] + public CAPS caps{get;set;} + + [ChunkOptional] + public PLYT plyt{get; set;} + + [ChunkOptional] + public SHP2 shp2{get; set;} + + [ChunkOptional] + public BDY4 bdy4{get; set;} + + + + + + + [ChunkOptional] + public SHOJ shoj { get; set; } + + [ChunkOptional] + public SHJ2 shj2{get; set;} + + + + [ChunkOptional] + public WLJ3 wlj3{get; set;} + + [ChunkOptional] + public SPHJ sphj{get; set;} + + + + + [ChunkOptional] + public PRS2 prs2{get; set;} + + [ChunkOptional] + public REV2 rev2{get; set;} + + [ChunkOptional] + public DSTJ dstj{get; set;} + + [ChunkOptional] + public JOIN join{get; set;} + + [ChunkOptional] + public PHYV phyv { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public Physics() + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// The binary data. + public Physics(byte[] inData) : base(inData) + { + + } + } +} \ No newline at end of file From e01d89592a57b76e1b06910fa7842fe3b57cf7bd Mon Sep 17 00:00:00 2001 From: gulasch7742 Date: Sat, 10 Aug 2024 20:03:25 +0200 Subject: [PATCH 02/15] yo --- Warcraft.NET.Docs/Program.cs | 18 +-- .../Files/M2/Chunks/{Legion => BfA}/LDV1.cs | 4 +- Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs | 62 +++++++++ Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs | 62 +++++++++ Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs | 58 ++++++++ Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs | 72 ++++++++++ Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs | 55 ++++++++ Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs | 55 ++++++++ Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs | 55 ++++++++ Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs | 2 +- Warcraft.NET/Files/M2/Chunks/SL/DETL.cs | 71 ++++++++++ Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs | 2 +- Warcraft.NET/Files/M2/Chunks/SL/NERF.cs | 73 ++++++++++ Warcraft.NET/Files/M2/Chunks/SL/WFV3.cs | 71 ++++++++++ Warcraft.NET/Files/M2/Entries/DETLEntry.cs | 65 +++++++++ Warcraft.NET/Files/M2/Entries/WFV3Entry.cs | 128 ++++++++++++++++++ Warcraft.NET/Files/M2/Model.cs | 102 +++++++++----- Warcraft.NET/Files/SKIN/Skin.cs | 2 +- Warcraft.NET/Files/Structures/CImVector.cs | 50 +++++++ Warcraft.NET/Files/phys/Entries/BDY4Entry.cs | 13 +- Warcraft.NET/Files/phys/Entries/JOINEntry.cs | 18 ++- Warcraft.NET/Files/phys/Entries/SHP2Entry.cs | 19 ++- Warcraft.NET/Files/phys/Physics.cs | 14 +- 23 files changed, 992 insertions(+), 79 deletions(-) rename Warcraft.NET/Files/M2/Chunks/{Legion => BfA}/LDV1.cs (92%) create mode 100644 Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/SL/DETL.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/SL/NERF.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/SL/WFV3.cs create mode 100644 Warcraft.NET/Files/M2/Entries/DETLEntry.cs create mode 100644 Warcraft.NET/Files/M2/Entries/WFV3Entry.cs create mode 100644 Warcraft.NET/Files/Structures/CImVector.cs diff --git a/Warcraft.NET.Docs/Program.cs b/Warcraft.NET.Docs/Program.cs index 867c66f..2ab861e 100644 --- a/Warcraft.NET.Docs/Program.cs +++ b/Warcraft.NET.Docs/Program.cs @@ -12,20 +12,6 @@ internal class Program /// static void Main(string[] args) { - string iripath = "C:\\Users\\marce\\Desktop\\WoWStuff\\wow.export\\creature\\iridikron\\"; - byte[] data = File.ReadAllBytes(iripath+"iridikron.m2"); - Model m = new Model(data); - - byte[] phys_test = File.ReadAllBytes("D:\\Unity Projects\\M2Tool\\M2Godot\\buckle_panstart_a_01.phys"); - Physics phys = new Physics(phys_test); - - File.WriteAllBytes(iripath+"iridikron_output.m2", m.Serialize()); - File.WriteAllBytes("D:\\Unity Projects\\M2Tool\\M2Godot\\buckle_panstart_a_01_output.phys", phys.Serialize()); - - - - if (1==2) { - Console.WriteLine($"BaseDirectory: {AppDomain.CurrentDomain.BaseDirectory}"); @@ -45,7 +31,7 @@ static void Main(string[] args) ConvertToMarkdownStep.Process(autoDocData, outputFolder); Console.WriteLine("Done!"); - } - } + + } } } \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/LDV1.cs b/Warcraft.NET/Files/M2/Chunks/BfA/LDV1.cs similarity index 92% rename from Warcraft.NET/Files/M2/Chunks/Legion/LDV1.cs rename to Warcraft.NET/Files/M2/Chunks/BfA/LDV1.cs index 92eb4eb..f640b86 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/LDV1.cs +++ b/Warcraft.NET/Files/M2/Chunks/BfA/LDV1.cs @@ -4,9 +4,9 @@ using Warcraft.NET.Files.Interfaces; using Warcraft.NET.Files.M2.Entries; -namespace Warcraft.NET.Files.M2.Chunks.Legion +namespace Warcraft.NET.Files.M2.Chunks.BfA { - [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterLegion, AutoDocChunkVersionHelper.VersionBeforeBfA)] public class LDV1 : IIFFChunk, IBinarySerializable { /// diff --git a/Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs b/Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs new file mode 100644 index 0000000..fbc23dc --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs @@ -0,0 +1,62 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.BfA +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterLegion, AutoDocChunkVersionHelper.VersionBeforeBfA)] + public class WFV1 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "WFV1"; + + public byte[] data; + + /// + /// Initializes a new instance of + /// + public WFV1() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public WFV1(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + data = inData; + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(data); + + + return ms.ToArray(); + } + } + + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs b/Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs new file mode 100644 index 0000000..af31db9 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs @@ -0,0 +1,62 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.BfA +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterLegion, AutoDocChunkVersionHelper.VersionBeforeBfA)] + public class WFV2 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "WFV2"; + + public byte[] data; + + /// + /// Initializes a new instance of + /// + public WFV2() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public WFV2(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + data = inData; + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(data); + + + return ms.ToArray(); + } + } + + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs b/Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs new file mode 100644 index 0000000..1fad62d --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs @@ -0,0 +1,58 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.DF +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterSL, AutoDocChunkVersionHelper.VersionBeforeDF)] + public class AFRA : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "AFRA"; + + /// + /// Initializes a new instance of + /// + public AFRA() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public AFRA(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + byte[] data; + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + data = inData; + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(data); + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs new file mode 100644 index 0000000..276cae0 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class PABC : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PABC"; + + /// + /// Gets or sets the Skin FileDataId + /// + public List PABCEntries = new(); + + /// + /// Initializes a new instance of + /// + public PABC() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PABC(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var PABCcount = br.BaseStream.Length / 2; + for (var i = 0; i < PABCcount; ++i) + { + PABCEntries.Add(br.ReadUInt16()); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (UInt16 obj in PABCEntries) + { + bw.Write(obj); + } + + return ms.ToArray(); + } + } + + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs new file mode 100644 index 0000000..e12ef1e --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs @@ -0,0 +1,55 @@ +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class PADC : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PADC"; + + byte[] data; + /// + /// Initializes a new instance of + /// + public PADC() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PADC(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + data = inData; + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(data); + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs new file mode 100644 index 0000000..372973a --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs @@ -0,0 +1,55 @@ +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class PEDC : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PEDC"; + + byte[] data; + /// + /// Initializes a new instance of + /// + public PEDC() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PEDC(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + data = inData; + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(data); + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs new file mode 100644 index 0000000..9070431 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs @@ -0,0 +1,55 @@ +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class PSBC : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PSBC"; + + byte[] data; + /// + /// Initializes a new instance of + /// + public PSBC() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PSBC(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + data = inData; + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(data); + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs b/Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs index cccf08c..7bf4c9e 100644 --- a/Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs +++ b/Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs @@ -6,7 +6,7 @@ namespace Warcraft.NET.Files.M2.Chunks.Legion { - [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class DBOC : IIFFChunk, IBinarySerializable { /// diff --git a/Warcraft.NET/Files/M2/Chunks/SL/DETL.cs b/Warcraft.NET/Files/M2/Chunks/SL/DETL.cs new file mode 100644 index 0000000..d9fa1ed --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/SL/DETL.cs @@ -0,0 +1,71 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.SL +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class DETL : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "DETL"; + + /// + /// Gets or sets the Skin FileDataId + /// + public List DETLEntries = new(); + + /// + /// Initializes a new instance of + /// + public DETL() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public DETL(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var DETLcount = br.BaseStream.Length / DETLEntry.GetSize(); + for (var i = 0; i < DETLcount; ++i) + { + DETLEntries.Add(new DETLEntry(br.ReadBytes(DETLEntry.GetSize()))); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (DETLEntry obj in DETLEntries) + { + bw.Write(obj.Serialize()); + } + + return ms.ToArray(); + } + } + + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs b/Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs index 311763c..d5a93d8 100644 --- a/Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs +++ b/Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs @@ -6,7 +6,7 @@ namespace Warcraft.NET.Files.M2.Chunks.Legion { - [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class EDGF : IIFFChunk, IBinarySerializable { /// diff --git a/Warcraft.NET/Files/M2/Chunks/SL/NERF.cs b/Warcraft.NET/Files/M2/Chunks/SL/NERF.cs new file mode 100644 index 0000000..8ebf09b --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/SL/NERF.cs @@ -0,0 +1,73 @@ +using System.Collections.Generic; +using System.IO; +using System.Numerics; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class NERF : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "NERF"; + + /// + /// Gets or sets the Skin FileDataId + /// + public List NERFEntries = new(); + + /// + /// Initializes a new instance of + /// + public NERF() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public NERF(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var NERFcount = br.BaseStream.Length / 8; + for (var i = 0; i < NERFcount; ++i) + { + NERFEntries.Add(new Vector2(br.ReadSingle(), br.ReadSingle())); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (Vector2 obj in NERFEntries) + { + bw.Write(obj.X); + bw.Write(obj.Y); + } + + return ms.ToArray(); + } + } + + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/WFV3.cs b/Warcraft.NET/Files/M2/Chunks/SL/WFV3.cs new file mode 100644 index 0000000..17ef33c --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/SL/WFV3.cs @@ -0,0 +1,71 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.SL +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class WFV3 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "WFV3"; + + /// + /// Gets or sets the Skin FileDataId + /// + public List WFV3Entries = new(); + + /// + /// Initializes a new instance of + /// + public WFV3() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public WFV3(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var WFV3count = br.BaseStream.Length / WFV3Entry.GetSize(); + for (var i = 0; i < WFV3count; ++i) + { + WFV3Entries.Add(new WFV3Entry(br.ReadBytes(WFV3Entry.GetSize()))); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (WFV3Entry obj in WFV3Entries) + { + bw.Write(obj.Serialize()); + } + + return ms.ToArray(); + } + } + + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/DETLEntry.cs b/Warcraft.NET/Files/M2/Entries/DETLEntry.cs new file mode 100644 index 0000000..cdbb8b3 --- /dev/null +++ b/Warcraft.NET/Files/M2/Entries/DETLEntry.cs @@ -0,0 +1,65 @@ +using System; +using System.IO; + +namespace Warcraft.NET.Files.M2.Entries +{ + public class DETLEntry + { + public UInt16 flags; + public UInt16 packedFloat0; + public UInt16 packedFloat1; // multiplier for M2Light.diffuse_color + public UInt16 unk0; + public UInt32 unk1; + + /// + /// Initializes a new instance of the class. + /// + public DETLEntry() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public DETLEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + flags = br.ReadUInt16(); + packedFloat0 = br.ReadUInt16(); + packedFloat1 = br.ReadUInt16(); + unk0 = br.ReadUInt16(); + unk1 = br.ReadUInt32(); + } + } + + /// + /// Gets the size of a AFRA Entry + /// + /// The size. + public static int GetSize() + { + return 12; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(flags); + bw.Write(packedFloat0); + bw.Write(packedFloat1); + bw.Write(unk0); + bw.Write(unk1); + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/M2/Entries/WFV3Entry.cs b/Warcraft.NET/Files/M2/Entries/WFV3Entry.cs new file mode 100644 index 0000000..f8eb38a --- /dev/null +++ b/Warcraft.NET/Files/M2/Entries/WFV3Entry.cs @@ -0,0 +1,128 @@ +using System; +using System.IO; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.M2.Entries +{ + public class WFV3Entry + { + public float bumpScale; //Passed to vertex shader + public float value0_x; + public float value0_y; + public float value0_z; + public float value1_w; + public float value0_w; + public float value1_x; + public float value1_y; + public float value2_w; + public float value3_y; + public float value3_x; + public CImVector baseColor; // in rgba (not bgra) + public UInt16 flags; + public UInt16 unk0; + public float value3_w; + public float value3_z; + public float value4_y; + public float unk1; + public float unk2; + public float unk3; + public float unk4; + + /// + /// Initializes a new instance of the class. + /// + public WFV3Entry() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public WFV3Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + bumpScale = br.ReadSingle(); + + value0_x = br.ReadSingle(); + value0_y = br.ReadSingle(); + value0_z = br.ReadSingle(); + value1_w = br.ReadSingle(); + + value0_w = br.ReadSingle(); + value1_x = br.ReadSingle(); + value1_y = br.ReadSingle(); + value2_w = br.ReadSingle(); + + value3_y = br.ReadSingle(); + value3_x = br.ReadSingle(); + + baseColor = new CImVector(br.ReadBytes(4)); + + flags = br.ReadUInt16(); + unk0 = br.ReadUInt16(); + + value3_w = br.ReadSingle(); + value3_z = br.ReadSingle(); + value4_y = br.ReadSingle(); + + unk1 = br.ReadSingle(); + unk2 = br.ReadSingle(); + unk3 = br.ReadSingle(); + unk4 = br.ReadSingle(); + } + } + + /// + /// Gets the size of a WFV3 Entry + /// + /// The size. + public static int GetSize() + { + return 80; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(bumpScale); + + bw.Write(value0_x); + bw.Write(value0_y); + bw.Write(value0_z); + bw.Write(value1_w); + + bw.Write(value0_w); + bw.Write(value1_x); + bw.Write(value1_y); + bw.Write(value2_w); + + bw.Write(value3_y); + bw.Write(value3_x); + + bw.Write(baseColor.toBytes()); + + bw.Write(flags); + bw.Write(unk0); + + bw.Write(value3_w); + bw.Write(value3_z); + bw.Write(value4_y); + + bw.Write(unk1); + bw.Write(unk2); + bw.Write(unk3); + bw.Write(unk4); + } + + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/M2/Model.cs b/Warcraft.NET/Files/M2/Model.cs index 61b8a5d..fb75684 100644 --- a/Warcraft.NET/Files/M2/Model.cs +++ b/Warcraft.NET/Files/M2/Model.cs @@ -1,6 +1,7 @@ using Warcraft.NET.Attribute; using Warcraft.NET.Files.M2.Chunks; using Warcraft.NET.Files.M2.Chunks.BfA; +using Warcraft.NET.Files.M2.Chunks.DF; using Warcraft.NET.Files.M2.Chunks.Legion; using Warcraft.NET.Files.M2.Chunks.SL; @@ -9,25 +10,25 @@ namespace Warcraft.NET.Files.M2 [AutoDocFile("m2")] public class Model : ChunkedFile { + /// /// Gets or sets the model information /// [ChunkOrder(1)] - public MD21 ModelInformation { get; set; } - - [ChunkOptional] - public TXAC TXAC { get; set; } - - //[ChunkOptional] - //public PEDC PEDC { get; set; } - - + public MD21 ModelInformation { get; set; } + + /// + /// Gets or sets the model phys file ids + /// [ChunkOptional] - public EXPT EXP2 { get; set; } + public PFID PhysFileIds { get; set; } + /// + /// Gets or sets the model skin file ids + /// [ChunkOptional] - public PGD1 PGD1 { get; set; } - + public SFID SkinFileIds { get; set; } + /// /// Gets or sets the model anim file ids /// @@ -41,19 +42,22 @@ public class Model : ChunkedFile public BFID BoneFileIds { get; set; } [ChunkOptional] - public LDV1 LDV1 { get; set; } - + public TXAC CParticleEmitter2 { get; set; } + [ChunkOptional] - public EDGF EDGF { get; set; } + public EXPT ExtendedParticle { get; set; } - /// - /// Gets or sets the model physics - /// - [ChunkOptional] - public PFDC ModelPhysics { get; set; } + //[ChunkOptional] + //public EXP2 ExtendedParticle2 { get; set; } [ChunkOptional] - public DBOC DBOC { get; set; } + public PABC M2InitBlacklistAnimData { get; set; }//Unfinished + [ChunkOptional] + public PADC M2InitParentAnimData { get; set; } //Unfinished + [ChunkOptional] + public PSBC M2InitParentSequencyBoundsData { get; set; }//Unfinished + [ChunkOptional] + public PEDC M2InitParentEventData { get; set; }//Unfinished /// /// Gets or sets the model skeleton file ids @@ -62,40 +66,68 @@ public class Model : ChunkedFile public SKID SkeletonFileIds { get; set; } /// - /// Gets or sets the model skin file ids + /// Gets or sets the texture file ids /// [ChunkOptional] - public SFID SkinFileIds { get; set; } + public TXID TextureFileIds { get; set; } + + [ChunkOptional] + public LDV1 LodDataVersion1 { get; set; } /// - /// Gets or sets the model phys file ids + /// Gets or sets the model recursive particle file ids /// [ChunkOptional] - public PFID PhysFileIds { get; set; } + public RPID RecursiveParticleFileIds { get; set; } /// - /// Gets or sets the texture file ids + /// Gets or sets the model geometry particle file ids /// [ChunkOptional] - public TXID TextureFileIds { get; set; } + public GPID GeometryParticleFileIds { get; set; } + [ChunkOptional] + public WFV1 WaterFallVersion1 { get; set; } - //[ChunkOptional] - //public PSBC PSBC { get; set; } + [ChunkOptional] + public WFV2 WaterFallVersion2 { get; set; } + [ChunkOptional] + public PGD1 ParticleGeosetData { get; set; } + [ChunkOptional] + public WFV3 WaterFallVersion3 { get; set; } /// - /// Gets or sets the model recursive particle file ids + /// Gets or sets the model physics /// [ChunkOptional] - public RPID RecursiveParticleFileIds { get; set; } + public PFDC ModelPhysics { get; set; } - /// - /// Gets or sets the model geometry particle file ids - /// [ChunkOptional] - public GPID GeometryParticleFileIds { get; set; } + public EDGF EdgeFade { get; set; } + + [ChunkOptional] + public NERF NERF { get; set; } + + [ChunkOptional] + public DETL DETL { get; set; } + + [ChunkOptional] + public DBOC DBOC { get; set; } + + [ChunkOptional] + public AFRA AFRA { get; set; } + + + + + + + + + + diff --git a/Warcraft.NET/Files/SKIN/Skin.cs b/Warcraft.NET/Files/SKIN/Skin.cs index 42f6f6f..d9ffd88 100644 --- a/Warcraft.NET/Files/SKIN/Skin.cs +++ b/Warcraft.NET/Files/SKIN/Skin.cs @@ -45,7 +45,7 @@ public Skin(byte[] inData) byte[] Serialize() { - + return null; } } diff --git a/Warcraft.NET/Files/Structures/CImVector.cs b/Warcraft.NET/Files/Structures/CImVector.cs new file mode 100644 index 0000000..ad01d56 --- /dev/null +++ b/Warcraft.NET/Files/Structures/CImVector.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.Structures +{ + public struct CImVector : IFlattenableData + { + public byte r, g, b, a; + + public CImVector(byte _r, byte _g, byte _b, byte _a) + { + r = _r; + g = _g; + b = _b; + a = _a; + } + + public byte[] toBytes() + { + byte[] arr = new byte[4] { r, g, b, a }; + return arr; + } + + public CImVector(byte[] input) + { + if (input.Length == 4) + { + r = input[0]; + g = input[1]; + b = input[2]; + a = input[3]; + } + } + + /// + public override string ToString() + { + return $"{r}, {g}, {b}, {a}"; + } + + public IReadOnlyCollection Flatten() + { + return new[] { r,g,b,a }; + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs b/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs index e147c77..6e9bab5 100644 --- a/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs +++ b/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs @@ -6,7 +6,14 @@ namespace Warcraft.NET.Files.phys.Entries public class BDY4Entry { - public ushort type { get; set; } // maps to dmBodyDef type enum. 0 -> 1, 1 -> 0 = dm_dynamicBody, * -> 2. Only one should be of type 0 (root). possibly only 0 and 1. + public enum Body_Type : ushort + { + root = 0, + dynamic = 1, + unk = 2, + } + + public Body_Type type { get; set; } // maps to dmBodyDef type enum. 0 -> 1, 1 -> 0 = dm_dynamicBody, * -> 2. Only one should be of type 0 (root). possibly only 0 and 1. public ushort boneIndex { get; set; } public C3Vector position { get; set; } public ushort shapeIndex { get; set; } @@ -38,7 +45,7 @@ public BDY4Entry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - type = br.ReadUInt16(); + type = (Body_Type)br.ReadUInt16(); boneIndex = br.ReadUInt16(); position = new C3Vector(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); shapeIndex = br.ReadUInt16(); @@ -69,7 +76,7 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write(type); + bw.Write((ushort)type); bw.Write(boneIndex); bw.Write(position.X); bw.Write(position.Y); diff --git a/Warcraft.NET/Files/phys/Entries/JOINEntry.cs b/Warcraft.NET/Files/phys/Entries/JOINEntry.cs index 6df6551..d0f57c3 100644 --- a/Warcraft.NET/Files/phys/Entries/JOINEntry.cs +++ b/Warcraft.NET/Files/phys/Entries/JOINEntry.cs @@ -4,15 +4,25 @@ namespace Warcraft.NET.Files.phys.Entries { + + public class JOINEntry { - + public enum Joint_Type : ushort + { + sphericalJoint = 0, + shoulderJoint = 1, + weldJoint = 2, + revoluteJoint = 3, + prismaticJoint = 4, + distanceJoint = 5, + } public uint bodyAIdx; public uint bodyBIdx; public byte[] unk; - public ushort jointType; + public Joint_Type jointType; public ushort jointId; /// @@ -32,7 +42,7 @@ public JOINEntry(byte[] data) bodyAIdx = br.ReadUInt32(); bodyBIdx = br.ReadUInt32(); unk = br.ReadBytes(4); - jointType = br.ReadUInt16(); + jointType = (Joint_Type)br.ReadUInt16(); jointId = br.ReadUInt16(); } } @@ -56,7 +66,7 @@ public byte[] Serialize(long offset = 0) bw.Write(bodyAIdx); bw.Write(bodyBIdx); bw.Write(unk); - bw.Write(jointType); + bw.Write((ushort)jointType); bw.Write(jointId); } diff --git a/Warcraft.NET/Files/phys/Entries/SHP2Entry.cs b/Warcraft.NET/Files/phys/Entries/SHP2Entry.cs index a3f8057..5f1efe3 100644 --- a/Warcraft.NET/Files/phys/Entries/SHP2Entry.cs +++ b/Warcraft.NET/Files/phys/Entries/SHP2Entry.cs @@ -4,12 +4,21 @@ namespace Warcraft.NET.Files.phys.Entries { + + + public class SHP2Entry { - + public enum Shape_Type : short + { + box = 0, + caps = 1, + sphere = 2, + polytope = 3, + } /*0x00*/ - public ushort shapeType; + public Shape_Type shapeType; /*0x02*/ public ushort shapeIndex; // into the corresponding chunk /*0x04*/ @@ -45,7 +54,7 @@ public SHP2Entry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - shapeType = br.ReadUInt16(); + shapeType = (Shape_Type)br.ReadUInt16(); shapeIndex = br.ReadUInt16(); unk = br.ReadBytes(4); friction = br.ReadSingle(); @@ -74,7 +83,7 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write(shapeType); + bw.Write((ushort)shapeType); bw.Write(shapeIndex); bw.Write(unk); bw.Write(friction); @@ -89,5 +98,7 @@ public byte[] Serialize(long offset = 0) return ms.ToArray(); } } + + } } diff --git a/Warcraft.NET/Files/phys/Physics.cs b/Warcraft.NET/Files/phys/Physics.cs index ee27189..343102b 100644 --- a/Warcraft.NET/Files/phys/Physics.cs +++ b/Warcraft.NET/Files/phys/Physics.cs @@ -9,10 +9,10 @@ public class Physics : ChunkedFile [ChunkOrder(1)] public PHYS phys{get; set;} - [ChunkOrder(2)] + [ChunkOptional] public PHYT phyt{get; set;} - [ChunkOptional] + [ChunkOptional] public BOXS boxs{get;set;} [ChunkOptional] @@ -30,28 +30,18 @@ public class Physics : ChunkedFile [ChunkOptional] public BDY4 bdy4{get; set;} - - - - - [ChunkOptional] public SHOJ shoj { get; set; } [ChunkOptional] public SHJ2 shj2{get; set;} - - [ChunkOptional] public WLJ3 wlj3{get; set;} [ChunkOptional] public SPHJ sphj{get; set;} - - - [ChunkOptional] public PRS2 prs2{get; set;} From 3446eef7bc634a84cb757d896d2a35ee71e31e15 Mon Sep 17 00:00:00 2001 From: gulasch7742 Date: Sun, 11 Aug 2024 21:04:36 +0200 Subject: [PATCH 03/15] Added .skin import/export --- Warcraft.NET.Docs/Program.cs | 26 ++-- Warcraft.NET/Extensions/ExtendedIO.cs | 27 ++++ Warcraft.NET/Files/SKIN/Skin.cs | 192 +++++++++++++++++++++---- Warcraft.NET/Files/SKIN/SkinStructs.cs | 74 ++++++++++ 4 files changed, 281 insertions(+), 38 deletions(-) create mode 100644 Warcraft.NET/Files/SKIN/SkinStructs.cs diff --git a/Warcraft.NET.Docs/Program.cs b/Warcraft.NET.Docs/Program.cs index 2ab861e..a7ac32c 100644 --- a/Warcraft.NET.Docs/Program.cs +++ b/Warcraft.NET.Docs/Program.cs @@ -1,6 +1,7 @@ using Warcraft.NET.Docs.Steps; using Warcraft.NET.Files.M2; using Warcraft.NET.Files.phys; +using Warcraft.NET.Files.SKIN; namespace Warcraft.NET.Docs { @@ -12,25 +13,24 @@ internal class Program /// static void Main(string[] args) { + Console.WriteLine($"BaseDirectory: {AppDomain.CurrentDomain.BaseDirectory}"); - Console.WriteLine($"BaseDirectory: {AppDomain.CurrentDomain.BaseDirectory}"); + if (args.Length == 0) + throw new System.Exception("Please provide an output folder"); - if (args.Length == 0) - throw new System.Exception("Please provide an output folder"); + string outputFolder = Path.GetFullPath(args[0]); + if (!Directory.Exists(outputFolder)) + throw new Exception("Output folder does not exist"); - string outputFolder = Path.GetFullPath(args[0]); - if (!Directory.Exists(outputFolder)) - throw new Exception("Output folder does not exist"); + Console.WriteLine($"Output folder: {outputFolder}"); - Console.WriteLine($"Output folder: {outputFolder}"); + Console.WriteLine("Generating documentation..."); + var autoDocData = GenerateAutoDocDataStep.Process(); - Console.WriteLine("Generating documentation..."); - var autoDocData = GenerateAutoDocDataStep.Process(); + Console.WriteLine("Converting to markdown..."); + ConvertToMarkdownStep.Process(autoDocData, outputFolder); - Console.WriteLine("Converting to markdown..."); - ConvertToMarkdownStep.Process(autoDocData, outputFolder); - - Console.WriteLine("Done!"); + Console.WriteLine("Done!"); } } diff --git a/Warcraft.NET/Extensions/ExtendedIO.cs b/Warcraft.NET/Extensions/ExtendedIO.cs index a76ba06..86bc251 100644 --- a/Warcraft.NET/Extensions/ExtendedIO.cs +++ b/Warcraft.NET/Extensions/ExtendedIO.cs @@ -7,6 +7,7 @@ using System.Numerics; using Warcraft.NET.Exceptions; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace Warcraft.NET.Extensions { @@ -410,6 +411,32 @@ public static void WriteChunkSignature(this BinaryWriter binaryWriter, string si } } + /// + /// Writes a struct to the BinaryWriter. + /// + /// The type of struct to write. + /// The BinaryWriter instance. + /// The struct value to write. + public static void WriteStruct(this BinaryWriter binaryWriter, T value) where T : struct + { + int size = Marshal.SizeOf(); + byte[] bytes = new byte[size]; + + IntPtr ptr = Marshal.AllocHGlobal(size); + try + { + Marshal.StructureToPtr(value, ptr, true); + Marshal.Copy(ptr, bytes, 0, size); + } + finally + { + Marshal.FreeHGlobal(ptr); + } + + // Write the padded bytes + binaryWriter.Write(bytes); + } + /// /// Writes a 12-byte value to the data stream in Pitch/Yaw/Roll order. /// diff --git a/Warcraft.NET/Files/SKIN/Skin.cs b/Warcraft.NET/Files/SKIN/Skin.cs index d9ffd88..5220d18 100644 --- a/Warcraft.NET/Files/SKIN/Skin.cs +++ b/Warcraft.NET/Files/SKIN/Skin.cs @@ -1,52 +1,194 @@ using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; using Warcraft.NET.Files.phys.Chunks; using Warcraft.NET.Files.Structures; -namespace Warcraft.NET.Files.phys +namespace Warcraft.NET.Files.SKIN { [AutoDocFile("skin")] - public class Skin + public class Skin { + public List Vertices{ get; set; } //index into M2s vertex list with offset + public List Triangles { get; set; } //3 indices per entry into vertices + public List BoneIndices { get; set; } + public List Submeshes { get; set; } + public List TextureUnits { get; set; } - public UInt32 magic; - - public M2Array vertices; - public M2Array indices; - public M2Array bones; - public M2Array submeshes; - public M2Array batches; - public UInt32 globalVertexOffset; - public M2Array shadow_batches; - - public UInt32 unk0; - public UInt32 unk1; + public UInt32 globalVertexOffset; //start offset into M2.Vertices -> something else in wotlk + public List ShadowBatches; + + public byte[] unk0; //Padding? + public bool wotlk = false; public Skin(byte[] inData) { using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) { - magic = br.ReadUInt32(); - vertices = new M2Array(br.ReadUInt32(),br.ReadUInt32()); - indices = new M2Array(br.ReadUInt32(), br.ReadUInt32()); - bones = new M2Array(br.ReadUInt32(), br.ReadUInt32()); - submeshes = new M2Array(br.ReadUInt32(), br.ReadUInt32()); - batches = new M2Array(br.ReadUInt32(), br.ReadUInt32()); + var magic = br.ReadUInt32(); + var nVertices = br.ReadUInt32(); + var ofsVertices = br.ReadUInt32(); + var nIndices = br.ReadUInt32(); + var ofsIndices = br.ReadUInt32(); + if (ofsVertices == 48) + { + wotlk = true; + } + var nBones = br.ReadUInt32(); + var ofsBones = br.ReadUInt32(); + var nSubmeshes = br.ReadUInt32(); + var ofsSubmeshes = br.ReadUInt32(); + var nBatches = br.ReadUInt32(); + var ofsBatches = br.ReadUInt32(); globalVertexOffset = br.ReadUInt32(); - shadow_batches = new M2Array(br.ReadUInt32(), br.ReadUInt32()); - unk0 = br.ReadUInt32(); - unk1 = br.ReadUInt32(); + + ShadowBatches = new List(); + unk0 = new byte[8]; + if (!wotlk) + { + var nShadow_batches = br.ReadUInt32(); + var ofsShadow_batches = br.ReadUInt32(); + unk0 = br.ReadBytes(8); + ShadowBatches = ReadStructList(nShadow_batches, ofsShadow_batches, br); + } + + Vertices = ReadStructList(nVertices, ofsVertices, br); + Triangles = ReadStructList(nIndices/3, ofsIndices, br); + BoneIndices = ReadStructList(nBones, ofsBones, br); + Submeshes = ReadStructList(nSubmeshes, ofsSubmeshes, br); + TextureUnits = ReadStructList(nBatches, ofsBatches, br); + } } + private List ReadStructList(uint count, uint offset, BinaryReader br) where T : struct + { + br.BaseStream.Position = offset; + List list = new List(); - byte[] Serialize() + for (var i = 0; i < count; i++) + list.Add(br.ReadStruct()); + + return list; + } + + public byte[] Serialize(long offset = 0) { - return null; + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(new byte[64]); //placeholder header + foreach (ushort vertex in Vertices) + { + bw.Write(vertex); + } + + + int _ofsTriangles = (int)bw.BaseStream.Position; + foreach (M2Triangle triangle in Triangles) + { + bw.WriteStruct(triangle); + } + + + int _ofsBones = (int)bw.BaseStream.Position; + foreach (BoneStruct bone in BoneIndices) + { + bw.WriteStruct(bone); + + } + + + int _ofsSubmeshes = (int)bw.BaseStream.Position; + foreach (M2SkinSection submesh in Submeshes) + { + bw.WriteStruct(submesh); + } + + + int _ofsTexUnits = (int)bw.BaseStream.Position; + foreach (M2Batch texUnit in TextureUnits) + { + bw.WriteStruct(texUnit); + } + + int _ofsShadowBatches = (int)bw.BaseStream.Position; + if (!wotlk) { + foreach (M2ShadowBatch shadowBatch in ShadowBatches) + { + bw.WriteStruct(shadowBatch); + } + } + + + + + + //Writing header + bw.BaseStream.Position = 0; + bw.Write('S'); + bw.Write('K'); + bw.Write('I'); + bw.Write('N'); + + bw.Write(Vertices.Count); + var _ofsVertices = 64; + if (wotlk) + _ofsVertices = 48; + bw.Write(_ofsVertices); + + bw.Write(Triangles.Count*3); + bw.Write(_ofsTriangles); + + bw.Write(BoneIndices.Count); + bw.Write(_ofsBones); + + bw.Write(Submeshes.Count); + bw.Write(_ofsSubmeshes); + + bw.Write(TextureUnits.Count); + bw.Write(_ofsTexUnits); + + bw.Write(globalVertexOffset); + + if (!wotlk) + { + bw.Write(ShadowBatches.Count); + bw.Write(_ofsShadowBatches); + bw.Write(unk0); + } + + + return ms.ToArray(); + } } + + /// + public uint GetSize() + { + return (uint)Serialize().Length; + } + + /* + public byte[] addPadding(byte[] bytes, int size) + { + // Calculate padding + int paddingSize = (4 - (size % 4)) % 4; + byte[] paddedBytes = new byte[size + paddingSize]; + Array.Copy(bytes, paddedBytes, size); + return paddedBytes; + } + */ + } + } + + diff --git a/Warcraft.NET/Files/SKIN/SkinStructs.cs b/Warcraft.NET/Files/SKIN/SkinStructs.cs new file mode 100644 index 0000000..eb386f1 --- /dev/null +++ b/Warcraft.NET/Files/SKIN/SkinStructs.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.SKIN +{ + public struct M2SkinSection + { + public UInt16 skinSectionId; // Mesh part ID, see below. + public UInt16 Level; // (level << 16) is added (|ed) to startTriangle and alike to avoid having to increase those fields to uint32s. + public UInt16 vertexStart; // Starting vertex number. + public UInt16 vertexCount; // Number of vertices. + public UInt16 indexStart; // Starting triangle index (that's 3* the number of triangles drawn so far). + public UInt16 indexCount; // Number of triangle indices. + public UInt16 boneCount; // Number of elements in the bone lookup table. Max seems to be 256 in Wrath. Shall be ≠ 0. + public UInt16 boneComboIndex; // Starting index in the bone lookup table. + public UInt16 boneInfluences; // <= 4 + // from <=BC documentation: Highest number of bones needed at one time in this Submesh --Tinyn (wowdev.org) + // In 2.x this is the amount of of bones up the parent-chain affecting the submesh --NaK + // Highest number of bones referenced by a vertex of this submesh. 3.3.5a and suspectedly all other client revisions. -- Skarn + public UInt16 centerBoneIndex; + public C3Vector centerPosition; // Average position of all the vertices in the sub mesh. + //≥BC + public C3Vector sortCenterPosition; // The center of the box when an axis aligned box is built around the vertices in the submesh. + public float sortRadius; // Distance of the vertex farthest from CenterBoundingBox. + } + + public struct BoneStruct + { + public byte b1; + public byte b2; + public byte b3; + public byte b4; + } + + public struct M2Batch + { + public byte flags; // Usually 16 for static textures, and 0 for animated textures. &0x1: materials invert something; &0x2: transform &0x4: projected texture; &0x10: something batch compatible; &0x20: projected texture?; &0x40: possibly don't multiply transparency by texture weight transparency to get final transparency value(?) + public sbyte priorityPlane; + public UInt16 shader_id; // See below. + public UInt16 skinSectionIndex; // A duplicate entry of a submesh from the list above. + public UInt16 geosetIndex; // See below. New name: flags2. 0x2 - projected. 0x8 - EDGF chunk in m2 is mandatory and data from is applied to this mesh + public UInt16 colorIndex; // A Color out of the Colors-Block or -1 if none. + public UInt16 materialIndex; // The renderflags used on this texture-unit. + public UInt16 materialLayer; // Capped at 7 (see CM2Scene::BeginDraw) + public UInt16 textureCount; // 1 to 4. See below. Also seems to be the number of textures to load, starting at the texture lookup in the next field (0x10). + public UInt16 textureComboIndex; // Index into Texture lookup table + public UInt16 textureCoordComboIndex; // Index into the texture mapping lookup table. + public UInt16 textureWeightComboIndex; // Index into transparency lookup table. + public UInt16 textureTransformComboIndex; // Index into uvanimation lookup table. + } + + public struct M2ShadowBatch + { + byte flags; // if auto-generated: M2Batch.flags & 0xFF + byte flags2; // if auto-generated: (renderFlag[i].flags & 0x04 ? 0x01 : 0x00) + // | (!renderFlag[i].blendingmode ? 0x02 : 0x00) + // | (renderFlag[i].flags & 0x80 ? 0x04 : 0x00) + // | (renderFlag[i].flags & 0x400 ? 0x06 : 0x00) + public UInt16 _unknown1; + public UInt16 submesh_id; + public UInt16 texture_id; // already looked-up + public UInt16 color_id; + public UInt16 transparency_id; // already looked-up + } + + public struct M2Triangle //Left handed + { + public ushort V1; + public ushort V3; + public ushort V2; + } +} From 3177ea711a1506571244b214dbea1b767793e4c1 Mon Sep 17 00:00:00 2001 From: gulasch7742 Date: Fri, 16 Aug 2024 14:53:02 +0200 Subject: [PATCH 04/15] updated spaces, comments and names --- Warcraft.NET/Extensions/ExtendedIO.cs | 113 ++++++---- Warcraft.NET/Files/M2/Chunks/BfA/LDV1.cs | 69 ++++++ Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs | 51 +++++ Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs | 51 +++++ Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs | 54 +++++ Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs | 70 +++++++ Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs | 48 +++++ Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs | 49 +++++ Warcraft.NET/Files/M2/Chunks/Legion/PGD1.cs | 69 ++++++ Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs | 51 +++++ Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs | 71 +++++++ Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs | 69 ++++++ Warcraft.NET/Files/M2/Chunks/SL/DETL.cs | 69 ++++++ Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs | 69 ++++++ Warcraft.NET/Files/M2/Chunks/SL/NERF.cs | 70 +++++++ Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs | 49 +++++ Warcraft.NET/Files/M2/Chunks/SL/WFV3.cs | 69 ++++++ Warcraft.NET/Files/M2/Entries/DBOCEntry.cs | 70 +++++++ Warcraft.NET/Files/M2/Entries/DETLEntry.cs | 82 ++++++++ Warcraft.NET/Files/M2/Entries/EDGFEntry.cs | 71 +++++++ Warcraft.NET/Files/M2/Entries/EXPTEntry.cs | 65 ++++++ Warcraft.NET/Files/M2/Entries/LDV1Entry.cs | 80 +++++++ Warcraft.NET/Files/M2/Entries/WFV3Entry.cs | 197 ++++++++++++++++++ Warcraft.NET/Files/M2/Model.cs | 118 +++++++++++ Warcraft.NET/Files/Phys/Entries/SPHSEntry.cs | 52 +++++ Warcraft.NET/Files/Phys/Enums/BodyType.cs | 13 ++ Warcraft.NET/Files/Phys/Enums/JointType.cs | 16 ++ Warcraft.NET/Files/Phys/Enums/ShapeType.cs | 14 ++ .../Files/Phys/Structures/PlytData.cs | 29 +++ .../Files/Phys/Structures/PlytHeader.cs | 52 +++++ .../Files/Phys/Structures/PlytNode.cs | 26 +++ Warcraft.NET/Files/SKIN/Skin.cs | 173 +++++++++++++++ Warcraft.NET/Files/Structures/M2Batch.cs | 23 ++ .../Files/Structures/M2ShadowBatch.cs | 20 ++ .../Files/Structures/M2SkinBoneStruct.cs | 14 ++ .../Files/Structures/M2SkinSection.cs | 28 +++ Warcraft.NET/Files/Structures/M2Triangle.cs | 13 ++ Warcraft.NET/Files/Structures/Matrix3x4.cs | 52 +++++ Warcraft.NET/Files/phys/Chunks/BDY4.cs | 69 ++++++ Warcraft.NET/Files/phys/Chunks/BOXS.cs | 68 ++++++ Warcraft.NET/Files/phys/Chunks/CAPS.cs | 68 ++++++ Warcraft.NET/Files/phys/Chunks/DSTJ.cs | 70 +++++++ Warcraft.NET/Files/phys/Chunks/JOIN.cs | 69 ++++++ Warcraft.NET/Files/phys/Chunks/PHYS.cs | 58 ++++++ Warcraft.NET/Files/phys/Chunks/PHYT.cs | 59 ++++++ Warcraft.NET/Files/phys/Chunks/PHYV.cs | 73 +++++++ Warcraft.NET/Files/phys/Chunks/PLYT.cs | 85 ++++++++ Warcraft.NET/Files/phys/Chunks/PRS2.cs | 70 +++++++ Warcraft.NET/Files/phys/Chunks/REV2.cs | 70 +++++++ Warcraft.NET/Files/phys/Chunks/SHJ2.cs | 70 +++++++ Warcraft.NET/Files/phys/Chunks/SHOJ.cs | 70 +++++++ Warcraft.NET/Files/phys/Chunks/SHP2.cs | 68 ++++++ Warcraft.NET/Files/phys/Chunks/SPHJ.cs | 68 ++++++ Warcraft.NET/Files/phys/Chunks/SPHS.cs | 68 ++++++ Warcraft.NET/Files/phys/Chunks/WLJ3.cs | 68 ++++++ Warcraft.NET/Files/phys/Entries/BDY4Entry.cs | 140 +++++++++++++ Warcraft.NET/Files/phys/Entries/BOXSEntry.cs | 52 +++++ Warcraft.NET/Files/phys/Entries/CAPSEntry.cs | 58 ++++++ Warcraft.NET/Files/phys/Entries/DSTJEntry.cs | 69 ++++++ Warcraft.NET/Files/phys/Entries/JOINEntry.cs | 89 ++++++++ Warcraft.NET/Files/phys/Entries/PLYTEntry.cs | 177 ++++++++++++++++ Warcraft.NET/Files/phys/Entries/PRS2Entry.cs | 111 ++++++++++ Warcraft.NET/Files/phys/Entries/REV2Entry.cs | 103 +++++++++ Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs | 114 ++++++++++ Warcraft.NET/Files/phys/Entries/SHOJEntry.cs | 100 +++++++++ Warcraft.NET/Files/phys/Entries/SHP2Entry.cs | 120 +++++++++++ Warcraft.NET/Files/phys/Entries/SPHJEntry.cs | 70 +++++++ Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs | 97 +++++++++ Warcraft.NET/Files/phys/Physics.cs | 77 +++++++ 69 files changed, 4808 insertions(+), 39 deletions(-) create mode 100644 Warcraft.NET/Files/M2/Chunks/BfA/LDV1.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/PGD1.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/SL/DETL.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/SL/NERF.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs create mode 100644 Warcraft.NET/Files/M2/Chunks/SL/WFV3.cs create mode 100644 Warcraft.NET/Files/M2/Entries/DBOCEntry.cs create mode 100644 Warcraft.NET/Files/M2/Entries/DETLEntry.cs create mode 100644 Warcraft.NET/Files/M2/Entries/EDGFEntry.cs create mode 100644 Warcraft.NET/Files/M2/Entries/EXPTEntry.cs create mode 100644 Warcraft.NET/Files/M2/Entries/LDV1Entry.cs create mode 100644 Warcraft.NET/Files/M2/Entries/WFV3Entry.cs create mode 100644 Warcraft.NET/Files/Phys/Entries/SPHSEntry.cs create mode 100644 Warcraft.NET/Files/Phys/Enums/BodyType.cs create mode 100644 Warcraft.NET/Files/Phys/Enums/JointType.cs create mode 100644 Warcraft.NET/Files/Phys/Enums/ShapeType.cs create mode 100644 Warcraft.NET/Files/Phys/Structures/PlytData.cs create mode 100644 Warcraft.NET/Files/Phys/Structures/PlytHeader.cs create mode 100644 Warcraft.NET/Files/Phys/Structures/PlytNode.cs create mode 100644 Warcraft.NET/Files/SKIN/Skin.cs create mode 100644 Warcraft.NET/Files/Structures/M2Batch.cs create mode 100644 Warcraft.NET/Files/Structures/M2ShadowBatch.cs create mode 100644 Warcraft.NET/Files/Structures/M2SkinBoneStruct.cs create mode 100644 Warcraft.NET/Files/Structures/M2SkinSection.cs create mode 100644 Warcraft.NET/Files/Structures/M2Triangle.cs create mode 100644 Warcraft.NET/Files/Structures/Matrix3x4.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/BDY4.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/BOXS.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/CAPS.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/DSTJ.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/JOIN.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/PHYS.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/PHYT.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/PHYV.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/PLYT.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/PRS2.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/REV2.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/SHJ2.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/SHOJ.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/SHP2.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/SPHJ.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/SPHS.cs create mode 100644 Warcraft.NET/Files/phys/Chunks/WLJ3.cs create mode 100644 Warcraft.NET/Files/phys/Entries/BDY4Entry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/BOXSEntry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/CAPSEntry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/DSTJEntry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/JOINEntry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/PLYTEntry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/PRS2Entry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/REV2Entry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/SHOJEntry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/SHP2Entry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/SPHJEntry.cs create mode 100644 Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs create mode 100644 Warcraft.NET/Files/phys/Physics.cs diff --git a/Warcraft.NET/Extensions/ExtendedIO.cs b/Warcraft.NET/Extensions/ExtendedIO.cs index a76ba06..c78cc2a 100644 --- a/Warcraft.NET/Extensions/ExtendedIO.cs +++ b/Warcraft.NET/Extensions/ExtendedIO.cs @@ -77,6 +77,22 @@ public static Vector3 ReadVector3(this BinaryReader binaryReader, AxisConfigurat } } + /// + /// Reads a 48-byte structure from the data stream and advances the position of the stream by + /// 48 bytes. + /// + /// The Mat3x4. + /// The reader. + /// Which axis configuration the read mat3x4 should be converted to. + public static Matrix3x4 ReadMatrix3x4(this BinaryReader binaryReader, AxisConfiguration convertTo = AxisConfiguration.YUp) + { + var a = binaryReader.ReadVector3(convertTo); + var b = binaryReader.ReadVector3(convertTo); + var c = binaryReader.ReadVector3(convertTo); + var pos = binaryReader.ReadVector3(convertTo); + return new Matrix3x4(a, b, c, pos); + } + /// /// Reads a 12-byte from the data stream and advances the position of the stream by /// 12 bytes. @@ -272,37 +288,37 @@ public static ShortVector3 ReadShortVector3(this BinaryReader binaryReader, Axis switch (convertTo) { case AxisConfiguration.Native: - { - return new ShortVector3(binaryReader.ReadInt16(), binaryReader.ReadInt16(), binaryReader.ReadInt16()); - } + { + return new ShortVector3(binaryReader.ReadInt16(), binaryReader.ReadInt16(), binaryReader.ReadInt16()); + } case AxisConfiguration.YUp: - { - var x1 = binaryReader.ReadInt16(); - var y1 = binaryReader.ReadInt16(); - var z1 = binaryReader.ReadInt16(); + { + var x1 = binaryReader.ReadInt16(); + var y1 = binaryReader.ReadInt16(); + var z1 = binaryReader.ReadInt16(); - var x = x1; - var y = z1; - var z = (short)-y1; + var x = x1; + var y = z1; + var z = (short)-y1; - return new ShortVector3(x, y, z); - } + return new ShortVector3(x, y, z); + } case AxisConfiguration.ZUp: - { - var x1 = binaryReader.ReadInt16(); - var y1 = binaryReader.ReadInt16(); - var z1 = binaryReader.ReadInt16(); + { + var x1 = binaryReader.ReadInt16(); + var y1 = binaryReader.ReadInt16(); + var z1 = binaryReader.ReadInt16(); - var x = x1; - var y = (short)-z1; - var z = y1; + var x = x1; + var y = (short)-z1; + var z = y1; - return new ShortVector3(x, y, z); - } + return new ShortVector3(x, y, z); + } default: - { - throw new ArgumentOutOfRangeException(nameof(convertTo), convertTo, null); - } + { + throw new ArgumentOutOfRangeException(nameof(convertTo), convertTo, null); + } } } @@ -538,6 +554,25 @@ public static void WriteVector3(this BinaryWriter binaryWriter, Vector3 vector, } } + /// + /// Writes a 48-byte value to the data stream. This function + /// + /// The current object. + /// The Vector to write. + /// Which axis configuration the read vector should be stored as. + public static void WriteMatrix3x4(this BinaryWriter binaryWriter, Matrix3x4 matrix, AxisConfiguration storeAs = AxisConfiguration.ZUp) + { + var column1 = matrix.RotationX * matrix.Scale.X; + var column2 = matrix.RotationY * matrix.Scale.Y; + var column3 = matrix.RotationZ * matrix.Scale.Z; + var column4 = matrix.Position; + + binaryWriter.WriteVector3(column1, storeAs); + binaryWriter.WriteVector3(column2, storeAs); + binaryWriter.WriteVector3(column3, storeAs); + binaryWriter.WriteVector3(column4, storeAs); + } + /// /// Writes a 16-byte to the data stream. /// @@ -575,23 +610,23 @@ public static void WriteShortVector3(this BinaryWriter binaryWriter, ShortVector { case AxisConfiguration.Native: case AxisConfiguration.YUp: - { - binaryWriter.Write(vector.X); - binaryWriter.Write(vector.Y); - binaryWriter.Write(vector.Z); - break; - } + { + binaryWriter.Write(vector.X); + binaryWriter.Write(vector.Y); + binaryWriter.Write(vector.Z); + break; + } case AxisConfiguration.ZUp: - { - binaryWriter.Write(vector.X); - binaryWriter.Write((short)(vector.Z * -1)); - binaryWriter.Write(vector.Y); - break; - } + { + binaryWriter.Write(vector.X); + binaryWriter.Write((short)(vector.Z * -1)); + binaryWriter.Write(vector.Y); + break; + } default: - { - throw new ArgumentOutOfRangeException(nameof(storeAs), storeAs, null); - } + { + throw new ArgumentOutOfRangeException(nameof(storeAs), storeAs, null); + } } } diff --git a/Warcraft.NET/Files/M2/Chunks/BfA/LDV1.cs b/Warcraft.NET/Files/M2/Chunks/BfA/LDV1.cs new file mode 100644 index 0000000..44a7e33 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/BfA/LDV1.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.BfA +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterLegion, AutoDocChunkVersionHelper.VersionBeforeBfA)] + public class LDV1 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "LDV1"; + + /// + /// Gets or sets the Lod Data Version 1 Entries + /// + public List LDV1Entries = new(); + + /// + /// Initializes a new instance of + /// + public LDV1() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public LDV1(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var LDV1count = br.BaseStream.Length / LDV1Entry.GetSize(); + for (var i = 0; i < LDV1count; ++i) + { + LDV1Entries.Add(new LDV1Entry(br.ReadBytes(LDV1Entry.GetSize()))); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (LDV1Entry obj in LDV1Entries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs b/Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs new file mode 100644 index 0000000..ee2e459 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs @@ -0,0 +1,51 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.BfA +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterLegion, AutoDocChunkVersionHelper.VersionBeforeBfA)] + public class WFV1 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "WFV1"; + + /// + /// Gets or sets the full data (deserialization NYI) + /// + public byte[] Data; + + /// + /// Initializes a new instance of + /// + public WFV1() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public WFV1(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + Data = inData; + } + + /// + public byte[] Serialize(long offset = 0) + { + return Data; + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs b/Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs new file mode 100644 index 0000000..3eacdc2 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs @@ -0,0 +1,51 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.BfA +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterLegion, AutoDocChunkVersionHelper.VersionBeforeBfA)] + public class WFV2 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "WFV2"; + + /// + /// Gets or sets the full data (deserialization NYI) + /// + public byte[] Data; + + /// + /// Initializes a new instance of + /// + public WFV2() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public WFV2(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + Data = inData; + } + + /// + public byte[] Serialize(long offset = 0) + { + return Data; + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs b/Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs new file mode 100644 index 0000000..a8d7263 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.DF +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterSL, AutoDocChunkVersionHelper.VersionBeforeDF)] + public class AFRA : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "AFRA"; + + /// + /// Gets or sets the full data (deserialization NYI) + /// + public byte[] Data; + + /// + /// Initializes a new instance of + /// + public AFRA() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public AFRA(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() + { + return (uint)Serialize().Length; + } + + /// + public void LoadBinaryData(byte[] inData) + { + Data = inData; + } + + /// + public byte[] Serialize(long offset = 0) + { + return Data; + } + } +} diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs new file mode 100644 index 0000000..7a4ab29 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class PABC : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PABC"; + + /// + /// Gets or sets the ParentSequenceBounds Entries + /// + public List PABCEntries = new(); + + /// + /// Initializes a new instance of + /// + public PABC() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PABC(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var PABCcount = br.BaseStream.Length / 2; + for (var i = 0; i < PABCcount; ++i) + { + PABCEntries.Add(br.ReadUInt16()); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (ushort obj in PABCEntries) + { + bw.Write(obj); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs new file mode 100644 index 0000000..b1f4ba3 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs @@ -0,0 +1,48 @@ +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class PADC : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PADC"; + + /// + /// Gets or sets the ParentAnimationData (deserialization NYI) + /// + public byte[] Data; + + /// + /// Initializes a new instance of + /// + public PADC() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PADC(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + Data = inData; + } + + /// + public byte[] Serialize(long offset = 0) + { + return Data; + } + } +} diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs new file mode 100644 index 0000000..e5409cb --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs @@ -0,0 +1,49 @@ +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class PEDC : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PEDC"; + + /// + /// Gets or sets the ParentEventData (deserialization NYI) + /// + public byte[] Data; + + /// + /// Initializes a new instance of + /// + public PEDC() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PEDC(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + Data = inData; + } + + /// + public byte[] Serialize(long offset = 0) + { + return Data; + } + } +} diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PGD1.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PGD1.cs new file mode 100644 index 0000000..dba0ea2 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PGD1.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class PGD1 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PGD1"; + + /// + /// Gets or sets the ParticleGeosetData1 Entries + /// + public List PGD1Entries = new(); + + /// + /// Initializes a new instance of + /// + public PGD1() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PGD1(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var PGD1count = br.BaseStream.Length / 2; + for (var i = 0; i < PGD1count; ++i) + { + PGD1Entries.Add(br.ReadUInt16()); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (UInt16 obj in PGD1Entries) + { + bw.Write(obj); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs new file mode 100644 index 0000000..fa2542b --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs @@ -0,0 +1,51 @@ +using System.IO; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + public class PSBC : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PSBC"; + + /// + /// Gets or sets the ParentSequenceBounds (deserialization NYI) + /// + public byte[] Data; + + /// + /// Initializes a new instance of + /// + public PSBC() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PSBC(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + Data = inData; + } + } + + /// + public byte[] Serialize(long offset = 0) + { + return Data; + } + } +} diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs new file mode 100644 index 0000000..86fb8da --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs @@ -0,0 +1,71 @@ +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using System.Collections.Generic; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class TXAC : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "TXAC"; + + /// + /// 2 byte array + /// From Wiki: + /// likely used in CM2SceneRender::SetupTextureTransforms and uploaded to the shader directly. 0 otherwise. + /// This chunk doesn't seem to be used directly. Inside CParticleEmitter2 class there are non-null checks that deal with selection of VertexBufferFormat for particles. Apart from that, the usage of these fields is unknown + /// + public List TXACEntries = new(); + + /// + /// Initializes a new instance of + /// + public TXAC() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public TXAC(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + for (int i = 0; i < inData.Length / 2; i++) + { + var entry = new byte[2]; + entry[0] = br.ReadByte(); + entry[1] = br.ReadByte(); + TXACEntries.Add(entry); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (var entry in TXACEntries) + { + bw.Write(entry); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs b/Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs new file mode 100644 index 0000000..912a6e0 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class DBOC : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "DBOC"; + + /// + /// Gets or sets the DBOC Entries + /// + public List DBOCEntries = new(); + + /// + /// Initializes a new instance of + /// + public DBOC() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public DBOC(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var DBOCcount = br.BaseStream.Length / DBOCEntry.GetSize(); + for (var i = 0; i < DBOCcount; ++i) + { + DBOCEntries.Add(new DBOCEntry(br.ReadBytes(DBOCEntry.GetSize()))); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (DBOCEntry obj in DBOCEntries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/DETL.cs b/Warcraft.NET/Files/M2/Chunks/SL/DETL.cs new file mode 100644 index 0000000..6a477a0 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/SL/DETL.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.SL +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class DETL : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "DETL"; + + /// + /// Gets or sets the DETL Entries + /// + public List DETLEntries = new(); + + /// + /// Initializes a new instance of + /// + public DETL() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public DETL(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var DETLcount = br.BaseStream.Length / DETLEntry.GetSize(); + for (var i = 0; i < DETLcount; ++i) + { + DETLEntries.Add(new DETLEntry(br.ReadBytes(DETLEntry.GetSize()))); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (DETLEntry obj in DETLEntries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs b/Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs new file mode 100644 index 0000000..23634a1 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class EDGF : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "EDGF"; + + /// + /// Gets or sets the EdgeFade Entries + /// + public List EDGFEntries = new(); + + /// + /// Initializes a new instance of + /// + public EDGF() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public EDGF(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var EDGFcount = br.BaseStream.Length / EDGFEntry.GetSize(); + for (var i = 0; i < EDGFcount; ++i) + { + EDGFEntries.Add(new EDGFEntry(br.ReadBytes(EDGFEntry.GetSize()))); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (EDGFEntry obj in EDGFEntries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/NERF.cs b/Warcraft.NET/Files/M2/Chunks/SL/NERF.cs new file mode 100644 index 0000000..cdc76a2 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/SL/NERF.cs @@ -0,0 +1,70 @@ +using System.Collections.Generic; +using System.IO; +using System.Numerics; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class NERF : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "NERF"; + + /// + /// Gets or sets the NERF Entries + /// + public List NERFEntries = new(); + + /// + /// Initializes a new instance of + /// + public NERF() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public NERF(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var NERFcount = br.BaseStream.Length / 8; + for (var i = 0; i < NERFcount; ++i) + { + NERFEntries.Add(new Vector2(br.ReadSingle(), br.ReadSingle())); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (Vector2 obj in NERFEntries) + { + bw.Write(obj.X); + bw.Write(obj.Y); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs b/Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs new file mode 100644 index 0000000..c9a8057 --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs @@ -0,0 +1,49 @@ +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Phys; + +namespace Warcraft.NET.Files.M2.Chunks.SL +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class PFDC : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PFDC"; + + /// + /// Gets or sets the Physics for the M2 + /// + public Physics Physics { get; set; } = null; + + /// + /// Initializes a new instance of + /// + public PFDC() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PFDC(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + Physics = new Physics(inData); + } + + /// + public byte[] Serialize(long offset = 0) + { + return Physics.Serialize(); + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/WFV3.cs b/Warcraft.NET/Files/M2/Chunks/SL/WFV3.cs new file mode 100644 index 0000000..c37dd2a --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/SL/WFV3.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.SL +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class WFV3 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "WFV3"; + + /// + /// Gets or sets the WaterFallVersion3 Entries + /// + public List WFV3Entries = new(); + + /// + /// Initializes a new instance of + /// + public WFV3() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public WFV3(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var WFV3count = br.BaseStream.Length / WFV3Entry.GetSize(); + for (var i = 0; i < WFV3count; ++i) + { + WFV3Entries.Add(new WFV3Entry(br.ReadBytes(WFV3Entry.GetSize()))); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (WFV3Entry obj in WFV3Entries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/DBOCEntry.cs b/Warcraft.NET/Files/M2/Entries/DBOCEntry.cs new file mode 100644 index 0000000..33c09f0 --- /dev/null +++ b/Warcraft.NET/Files/M2/Entries/DBOCEntry.cs @@ -0,0 +1,70 @@ +using System.IO; + +namespace Warcraft.NET.Files.M2.Entries +{ + public class DBOCEntry + { + /// + /// unknown float + /// + public float Unk0; + /// + /// unknown float + /// + public float Unk1; + /// + /// unknown int + /// + public uint Unk2; + /// + /// unknown int + /// + public uint Unk3; + + /// + /// Initializes a new instance of the class. + /// + public DBOCEntry(){} + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public DBOCEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + Unk0 = br.ReadSingle(); + Unk1 = br.ReadSingle(); + Unk2 = br.ReadUInt32(); + Unk3 = br.ReadUInt32(); + } + } + + /// + /// Gets the size of a DBOC Entry + /// + /// The size. + public static int GetSize() + { + return 16; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(Unk0); + bw.Write(Unk1); + bw.Write(Unk2); + bw.Write(Unk3); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/M2/Entries/DETLEntry.cs b/Warcraft.NET/Files/M2/Entries/DETLEntry.cs new file mode 100644 index 0000000..4b38503 --- /dev/null +++ b/Warcraft.NET/Files/M2/Entries/DETLEntry.cs @@ -0,0 +1,82 @@ +using System.IO; + +namespace Warcraft.NET.Files.M2.Entries +{ + public class DETLEntry + { + /// + /// unknown Flags + /// + public ushort Flags; + + /// + /// multiplier for M2Light.diffuse_color + /// + public ushort PackedFloat0; + + /// + /// multiplier for M2Light.diffuse_color + /// + public ushort PackedFloat1; + + /// + /// unknown field + /// + public ushort Unk0; + + /// + /// unknown field + /// + public uint Unk1; + + /// + /// Initializes a new instance of the class. + /// + public DETLEntry() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public DETLEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + Flags = br.ReadUInt16(); + PackedFloat0 = br.ReadUInt16(); + PackedFloat1 = br.ReadUInt16(); + Unk0 = br.ReadUInt16(); + Unk1 = br.ReadUInt32(); + } + } + + /// + /// Gets the size of a AFRA Entry + /// + /// The size. + public static int GetSize() + { + return 12; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(Flags); + bw.Write(PackedFloat0); + bw.Write(PackedFloat1); + bw.Write(Unk0); + bw.Write(Unk1); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/M2/Entries/EDGFEntry.cs b/Warcraft.NET/Files/M2/Entries/EDGFEntry.cs new file mode 100644 index 0000000..346c50f --- /dev/null +++ b/Warcraft.NET/Files/M2/Entries/EDGFEntry.cs @@ -0,0 +1,71 @@ +using System.IO; + +namespace Warcraft.NET.Files.M2.Entries +{ + public class EDGFEntry + { + /// + /// unknown 2-floats array + /// + public float[] Unk0; + + /// + /// unknown float + /// + public float Unk1; + + /// + /// unknown 4 byte array + /// + public byte[] Unk2; + + /// + /// Initializes a new instance of the class. + /// + public EDGFEntry() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public EDGFEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + Unk0 = new float[2]; + Unk0[0] = br.ReadSingle(); + Unk0[1] = br.ReadSingle(); + Unk1 = br.ReadSingle(); + Unk2 = br.ReadBytes(4); + } + } + + /// + /// Gets the size of a EDGF Entry + /// + /// The size. + public static int GetSize() + { + return 16; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(Unk0[0]); + bw.Write(Unk0[1]); + bw.Write(Unk1); + bw.Write(Unk2); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/EXPTEntry.cs b/Warcraft.NET/Files/M2/Entries/EXPTEntry.cs new file mode 100644 index 0000000..5dab686 --- /dev/null +++ b/Warcraft.NET/Files/M2/Entries/EXPTEntry.cs @@ -0,0 +1,65 @@ +using System.IO; + +namespace Warcraft.NET.Files.M2.Entries +{ + public class EXPTEntry + { + + /// + /// replaces zSource from ParticleEmitter + /// + public float ZSource; + /// + /// colorMult is applied against particle's diffuse color + /// + public float ColorMult; + /// + ///alphaMult is applied against particle's opacity. + /// + public float AlphaMult; + + /// + /// Initializes a new instance of the class. + /// + public EXPTEntry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public EXPTEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + ZSource = br.ReadSingle(); + ColorMult = br.ReadSingle(); + AlphaMult = br.ReadSingle(); + } + } + + /// + /// Gets the size of a animation file id entry. + /// + /// The size. + public static int GetSize() + { + return 12; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(ZSource); + bw.Write(ColorMult); + bw.Write(AlphaMult); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/LDV1Entry.cs b/Warcraft.NET/Files/M2/Entries/LDV1Entry.cs new file mode 100644 index 0000000..007466f --- /dev/null +++ b/Warcraft.NET/Files/M2/Entries/LDV1Entry.cs @@ -0,0 +1,80 @@ +using System.IO; + +namespace Warcraft.NET.Files.M2.Entries +{ + public class LDV1Entry + { + /// + /// unknown field + /// + public ushort Unk0; + + /// + /// the maximum lod count + /// + public ushort LodCount; + + /// + /// unknown field + /// + public float Unk1; + + /// + /// lod serves as indes into this array + /// + public byte[] ParticleBoneLod; + + /// + /// unknown field + /// + public uint Unk2; + + /// + /// Initializes a new instance of the class. + /// + public LDV1Entry() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public LDV1Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + Unk0 = br.ReadUInt16(); + LodCount = br.ReadUInt16(); + Unk1 = br.ReadSingle(); + ParticleBoneLod = br.ReadBytes(4); + Unk2 = br.ReadUInt32(); + } + } + + /// + /// Gets the size of a LDV1 Entry + /// + /// The size. + public static int GetSize() + { + return 16; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(Unk0); + bw.Write(LodCount); + bw.Write(Unk1); + bw.Write(ParticleBoneLod); + bw.Write(Unk2); + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/WFV3Entry.cs b/Warcraft.NET/Files/M2/Entries/WFV3Entry.cs new file mode 100644 index 0000000..963bd66 --- /dev/null +++ b/Warcraft.NET/Files/M2/Entries/WFV3Entry.cs @@ -0,0 +1,197 @@ +using System; +using System.IO; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.M2.Entries +{ + public class WFV3Entry + { + /// + /// BumpScale -> Passed to vertex shader + /// + public float BumpScale; + + /// + /// value 0 x + /// + public float Value0X; + + /// + /// value 0 y + /// + public float Value0Y; + + /// + /// value 0 z + /// + public float Value0Z; + + /// + /// value 1 W + /// + public float Value1W; + + /// + /// value 0 W + /// + public float Value0W; + + /// + /// value 1 x + /// + public float Value1X; + + /// + /// value 1 y + /// + public float Value1Y; + + /// + /// value 2 w + /// + public float Value2W; + + /// + /// value 3 y + /// + public float Value3Y; + + /// + /// value 3 x + /// + public float Value3X; + + /// + /// BaseColor in rgba (not bgra) + /// + public RGBA BaseColor; + + /// + /// unknown Flags + /// + public ushort Flags; + + /// + /// unknown field + /// + public ushort Unk0; + + /// + /// value 3 W + /// + public float Value3W; + + /// + /// value 3 Z + /// + public float Value3Z; + + /// + /// value 4 y + /// + public float Value4Y; + + /// + /// unknown field + /// + public float Unk1; + + /// + /// unknown field + /// + public float Unk2; + + /// + /// unknown field + /// + public float Unk3; + + /// + /// unknown field + /// + public float Unk4; + + /// + /// Initializes a new instance of the class. + /// + public WFV3Entry() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public WFV3Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + BumpScale = br.ReadSingle(); + Value0X = br.ReadSingle(); + Value0Y = br.ReadSingle(); + Value0Z = br.ReadSingle(); + Value1W = br.ReadSingle(); + Value0W = br.ReadSingle(); + Value1X = br.ReadSingle(); + Value1Y = br.ReadSingle(); + Value2W = br.ReadSingle(); + Value3Y = br.ReadSingle(); + Value3X = br.ReadSingle(); + BaseColor = br.ReadRGBA(); + Flags = br.ReadUInt16(); + Unk0 = br.ReadUInt16(); + Value3W = br.ReadSingle(); + Value3Z = br.ReadSingle(); + Value4Y = br.ReadSingle(); + Unk1 = br.ReadSingle(); + Unk2 = br.ReadSingle(); + Unk3 = br.ReadSingle(); + Unk4 = br.ReadSingle(); + } + } + + /// + /// Gets the size of a WFV3 Entry + /// + /// The size. + public static int GetSize() + { + return 80; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(BumpScale); + bw.Write(Value0X); + bw.Write(Value0Y); + bw.Write(Value0Z); + bw.Write(Value1W); + bw.Write(Value0W); + bw.Write(Value1X); + bw.Write(Value1Y); + bw.Write(Value2W); + bw.Write(Value3Y); + bw.Write(Value3X); + bw.WriteRGBA(BaseColor); + bw.Write(Flags); + bw.Write(Unk0); + bw.Write(Value3W); + bw.Write(Value3Z); + bw.Write(Value4Y); + bw.Write(Unk1); + bw.Write(Unk2); + bw.Write(Unk3); + bw.Write(Unk4); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Model.cs b/Warcraft.NET/Files/M2/Model.cs index 9c251bf..29b3c6c 100644 --- a/Warcraft.NET/Files/M2/Model.cs +++ b/Warcraft.NET/Files/M2/Model.cs @@ -38,6 +38,63 @@ public class Model : ChunkedFile [ChunkOrder(5), ChunkOptional] public BFID BoneFileIds { get; set; } +<<<<<<< Updated upstream +======= + /// + /// Gets or sets the TXAC + /// + [ChunkOptional] + public TXAC CParticleEmitter2 { get; set; } + + /// + /// Gets or sets the particle extension + /// + [ChunkOptional] + public EXPT ExtendedParticle { get; set; } + + /// + /// Gets or sets the BlacklistAnimData + /// + [ChunkOptional] + public PABC M2InitBlacklistAnimData { get; set; } + + /// + /// Gets or sets the ParentAnimData + /// + [ChunkOptional] + public PADC M2InitParentAnimData { get; set; } + + /// + /// Gets or sets the ParentSequenceBoundsData + /// + [ChunkOptional] + public PSBC M2InitParentSequenceBoundsData { get; set; } + + /// + /// Gets or sets the ParentEventData + /// + [ChunkOptional] + public PEDC M2InitParentEventData { get; set; } + + /// + /// Gets or sets the model skeleton file ids + /// + [ChunkOptional] + public SKID SkeletonFileIds { get; set; } + + /// + /// Gets or sets the texture file ids + /// + [ChunkOptional] + public TXID TextureFileIds { get; set; } + + /// + /// Gets or sets the LodDataVersion1 + /// + [ChunkOptional] + public LDV1 LodDataVersion1 { get; set; } + +>>>>>>> Stashed changes /// /// Gets or sets the model recursive particle file ids /// @@ -51,6 +108,7 @@ public class Model : ChunkedFile public GPID GeometryParticleFileIds { get; set; } /// +<<<<<<< Updated upstream /// Gets or sets the model skeleton file ids /// [ChunkOrder(8), ChunkOptional] @@ -61,6 +119,66 @@ public class Model : ChunkedFile /// [ChunkOrder(9), ChunkOptional] public TXID TextureFileIds { get; set; } +======= + /// Gets or sets the WaterFallVersion1 + /// + [ChunkOptional] + public WFV1 WaterFallVersion1 { get; set; } + + /// + /// Gets or sets the WaterFallVersion2 + /// + [ChunkOptional] + public WFV2 WaterFallVersion2 { get; set; } + + /// + /// Gets or sets the ParticleGeosetData + /// + [ChunkOptional] + public PGD1 ParticleGeosetData { get; set; } + + /// + /// Gets or sets the WaterFallVersion3 + /// + [ChunkOptional] + public WFV3 WaterFallVersion3 { get; set; } + + /// + /// Gets or sets the Physics of the M2 + /// + [ChunkOptional] + public PFDC ModelPhysics { get; set; } + + /// + /// Gets or sets the EdgeFade + /// + [ChunkOptional] + public EDGF EdgeFade { get; set; } + + /// + /// Gets or sets the NERF + /// + [ChunkOptional] + public NERF NERF { get; set; } + + /// + /// Gets or sets the DETL (light related) + /// + [ChunkOptional] + public DETL DETL { get; set; } + + /// + /// Gets or sets the DBOC + /// + [ChunkOptional] + public DBOC DBOC { get; set; } + + /// + /// Gets or sets the AFRA + /// + [ChunkOptional] + public AFRA AFRA { get; set; } +>>>>>>> Stashed changes /// /// Initializes a new instance of the class. diff --git a/Warcraft.NET/Files/Phys/Entries/SPHSEntry.cs b/Warcraft.NET/Files/Phys/Entries/SPHSEntry.cs new file mode 100644 index 0000000..51ceec7 --- /dev/null +++ b/Warcraft.NET/Files/Phys/Entries/SPHSEntry.cs @@ -0,0 +1,52 @@ +using System.IO; +using System.Numerics; +using Warcraft.NET.Extensions; + +namespace Warcraft.NET.Files.Phys.Entries +{ + public class SPHSEntry + { + /// + /// Gets or Sets the local position of the Sphere shape + /// + public Vector3 LocalPosition; + + /// + /// Gets or Sets the radius of the Sphere shape + /// + public float Radius; + + public SPHSEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + LocalPosition = br.ReadVector3(); + Radius = br.ReadSingle(); + } + } + + /// + /// Gets the size of a Sphere entry. + /// + /// The size. + public static int GetSize() + { + return 16; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.WriteVector3(LocalPosition); + bw.Write(Radius); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/Phys/Enums/BodyType.cs b/Warcraft.NET/Files/Phys/Enums/BodyType.cs new file mode 100644 index 0000000..99a1779 --- /dev/null +++ b/Warcraft.NET/Files/Phys/Enums/BodyType.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Warcraft.NET.Files.Phys.Enums +{ + public enum BodyType : ushort + { + root = 0, + dynamic = 1, + unk = 2, + } +} diff --git a/Warcraft.NET/Files/Phys/Enums/JointType.cs b/Warcraft.NET/Files/Phys/Enums/JointType.cs new file mode 100644 index 0000000..28f6014 --- /dev/null +++ b/Warcraft.NET/Files/Phys/Enums/JointType.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Warcraft.NET.Files.Phys.Enums +{ + public enum JointType : ushort + { + sphericalJoint = 0, + shoulderJoint = 1, + weldJoint = 2, + revoluteJoint = 3, + prismaticJoint = 4, + distanceJoint = 5, + } +} diff --git a/Warcraft.NET/Files/Phys/Enums/ShapeType.cs b/Warcraft.NET/Files/Phys/Enums/ShapeType.cs new file mode 100644 index 0000000..108fc39 --- /dev/null +++ b/Warcraft.NET/Files/Phys/Enums/ShapeType.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Warcraft.NET.Files.Phys.Enums +{ + public enum ShapeType : short + { + box = 0, + caps = 1, + sphere = 2, + polytope = 3, + } +} diff --git a/Warcraft.NET/Files/Phys/Structures/PlytData.cs b/Warcraft.NET/Files/Phys/Structures/PlytData.cs new file mode 100644 index 0000000..65ddf95 --- /dev/null +++ b/Warcraft.NET/Files/Phys/Structures/PlytData.cs @@ -0,0 +1,29 @@ +using System; +using System.Numerics; + +namespace Warcraft.NET.Files.Phys.Structures +{ + [Serializable] + public struct PlytData + { + /// + /// gets or sets the vertices. Amount is defined by header.VertexCount + /// + public Vector3[] Vertices; //amount = VertexCount in Header + + /// + /// gets or sets the Unk1 array. Unknown purpose. Amount is defined by header.Count10 + /// + public byte[] Unk1; //multiple of 16 -> amount = count_10 in Header + + /// + /// gets or sets the Unk2 array. Unknown purpose.Amount is defined by header.Count10 + /// + public byte[] Unk2; //amount = count_10 in Header + + /// + /// gets or sets the Unk2 array. Unknown purpose.Amount is defined by header.NodeCount + /// + public PlytNode[] Nodes; + } +} diff --git a/Warcraft.NET/Files/Phys/Structures/PlytHeader.cs b/Warcraft.NET/Files/Phys/Structures/PlytHeader.cs new file mode 100644 index 0000000..6da1481 --- /dev/null +++ b/Warcraft.NET/Files/Phys/Structures/PlytHeader.cs @@ -0,0 +1,52 @@ +using System; + +namespace Warcraft.NET.Files.Phys.Structures +{ + public struct PlytHeader + { + /// + /// gets or sets the amount of vertices for this polytope + /// + public uint VertexCount; // Mostly 8 + /// + /// gets or sets unknown data + /// + public byte[] Unk0; //prev unk_04 + /// + /// gets or sets certain runtime data. Unknown purpose + /// + public UInt64 RUNTIME08ptrData0; // = &Data[i].unk_0 + /// + /// gets or sets the count10, which defines how many Unk1[] and Unk2[] there are inside the Data. + /// + public uint Count10; // Mostly 6 + /// + /// gets or sets the Unk1 array. Unknown purpose + /// + public byte[] Unk1; + /// + /// gets or sets certain runtime data. Unknown purpose + /// + public UInt64 RUNTIME18ptrData1; // = &Data[i].unk_1 + /// + /// gets or sets certain runtime data. Unknown purpose + /// + public UInt64 RUNTIME20ptrData2; // = &Data[i].unk_2 + /// + /// gets or sets the amount of nodes. Defines how Vertices are connected + /// + public uint NodeCount; // Mostly 24 + /// + /// gets or sets the Unk2 array. Unknown purpose + /// + public byte[] Unk2; + /// + /// gets or sets certain runtime data. Unknown purpose + /// + public UInt64 RUNTIME30ptrData3; // = &Data[i].unk_3 + /// + /// gets or sets the Unk3 array. Unknown purpose + /// + public float[] Unk3;// not sure if floats: has e-08 values + } +} diff --git a/Warcraft.NET/Files/Phys/Structures/PlytNode.cs b/Warcraft.NET/Files/Phys/Structures/PlytNode.cs new file mode 100644 index 0000000..92248da --- /dev/null +++ b/Warcraft.NET/Files/Phys/Structures/PlytNode.cs @@ -0,0 +1,26 @@ +using System; + +namespace Warcraft.NET.Files.Phys.Structures +{ + + [Serializable] + public struct PlytNode + { + /// + /// Unknown byte. Always 1 or -1 + /// + public byte Unk; // 1 or -1 + /// + /// Index into the data.Vertices + /// + public byte VertexIndex; // index in vertex list + /// + /// Index into data.Nodes + /// + public byte UnkIndex0; // index into the nodes + /// + /// Index into data.Nodes + /// + public byte UnkIndex1; // index into the nodes + } +} diff --git a/Warcraft.NET/Files/SKIN/Skin.cs b/Warcraft.NET/Files/SKIN/Skin.cs new file mode 100644 index 0000000..9131b41 --- /dev/null +++ b/Warcraft.NET/Files/SKIN/Skin.cs @@ -0,0 +1,173 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.SKIN +{ + [AutoDocFile("skin")] + public class Skin + { + public List Vertices { get; set; } //index into M2s vertex list with offset + public List Triangles { get; set; } //3 indices per entry into vertices + public List BoneIndices { get; set; } + public List Submeshes { get; set; } + public List TextureUnits { get; set; } + + public uint GlobalVertexOffset; //start offset into M2.Vertices -> something else in wotlk + + public List ShadowBatches; + + public byte[] Unk0; //Padding? + + public bool Wotlk = false; + + public Skin(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var magic = br.ReadUInt32(); + var nVertices = br.ReadUInt32(); + var ofsVertices = br.ReadUInt32(); + var nIndices = br.ReadUInt32(); + var ofsIndices = br.ReadUInt32(); + if (ofsVertices == 48) + { + Wotlk = true; + } + var nBones = br.ReadUInt32(); + var ofsBones = br.ReadUInt32(); + var nSubmeshes = br.ReadUInt32(); + var ofsSubmeshes = br.ReadUInt32(); + var nBatches = br.ReadUInt32(); + var ofsBatches = br.ReadUInt32(); + GlobalVertexOffset = br.ReadUInt32(); + + ShadowBatches = new List(); + Unk0 = new byte[8]; + if (!Wotlk) + { + var nShadow_batches = br.ReadUInt32(); + var ofsShadow_batches = br.ReadUInt32(); + Unk0 = br.ReadBytes(8); + ShadowBatches = ReadStructList(nShadow_batches, ofsShadow_batches, br); + } + Vertices = ReadStructList(nVertices, ofsVertices, br); + Triangles = ReadStructList(nIndices / 3, ofsIndices, br); + BoneIndices = ReadStructList(nBones, ofsBones, br); + Submeshes = ReadStructList(nSubmeshes, ofsSubmeshes, br); + TextureUnits = ReadStructList(nBatches, ofsBatches, br); + + } + } + private List ReadStructList(uint count, uint offset, BinaryReader br) where T : struct + { + br.BaseStream.Position = offset; + List list = new List(); + + for (var i = 0; i < count; i++) + list.Add(br.ReadStruct()); + + return list; + } + + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + //Writing Empty Header -> Filling with data after writing the data + if (Wotlk) + { + bw.Write(new byte[48]); + } + else + { + bw.Write(new byte[64]); + } + + foreach (ushort vertex in Vertices) + { + bw.Write(vertex); + } + + int _ofsTriangles = (int)bw.BaseStream.Position; + foreach (M2Triangle triangle in Triangles) + { + bw.WriteStruct(triangle); + } + + int _ofsBones = (int)bw.BaseStream.Position; + foreach (M2SkinBoneStruct bone in BoneIndices) + { + bw.WriteStruct(bone); + } + + int _ofsSubmeshes = (int)bw.BaseStream.Position; + foreach (M2SkinSection submesh in Submeshes) + { + bw.WriteStruct(submesh); + } + + int _ofsTexUnits = (int)bw.BaseStream.Position; + foreach (M2Batch texUnit in TextureUnits) + { + bw.WriteStruct(texUnit); + } + + int _ofsShadowBatches = (int)bw.BaseStream.Position; + if (!Wotlk) + { + foreach (M2ShadowBatch shadowBatch in ShadowBatches) + { + bw.WriteStruct(shadowBatch); + } + } + //Writing actual header data + bw.BaseStream.Position = 0; + bw.Write('S'); + bw.Write('K'); + bw.Write('I'); + bw.Write('N'); + + bw.Write(Vertices.Count); + var _ofsVertices = 64; + if (Wotlk) + _ofsVertices = 48; + bw.Write(_ofsVertices); + + bw.Write(Triangles.Count * 3); + bw.Write(_ofsTriangles); + + bw.Write(BoneIndices.Count); + bw.Write(_ofsBones); + + bw.Write(Submeshes.Count); + bw.Write(_ofsSubmeshes); + + bw.Write(TextureUnits.Count); + bw.Write(_ofsTexUnits); + + bw.Write(GlobalVertexOffset); + + if (!Wotlk) + { + bw.Write(ShadowBatches.Count); + bw.Write(_ofsShadowBatches); + bw.Write(Unk0); + } + return ms.ToArray(); + } + } + + /// + public uint GetSize() + { + return (uint)Serialize().Length; + } + } +} + + diff --git a/Warcraft.NET/Files/Structures/M2Batch.cs b/Warcraft.NET/Files/Structures/M2Batch.cs new file mode 100644 index 0000000..97891b0 --- /dev/null +++ b/Warcraft.NET/Files/Structures/M2Batch.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Warcraft.NET.Files.Structures +{ + public struct M2Batch + { + public byte Flags; // Usually 16 for static textures, and 0 for animated textures. &0x1: materials invert something; &0x2: transform &0x4: projected texture; &0x10: something batch compatible; &0x20: projected texture?; &0x40: possibly don't multiply transparency by texture weight transparency to get final transparency value(?) + public sbyte PriorityPlane; + public ushort ShaderId; // See below. + public ushort SkinSectionIndex; // A duplicate entry of a submesh from the list above. + public ushort GeosetIndex; // See below. New name: flags2. 0x2 - projected. 0x8 - EDGF chunk in m2 is mandatory and data from is applied to this mesh + public ushort ColorIndex; // A Color out of the Colors-Block or -1 if none. + public ushort MaterialIndex; // The renderflags used on this texture-unit. + public ushort MaterialLayer; // Capped at 7 (see CM2Scene::BeginDraw) + public ushort TextureCount; // 1 to 4. See below. Also seems to be the number of textures to load, starting at the texture lookup in the next field (0x10). + public ushort TextureComboIndex; // Index into Texture lookup table + public ushort TextureCoordComboIndex; // Index into the texture mapping lookup table. + public ushort TextureWeightComboIndex; // Index into transparency lookup table. + public ushort TextureTransformComboIndex; // Index into uvanimation lookup table. + } +} diff --git a/Warcraft.NET/Files/Structures/M2ShadowBatch.cs b/Warcraft.NET/Files/Structures/M2ShadowBatch.cs new file mode 100644 index 0000000..ca6a815 --- /dev/null +++ b/Warcraft.NET/Files/Structures/M2ShadowBatch.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Warcraft.NET.Files.Structures +{ + public struct M2ShadowBatch + { + public byte Flags; // if auto-generated: M2Batch.Flags & 0xFF + public byte Flags2; // if auto-generated: (renderFlag[i].Flags & 0x04 ? 0x01 : 0x00) + // | (!renderFlag[i].Blendingmode ? 0x02 : 0x00) + // | (renderFlag[i].Flags & 0x80 ? 0x04 : 0x00) + // | (renderFlag[i].Flags & 0x400 ? 0x06 : 0x00) + public ushort Unk1; + public ushort SubmeshId; + public ushort TextureId; // already looked-up + public ushort ColorId; + public ushort TransparencyId; // already looked-up + } +} diff --git a/Warcraft.NET/Files/Structures/M2SkinBoneStruct.cs b/Warcraft.NET/Files/Structures/M2SkinBoneStruct.cs new file mode 100644 index 0000000..0da3e2b --- /dev/null +++ b/Warcraft.NET/Files/Structures/M2SkinBoneStruct.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Warcraft.NET.Files.Structures +{ + public struct M2SkinBoneStruct + { + public byte Bone1ID; + public byte Bone2ID; + public byte Bone3ID; + public byte Bone4ID; + } +} diff --git a/Warcraft.NET/Files/Structures/M2SkinSection.cs b/Warcraft.NET/Files/Structures/M2SkinSection.cs new file mode 100644 index 0000000..5aee7c2 --- /dev/null +++ b/Warcraft.NET/Files/Structures/M2SkinSection.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using System.Text; + +namespace Warcraft.NET.Files.Structures +{ + public struct M2SkinSection + { + public ushort SkinSectionId; // Mesh part ID, see below. + public ushort Level; // (level << 16) is added (|ed) to startTriangle and alike to avoid having to increase those fields to uint32s. + public ushort VertexStart; // Starting vertex number. + public ushort VertexCount; // Number of vertices. + public ushort IndexStart; // Starting triangle index (that's 3* the number of triangles drawn so far). + public ushort IndexCount; // Number of triangle indices. + public ushort BoneCount; // Number of elements in the bone lookup table. Max seems to be 256 in Wrath. Shall be ≠ 0. + public ushort BoneComboIndex; // Starting index in the bone lookup table. + public ushort BoneInfluences; // <= 4 + // from <=BC documentation: Highest number of bones needed at one time in this Submesh --Tinyn (wowdev.org) + // In 2.x this is the amount of of bones up the parent-chain affecting the submesh --NaK + // Highest number of bones referenced by a vertex of this submesh. 3.3.5a and suspectedly all other client revisions. -- Skarn + public ushort CenterBoneIndex; + public Vector3 CenterPosition; // Average position of all the vertices in the sub mesh. + //≥BC + public Vector3 SortCenterPosition; // The center of the box when an axis aligned box is built around the vertices in the submesh. + public float SortRadius; // Distance of the vertex farthest from CenterBoundingBox. + } +} diff --git a/Warcraft.NET/Files/Structures/M2Triangle.cs b/Warcraft.NET/Files/Structures/M2Triangle.cs new file mode 100644 index 0000000..250ad77 --- /dev/null +++ b/Warcraft.NET/Files/Structures/M2Triangle.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Warcraft.NET.Files.Structures +{ + public struct M2Triangle //132->Left handed; 123->right handed + { + public ushort Vertex1; + public ushort Vertex3; + public ushort Vertex2; + } +} diff --git a/Warcraft.NET/Files/Structures/Matrix3x4.cs b/Warcraft.NET/Files/Structures/Matrix3x4.cs new file mode 100644 index 0000000..cbdbdf0 --- /dev/null +++ b/Warcraft.NET/Files/Structures/Matrix3x4.cs @@ -0,0 +1,52 @@ +using System.Collections.Generic; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Structures; +using System.Numerics; +using System.IO; +using Warcraft.NET.Extensions; + +public class Matrix3x4 : IFlattenableData +{ + public Vector3 RotationX { get; set; } + public Vector3 RotationY { get; set; } + public Vector3 RotationZ { get; set; } + public Vector3 Scale { get; set; } + public Vector3 Position { get; set; } + + public Matrix3x4 (Vector3 column1, Vector3 column2, Vector3 column3, Vector3 column4) + { + float scaleX = column1.Length(); + float scaleY = column2.Length(); + float scaleZ = column3.Length(); + + RotationX = column1 / scaleX; + RotationY = column2 / scaleY; + RotationZ = column3 / scaleZ; + + Scale = new Vector3(scaleX, scaleY, scaleZ); + Position = column4; + } + + public Vector3 GetForward() + { + return Vector3.Normalize(RotationZ); + } + + public Vector3 GetUp() + { + return Vector3.Normalize(RotationY); + } + + public Vector3 GetRight() + { + return Vector3.Normalize(RotationX); + } + + public IReadOnlyCollection Flatten() + { + return new[] { + GetForward().X,GetForward().Y,GetForward().Z, + Scale.X, Scale.Y, Scale.Z, + Position.X, Position.Y, Position.Z }; + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Chunks/BDY4.cs b/Warcraft.NET/Files/phys/Chunks/BDY4.cs new file mode 100644 index 0000000..c3efe6f --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/BDY4.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Phys.Entries; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class BDY4 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "BDY4"; + + /// + /// Gets or Sets the used rigidbodies(V4) + /// + public List BDY4Entries = new(); + + /// + /// Initializes a new instance of + /// + public BDY4() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public BDY4(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var bdy4count = br.BaseStream.Length / BDY4Entry.GetSize(); + + for (var i = 0; i < bdy4count; ++i) + { + BDY4Entries.Add(new BDY4Entry(br.ReadBytes(BDY4Entry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (BDY4Entry obj in BDY4Entries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/BOXS.cs b/Warcraft.NET/Files/phys/Chunks/BOXS.cs new file mode 100644 index 0000000..98128a9 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/BOXS.cs @@ -0,0 +1,68 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Phys.Entries; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class BOXS : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "BOXS"; + + /// + /// sets or gets the box shapes + /// + public List BOXSEntries = new(); + + /// + /// Initializes a new instance of + /// + public BOXS() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public BOXS(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var boxscount = br.BaseStream.Length / BOXSEntry.GetSize(); + + for (var i = 0; i < boxscount; ++i) + { + BOXSEntries.Add(new BOXSEntry(br.ReadBytes(BOXSEntry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (BOXSEntry obj in BOXSEntries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/CAPS.cs b/Warcraft.NET/Files/phys/Chunks/CAPS.cs new file mode 100644 index 0000000..26fab82 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/CAPS.cs @@ -0,0 +1,68 @@ +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using System.Collections.Generic; +using Warcraft.NET.Files.Phys.Entries; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class CAPS : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "CAPS"; + + /// + /// sets or gets the capsule shapes + /// + public List CAPSEntries = new(); + + /// + /// Initializes a new instance of + /// + public CAPS() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public CAPS(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var capscount = br.BaseStream.Length / CAPSEntry.GetSize(); + + for (var i = 0; i < capscount; ++i) + { + CAPSEntries.Add(new CAPSEntry(br.ReadBytes(CAPSEntry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (CAPSEntry obj in CAPSEntries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/DSTJ.cs b/Warcraft.NET/Files/phys/Chunks/DSTJ.cs new file mode 100644 index 0000000..55e9cdd --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/DSTJ.cs @@ -0,0 +1,70 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class DSTJ : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "DSTJ"; + + /// + /// sets or gets the distance joints + /// + public List DSTJEntries = new(); + + /// + /// Initializes a new instance of + /// + public DSTJ() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public DSTJ(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var DSTJcount = br.BaseStream.Length / DSTJEntry.GetSize(); + + for (var i = 0; i < DSTJcount; ++i) + { + DSTJEntries.Add(new DSTJEntry(br.ReadBytes(DSTJEntry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (DSTJEntry obj in DSTJEntries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/JOIN.cs b/Warcraft.NET/Files/phys/Chunks/JOIN.cs new file mode 100644 index 0000000..d278dc8 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/JOIN.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class JOIN : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "JOIN"; + + /// + /// sets or gets the joints + /// + public List JOINEntries = new(); + + /// + /// Initializes a new instance of + /// + public JOIN() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public JOIN(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var JOINcount = br.BaseStream.Length / JOINEntry.GetSize(); + for (var i = 0; i < JOINcount; ++i) + { + JOINEntries.Add(new JOINEntry(br.ReadBytes(JOINEntry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (JOINEntry obj in JOINEntries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/PHYS.cs b/Warcraft.NET/Files/phys/Chunks/PHYS.cs new file mode 100644 index 0000000..7226e29 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/PHYS.cs @@ -0,0 +1,58 @@ +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class PHYS : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PHYS"; + + /// + /// Gets or Sets the version of the physics + /// + public ushort Version; + + /// + /// Initializes a new instance of + /// + public PHYS() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PHYS(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + Version = br.ReadUInt16(); + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(Version); + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/PHYT.cs b/Warcraft.NET/Files/phys/Chunks/PHYT.cs new file mode 100644 index 0000000..2ac67b7 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/PHYT.cs @@ -0,0 +1,59 @@ +using System; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class PHYT : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PHYT"; + + /// + /// Gets or Sets PHYT (unknown) + /// + public uint Phyt; + + /// + /// Initializes a new instance of + /// + public PHYT() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PHYT(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + Phyt = br.ReadUInt32(); + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write(Phyt); + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/PHYV.cs b/Warcraft.NET/Files/phys/Chunks/PHYV.cs new file mode 100644 index 0000000..c102552 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/PHYV.cs @@ -0,0 +1,73 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Phys.Entries; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class PHYV : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PHYV"; + + /// + /// Gets or Sets the PHYV (unknown) + /// + public float[] Values; + + /// + /// Initializes a new instance of + /// + public PHYV() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PHYV(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var PHYVcount = br.BaseStream.Length / 24; + Values = new float[PHYVcount * 6]; + for (var i = 0; i < PHYVcount; ++i) + { + Values[i] = br.ReadSingle(); + Values[i+1] = br.ReadSingle(); + Values[i+2] = br.ReadSingle(); + Values[i+3] = br.ReadSingle(); + Values[i+4] = br.ReadSingle(); + Values[i+5] = br.ReadSingle(); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (float f in Values) + { + bw.Write(f); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/PLYT.cs b/Warcraft.NET/Files/phys/Chunks/PLYT.cs new file mode 100644 index 0000000..65a3277 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/PLYT.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Numerics; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.ADT.Terrain.MCNK; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Phys.Entries; +using Warcraft.NET.Files.Phys.Structures; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class PLYT : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PLYT"; + + /// + /// sets or gets the polytope shapes + /// + public List PLYTEntries = new(); + + /// + /// Initializes a new instance of + /// + public PLYT() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PLYT(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var PLYTcount = br.ReadUInt32(); + for (var i = 0; i < PLYTcount; i++) + { + PLYTEntry plyt_entry = new PLYTEntry(br.ReadBytes(80)); + PLYTEntries.Add(plyt_entry); + } + for (var j = 0; j < PLYTcount; j++) + { + PLYTEntry plyt_entry = PLYTEntries[j]; + plyt_entry.DeserializeData(br.ReadBytes(plyt_entry.DataSize)); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.Write((uint)PLYTEntries.Count); + foreach (PLYTEntry obj in PLYTEntries) + { + Console.WriteLine("Writing Plyt Header Length: " + obj.SerializeHeader().Length); + bw.Write(obj.SerializeHeader()); + } + foreach (PLYTEntry obj in PLYTEntries) + { + bw.Write(obj.SerializeData()); + Console.WriteLine("Writing Plyt Data Length:" + obj.SerializeData().Length); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/PRS2.cs b/Warcraft.NET/Files/phys/Chunks/PRS2.cs new file mode 100644 index 0000000..7635418 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/PRS2.cs @@ -0,0 +1,70 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class PRS2 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "PRS2"; + + /// + /// sets or gets the prismatic(V2) joints + /// + public List PRS2Entries = new(); + + /// + /// Initializes a new instance of + /// + public PRS2() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public PRS2(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var PRS2count = br.BaseStream.Length / PRS2Entry.GetSize(); + + for (var i = 0; i < PRS2count; ++i) + { + PRS2Entries.Add(new PRS2Entry(br.ReadBytes(PRS2Entry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (PRS2Entry obj in PRS2Entries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/REV2.cs b/Warcraft.NET/Files/phys/Chunks/REV2.cs new file mode 100644 index 0000000..57ebd62 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/REV2.cs @@ -0,0 +1,70 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class REV2 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "REV2"; + + /// + /// sets or gets the revolute(V2) joints + /// + public List REV2Entries = new(); + + /// + /// Initializes a new instance of + /// + public REV2() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public REV2(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var REV2count = br.BaseStream.Length / REV2Entry.GetSize(); + + for (var i = 0; i < REV2count; ++i) + { + REV2Entries.Add(new REV2Entry(br.ReadBytes(REV2Entry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (REV2Entry obj in REV2Entries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/SHJ2.cs b/Warcraft.NET/Files/phys/Chunks/SHJ2.cs new file mode 100644 index 0000000..4ee4adf --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/SHJ2.cs @@ -0,0 +1,70 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class SHJ2 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "SHJ2"; + + /// + /// sets or gets the shoulder(V2) joints + /// + public List SHJ2Entries = new(); + + /// + /// Initializes a new instance of + /// + public SHJ2() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public SHJ2(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var SHJ2count = br.BaseStream.Length / SHJ2Entry.GetSize(); + + for (var i = 0; i < SHJ2count; ++i) + { + SHJ2Entries.Add(new SHJ2Entry(br.ReadBytes(SHJ2Entry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (SHJ2Entry obj in SHJ2Entries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/SHOJ.cs b/Warcraft.NET/Files/phys/Chunks/SHOJ.cs new file mode 100644 index 0000000..75bac28 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/SHOJ.cs @@ -0,0 +1,70 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Phys.Entries; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class SHOJ : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "SHOJ"; + + /// + /// sets or gets the shoulder joints + /// + public List SHOJEntries = new(); + + /// + /// Initializes a new instance of + /// + public SHOJ() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public SHOJ(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var SHOJcount = br.BaseStream.Length / SHOJEntry.GetSize(); + + for (var i = 0; i < SHOJcount; ++i) + { + SHOJEntries.Add(new SHOJEntry(br.ReadBytes(SHOJEntry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (SHOJEntry obj in SHOJEntries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/SHP2.cs b/Warcraft.NET/Files/phys/Chunks/SHP2.cs new file mode 100644 index 0000000..21f1265 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/SHP2.cs @@ -0,0 +1,68 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Phys.Entries; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class SHP2 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "SHP2"; + + /// + /// sets or gets the shapes(V2) + /// + public List SHP2Entries = new(); + + /// + /// Initializes a new instance of + /// + public SHP2() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public SHP2(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var SHP2count = br.BaseStream.Length / SHP2Entry.GetSize(); + + for (var i = 0; i < SHP2count; ++i) + { + SHP2Entries.Add(new SHP2Entry(br.ReadBytes(SHP2Entry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (SHP2Entry obj in SHP2Entries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/SPHJ.cs b/Warcraft.NET/Files/phys/Chunks/SPHJ.cs new file mode 100644 index 0000000..fd01294 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/SPHJ.cs @@ -0,0 +1,68 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Phys.Entries; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class SPHJ : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "SPHJ"; + + /// + /// sets or gets the spherical joints + /// + public List SPHJEntries = new(); + + /// + /// Initializes a new instance of + /// + public SPHJ() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public SPHJ(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var SPHJcount = br.BaseStream.Length / SPHJEntry.GetSize(); + + for (var i = 0; i < SPHJcount; ++i) + { + SPHJEntries.Add(new SPHJEntry(br.ReadBytes(SPHJEntry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (SPHJEntry obj in SPHJEntries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/SPHS.cs b/Warcraft.NET/Files/phys/Chunks/SPHS.cs new file mode 100644 index 0000000..5b55a64 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/SPHS.cs @@ -0,0 +1,68 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Phys.Entries; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class SPHS : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "SPHS"; + + /// + /// sets or gets a list of sphere shapes + /// + public List Spheres = new(); + + /// + /// Initializes a new instance of + /// + public SPHS() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public SPHS(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var SHP2count = br.BaseStream.Length / SHP2Entry.GetSize(); + + for (var i = 0; i < SHP2count; ++i) + { + Spheres.Add(new SPHSEntry(br.ReadBytes(SPHSEntry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (SPHSEntry obj in Spheres) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Chunks/WLJ3.cs b/Warcraft.NET/Files/phys/Chunks/WLJ3.cs new file mode 100644 index 0000000..b71e7a7 --- /dev/null +++ b/Warcraft.NET/Files/phys/Chunks/WLJ3.cs @@ -0,0 +1,68 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Phys.Entries; + +namespace Warcraft.NET.Files.Phys.Chunks +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] + public class WLJ3 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "WLJ3"; + + /// + /// sets or gets a list of Weld(V3) Joints + /// + public List WLJ3Entries = new(); + + /// + /// Initializes a new instance of + /// + public WLJ3() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public WLJ3(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var WLJ3count = br.BaseStream.Length / WLJ3Entry.GetSize(); + + for (var i = 0; i < WLJ3count; ++i) + { + WLJ3Entries.Add(new WLJ3Entry(br.ReadBytes(WLJ3Entry.GetSize()))); + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (WLJ3Entry obj in WLJ3Entries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs b/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs new file mode 100644 index 0000000..1ae1d46 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs @@ -0,0 +1,140 @@ +using System.IO; +using System.Numerics; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Phys.Enums; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.Phys.Entries +{ + public class BDY4Entry + { + /// + /// Sets or gets the BodyType of the rigidbody + /// 0=static + /// 1=dynamic + /// 2=unknown + /// + public BodyType BodyType { get; set; } // maps to dmBodyDef BodyType enum. 0 -> 1, 1 -> 0 = dm_dynamicBody, * -> 2. Only one should be of BodyType 0 (root). possibly only 0 and 1. + + /// + /// Sets or gets the index of the bone, which is connected to this rigidbody + /// + public ushort BoneIndex { get; set; } + + /// + /// sets or gets the default Position of the rigidbody + /// + public Vector3 Position { get; set; } = new Vector3(0,0,0); + + /// + /// sets or gets the index of the shape, which is connected to this rigidbody + /// + public ushort ShapesIndex { get; set; } + + /// + /// sets or gets a currently unknown field. Possibly 'Padding' + /// + public byte[] Unk0 { get; set; } = {0,0}; + + /// + /// sets or gets the amount of shapes this rigidbody has + /// + public int ShapesCount { get; set; } // shapes_count shapes are in this body. + + /// + /// sets or gets a currently unknown field. Possibly 'UpliftFactor' + /// + public float Unk1 { get; set; } = 0f; + + //#if version >= 3 // BDY3 + /// + /// sets or gets a currently unknown field. Possibly 'GravityScale' + /// + public float Unk2 { get; set; } = 1.0f; + + /// + /// sets or gets the Drag value of the rigidbody. + /// + public float Drag { get; set; } = 0f; + + /// + /// sets or gets a currently unknown field. Possibly 'Mass/Weight' + /// + public float Unk3 = 0f; // default 0, seems to be some sort of weight. + // If version >= 3 and Unk3 == 0 the body will be non kinematic even if the flag is set, it needs to get its transform from the parent bone. + // See offhand_1h_artifactskulloferedar_d_06 where all the bodies have the kinematic flag + /// + /// sets or gets a currently unknown field. + /// + public float Unk4 { get; set; } = 0.89999998f; + + /// + /// sets or gets a currently unknown field. + /// + public byte[] Unk5 { get; set; } = { 0,0,0,0}; + + /// + /// Initializes a new instance of the class. + /// + public BDY4Entry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public BDY4Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + BodyType = (BodyType)br.ReadUInt16(); + BoneIndex = br.ReadUInt16(); + Position = br.ReadVector3(AxisConfiguration.ZUp); + ShapesIndex = br.ReadUInt16(); + Unk0 = br.ReadBytes(2); + ShapesCount = br.ReadInt32(); + Unk1 = br.ReadSingle(); + Unk2 = br.ReadSingle(); + Drag = br.ReadSingle(); + Unk3 = br.ReadSingle(); + Unk4 = br.ReadSingle(); + Unk5 = br.ReadBytes(4); + } + } + + /// + /// Gets the size of a bdy4 entry. + /// + /// The size. + public static int GetSize() + { + return 48; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write((ushort)BodyType); + bw.Write(BoneIndex); + bw.Write(Position.X); + bw.Write(Position.Y); + bw.Write(Position.Z); + bw.Write(ShapesIndex); + bw.Write(Unk0); + bw.Write(ShapesCount); + bw.Write(Unk1); + bw.Write(Unk2); + bw.Write(Drag); + bw.Write(Unk3); + bw.Write(Unk4); + bw.Write(Unk5); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/BOXSEntry.cs b/Warcraft.NET/Files/phys/Entries/BOXSEntry.cs new file mode 100644 index 0000000..8fffebd --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/BOXSEntry.cs @@ -0,0 +1,52 @@ +using System.IO; +using System.Numerics; +using Warcraft.NET.Extensions; + +namespace Warcraft.NET.Files.Phys.Entries +{ + public class BOXSEntry + { + /// + /// Gets or Sets the transformation matrix of the box shape + /// + public Matrix3x4 Dimensions; + + /// + /// Gets or Sets the local position of the box shape + /// + public Vector3 Position; + + public BOXSEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + Dimensions = br.ReadMatrix3x4(); + Position = br.ReadVector3(); + } + } + + /// + /// Gets the size of a box entry. + /// + /// The size. + public static int GetSize() + { + return 60; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.WriteMatrix3x4(Dimensions); + bw.WriteVector3(Position); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/CAPSEntry.cs b/Warcraft.NET/Files/phys/Entries/CAPSEntry.cs new file mode 100644 index 0000000..f8c08ac --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/CAPSEntry.cs @@ -0,0 +1,58 @@ +using System.IO; +using System.Numerics; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Phys.Chunks; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.Phys.Entries +{ + public class CAPSEntry + { + /// + /// Gets or Sets the local start position of this capsule shape + /// + public Vector3 LocalPosition1; + + /// + /// Gets or Sets the local end position of this capsule shape + /// + public Vector3 LocalPosition2; + + /// + /// Gets or Sets the Radius of this capsule shape + /// + public float Radius; + + public CAPSEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + LocalPosition1 = br.ReadVector3(AxisConfiguration.ZUp); + LocalPosition2 = br.ReadVector3(AxisConfiguration.ZUp); + Radius = br.ReadSingle(); + } + } + /// + /// Gets the size of a caps entry. + /// + /// The size. + public static int GetSize() + { + return 28; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.WriteVector3(LocalPosition1); + bw.WriteVector3(LocalPosition2); + bw.Write(Radius); + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/DSTJEntry.cs b/Warcraft.NET/Files/phys/Entries/DSTJEntry.cs new file mode 100644 index 0000000..3ffee70 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/DSTJEntry.cs @@ -0,0 +1,69 @@ +using System.IO; +using System.Numerics; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.Phys.Entries +{ + public class DSTJEntry + { + /// + /// sets or gets the local Anchor for Bone A from the Joint + /// + public Vector3 LocalAnchorA; + + /// + /// sets or gets the local Anchor for Bone B from the Joint + /// + public Vector3 LocalAnchorB; + + /// + /// sets or gets the currently unknown value for the distance joint calculation + /// + public float UnknownDistanceFactor; + + /// + /// Initializes a new instance of the class. + /// + public DSTJEntry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public DSTJEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + LocalAnchorA = br.ReadVector3(); + LocalAnchorB = br.ReadVector3(); + UnknownDistanceFactor = br.ReadSingle(); + } + } + + /// + /// Gets the size of a DSTJ entry. + /// + /// The size. + public static int GetSize() + { + return 28; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.WriteVector3(LocalAnchorA); + bw.WriteVector3(LocalAnchorB); + bw.Write(UnknownDistanceFactor); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/JOINEntry.cs b/Warcraft.NET/Files/phys/Entries/JOINEntry.cs new file mode 100644 index 0000000..8d07115 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/JOINEntry.cs @@ -0,0 +1,89 @@ +using System.IO; +using Warcraft.NET.Files.Phys.Enums; + +namespace Warcraft.NET.Files.Phys.Entries +{ + + + public class JOINEntry + { + /// + /// sets or gets the index of the first connected Rigidbody + /// + public uint BodyAIdx; + + /// + /// sets or gets the index of the second connected Rigidbody + /// + public uint BodyBIdx; + + /// + /// sets or gets a Unknown field. + /// + public byte[] Unk; + + /// + /// sets or gets the JointType + /// 0 = SphericalJoint + /// 1 = ShoulderJoint + /// 2 = WeldJoint + /// 3 = RevoluteJoint + /// 4 = PrismaticJoint + /// 5 = DistanceJoint + /// + public JointType JointType; + + /// + /// sets or gets the index of the joint into the joint list based on the JointType field + /// + public ushort JointID; + + /// + /// Initializes a new instance of the class. + /// + public JOINEntry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public JOINEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + BodyAIdx = br.ReadUInt32(); + BodyBIdx = br.ReadUInt32(); + Unk = br.ReadBytes(4); + JointType = (JointType)br.ReadUInt16(); + JointID = br.ReadUInt16(); + } + } + + /// + /// Gets the size of a JOIN entry. + /// + /// The size. + public static int GetSize() + { + return 16; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(BodyAIdx); + bw.Write(BodyBIdx); + bw.Write(Unk); + bw.Write((ushort)JointType); + bw.Write(JointID); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs b/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs new file mode 100644 index 0000000..b6bfca2 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs @@ -0,0 +1,177 @@ +using SharpCompress.Common; +using System.IO; +using System.Numerics; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Phys.Structures; + +namespace Warcraft.NET.Files.Phys.Entries +{ + public class PLYTEntry + { + /// + /// gets or set the Polytope Header + /// + public PlytHeader Header; + + /// + /// gets or set the Polytope Data + /// + public PlytData Data; + + /// + /// gets or set the Polytope Data + /// + public int DataSize { get; } + + /// + /// Initializes a new instance of the class. + /// + public PLYTEntry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public PLYTEntry(byte[] header) + { + using (var ms = new MemoryStream(header)) + using (var br = new BinaryReader(ms)) + { + Header = new PlytHeader + { + VertexCount = br.ReadUInt32(), + Unk0 = br.ReadBytes(4), + RUNTIME08ptrData0 = br.ReadUInt64(), + Count10 = br.ReadUInt32(), + Unk1 = br.ReadBytes(4), + RUNTIME18ptrData1 = br.ReadUInt64(), + RUNTIME20ptrData2 = br.ReadUInt64(), + NodeCount = br.ReadUInt32(), + Unk2 = br.ReadBytes(4), + RUNTIME30ptrData3 = br.ReadUInt64(), + Unk3 = [br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()] + }; + int size = 0; + size += (int)Header.VertexCount * 12; + size += (int)Header.Count10 * 16; + size += (int)Header.Count10; + size += (int)Header.NodeCount * 4; + DataSize = size; + } + } + + public void DeserializeData(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + uint vcount = Header.VertexCount; + uint count_10 = Header.Count10; + uint nodeCount = Header.NodeCount; + + Data.Vertices = new Vector3[vcount]; + for (int v = 0; v < vcount; v++) + { + Data.Vertices[v] = br.ReadVector3(); + } + Data.Unk1 = br.ReadBytes((int)count_10 * 16); + Data.Unk2 = br.ReadBytes((int)count_10); + Data.Nodes = new PlytNode[nodeCount]; + for (int n = 0; n < nodeCount; n++) + { + PlytNode node = new PlytNode(); + node.Unk = br.ReadByte(); + node.VertexIndex = br.ReadByte(); + node.UnkIndex0 = br.ReadByte(); + node.UnkIndex1 = br.ReadByte(); + Data.Nodes[n] = node; + } + } + } + + /// + /// gets the data size of the polytope. + /// + /// The size. + public int GetDataSize() + { + return SerializeData().Length; + } + + /// + /// gets the header size of the polytope. + /// + /// The size. + public int GetHeaderSize() + { + return SerializeHeader().Length; + } + + /// + /// gets the full size of the polytope. + /// + /// The size. + public int GetSize() + { + return SerializeHeader().Length + SerializeData().Length; + } + + /// + public byte[] SerializeHeader(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(Header.VertexCount); + bw.Write(Header.Unk0); + + bw.Write(Header.RUNTIME08ptrData0); + + bw.Write(Header.Count10); + bw.Write(Header.Unk1); + + bw.Write(Header.RUNTIME18ptrData1); + + bw.Write(Header.RUNTIME20ptrData2); + + bw.Write(Header.NodeCount); + + bw.Write(Header.Unk2); + + bw.Write(Header.RUNTIME30ptrData3); + foreach (float f in Header.Unk3) + { + bw.Write(f); + } + } + return ms.ToArray(); + } + } + + /// + public byte[] SerializeData(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + foreach (var vertex in Data.Vertices) + { + bw.WriteVector3(vertex); + } + bw.Write(Data.Unk1); + bw.Write(Data.Unk2); + foreach (var node in Data.Nodes) + { + bw.Write(node.Unk); + bw.Write(node.VertexIndex); + bw.Write(node.UnkIndex0); + bw.Write(node.UnkIndex1); + } + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/PRS2Entry.cs b/Warcraft.NET/Files/phys/Entries/PRS2Entry.cs new file mode 100644 index 0000000..21e6b12 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/PRS2Entry.cs @@ -0,0 +1,111 @@ +using System; +using System.IO; +using Warcraft.NET.Extensions; + +namespace Warcraft.NET.Files.Phys.Entries +{ + public class PRS2Entry + { + /// + /// The Transformation Matrix for Bone A of this Joint + /// + public Matrix3x4 FrameA; + /// + /// The Transformation Matrix for Bone B of this Joint + /// + public Matrix3x4 FrameB; + /// + /// The lower limit + /// + public float LowerLimit; + /// + /// The upper limit + /// + public float UpperLimit; + /// + /// Unknown value + /// + public float Unk0; //prev unk_68 + /// + /// Max motor force if enabled + /// + public float MaxMotorForce; + /// + /// unknown value + /// + public float Unk1; //prev unk_70 + /// + /// The MotorMode + /// 0 = disabled? + /// 1 = motorPositionMode (MotorFrequencyHz>0) + /// 2 = motorVelocityMode + /// + public uint MotorMode; + /// + /// how often per second the motor damps + /// + public float MotorFrequencyHz; + /// + /// the ratio how much the motor damps + /// + public float MotorDampingRatio; + + /// + /// Initializes a new instance of the class. + /// + public PRS2Entry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public PRS2Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + FrameA = br.ReadMatrix3x4(); + FrameB = br.ReadMatrix3x4(); + LowerLimit = br.ReadSingle(); + UpperLimit = br.ReadSingle(); + Unk0 = br.ReadSingle(); + MaxMotorForce = br.ReadSingle(); + Unk1 = br.ReadSingle(); + MotorMode = br.ReadUInt32(); + MotorFrequencyHz = br.ReadSingle(); + MotorDampingRatio = br.ReadSingle(); + } + } + + /// + /// Gets the size of a PRS2 entry. + /// + /// The size. + public static int GetSize() + { + return 128; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.WriteMatrix3x4(FrameA); + bw.WriteMatrix3x4(FrameB); + bw.Write(LowerLimit); + bw.Write(UpperLimit); + bw.Write(Unk0); + bw.Write(MaxMotorForce); + bw.Write(Unk1); + bw.Write(MotorMode); + bw.Write(MotorFrequencyHz); + bw.Write(MotorDampingRatio); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/REV2Entry.cs b/Warcraft.NET/Files/phys/Entries/REV2Entry.cs new file mode 100644 index 0000000..a142d3d --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/REV2Entry.cs @@ -0,0 +1,103 @@ +using System; +using System.IO; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.Phys.Entries +{ + public class REV2Entry + { + /// + /// The Transformation Matrix for Bone A of this Joint + /// + public Matrix3x4 FrameA; + + /// + /// The Transformation Matrix for Bone B of this Joint + /// + public Matrix3x4 FrameB; + + /// + /// The lower swing angle + /// + public float LowerAngle; + /// + /// The upper swing angle + /// + public float UpperAngle; + + /// + /// The max motor torque + /// + public float MaxMotorTorque; + /// + /// The MotorMode + /// 0 = disabled? + /// 1 = motorPositionMode (MotorFrequencyHz>0) + /// 2 = motorVelocityMode + /// + public uint MotorMode; // 1: motorPositionMode → frequency > 0, 2: motorVelocityMode + /// + /// how often per second the motor damps + /// + public float MotorFrequencyHz; + /// + /// the ratio how much the motor damps + /// + public float MotorDampingRatio; + + /// + /// Initializes a new instance of the class. + /// + public REV2Entry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public REV2Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + FrameA = br.ReadMatrix3x4(); + FrameB = br.ReadMatrix3x4(); + LowerAngle = br.ReadSingle(); + UpperAngle = br.ReadSingle(); + MaxMotorTorque = br.ReadSingle(); + MotorMode = br.ReadUInt32(); + MotorFrequencyHz = br.ReadSingle(); + MotorDampingRatio = br.ReadSingle(); + } + } + + /// + /// Gets the size of a REV2 entry. + /// + /// The size. + public static int GetSize() + { + return 120; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.WriteMatrix3x4(FrameA); + bw.WriteMatrix3x4(FrameB); + bw.Write(LowerAngle); + bw.Write(UpperAngle); + bw.Write(MaxMotorTorque); + bw.Write(MotorMode); + bw.Write(MotorFrequencyHz); + bw.Write(MotorDampingRatio); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs b/Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs new file mode 100644 index 0000000..6e6446d --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs @@ -0,0 +1,114 @@ +using System; +using System.IO; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.Phys.Entries +{ + public class SHJ2Entry + { + /// + /// The Transformation Matrix for Bone A of this Joint + /// + public Matrix3x4 FrameA; + + /// + /// The Transformation Matrix for Bone B of this Joint + /// + public Matrix3x4 FrameB; + + /// + /// The lower twist angle of the angular constraint + /// + public float LowerTwistAngle; + + /// + /// The upper twist angle of the angular constraint + /// + public float UpperTwistAngle; + + /// + /// The cone angle of the angular constraint + /// + public float ConeAngle; + + /// + /// The max motor torque + /// + public float MaxMotorTorque; + + /// + /// The MotorMode + /// 0 = disabled? + /// 1 = motorPositionMode (MotorFrequencyHz>0) + /// 2 = motorVelocityMode + /// + public uint MotorMode; // 1: motorPositionMode → frequency > 0, 2: motorVelocityMode + + /// + /// how often per second the motor damps + /// + public float MotorFrequencyHz; + + /// + /// the ratio how much the motor damps + /// + public float MotorDampingRatio; + + /// + /// Initializes a new instance of the class. + /// + public SHJ2Entry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public SHJ2Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + FrameA = br.ReadMatrix3x4(); + FrameB = br.ReadMatrix3x4(); + LowerTwistAngle = br.ReadSingle(); + UpperTwistAngle = br.ReadSingle(); + ConeAngle = br.ReadSingle(); + MaxMotorTorque = br.ReadSingle(); + MotorMode = br.ReadUInt32(); + MotorFrequencyHz = br.ReadSingle(); + MotorDampingRatio = br.ReadSingle(); + } + } + + /// + /// Gets the size of a SHJ2 entry. + /// + /// The size. + public static int GetSize() + { + return 124; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.WriteMatrix3x4(FrameA); + bw.WriteMatrix3x4(FrameB); + bw.Write(LowerTwistAngle); + bw.Write(UpperTwistAngle); + bw.Write(ConeAngle); + bw.Write(MaxMotorTorque); + bw.Write(MotorMode); + bw.Write(MotorFrequencyHz); + bw.Write(MotorDampingRatio); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/SHOJEntry.cs b/Warcraft.NET/Files/phys/Entries/SHOJEntry.cs new file mode 100644 index 0000000..38f0626 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/SHOJEntry.cs @@ -0,0 +1,100 @@ +using System; +using System.IO; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.Phys.Entries +{ + public class SHOJEntry + { + /// + /// The Transformation Matrix for Bone A of this Joint + /// + public Matrix3x4 FrameA; + + /// + /// The Transformation Matrix for Bone B of this Joint + /// + public Matrix3x4 FrameB; + + /// + /// The lower twist angle for the angular constraint + /// + public float LowerTwistAngle; + + /// + /// The upper twist angle for the angular constraint + /// + public float UpperTwistAngle; + + /// + /// The cone angle for the angular constraint + /// + public float ConeAngle; + + /// + /// The Maximum torque the motor can apply + /// + public float MaxMotorTorque; + + /// + /// The MotorMode + /// 0 = disabled? + /// 1 = motorPositionMode (MotorFrequencyHz>0) + /// 2 = motorVelocityMode + /// + public uint MotorMode; // NO BACKWARDS COMPATIBILITY as of Legion (7.0.1.20979) and Legion (7.3.0.24931)! client always assumes new size! + + /// + /// Initializes a new instance of the class. + /// + public SHOJEntry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public SHOJEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + FrameA = br.ReadMatrix3x4(); + FrameB = br.ReadMatrix3x4(); + LowerTwistAngle = br.ReadSingle(); + UpperTwistAngle = br.ReadSingle(); + ConeAngle = br.ReadSingle(); + MaxMotorTorque = br.ReadSingle(); + MotorMode = br.ReadUInt32(); + } + } + + /// + /// Gets the size of a SHOJ entry. + /// + /// The size. + public static int GetSize() + { + return 116; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.WriteMatrix3x4(FrameA); + bw.WriteMatrix3x4(FrameB); + bw.Write(LowerTwistAngle); + bw.Write(UpperTwistAngle); + bw.Write(ConeAngle); + bw.Write(MaxMotorTorque); + bw.Write(MotorMode); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/SHP2Entry.cs b/Warcraft.NET/Files/phys/Entries/SHP2Entry.cs new file mode 100644 index 0000000..e179c04 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/SHP2Entry.cs @@ -0,0 +1,120 @@ +using System.IO; +using Warcraft.NET.Files.Phys.Enums; + +namespace Warcraft.NET.Files.Phys.Entries +{ + public class SHP2Entry + { + /// + /// The Shape Type + /// 0 = Box + /// 1 = Capsule + /// 2 = Sphere + /// 3 = Polytope + /// + public ShapeType ShapeType; + + /// + /// The index into the corresponding chunk based on ShapeType + /// + public ushort ShapeIndex; + + /// + /// unknown field + /// + public byte[] Unk0; + + /// + /// the friction of the shape + /// + public float Friction; + + /// + /// the restitution of the shape + /// + public float Restitution; + + /// + /// the density of the shape + /// + public float Density; + + /// + /// unknown field + /// + public uint Unk1 = 0; + + /// + /// unknown field + /// + public float Unk2 = 1f; + + /// + /// unknown field + /// + public ushort Unk3 = 0; + + /// + /// unknown field + /// + public ushort Unk4; //no default, padding? + + /// + /// Initializes a new instance of the class. + /// + public SHP2Entry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public SHP2Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + ShapeType = (ShapeType)br.ReadUInt16(); + ShapeIndex = br.ReadUInt16(); + Unk0 = br.ReadBytes(4); + Friction = br.ReadSingle(); + Restitution = br.ReadSingle(); + Density = br.ReadSingle(); + Unk1 = br.ReadUInt32(); + Unk2 = br.ReadSingle(); + Unk3 = br.ReadUInt16(); + Unk4 = br.ReadUInt16(); + } + } + + /// + /// Gets the size of a SHP2 entry. + /// + /// The size. + public static int GetSize() + { + return 32; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write((ushort)ShapeType); + bw.Write(ShapeIndex); + bw.Write(Unk0); + bw.Write(Friction); + bw.Write(Restitution); + bw.Write(Density); + bw.Write(Unk1); + bw.Write(Unk2); + bw.Write(Unk3); + bw.Write(Unk4); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/SPHJEntry.cs b/Warcraft.NET/Files/phys/Entries/SPHJEntry.cs new file mode 100644 index 0000000..100f179 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/SPHJEntry.cs @@ -0,0 +1,70 @@ +using System; +using System.IO; +using System.Numerics; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.Phys.Entries +{ + public class SPHJEntry + { + /// + /// the local anchor of the Bone A of the joint + /// + public Vector3 AnchorA; + + /// + /// the local anchor of the Bone B of the joint + /// + public Vector3 AnchorB; + + /// + /// the friction torque + /// + public float FrictionTorque; + + /// + /// Initializes a new instance of the class. + /// + public SPHJEntry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public SPHJEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + AnchorA = br.ReadVector3(AxisConfiguration.ZUp); + AnchorB = br.ReadVector3(AxisConfiguration.ZUp); + FrictionTorque = br.ReadSingle(); + } + } + + /// + /// Gets the size of a SPHJ entry. + /// + /// The size. + public static int GetSize() + { + return 28; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.WriteVector3(AnchorA); + bw.WriteVector3(AnchorB); + bw.Write(FrictionTorque); + } + return ms.ToArray(); + } + } + } +} diff --git a/Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs b/Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs new file mode 100644 index 0000000..dddbe48 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs @@ -0,0 +1,97 @@ +using System; +using System.IO; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Structures; + +namespace Warcraft.NET.Files.Phys.Entries +{ + public class WLJ3Entry + { + /// + /// The Transformation Matrix for Bone A of this Joint + /// + public Matrix3x4 FrameA; + + /// + /// The Transformation Matrix for Bone B of this Joint + /// + public Matrix3x4 FrameB; + + /// + /// how often the angular dampening is applied per second + /// + public float AngularFrequencyHz; + + /// + /// the ratio how strong the angular dampening is applied + /// + public float AngularDampingRatio; + + /// + /// how often the linear dampening is applied per second + /// + public float LinearFrequencyHz; // default 0 + + /// + /// the ratio how linear the angular dampening is applied + /// + public float LinearDampingRatio; // default 0 + + /// + /// unknown field + /// + public float Unk0; + + /// + /// Initializes a new instance of the class. + /// + public WLJ3Entry() { } + + /// + /// Initializes a new instance of the class. + /// + /// ExtendedData. + public WLJ3Entry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + FrameA = br.ReadMatrix3x4(); + FrameB = br.ReadMatrix3x4(); + AngularFrequencyHz = br.ReadSingle(); + AngularDampingRatio = br.ReadSingle(); + LinearFrequencyHz = br.ReadSingle(); + LinearDampingRatio = br.ReadSingle(); + Unk0 = br.ReadSingle(); + } + } + + /// + /// Gets the size of a WLJ3 entry. + /// + /// The size. + public static int GetSize() + { + return 116; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + bw.WriteMatrix3x4(FrameA); + bw.WriteMatrix3x4(FrameB); + bw.Write(AngularFrequencyHz); + bw.Write(AngularDampingRatio); + bw.Write(LinearFrequencyHz); + bw.Write(LinearDampingRatio); + bw.Write(Unk0); + return ms.ToArray(); + } + + } + + } +} diff --git a/Warcraft.NET/Files/phys/Physics.cs b/Warcraft.NET/Files/phys/Physics.cs new file mode 100644 index 0000000..090069c --- /dev/null +++ b/Warcraft.NET/Files/phys/Physics.cs @@ -0,0 +1,77 @@ +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Phys.Chunks; + +namespace Warcraft.NET.Files.Phys +{ + [AutoDocFile("phys")] + public class Physics : ChunkedFile + { + [ChunkOrder(1)] + public PHYS Version{get; set;} + + [ChunkOptional] + public PHYT Phyt{get; set; } //unknown what it stands for + + [ChunkOptional] + public BOXS BoxShapes{get;set;} + + [ChunkOptional] + public SPHS SphereShapes{get;set;} + + [ChunkOptional] + public CAPS CapsuleShapes{get;set;} + + [ChunkOptional] + public PLYT PolytopeShapes{get; set;} + + [ChunkOptional] + public SHP2 Shapes2{get; set;} //SHAP nyi + + [ChunkOptional] + public BDY4 Rigidbodies4{get; set;} //BODY,BDY2,BDY3 NYI + + [ChunkOptional] + public SHOJ ShoulderJoints { get; set; } + + [ChunkOptional] + public SHJ2 ShoulderJoints2{get; set;} + + [ChunkOptional] + public WLJ3 WeldJoints3{get; set;} //WELJ,WLJ2 nyi + + [ChunkOptional] + public SPHJ SphericalJoints{get; set;} + + [ChunkOptional] + public PRS2 PrismaticJoints2{get; set;} //PRSJ nyi + + [ChunkOptional] + public REV2 RevoluteJoints2{get; set;} //REVJ nyi + + [ChunkOptional] + public DSTJ DistanceJoints{get; set;} + + [ChunkOptional] + public JOIN Joints{get; set;} + + [ChunkOptional] + public PHYV Phyv { get; set; } //unknown what it stands for + + /// + /// Initializes a new instance of the class. + /// + public Physics() + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// The binary data. + public Physics(byte[] inData) : base(inData) + { + + } + } +} \ No newline at end of file From ddea8129e854fb1866b4f566b9095d24e807fd3d Mon Sep 17 00:00:00 2001 From: gulasch7742 Date: Sat, 17 Aug 2024 14:12:52 +0200 Subject: [PATCH 05/15] fixed more --- Warcraft.NET.Docs/ChunkAvailability.cs | 1 - Warcraft.NET/Extensions/ExtendedIO.cs | 27 +++ Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs | 7 +- Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs | 2 +- Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs | 2 +- Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs | 69 ++++++++ Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs | 4 +- Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs | 6 +- Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs | 5 +- Warcraft.NET/Files/M2/Chunks/Legion/PFID.cs | 2 +- Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs | 2 +- Warcraft.NET/Files/M2/Chunks/Legion/SFID.cs | 2 +- Warcraft.NET/Files/M2/Chunks/Legion/SKID.cs | 2 +- Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs | 2 +- Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs | 17 +- Warcraft.NET/Files/M2/Entries/AFIDEntry.cs | 4 +- Warcraft.NET/Files/M2/Entries/DBOCEntry.cs | 2 +- Warcraft.NET/Files/M2/Entries/DETLEntry.cs | 2 +- Warcraft.NET/Files/M2/Entries/EXPTEntry.cs | 1 - Warcraft.NET/Files/M2/Entries/WFV3Entry.cs | 3 +- Warcraft.NET/Files/M2/Model.cs | 154 +++++++++--------- Warcraft.NET/Files/Phys/Enums/BodyType.cs | 6 +- Warcraft.NET/Files/Phys/Enums/JointType.cs | 6 +- Warcraft.NET/Files/Phys/Enums/ShapeType.cs | 6 +- .../Files/Phys/Structures/PlytHeader.cs | 30 ++-- .../Files/Phys/Structures/PlytNode.cs | 5 +- Warcraft.NET/Files/SKIN/Skin.cs | 41 ++++- Warcraft.NET/Files/Structures/M2Batch.cs | 84 ++++++++-- .../Files/Structures/M2ShadowBatch.cs | 43 +++-- .../Files/Structures/M2SkinBoneStruct.cs | 21 ++- .../Files/Structures/M2SkinSection.cs | 81 +++++++-- Warcraft.NET/Files/Structures/M2Triangle.cs | 26 ++- Warcraft.NET/Files/Structures/Matrix3x4.cs | 22 ++- Warcraft.NET/Files/phys/Chunks/BDY4.cs | 1 - Warcraft.NET/Files/phys/Chunks/DSTJ.cs | 2 - Warcraft.NET/Files/phys/Chunks/JOIN.cs | 2 - Warcraft.NET/Files/phys/Chunks/PHYT.cs | 3 +- Warcraft.NET/Files/phys/Chunks/PHYV.cs | 4 +- Warcraft.NET/Files/phys/Chunks/PLYT.cs | 4 - Warcraft.NET/Files/phys/Chunks/PRS2.cs | 2 - Warcraft.NET/Files/phys/Chunks/REV2.cs | 2 - Warcraft.NET/Files/phys/Chunks/SHJ2.cs | 2 - Warcraft.NET/Files/phys/Chunks/SHOJ.cs | 2 - Warcraft.NET/Files/phys/Entries/BDY4Entry.cs | 13 +- Warcraft.NET/Files/phys/Entries/CAPSEntry.cs | 1 - Warcraft.NET/Files/phys/Entries/DSTJEntry.cs | 3 +- Warcraft.NET/Files/phys/Entries/JOINEntry.cs | 2 - Warcraft.NET/Files/phys/Entries/PLYTEntry.cs | 1 - Warcraft.NET/Files/phys/Entries/PRS2Entry.cs | 16 +- Warcraft.NET/Files/phys/Entries/REV2Entry.cs | 4 +- Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs | 6 +- Warcraft.NET/Files/phys/Entries/SHOJEntry.cs | 6 +- Warcraft.NET/Files/phys/Entries/SPHJEntry.cs | 3 +- Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs | 4 - Warcraft.NET/Files/phys/Physics.cs | 60 ++++++- 55 files changed, 568 insertions(+), 262 deletions(-) create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs diff --git a/Warcraft.NET.Docs/ChunkAvailability.cs b/Warcraft.NET.Docs/ChunkAvailability.cs index f3d2d31..024a03f 100644 --- a/Warcraft.NET.Docs/ChunkAvailability.cs +++ b/Warcraft.NET.Docs/ChunkAvailability.cs @@ -107,7 +107,6 @@ internal static class ChunkAvailability "M2", new() { "MD21", - "PFID", "SFID", "AFID", "BFID", diff --git a/Warcraft.NET/Extensions/ExtendedIO.cs b/Warcraft.NET/Extensions/ExtendedIO.cs index c78cc2a..4d96681 100644 --- a/Warcraft.NET/Extensions/ExtendedIO.cs +++ b/Warcraft.NET/Extensions/ExtendedIO.cs @@ -7,6 +7,7 @@ using System.Numerics; using Warcraft.NET.Exceptions; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace Warcraft.NET.Extensions { @@ -426,6 +427,32 @@ public static void WriteChunkSignature(this BinaryWriter binaryWriter, string si } } + /// + /// Writes a struct to the BinaryWriter. + /// + /// The type of struct to write. + /// The BinaryWriter instance. + /// The struct value to write. + public static void WriteStruct(this BinaryWriter binaryWriter, T value) where T : struct + { + int size = Marshal.SizeOf(); + byte[] bytes = new byte[size]; + + IntPtr ptr = Marshal.AllocHGlobal(size); + try + { + Marshal.StructureToPtr(value, ptr, true); + Marshal.Copy(ptr, bytes, 0, size); + } + finally + { + Marshal.FreeHGlobal(ptr); + } + + // Write the padded bytes + binaryWriter.Write(bytes); + } + /// /// Writes a 12-byte value to the data stream in Pitch/Yaw/Roll order. /// diff --git a/Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs b/Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs index a8d7263..3225f66 100644 --- a/Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs +++ b/Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs @@ -1,12 +1,7 @@ -using System.Collections.Generic; -using System.IO; -using Warcraft.NET.Attribute; -using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.M2.Entries; +using Warcraft.NET.Files.Interfaces; namespace Warcraft.NET.Files.M2.Chunks.DF { - [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterSL, AutoDocChunkVersionHelper.VersionBeforeDF)] public class AFRA : IIFFChunk, IBinarySerializable { /// diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs b/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs index 91d0185..aa58e66 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs @@ -66,4 +66,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs b/Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs index 26b13ca..5182dbd 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs @@ -61,4 +61,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs b/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs new file mode 100644 index 0000000..8e9956e --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] + public class EXPT : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "EXP2"; + + /// + /// Gets or sets the Skin FileDataId + /// + public List EXP2Entries = new(); + + /// + /// Initializes a new instance of + /// + public EXPT() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public EXPT(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + var exp2count = br.BaseStream.Length / EXPTEntry.GetSize(); + for (var i = 0; i < exp2count; ++i) + { + EXP2Entries.Add(new EXPTEntry(br.ReadBytes(EXPTEntry.GetSize()))); + } + } + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + foreach (EXPTEntry obj in EXP2Entries) + { + bw.Write(obj.Serialize()); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs index 7a4ab29..d010543 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs @@ -1,9 +1,7 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.M2.Entries; namespace Warcraft.NET.Files.M2.Chunks.Legion { diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs index b1f4ba3..ec885fb 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs @@ -1,9 +1,7 @@ -using Warcraft.NET.Attribute; -using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Interfaces; namespace Warcraft.NET.Files.M2.Chunks.Legion { - [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] public class PADC : IIFFChunk, IBinarySerializable { /// @@ -45,4 +43,4 @@ public byte[] Serialize(long offset = 0) return Data; } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs index e5409cb..3881430 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs @@ -1,5 +1,4 @@ -using System.IO; -using Warcraft.NET.Attribute; +using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; namespace Warcraft.NET.Files.M2.Chunks.Legion @@ -46,4 +45,4 @@ public byte[] Serialize(long offset = 0) return Data; } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PFID.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PFID.cs index f92f272..729142a 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/PFID.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PFID.cs @@ -61,4 +61,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs index fa2542b..570981b 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs @@ -48,4 +48,4 @@ public byte[] Serialize(long offset = 0) return Data; } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/SFID.cs b/Warcraft.NET/Files/M2/Chunks/Legion/SFID.cs index bf6b4c3..90ff088 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/SFID.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/SFID.cs @@ -61,4 +61,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/SKID.cs b/Warcraft.NET/Files/M2/Chunks/Legion/SKID.cs index abcda1d..ad43e1d 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/SKID.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/SKID.cs @@ -56,4 +56,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs index 86fb8da..3ffe3d4 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs @@ -68,4 +68,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs b/Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs index c9a8057..5c8bb6b 100644 --- a/Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs +++ b/Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs @@ -1,3 +1,4 @@ +using System; using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; using Warcraft.NET.Files.Phys; @@ -43,7 +44,21 @@ public void LoadBinaryData(byte[] inData) /// public byte[] Serialize(long offset = 0) { - return Physics.Serialize(); + return PadTo8Bytes(Physics.Serialize()); + } + + static byte[] PadTo8Bytes(byte[] input) + { + int paddingNeeded = 8 - (input.Length % 8); + if (paddingNeeded == 8) + paddingNeeded = 0; + byte[] paddedArray = new byte[input.Length + paddingNeeded]; + Array.Copy(input, paddedArray, input.Length); + for (int i = input.Length; i < paddedArray.Length; i++) + { + paddedArray[i] = 0x00; + } + return paddedArray; } } } \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/AFIDEntry.cs b/Warcraft.NET/Files/M2/Entries/AFIDEntry.cs index 45bb227..6c85f43 100644 --- a/Warcraft.NET/Files/M2/Entries/AFIDEntry.cs +++ b/Warcraft.NET/Files/M2/Entries/AFIDEntry.cs @@ -9,7 +9,6 @@ public class AFIDEntry /// public ushort AnimationId { get; set; } - /// /// Gets or sets the sub animation id. /// @@ -20,7 +19,6 @@ public class AFIDEntry /// public uint FileDataId { get; set; } - /// /// Initializes a new instance of the class. /// @@ -68,4 +66,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/DBOCEntry.cs b/Warcraft.NET/Files/M2/Entries/DBOCEntry.cs index 33c09f0..58a8bf5 100644 --- a/Warcraft.NET/Files/M2/Entries/DBOCEntry.cs +++ b/Warcraft.NET/Files/M2/Entries/DBOCEntry.cs @@ -67,4 +67,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/DETLEntry.cs b/Warcraft.NET/Files/M2/Entries/DETLEntry.cs index 4b38503..da70cdc 100644 --- a/Warcraft.NET/Files/M2/Entries/DETLEntry.cs +++ b/Warcraft.NET/Files/M2/Entries/DETLEntry.cs @@ -79,4 +79,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/EXPTEntry.cs b/Warcraft.NET/Files/M2/Entries/EXPTEntry.cs index 5dab686..ece3be3 100644 --- a/Warcraft.NET/Files/M2/Entries/EXPTEntry.cs +++ b/Warcraft.NET/Files/M2/Entries/EXPTEntry.cs @@ -4,7 +4,6 @@ namespace Warcraft.NET.Files.M2.Entries { public class EXPTEntry { - /// /// replaces zSource from ParticleEmitter /// diff --git a/Warcraft.NET/Files/M2/Entries/WFV3Entry.cs b/Warcraft.NET/Files/M2/Entries/WFV3Entry.cs index 963bd66..12d0463 100644 --- a/Warcraft.NET/Files/M2/Entries/WFV3Entry.cs +++ b/Warcraft.NET/Files/M2/Entries/WFV3Entry.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; +using System.IO; using Warcraft.NET.Extensions; using Warcraft.NET.Files.Structures; diff --git a/Warcraft.NET/Files/M2/Model.cs b/Warcraft.NET/Files/M2/Model.cs index 29b3c6c..54330ea 100644 --- a/Warcraft.NET/Files/M2/Model.cs +++ b/Warcraft.NET/Files/M2/Model.cs @@ -1,7 +1,9 @@ using Warcraft.NET.Attribute; using Warcraft.NET.Files.M2.Chunks; using Warcraft.NET.Files.M2.Chunks.BfA; +using Warcraft.NET.Files.M2.Chunks.DF; using Warcraft.NET.Files.M2.Chunks.Legion; +using Warcraft.NET.Files.M2.Chunks.SL; namespace Warcraft.NET.Files.M2 { @@ -15,170 +17,162 @@ public class Model : ChunkedFile public MD21 ModelInformation { get; set; } /// - /// Gets or sets the model phys file ids + /// Gets or sets the CParticleEmitter2 data /// - [ChunkOrder(2), ChunkOptional] - public PFID PhysFileIds { get; set; } + [ChunkOrder(2),ChunkOptional] + public TXAC CParticleEmitter2 { get; set; } /// - /// Gets or sets the model skin file ids + /// Gets or sets the ParentEventData /// - [ChunkOrder(3), ChunkOptional] - public SFID SkinFileIds { get; set; } + [ChunkOrder(3),ChunkOptional] + public PEDC M2InitParentEventData { get; set; } /// - /// Gets or sets the model anim file ids + /// Gets or sets the ExtendedParticle /// [ChunkOrder(4), ChunkOptional] - public AFID AnimFileIds { get; set; } + public EXPT ExtendedParticle { get; set; } /// - /// Gets or sets the model bone file ids + /// Gets or sets the ExtendedParticle2 /// - [ChunkOrder(5), ChunkOptional] - public BFID BoneFileIds { get; set; } + [ChunkOrder(5),ChunkOptional] + public EXP2 ExtendedParticle2 { get; set; } -<<<<<<< Updated upstream -======= /// - /// Gets or sets the TXAC + /// Gets or sets the ParticleGeosetData /// - [ChunkOptional] - public TXAC CParticleEmitter2 { get; set; } + [ChunkOrder(6),ChunkOptional] + public PGD1 ParticleGeosetData { get; set; } /// - /// Gets or sets the particle extension + /// Gets or sets the model anim file ids /// - [ChunkOptional] - public EXPT ExtendedParticle { get; set; } + [ChunkOrder(7), ChunkOptional] + public AFID AnimFileIds { get; set; } + + /// + /// Gets or sets the model bone file ids + /// + [ChunkOrder(8), ChunkOptional] + public BFID BoneFileIds { get; set; } /// /// Gets or sets the BlacklistAnimData /// - [ChunkOptional] + [ChunkOrder(9), ChunkOptional] public PABC M2InitBlacklistAnimData { get; set; } /// - /// Gets or sets the ParentAnimData + /// Gets or sets the LodDataVersion1 /// - [ChunkOptional] - public PADC M2InitParentAnimData { get; set; } + [ChunkOrder(10), ChunkOptional] + public LDV1 LodDataVersion1 { get; set; } /// - /// Gets or sets the ParentSequenceBoundsData + /// Gets or sets the EdgeFade /// - [ChunkOptional] - public PSBC M2InitParentSequenceBoundsData { get; set; } + [ChunkOrder(11), ChunkOptional] + public EDGF EdgeFade { get; set; } /// - /// Gets or sets the ParentEventData + /// Gets or sets the Physics of the M2 /// - [ChunkOptional] - public PEDC M2InitParentEventData { get; set; } + [ChunkOrder(12),ChunkOptional] + public PFDC ModelPhysics { get; set; } /// /// Gets or sets the model skeleton file ids /// - [ChunkOptional] + [ChunkOrder(13), ChunkOptional] public SKID SkeletonFileIds { get; set; } /// - /// Gets or sets the texture file ids + /// Gets or sets the WaterFallVersion1 /// - [ChunkOptional] - public TXID TextureFileIds { get; set; } + [ChunkOrder(14),ChunkOptional] + public WFV1 WaterFallVersion1 { get; set; } /// - /// Gets or sets the LodDataVersion1 + /// Gets or sets the WaterFallVersion2 /// - [ChunkOptional] - public LDV1 LodDataVersion1 { get; set; } + [ChunkOrder(15),ChunkOptional] + public WFV2 WaterFallVersion2 { get; set; } ->>>>>>> Stashed changes /// - /// Gets or sets the model recursive particle file ids + /// Gets or sets the WaterFallVersion3 /// - [ChunkOrder(6), ChunkOptional] - public RPID RecursiveParticleFileIds { get; set; } + [ChunkOrder(16),ChunkOptional] + public WFV3 WaterFallVersion3 { get; set; } /// - /// Gets or sets the model geometry particle file ids + /// Gets or sets the DBOC /// - [ChunkOrder(7), ChunkOptional] - public GPID GeometryParticleFileIds { get; set; } + [ChunkOrder(17), ChunkOptional] + public DBOC DBOC { get; set; } /// -<<<<<<< Updated upstream - /// Gets or sets the model skeleton file ids + /// Gets or sets the model skin file ids /// - [ChunkOrder(8), ChunkOptional] - public SKID SkeletonFileIds { get; set; } + [ChunkOrder(18), ChunkOptional] + public SFID SkinFileIds { get; set; } /// - /// Gets or sets the model texture file ids - /// - [ChunkOrder(9), ChunkOptional] - public TXID TextureFileIds { get; set; } -======= - /// Gets or sets the WaterFallVersion1 + /// Gets or sets the model phys file ids /// - [ChunkOptional] - public WFV1 WaterFallVersion1 { get; set; } + [ChunkOrder(19), ChunkOptional] + public PFID PhysFileIds { get; set; } /// - /// Gets or sets the WaterFallVersion2 + /// Gets or sets the model texture file ids /// - [ChunkOptional] - public WFV2 WaterFallVersion2 { get; set; } + [ChunkOrder(20), ChunkOptional] + public TXID TextureFileIds { get; set; } /// - /// Gets or sets the ParticleGeosetData + /// Gets or sets the ParentSequenceBoundsData /// - [ChunkOptional] - public PGD1 ParticleGeosetData { get; set; } + [ChunkOrder(21),ChunkOptional] + public PSBC M2InitParentSequenceBoundsData { get; set; } + + /// - /// Gets or sets the WaterFallVersion3 + /// Gets or sets the model recursive particle file ids /// - [ChunkOptional] - public WFV3 WaterFallVersion3 { get; set; } + [ChunkOrder(), ChunkOptional] + public RPID RecursiveParticleFileIds { get; set; } /// - /// Gets or sets the Physics of the M2 + /// Gets or sets the model geometry particle file ids /// - [ChunkOptional] - public PFDC ModelPhysics { get; set; } + [ChunkOrder(), ChunkOptional] + public GPID GeometryParticleFileIds { get; set; } /// - /// Gets or sets the EdgeFade + /// Gets or sets the ParentAnimData /// - [ChunkOptional] - public EDGF EdgeFade { get; set; } + [ChunkOrder(),ChunkOptional] + public PADC M2InitParentAnimData { get; set; } /// /// Gets or sets the NERF /// - [ChunkOptional] + [ChunkOrder(),ChunkOptional] public NERF NERF { get; set; } /// /// Gets or sets the DETL (light related) /// - [ChunkOptional] + [ChunkOrder(),ChunkOptional] public DETL DETL { get; set; } - /// - /// Gets or sets the DBOC - /// - [ChunkOptional] - public DBOC DBOC { get; set; } - /// /// Gets or sets the AFRA /// - [ChunkOptional] + [ChunkOrder(),ChunkOptional] public AFRA AFRA { get; set; } ->>>>>>> Stashed changes /// /// Initializes a new instance of the class. diff --git a/Warcraft.NET/Files/Phys/Enums/BodyType.cs b/Warcraft.NET/Files/Phys/Enums/BodyType.cs index 99a1779..5908459 100644 --- a/Warcraft.NET/Files/Phys/Enums/BodyType.cs +++ b/Warcraft.NET/Files/Phys/Enums/BodyType.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Warcraft.NET.Files.Phys.Enums +namespace Warcraft.NET.Files.Phys.Enums { public enum BodyType : ushort { diff --git a/Warcraft.NET/Files/Phys/Enums/JointType.cs b/Warcraft.NET/Files/Phys/Enums/JointType.cs index 28f6014..e7f605d 100644 --- a/Warcraft.NET/Files/Phys/Enums/JointType.cs +++ b/Warcraft.NET/Files/Phys/Enums/JointType.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Warcraft.NET.Files.Phys.Enums +namespace Warcraft.NET.Files.Phys.Enums { public enum JointType : ushort { diff --git a/Warcraft.NET/Files/Phys/Enums/ShapeType.cs b/Warcraft.NET/Files/Phys/Enums/ShapeType.cs index 108fc39..290f93f 100644 --- a/Warcraft.NET/Files/Phys/Enums/ShapeType.cs +++ b/Warcraft.NET/Files/Phys/Enums/ShapeType.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Warcraft.NET.Files.Phys.Enums +namespace Warcraft.NET.Files.Phys.Enums { public enum ShapeType : short { diff --git a/Warcraft.NET/Files/Phys/Structures/PlytHeader.cs b/Warcraft.NET/Files/Phys/Structures/PlytHeader.cs index 6da1481..c6b871a 100644 --- a/Warcraft.NET/Files/Phys/Structures/PlytHeader.cs +++ b/Warcraft.NET/Files/Phys/Structures/PlytHeader.cs @@ -7,46 +7,56 @@ public struct PlytHeader /// /// gets or sets the amount of vertices for this polytope /// - public uint VertexCount; // Mostly 8 + public uint VertexCount; + /// /// gets or sets unknown data /// - public byte[] Unk0; //prev unk_04 + public byte[] Unk0; + /// /// gets or sets certain runtime data. Unknown purpose /// - public UInt64 RUNTIME08ptrData0; // = &Data[i].unk_0 + public UInt64 RUNTIME08ptrData0; + /// /// gets or sets the count10, which defines how many Unk1[] and Unk2[] there are inside the Data. /// - public uint Count10; // Mostly 6 + public uint Count10; + /// /// gets or sets the Unk1 array. Unknown purpose /// public byte[] Unk1; + /// /// gets or sets certain runtime data. Unknown purpose /// - public UInt64 RUNTIME18ptrData1; // = &Data[i].unk_1 + public UInt64 RUNTIME18ptrData1; + /// /// gets or sets certain runtime data. Unknown purpose /// - public UInt64 RUNTIME20ptrData2; // = &Data[i].unk_2 + public UInt64 RUNTIME20ptrData2; + /// /// gets or sets the amount of nodes. Defines how Vertices are connected /// - public uint NodeCount; // Mostly 24 + public uint NodeCount; + /// /// gets or sets the Unk2 array. Unknown purpose /// public byte[] Unk2; + /// /// gets or sets certain runtime data. Unknown purpose /// - public UInt64 RUNTIME30ptrData3; // = &Data[i].unk_3 + public UInt64 RUNTIME30ptrData3; + /// /// gets or sets the Unk3 array. Unknown purpose /// - public float[] Unk3;// not sure if floats: has e-08 values + public float[] Unk3; } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/Phys/Structures/PlytNode.cs b/Warcraft.NET/Files/Phys/Structures/PlytNode.cs index 92248da..c727e69 100644 --- a/Warcraft.NET/Files/Phys/Structures/PlytNode.cs +++ b/Warcraft.NET/Files/Phys/Structures/PlytNode.cs @@ -10,17 +10,20 @@ public struct PlytNode /// Unknown byte. Always 1 or -1 /// public byte Unk; // 1 or -1 + /// /// Index into the data.Vertices /// public byte VertexIndex; // index in vertex list + /// /// Index into data.Nodes /// public byte UnkIndex0; // index into the nodes + /// /// Index into data.Nodes /// public byte UnkIndex1; // index into the nodes } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/SKIN/Skin.cs b/Warcraft.NET/Files/SKIN/Skin.cs index 9131b41..58d2c95 100644 --- a/Warcraft.NET/Files/SKIN/Skin.cs +++ b/Warcraft.NET/Files/SKIN/Skin.cs @@ -4,22 +4,53 @@ using Warcraft.NET.Extensions; using Warcraft.NET.Files.Structures; -namespace Warcraft.NET.Files.SKIN +namespace Warcraft.NET.Files.Skin { [AutoDocFile("skin")] public class Skin { - public List Vertices { get; set; } //index into M2s vertex list with offset - public List Triangles { get; set; } //3 indices per entry into vertices + /// + /// The list of Vertices used for this skin + /// indexed into M2s vertex list with offset 'GlobalVertexOffset' + /// + public List Vertices { get; set; } + + /// + /// the triangles used for this skin (Right Handed) + /// indexed into the local list of vertices + /// + public List Triangles { get; set; } + + /// + /// the bones used for this skin. + /// indexed into the bone lookup table of the m2 + /// public List BoneIndices { get; set; } + + /// + /// the submeshes used for this skin + /// public List Submeshes { get; set; } + + /// + /// the texture units used for this skin. + /// public List TextureUnits { get; set; } - public uint GlobalVertexOffset; //start offset into M2.Vertices -> something else in wotlk + /// + /// start offset into M2.Vertices -> something else in wotlk + /// + public uint GlobalVertexOffset; + /// + /// the shadowbatches used in this skin + /// public List ShadowBatches; - public byte[] Unk0; //Padding? + /// + /// unknown field. Maybe padding? + /// + public byte[] Unk0; public bool Wotlk = false; diff --git a/Warcraft.NET/Files/Structures/M2Batch.cs b/Warcraft.NET/Files/Structures/M2Batch.cs index 97891b0..37040e8 100644 --- a/Warcraft.NET/Files/Structures/M2Batch.cs +++ b/Warcraft.NET/Files/Structures/M2Batch.cs @@ -1,23 +1,73 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Warcraft.NET.Files.Structures +namespace Warcraft.NET.Files.Structures { public struct M2Batch { - public byte Flags; // Usually 16 for static textures, and 0 for animated textures. &0x1: materials invert something; &0x2: transform &0x4: projected texture; &0x10: something batch compatible; &0x20: projected texture?; &0x40: possibly don't multiply transparency by texture weight transparency to get final transparency value(?) + /// + /// Texture Flags + /// Usually 16 for static textures, and 0 for animated textures. &0x1: materials invert something; &0x2: transform &0x4: projected texture; &0x10: something batch compatible; &0x20: projected texture?; &0x40: possibly don't multiply transparency by texture weight transparency to get final transparency value(?) + /// + public byte Flags; + + /// + /// Priority Plane + /// public sbyte PriorityPlane; - public ushort ShaderId; // See below. - public ushort SkinSectionIndex; // A duplicate entry of a submesh from the list above. - public ushort GeosetIndex; // See below. New name: flags2. 0x2 - projected. 0x8 - EDGF chunk in m2 is mandatory and data from is applied to this mesh - public ushort ColorIndex; // A Color out of the Colors-Block or -1 if none. - public ushort MaterialIndex; // The renderflags used on this texture-unit. - public ushort MaterialLayer; // Capped at 7 (see CM2Scene::BeginDraw) - public ushort TextureCount; // 1 to 4. See below. Also seems to be the number of textures to load, starting at the texture lookup in the next field (0x10). - public ushort TextureComboIndex; // Index into Texture lookup table - public ushort TextureCoordComboIndex; // Index into the texture mapping lookup table. - public ushort TextureWeightComboIndex; // Index into transparency lookup table. - public ushort TextureTransformComboIndex; // Index into uvanimation lookup table. + + /// + /// ShaderID + /// negative = direct selection + /// positive = selection trough a function. See wiki for more information + /// + public ushort ShaderId; + + /// + /// A duplicate entry of a submesh from the list above. + /// + public ushort SkinSectionIndex; + + /// + /// New name: flags2. 0x2 - projected. 0x8 - EDGF chunk in m2 is mandatory and data from is applied to this mesh + /// + public ushort GeosetIndex; + + /// + /// A Color out of the Colors-Block or -1 if none. + /// + public ushort ColorIndex; + + /// + /// The renderflags used on this texture-unit. Index into M2 Materials + /// + public ushort MaterialIndex; + + /// + /// Capped at 7 (CM2Scene::BeginDraw) + /// + public ushort MaterialLayer; + + /// + /// 1 to 4. See below. Also seems to be the number of textures to load, starting at the texture lookup in the next field (0x10). + /// + public ushort TextureCount; + + /// + /// Index into Texture lookup table + /// + public ushort TextureComboIndex; + + /// + /// Index into the texture mapping lookup table. + /// + public ushort TextureCoordComboIndex; + + /// + /// Index into transparency lookup table. + /// + public ushort TextureWeightComboIndex; + + /// + /// Index into uvanimation lookup table. + /// + public ushort TextureTransformComboIndex; } } diff --git a/Warcraft.NET/Files/Structures/M2ShadowBatch.cs b/Warcraft.NET/Files/Structures/M2ShadowBatch.cs index ca6a815..db25b23 100644 --- a/Warcraft.NET/Files/Structures/M2ShadowBatch.cs +++ b/Warcraft.NET/Files/Structures/M2ShadowBatch.cs @@ -1,20 +1,41 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Warcraft.NET.Files.Structures +namespace Warcraft.NET.Files.Structures { public struct M2ShadowBatch - { - public byte Flags; // if auto-generated: M2Batch.Flags & 0xFF - public byte Flags2; // if auto-generated: (renderFlag[i].Flags & 0x04 ? 0x01 : 0x00) - // | (!renderFlag[i].Blendingmode ? 0x02 : 0x00) - // | (renderFlag[i].Flags & 0x80 ? 0x04 : 0x00) - // | (renderFlag[i].Flags & 0x400 ? 0x06 : 0x00) + { + /// + /// if auto-generated: M2Batch.Flags & 0xFF + /// + public byte Flags; + + /// + /// gets auto generated if certain flags in TextureUnit are set + /// See wiki for more information + /// + public byte Flags2; + + /// + /// unknown field + /// public ushort Unk1; + + /// + /// same as TextureUnit + /// public ushort SubmeshId; + + /// + /// same as TextureUnit + /// public ushort TextureId; // already looked-up + + /// + /// same as TextureUnit + /// public ushort ColorId; + + /// + /// same as TextureUnit + /// public ushort TransparencyId; // already looked-up } } diff --git a/Warcraft.NET/Files/Structures/M2SkinBoneStruct.cs b/Warcraft.NET/Files/Structures/M2SkinBoneStruct.cs index 0da3e2b..6f813ee 100644 --- a/Warcraft.NET/Files/Structures/M2SkinBoneStruct.cs +++ b/Warcraft.NET/Files/Structures/M2SkinBoneStruct.cs @@ -1,14 +1,25 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Warcraft.NET.Files.Structures +namespace Warcraft.NET.Files.Structures { public struct M2SkinBoneStruct { + /// + /// Bone 1 Index into BoneLookupTable from M2. see wiki for exact calculation + /// public byte Bone1ID; + + /// + /// Bone 2 Index into BoneLookupTable from M2. see wiki for exact calculation + /// public byte Bone2ID; + + /// + /// Bone 3 Index into BoneLookupTable from M2. see wiki for exact calculation + /// public byte Bone3ID; + + /// + /// Bone 4 Index into BoneLookupTable from M2. see wiki for exact calculation + /// public byte Bone4ID; } } diff --git a/Warcraft.NET/Files/Structures/M2SkinSection.cs b/Warcraft.NET/Files/Structures/M2SkinSection.cs index 5aee7c2..e189026 100644 --- a/Warcraft.NET/Files/Structures/M2SkinSection.cs +++ b/Warcraft.NET/Files/Structures/M2SkinSection.cs @@ -7,22 +7,73 @@ namespace Warcraft.NET.Files.Structures { public struct M2SkinSection { - public ushort SkinSectionId; // Mesh part ID, see below. - public ushort Level; // (level << 16) is added (|ed) to startTriangle and alike to avoid having to increase those fields to uint32s. - public ushort VertexStart; // Starting vertex number. - public ushort VertexCount; // Number of vertices. - public ushort IndexStart; // Starting triangle index (that's 3* the number of triangles drawn so far). - public ushort IndexCount; // Number of triangle indices. - public ushort BoneCount; // Number of elements in the bone lookup table. Max seems to be 256 in Wrath. Shall be ≠ 0. - public ushort BoneComboIndex; // Starting index in the bone lookup table. - public ushort BoneInfluences; // <= 4 - // from <=BC documentation: Highest number of bones needed at one time in this Submesh --Tinyn (wowdev.org) - // In 2.x this is the amount of of bones up the parent-chain affecting the submesh --NaK - // Highest number of bones referenced by a vertex of this submesh. 3.3.5a and suspectedly all other client revisions. -- Skarn + /// + /// Mesh part ID, see wiki for exact calculation + /// + public ushort SkinSectionId; + + /// + /// (level << 16) is added (|ed) to startTriangle and alike to avoid having to increase those fields to uint32s. + /// + public ushort Level; + + /// + /// Starting Vertex. Index into local vertex list + /// + public ushort VertexStart; + + /// + /// Number of Vertices taken from local vertex list + /// + public ushort VertexCount; + + /// + /// Starting triangle index. + /// + public ushort IndexStart; + + /// + /// Number of triangle indices. + /// + public ushort IndexCount; + + /// + /// Number of elements in the bone lookup table. Max seems to be 256 in Wrath. Shall be ≠ 0. + /// + public ushort BoneCount; + + /// + /// Starting index in the bone lookup table. + /// + public ushort BoneComboIndex; + + /// + /// <= 4 + /// from <=BC documentation: Highest number of bones needed at one time in this Submesh --Tinyn (wowdev.org) + /// In 2.x this is the amount of of bones up the parent-chain affecting the submesh --NaK + /// Highest number of bones referenced by a vertex of this submesh. 3.3.5a and suspectedly all other client revisions. -- Skarn + /// + public ushort BoneInfluences; + + /// + /// Index of the center bone + /// public ushort CenterBoneIndex; - public Vector3 CenterPosition; // Average position of all the vertices in the sub mesh. + + /// + /// Average position of all the vertices in the sub mesh. + /// + public Vector3 CenterPosition; + //≥BC - public Vector3 SortCenterPosition; // The center of the box when an axis aligned box is built around the vertices in the submesh. - public float SortRadius; // Distance of the vertex farthest from CenterBoundingBox. + /// + /// The center of the box when an axis aligned box is built around the vertices in the submesh. + /// + public Vector3 SortCenterPosition; + + /// + /// Distance of the vertex farthest from CenterBoundingBox. + /// + public float SortRadius; } } diff --git a/Warcraft.NET/Files/Structures/M2Triangle.cs b/Warcraft.NET/Files/Structures/M2Triangle.cs index 250ad77..639055d 100644 --- a/Warcraft.NET/Files/Structures/M2Triangle.cs +++ b/Warcraft.NET/Files/Structures/M2Triangle.cs @@ -1,13 +1,25 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Warcraft.NET.Files.Structures +namespace Warcraft.NET.Files.Structures { - public struct M2Triangle //132->Left handed; 123->right handed + /// + /// Triangle read from skin. + /// Default = Right Handed + /// To make it left handed, swap the second and third vertex + /// + public struct M2Triangle { + /// + /// the first vertex of the Triangle + /// public ushort Vertex1; - public ushort Vertex3; + + /// + /// the second vertex of the Triangle + /// public ushort Vertex2; + + /// + /// the third vertex of the Triangle + /// + public ushort Vertex3; } } diff --git a/Warcraft.NET/Files/Structures/Matrix3x4.cs b/Warcraft.NET/Files/Structures/Matrix3x4.cs index cbdbdf0..7c6e0d6 100644 --- a/Warcraft.NET/Files/Structures/Matrix3x4.cs +++ b/Warcraft.NET/Files/Structures/Matrix3x4.cs @@ -1,16 +1,32 @@ using System.Collections.Generic; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.Structures; using System.Numerics; -using System.IO; -using Warcraft.NET.Extensions; public class Matrix3x4 : IFlattenableData { + /// + /// The directional vector 'right' + /// public Vector3 RotationX { get; set; } + + /// + /// The directional vector 'up' + /// public Vector3 RotationY { get; set; } + + /// + /// The directional vector 'forward' + /// public Vector3 RotationZ { get; set; } + + /// + /// The scale of the matrix + /// public Vector3 Scale { get; set; } + + /// + /// The position of the matrix + /// public Vector3 Position { get; set; } public Matrix3x4 (Vector3 column1, Vector3 column2, Vector3 column3, Vector3 column4) diff --git a/Warcraft.NET/Files/phys/Chunks/BDY4.cs b/Warcraft.NET/Files/phys/Chunks/BDY4.cs index c3efe6f..7f90e83 100644 --- a/Warcraft.NET/Files/phys/Chunks/BDY4.cs +++ b/Warcraft.NET/Files/phys/Chunks/BDY4.cs @@ -64,6 +64,5 @@ public byte[] Serialize(long offset = 0) return ms.ToArray(); } } - } } diff --git a/Warcraft.NET/Files/phys/Chunks/DSTJ.cs b/Warcraft.NET/Files/phys/Chunks/DSTJ.cs index 55e9cdd..32db762 100644 --- a/Warcraft.NET/Files/phys/Chunks/DSTJ.cs +++ b/Warcraft.NET/Files/phys/Chunks/DSTJ.cs @@ -1,10 +1,8 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; using Warcraft.NET.Files.Phys.Entries; -using Warcraft.NET.Files.Structures; namespace Warcraft.NET.Files.Phys.Chunks { diff --git a/Warcraft.NET/Files/phys/Chunks/JOIN.cs b/Warcraft.NET/Files/phys/Chunks/JOIN.cs index d278dc8..d378ac3 100644 --- a/Warcraft.NET/Files/phys/Chunks/JOIN.cs +++ b/Warcraft.NET/Files/phys/Chunks/JOIN.cs @@ -1,10 +1,8 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; using Warcraft.NET.Files.Phys.Entries; -using Warcraft.NET.Files.Structures; namespace Warcraft.NET.Files.Phys.Chunks { diff --git a/Warcraft.NET/Files/phys/Chunks/PHYT.cs b/Warcraft.NET/Files/phys/Chunks/PHYT.cs index 2ac67b7..7e2d5c7 100644 --- a/Warcraft.NET/Files/phys/Chunks/PHYT.cs +++ b/Warcraft.NET/Files/phys/Chunks/PHYT.cs @@ -1,4 +1,3 @@ -using System; using System.IO; using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; @@ -16,7 +15,7 @@ public class PHYT : IIFFChunk, IBinarySerializable /// /// Gets or Sets PHYT (unknown) /// - public uint Phyt; + public uint Phyt = 0; /// /// Initializes a new instance of diff --git a/Warcraft.NET/Files/phys/Chunks/PHYV.cs b/Warcraft.NET/Files/phys/Chunks/PHYV.cs index c102552..690428a 100644 --- a/Warcraft.NET/Files/phys/Chunks/PHYV.cs +++ b/Warcraft.NET/Files/phys/Chunks/PHYV.cs @@ -1,8 +1,6 @@ -using System.Collections.Generic; -using System.IO; +using System.IO; using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.Phys.Entries; namespace Warcraft.NET.Files.Phys.Chunks { diff --git a/Warcraft.NET/Files/phys/Chunks/PLYT.cs b/Warcraft.NET/Files/phys/Chunks/PLYT.cs index 65a3277..d77a03d 100644 --- a/Warcraft.NET/Files/phys/Chunks/PLYT.cs +++ b/Warcraft.NET/Files/phys/Chunks/PLYT.cs @@ -1,13 +1,9 @@ using System; using System.Collections.Generic; using System.IO; -using System.Numerics; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; -using Warcraft.NET.Files.ADT.Terrain.MCNK; using Warcraft.NET.Files.Interfaces; using Warcraft.NET.Files.Phys.Entries; -using Warcraft.NET.Files.Phys.Structures; namespace Warcraft.NET.Files.Phys.Chunks { diff --git a/Warcraft.NET/Files/phys/Chunks/PRS2.cs b/Warcraft.NET/Files/phys/Chunks/PRS2.cs index 7635418..7d1e742 100644 --- a/Warcraft.NET/Files/phys/Chunks/PRS2.cs +++ b/Warcraft.NET/Files/phys/Chunks/PRS2.cs @@ -1,10 +1,8 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; using Warcraft.NET.Files.Phys.Entries; -using Warcraft.NET.Files.Structures; namespace Warcraft.NET.Files.Phys.Chunks { diff --git a/Warcraft.NET/Files/phys/Chunks/REV2.cs b/Warcraft.NET/Files/phys/Chunks/REV2.cs index 57ebd62..297898a 100644 --- a/Warcraft.NET/Files/phys/Chunks/REV2.cs +++ b/Warcraft.NET/Files/phys/Chunks/REV2.cs @@ -1,10 +1,8 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; using Warcraft.NET.Files.Phys.Entries; -using Warcraft.NET.Files.Structures; namespace Warcraft.NET.Files.Phys.Chunks { diff --git a/Warcraft.NET/Files/phys/Chunks/SHJ2.cs b/Warcraft.NET/Files/phys/Chunks/SHJ2.cs index 4ee4adf..c8ae2e2 100644 --- a/Warcraft.NET/Files/phys/Chunks/SHJ2.cs +++ b/Warcraft.NET/Files/phys/Chunks/SHJ2.cs @@ -1,10 +1,8 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; using Warcraft.NET.Files.Phys.Entries; -using Warcraft.NET.Files.Structures; namespace Warcraft.NET.Files.Phys.Chunks { diff --git a/Warcraft.NET/Files/phys/Chunks/SHOJ.cs b/Warcraft.NET/Files/phys/Chunks/SHOJ.cs index 75bac28..b1149ac 100644 --- a/Warcraft.NET/Files/phys/Chunks/SHOJ.cs +++ b/Warcraft.NET/Files/phys/Chunks/SHOJ.cs @@ -1,10 +1,8 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; using Warcraft.NET.Files.Phys.Entries; -using Warcraft.NET.Files.Structures; namespace Warcraft.NET.Files.Phys.Chunks { diff --git a/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs b/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs index 1ae1d46..8fc497e 100644 --- a/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs +++ b/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs @@ -24,7 +24,7 @@ public class BDY4Entry /// /// sets or gets the default Position of the rigidbody /// - public Vector3 Position { get; set; } = new Vector3(0,0,0); + public Vector3 Position { get; set; } = new Vector3(0, 0, 0); /// /// sets or gets the index of the shape, which is connected to this rigidbody @@ -34,7 +34,7 @@ public class BDY4Entry /// /// sets or gets a currently unknown field. Possibly 'Padding' /// - public byte[] Unk0 { get; set; } = {0,0}; + public byte[] Unk0 { get; set; } = { 0, 0 }; /// /// sets or gets the amount of shapes this rigidbody has @@ -60,9 +60,8 @@ public class BDY4Entry /// /// sets or gets a currently unknown field. Possibly 'Mass/Weight' /// - public float Unk3 = 0f; // default 0, seems to be some sort of weight. - // If version >= 3 and Unk3 == 0 the body will be non kinematic even if the flag is set, it needs to get its transform from the parent bone. - // See offhand_1h_artifactskulloferedar_d_06 where all the bodies have the kinematic flag + public float Unk3 = 0f; + /// /// sets or gets a currently unknown field. /// @@ -71,7 +70,7 @@ public class BDY4Entry /// /// sets or gets a currently unknown field. /// - public byte[] Unk5 { get; set; } = { 0,0,0,0}; + public byte[] Unk5 { get; set; } = { 0, 0, 0, 0 }; /// /// Initializes a new instance of the class. @@ -137,4 +136,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/CAPSEntry.cs b/Warcraft.NET/Files/phys/Entries/CAPSEntry.cs index f8c08ac..dcfde2d 100644 --- a/Warcraft.NET/Files/phys/Entries/CAPSEntry.cs +++ b/Warcraft.NET/Files/phys/Entries/CAPSEntry.cs @@ -1,7 +1,6 @@ using System.IO; using System.Numerics; using Warcraft.NET.Extensions; -using Warcraft.NET.Files.Phys.Chunks; using Warcraft.NET.Files.Structures; namespace Warcraft.NET.Files.Phys.Entries diff --git a/Warcraft.NET/Files/phys/Entries/DSTJEntry.cs b/Warcraft.NET/Files/phys/Entries/DSTJEntry.cs index 3ffee70..6752e96 100644 --- a/Warcraft.NET/Files/phys/Entries/DSTJEntry.cs +++ b/Warcraft.NET/Files/phys/Entries/DSTJEntry.cs @@ -1,7 +1,6 @@ using System.IO; using System.Numerics; using Warcraft.NET.Extensions; -using Warcraft.NET.Files.Structures; namespace Warcraft.NET.Files.Phys.Entries { @@ -66,4 +65,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/JOINEntry.cs b/Warcraft.NET/Files/phys/Entries/JOINEntry.cs index 8d07115..03aaa3c 100644 --- a/Warcraft.NET/Files/phys/Entries/JOINEntry.cs +++ b/Warcraft.NET/Files/phys/Entries/JOINEntry.cs @@ -3,8 +3,6 @@ namespace Warcraft.NET.Files.Phys.Entries { - - public class JOINEntry { /// diff --git a/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs b/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs index b6bfca2..ea05bee 100644 --- a/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs +++ b/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs @@ -1,4 +1,3 @@ -using SharpCompress.Common; using System.IO; using System.Numerics; using Warcraft.NET.Extensions; diff --git a/Warcraft.NET/Files/phys/Entries/PRS2Entry.cs b/Warcraft.NET/Files/phys/Entries/PRS2Entry.cs index 21e6b12..fc925a8 100644 --- a/Warcraft.NET/Files/phys/Entries/PRS2Entry.cs +++ b/Warcraft.NET/Files/phys/Entries/PRS2Entry.cs @@ -1,4 +1,3 @@ -using System; using System.IO; using Warcraft.NET.Extensions; @@ -10,30 +9,37 @@ public class PRS2Entry /// The Transformation Matrix for Bone A of this Joint /// public Matrix3x4 FrameA; + /// /// The Transformation Matrix for Bone B of this Joint /// public Matrix3x4 FrameB; + /// /// The lower limit /// public float LowerLimit; + /// /// The upper limit /// public float UpperLimit; + /// /// Unknown value /// - public float Unk0; //prev unk_68 + public float Unk0; + /// /// Max motor force if enabled /// public float MaxMotorForce; + /// /// unknown value /// - public float Unk1; //prev unk_70 + public float Unk1; + /// /// The MotorMode /// 0 = disabled? @@ -41,10 +47,12 @@ public class PRS2Entry /// 2 = motorVelocityMode /// public uint MotorMode; + /// /// how often per second the motor damps /// public float MotorFrequencyHz; + /// /// the ratio how much the motor damps /// @@ -108,4 +116,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/REV2Entry.cs b/Warcraft.NET/Files/phys/Entries/REV2Entry.cs index a142d3d..bc747ac 100644 --- a/Warcraft.NET/Files/phys/Entries/REV2Entry.cs +++ b/Warcraft.NET/Files/phys/Entries/REV2Entry.cs @@ -1,7 +1,5 @@ -using System; using System.IO; using Warcraft.NET.Extensions; -using Warcraft.NET.Files.Structures; namespace Warcraft.NET.Files.Phys.Entries { @@ -100,4 +98,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs b/Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs index 6e6446d..0586d11 100644 --- a/Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs +++ b/Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs @@ -1,7 +1,5 @@ -using System; -using System.IO; +using System.IO; using Warcraft.NET.Extensions; -using Warcraft.NET.Files.Structures; namespace Warcraft.NET.Files.Phys.Entries { @@ -111,4 +109,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/SHOJEntry.cs b/Warcraft.NET/Files/phys/Entries/SHOJEntry.cs index 38f0626..1c5bead 100644 --- a/Warcraft.NET/Files/phys/Entries/SHOJEntry.cs +++ b/Warcraft.NET/Files/phys/Entries/SHOJEntry.cs @@ -1,7 +1,5 @@ -using System; -using System.IO; +using System.IO; using Warcraft.NET.Extensions; -using Warcraft.NET.Files.Structures; namespace Warcraft.NET.Files.Phys.Entries { @@ -97,4 +95,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/SPHJEntry.cs b/Warcraft.NET/Files/phys/Entries/SPHJEntry.cs index 100f179..1f0d175 100644 --- a/Warcraft.NET/Files/phys/Entries/SPHJEntry.cs +++ b/Warcraft.NET/Files/phys/Entries/SPHJEntry.cs @@ -1,4 +1,3 @@ -using System; using System.IO; using System.Numerics; using Warcraft.NET.Extensions; @@ -67,4 +66,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs b/Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs index dddbe48..396083e 100644 --- a/Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs +++ b/Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs @@ -1,7 +1,5 @@ -using System; using System.IO; using Warcraft.NET.Extensions; -using Warcraft.NET.Files.Structures; namespace Warcraft.NET.Files.Phys.Entries { @@ -90,8 +88,6 @@ public byte[] Serialize(long offset = 0) bw.Write(Unk0); return ms.ToArray(); } - } - } } diff --git a/Warcraft.NET/Files/phys/Physics.cs b/Warcraft.NET/Files/phys/Physics.cs index 090069c..32a3200 100644 --- a/Warcraft.NET/Files/phys/Physics.cs +++ b/Warcraft.NET/Files/phys/Physics.cs @@ -6,56 +6,108 @@ namespace Warcraft.NET.Files.Phys [AutoDocFile("phys")] public class Physics : ChunkedFile { + /// + /// contains the version of the physics + /// [ChunkOrder(1)] public PHYS Version{get; set;} + /// + /// contains an unknown uint + /// [ChunkOptional] - public PHYT Phyt{get; set; } //unknown what it stands for + public PHYT Phyt{get; set; } + /// + /// contains the used box shapes + /// [ChunkOptional] public BOXS BoxShapes{get;set;} + /// + /// contains the used sphere shapes + /// [ChunkOptional] public SPHS SphereShapes{get;set;} + /// + /// contains the used capsule shapes + /// + [ChunkOptional] public CAPS CapsuleShapes{get;set;} + /// + /// contains the used polytope shapes + /// [ChunkOptional] public PLYT PolytopeShapes{get; set;} + /// + /// contains the used shapes + /// [ChunkOptional] public SHP2 Shapes2{get; set;} //SHAP nyi + /// + /// contains the used rigidbodies + /// [ChunkOptional] public BDY4 Rigidbodies4{get; set;} //BODY,BDY2,BDY3 NYI + /// + /// contains the used shoulder joints + /// [ChunkOptional] public SHOJ ShoulderJoints { get; set; } + /// + /// contains the used shoulder joints + /// [ChunkOptional] public SHJ2 ShoulderJoints2{get; set;} + /// + /// contains the used weld joints + /// [ChunkOptional] public WLJ3 WeldJoints3{get; set;} //WELJ,WLJ2 nyi + /// + /// contains the used spherical joints + /// [ChunkOptional] public SPHJ SphericalJoints{get; set;} + /// + /// contains the used prismatic joints + /// [ChunkOptional] public PRS2 PrismaticJoints2{get; set;} //PRSJ nyi + /// + /// contains the used revolute joints + /// [ChunkOptional] public REV2 RevoluteJoints2{get; set;} //REVJ nyi + /// + /// contains the used distance joints + /// [ChunkOptional] - public DSTJ DistanceJoints{get; set;} - + public DSTJ DistanceJoints{get; set;} + + /// + /// contains the used joints + /// [ChunkOptional] public JOIN Joints{get; set;} + /// + /// contains the used phyv data (unknown) + /// [ChunkOptional] - public PHYV Phyv { get; set; } //unknown what it stands for + public PHYV Phyv { get; set; } /// /// Initializes a new instance of the class. From a352a4f11f40d18af4a4197d60b7034ee36bc90e Mon Sep 17 00:00:00 2001 From: gulasch7742 Date: Sat, 24 Aug 2024 10:21:35 +0200 Subject: [PATCH 06/15] h --- Warcraft.NET/Files/M2/Chunks/BfA/TXID.cs | 2 +- Warcraft.NET/Files/M2/Chunks/Legion/EXP2.cs | 50 +++++++++++++++++++++ Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs | 2 +- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/EXP2.cs diff --git a/Warcraft.NET/Files/M2/Chunks/BfA/TXID.cs b/Warcraft.NET/Files/M2/Chunks/BfA/TXID.cs index 37daeb6..4f06227 100644 --- a/Warcraft.NET/Files/M2/Chunks/BfA/TXID.cs +++ b/Warcraft.NET/Files/M2/Chunks/BfA/TXID.cs @@ -61,4 +61,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/EXP2.cs b/Warcraft.NET/Files/M2/Chunks/Legion/EXP2.cs new file mode 100644 index 0000000..155bdbc --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/EXP2.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + public class EXP2 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "EXP2"; + + /// + /// Gets or sets the EXP2 Data + /// + public byte[] Data; + + /// + /// Initializes a new instance of + /// + public EXP2() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public EXP2(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + Data = inData; + } + + /// + public byte[] Serialize(long offset = 0) + { + return Data; + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs b/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs index 8e9956e..bd4815b 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs @@ -15,7 +15,7 @@ public class EXPT : IIFFChunk, IBinarySerializable public const string Signature = "EXP2"; /// - /// Gets or sets the Skin FileDataId + /// Gets or sets the EXPT Entries /// public List EXP2Entries = new(); From 3308832da815e19f41e02fa7209b54ea07153480 Mon Sep 17 00:00:00 2001 From: gulasch7742 Date: Tue, 27 Aug 2024 11:19:54 +0200 Subject: [PATCH 07/15] change --- Warcraft.NET/Files/M2/Model.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Warcraft.NET/Files/M2/Model.cs b/Warcraft.NET/Files/M2/Model.cs index 54330ea..4bb1156 100644 --- a/Warcraft.NET/Files/M2/Model.cs +++ b/Warcraft.NET/Files/M2/Model.cs @@ -141,37 +141,37 @@ public class Model : ChunkedFile /// /// Gets or sets the model recursive particle file ids /// - [ChunkOrder(), ChunkOptional] + [ChunkOrder(22), ChunkOptional] public RPID RecursiveParticleFileIds { get; set; } /// /// Gets or sets the model geometry particle file ids /// - [ChunkOrder(), ChunkOptional] + [ChunkOrder(23), ChunkOptional] public GPID GeometryParticleFileIds { get; set; } /// /// Gets or sets the ParentAnimData /// - [ChunkOrder(),ChunkOptional] + [ChunkOrder(24),ChunkOptional] public PADC M2InitParentAnimData { get; set; } /// /// Gets or sets the NERF /// - [ChunkOrder(),ChunkOptional] + [ChunkOrder(25),ChunkOptional] public NERF NERF { get; set; } /// /// Gets or sets the DETL (light related) /// - [ChunkOrder(),ChunkOptional] + [ChunkOrder(26),ChunkOptional] public DETL DETL { get; set; } /// /// Gets or sets the AFRA /// - [ChunkOrder(),ChunkOptional] + [ChunkOrder(27),ChunkOptional] public AFRA AFRA { get; set; } /// From f78e289e2f5621ef98a83706c926237d960f48ce Mon Sep 17 00:00:00 2001 From: gulasch7742 Date: Tue, 27 Aug 2024 11:44:49 +0200 Subject: [PATCH 08/15] changes --- Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs | 1 - Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs | 2 -- Warcraft.NET/Files/M2/Chunks/Legion/SKID.cs | 1 - Warcraft.NET/Files/M2/Model.cs | 2 -- .../Files/Structures/M2SkinSection.cs | 8 ++--- Warcraft.NET/Files/phys/Chunks/SPHJ.cs | 1 - Warcraft.NET/Files/phys/Entries/PLYTEntry.cs | 20 +++++++++--- Warcraft.NET/Files/phys/Physics.cs | 32 +++++++++---------- 8 files changed, 36 insertions(+), 31 deletions(-) diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs b/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs index aa58e66..b3a175e 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs @@ -61,7 +61,6 @@ public byte[] Serialize(long offset = 0) { bw.Write(obj.Serialize()); } - return ms.ToArray(); } } diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs b/Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs index 5182dbd..888cdc6 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs @@ -42,7 +42,6 @@ public void LoadBinaryData(byte[] inData) using (var br = new BinaryReader(ms)) { uint nBone = (uint)inData.Length / 4; - for (var i = 0; i < nBone; i++) BoneFileDataIds.Add(br.ReadUInt32()); } @@ -56,7 +55,6 @@ public byte[] Serialize(long offset = 0) { foreach(uint boneFileDataId in BoneFileDataIds) bw.Write(boneFileDataId); - return ms.ToArray(); } } diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/SKID.cs b/Warcraft.NET/Files/M2/Chunks/Legion/SKID.cs index ad43e1d..1908f10 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/SKID.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/SKID.cs @@ -51,7 +51,6 @@ public byte[] Serialize(long offset = 0) using (var bw = new BinaryWriter(ms)) { bw.Write(SkeletonFileDataId); - return ms.ToArray(); } } diff --git a/Warcraft.NET/Files/M2/Model.cs b/Warcraft.NET/Files/M2/Model.cs index 4bb1156..e92e642 100644 --- a/Warcraft.NET/Files/M2/Model.cs +++ b/Warcraft.NET/Files/M2/Model.cs @@ -136,8 +136,6 @@ public class Model : ChunkedFile [ChunkOrder(21),ChunkOptional] public PSBC M2InitParentSequenceBoundsData { get; set; } - - /// /// Gets or sets the model recursive particle file ids /// diff --git a/Warcraft.NET/Files/Structures/M2SkinSection.cs b/Warcraft.NET/Files/Structures/M2SkinSection.cs index e189026..cbd4b55 100644 --- a/Warcraft.NET/Files/Structures/M2SkinSection.cs +++ b/Warcraft.NET/Files/Structures/M2SkinSection.cs @@ -48,10 +48,10 @@ public struct M2SkinSection public ushort BoneComboIndex; /// - /// <= 4 - /// from <=BC documentation: Highest number of bones needed at one time in this Submesh --Tinyn (wowdev.org) - /// In 2.x this is the amount of of bones up the parent-chain affecting the submesh --NaK - /// Highest number of bones referenced by a vertex of this submesh. 3.3.5a and suspectedly all other client revisions. -- Skarn + /// <= 4 + /// from <=BC documentation: Highest number of bones needed at one time in this Submesh --Tinyn (wowdev.org) + /// In 2.x this is the amount of of bones up the parent-chain affecting the submesh --NaK + /// Highest number of bones referenced by a vertex of this submesh. 3.3.5a and suspectedly all other client revisions. -- Skarn /// public ushort BoneInfluences; diff --git a/Warcraft.NET/Files/phys/Chunks/SPHJ.cs b/Warcraft.NET/Files/phys/Chunks/SPHJ.cs index fd01294..4ec195f 100644 --- a/Warcraft.NET/Files/phys/Chunks/SPHJ.cs +++ b/Warcraft.NET/Files/phys/Chunks/SPHJ.cs @@ -43,7 +43,6 @@ public void LoadBinaryData(byte[] inData) using (var br = new BinaryReader(ms)) { var SPHJcount = br.BaseStream.Length / SPHJEntry.GetSize(); - for (var i = 0; i < SPHJcount; ++i) { SPHJEntries.Add(new SPHJEntry(br.ReadBytes(SPHJEntry.GetSize()))); diff --git a/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs b/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs index ea05bee..5e5ce51 100644 --- a/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs +++ b/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs @@ -30,7 +30,7 @@ public PLYTEntry() { } /// /// Initializes a new instance of the class. /// - /// ExtendedData. + /// Header Data public PLYTEntry(byte[] header) { using (var ms = new MemoryStream(header)) @@ -59,6 +59,10 @@ public PLYTEntry(byte[] header) } } + /// + /// Deserialization of the Data Chunks + /// + /// public void DeserializeData(byte[] data) { using (var ms = new MemoryStream(data)) @@ -78,7 +82,7 @@ public void DeserializeData(byte[] data) Data.Nodes = new PlytNode[nodeCount]; for (int n = 0; n < nodeCount; n++) { - PlytNode node = new PlytNode(); + PlytNode node = new(); node.Unk = br.ReadByte(); node.VertexIndex = br.ReadByte(); node.UnkIndex0 = br.ReadByte(); @@ -115,7 +119,11 @@ public int GetSize() return SerializeHeader().Length + SerializeData().Length; } - /// + /// + /// Serialize the Header + /// + /// + /// public byte[] SerializeHeader(long offset = 0) { using (var ms = new MemoryStream()) @@ -148,7 +156,11 @@ public byte[] SerializeHeader(long offset = 0) } } - /// + /// + /// Serialize the Data + /// + /// + /// public byte[] SerializeData(long offset = 0) { using (var ms = new MemoryStream()) diff --git a/Warcraft.NET/Files/phys/Physics.cs b/Warcraft.NET/Files/phys/Physics.cs index 32a3200..45ec5ef 100644 --- a/Warcraft.NET/Files/phys/Physics.cs +++ b/Warcraft.NET/Files/phys/Physics.cs @@ -15,98 +15,98 @@ public class Physics : ChunkedFile /// /// contains an unknown uint /// - [ChunkOptional] + [ChunkOrder(2),ChunkOptional] public PHYT Phyt{get; set; } /// /// contains the used box shapes /// - [ChunkOptional] + [ChunkOrder(3),ChunkOptional] public BOXS BoxShapes{get;set;} /// /// contains the used sphere shapes /// - [ChunkOptional] + [ChunkOrder(4),ChunkOptional] public SPHS SphereShapes{get;set;} /// /// contains the used capsule shapes /// - [ChunkOptional] + [ChunkOrder(5),ChunkOptional] public CAPS CapsuleShapes{get;set;} /// /// contains the used polytope shapes /// - [ChunkOptional] + [ChunkOrder(6),ChunkOptional] public PLYT PolytopeShapes{get; set;} /// /// contains the used shapes /// - [ChunkOptional] + [ChunkOrder(7),ChunkOptional] public SHP2 Shapes2{get; set;} //SHAP nyi /// /// contains the used rigidbodies /// - [ChunkOptional] + [ChunkOrder(8),ChunkOptional] public BDY4 Rigidbodies4{get; set;} //BODY,BDY2,BDY3 NYI /// /// contains the used shoulder joints /// - [ChunkOptional] + [ChunkOrder(9),ChunkOptional] public SHOJ ShoulderJoints { get; set; } /// /// contains the used shoulder joints /// - [ChunkOptional] + [ChunkOrder(10),ChunkOptional] public SHJ2 ShoulderJoints2{get; set;} /// /// contains the used weld joints /// - [ChunkOptional] + [ChunkOrder(11),ChunkOptional] public WLJ3 WeldJoints3{get; set;} //WELJ,WLJ2 nyi /// /// contains the used spherical joints /// - [ChunkOptional] + [ChunkOrder(12),ChunkOptional] public SPHJ SphericalJoints{get; set;} /// /// contains the used prismatic joints /// - [ChunkOptional] + [ChunkOrder(13),ChunkOptional] public PRS2 PrismaticJoints2{get; set;} //PRSJ nyi /// /// contains the used revolute joints /// - [ChunkOptional] + [ChunkOrder(14),ChunkOptional] public REV2 RevoluteJoints2{get; set;} //REVJ nyi /// /// contains the used distance joints /// - [ChunkOptional] + [ChunkOrder(15),ChunkOptional] public DSTJ DistanceJoints{get; set;} /// /// contains the used joints /// - [ChunkOptional] + [ChunkOrder(16),ChunkOptional] public JOIN Joints{get; set;} /// /// contains the used phyv data (unknown) /// - [ChunkOptional] + [ChunkOrder(17),ChunkOptional] public PHYV Phyv { get; set; } /// From 2c7056b7f47cfed4bd1522d8c18e8e26d945a7a1 Mon Sep 17 00:00:00 2001 From: gulasch7742 Date: Tue, 27 Aug 2024 11:51:48 +0200 Subject: [PATCH 09/15] plyt --- Warcraft.NET/Files/phys/Chunks/PLYT.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Warcraft.NET/Files/phys/Chunks/PLYT.cs b/Warcraft.NET/Files/phys/Chunks/PLYT.cs index d77a03d..12fd612 100644 --- a/Warcraft.NET/Files/phys/Chunks/PLYT.cs +++ b/Warcraft.NET/Files/phys/Chunks/PLYT.cs @@ -43,13 +43,13 @@ public void LoadBinaryData(byte[] inData) using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) { - var PLYTcount = br.ReadUInt32(); - for (var i = 0; i < PLYTcount; i++) + var plyt_count = br.ReadUInt32(); + for (var i = 0; i < plyt_count; i++) { PLYTEntry plyt_entry = new PLYTEntry(br.ReadBytes(80)); PLYTEntries.Add(plyt_entry); } - for (var j = 0; j < PLYTcount; j++) + for (var j = 0; j < plyt_count; j++) { PLYTEntry plyt_entry = PLYTEntries[j]; plyt_entry.DeserializeData(br.ReadBytes(plyt_entry.DataSize)); From 6f141f690388528a55e600363974fbac0ab51260 Mon Sep 17 00:00:00 2001 From: gulasch7742 Date: Wed, 28 Aug 2024 23:57:41 +0200 Subject: [PATCH 10/15] Fixing fixed the namings and spaces --- Warcraft.NET/Extensions/ExtendedIO.cs | 113 ++++++--- Warcraft.NET/Files/M2/Chunks/BfA/LDV1.cs | 4 +- Warcraft.NET/Files/M2/Chunks/BfA/TXID.cs | 2 +- Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs | 23 +- Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs | 23 +- Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs | 33 +-- Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs | 3 +- Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs | 4 +- Warcraft.NET/Files/M2/Chunks/Legion/EXP2.cs | 50 ++++ Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs | 4 +- Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs | 12 +- Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs | 27 +- Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs | 25 +- Warcraft.NET/Files/M2/Chunks/Legion/PFID.cs | 2 +- Warcraft.NET/Files/M2/Chunks/Legion/PGD1.cs | 7 +- Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs | 20 +- Warcraft.NET/Files/M2/Chunks/Legion/SFID.cs | 2 +- Warcraft.NET/Files/M2/Chunks/Legion/SKID.cs | 3 +- Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs | 24 +- Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs | 6 +- Warcraft.NET/Files/M2/Chunks/SL/DETL.cs | 4 +- Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs | 4 +- Warcraft.NET/Files/M2/Chunks/SL/NERF.cs | 5 +- Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs | 37 +-- Warcraft.NET/Files/M2/Chunks/SL/WFV3.cs | 4 +- Warcraft.NET/Files/M2/Entries/AFIDEntry.cs | 6 +- Warcraft.NET/Files/M2/Entries/DBOCEntry.cs | 46 ++-- Warcraft.NET/Files/M2/Entries/DETLEntry.cs | 55 ++-- Warcraft.NET/Files/M2/Entries/EDGFEntry.cs | 41 +-- Warcraft.NET/Files/M2/Entries/EXPTEntry.cs | 35 +-- Warcraft.NET/Files/M2/Entries/LDV1Entry.cs | 58 +++-- Warcraft.NET/Files/M2/Entries/WFV3Entry.cs | 234 +++++++++++------- Warcraft.NET/Files/M2/Model.cs | 177 +++++++------ Warcraft.NET/Files/SKIN/Skin.cs | 140 ++++++----- Warcraft.NET/Files/Structures/M2Batch.cs | 73 ++++++ .../Files/Structures/M2ShadowBatch.cs | 41 +++ .../Files/Structures/M2SkinBoneStruct.cs | 25 ++ .../Files/Structures/M2SkinSection.cs | 79 ++++++ Warcraft.NET/Files/Structures/M2Triangle.cs | 25 ++ Warcraft.NET/Files/Structures/Matrix3x4.cs | 68 +++++ Warcraft.NET/Files/phys/Chunks/BDY4.cs | 13 +- Warcraft.NET/Files/phys/Chunks/BOXS.cs | 11 +- Warcraft.NET/Files/phys/Chunks/CAPS.cs | 12 +- Warcraft.NET/Files/phys/Chunks/DSTJ.cs | 11 +- Warcraft.NET/Files/phys/Chunks/JOIN.cs | 12 +- Warcraft.NET/Files/phys/Chunks/PHYS.cs | 8 +- Warcraft.NET/Files/phys/Chunks/PHYT.cs | 10 +- Warcraft.NET/Files/phys/Chunks/PHYV.cs | 27 +- Warcraft.NET/Files/phys/Chunks/PLYT.cs | 66 +---- Warcraft.NET/Files/phys/Chunks/PRS2.cs | 11 +- Warcraft.NET/Files/phys/Chunks/REV2.cs | 11 +- Warcraft.NET/Files/phys/Chunks/SHJ2.cs | 11 +- Warcraft.NET/Files/phys/Chunks/SHOJ.cs | 11 +- Warcraft.NET/Files/phys/Chunks/SHP2.cs | 11 +- Warcraft.NET/Files/phys/Chunks/SPHJ.cs | 12 +- Warcraft.NET/Files/phys/Chunks/SPHS.cs | 31 +-- Warcraft.NET/Files/phys/Chunks/WLJ3.cs | 11 +- Warcraft.NET/Files/phys/Entries/BDY4Entry.cs | 140 +++++++---- Warcraft.NET/Files/phys/Entries/BOXSEntry.cs | 23 +- Warcraft.NET/Files/phys/Entries/CAPSEntry.cs | 30 +-- Warcraft.NET/Files/phys/Entries/DSTJEntry.cs | 38 +-- Warcraft.NET/Files/phys/Entries/JOINEntry.cs | 71 +++--- Warcraft.NET/Files/phys/Entries/PLYTEntry.cs | 202 +++++++++------ Warcraft.NET/Files/phys/Entries/PRS2Entry.cs | 106 +++++--- Warcraft.NET/Files/phys/Entries/REV2Entry.cs | 83 ++++--- Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs | 98 +++++--- Warcraft.NET/Files/phys/Entries/SHOJEntry.cs | 79 ++++-- Warcraft.NET/Files/phys/Entries/SHP2Entry.cs | 128 +++++----- Warcraft.NET/Files/phys/Entries/SPHJEntry.cs | 36 ++- Warcraft.NET/Files/phys/Entries/SPHSEntry.cs | 52 ++++ Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs | 76 +++--- Warcraft.NET/Files/phys/Enums/BodyType.cs | 9 + Warcraft.NET/Files/phys/Enums/JointType.cs | 12 + Warcraft.NET/Files/phys/Enums/ShapeType.cs | 10 + Warcraft.NET/Files/phys/Physics.cs | 124 +++++++--- .../Files/phys/Structures/PlytData.cs | 29 +++ .../Files/phys/Structures/PlytHeader.cs | 62 +++++ .../Files/phys/Structures/PlytNode.cs | 29 +++ 78 files changed, 2115 insertions(+), 1145 deletions(-) create mode 100644 Warcraft.NET/Files/M2/Chunks/Legion/EXP2.cs create mode 100644 Warcraft.NET/Files/Structures/M2Batch.cs create mode 100644 Warcraft.NET/Files/Structures/M2ShadowBatch.cs create mode 100644 Warcraft.NET/Files/Structures/M2SkinBoneStruct.cs create mode 100644 Warcraft.NET/Files/Structures/M2SkinSection.cs create mode 100644 Warcraft.NET/Files/Structures/M2Triangle.cs create mode 100644 Warcraft.NET/Files/Structures/Matrix3x4.cs create mode 100644 Warcraft.NET/Files/phys/Entries/SPHSEntry.cs create mode 100644 Warcraft.NET/Files/phys/Enums/BodyType.cs create mode 100644 Warcraft.NET/Files/phys/Enums/JointType.cs create mode 100644 Warcraft.NET/Files/phys/Enums/ShapeType.cs create mode 100644 Warcraft.NET/Files/phys/Structures/PlytData.cs create mode 100644 Warcraft.NET/Files/phys/Structures/PlytHeader.cs create mode 100644 Warcraft.NET/Files/phys/Structures/PlytNode.cs diff --git a/Warcraft.NET/Extensions/ExtendedIO.cs b/Warcraft.NET/Extensions/ExtendedIO.cs index 86bc251..4d96681 100644 --- a/Warcraft.NET/Extensions/ExtendedIO.cs +++ b/Warcraft.NET/Extensions/ExtendedIO.cs @@ -78,6 +78,22 @@ public static Vector3 ReadVector3(this BinaryReader binaryReader, AxisConfigurat } } + /// + /// Reads a 48-byte structure from the data stream and advances the position of the stream by + /// 48 bytes. + /// + /// The Mat3x4. + /// The reader. + /// Which axis configuration the read mat3x4 should be converted to. + public static Matrix3x4 ReadMatrix3x4(this BinaryReader binaryReader, AxisConfiguration convertTo = AxisConfiguration.YUp) + { + var a = binaryReader.ReadVector3(convertTo); + var b = binaryReader.ReadVector3(convertTo); + var c = binaryReader.ReadVector3(convertTo); + var pos = binaryReader.ReadVector3(convertTo); + return new Matrix3x4(a, b, c, pos); + } + /// /// Reads a 12-byte from the data stream and advances the position of the stream by /// 12 bytes. @@ -273,37 +289,37 @@ public static ShortVector3 ReadShortVector3(this BinaryReader binaryReader, Axis switch (convertTo) { case AxisConfiguration.Native: - { - return new ShortVector3(binaryReader.ReadInt16(), binaryReader.ReadInt16(), binaryReader.ReadInt16()); - } + { + return new ShortVector3(binaryReader.ReadInt16(), binaryReader.ReadInt16(), binaryReader.ReadInt16()); + } case AxisConfiguration.YUp: - { - var x1 = binaryReader.ReadInt16(); - var y1 = binaryReader.ReadInt16(); - var z1 = binaryReader.ReadInt16(); + { + var x1 = binaryReader.ReadInt16(); + var y1 = binaryReader.ReadInt16(); + var z1 = binaryReader.ReadInt16(); - var x = x1; - var y = z1; - var z = (short)-y1; + var x = x1; + var y = z1; + var z = (short)-y1; - return new ShortVector3(x, y, z); - } + return new ShortVector3(x, y, z); + } case AxisConfiguration.ZUp: - { - var x1 = binaryReader.ReadInt16(); - var y1 = binaryReader.ReadInt16(); - var z1 = binaryReader.ReadInt16(); + { + var x1 = binaryReader.ReadInt16(); + var y1 = binaryReader.ReadInt16(); + var z1 = binaryReader.ReadInt16(); - var x = x1; - var y = (short)-z1; - var z = y1; + var x = x1; + var y = (short)-z1; + var z = y1; - return new ShortVector3(x, y, z); - } + return new ShortVector3(x, y, z); + } default: - { - throw new ArgumentOutOfRangeException(nameof(convertTo), convertTo, null); - } + { + throw new ArgumentOutOfRangeException(nameof(convertTo), convertTo, null); + } } } @@ -565,6 +581,25 @@ public static void WriteVector3(this BinaryWriter binaryWriter, Vector3 vector, } } + /// + /// Writes a 48-byte value to the data stream. This function + /// + /// The current object. + /// The Vector to write. + /// Which axis configuration the read vector should be stored as. + public static void WriteMatrix3x4(this BinaryWriter binaryWriter, Matrix3x4 matrix, AxisConfiguration storeAs = AxisConfiguration.ZUp) + { + var column1 = matrix.RotationX * matrix.Scale.X; + var column2 = matrix.RotationY * matrix.Scale.Y; + var column3 = matrix.RotationZ * matrix.Scale.Z; + var column4 = matrix.Position; + + binaryWriter.WriteVector3(column1, storeAs); + binaryWriter.WriteVector3(column2, storeAs); + binaryWriter.WriteVector3(column3, storeAs); + binaryWriter.WriteVector3(column4, storeAs); + } + /// /// Writes a 16-byte to the data stream. /// @@ -602,23 +637,23 @@ public static void WriteShortVector3(this BinaryWriter binaryWriter, ShortVector { case AxisConfiguration.Native: case AxisConfiguration.YUp: - { - binaryWriter.Write(vector.X); - binaryWriter.Write(vector.Y); - binaryWriter.Write(vector.Z); - break; - } + { + binaryWriter.Write(vector.X); + binaryWriter.Write(vector.Y); + binaryWriter.Write(vector.Z); + break; + } case AxisConfiguration.ZUp: - { - binaryWriter.Write(vector.X); - binaryWriter.Write((short)(vector.Z * -1)); - binaryWriter.Write(vector.Y); - break; - } + { + binaryWriter.Write(vector.X); + binaryWriter.Write((short)(vector.Z * -1)); + binaryWriter.Write(vector.Y); + break; + } default: - { - throw new ArgumentOutOfRangeException(nameof(storeAs), storeAs, null); - } + { + throw new ArgumentOutOfRangeException(nameof(storeAs), storeAs, null); + } } } diff --git a/Warcraft.NET/Files/M2/Chunks/BfA/LDV1.cs b/Warcraft.NET/Files/M2/Chunks/BfA/LDV1.cs index f640b86..44a7e33 100644 --- a/Warcraft.NET/Files/M2/Chunks/BfA/LDV1.cs +++ b/Warcraft.NET/Files/M2/Chunks/BfA/LDV1.cs @@ -15,7 +15,7 @@ public class LDV1 : IIFFChunk, IBinarySerializable public const string Signature = "LDV1"; /// - /// Gets or sets the Skin FileDataId + /// Gets or sets the Lod Data Version 1 Entries /// public List LDV1Entries = new(); @@ -62,10 +62,8 @@ public byte[] Serialize(long offset = 0) { bw.Write(obj.Serialize()); } - return ms.ToArray(); } } - } } \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/BfA/TXID.cs b/Warcraft.NET/Files/M2/Chunks/BfA/TXID.cs index 37daeb6..4f06227 100644 --- a/Warcraft.NET/Files/M2/Chunks/BfA/TXID.cs +++ b/Warcraft.NET/Files/M2/Chunks/BfA/TXID.cs @@ -61,4 +61,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs b/Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs index fbc23dc..ee2e459 100644 --- a/Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs +++ b/Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs @@ -14,7 +14,10 @@ public class WFV1 : IIFFChunk, IBinarySerializable /// public const string Signature = "WFV1"; - public byte[] data; + /// + /// Gets or sets the full data (deserialization NYI) + /// + public byte[] Data; /// /// Initializes a new instance of @@ -36,27 +39,13 @@ public WFV1() { } /// public void LoadBinaryData(byte[] inData) { - { - using (var ms = new MemoryStream(inData)) - using (var br = new BinaryReader(ms)) - { - data = inData; - } - } + Data = inData; } /// public byte[] Serialize(long offset = 0) { - using (var ms = new MemoryStream()) - using (var bw = new BinaryWriter(ms)) - { - bw.Write(data); - - - return ms.ToArray(); - } + return Data; } - } } \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs b/Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs index af31db9..3eacdc2 100644 --- a/Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs +++ b/Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs @@ -14,7 +14,10 @@ public class WFV2 : IIFFChunk, IBinarySerializable /// public const string Signature = "WFV2"; - public byte[] data; + /// + /// Gets or sets the full data (deserialization NYI) + /// + public byte[] Data; /// /// Initializes a new instance of @@ -36,27 +39,13 @@ public WFV2() { } /// public void LoadBinaryData(byte[] inData) { - { - using (var ms = new MemoryStream(inData)) - using (var br = new BinaryReader(ms)) - { - data = inData; - } - } + Data = inData; } /// public byte[] Serialize(long offset = 0) { - using (var ms = new MemoryStream()) - using (var bw = new BinaryWriter(ms)) - { - bw.Write(data); - - - return ms.ToArray(); - } + return Data; } - } } \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs b/Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs index 1fad62d..3225f66 100644 --- a/Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs +++ b/Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs @@ -1,12 +1,7 @@ -using System.Collections.Generic; -using System.IO; -using Warcraft.NET.Attribute; -using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.M2.Entries; +using Warcraft.NET.Files.Interfaces; namespace Warcraft.NET.Files.M2.Chunks.DF { - [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterSL, AutoDocChunkVersionHelper.VersionBeforeDF)] public class AFRA : IIFFChunk, IBinarySerializable { /// @@ -14,6 +9,11 @@ public class AFRA : IIFFChunk, IBinarySerializable /// public const string Signature = "AFRA"; + /// + /// Gets or sets the full data (deserialization NYI) + /// + public byte[] Data; + /// /// Initializes a new instance of /// @@ -29,30 +29,21 @@ public AFRA() { } public string GetSignature() { return Signature; } /// - public uint GetSize() { return (uint)Serialize().Length; } - - byte[] data; + public uint GetSize() + { + return (uint)Serialize().Length; + } /// public void LoadBinaryData(byte[] inData) { - using (var ms = new MemoryStream(inData)) - using (var br = new BinaryReader(ms)) - { - data = inData; - } + Data = inData; } /// public byte[] Serialize(long offset = 0) { - using (var ms = new MemoryStream()) - using (var bw = new BinaryWriter(ms)) - { - bw.Write(data); - - return ms.ToArray(); - } + return Data; } } } diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs b/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs index 91d0185..b3a175e 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs @@ -61,9 +61,8 @@ public byte[] Serialize(long offset = 0) { bw.Write(obj.Serialize()); } - return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs b/Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs index 26b13ca..888cdc6 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs @@ -42,7 +42,6 @@ public void LoadBinaryData(byte[] inData) using (var br = new BinaryReader(ms)) { uint nBone = (uint)inData.Length / 4; - for (var i = 0; i < nBone; i++) BoneFileDataIds.Add(br.ReadUInt32()); } @@ -56,9 +55,8 @@ public byte[] Serialize(long offset = 0) { foreach(uint boneFileDataId in BoneFileDataIds) bw.Write(boneFileDataId); - return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/EXP2.cs b/Warcraft.NET/Files/M2/Chunks/Legion/EXP2.cs new file mode 100644 index 0000000..155bdbc --- /dev/null +++ b/Warcraft.NET/Files/M2/Chunks/Legion/EXP2.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.M2.Chunks.Legion +{ + public class EXP2 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "EXP2"; + + /// + /// Gets or sets the EXP2 Data + /// + public byte[] Data; + + /// + /// Initializes a new instance of + /// + public EXP2() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public EXP2(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + Data = inData; + } + + /// + public byte[] Serialize(long offset = 0) + { + return Data; + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs b/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs index 6483a5a..bd4815b 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs @@ -15,7 +15,7 @@ public class EXPT : IIFFChunk, IBinarySerializable public const string Signature = "EXP2"; /// - /// Gets or sets the Skin FileDataId + /// Gets or sets the EXPT Entries /// public List EXP2Entries = new(); @@ -62,10 +62,8 @@ public byte[] Serialize(long offset = 0) { bw.Write(obj.Serialize()); } - return ms.ToArray(); } } - } } \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs index 276cae0..d010543 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PABC.cs @@ -1,9 +1,7 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.M2.Entries; namespace Warcraft.NET.Files.M2.Chunks.Legion { @@ -16,9 +14,9 @@ public class PABC : IIFFChunk, IBinarySerializable public const string Signature = "PABC"; /// - /// Gets or sets the Skin FileDataId + /// Gets or sets the ParentSequenceBounds Entries /// - public List PABCEntries = new(); + public List PABCEntries = new(); /// /// Initializes a new instance of @@ -59,14 +57,12 @@ public byte[] Serialize(long offset = 0) using (var ms = new MemoryStream()) using (var bw = new BinaryWriter(ms)) { - foreach (UInt16 obj in PABCEntries) + foreach (ushort obj in PABCEntries) { bw.Write(obj); } - return ms.ToArray(); } } - } } \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs index e12ef1e..ec885fb 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PADC.cs @@ -1,10 +1,7 @@ -using System.IO; -using Warcraft.NET.Attribute; -using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.Interfaces; namespace Warcraft.NET.Files.M2.Chunks.Legion { - [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] public class PADC : IIFFChunk, IBinarySerializable { /// @@ -12,7 +9,11 @@ public class PADC : IIFFChunk, IBinarySerializable /// public const string Signature = "PADC"; - byte[] data; + /// + /// Gets or sets the ParentAnimationData (deserialization NYI) + /// + public byte[] Data; + /// /// Initializes a new instance of /// @@ -33,23 +34,13 @@ public PADC() { } /// public void LoadBinaryData(byte[] inData) { - using (var ms = new MemoryStream(inData)) - using (var br = new BinaryReader(ms)) - { - data = inData; - } + Data = inData; } /// public byte[] Serialize(long offset = 0) { - using (var ms = new MemoryStream()) - using (var bw = new BinaryWriter(ms)) - { - bw.Write(data); - - return ms.ToArray(); - } + return Data; } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs index 372973a..3881430 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PEDC.cs @@ -1,5 +1,4 @@ -using System.IO; -using Warcraft.NET.Attribute; +using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; namespace Warcraft.NET.Files.M2.Chunks.Legion @@ -12,7 +11,11 @@ public class PEDC : IIFFChunk, IBinarySerializable /// public const string Signature = "PEDC"; - byte[] data; + /// + /// Gets or sets the ParentEventData (deserialization NYI) + /// + public byte[] Data; + /// /// Initializes a new instance of /// @@ -33,23 +36,13 @@ public PEDC() { } /// public void LoadBinaryData(byte[] inData) { - using (var ms = new MemoryStream(inData)) - using (var br = new BinaryReader(ms)) - { - data = inData; - } + Data = inData; } /// public byte[] Serialize(long offset = 0) { - using (var ms = new MemoryStream()) - using (var bw = new BinaryWriter(ms)) - { - bw.Write(data); - - return ms.ToArray(); - } + return Data; } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PFID.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PFID.cs index f92f272..729142a 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/PFID.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PFID.cs @@ -61,4 +61,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PGD1.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PGD1.cs index 5502817..dba0ea2 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/PGD1.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PGD1.cs @@ -3,7 +3,6 @@ using System.IO; using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.M2.Entries; namespace Warcraft.NET.Files.M2.Chunks.Legion { @@ -16,9 +15,9 @@ public class PGD1 : IIFFChunk, IBinarySerializable public const string Signature = "PGD1"; /// - /// Gets or sets the Skin FileDataId + /// Gets or sets the ParticleGeosetData1 Entries /// - public List PGD1Entries = new(); + public List PGD1Entries = new(); /// /// Initializes a new instance of @@ -63,10 +62,8 @@ public byte[] Serialize(long offset = 0) { bw.Write(obj); } - return ms.ToArray(); } } - } } \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs index 9070431..570981b 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/PSBC.cs @@ -1,10 +1,8 @@ using System.IO; -using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; namespace Warcraft.NET.Files.M2.Chunks.Legion { - [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterWoD, AutoDocChunkVersionHelper.VersionBeforeLegion)] public class PSBC : IIFFChunk, IBinarySerializable { /// @@ -12,7 +10,11 @@ public class PSBC : IIFFChunk, IBinarySerializable /// public const string Signature = "PSBC"; - byte[] data; + /// + /// Gets or sets the ParentSequenceBounds (deserialization NYI) + /// + public byte[] Data; + /// /// Initializes a new instance of /// @@ -36,20 +38,14 @@ public void LoadBinaryData(byte[] inData) using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) { - data = inData; + Data = inData; } } /// public byte[] Serialize(long offset = 0) { - using (var ms = new MemoryStream()) - using (var bw = new BinaryWriter(ms)) - { - bw.Write(data); - - return ms.ToArray(); - } + return Data; } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/SFID.cs b/Warcraft.NET/Files/M2/Chunks/Legion/SFID.cs index bf6b4c3..90ff088 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/SFID.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/SFID.cs @@ -61,4 +61,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/SKID.cs b/Warcraft.NET/Files/M2/Chunks/Legion/SKID.cs index abcda1d..1908f10 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/SKID.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/SKID.cs @@ -51,9 +51,8 @@ public byte[] Serialize(long offset = 0) using (var bw = new BinaryWriter(ms)) { bw.Write(SkeletonFileDataId); - return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs b/Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs index a4bcd8e..3ffe3d4 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/TXAC.cs @@ -1,6 +1,7 @@ using System.IO; using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; +using System.Collections.Generic; namespace Warcraft.NET.Files.M2.Chunks.Legion { @@ -13,9 +14,12 @@ public class TXAC : IIFFChunk, IBinarySerializable public const string Signature = "TXAC"; /// - /// Gets or sets the Skin FileDataId + /// 2 byte array + /// From Wiki: + /// likely used in CM2SceneRender::SetupTextureTransforms and uploaded to the shader directly. 0 otherwise. + /// This chunk doesn't seem to be used directly. Inside CParticleEmitter2 class there are non-null checks that deal with selection of VertexBufferFormat for particles. Apart from that, the usage of these fields is unknown /// - public byte[] unk; + public List TXACEntries = new(); /// /// Initializes a new instance of @@ -40,7 +44,13 @@ public void LoadBinaryData(byte[] inData) using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) { - unk = br.ReadBytes((int)br.BaseStream.Length); + for (int i = 0; i < inData.Length / 2; i++) + { + var entry = new byte[2]; + entry[0] = br.ReadByte(); + entry[1] = br.ReadByte(); + TXACEntries.Add(entry); + } } } @@ -50,10 +60,12 @@ public byte[] Serialize(long offset = 0) using (var ms = new MemoryStream()) using (var bw = new BinaryWriter(ms)) { - bw.Write(unk); - + foreach (var entry in TXACEntries) + { + bw.Write(entry); + } return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs b/Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs index 7bf4c9e..912a6e0 100644 --- a/Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs +++ b/Warcraft.NET/Files/M2/Chunks/SL/DBOC.cs @@ -15,7 +15,7 @@ public class DBOC : IIFFChunk, IBinarySerializable public const string Signature = "DBOC"; /// - /// Gets or sets the Skin FileDataId + /// Gets or sets the DBOC Entries /// public List DBOCEntries = new(); @@ -24,7 +24,7 @@ public class DBOC : IIFFChunk, IBinarySerializable /// public DBOC() { } - /// + /// /// Initializes a new instance of /// /// ExtendedData. @@ -62,10 +62,8 @@ public byte[] Serialize(long offset = 0) { bw.Write(obj.Serialize()); } - return ms.ToArray(); } } - } } \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/DETL.cs b/Warcraft.NET/Files/M2/Chunks/SL/DETL.cs index d9fa1ed..6a477a0 100644 --- a/Warcraft.NET/Files/M2/Chunks/SL/DETL.cs +++ b/Warcraft.NET/Files/M2/Chunks/SL/DETL.cs @@ -15,7 +15,7 @@ public class DETL : IIFFChunk, IBinarySerializable public const string Signature = "DETL"; /// - /// Gets or sets the Skin FileDataId + /// Gets or sets the DETL Entries /// public List DETLEntries = new(); @@ -62,10 +62,8 @@ public byte[] Serialize(long offset = 0) { bw.Write(obj.Serialize()); } - return ms.ToArray(); } } - } } \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs b/Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs index d5a93d8..23634a1 100644 --- a/Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs +++ b/Warcraft.NET/Files/M2/Chunks/SL/EDGF.cs @@ -15,7 +15,7 @@ public class EDGF : IIFFChunk, IBinarySerializable public const string Signature = "EDGF"; /// - /// Gets or sets the Skin FileDataId + /// Gets or sets the EdgeFade Entries /// public List EDGFEntries = new(); @@ -62,10 +62,8 @@ public byte[] Serialize(long offset = 0) { bw.Write(obj.Serialize()); } - return ms.ToArray(); } } - } } \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/NERF.cs b/Warcraft.NET/Files/M2/Chunks/SL/NERF.cs index 8ebf09b..cdc76a2 100644 --- a/Warcraft.NET/Files/M2/Chunks/SL/NERF.cs +++ b/Warcraft.NET/Files/M2/Chunks/SL/NERF.cs @@ -3,7 +3,6 @@ using System.Numerics; using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.M2.Entries; namespace Warcraft.NET.Files.M2.Chunks.Legion { @@ -16,7 +15,7 @@ public class NERF : IIFFChunk, IBinarySerializable public const string Signature = "NERF"; /// - /// Gets or sets the Skin FileDataId + /// Gets or sets the NERF Entries /// public List NERFEntries = new(); @@ -64,10 +63,8 @@ public byte[] Serialize(long offset = 0) bw.Write(obj.X); bw.Write(obj.Y); } - return ms.ToArray(); } } - } } \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs b/Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs index f6ff583..5c8bb6b 100644 --- a/Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs +++ b/Warcraft.NET/Files/M2/Chunks/SL/PFDC.cs @@ -1,9 +1,7 @@ -using System.Collections.Generic; -using System.IO; +using System; using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.M2.Entries; -using Warcraft.NET.Files.phys; +using Warcraft.NET.Files.Phys; namespace Warcraft.NET.Files.M2.Chunks.SL { @@ -16,9 +14,9 @@ public class PFDC : IIFFChunk, IBinarySerializable public const string Signature = "PFDC"; /// - /// Gets or sets the Physics of the chunk + /// Gets or sets the Physics for the M2 /// - public Physics physics { get; set; } = null; + public Physics Physics { get; set; } = null; /// /// Initializes a new instance of @@ -40,24 +38,27 @@ public PFDC() { } /// public void LoadBinaryData(byte[] inData) { - using (var ms = new MemoryStream(inData)) - using (var br = new BinaryReader(ms)) - { - physics = new Physics(inData); - //convert inData into >physics< - } + Physics = new Physics(inData); } - /// + /// public byte[] Serialize(long offset = 0) { - using (var ms = new MemoryStream()) - using (var bw = new BinaryWriter(ms)) + return PadTo8Bytes(Physics.Serialize()); + } + + static byte[] PadTo8Bytes(byte[] input) + { + int paddingNeeded = 8 - (input.Length % 8); + if (paddingNeeded == 8) + paddingNeeded = 0; + byte[] paddedArray = new byte[input.Length + paddingNeeded]; + Array.Copy(input, paddedArray, input.Length); + for (int i = input.Length; i < paddedArray.Length; i++) { - bw.Write(physics.Serialize()); - //convert >physics< into byte[] - return ms.ToArray(); + paddedArray[i] = 0x00; } + return paddedArray; } } } \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Chunks/SL/WFV3.cs b/Warcraft.NET/Files/M2/Chunks/SL/WFV3.cs index 17ef33c..c37dd2a 100644 --- a/Warcraft.NET/Files/M2/Chunks/SL/WFV3.cs +++ b/Warcraft.NET/Files/M2/Chunks/SL/WFV3.cs @@ -15,7 +15,7 @@ public class WFV3 : IIFFChunk, IBinarySerializable public const string Signature = "WFV3"; /// - /// Gets or sets the Skin FileDataId + /// Gets or sets the WaterFallVersion3 Entries /// public List WFV3Entries = new(); @@ -62,10 +62,8 @@ public byte[] Serialize(long offset = 0) { bw.Write(obj.Serialize()); } - return ms.ToArray(); } } - } } \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/AFIDEntry.cs b/Warcraft.NET/Files/M2/Entries/AFIDEntry.cs index 31a0080..6c85f43 100644 --- a/Warcraft.NET/Files/M2/Entries/AFIDEntry.cs +++ b/Warcraft.NET/Files/M2/Entries/AFIDEntry.cs @@ -9,7 +9,6 @@ public class AFIDEntry /// public ushort AnimationId { get; set; } - /// /// Gets or sets the sub animation id. /// @@ -20,7 +19,6 @@ public class AFIDEntry /// public uint FileDataId { get; set; } - /// /// Initializes a new instance of the class. /// @@ -49,7 +47,7 @@ public AFIDEntry(byte[] data) /// The size. public static int GetSize() { - return 8; + return 16; } /// @@ -68,4 +66,4 @@ public byte[] Serialize(long offset = 0) } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/DBOCEntry.cs b/Warcraft.NET/Files/M2/Entries/DBOCEntry.cs index c8c04a1..58a8bf5 100644 --- a/Warcraft.NET/Files/M2/Entries/DBOCEntry.cs +++ b/Warcraft.NET/Files/M2/Entries/DBOCEntry.cs @@ -1,21 +1,30 @@ -using System; -using System.IO; +using System.IO; namespace Warcraft.NET.Files.M2.Entries { public class DBOCEntry { - public float unk_float1; - public float unk_float2; - public UInt32 unk_int1; - public UInt32 unk_int2; + /// + /// unknown float + /// + public float Unk0; + /// + /// unknown float + /// + public float Unk1; + /// + /// unknown int + /// + public uint Unk2; + /// + /// unknown int + /// + public uint Unk3; /// /// Initializes a new instance of the class. /// - public DBOCEntry() - { - } + public DBOCEntry(){} /// /// Initializes a new instance of the class. @@ -26,10 +35,10 @@ public DBOCEntry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - unk_float1 = br.ReadSingle(); - unk_float2 = br.ReadSingle(); - unk_int1 = br.ReadUInt32(); - unk_int2 = br.ReadUInt32(); + Unk0 = br.ReadSingle(); + Unk1 = br.ReadSingle(); + Unk2 = br.ReadUInt32(); + Unk3 = br.ReadUInt32(); } } @@ -49,14 +58,13 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write(unk_float1); - bw.Write(unk_float2); - bw.Write(unk_int1); - bw.Write(unk_int2); + bw.Write(Unk0); + bw.Write(Unk1); + bw.Write(Unk2); + bw.Write(Unk3); } - return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/DETLEntry.cs b/Warcraft.NET/Files/M2/Entries/DETLEntry.cs index cdbb8b3..da70cdc 100644 --- a/Warcraft.NET/Files/M2/Entries/DETLEntry.cs +++ b/Warcraft.NET/Files/M2/Entries/DETLEntry.cs @@ -1,15 +1,33 @@ -using System; -using System.IO; +using System.IO; namespace Warcraft.NET.Files.M2.Entries { public class DETLEntry { - public UInt16 flags; - public UInt16 packedFloat0; - public UInt16 packedFloat1; // multiplier for M2Light.diffuse_color - public UInt16 unk0; - public UInt32 unk1; + /// + /// unknown Flags + /// + public ushort Flags; + + /// + /// multiplier for M2Light.diffuse_color + /// + public ushort PackedFloat0; + + /// + /// multiplier for M2Light.diffuse_color + /// + public ushort PackedFloat1; + + /// + /// unknown field + /// + public ushort Unk0; + + /// + /// unknown field + /// + public uint Unk1; /// /// Initializes a new instance of the class. @@ -27,11 +45,11 @@ public DETLEntry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - flags = br.ReadUInt16(); - packedFloat0 = br.ReadUInt16(); - packedFloat1 = br.ReadUInt16(); - unk0 = br.ReadUInt16(); - unk1 = br.ReadUInt32(); + Flags = br.ReadUInt16(); + PackedFloat0 = br.ReadUInt16(); + PackedFloat1 = br.ReadUInt16(); + Unk0 = br.ReadUInt16(); + Unk1 = br.ReadUInt32(); } } @@ -51,15 +69,14 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write(flags); - bw.Write(packedFloat0); - bw.Write(packedFloat1); - bw.Write(unk0); - bw.Write(unk1); + bw.Write(Flags); + bw.Write(PackedFloat0); + bw.Write(PackedFloat1); + bw.Write(Unk0); + bw.Write(Unk1); } - return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/EDGFEntry.cs b/Warcraft.NET/Files/M2/Entries/EDGFEntry.cs index 5238753..346c50f 100644 --- a/Warcraft.NET/Files/M2/Entries/EDGFEntry.cs +++ b/Warcraft.NET/Files/M2/Entries/EDGFEntry.cs @@ -1,13 +1,23 @@ -using System; -using System.IO; +using System.IO; namespace Warcraft.NET.Files.M2.Entries { public class EDGFEntry { - public float[] _0x0; - public float _0x8; - public byte[] _0xC; + /// + /// unknown 2-floats array + /// + public float[] Unk0; + + /// + /// unknown float + /// + public float Unk1; + + /// + /// unknown 4 byte array + /// + public byte[] Unk2; /// /// Initializes a new instance of the class. @@ -25,11 +35,11 @@ public EDGFEntry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - _0x0 = new float[2]; - _0x0[0] = br.ReadSingle(); - _0x0[1] = br.ReadSingle(); - _0x8 = br.ReadSingle(); - _0xC = br.ReadBytes(4); + Unk0 = new float[2]; + Unk0[0] = br.ReadSingle(); + Unk0[1] = br.ReadSingle(); + Unk1 = br.ReadSingle(); + Unk2 = br.ReadBytes(4); } } @@ -49,14 +59,13 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write(_0x0[0]); - bw.Write(_0x0[1]); - bw.Write(_0x8); - bw.Write(_0xC); + bw.Write(Unk0[0]); + bw.Write(Unk0[1]); + bw.Write(Unk1); + bw.Write(Unk2); } - return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/EXPTEntry.cs b/Warcraft.NET/Files/M2/Entries/EXPTEntry.cs index 858929b..ece3be3 100644 --- a/Warcraft.NET/Files/M2/Entries/EXPTEntry.cs +++ b/Warcraft.NET/Files/M2/Entries/EXPTEntry.cs @@ -4,17 +4,23 @@ namespace Warcraft.NET.Files.M2.Entries { public class EXPTEntry { - public float zSource; - public float colorMult; - public float alphaMult; - + /// + /// replaces zSource from ParticleEmitter + /// + public float ZSource; + /// + /// colorMult is applied against particle's diffuse color + /// + public float ColorMult; + /// + ///alphaMult is applied against particle's opacity. + /// + public float AlphaMult; /// /// Initializes a new instance of the class. /// - public EXPTEntry() - { - } + public EXPTEntry() { } /// /// Initializes a new instance of the class. @@ -25,9 +31,9 @@ public EXPTEntry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - zSource = br.ReadSingle(); - colorMult = br.ReadSingle(); - alphaMult = br.ReadSingle(); + ZSource = br.ReadSingle(); + ColorMult = br.ReadSingle(); + AlphaMult = br.ReadSingle(); } } @@ -47,13 +53,12 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write(zSource); - bw.Write(colorMult); - bw.Write(alphaMult); + bw.Write(ZSource); + bw.Write(ColorMult); + bw.Write(AlphaMult); } - return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/LDV1Entry.cs b/Warcraft.NET/Files/M2/Entries/LDV1Entry.cs index e502496..007466f 100644 --- a/Warcraft.NET/Files/M2/Entries/LDV1Entry.cs +++ b/Warcraft.NET/Files/M2/Entries/LDV1Entry.cs @@ -1,16 +1,33 @@ -using System; -using System.IO; +using System.IO; namespace Warcraft.NET.Files.M2.Entries { public class LDV1Entry { - public UInt16 unk0; - public UInt16 lodCount; //maxLod = lodCount-1; - float unk2_f; - public byte[] particleBoneLod; //lod serves as indes into this array - public UInt32 unk4; + /// + /// unknown field + /// + public ushort Unk0; + + /// + /// the maximum lod count + /// + public ushort LodCount; + + /// + /// unknown field + /// + public float Unk1; + /// + /// lod serves as indes into this array + /// + public byte[] ParticleBoneLod; + + /// + /// unknown field + /// + public uint Unk2; /// /// Initializes a new instance of the class. @@ -28,11 +45,11 @@ public LDV1Entry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - unk0 = br.ReadUInt16(); - lodCount = br.ReadUInt16(); - unk2_f = br.ReadSingle(); - particleBoneLod = br.ReadBytes(4); - unk4 = br.ReadUInt32(); + Unk0 = br.ReadUInt16(); + LodCount = br.ReadUInt16(); + Unk1 = br.ReadSingle(); + ParticleBoneLod = br.ReadBytes(4); + Unk2 = br.ReadUInt32(); } } @@ -49,18 +66,15 @@ public static int GetSize() public byte[] Serialize(long offset = 0) { using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) { - using (var bw = new BinaryWriter(ms)) - { - bw.Write(unk0); - bw.Write(lodCount); - bw.Write(unk2_f); - bw.Write(particleBoneLod); - bw.Write(unk4); - } - + bw.Write(Unk0); + bw.Write(LodCount); + bw.Write(Unk1); + bw.Write(ParticleBoneLod); + bw.Write(Unk2); return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Entries/WFV3Entry.cs b/Warcraft.NET/Files/M2/Entries/WFV3Entry.cs index f8eb38a..12d0463 100644 --- a/Warcraft.NET/Files/M2/Entries/WFV3Entry.cs +++ b/Warcraft.NET/Files/M2/Entries/WFV3Entry.cs @@ -1,32 +1,115 @@ -using System; -using System.IO; +using System.IO; +using Warcraft.NET.Extensions; using Warcraft.NET.Files.Structures; namespace Warcraft.NET.Files.M2.Entries { public class WFV3Entry { - public float bumpScale; //Passed to vertex shader - public float value0_x; - public float value0_y; - public float value0_z; - public float value1_w; - public float value0_w; - public float value1_x; - public float value1_y; - public float value2_w; - public float value3_y; - public float value3_x; - public CImVector baseColor; // in rgba (not bgra) - public UInt16 flags; - public UInt16 unk0; - public float value3_w; - public float value3_z; - public float value4_y; - public float unk1; - public float unk2; - public float unk3; - public float unk4; + /// + /// BumpScale -> Passed to vertex shader + /// + public float BumpScale; + + /// + /// value 0 x + /// + public float Value0X; + + /// + /// value 0 y + /// + public float Value0Y; + + /// + /// value 0 z + /// + public float Value0Z; + + /// + /// value 1 W + /// + public float Value1W; + + /// + /// value 0 W + /// + public float Value0W; + + /// + /// value 1 x + /// + public float Value1X; + + /// + /// value 1 y + /// + public float Value1Y; + + /// + /// value 2 w + /// + public float Value2W; + + /// + /// value 3 y + /// + public float Value3Y; + + /// + /// value 3 x + /// + public float Value3X; + + /// + /// BaseColor in rgba (not bgra) + /// + public RGBA BaseColor; + + /// + /// unknown Flags + /// + public ushort Flags; + + /// + /// unknown field + /// + public ushort Unk0; + + /// + /// value 3 W + /// + public float Value3W; + + /// + /// value 3 Z + /// + public float Value3Z; + + /// + /// value 4 y + /// + public float Value4Y; + + /// + /// unknown field + /// + public float Unk1; + + /// + /// unknown field + /// + public float Unk2; + + /// + /// unknown field + /// + public float Unk3; + + /// + /// unknown field + /// + public float Unk4; /// /// Initializes a new instance of the class. @@ -44,34 +127,27 @@ public WFV3Entry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - bumpScale = br.ReadSingle(); - - value0_x = br.ReadSingle(); - value0_y = br.ReadSingle(); - value0_z = br.ReadSingle(); - value1_w = br.ReadSingle(); - - value0_w = br.ReadSingle(); - value1_x = br.ReadSingle(); - value1_y = br.ReadSingle(); - value2_w = br.ReadSingle(); - - value3_y = br.ReadSingle(); - value3_x = br.ReadSingle(); - - baseColor = new CImVector(br.ReadBytes(4)); - - flags = br.ReadUInt16(); - unk0 = br.ReadUInt16(); - - value3_w = br.ReadSingle(); - value3_z = br.ReadSingle(); - value4_y = br.ReadSingle(); - - unk1 = br.ReadSingle(); - unk2 = br.ReadSingle(); - unk3 = br.ReadSingle(); - unk4 = br.ReadSingle(); + BumpScale = br.ReadSingle(); + Value0X = br.ReadSingle(); + Value0Y = br.ReadSingle(); + Value0Z = br.ReadSingle(); + Value1W = br.ReadSingle(); + Value0W = br.ReadSingle(); + Value1X = br.ReadSingle(); + Value1Y = br.ReadSingle(); + Value2W = br.ReadSingle(); + Value3Y = br.ReadSingle(); + Value3X = br.ReadSingle(); + BaseColor = br.ReadRGBA(); + Flags = br.ReadUInt16(); + Unk0 = br.ReadUInt16(); + Value3W = br.ReadSingle(); + Value3Z = br.ReadSingle(); + Value4Y = br.ReadSingle(); + Unk1 = br.ReadSingle(); + Unk2 = br.ReadSingle(); + Unk3 = br.ReadSingle(); + Unk4 = br.ReadSingle(); } } @@ -90,39 +166,31 @@ public byte[] Serialize(long offset = 0) using (var ms = new MemoryStream()) { using (var bw = new BinaryWriter(ms)) - { - bw.Write(bumpScale); - - bw.Write(value0_x); - bw.Write(value0_y); - bw.Write(value0_z); - bw.Write(value1_w); - - bw.Write(value0_w); - bw.Write(value1_x); - bw.Write(value1_y); - bw.Write(value2_w); - - bw.Write(value3_y); - bw.Write(value3_x); - - bw.Write(baseColor.toBytes()); - - bw.Write(flags); - bw.Write(unk0); - - bw.Write(value3_w); - bw.Write(value3_z); - bw.Write(value4_y); - - bw.Write(unk1); - bw.Write(unk2); - bw.Write(unk3); - bw.Write(unk4); - } - + { + bw.Write(BumpScale); + bw.Write(Value0X); + bw.Write(Value0Y); + bw.Write(Value0Z); + bw.Write(Value1W); + bw.Write(Value0W); + bw.Write(Value1X); + bw.Write(Value1Y); + bw.Write(Value2W); + bw.Write(Value3Y); + bw.Write(Value3X); + bw.WriteRGBA(BaseColor); + bw.Write(Flags); + bw.Write(Unk0); + bw.Write(Value3W); + bw.Write(Value3Z); + bw.Write(Value4Y); + bw.Write(Unk1); + bw.Write(Unk2); + bw.Write(Unk3); + bw.Write(Unk4); + } return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/M2/Model.cs b/Warcraft.NET/Files/M2/Model.cs index fb75684..e92e642 100644 --- a/Warcraft.NET/Files/M2/Model.cs +++ b/Warcraft.NET/Files/M2/Model.cs @@ -10,7 +10,6 @@ namespace Warcraft.NET.Files.M2 [AutoDocFile("m2")] public class Model : ChunkedFile { - /// /// Gets or sets the model information /// @@ -18,127 +17,166 @@ public class Model : ChunkedFile public MD21 ModelInformation { get; set; } /// - /// Gets or sets the model phys file ids + /// Gets or sets the CParticleEmitter2 data /// - [ChunkOptional] - public PFID PhysFileIds { get; set; } + [ChunkOrder(2),ChunkOptional] + public TXAC CParticleEmitter2 { get; set; } /// - /// Gets or sets the model skin file ids + /// Gets or sets the ParentEventData /// - [ChunkOptional] - public SFID SkinFileIds { get; set; } + [ChunkOrder(3),ChunkOptional] + public PEDC M2InitParentEventData { get; set; } + + /// + /// Gets or sets the ExtendedParticle + /// + [ChunkOrder(4), ChunkOptional] + public EXPT ExtendedParticle { get; set; } + + /// + /// Gets or sets the ExtendedParticle2 + /// + [ChunkOrder(5),ChunkOptional] + public EXP2 ExtendedParticle2 { get; set; } + + /// + /// Gets or sets the ParticleGeosetData + /// + [ChunkOrder(6),ChunkOptional] + public PGD1 ParticleGeosetData { get; set; } /// /// Gets or sets the model anim file ids /// - [ChunkOptional] + [ChunkOrder(7), ChunkOptional] public AFID AnimFileIds { get; set; } /// /// Gets or sets the model bone file ids /// - [ChunkOptional] + [ChunkOrder(8), ChunkOptional] public BFID BoneFileIds { get; set; } - [ChunkOptional] - public TXAC CParticleEmitter2 { get; set; } - - [ChunkOptional] - public EXPT ExtendedParticle { get; set; } - - //[ChunkOptional] - //public EXP2 ExtendedParticle2 { get; set; } - - [ChunkOptional] - public PABC M2InitBlacklistAnimData { get; set; }//Unfinished - [ChunkOptional] - public PADC M2InitParentAnimData { get; set; } //Unfinished - [ChunkOptional] - public PSBC M2InitParentSequencyBoundsData { get; set; }//Unfinished - [ChunkOptional] - public PEDC M2InitParentEventData { get; set; }//Unfinished - /// - /// Gets or sets the model skeleton file ids + /// Gets or sets the BlacklistAnimData /// - [ChunkOptional] - public SKID SkeletonFileIds { get; set; } + [ChunkOrder(9), ChunkOptional] + public PABC M2InitBlacklistAnimData { get; set; } /// - /// Gets or sets the texture file ids + /// Gets or sets the LodDataVersion1 /// - [ChunkOptional] - public TXID TextureFileIds { get; set; } - - [ChunkOptional] + [ChunkOrder(10), ChunkOptional] public LDV1 LodDataVersion1 { get; set; } /// - /// Gets or sets the model recursive particle file ids + /// Gets or sets the EdgeFade /// - [ChunkOptional] - public RPID RecursiveParticleFileIds { get; set; } + [ChunkOrder(11), ChunkOptional] + public EDGF EdgeFade { get; set; } /// - /// Gets or sets the model geometry particle file ids + /// Gets or sets the Physics of the M2 /// - [ChunkOptional] - public GPID GeometryParticleFileIds { get; set; } + [ChunkOrder(12),ChunkOptional] + public PFDC ModelPhysics { get; set; } - [ChunkOptional] + /// + /// Gets or sets the model skeleton file ids + /// + [ChunkOrder(13), ChunkOptional] + public SKID SkeletonFileIds { get; set; } + + /// + /// Gets or sets the WaterFallVersion1 + /// + [ChunkOrder(14),ChunkOptional] public WFV1 WaterFallVersion1 { get; set; } - [ChunkOptional] + /// + /// Gets or sets the WaterFallVersion2 + /// + [ChunkOrder(15),ChunkOptional] public WFV2 WaterFallVersion2 { get; set; } - [ChunkOptional] - public PGD1 ParticleGeosetData { get; set; } - - [ChunkOptional] + /// + /// Gets or sets the WaterFallVersion3 + /// + [ChunkOrder(16),ChunkOptional] public WFV3 WaterFallVersion3 { get; set; } /// - /// Gets or sets the model physics + /// Gets or sets the DBOC /// - [ChunkOptional] - public PFDC ModelPhysics { get; set; } - - [ChunkOptional] - public EDGF EdgeFade { get; set; } - - [ChunkOptional] - public NERF NERF { get; set; } - - [ChunkOptional] - public DETL DETL { get; set; } - - [ChunkOptional] + [ChunkOrder(17), ChunkOptional] public DBOC DBOC { get; set; } - [ChunkOptional] - public AFRA AFRA { get; set; } - - - - - + /// + /// Gets or sets the model skin file ids + /// + [ChunkOrder(18), ChunkOptional] + public SFID SkinFileIds { get; set; } + /// + /// Gets or sets the model phys file ids + /// + [ChunkOrder(19), ChunkOptional] + public PFID PhysFileIds { get; set; } + /// + /// Gets or sets the model texture file ids + /// + [ChunkOrder(20), ChunkOptional] + public TXID TextureFileIds { get; set; } + /// + /// Gets or sets the ParentSequenceBoundsData + /// + [ChunkOrder(21),ChunkOptional] + public PSBC M2InitParentSequenceBoundsData { get; set; } + /// + /// Gets or sets the model recursive particle file ids + /// + [ChunkOrder(22), ChunkOptional] + public RPID RecursiveParticleFileIds { get; set; } + /// + /// Gets or sets the model geometry particle file ids + /// + [ChunkOrder(23), ChunkOptional] + public GPID GeometryParticleFileIds { get; set; } + /// + /// Gets or sets the ParentAnimData + /// + [ChunkOrder(24),ChunkOptional] + public PADC M2InitParentAnimData { get; set; } + /// + /// Gets or sets the NERF + /// + [ChunkOrder(25),ChunkOptional] + public NERF NERF { get; set; } + /// + /// Gets or sets the DETL (light related) + /// + [ChunkOrder(26),ChunkOptional] + public DETL DETL { get; set; } + /// + /// Gets or sets the AFRA + /// + [ChunkOrder(27),ChunkOptional] + public AFRA AFRA { get; set; } /// /// Initializes a new instance of the class. /// public Model() { - } /// @@ -147,7 +185,6 @@ public Model() /// The binary data. public Model(byte[] inData) : base(inData) { - } public override bool IsReverseSignature() diff --git a/Warcraft.NET/Files/SKIN/Skin.cs b/Warcraft.NET/Files/SKIN/Skin.cs index 5220d18..58d2c95 100644 --- a/Warcraft.NET/Files/SKIN/Skin.cs +++ b/Warcraft.NET/Files/SKIN/Skin.cs @@ -1,33 +1,60 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; -using System.Linq; using Warcraft.NET.Attribute; using Warcraft.NET.Extensions; -using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.phys.Chunks; using Warcraft.NET.Files.Structures; -namespace Warcraft.NET.Files.SKIN +namespace Warcraft.NET.Files.Skin { [AutoDocFile("skin")] public class Skin { - public List Vertices{ get; set; } //index into M2s vertex list with offset - public List Triangles { get; set; } //3 indices per entry into vertices - public List BoneIndices { get; set; } + /// + /// The list of Vertices used for this skin + /// indexed into M2s vertex list with offset 'GlobalVertexOffset' + /// + public List Vertices { get; set; } + + /// + /// the triangles used for this skin (Right Handed) + /// indexed into the local list of vertices + /// + public List Triangles { get; set; } + + /// + /// the bones used for this skin. + /// indexed into the bone lookup table of the m2 + /// + public List BoneIndices { get; set; } + + /// + /// the submeshes used for this skin + /// public List Submeshes { get; set; } + + /// + /// the texture units used for this skin. + /// public List TextureUnits { get; set; } - public UInt32 globalVertexOffset; //start offset into M2.Vertices -> something else in wotlk + /// + /// start offset into M2.Vertices -> something else in wotlk + /// + public uint GlobalVertexOffset; + /// + /// the shadowbatches used in this skin + /// public List ShadowBatches; - - public byte[] unk0; //Padding? - public bool wotlk = false; + /// + /// unknown field. Maybe padding? + /// + public byte[] Unk0; + + public bool Wotlk = false; - public Skin(byte[] inData) + public Skin(byte[] inData) { using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) @@ -39,7 +66,7 @@ public Skin(byte[] inData) var ofsIndices = br.ReadUInt32(); if (ofsVertices == 48) { - wotlk = true; + Wotlk = true; } var nBones = br.ReadUInt32(); var ofsBones = br.ReadUInt32(); @@ -47,21 +74,20 @@ public Skin(byte[] inData) var ofsSubmeshes = br.ReadUInt32(); var nBatches = br.ReadUInt32(); var ofsBatches = br.ReadUInt32(); - globalVertexOffset = br.ReadUInt32(); + GlobalVertexOffset = br.ReadUInt32(); ShadowBatches = new List(); - unk0 = new byte[8]; - if (!wotlk) + Unk0 = new byte[8]; + if (!Wotlk) { var nShadow_batches = br.ReadUInt32(); var ofsShadow_batches = br.ReadUInt32(); - unk0 = br.ReadBytes(8); + Unk0 = br.ReadBytes(8); ShadowBatches = ReadStructList(nShadow_batches, ofsShadow_batches, br); } - Vertices = ReadStructList(nVertices, ofsVertices, br); - Triangles = ReadStructList(nIndices/3, ofsIndices, br); - BoneIndices = ReadStructList(nBones, ofsBones, br); + Triangles = ReadStructList(nIndices / 3, ofsIndices, br); + BoneIndices = ReadStructList(nBones, ofsBones, br); Submeshes = ReadStructList(nSubmeshes, ofsSubmeshes, br); TextureUnits = ReadStructList(nBatches, ofsBatches, br); @@ -83,54 +109,54 @@ public byte[] Serialize(long offset = 0) using (var ms = new MemoryStream()) using (var bw = new BinaryWriter(ms)) { - bw.Write(new byte[64]); //placeholder header + //Writing Empty Header -> Filling with data after writing the data + if (Wotlk) + { + bw.Write(new byte[48]); + } + else + { + bw.Write(new byte[64]); + } + foreach (ushort vertex in Vertices) { bw.Write(vertex); } - int _ofsTriangles = (int)bw.BaseStream.Position; foreach (M2Triangle triangle in Triangles) { bw.WriteStruct(triangle); } - int _ofsBones = (int)bw.BaseStream.Position; - foreach (BoneStruct bone in BoneIndices) + foreach (M2SkinBoneStruct bone in BoneIndices) { bw.WriteStruct(bone); - } - int _ofsSubmeshes = (int)bw.BaseStream.Position; foreach (M2SkinSection submesh in Submeshes) { bw.WriteStruct(submesh); } - int _ofsTexUnits = (int)bw.BaseStream.Position; foreach (M2Batch texUnit in TextureUnits) { bw.WriteStruct(texUnit); } - + int _ofsShadowBatches = (int)bw.BaseStream.Position; - if (!wotlk) { + if (!Wotlk) + { foreach (M2ShadowBatch shadowBatch in ShadowBatches) { bw.WriteStruct(shadowBatch); } } - - - - - - //Writing header + //Writing actual header data bw.BaseStream.Position = 0; bw.Write('S'); bw.Write('K'); @@ -139,32 +165,30 @@ public byte[] Serialize(long offset = 0) bw.Write(Vertices.Count); var _ofsVertices = 64; - if (wotlk) + if (Wotlk) _ofsVertices = 48; - bw.Write(_ofsVertices); - - bw.Write(Triangles.Count*3); + bw.Write(_ofsVertices); + + bw.Write(Triangles.Count * 3); bw.Write(_ofsTriangles); bw.Write(BoneIndices.Count); bw.Write(_ofsBones); bw.Write(Submeshes.Count); - bw.Write(_ofsSubmeshes); - + bw.Write(_ofsSubmeshes); + bw.Write(TextureUnits.Count); - bw.Write(_ofsTexUnits); - - bw.Write(globalVertexOffset); + bw.Write(_ofsTexUnits); + + bw.Write(GlobalVertexOffset); - if (!wotlk) - { + if (!Wotlk) + { bw.Write(ShadowBatches.Count); bw.Write(_ofsShadowBatches); - bw.Write(unk0); + bw.Write(Unk0); } - - return ms.ToArray(); } } @@ -174,21 +198,7 @@ public uint GetSize() { return (uint)Serialize().Length; } - - /* - public byte[] addPadding(byte[] bytes, int size) - { - // Calculate padding - int paddingSize = (4 - (size % 4)) % 4; - byte[] paddedBytes = new byte[size + paddingSize]; - Array.Copy(bytes, paddedBytes, size); - return paddedBytes; - } - */ - } - - } diff --git a/Warcraft.NET/Files/Structures/M2Batch.cs b/Warcraft.NET/Files/Structures/M2Batch.cs new file mode 100644 index 0000000..37040e8 --- /dev/null +++ b/Warcraft.NET/Files/Structures/M2Batch.cs @@ -0,0 +1,73 @@ +namespace Warcraft.NET.Files.Structures +{ + public struct M2Batch + { + /// + /// Texture Flags + /// Usually 16 for static textures, and 0 for animated textures. &0x1: materials invert something; &0x2: transform &0x4: projected texture; &0x10: something batch compatible; &0x20: projected texture?; &0x40: possibly don't multiply transparency by texture weight transparency to get final transparency value(?) + /// + public byte Flags; + + /// + /// Priority Plane + /// + public sbyte PriorityPlane; + + /// + /// ShaderID + /// negative = direct selection + /// positive = selection trough a function. See wiki for more information + /// + public ushort ShaderId; + + /// + /// A duplicate entry of a submesh from the list above. + /// + public ushort SkinSectionIndex; + + /// + /// New name: flags2. 0x2 - projected. 0x8 - EDGF chunk in m2 is mandatory and data from is applied to this mesh + /// + public ushort GeosetIndex; + + /// + /// A Color out of the Colors-Block or -1 if none. + /// + public ushort ColorIndex; + + /// + /// The renderflags used on this texture-unit. Index into M2 Materials + /// + public ushort MaterialIndex; + + /// + /// Capped at 7 (CM2Scene::BeginDraw) + /// + public ushort MaterialLayer; + + /// + /// 1 to 4. See below. Also seems to be the number of textures to load, starting at the texture lookup in the next field (0x10). + /// + public ushort TextureCount; + + /// + /// Index into Texture lookup table + /// + public ushort TextureComboIndex; + + /// + /// Index into the texture mapping lookup table. + /// + public ushort TextureCoordComboIndex; + + /// + /// Index into transparency lookup table. + /// + public ushort TextureWeightComboIndex; + + /// + /// Index into uvanimation lookup table. + /// + public ushort TextureTransformComboIndex; + } +} diff --git a/Warcraft.NET/Files/Structures/M2ShadowBatch.cs b/Warcraft.NET/Files/Structures/M2ShadowBatch.cs new file mode 100644 index 0000000..db25b23 --- /dev/null +++ b/Warcraft.NET/Files/Structures/M2ShadowBatch.cs @@ -0,0 +1,41 @@ +namespace Warcraft.NET.Files.Structures +{ + public struct M2ShadowBatch + { + /// + /// if auto-generated: M2Batch.Flags & 0xFF + /// + public byte Flags; + + /// + /// gets auto generated if certain flags in TextureUnit are set + /// See wiki for more information + /// + public byte Flags2; + + /// + /// unknown field + /// + public ushort Unk1; + + /// + /// same as TextureUnit + /// + public ushort SubmeshId; + + /// + /// same as TextureUnit + /// + public ushort TextureId; // already looked-up + + /// + /// same as TextureUnit + /// + public ushort ColorId; + + /// + /// same as TextureUnit + /// + public ushort TransparencyId; // already looked-up + } +} diff --git a/Warcraft.NET/Files/Structures/M2SkinBoneStruct.cs b/Warcraft.NET/Files/Structures/M2SkinBoneStruct.cs new file mode 100644 index 0000000..6f813ee --- /dev/null +++ b/Warcraft.NET/Files/Structures/M2SkinBoneStruct.cs @@ -0,0 +1,25 @@ +namespace Warcraft.NET.Files.Structures +{ + public struct M2SkinBoneStruct + { + /// + /// Bone 1 Index into BoneLookupTable from M2. see wiki for exact calculation + /// + public byte Bone1ID; + + /// + /// Bone 2 Index into BoneLookupTable from M2. see wiki for exact calculation + /// + public byte Bone2ID; + + /// + /// Bone 3 Index into BoneLookupTable from M2. see wiki for exact calculation + /// + public byte Bone3ID; + + /// + /// Bone 4 Index into BoneLookupTable from M2. see wiki for exact calculation + /// + public byte Bone4ID; + } +} diff --git a/Warcraft.NET/Files/Structures/M2SkinSection.cs b/Warcraft.NET/Files/Structures/M2SkinSection.cs new file mode 100644 index 0000000..cbd4b55 --- /dev/null +++ b/Warcraft.NET/Files/Structures/M2SkinSection.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using System.Text; + +namespace Warcraft.NET.Files.Structures +{ + public struct M2SkinSection + { + /// + /// Mesh part ID, see wiki for exact calculation + /// + public ushort SkinSectionId; + + /// + /// (level << 16) is added (|ed) to startTriangle and alike to avoid having to increase those fields to uint32s. + /// + public ushort Level; + + /// + /// Starting Vertex. Index into local vertex list + /// + public ushort VertexStart; + + /// + /// Number of Vertices taken from local vertex list + /// + public ushort VertexCount; + + /// + /// Starting triangle index. + /// + public ushort IndexStart; + + /// + /// Number of triangle indices. + /// + public ushort IndexCount; + + /// + /// Number of elements in the bone lookup table. Max seems to be 256 in Wrath. Shall be ≠ 0. + /// + public ushort BoneCount; + + /// + /// Starting index in the bone lookup table. + /// + public ushort BoneComboIndex; + + /// + /// <= 4 + /// from <=BC documentation: Highest number of bones needed at one time in this Submesh --Tinyn (wowdev.org) + /// In 2.x this is the amount of of bones up the parent-chain affecting the submesh --NaK + /// Highest number of bones referenced by a vertex of this submesh. 3.3.5a and suspectedly all other client revisions. -- Skarn + /// + public ushort BoneInfluences; + + /// + /// Index of the center bone + /// + public ushort CenterBoneIndex; + + /// + /// Average position of all the vertices in the sub mesh. + /// + public Vector3 CenterPosition; + + //≥BC + /// + /// The center of the box when an axis aligned box is built around the vertices in the submesh. + /// + public Vector3 SortCenterPosition; + + /// + /// Distance of the vertex farthest from CenterBoundingBox. + /// + public float SortRadius; + } +} diff --git a/Warcraft.NET/Files/Structures/M2Triangle.cs b/Warcraft.NET/Files/Structures/M2Triangle.cs new file mode 100644 index 0000000..639055d --- /dev/null +++ b/Warcraft.NET/Files/Structures/M2Triangle.cs @@ -0,0 +1,25 @@ +namespace Warcraft.NET.Files.Structures +{ + /// + /// Triangle read from skin. + /// Default = Right Handed + /// To make it left handed, swap the second and third vertex + /// + public struct M2Triangle + { + /// + /// the first vertex of the Triangle + /// + public ushort Vertex1; + + /// + /// the second vertex of the Triangle + /// + public ushort Vertex2; + + /// + /// the third vertex of the Triangle + /// + public ushort Vertex3; + } +} diff --git a/Warcraft.NET/Files/Structures/Matrix3x4.cs b/Warcraft.NET/Files/Structures/Matrix3x4.cs new file mode 100644 index 0000000..7c6e0d6 --- /dev/null +++ b/Warcraft.NET/Files/Structures/Matrix3x4.cs @@ -0,0 +1,68 @@ +using System.Collections.Generic; +using Warcraft.NET.Files.Interfaces; +using System.Numerics; + +public class Matrix3x4 : IFlattenableData +{ + /// + /// The directional vector 'right' + /// + public Vector3 RotationX { get; set; } + + /// + /// The directional vector 'up' + /// + public Vector3 RotationY { get; set; } + + /// + /// The directional vector 'forward' + /// + public Vector3 RotationZ { get; set; } + + /// + /// The scale of the matrix + /// + public Vector3 Scale { get; set; } + + /// + /// The position of the matrix + /// + public Vector3 Position { get; set; } + + public Matrix3x4 (Vector3 column1, Vector3 column2, Vector3 column3, Vector3 column4) + { + float scaleX = column1.Length(); + float scaleY = column2.Length(); + float scaleZ = column3.Length(); + + RotationX = column1 / scaleX; + RotationY = column2 / scaleY; + RotationZ = column3 / scaleZ; + + Scale = new Vector3(scaleX, scaleY, scaleZ); + Position = column4; + } + + public Vector3 GetForward() + { + return Vector3.Normalize(RotationZ); + } + + public Vector3 GetUp() + { + return Vector3.Normalize(RotationY); + } + + public Vector3 GetRight() + { + return Vector3.Normalize(RotationX); + } + + public IReadOnlyCollection Flatten() + { + return new[] { + GetForward().X,GetForward().Y,GetForward().Z, + Scale.X, Scale.Y, Scale.Z, + Position.X, Position.Y, Position.Z }; + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Chunks/BDY4.cs b/Warcraft.NET/Files/phys/Chunks/BDY4.cs index ef7a3bd..7f90e83 100644 --- a/Warcraft.NET/Files/phys/Chunks/BDY4.cs +++ b/Warcraft.NET/Files/phys/Chunks/BDY4.cs @@ -2,9 +2,9 @@ using System.IO; using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.phys.Entries; +using Warcraft.NET.Files.Phys.Entries; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class BDY4 : IIFFChunk, IBinarySerializable @@ -15,9 +15,9 @@ public class BDY4 : IIFFChunk, IBinarySerializable public const string Signature = "BDY4"; /// - /// Gets or Sets the version of the physics + /// Gets or Sets the used rigidbodies(V4) /// - public List bdy4Entries = new(); + public List BDY4Entries = new(); /// /// Initializes a new instance of @@ -46,7 +46,7 @@ public void LoadBinaryData(byte[] inData) for (var i = 0; i < bdy4count; ++i) { - bdy4Entries.Add(new BDY4Entry(br.ReadBytes(BDY4Entry.GetSize()))); + BDY4Entries.Add(new BDY4Entry(br.ReadBytes(BDY4Entry.GetSize()))); } } } @@ -57,13 +57,12 @@ public byte[] Serialize(long offset = 0) using (var ms = new MemoryStream()) using (var bw = new BinaryWriter(ms)) { - foreach (BDY4Entry obj in bdy4Entries) + foreach (BDY4Entry obj in BDY4Entries) { bw.Write(obj.Serialize()); } return ms.ToArray(); } } - } } diff --git a/Warcraft.NET/Files/phys/Chunks/BOXS.cs b/Warcraft.NET/Files/phys/Chunks/BOXS.cs index b4e2c87..98128a9 100644 --- a/Warcraft.NET/Files/phys/Chunks/BOXS.cs +++ b/Warcraft.NET/Files/phys/Chunks/BOXS.cs @@ -1,12 +1,10 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.phys.Entries; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Files.Phys.Entries; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class BOXS : IIFFChunk, IBinarySerializable @@ -16,9 +14,11 @@ public class BOXS : IIFFChunk, IBinarySerializable /// public const string Signature = "BOXS"; + /// + /// sets or gets the box shapes + /// public List BOXSEntries = new(); - /// /// Initializes a new instance of /// @@ -62,7 +62,6 @@ public byte[] Serialize(long offset = 0) bw.Write(obj.Serialize()); } return ms.ToArray(); - } } } diff --git a/Warcraft.NET/Files/phys/Chunks/CAPS.cs b/Warcraft.NET/Files/phys/Chunks/CAPS.cs index d7286e4..26fab82 100644 --- a/Warcraft.NET/Files/phys/Chunks/CAPS.cs +++ b/Warcraft.NET/Files/phys/Chunks/CAPS.cs @@ -1,12 +1,10 @@ using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.Structures; using System.Collections.Generic; -using Warcraft.NET.Files.phys.Entries; +using Warcraft.NET.Files.Phys.Entries; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class CAPS : IIFFChunk, IBinarySerializable @@ -16,9 +14,11 @@ public class CAPS : IIFFChunk, IBinarySerializable /// public const string Signature = "CAPS"; + /// + /// sets or gets the capsule shapes + /// public List CAPSEntries = new(); - /// /// Initializes a new instance of /// @@ -63,8 +63,6 @@ public byte[] Serialize(long offset = 0) } return ms.ToArray(); } - - } } } diff --git a/Warcraft.NET/Files/phys/Chunks/DSTJ.cs b/Warcraft.NET/Files/phys/Chunks/DSTJ.cs index 63731a9..32db762 100644 --- a/Warcraft.NET/Files/phys/Chunks/DSTJ.cs +++ b/Warcraft.NET/Files/phys/Chunks/DSTJ.cs @@ -1,12 +1,10 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.phys.Entries; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Files.Phys.Entries; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class DSTJ : IIFFChunk, IBinarySerializable @@ -16,6 +14,9 @@ public class DSTJ : IIFFChunk, IBinarySerializable /// public const string Signature = "DSTJ"; + /// + /// sets or gets the distance joints + /// public List DSTJEntries = new(); /// @@ -62,8 +63,6 @@ public byte[] Serialize(long offset = 0) } return ms.ToArray(); } - - } } } diff --git a/Warcraft.NET/Files/phys/Chunks/JOIN.cs b/Warcraft.NET/Files/phys/Chunks/JOIN.cs index 94330a0..d378ac3 100644 --- a/Warcraft.NET/Files/phys/Chunks/JOIN.cs +++ b/Warcraft.NET/Files/phys/Chunks/JOIN.cs @@ -1,12 +1,10 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.phys.Entries; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Files.Phys.Entries; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class JOIN : IIFFChunk, IBinarySerializable @@ -16,6 +14,9 @@ public class JOIN : IIFFChunk, IBinarySerializable /// public const string Signature = "JOIN"; + /// + /// sets or gets the joints + /// public List JOINEntries = new(); /// @@ -42,7 +43,6 @@ public void LoadBinaryData(byte[] inData) using (var br = new BinaryReader(ms)) { var JOINcount = br.BaseStream.Length / JOINEntry.GetSize(); - for (var i = 0; i < JOINcount; ++i) { JOINEntries.Add(new JOINEntry(br.ReadBytes(JOINEntry.GetSize()))); @@ -62,8 +62,6 @@ public byte[] Serialize(long offset = 0) } return ms.ToArray(); } - - } } } diff --git a/Warcraft.NET/Files/phys/Chunks/PHYS.cs b/Warcraft.NET/Files/phys/Chunks/PHYS.cs index 4f98688..7226e29 100644 --- a/Warcraft.NET/Files/phys/Chunks/PHYS.cs +++ b/Warcraft.NET/Files/phys/Chunks/PHYS.cs @@ -2,7 +2,7 @@ using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class PHYS : IIFFChunk, IBinarySerializable @@ -15,7 +15,7 @@ public class PHYS : IIFFChunk, IBinarySerializable /// /// Gets or Sets the version of the physics /// - public ushort version; + public ushort Version; /// /// Initializes a new instance of @@ -40,7 +40,7 @@ public void LoadBinaryData(byte[] inData) using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) { - version = br.ReadUInt16(); + Version = br.ReadUInt16(); } } @@ -50,7 +50,7 @@ public byte[] Serialize(long offset = 0) using (var ms = new MemoryStream()) using (var bw = new BinaryWriter(ms)) { - bw.Write(version); + bw.Write(Version); return ms.ToArray(); } } diff --git a/Warcraft.NET/Files/phys/Chunks/PHYT.cs b/Warcraft.NET/Files/phys/Chunks/PHYT.cs index 9d0e48e..7e2d5c7 100644 --- a/Warcraft.NET/Files/phys/Chunks/PHYT.cs +++ b/Warcraft.NET/Files/phys/Chunks/PHYT.cs @@ -2,7 +2,7 @@ using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class PHYT : IIFFChunk, IBinarySerializable @@ -13,9 +13,9 @@ public class PHYT : IIFFChunk, IBinarySerializable public const string Signature = "PHYT"; /// - /// Gets or Sets the version of the physics + /// Gets or Sets PHYT (unknown) /// - public uint phyt; + public uint Phyt = 0; /// /// Initializes a new instance of @@ -40,7 +40,7 @@ public void LoadBinaryData(byte[] inData) using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) { - phyt = br.ReadUInt32(); + Phyt = br.ReadUInt32(); } } @@ -50,7 +50,7 @@ public byte[] Serialize(long offset = 0) using (var ms = new MemoryStream()) using (var bw = new BinaryWriter(ms)) { - bw.Write(phyt); + bw.Write(Phyt); return ms.ToArray(); } } diff --git a/Warcraft.NET/Files/phys/Chunks/PHYV.cs b/Warcraft.NET/Files/phys/Chunks/PHYV.cs index 5d22e0b..690428a 100644 --- a/Warcraft.NET/Files/phys/Chunks/PHYV.cs +++ b/Warcraft.NET/Files/phys/Chunks/PHYV.cs @@ -1,10 +1,8 @@ -using System.Collections.Generic; -using System.IO; +using System.IO; using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.phys.Entries; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class PHYV : IIFFChunk, IBinarySerializable @@ -15,9 +13,9 @@ public class PHYV : IIFFChunk, IBinarySerializable public const string Signature = "PHYV"; /// - /// Gets or Sets the version of the physics + /// Gets or Sets the PHYV (unknown) /// - public float[] values; + public float[] Values; /// /// Initializes a new instance of @@ -43,15 +41,15 @@ public void LoadBinaryData(byte[] inData) using (var br = new BinaryReader(ms)) { var PHYVcount = br.BaseStream.Length / 24; - values = new float[PHYVcount * 6]; + Values = new float[PHYVcount * 6]; for (var i = 0; i < PHYVcount; ++i) { - values[i] = br.ReadSingle(); - values[i+1] = br.ReadSingle(); - values[i+2] = br.ReadSingle(); - values[i+3] = br.ReadSingle(); - values[i+4] = br.ReadSingle(); - values[i+5] = br.ReadSingle(); + Values[i] = br.ReadSingle(); + Values[i+1] = br.ReadSingle(); + Values[i+2] = br.ReadSingle(); + Values[i+3] = br.ReadSingle(); + Values[i+4] = br.ReadSingle(); + Values[i+5] = br.ReadSingle(); } } } @@ -62,13 +60,12 @@ public byte[] Serialize(long offset = 0) using (var ms = new MemoryStream()) using (var bw = new BinaryWriter(ms)) { - foreach (float f in values) + foreach (float f in Values) { bw.Write(f); } return ms.ToArray(); } } - } } diff --git a/Warcraft.NET/Files/phys/Chunks/PLYT.cs b/Warcraft.NET/Files/phys/Chunks/PLYT.cs index d3d9418..12fd612 100644 --- a/Warcraft.NET/Files/phys/Chunks/PLYT.cs +++ b/Warcraft.NET/Files/phys/Chunks/PLYT.cs @@ -2,12 +2,10 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.phys.Entries; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Files.Phys.Entries; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class PLYT : IIFFChunk, IBinarySerializable @@ -17,6 +15,9 @@ public class PLYT : IIFFChunk, IBinarySerializable /// public const string Signature = "PLYT"; + /// + /// sets or gets the polytope shapes + /// public List PLYTEntries = new(); /// @@ -42,55 +43,16 @@ public void LoadBinaryData(byte[] inData) using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) { - - var PLYTcount = br.ReadUInt32(); - - for (var i = 0; i < PLYTcount; ++i) + var plyt_count = br.ReadUInt32(); + for (var i = 0; i < plyt_count; i++) { - PLYTEntry plyt_entry = new PLYTEntry - { - header = new PLYTEntry.PLYT_HEADER - { - vertexCount = br.ReadUInt32(), - unk_04 = br.ReadBytes(4), - RUNTIME_08_ptr_data_0 = br.ReadUInt64(), - count_10 = br.ReadUInt32(), - unk_14 = br.ReadBytes(4), - RUNTIME_18_ptr_data_1 = br.ReadUInt64(), - RUNTIME_20_ptr_data_2 = br.ReadUInt64(), - nodeCount = br.ReadUInt32(), - unk_2C = br.ReadBytes(4), - RUNTIME_30_ptr_data_3 = br.ReadUInt64(), - unk_38 = new float[6] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle() } - } - }; - + PLYTEntry plyt_entry = new PLYTEntry(br.ReadBytes(80)); PLYTEntries.Add(plyt_entry); } - for (var j = 0; j < PLYTcount; j++) + for (var j = 0; j < plyt_count; j++) { - PLYTEntry entry = PLYTEntries[j]; - uint vcount = entry.header.vertexCount; - uint count_10 = entry.header.count_10; - uint nodeCount = entry.header.nodeCount; - - entry.data.vertices = new C3Vector[vcount]; - for (int v = 0; v < vcount; v++) - { - entry.data.vertices[v] = new C3Vector(br.ReadBytes(12)); - } - entry.data.unk1 = br.ReadBytes((int)count_10 * 16); - entry.data.unk2 = br.ReadBytes((int)count_10); - entry.data.nodes = new PLYTEntry.NODE[nodeCount]; - for (int n = 0; n < nodeCount; n++) - { - PLYTEntry.NODE node = new PLYTEntry.NODE(); - node.unk = br.ReadByte(); - node.vertexIndex = br.ReadByte(); - node.unkIndex0 = br.ReadByte(); - node.unkIndex1 = br.ReadByte(); - entry.data.nodes[n] = node; - } + PLYTEntry plyt_entry = PLYTEntries[j]; + plyt_entry.DeserializeData(br.ReadBytes(plyt_entry.DataSize)); } } } @@ -101,10 +63,10 @@ public byte[] Serialize(long offset = 0) using (var ms = new MemoryStream()) using (var bw = new BinaryWriter(ms)) { - bw.Write((UInt32)PLYTEntries.Count); + bw.Write((uint)PLYTEntries.Count); foreach (PLYTEntry obj in PLYTEntries) { - Console.WriteLine("Writing Plyt Header Length: "+ obj.SerializeHeader().Length); + Console.WriteLine("Writing Plyt Header Length: " + obj.SerializeHeader().Length); bw.Write(obj.SerializeHeader()); } foreach (PLYTEntry obj in PLYTEntries) @@ -114,8 +76,6 @@ public byte[] Serialize(long offset = 0) } return ms.ToArray(); } - - } } } diff --git a/Warcraft.NET/Files/phys/Chunks/PRS2.cs b/Warcraft.NET/Files/phys/Chunks/PRS2.cs index 1c4feb3..7d1e742 100644 --- a/Warcraft.NET/Files/phys/Chunks/PRS2.cs +++ b/Warcraft.NET/Files/phys/Chunks/PRS2.cs @@ -1,12 +1,10 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.phys.Entries; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Files.Phys.Entries; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class PRS2 : IIFFChunk, IBinarySerializable @@ -16,6 +14,9 @@ public class PRS2 : IIFFChunk, IBinarySerializable /// public const string Signature = "PRS2"; + /// + /// sets or gets the prismatic(V2) joints + /// public List PRS2Entries = new(); /// @@ -62,8 +63,6 @@ public byte[] Serialize(long offset = 0) } return ms.ToArray(); } - - } } } diff --git a/Warcraft.NET/Files/phys/Chunks/REV2.cs b/Warcraft.NET/Files/phys/Chunks/REV2.cs index 2024f40..297898a 100644 --- a/Warcraft.NET/Files/phys/Chunks/REV2.cs +++ b/Warcraft.NET/Files/phys/Chunks/REV2.cs @@ -1,12 +1,10 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.phys.Entries; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Files.Phys.Entries; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class REV2 : IIFFChunk, IBinarySerializable @@ -16,6 +14,9 @@ public class REV2 : IIFFChunk, IBinarySerializable /// public const string Signature = "REV2"; + /// + /// sets or gets the revolute(V2) joints + /// public List REV2Entries = new(); /// @@ -62,8 +63,6 @@ public byte[] Serialize(long offset = 0) } return ms.ToArray(); } - - } } } diff --git a/Warcraft.NET/Files/phys/Chunks/SHJ2.cs b/Warcraft.NET/Files/phys/Chunks/SHJ2.cs index 757a5ad..c8ae2e2 100644 --- a/Warcraft.NET/Files/phys/Chunks/SHJ2.cs +++ b/Warcraft.NET/Files/phys/Chunks/SHJ2.cs @@ -1,12 +1,10 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.phys.Entries; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Files.Phys.Entries; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class SHJ2 : IIFFChunk, IBinarySerializable @@ -16,6 +14,9 @@ public class SHJ2 : IIFFChunk, IBinarySerializable /// public const string Signature = "SHJ2"; + /// + /// sets or gets the shoulder(V2) joints + /// public List SHJ2Entries = new(); /// @@ -62,8 +63,6 @@ public byte[] Serialize(long offset = 0) } return ms.ToArray(); } - - } } } diff --git a/Warcraft.NET/Files/phys/Chunks/SHOJ.cs b/Warcraft.NET/Files/phys/Chunks/SHOJ.cs index 4adde28..b1149ac 100644 --- a/Warcraft.NET/Files/phys/Chunks/SHOJ.cs +++ b/Warcraft.NET/Files/phys/Chunks/SHOJ.cs @@ -1,12 +1,10 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.phys.Entries; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Files.Phys.Entries; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class SHOJ : IIFFChunk, IBinarySerializable @@ -16,6 +14,9 @@ public class SHOJ : IIFFChunk, IBinarySerializable /// public const string Signature = "SHOJ"; + /// + /// sets or gets the shoulder joints + /// public List SHOJEntries = new(); /// @@ -62,8 +63,6 @@ public byte[] Serialize(long offset = 0) } return ms.ToArray(); } - - } } } diff --git a/Warcraft.NET/Files/phys/Chunks/SHP2.cs b/Warcraft.NET/Files/phys/Chunks/SHP2.cs index 948105c..21f1265 100644 --- a/Warcraft.NET/Files/phys/Chunks/SHP2.cs +++ b/Warcraft.NET/Files/phys/Chunks/SHP2.cs @@ -1,12 +1,10 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.phys.Entries; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Files.Phys.Entries; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class SHP2 : IIFFChunk, IBinarySerializable @@ -16,6 +14,9 @@ public class SHP2 : IIFFChunk, IBinarySerializable /// public const string Signature = "SHP2"; + /// + /// sets or gets the shapes(V2) + /// public List SHP2Entries = new(); /// @@ -62,8 +63,6 @@ public byte[] Serialize(long offset = 0) } return ms.ToArray(); } - - } } } diff --git a/Warcraft.NET/Files/phys/Chunks/SPHJ.cs b/Warcraft.NET/Files/phys/Chunks/SPHJ.cs index 2f8fa97..4ec195f 100644 --- a/Warcraft.NET/Files/phys/Chunks/SPHJ.cs +++ b/Warcraft.NET/Files/phys/Chunks/SPHJ.cs @@ -1,12 +1,10 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.phys.Entries; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Files.Phys.Entries; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class SPHJ : IIFFChunk, IBinarySerializable @@ -16,6 +14,9 @@ public class SPHJ : IIFFChunk, IBinarySerializable /// public const string Signature = "SPHJ"; + /// + /// sets or gets the spherical joints + /// public List SPHJEntries = new(); /// @@ -42,7 +43,6 @@ public void LoadBinaryData(byte[] inData) using (var br = new BinaryReader(ms)) { var SPHJcount = br.BaseStream.Length / SPHJEntry.GetSize(); - for (var i = 0; i < SPHJcount; ++i) { SPHJEntries.Add(new SPHJEntry(br.ReadBytes(SPHJEntry.GetSize()))); @@ -62,8 +62,6 @@ public byte[] Serialize(long offset = 0) } return ms.ToArray(); } - - } } } diff --git a/Warcraft.NET/Files/phys/Chunks/SPHS.cs b/Warcraft.NET/Files/phys/Chunks/SPHS.cs index 4798579..5b55a64 100644 --- a/Warcraft.NET/Files/phys/Chunks/SPHS.cs +++ b/Warcraft.NET/Files/phys/Chunks/SPHS.cs @@ -1,10 +1,10 @@ +using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Files.Phys.Entries; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class SPHS : IIFFChunk, IBinarySerializable @@ -15,14 +15,9 @@ public class SPHS : IIFFChunk, IBinarySerializable public const string Signature = "SPHS"; /// - /// Gets or Sets the local position of the Sphere shape + /// sets or gets a list of sphere shapes /// - public C3Vector localPosition; - - /// - /// Gets or Sets the radius of the Sphere shape - /// - public float radius; + public List Spheres = new(); /// /// Initializes a new instance of @@ -47,8 +42,12 @@ public void LoadBinaryData(byte[] inData) using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) { - localPosition = new C3Vector(br.ReadBytes(12)); - radius = br.ReadSingle(); + var SHP2count = br.BaseStream.Length / SHP2Entry.GetSize(); + + for (var i = 0; i < SHP2count; ++i) + { + Spheres.Add(new SPHSEntry(br.ReadBytes(SPHSEntry.GetSize()))); + } } } @@ -57,9 +56,11 @@ public byte[] Serialize(long offset = 0) { using (var ms = new MemoryStream()) using (var bw = new BinaryWriter(ms)) - { - bw.Write(localPosition.asBytes()); - bw.Write(radius); + { + foreach (SPHSEntry obj in Spheres) + { + bw.Write(obj.Serialize()); + } return ms.ToArray(); } } diff --git a/Warcraft.NET/Files/phys/Chunks/WLJ3.cs b/Warcraft.NET/Files/phys/Chunks/WLJ3.cs index 086d177..b71e7a7 100644 --- a/Warcraft.NET/Files/phys/Chunks/WLJ3.cs +++ b/Warcraft.NET/Files/phys/Chunks/WLJ3.cs @@ -1,12 +1,10 @@ using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; -using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.phys.Entries; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Files.Phys.Entries; -namespace Warcraft.NET.Files.phys.Chunks +namespace Warcraft.NET.Files.Phys.Chunks { [AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterBfA, AutoDocChunkVersionHelper.VersionBeforeSL)] public class WLJ3 : IIFFChunk, IBinarySerializable @@ -16,6 +14,9 @@ public class WLJ3 : IIFFChunk, IBinarySerializable /// public const string Signature = "WLJ3"; + /// + /// sets or gets a list of Weld(V3) Joints + /// public List WLJ3Entries = new(); /// @@ -62,8 +63,6 @@ public byte[] Serialize(long offset = 0) } return ms.ToArray(); } - - } } } diff --git a/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs b/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs index 6e9bab5..8fc497e 100644 --- a/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs +++ b/Warcraft.NET/Files/phys/Entries/BDY4Entry.cs @@ -1,40 +1,81 @@ using System.IO; +using System.Numerics; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Phys.Enums; using Warcraft.NET.Files.Structures; -namespace Warcraft.NET.Files.phys.Entries +namespace Warcraft.NET.Files.Phys.Entries { public class BDY4Entry { + /// + /// Sets or gets the BodyType of the rigidbody + /// 0=static + /// 1=dynamic + /// 2=unknown + /// + public BodyType BodyType { get; set; } // maps to dmBodyDef BodyType enum. 0 -> 1, 1 -> 0 = dm_dynamicBody, * -> 2. Only one should be of BodyType 0 (root). possibly only 0 and 1. - public enum Body_Type : ushort - { - root = 0, - dynamic = 1, - unk = 2, - } + /// + /// Sets or gets the index of the bone, which is connected to this rigidbody + /// + public ushort BoneIndex { get; set; } + + /// + /// sets or gets the default Position of the rigidbody + /// + public Vector3 Position { get; set; } = new Vector3(0, 0, 0); + + /// + /// sets or gets the index of the shape, which is connected to this rigidbody + /// + public ushort ShapesIndex { get; set; } + + /// + /// sets or gets a currently unknown field. Possibly 'Padding' + /// + public byte[] Unk0 { get; set; } = { 0, 0 }; + + /// + /// sets or gets the amount of shapes this rigidbody has + /// + public int ShapesCount { get; set; } // shapes_count shapes are in this body. + + /// + /// sets or gets a currently unknown field. Possibly 'UpliftFactor' + /// + public float Unk1 { get; set; } = 0f; - public Body_Type type { get; set; } // maps to dmBodyDef type enum. 0 -> 1, 1 -> 0 = dm_dynamicBody, * -> 2. Only one should be of type 0 (root). possibly only 0 and 1. - public ushort boneIndex { get; set; } - public C3Vector position { get; set; } - public ushort shapeIndex { get; set; } - public byte[] PADDING { get; set; } - public int shapesCount { get; set; } // shapes_count shapes are in this body. - public float unk0 { get; set; } //#if version >= 3 // BDY3 - public float _x1c { get; set; } // default 1.0 - public float drag { get; set; } // default 0, maybe incorrect - public float unk1; // default 0, seems to be some sort of weight. - // If version >= 3 and unk1 == 0 the body will be non kinematic even if the flag is set, it needs to get its transform from the parent bone. - // See offhand_1h_artifactskulloferedar_d_06 where all the bodies have the kinematic flag - public float _x28 { get; set; } // default 0.89999998 + /// + /// sets or gets a currently unknown field. Possibly 'GravityScale' + /// + public float Unk2 { get; set; } = 1.0f; - public byte[] x2c { get; set; }// default 0x00000000 + /// + /// sets or gets the Drag value of the rigidbody. + /// + public float Drag { get; set; } = 0f; + /// + /// sets or gets a currently unknown field. Possibly 'Mass/Weight' + /// + public float Unk3 = 0f; + + /// + /// sets or gets a currently unknown field. + /// + public float Unk4 { get; set; } = 0.89999998f; + + /// + /// sets or gets a currently unknown field. + /// + public byte[] Unk5 { get; set; } = { 0, 0, 0, 0 }; /// /// Initializes a new instance of the class. /// - public BDY4Entry(){} + public BDY4Entry() { } /// /// Initializes a new instance of the class. @@ -45,18 +86,18 @@ public BDY4Entry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - type = (Body_Type)br.ReadUInt16(); - boneIndex = br.ReadUInt16(); - position = new C3Vector(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); - shapeIndex = br.ReadUInt16(); - PADDING = br.ReadBytes(2); - shapesCount = br.ReadInt32(); - unk0 = br.ReadSingle(); - _x1c = br.ReadSingle(); - drag = br.ReadSingle(); - unk1 = br.ReadSingle(); - _x28 = br.ReadSingle(); - x2c = br.ReadBytes(4); + BodyType = (BodyType)br.ReadUInt16(); + BoneIndex = br.ReadUInt16(); + Position = br.ReadVector3(AxisConfiguration.ZUp); + ShapesIndex = br.ReadUInt16(); + Unk0 = br.ReadBytes(2); + ShapesCount = br.ReadInt32(); + Unk1 = br.ReadSingle(); + Unk2 = br.ReadSingle(); + Drag = br.ReadSingle(); + Unk3 = br.ReadSingle(); + Unk4 = br.ReadSingle(); + Unk5 = br.ReadBytes(4); } } @@ -76,24 +117,23 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write((ushort)type); - bw.Write(boneIndex); - bw.Write(position.X); - bw.Write(position.Y); - bw.Write(position.Z); - bw.Write(shapeIndex); - bw.Write(PADDING); - bw.Write(shapesCount); - bw.Write(unk0); - bw.Write(_x1c); - bw.Write(drag); - bw.Write(unk1); - bw.Write(_x28); - bw.Write(x2c); + bw.Write((ushort)BodyType); + bw.Write(BoneIndex); + bw.Write(Position.X); + bw.Write(Position.Y); + bw.Write(Position.Z); + bw.Write(ShapesIndex); + bw.Write(Unk0); + bw.Write(ShapesCount); + bw.Write(Unk1); + bw.Write(Unk2); + bw.Write(Drag); + bw.Write(Unk3); + bw.Write(Unk4); + bw.Write(Unk5); } - return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/BOXSEntry.cs b/Warcraft.NET/Files/phys/Entries/BOXSEntry.cs index cc0b3fc..8fffebd 100644 --- a/Warcraft.NET/Files/phys/Entries/BOXSEntry.cs +++ b/Warcraft.NET/Files/phys/Entries/BOXSEntry.cs @@ -1,30 +1,31 @@ using System.IO; -using Warcraft.NET.Files.phys.Chunks; -using Warcraft.NET.Files.Structures; +using System.Numerics; +using Warcraft.NET.Extensions; -namespace Warcraft.NET.Files.phys.Entries +namespace Warcraft.NET.Files.Phys.Entries { public class BOXSEntry { /// - /// Gets or Sets the matrix of the box shape + /// Gets or Sets the transformation matrix of the box shape /// - public Mat3x4 a; + public Matrix3x4 Dimensions; /// /// Gets or Sets the local position of the box shape /// - public C3Vector c; + public Vector3 Position; public BOXSEntry(byte[] data) { using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - a = new Mat3x4(br.ReadBytes(48)); - c = new C3Vector(br.ReadBytes(12)); + Dimensions = br.ReadMatrix3x4(); + Position = br.ReadVector3(); } } + /// /// Gets the size of a box entry. /// @@ -41,13 +42,11 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write(a.asBytes()); - bw.Write(c.asBytes()); + bw.WriteMatrix3x4(Dimensions); + bw.WriteVector3(Position); } - return ms.ToArray(); } } - } } \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/CAPSEntry.cs b/Warcraft.NET/Files/phys/Entries/CAPSEntry.cs index 05e86db..dcfde2d 100644 --- a/Warcraft.NET/Files/phys/Entries/CAPSEntry.cs +++ b/Warcraft.NET/Files/phys/Entries/CAPSEntry.cs @@ -1,35 +1,35 @@ using System.IO; -using Warcraft.NET.Files.phys.Chunks; +using System.Numerics; +using Warcraft.NET.Extensions; using Warcraft.NET.Files.Structures; -namespace Warcraft.NET.Files.phys.Entries +namespace Warcraft.NET.Files.Phys.Entries { public class CAPSEntry { - /// - /// Gets or Sets the local start position of the capsule shape + /// Gets or Sets the local start position of this capsule shape /// - public C3Vector localPosition1; + public Vector3 LocalPosition1; /// - /// Gets or Sets the local end position of the capsule shape + /// Gets or Sets the local end position of this capsule shape /// - public C3Vector localPosition2; + public Vector3 LocalPosition2; /// - /// Gets or Sets the radius of the capsule shape + /// Gets or Sets the Radius of this capsule shape /// - public float radius; + public float Radius; public CAPSEntry(byte[] data) { using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - localPosition1 = new C3Vector(br.ReadBytes(12)); - localPosition2 = new C3Vector(br.ReadBytes(12)); - radius = br.ReadSingle(); + LocalPosition1 = br.ReadVector3(AxisConfiguration.ZUp); + LocalPosition2 = br.ReadVector3(AxisConfiguration.ZUp); + Radius = br.ReadSingle(); } } /// @@ -47,9 +47,9 @@ public byte[] Serialize(long offset = 0) using (var ms = new MemoryStream()) using (var bw = new BinaryWriter(ms)) { - bw.Write(localPosition1.asBytes()); - bw.Write(localPosition2.asBytes()); - bw.Write(radius); + bw.WriteVector3(LocalPosition1); + bw.WriteVector3(LocalPosition2); + bw.Write(Radius); return ms.ToArray(); } } diff --git a/Warcraft.NET/Files/phys/Entries/DSTJEntry.cs b/Warcraft.NET/Files/phys/Entries/DSTJEntry.cs index add4cee..6752e96 100644 --- a/Warcraft.NET/Files/phys/Entries/DSTJEntry.cs +++ b/Warcraft.NET/Files/phys/Entries/DSTJEntry.cs @@ -1,18 +1,25 @@ -using System; using System.IO; -using Warcraft.NET.Files.Structures; +using System.Numerics; +using Warcraft.NET.Extensions; -namespace Warcraft.NET.Files.phys.Entries +namespace Warcraft.NET.Files.Phys.Entries { public class DSTJEntry { + /// + /// sets or gets the local Anchor for Bone A from the Joint + /// + public Vector3 LocalAnchorA; + /// + /// sets or gets the local Anchor for Bone B from the Joint + /// + public Vector3 LocalAnchorB; - public C3Vector localAnchorA; - public C3Vector localAnchorB; - - public float some_distance_factor; - + /// + /// sets or gets the currently unknown value for the distance joint calculation + /// + public float UnknownDistanceFactor; /// /// Initializes a new instance of the class. @@ -28,9 +35,9 @@ public DSTJEntry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - localAnchorA = new C3Vector(br.ReadBytes(12)); - localAnchorB = new C3Vector(br.ReadBytes(12)); - some_distance_factor = br.ReadSingle(); + LocalAnchorA = br.ReadVector3(); + LocalAnchorB = br.ReadVector3(); + UnknownDistanceFactor = br.ReadSingle(); } } @@ -50,13 +57,12 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write(localAnchorA.asBytes()); - bw.Write(localAnchorB.asBytes()); - bw.Write(some_distance_factor); + bw.WriteVector3(LocalAnchorA); + bw.WriteVector3(LocalAnchorB); + bw.Write(UnknownDistanceFactor); } - return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/JOINEntry.cs b/Warcraft.NET/Files/phys/Entries/JOINEntry.cs index d0f57c3..03aaa3c 100644 --- a/Warcraft.NET/Files/phys/Entries/JOINEntry.cs +++ b/Warcraft.NET/Files/phys/Entries/JOINEntry.cs @@ -1,29 +1,40 @@ -using System; using System.IO; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Files.Phys.Enums; -namespace Warcraft.NET.Files.phys.Entries +namespace Warcraft.NET.Files.Phys.Entries { - - public class JOINEntry { - public enum Joint_Type : ushort - { - sphericalJoint = 0, - shoulderJoint = 1, - weldJoint = 2, - revoluteJoint = 3, - prismaticJoint = 4, - distanceJoint = 5, - } + /// + /// sets or gets the index of the first connected Rigidbody + /// + public uint BodyAIdx; - public uint bodyAIdx; - public uint bodyBIdx; - public byte[] unk; + /// + /// sets or gets the index of the second connected Rigidbody + /// + public uint BodyBIdx; - public Joint_Type jointType; - public ushort jointId; + /// + /// sets or gets a Unknown field. + /// + public byte[] Unk; + + /// + /// sets or gets the JointType + /// 0 = SphericalJoint + /// 1 = ShoulderJoint + /// 2 = WeldJoint + /// 3 = RevoluteJoint + /// 4 = PrismaticJoint + /// 5 = DistanceJoint + /// + public JointType JointType; + + /// + /// sets or gets the index of the joint into the joint list based on the JointType field + /// + public ushort JointID; /// /// Initializes a new instance of the class. @@ -39,11 +50,11 @@ public JOINEntry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - bodyAIdx = br.ReadUInt32(); - bodyBIdx = br.ReadUInt32(); - unk = br.ReadBytes(4); - jointType = (Joint_Type)br.ReadUInt16(); - jointId = br.ReadUInt16(); + BodyAIdx = br.ReadUInt32(); + BodyBIdx = br.ReadUInt32(); + Unk = br.ReadBytes(4); + JointType = (JointType)br.ReadUInt16(); + JointID = br.ReadUInt16(); } } @@ -63,14 +74,12 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write(bodyAIdx); - bw.Write(bodyBIdx); - bw.Write(unk); - bw.Write((ushort)jointType); - bw.Write(jointId); - + bw.Write(BodyAIdx); + bw.Write(BodyBIdx); + bw.Write(Unk); + bw.Write((ushort)JointType); + bw.Write(JointID); } - return ms.ToArray(); } } diff --git a/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs b/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs index 0f784c3..5e5ce51 100644 --- a/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs +++ b/Warcraft.NET/Files/phys/Entries/PLYTEntry.cs @@ -1,132 +1,188 @@ -using System; using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Warcraft.NET.Files.Structures; +using System.Numerics; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Phys.Structures; -namespace Warcraft.NET.Files.phys.Entries +namespace Warcraft.NET.Files.Phys.Entries { public class PLYTEntry { - public PLYT_HEADER header; - public PLYT_DATA data; + /// + /// gets or set the Polytope Header + /// + public PlytHeader Header; - [Serializable] - public struct PLYT_HEADER - { - public UInt32 vertexCount; // Mostly 8 - public byte[] unk_04; - public UInt64 RUNTIME_08_ptr_data_0; // = &data[i].unk_0 - public UInt32 count_10; // Mostly 6 - public byte[] unk_14; - public UInt64 RUNTIME_18_ptr_data_1; // = &data[i].unk_1 - public UInt64 RUNTIME_20_ptr_data_2; // = &data[i].unk_2 - public UInt32 nodeCount; // Mostly 24 - public byte[] unk_2C; - public UInt64 RUNTIME_30_ptr_data_3; // = &data[i].unk_3 - public float[] unk_38; // not sure if floats: has e-08 values - } + /// + /// gets or set the Polytope Data + /// + public PlytData Data; + + /// + /// gets or set the Polytope Data + /// + public int DataSize { get; } + + /// + /// Initializes a new instance of the class. + /// + public PLYTEntry() { } - [Serializable] - public struct PLYT_DATA + /// + /// Initializes a new instance of the class. + /// + /// Header Data + public PLYTEntry(byte[] header) { - public C3Vector[] vertices; //amount = vertexCount in header - public byte[] unk1; //multiple of 16 -> amount = count_10 in header - public byte[] unk2; //amount = count_10 in header - public NODE[] nodes;//amount = node_count in header + using (var ms = new MemoryStream(header)) + using (var br = new BinaryReader(ms)) + { + Header = new PlytHeader + { + VertexCount = br.ReadUInt32(), + Unk0 = br.ReadBytes(4), + RUNTIME08ptrData0 = br.ReadUInt64(), + Count10 = br.ReadUInt32(), + Unk1 = br.ReadBytes(4), + RUNTIME18ptrData1 = br.ReadUInt64(), + RUNTIME20ptrData2 = br.ReadUInt64(), + NodeCount = br.ReadUInt32(), + Unk2 = br.ReadBytes(4), + RUNTIME30ptrData3 = br.ReadUInt64(), + Unk3 = [br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()] + }; + int size = 0; + size += (int)Header.VertexCount * 12; + size += (int)Header.Count10 * 16; + size += (int)Header.Count10; + size += (int)Header.NodeCount * 4; + DataSize = size; + } } - [Serializable] - public struct NODE + /// + /// Deserialization of the Data Chunks + /// + /// + public void DeserializeData(byte[] data) { - public byte unk; // 1 or -1 - public byte vertexIndex; // index in vertex list - public byte unkIndex0; // index into the nodes - public byte unkIndex1; // index into the nodes + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + uint vcount = Header.VertexCount; + uint count_10 = Header.Count10; + uint nodeCount = Header.NodeCount; + + Data.Vertices = new Vector3[vcount]; + for (int v = 0; v < vcount; v++) + { + Data.Vertices[v] = br.ReadVector3(); + } + Data.Unk1 = br.ReadBytes((int)count_10 * 16); + Data.Unk2 = br.ReadBytes((int)count_10); + Data.Nodes = new PlytNode[nodeCount]; + for (int n = 0; n < nodeCount; n++) + { + PlytNode node = new(); + node.Unk = br.ReadByte(); + node.VertexIndex = br.ReadByte(); + node.UnkIndex0 = br.ReadByte(); + node.UnkIndex1 = br.ReadByte(); + Data.Nodes[n] = node; + } + } } /// - /// Initializes a new instance of the class. + /// gets the data size of the polytope. /// - public PLYTEntry() { } + /// The size. + public int GetDataSize() + { + return SerializeData().Length; + } /// - /// Initializes a new instance of the class. + /// gets the header size of the polytope. /// - /// ExtendedData. - public PLYTEntry(byte[] data) + /// The size. + public int GetHeaderSize() { - + return SerializeHeader().Length; } /// - /// Gets the size of a PLYT entry. + /// gets the full size of the polytope. /// /// The size. - public static int GetSize() + public int GetSize() { - return 0; + return SerializeHeader().Length + SerializeData().Length; } - /// + /// + /// Serialize the Header + /// + /// + /// public byte[] SerializeHeader(long offset = 0) { using (var ms = new MemoryStream()) { using (var bw = new BinaryWriter(ms)) { - - bw.Write(header.vertexCount); - bw.Write(header.unk_04); - - bw.Write(header.RUNTIME_08_ptr_data_0); + bw.Write(Header.VertexCount); + bw.Write(Header.Unk0); + + bw.Write(Header.RUNTIME08ptrData0); + + bw.Write(Header.Count10); + bw.Write(Header.Unk1); + + bw.Write(Header.RUNTIME18ptrData1); - bw.Write(header.count_10); - bw.Write(header.unk_14); + bw.Write(Header.RUNTIME20ptrData2); - bw.Write(header.RUNTIME_18_ptr_data_1); + bw.Write(Header.NodeCount); - bw.Write(header.RUNTIME_20_ptr_data_2); + bw.Write(Header.Unk2); - bw.Write(header.nodeCount); - - bw.Write(header.unk_2C); - - bw.Write(header.RUNTIME_30_ptr_data_3); - foreach (float f in header.unk_38) + bw.Write(Header.RUNTIME30ptrData3); + foreach (float f in Header.Unk3) { bw.Write(f); } - - } return ms.ToArray(); } } + + /// + /// Serialize the Data + /// + /// + /// public byte[] SerializeData(long offset = 0) { using (var ms = new MemoryStream()) { using (var bw = new BinaryWriter(ms)) { - foreach (var vertex in data.vertices) + foreach (var vertex in Data.Vertices) { - bw.Write(vertex.asBytes()); + bw.WriteVector3(vertex); } - bw.Write(data.unk1); - bw.Write(data.unk2); - foreach (var node in data.nodes) + bw.Write(Data.Unk1); + bw.Write(Data.Unk2); + foreach (var node in Data.Nodes) { - bw.Write(node.unk); - bw.Write(node.vertexIndex); - bw.Write(node.unkIndex0); - bw.Write(node.unkIndex1); + bw.Write(node.Unk); + bw.Write(node.VertexIndex); + bw.Write(node.UnkIndex0); + bw.Write(node.UnkIndex1); } } return ms.ToArray(); } } - - } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/PRS2Entry.cs b/Warcraft.NET/Files/phys/Entries/PRS2Entry.cs index de4420c..fc925a8 100644 --- a/Warcraft.NET/Files/phys/Entries/PRS2Entry.cs +++ b/Warcraft.NET/Files/phys/Entries/PRS2Entry.cs @@ -1,25 +1,62 @@ -using System; using System.IO; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Extensions; -namespace Warcraft.NET.Files.phys.Entries +namespace Warcraft.NET.Files.Phys.Entries { public class PRS2Entry { + /// + /// The Transformation Matrix for Bone A of this Joint + /// + public Matrix3x4 FrameA; + + /// + /// The Transformation Matrix for Bone B of this Joint + /// + public Matrix3x4 FrameB; + + /// + /// The lower limit + /// + public float LowerLimit; + + /// + /// The upper limit + /// + public float UpperLimit; + + /// + /// Unknown value + /// + public float Unk0; + /// + /// Max motor force if enabled + /// + public float MaxMotorForce; - public Mat3x4 frameA; - public Mat3x4 frameB; - public float lowerLimit; - public float upperLimit; - public float _68; - public float maxMotorForce; - public float _70; - public UInt32 motorMode; + /// + /// unknown value + /// + public float Unk1; - public float motorFrequencyHz; - public float motorDampingRatio; + /// + /// The MotorMode + /// 0 = disabled? + /// 1 = motorPositionMode (MotorFrequencyHz>0) + /// 2 = motorVelocityMode + /// + public uint MotorMode; + /// + /// how often per second the motor damps + /// + public float MotorFrequencyHz; + + /// + /// the ratio how much the motor damps + /// + public float MotorDampingRatio; /// /// Initializes a new instance of the class. @@ -35,16 +72,16 @@ public PRS2Entry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - frameA = new Mat3x4(br.ReadBytes(48)); - frameB = new Mat3x4(br.ReadBytes(48)); - lowerLimit = br.ReadSingle(); - upperLimit = br.ReadSingle(); - _68 = br.ReadSingle(); - maxMotorForce = br.ReadSingle(); - _70 = br.ReadSingle(); - motorMode = br.ReadUInt32(); - motorFrequencyHz = br.ReadSingle(); - motorDampingRatio = br.ReadSingle(); + FrameA = br.ReadMatrix3x4(); + FrameB = br.ReadMatrix3x4(); + LowerLimit = br.ReadSingle(); + UpperLimit = br.ReadSingle(); + Unk0 = br.ReadSingle(); + MaxMotorForce = br.ReadSingle(); + Unk1 = br.ReadSingle(); + MotorMode = br.ReadUInt32(); + MotorFrequencyHz = br.ReadSingle(); + MotorDampingRatio = br.ReadSingle(); } } @@ -64,20 +101,19 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write(frameA.asBytes()); - bw.Write(frameB.asBytes()); - bw.Write(lowerLimit); - bw.Write(upperLimit); - bw.Write(_68); - bw.Write(maxMotorForce); - bw.Write(_70); - bw.Write(motorMode); - bw.Write(motorFrequencyHz); - bw.Write(motorDampingRatio); + bw.WriteMatrix3x4(FrameA); + bw.WriteMatrix3x4(FrameB); + bw.Write(LowerLimit); + bw.Write(UpperLimit); + bw.Write(Unk0); + bw.Write(MaxMotorForce); + bw.Write(Unk1); + bw.Write(MotorMode); + bw.Write(MotorFrequencyHz); + bw.Write(MotorDampingRatio); } - return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/REV2Entry.cs b/Warcraft.NET/Files/phys/Entries/REV2Entry.cs index b1ef402..bc747ac 100644 --- a/Warcraft.NET/Files/phys/Entries/REV2Entry.cs +++ b/Warcraft.NET/Files/phys/Entries/REV2Entry.cs @@ -1,22 +1,48 @@ -using System; using System.IO; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Extensions; -namespace Warcraft.NET.Files.phys.Entries +namespace Warcraft.NET.Files.Phys.Entries { public class REV2Entry { - public Mat3x4 frameA; - public Mat3x4 frameB; - public float lowerAngle; - public float upperAngle; + /// + /// The Transformation Matrix for Bone A of this Joint + /// + public Matrix3x4 FrameA; - public float maxMotorTorque; - public UInt32 motorMode; // 1: motorPositionMode → frequency > 0, 2: motorVelocityMode + /// + /// The Transformation Matrix for Bone B of this Joint + /// + public Matrix3x4 FrameB; - public float motorFrequencyHz; - public float motorDampingRatio; + /// + /// The lower swing angle + /// + public float LowerAngle; + /// + /// The upper swing angle + /// + public float UpperAngle; + /// + /// The max motor torque + /// + public float MaxMotorTorque; + /// + /// The MotorMode + /// 0 = disabled? + /// 1 = motorPositionMode (MotorFrequencyHz>0) + /// 2 = motorVelocityMode + /// + public uint MotorMode; // 1: motorPositionMode → frequency > 0, 2: motorVelocityMode + /// + /// how often per second the motor damps + /// + public float MotorFrequencyHz; + /// + /// the ratio how much the motor damps + /// + public float MotorDampingRatio; /// /// Initializes a new instance of the class. @@ -32,14 +58,14 @@ public REV2Entry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - frameA = new Mat3x4(br.ReadBytes(48)); - frameB = new Mat3x4(br.ReadBytes(48)); - lowerAngle = br.ReadSingle(); - upperAngle = br.ReadSingle(); - maxMotorTorque = br.ReadSingle(); - motorMode = br.ReadUInt32(); - motorFrequencyHz = br.ReadSingle(); - motorDampingRatio = br.ReadSingle(); + FrameA = br.ReadMatrix3x4(); + FrameB = br.ReadMatrix3x4(); + LowerAngle = br.ReadSingle(); + UpperAngle = br.ReadSingle(); + MaxMotorTorque = br.ReadSingle(); + MotorMode = br.ReadUInt32(); + MotorFrequencyHz = br.ReadSingle(); + MotorDampingRatio = br.ReadSingle(); } } @@ -59,18 +85,17 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write(frameA.asBytes()); - bw.Write(frameB.asBytes()); - bw.Write(lowerAngle); - bw.Write(upperAngle); - bw.Write(maxMotorTorque); - bw.Write(motorMode); - bw.Write(motorFrequencyHz); - bw.Write(motorDampingRatio); + bw.WriteMatrix3x4(FrameA); + bw.WriteMatrix3x4(FrameB); + bw.Write(LowerAngle); + bw.Write(UpperAngle); + bw.Write(MaxMotorTorque); + bw.Write(MotorMode); + bw.Write(MotorFrequencyHz); + bw.Write(MotorDampingRatio); } - return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs b/Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs index cdd41f5..0586d11 100644 --- a/Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs +++ b/Warcraft.NET/Files/phys/Entries/SHJ2Entry.cs @@ -1,24 +1,57 @@ -using System; -using System.IO; -using Warcraft.NET.Files.Structures; +using System.IO; +using Warcraft.NET.Extensions; -namespace Warcraft.NET.Files.phys.Entries +namespace Warcraft.NET.Files.Phys.Entries { public class SHJ2Entry { + /// + /// The Transformation Matrix for Bone A of this Joint + /// + public Matrix3x4 FrameA; + /// + /// The Transformation Matrix for Bone B of this Joint + /// + public Matrix3x4 FrameB; - public Mat3x4 frameA; - public Mat3x4 frameB; - public float lowerTwistAngle; - public float upperTwistAngle; - public float coneAngle; - public float maxMotorTorque; - public UInt32 motorMode; // NO BACKWARDS COMPATIBILITY as of Legion (7.0.1.20979) and Legion (7.3.0.24931)! client always assumes new size! + /// + /// The lower twist angle of the angular constraint + /// + public float LowerTwistAngle; - public float motorFrequencyHz; - public float motorDampingRatio; + /// + /// The upper twist angle of the angular constraint + /// + public float UpperTwistAngle; + /// + /// The cone angle of the angular constraint + /// + public float ConeAngle; + + /// + /// The max motor torque + /// + public float MaxMotorTorque; + + /// + /// The MotorMode + /// 0 = disabled? + /// 1 = motorPositionMode (MotorFrequencyHz>0) + /// 2 = motorVelocityMode + /// + public uint MotorMode; // 1: motorPositionMode → frequency > 0, 2: motorVelocityMode + + /// + /// how often per second the motor damps + /// + public float MotorFrequencyHz; + + /// + /// the ratio how much the motor damps + /// + public float MotorDampingRatio; /// /// Initializes a new instance of the class. @@ -34,15 +67,15 @@ public SHJ2Entry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - frameA = new Mat3x4(br.ReadBytes(48)); - frameB = new Mat3x4(br.ReadBytes(48)); - lowerTwistAngle = br.ReadSingle(); - upperTwistAngle = br.ReadSingle(); - coneAngle = br.ReadSingle(); - maxMotorTorque = br.ReadSingle(); - motorMode = br.ReadUInt32(); - motorFrequencyHz = br.ReadSingle(); - motorDampingRatio = br.ReadSingle(); + FrameA = br.ReadMatrix3x4(); + FrameB = br.ReadMatrix3x4(); + LowerTwistAngle = br.ReadSingle(); + UpperTwistAngle = br.ReadSingle(); + ConeAngle = br.ReadSingle(); + MaxMotorTorque = br.ReadSingle(); + MotorMode = br.ReadUInt32(); + MotorFrequencyHz = br.ReadSingle(); + MotorDampingRatio = br.ReadSingle(); } } @@ -62,19 +95,18 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write(frameA.asBytes()); - bw.Write(frameB.asBytes()); - bw.Write(lowerTwistAngle); - bw.Write(upperTwistAngle); - bw.Write(coneAngle); - bw.Write(maxMotorTorque); - bw.Write(motorMode); - bw.Write(motorFrequencyHz); - bw.Write(motorDampingRatio); + bw.WriteMatrix3x4(FrameA); + bw.WriteMatrix3x4(FrameB); + bw.Write(LowerTwistAngle); + bw.Write(UpperTwistAngle); + bw.Write(ConeAngle); + bw.Write(MaxMotorTorque); + bw.Write(MotorMode); + bw.Write(MotorFrequencyHz); + bw.Write(MotorDampingRatio); } - return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/SHOJEntry.cs b/Warcraft.NET/Files/phys/Entries/SHOJEntry.cs index 5218b7a..1c5bead 100644 --- a/Warcraft.NET/Files/phys/Entries/SHOJEntry.cs +++ b/Warcraft.NET/Files/phys/Entries/SHOJEntry.cs @@ -1,21 +1,47 @@ -using System; -using System.IO; -using Warcraft.NET.Files.Structures; +using System.IO; +using Warcraft.NET.Extensions; -namespace Warcraft.NET.Files.phys.Entries +namespace Warcraft.NET.Files.Phys.Entries { public class SHOJEntry { + /// + /// The Transformation Matrix for Bone A of this Joint + /// + public Matrix3x4 FrameA; + + /// + /// The Transformation Matrix for Bone B of this Joint + /// + public Matrix3x4 FrameB; + + /// + /// The lower twist angle for the angular constraint + /// + public float LowerTwistAngle; + + /// + /// The upper twist angle for the angular constraint + /// + public float UpperTwistAngle; + /// + /// The cone angle for the angular constraint + /// + public float ConeAngle; - public Mat3x4 frameA; - public Mat3x4 frameB; - public float lowerTwistAngle; - public float upperTwistAngle; - public float coneAngle; - public float maxMotorTorque; - public UInt32 motorMode; // NO BACKWARDS COMPATIBILITY as of Legion (7.0.1.20979) and Legion (7.3.0.24931)! client always assumes new size! + /// + /// The Maximum torque the motor can apply + /// + public float MaxMotorTorque; + /// + /// The MotorMode + /// 0 = disabled? + /// 1 = motorPositionMode (MotorFrequencyHz>0) + /// 2 = motorVelocityMode + /// + public uint MotorMode; // NO BACKWARDS COMPATIBILITY as of Legion (7.0.1.20979) and Legion (7.3.0.24931)! client always assumes new size! /// /// Initializes a new instance of the class. @@ -31,13 +57,13 @@ public SHOJEntry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - frameA = new Mat3x4(br.ReadBytes(48)); - frameB = new Mat3x4(br.ReadBytes(48)); - lowerTwistAngle = br.ReadSingle(); - upperTwistAngle = br.ReadSingle(); - coneAngle = br.ReadSingle(); - maxMotorTorque = br.ReadSingle(); - motorMode = br.ReadUInt32(); + FrameA = br.ReadMatrix3x4(); + FrameB = br.ReadMatrix3x4(); + LowerTwistAngle = br.ReadSingle(); + UpperTwistAngle = br.ReadSingle(); + ConeAngle = br.ReadSingle(); + MaxMotorTorque = br.ReadSingle(); + MotorMode = br.ReadUInt32(); } } @@ -57,17 +83,16 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write(frameA.asBytes()); - bw.Write(frameB.asBytes()); - bw.Write(lowerTwistAngle); - bw.Write(upperTwistAngle); - bw.Write(coneAngle); - bw.Write(maxMotorTorque); - bw.Write(motorMode); + bw.WriteMatrix3x4(FrameA); + bw.WriteMatrix3x4(FrameB); + bw.Write(LowerTwistAngle); + bw.Write(UpperTwistAngle); + bw.Write(ConeAngle); + bw.Write(MaxMotorTorque); + bw.Write(MotorMode); } - return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/SHP2Entry.cs b/Warcraft.NET/Files/phys/Entries/SHP2Entry.cs index 5f1efe3..e179c04 100644 --- a/Warcraft.NET/Files/phys/Entries/SHP2Entry.cs +++ b/Warcraft.NET/Files/phys/Entries/SHP2Entry.cs @@ -1,44 +1,63 @@ -using System; using System.IO; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Files.Phys.Enums; -namespace Warcraft.NET.Files.phys.Entries +namespace Warcraft.NET.Files.Phys.Entries { + public class SHP2Entry + { + /// + /// The Shape Type + /// 0 = Box + /// 1 = Capsule + /// 2 = Sphere + /// 3 = Polytope + /// + public ShapeType ShapeType; + /// + /// The index into the corresponding chunk based on ShapeType + /// + public ushort ShapeIndex; + + /// + /// unknown field + /// + public byte[] Unk0; + /// + /// the friction of the shape + /// + public float Friction; - public class SHP2Entry - { - public enum Shape_Type : short - { - box = 0, - caps = 1, - sphere = 2, - polytope = 3, - } + /// + /// the restitution of the shape + /// + public float Restitution; + + /// + /// the density of the shape + /// + public float Density; - /*0x00*/ - public Shape_Type shapeType; - /*0x02*/ - public ushort shapeIndex; // into the corresponding chunk - /*0x04*/ - public byte[] unk; - /*0x08*/ - public float friction; - /*0x0c*/ - public float restitution; - /*0x10*/ - public float density; - /*0x14*/ - public UInt32 _x14; // default 0 - /*0x18*/ - public float _x18; // default 1.0 - /*0x1c*/ - public UInt16 _x1c; // default 0 - /*0x1e*/ - public UInt16 _x1e; // no default, padding? + /// + /// unknown field + /// + public uint Unk1 = 0; + + /// + /// unknown field + /// + public float Unk2 = 1f; + /// + /// unknown field + /// + public ushort Unk3 = 0; + /// + /// unknown field + /// + public ushort Unk4; //no default, padding? /// /// Initializes a new instance of the class. @@ -54,16 +73,16 @@ public SHP2Entry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - shapeType = (Shape_Type)br.ReadUInt16(); - shapeIndex = br.ReadUInt16(); - unk = br.ReadBytes(4); - friction = br.ReadSingle(); - restitution = br.ReadSingle(); - density = br.ReadSingle(); - _x14 = br.ReadUInt32(); - _x18 = br.ReadSingle(); - _x1c = br.ReadUInt16(); - _x1e = br.ReadUInt16(); + ShapeType = (ShapeType)br.ReadUInt16(); + ShapeIndex = br.ReadUInt16(); + Unk0 = br.ReadBytes(4); + Friction = br.ReadSingle(); + Restitution = br.ReadSingle(); + Density = br.ReadSingle(); + Unk1 = br.ReadUInt32(); + Unk2 = br.ReadSingle(); + Unk3 = br.ReadUInt16(); + Unk4 = br.ReadUInt16(); } } @@ -83,22 +102,19 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write((ushort)shapeType); - bw.Write(shapeIndex); - bw.Write(unk); - bw.Write(friction); - bw.Write(restitution); - bw.Write(density); - bw.Write(_x14); - bw.Write(_x18); - bw.Write(_x1c); - bw.Write(_x1e); + bw.Write((ushort)ShapeType); + bw.Write(ShapeIndex); + bw.Write(Unk0); + bw.Write(Friction); + bw.Write(Restitution); + bw.Write(Density); + bw.Write(Unk1); + bw.Write(Unk2); + bw.Write(Unk3); + bw.Write(Unk4); } - return ms.ToArray(); } } - - } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/SPHJEntry.cs b/Warcraft.NET/Files/phys/Entries/SPHJEntry.cs index a2a428d..1f0d175 100644 --- a/Warcraft.NET/Files/phys/Entries/SPHJEntry.cs +++ b/Warcraft.NET/Files/phys/Entries/SPHJEntry.cs @@ -1,15 +1,26 @@ -using System; using System.IO; +using System.Numerics; +using Warcraft.NET.Extensions; using Warcraft.NET.Files.Structures; -namespace Warcraft.NET.Files.phys.Entries +namespace Warcraft.NET.Files.Phys.Entries { public class SPHJEntry { - public C3Vector anchorA; - public C3Vector anchorB; - public float frictionTorque; + /// + /// the local anchor of the Bone A of the joint + /// + public Vector3 AnchorA; + + /// + /// the local anchor of the Bone B of the joint + /// + public Vector3 AnchorB; + /// + /// the friction torque + /// + public float FrictionTorque; /// /// Initializes a new instance of the class. @@ -25,9 +36,9 @@ public SPHJEntry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - anchorA = new C3Vector(br.ReadBytes(12)); - anchorB = new C3Vector(br.ReadBytes(12)); - frictionTorque = br.ReadSingle(); + AnchorA = br.ReadVector3(AxisConfiguration.ZUp); + AnchorB = br.ReadVector3(AxisConfiguration.ZUp); + FrictionTorque = br.ReadSingle(); } } @@ -47,13 +58,12 @@ public byte[] Serialize(long offset = 0) { using (var bw = new BinaryWriter(ms)) { - bw.Write(anchorA.asBytes()); - bw.Write(anchorB.asBytes()); - bw.Write(frictionTorque); + bw.WriteVector3(AnchorA); + bw.WriteVector3(AnchorB); + bw.Write(FrictionTorque); } - return ms.ToArray(); } } } -} +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/SPHSEntry.cs b/Warcraft.NET/Files/phys/Entries/SPHSEntry.cs new file mode 100644 index 0000000..51ceec7 --- /dev/null +++ b/Warcraft.NET/Files/phys/Entries/SPHSEntry.cs @@ -0,0 +1,52 @@ +using System.IO; +using System.Numerics; +using Warcraft.NET.Extensions; + +namespace Warcraft.NET.Files.Phys.Entries +{ + public class SPHSEntry + { + /// + /// Gets or Sets the local position of the Sphere shape + /// + public Vector3 LocalPosition; + + /// + /// Gets or Sets the radius of the Sphere shape + /// + public float Radius; + + public SPHSEntry(byte[] data) + { + using (var ms = new MemoryStream(data)) + using (var br = new BinaryReader(ms)) + { + LocalPosition = br.ReadVector3(); + Radius = br.ReadSingle(); + } + } + + /// + /// Gets the size of a Sphere entry. + /// + /// The size. + public static int GetSize() + { + return 16; + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + { + using (var bw = new BinaryWriter(ms)) + { + bw.WriteVector3(LocalPosition); + bw.Write(Radius); + } + return ms.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs b/Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs index 56be673..396083e 100644 --- a/Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs +++ b/Warcraft.NET/Files/phys/Entries/WLJ3Entry.cs @@ -1,21 +1,44 @@ -using System; using System.IO; -using Warcraft.NET.Files.Structures; +using Warcraft.NET.Extensions; -namespace Warcraft.NET.Files.phys.Entries +namespace Warcraft.NET.Files.Phys.Entries { public class WLJ3Entry { - public Mat3x4 frameA; - public Mat3x4 frameB; - public float angularFrequencyHz; - public float angularDampingRatio; + /// + /// The Transformation Matrix for Bone A of this Joint + /// + public Matrix3x4 FrameA; + + /// + /// The Transformation Matrix for Bone B of this Joint + /// + public Matrix3x4 FrameB; + + /// + /// how often the angular dampening is applied per second + /// + public float AngularFrequencyHz; + + /// + /// the ratio how strong the angular dampening is applied + /// + public float AngularDampingRatio; - public float linearFrequencyHz; // default 0 - public float linearDampingRatio; // default 0 + /// + /// how often the linear dampening is applied per second + /// + public float LinearFrequencyHz; // default 0 - public float unk70; + /// + /// the ratio how linear the angular dampening is applied + /// + public float LinearDampingRatio; // default 0 + /// + /// unknown field + /// + public float Unk0; /// /// Initializes a new instance of the class. @@ -31,13 +54,13 @@ public WLJ3Entry(byte[] data) using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { - frameA = new Mat3x4(br.ReadBytes(48)); - frameB = new Mat3x4(br.ReadBytes(48)); - angularFrequencyHz = br.ReadSingle(); - angularDampingRatio = br.ReadSingle(); - linearFrequencyHz = br.ReadSingle(); - linearDampingRatio = br.ReadSingle(); - unk70 = br.ReadSingle(); + FrameA = br.ReadMatrix3x4(); + FrameB = br.ReadMatrix3x4(); + AngularFrequencyHz = br.ReadSingle(); + AngularDampingRatio = br.ReadSingle(); + LinearFrequencyHz = br.ReadSingle(); + LinearDampingRatio = br.ReadSingle(); + Unk0 = br.ReadSingle(); } } @@ -54,18 +77,15 @@ public static int GetSize() public byte[] Serialize(long offset = 0) { using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) { - using (var bw = new BinaryWriter(ms)) - { - bw.Write(frameA.asBytes()); - bw.Write(frameB.asBytes()); - bw.Write(angularFrequencyHz); - bw.Write(angularDampingRatio); - bw.Write(linearFrequencyHz); - bw.Write(linearDampingRatio); - bw.Write(unk70); - } - + bw.WriteMatrix3x4(FrameA); + bw.WriteMatrix3x4(FrameB); + bw.Write(AngularFrequencyHz); + bw.Write(AngularDampingRatio); + bw.Write(LinearFrequencyHz); + bw.Write(LinearDampingRatio); + bw.Write(Unk0); return ms.ToArray(); } } diff --git a/Warcraft.NET/Files/phys/Enums/BodyType.cs b/Warcraft.NET/Files/phys/Enums/BodyType.cs new file mode 100644 index 0000000..5908459 --- /dev/null +++ b/Warcraft.NET/Files/phys/Enums/BodyType.cs @@ -0,0 +1,9 @@ +namespace Warcraft.NET.Files.Phys.Enums +{ + public enum BodyType : ushort + { + root = 0, + dynamic = 1, + unk = 2, + } +} diff --git a/Warcraft.NET/Files/phys/Enums/JointType.cs b/Warcraft.NET/Files/phys/Enums/JointType.cs new file mode 100644 index 0000000..e7f605d --- /dev/null +++ b/Warcraft.NET/Files/phys/Enums/JointType.cs @@ -0,0 +1,12 @@ +namespace Warcraft.NET.Files.Phys.Enums +{ + public enum JointType : ushort + { + sphericalJoint = 0, + shoulderJoint = 1, + weldJoint = 2, + revoluteJoint = 3, + prismaticJoint = 4, + distanceJoint = 5, + } +} diff --git a/Warcraft.NET/Files/phys/Enums/ShapeType.cs b/Warcraft.NET/Files/phys/Enums/ShapeType.cs new file mode 100644 index 0000000..290f93f --- /dev/null +++ b/Warcraft.NET/Files/phys/Enums/ShapeType.cs @@ -0,0 +1,10 @@ +namespace Warcraft.NET.Files.Phys.Enums +{ + public enum ShapeType : short + { + box = 0, + caps = 1, + sphere = 2, + polytope = 3, + } +} diff --git a/Warcraft.NET/Files/phys/Physics.cs b/Warcraft.NET/Files/phys/Physics.cs index 343102b..45ec5ef 100644 --- a/Warcraft.NET/Files/phys/Physics.cs +++ b/Warcraft.NET/Files/phys/Physics.cs @@ -1,61 +1,113 @@ using Warcraft.NET.Attribute; -using Warcraft.NET.Files.phys.Chunks; +using Warcraft.NET.Files.Phys.Chunks; -namespace Warcraft.NET.Files.phys +namespace Warcraft.NET.Files.Phys { [AutoDocFile("phys")] public class Physics : ChunkedFile { + /// + /// contains the version of the physics + /// [ChunkOrder(1)] - public PHYS phys{get; set;} + public PHYS Version{get; set;} - [ChunkOptional] - public PHYT phyt{get; set;} + /// + /// contains an unknown uint + /// + [ChunkOrder(2),ChunkOptional] + public PHYT Phyt{get; set; } - [ChunkOptional] - public BOXS boxs{get;set;} + /// + /// contains the used box shapes + /// + [ChunkOrder(3),ChunkOptional] + public BOXS BoxShapes{get;set;} - [ChunkOptional] - public SPHS sphs{get;set;} + /// + /// contains the used sphere shapes + /// + [ChunkOrder(4),ChunkOptional] + public SPHS SphereShapes{get;set;} - [ChunkOptional] - public CAPS caps{get;set;} + /// + /// contains the used capsule shapes + /// + + [ChunkOrder(5),ChunkOptional] + public CAPS CapsuleShapes{get;set;} - [ChunkOptional] - public PLYT plyt{get; set;} + /// + /// contains the used polytope shapes + /// + [ChunkOrder(6),ChunkOptional] + public PLYT PolytopeShapes{get; set;} - [ChunkOptional] - public SHP2 shp2{get; set;} + /// + /// contains the used shapes + /// + [ChunkOrder(7),ChunkOptional] + public SHP2 Shapes2{get; set;} //SHAP nyi - [ChunkOptional] - public BDY4 bdy4{get; set;} + /// + /// contains the used rigidbodies + /// + [ChunkOrder(8),ChunkOptional] + public BDY4 Rigidbodies4{get; set;} //BODY,BDY2,BDY3 NYI - [ChunkOptional] - public SHOJ shoj { get; set; } + /// + /// contains the used shoulder joints + /// + [ChunkOrder(9),ChunkOptional] + public SHOJ ShoulderJoints { get; set; } - [ChunkOptional] - public SHJ2 shj2{get; set;} + /// + /// contains the used shoulder joints + /// + [ChunkOrder(10),ChunkOptional] + public SHJ2 ShoulderJoints2{get; set;} - [ChunkOptional] - public WLJ3 wlj3{get; set;} + /// + /// contains the used weld joints + /// + [ChunkOrder(11),ChunkOptional] + public WLJ3 WeldJoints3{get; set;} //WELJ,WLJ2 nyi - [ChunkOptional] - public SPHJ sphj{get; set;} + /// + /// contains the used spherical joints + /// + [ChunkOrder(12),ChunkOptional] + public SPHJ SphericalJoints{get; set;} + + /// + /// contains the used prismatic joints + /// + [ChunkOrder(13),ChunkOptional] + public PRS2 PrismaticJoints2{get; set;} //PRSJ nyi - [ChunkOptional] - public PRS2 prs2{get; set;} + /// + /// contains the used revolute joints + /// + [ChunkOrder(14),ChunkOptional] + public REV2 RevoluteJoints2{get; set;} //REVJ nyi - [ChunkOptional] - public REV2 rev2{get; set;} + /// + /// contains the used distance joints + /// + [ChunkOrder(15),ChunkOptional] + public DSTJ DistanceJoints{get; set;} - [ChunkOptional] - public DSTJ dstj{get; set;} - - [ChunkOptional] - public JOIN join{get; set;} + /// + /// contains the used joints + /// + [ChunkOrder(16),ChunkOptional] + public JOIN Joints{get; set;} - [ChunkOptional] - public PHYV phyv { get; set; } + /// + /// contains the used phyv data (unknown) + /// + [ChunkOrder(17),ChunkOptional] + public PHYV Phyv { get; set; } /// /// Initializes a new instance of the class. diff --git a/Warcraft.NET/Files/phys/Structures/PlytData.cs b/Warcraft.NET/Files/phys/Structures/PlytData.cs new file mode 100644 index 0000000..65ddf95 --- /dev/null +++ b/Warcraft.NET/Files/phys/Structures/PlytData.cs @@ -0,0 +1,29 @@ +using System; +using System.Numerics; + +namespace Warcraft.NET.Files.Phys.Structures +{ + [Serializable] + public struct PlytData + { + /// + /// gets or sets the vertices. Amount is defined by header.VertexCount + /// + public Vector3[] Vertices; //amount = VertexCount in Header + + /// + /// gets or sets the Unk1 array. Unknown purpose. Amount is defined by header.Count10 + /// + public byte[] Unk1; //multiple of 16 -> amount = count_10 in Header + + /// + /// gets or sets the Unk2 array. Unknown purpose.Amount is defined by header.Count10 + /// + public byte[] Unk2; //amount = count_10 in Header + + /// + /// gets or sets the Unk2 array. Unknown purpose.Amount is defined by header.NodeCount + /// + public PlytNode[] Nodes; + } +} diff --git a/Warcraft.NET/Files/phys/Structures/PlytHeader.cs b/Warcraft.NET/Files/phys/Structures/PlytHeader.cs new file mode 100644 index 0000000..c6b871a --- /dev/null +++ b/Warcraft.NET/Files/phys/Structures/PlytHeader.cs @@ -0,0 +1,62 @@ +using System; + +namespace Warcraft.NET.Files.Phys.Structures +{ + public struct PlytHeader + { + /// + /// gets or sets the amount of vertices for this polytope + /// + public uint VertexCount; + + /// + /// gets or sets unknown data + /// + public byte[] Unk0; + + /// + /// gets or sets certain runtime data. Unknown purpose + /// + public UInt64 RUNTIME08ptrData0; + + /// + /// gets or sets the count10, which defines how many Unk1[] and Unk2[] there are inside the Data. + /// + public uint Count10; + + /// + /// gets or sets the Unk1 array. Unknown purpose + /// + public byte[] Unk1; + + /// + /// gets or sets certain runtime data. Unknown purpose + /// + public UInt64 RUNTIME18ptrData1; + + /// + /// gets or sets certain runtime data. Unknown purpose + /// + public UInt64 RUNTIME20ptrData2; + + /// + /// gets or sets the amount of nodes. Defines how Vertices are connected + /// + public uint NodeCount; + + /// + /// gets or sets the Unk2 array. Unknown purpose + /// + public byte[] Unk2; + + /// + /// gets or sets certain runtime data. Unknown purpose + /// + public UInt64 RUNTIME30ptrData3; + + /// + /// gets or sets the Unk3 array. Unknown purpose + /// + public float[] Unk3; + } +} \ No newline at end of file diff --git a/Warcraft.NET/Files/phys/Structures/PlytNode.cs b/Warcraft.NET/Files/phys/Structures/PlytNode.cs new file mode 100644 index 0000000..c727e69 --- /dev/null +++ b/Warcraft.NET/Files/phys/Structures/PlytNode.cs @@ -0,0 +1,29 @@ +using System; + +namespace Warcraft.NET.Files.Phys.Structures +{ + + [Serializable] + public struct PlytNode + { + /// + /// Unknown byte. Always 1 or -1 + /// + public byte Unk; // 1 or -1 + + /// + /// Index into the data.Vertices + /// + public byte VertexIndex; // index in vertex list + + /// + /// Index into data.Nodes + /// + public byte UnkIndex0; // index into the nodes + + /// + /// Index into data.Nodes + /// + public byte UnkIndex1; // index into the nodes + } +} \ No newline at end of file From f4647ccdbb1f23d102d13191311e9b9112699529 Mon Sep 17 00:00:00 2001 From: gulasch7742 Date: Fri, 6 Sep 2024 13:46:31 +0200 Subject: [PATCH 11/15] skel --- Warcraft.NET.Docs/Program.cs | 2 + Warcraft.NET/Files/Skel/Chunks/SKA1.cs | 74 +++++++++++++++++++++ Warcraft.NET/Files/Skel/Chunks/SKB1.cs | 75 +++++++++++++++++++++ Warcraft.NET/Files/Skel/Chunks/SKL1.cs | 75 +++++++++++++++++++++ Warcraft.NET/Files/Skel/Chunks/SKPD.cs | 91 ++++++++++++++++++++++++++ Warcraft.NET/Files/Skel/Chunks/SKS1.cs | 88 +++++++++++++++++++++++++ Warcraft.NET/Files/Skel/Skel.cs | 75 +++++++++++++++++++++ 7 files changed, 480 insertions(+) create mode 100644 Warcraft.NET/Files/Skel/Chunks/SKA1.cs create mode 100644 Warcraft.NET/Files/Skel/Chunks/SKB1.cs create mode 100644 Warcraft.NET/Files/Skel/Chunks/SKL1.cs create mode 100644 Warcraft.NET/Files/Skel/Chunks/SKPD.cs create mode 100644 Warcraft.NET/Files/Skel/Chunks/SKS1.cs create mode 100644 Warcraft.NET/Files/Skel/Skel.cs diff --git a/Warcraft.NET.Docs/Program.cs b/Warcraft.NET.Docs/Program.cs index ce9d6ff..e193afc 100644 --- a/Warcraft.NET.Docs/Program.cs +++ b/Warcraft.NET.Docs/Program.cs @@ -10,6 +10,8 @@ internal class Program /// static void Main(string[] args) { + byte[] data = File.ReadAllBytes("C:\\Users\\marce\\Desktop\\WoWStuff\\wow.export\\character\\highmountaintauren\\female/highmountaintaurenfemale.skel"); + Files.Skel.Skel skel = new Files.Skel.Skel(data); Console.WriteLine($"BaseDirectory: {AppDomain.CurrentDomain.BaseDirectory}"); if (args.Length == 0) diff --git a/Warcraft.NET/Files/Skel/Chunks/SKA1.cs b/Warcraft.NET/Files/Skel/Chunks/SKA1.cs new file mode 100644 index 0000000..34846e1 --- /dev/null +++ b/Warcraft.NET/Files/Skel/Chunks/SKA1.cs @@ -0,0 +1,74 @@ +using System.Collections.Generic; +using System.IO; +using System.Net.Mail; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.Skel.Chunks +{ + public class SKA1 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "SKA1"; + + /// + /// Gets or Sets the attachments + /// + public List Attachments { get; set; } + /// + /// Gets or Sets the AttachmentLookupTable + /// + public List AttachLookup { get; set; } + /// + /// Initializes a new instance of + /// + public SKA1() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public SKA1(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + Attachments = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); + AttachLookup = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + return null; + } + } + + private List ReadStructList(uint count, uint offset, BinaryReader br) where T : struct + { + br.BaseStream.Position = offset; + List list = new List(); + + for (var i = 0; i < count; i++) + list.Add(br.ReadStruct()); + + return list; + } + } +} diff --git a/Warcraft.NET/Files/Skel/Chunks/SKB1.cs b/Warcraft.NET/Files/Skel/Chunks/SKB1.cs new file mode 100644 index 0000000..91c8101 --- /dev/null +++ b/Warcraft.NET/Files/Skel/Chunks/SKB1.cs @@ -0,0 +1,75 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.Skel.Chunks +{ + public class SKB1 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "SKB1"; + + /// + /// Gets or Sets the bones + /// + public List Bones { get; set; } + + /// + /// Gets or Sets the KeyBoneLookupTable + /// + public List KeyBoneLookup { get; set; } + + /// + /// Initializes a new instance of + /// + public SKB1() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public SKB1(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + Bones = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); + KeyBoneLookup = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + return null; + } + } + + private List ReadStructList(uint count, uint offset, BinaryReader br) where T : struct + { + br.BaseStream.Position = offset; + List list = new List(); + + for (var i = 0; i < count; i++) + list.Add(br.ReadStruct()); + + return list; + } + } +} diff --git a/Warcraft.NET/Files/Skel/Chunks/SKL1.cs b/Warcraft.NET/Files/Skel/Chunks/SKL1.cs new file mode 100644 index 0000000..8a66bcf --- /dev/null +++ b/Warcraft.NET/Files/Skel/Chunks/SKL1.cs @@ -0,0 +1,75 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.Skel.Chunks +{ + public class SKL1 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "SKL1"; + + /// + /// Gets or Sets the Unk Field (always 256 so far, possibly flags?) + /// + public uint Unk; + + /// + /// Gets or Sets the KeyBoneLookupTable + /// + public List Name { get; set; } + + /// + /// Initializes a new instance of + /// + public SKL1() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public SKL1(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + Unk = br.ReadUInt32(); + Name = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); + uint t = br.ReadUInt32(); + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + return null; + } + } + + private List ReadStructList(uint count, uint offset, BinaryReader br) where T : struct + { + br.BaseStream.Position = offset; + List list = new List(); + + for (var i = 0; i < count; i++) + list.Add(br.ReadStruct()); + + return list; + } + } +} diff --git a/Warcraft.NET/Files/Skel/Chunks/SKPD.cs b/Warcraft.NET/Files/Skel/Chunks/SKPD.cs new file mode 100644 index 0000000..ce19fdb --- /dev/null +++ b/Warcraft.NET/Files/Skel/Chunks/SKPD.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; + +namespace Warcraft.NET.Files.Skel.Chunks +{ + public class SKPD : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "SKPD"; + + /// + /// unk + /// + public uint Unk0; + + /// + /// unk + /// + public uint Unk1; + + /// + /// unk + /// + public uint ParentSkeletonFileID; + + /// + /// unk + /// + public uint Unk2; + + /// + /// Gets or Sets the KeyBoneLookupTable + /// + public List Name { get; set; } + + /// + /// Initializes a new instance of + /// + public SKPD() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public SKPD(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + Unk0 = br.ReadUInt32(); + ParentSkeletonFileID = br.ReadUInt32(); + Unk1 = br.ReadUInt32(); + Unk2 = br.ReadUInt32(); + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + return null; + } + } + + private List ReadStructList(uint count, uint offset, BinaryReader br) where T : struct + { + br.BaseStream.Position = offset; + List list = new List(); + + for (var i = 0; i < count; i++) + list.Add(br.ReadStruct()); + + return list; + } + } +} diff --git a/Warcraft.NET/Files/Skel/Chunks/SKS1.cs b/Warcraft.NET/Files/Skel/Chunks/SKS1.cs new file mode 100644 index 0000000..d789462 --- /dev/null +++ b/Warcraft.NET/Files/Skel/Chunks/SKS1.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; +using Warcraft.NET.Files.M2.Entries; + +namespace Warcraft.NET.Files.Skel.Chunks +{ + public class SKS1 : IIFFChunk, IBinarySerializable + { + /// + /// Holds the binary chunk signature. + /// + public const string Signature = "SKS1"; + + /// + /// Gets or Sets the global sequences + /// + public List Sequences { get; set; } + + /// + /// Gets or Sets the animations + /// + public List Animations { get; set; } + + /// + /// Gets or Sets the animation lookups + /// + public List AnimationLookups { get; set; } + + /// + /// Gets or Sets the Unknown field (padding?) + /// + public UInt64 Unk { get; set; } + + /// + /// Initializes a new instance of + /// + public SKS1() { } + + /// + /// Initializes a new instance of + /// + /// ExtendedData. + public SKS1(byte[] inData) => LoadBinaryData(inData); + + /// + public string GetSignature() { return Signature; } + + /// + public uint GetSize() { return (uint)Serialize().Length; } + + /// + public void LoadBinaryData(byte[] inData) + { + using (var ms = new MemoryStream(inData)) + using (var br = new BinaryReader(ms)) + { + Sequences = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); + Animations = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); + AnimationLookups = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); + Unk = br.ReadUInt64(); + } + } + + /// + public byte[] Serialize(long offset = 0) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + return null; + } + } + + private List ReadStructList(uint count, uint offset, BinaryReader br) where T : struct + { + br.BaseStream.Position = offset; + List list = new List(); + + for (var i = 0; i < count; i++) + list.Add(br.ReadStruct()); + + return list; + } + } +} diff --git a/Warcraft.NET/Files/Skel/Skel.cs b/Warcraft.NET/Files/Skel/Skel.cs new file mode 100644 index 0000000..f2d3fb4 --- /dev/null +++ b/Warcraft.NET/Files/Skel/Skel.cs @@ -0,0 +1,75 @@ +using Warcraft.NET.Attribute; +using Warcraft.NET.Files.Skel.Chunks; +using Warcraft.NET.Files.M2.Chunks.Legion; + +namespace Warcraft.NET.Files.Skel +{ + public class Skel : ChunkedFile + { + /// + /// contains the name and unknown data of the skeleton + /// + [ChunkOrder(1)] + public SKL1 Skeleton { get; set; } + + /// + /// contains the attachments of the skeleton + /// + [ChunkOrder(2), ChunkOptional] + public SKA1 Attachments { get; set; } + + /// + /// contains the animations of the skeleton + /// + [ChunkOrder(3), ChunkOptional] + public SKS1 Animations { get; set; } + + /// + /// contains the bones of the skeleton + /// + [ChunkOrder(3), ChunkOptional] + public SKB1 Bones { get; set; } + + /// + /// contains the animations of the skeleton + /// + [ChunkOrder(4), ChunkOptional] + public SKPD ParentSkelFileID { get; set; } + + /// + /// contains the animation file ids of the skeleton + /// + [ChunkOrder(5), ChunkOptional] + public AFID AnimationFileIDs { get; set; } + + /// + /// contains the bone file ids of the skeleton + /// + [ChunkOrder(6), ChunkOptional] + public BFID BoneFileIDs { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public Skel() + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// The binary data. + public Skel(byte[] inData) : base(inData) + { + + } + public override bool IsReverseSignature() + { + return false; + } + + } +} + + From b6d460a82885b74ee26ae441d6b974d571342364 Mon Sep 17 00:00:00 2001 From: gulasch7742 Date: Sun, 8 Sep 2024 17:18:44 +0200 Subject: [PATCH 12/15] e --- Warcraft.NET.Docs/Program.cs | 6 +++-- Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs | 4 +-- Warcraft.NET/Files/Skel/Chunks/SKA1.cs | 12 ++++++--- Warcraft.NET/Files/Skel/Chunks/SKB1.cs | 10 +++++-- Warcraft.NET/Files/Skel/Chunks/SKL1.cs | 17 ++++++++---- Warcraft.NET/Files/Skel/Chunks/SKPD.cs | 19 ++++--------- Warcraft.NET/Files/Skel/Chunks/SKS1.cs | 14 +++++++--- Warcraft.NET/Files/Skel/Skel.cs | 30 ++++++++++----------- 8 files changed, 66 insertions(+), 46 deletions(-) diff --git a/Warcraft.NET.Docs/Program.cs b/Warcraft.NET.Docs/Program.cs index e193afc..92e7902 100644 --- a/Warcraft.NET.Docs/Program.cs +++ b/Warcraft.NET.Docs/Program.cs @@ -1,4 +1,5 @@ using Warcraft.NET.Docs.Steps; +using Warcraft.NET.Files.Skel; namespace Warcraft.NET.Docs { @@ -10,8 +11,9 @@ internal class Program /// static void Main(string[] args) { - byte[] data = File.ReadAllBytes("C:\\Users\\marce\\Desktop\\WoWStuff\\wow.export\\character\\highmountaintauren\\female/highmountaintaurenfemale.skel"); - Files.Skel.Skel skel = new Files.Skel.Skel(data); + byte[] data = File.ReadAllBytes(@"D:\Desktop\WoWStuff\ExtractFromGame\character\draenei\female\draeneifemale_hd.skel"); + Console.WriteLine(data.Length); + Skel skel = new Skel(data); Console.WriteLine($"BaseDirectory: {AppDomain.CurrentDomain.BaseDirectory}"); if (args.Length == 0) diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs b/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs index b3a175e..5be18b2 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using Warcraft.NET.Attribute; using Warcraft.NET.Files.Interfaces; @@ -43,7 +44,6 @@ public void LoadBinaryData(byte[] inData) using (var br = new BinaryReader(ms)) { var animCount = br.BaseStream.Length / AFIDEntry.GetSize(); - for (var i = 0; i < animCount; ++i) { AFIDEntries.Add(new AFIDEntry(br.ReadBytes(AFIDEntry.GetSize()))); diff --git a/Warcraft.NET/Files/Skel/Chunks/SKA1.cs b/Warcraft.NET/Files/Skel/Chunks/SKA1.cs index 34846e1..760f8a0 100644 --- a/Warcraft.NET/Files/Skel/Chunks/SKA1.cs +++ b/Warcraft.NET/Files/Skel/Chunks/SKA1.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using System.Net.Mail; using Warcraft.NET.Extensions; @@ -45,9 +46,14 @@ public void LoadBinaryData(byte[] inData) using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) { - Attachments = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); - AttachLookup = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); + var nAttachments = br.ReadUInt32(); + var ofsAttachments = br.ReadUInt32(); + var nAttachLookup = br.ReadUInt32(); + var ofsAttachLookup = br.ReadUInt32(); + Attachments = ReadStructList(nAttachments, ofsAttachments, br); + AttachLookup = ReadStructList(nAttachLookup, ofsAttachLookup, br); } + Console.WriteLine("Finished SKA1"); } /// diff --git a/Warcraft.NET/Files/Skel/Chunks/SKB1.cs b/Warcraft.NET/Files/Skel/Chunks/SKB1.cs index 91c8101..5d5a963 100644 --- a/Warcraft.NET/Files/Skel/Chunks/SKB1.cs +++ b/Warcraft.NET/Files/Skel/Chunks/SKB1.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using Warcraft.NET.Extensions; @@ -46,9 +47,14 @@ public void LoadBinaryData(byte[] inData) using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) { - Bones = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); - KeyBoneLookup = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); + var nBones = br.ReadUInt32(); + var ofsBones = br.ReadUInt32(); + var nKeyboneLookup = br.ReadUInt32(); + var ofsKeyboneLookup = br.ReadUInt32(); + Bones = ReadStructList(nBones, ofsBones, br); + KeyBoneLookup = ReadStructList(nKeyboneLookup, ofsKeyboneLookup, br); } + Console.WriteLine("Finished SKB1"); } /// diff --git a/Warcraft.NET/Files/Skel/Chunks/SKL1.cs b/Warcraft.NET/Files/Skel/Chunks/SKL1.cs index 8a66bcf..43d6309 100644 --- a/Warcraft.NET/Files/Skel/Chunks/SKL1.cs +++ b/Warcraft.NET/Files/Skel/Chunks/SKL1.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; @@ -15,13 +16,15 @@ public class SKL1 : IIFFChunk, IBinarySerializable /// /// Gets or Sets the Unk Field (always 256 so far, possibly flags?) /// - public uint Unk; + public uint Unk0; /// /// Gets or Sets the KeyBoneLookupTable /// public List Name { get; set; } + public uint Unk1; + /// /// Initializes a new instance of /// @@ -45,10 +48,14 @@ public void LoadBinaryData(byte[] inData) using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) { - Unk = br.ReadUInt32(); - Name = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); - uint t = br.ReadUInt32(); + Unk0 = br.ReadUInt32(); + uint count = br.ReadUInt32(); + uint offset = br.ReadUInt32(); + if(count>0) + Name = ReadStructList(count, offset, br); + Unk1 = br.ReadUInt32(); } + Console.WriteLine("Finished SKL1"); } /// diff --git a/Warcraft.NET/Files/Skel/Chunks/SKPD.cs b/Warcraft.NET/Files/Skel/Chunks/SKPD.cs index ce19fdb..2005215 100644 --- a/Warcraft.NET/Files/Skel/Chunks/SKPD.cs +++ b/Warcraft.NET/Files/Skel/Chunks/SKPD.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using Warcraft.NET.Extensions; using Warcraft.NET.Files.Interfaces; @@ -60,11 +61,12 @@ public void LoadBinaryData(byte[] inData) using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) { - Unk0 = br.ReadUInt32(); - ParentSkeletonFileID = br.ReadUInt32(); + Unk0 = br.ReadUInt32(); Unk1 = br.ReadUInt32(); + ParentSkeletonFileID = br.ReadUInt32(); Unk2 = br.ReadUInt32(); } + Console.WriteLine("Finished SKPD"); } /// @@ -76,16 +78,5 @@ public byte[] Serialize(long offset = 0) return null; } } - - private List ReadStructList(uint count, uint offset, BinaryReader br) where T : struct - { - br.BaseStream.Position = offset; - List list = new List(); - - for (var i = 0; i < count; i++) - list.Add(br.ReadStruct()); - - return list; - } } } diff --git a/Warcraft.NET/Files/Skel/Chunks/SKS1.cs b/Warcraft.NET/Files/Skel/Chunks/SKS1.cs index d789462..0982c64 100644 --- a/Warcraft.NET/Files/Skel/Chunks/SKS1.cs +++ b/Warcraft.NET/Files/Skel/Chunks/SKS1.cs @@ -57,11 +57,19 @@ public void LoadBinaryData(byte[] inData) using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) { - Sequences = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); - Animations = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); - AnimationLookups = ReadStructList(br.ReadUInt32(), br.ReadUInt32(), br); + var nSequences = br.ReadUInt32(); + var ofsSequences = br.ReadUInt32(); + var nAnimations = br.ReadUInt32(); + var ofsAnimations = br.ReadUInt32(); + var nAnimationLookup = br.ReadUInt32(); + var ofsAnimationLookup = br.ReadUInt32(); Unk = br.ReadUInt64(); + Sequences = ReadStructList(nSequences, ofsSequences, br); + Animations = ReadStructList(nAnimations, ofsAnimations, br); + AnimationLookups = ReadStructList(nAnimationLookup, ofsAnimationLookup, br); } + Console.WriteLine("Finished SKS1"); + } /// diff --git a/Warcraft.NET/Files/Skel/Skel.cs b/Warcraft.NET/Files/Skel/Skel.cs index f2d3fb4..0d64f5b 100644 --- a/Warcraft.NET/Files/Skel/Skel.cs +++ b/Warcraft.NET/Files/Skel/Skel.cs @@ -13,39 +13,39 @@ public class Skel : ChunkedFile public SKL1 Skeleton { get; set; } /// - /// contains the attachments of the skeleton + /// contains the animations of the skeleton /// - [ChunkOrder(2), ChunkOptional] - public SKA1 Attachments { get; set; } + [ChunkOptional] + public SKS1 Animations { get; set; } /// - /// contains the animations of the skeleton + /// contains the attachments of the skeleton /// - [ChunkOrder(3), ChunkOptional] - public SKS1 Animations { get; set; } + [ChunkOptional] + public SKA1 Attachments { get; set; } /// /// contains the bones of the skeleton /// - [ChunkOrder(3), ChunkOptional] + [ChunkOptional] public SKB1 Bones { get; set; } - + /// - /// contains the animations of the skeleton + /// contains the animation file ids of the skeleton /// - [ChunkOrder(4), ChunkOptional] - public SKPD ParentSkelFileID { get; set; } + [ChunkOptional] + public AFID AnimationFileIDs { get; set; } /// - /// contains the animation file ids of the skeleton + /// contains the animations of the skeleton /// - [ChunkOrder(5), ChunkOptional] - public AFID AnimationFileIDs { get; set; } + [ChunkOptional] + public SKPD ParentSkelFileID { get; set; } /// /// contains the bone file ids of the skeleton /// - [ChunkOrder(6), ChunkOptional] + [ChunkOptional] public BFID BoneFileIDs { get; set; } /// From f65726a82aaee8881830ca82190e4678f5a766ec Mon Sep 17 00:00:00 2001 From: gulasch7742 Date: Tue, 17 Sep 2024 17:14:24 +0200 Subject: [PATCH 13/15] fixes --- Warcraft.NET.Docs/Program.cs | 3 -- Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs | 2 +- Warcraft.NET/Files/Phys/Enums/BodyType.cs | 6 +-- Warcraft.NET/Files/Phys/Enums/JointType.cs | 12 +++--- Warcraft.NET/Files/Phys/Enums/ShapeType.cs | 8 ++-- Warcraft.NET/Files/SKIN/Skin.cs | 47 +++++---------------- Warcraft.NET/Files/phys/Chunks/PLYT.cs | 2 - 7 files changed, 25 insertions(+), 55 deletions(-) diff --git a/Warcraft.NET.Docs/Program.cs b/Warcraft.NET.Docs/Program.cs index 92e7902..b4dde70 100644 --- a/Warcraft.NET.Docs/Program.cs +++ b/Warcraft.NET.Docs/Program.cs @@ -11,9 +11,6 @@ internal class Program /// static void Main(string[] args) { - byte[] data = File.ReadAllBytes(@"D:\Desktop\WoWStuff\ExtractFromGame\character\draenei\female\draeneifemale_hd.skel"); - Console.WriteLine(data.Length); - Skel skel = new Skel(data); Console.WriteLine($"BaseDirectory: {AppDomain.CurrentDomain.BaseDirectory}"); if (args.Length == 0) diff --git a/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs b/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs index bd4815b..52fbf28 100644 --- a/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs +++ b/Warcraft.NET/Files/M2/Chunks/Legion/EXPT.cs @@ -12,7 +12,7 @@ public class EXPT : IIFFChunk, IBinarySerializable /// /// Holds the binary chunk signature. /// - public const string Signature = "EXP2"; + public const string Signature = "EXPT"; /// /// Gets or sets the EXPT Entries diff --git a/Warcraft.NET/Files/Phys/Enums/BodyType.cs b/Warcraft.NET/Files/Phys/Enums/BodyType.cs index 5908459..070e59b 100644 --- a/Warcraft.NET/Files/Phys/Enums/BodyType.cs +++ b/Warcraft.NET/Files/Phys/Enums/BodyType.cs @@ -2,8 +2,8 @@ { public enum BodyType : ushort { - root = 0, - dynamic = 1, - unk = 2, + Root = 0, + Dynamic = 1, + Unk = 2, } } diff --git a/Warcraft.NET/Files/Phys/Enums/JointType.cs b/Warcraft.NET/Files/Phys/Enums/JointType.cs index e7f605d..0ea6327 100644 --- a/Warcraft.NET/Files/Phys/Enums/JointType.cs +++ b/Warcraft.NET/Files/Phys/Enums/JointType.cs @@ -2,11 +2,11 @@ { public enum JointType : ushort { - sphericalJoint = 0, - shoulderJoint = 1, - weldJoint = 2, - revoluteJoint = 3, - prismaticJoint = 4, - distanceJoint = 5, + SphericalJoint = 0, + ShoulderJoint = 1, + WeldJoint = 2, + RevoluteJoint = 3, + PrismaticJoint = 4, + DistanceJoint = 5, } } diff --git a/Warcraft.NET/Files/Phys/Enums/ShapeType.cs b/Warcraft.NET/Files/Phys/Enums/ShapeType.cs index 290f93f..1f599e5 100644 --- a/Warcraft.NET/Files/Phys/Enums/ShapeType.cs +++ b/Warcraft.NET/Files/Phys/Enums/ShapeType.cs @@ -2,9 +2,9 @@ { public enum ShapeType : short { - box = 0, - caps = 1, - sphere = 2, - polytope = 3, + Box = 0, + Caps = 1, + Sphere = 2, + Polytope = 3, } } diff --git a/Warcraft.NET/Files/SKIN/Skin.cs b/Warcraft.NET/Files/SKIN/Skin.cs index 58d2c95..10e4511 100644 --- a/Warcraft.NET/Files/SKIN/Skin.cs +++ b/Warcraft.NET/Files/SKIN/Skin.cs @@ -52,8 +52,6 @@ public class Skin /// public byte[] Unk0; - public bool Wotlk = false; - public Skin(byte[] inData) { using (var ms = new MemoryStream(inData)) @@ -64,10 +62,6 @@ public Skin(byte[] inData) var ofsVertices = br.ReadUInt32(); var nIndices = br.ReadUInt32(); var ofsIndices = br.ReadUInt32(); - if (ofsVertices == 48) - { - Wotlk = true; - } var nBones = br.ReadUInt32(); var ofsBones = br.ReadUInt32(); var nSubmeshes = br.ReadUInt32(); @@ -78,13 +72,10 @@ public Skin(byte[] inData) ShadowBatches = new List(); Unk0 = new byte[8]; - if (!Wotlk) - { - var nShadow_batches = br.ReadUInt32(); - var ofsShadow_batches = br.ReadUInt32(); - Unk0 = br.ReadBytes(8); - ShadowBatches = ReadStructList(nShadow_batches, ofsShadow_batches, br); - } + var nShadow_batches = br.ReadUInt32(); + var ofsShadow_batches = br.ReadUInt32(); + Unk0 = br.ReadBytes(8); + ShadowBatches = ReadStructList(nShadow_batches, ofsShadow_batches, br); Vertices = ReadStructList(nVertices, ofsVertices, br); Triangles = ReadStructList(nIndices / 3, ofsIndices, br); BoneIndices = ReadStructList(nBones, ofsBones, br); @@ -109,16 +100,7 @@ public byte[] Serialize(long offset = 0) using (var ms = new MemoryStream()) using (var bw = new BinaryWriter(ms)) { - //Writing Empty Header -> Filling with data after writing the data - if (Wotlk) - { - bw.Write(new byte[48]); - } - else - { - bw.Write(new byte[64]); - } - + bw.Write(new byte[64]); foreach (ushort vertex in Vertices) { bw.Write(vertex); @@ -149,12 +131,9 @@ public byte[] Serialize(long offset = 0) } int _ofsShadowBatches = (int)bw.BaseStream.Position; - if (!Wotlk) + foreach (M2ShadowBatch shadowBatch in ShadowBatches) { - foreach (M2ShadowBatch shadowBatch in ShadowBatches) - { - bw.WriteStruct(shadowBatch); - } + bw.WriteStruct(shadowBatch); } //Writing actual header data bw.BaseStream.Position = 0; @@ -165,8 +144,7 @@ public byte[] Serialize(long offset = 0) bw.Write(Vertices.Count); var _ofsVertices = 64; - if (Wotlk) - _ofsVertices = 48; + _ofsVertices = 48; bw.Write(_ofsVertices); bw.Write(Triangles.Count * 3); @@ -183,12 +161,9 @@ public byte[] Serialize(long offset = 0) bw.Write(GlobalVertexOffset); - if (!Wotlk) - { - bw.Write(ShadowBatches.Count); - bw.Write(_ofsShadowBatches); - bw.Write(Unk0); - } + bw.Write(ShadowBatches.Count); + bw.Write(_ofsShadowBatches); + bw.Write(Unk0); return ms.ToArray(); } } diff --git a/Warcraft.NET/Files/phys/Chunks/PLYT.cs b/Warcraft.NET/Files/phys/Chunks/PLYT.cs index 12fd612..1316870 100644 --- a/Warcraft.NET/Files/phys/Chunks/PLYT.cs +++ b/Warcraft.NET/Files/phys/Chunks/PLYT.cs @@ -66,13 +66,11 @@ public byte[] Serialize(long offset = 0) bw.Write((uint)PLYTEntries.Count); foreach (PLYTEntry obj in PLYTEntries) { - Console.WriteLine("Writing Plyt Header Length: " + obj.SerializeHeader().Length); bw.Write(obj.SerializeHeader()); } foreach (PLYTEntry obj in PLYTEntries) { bw.Write(obj.SerializeData()); - Console.WriteLine("Writing Plyt Data Length:" + obj.SerializeData().Length); } return ms.ToArray(); } From d6e9ed102f633ae2704b4541d3513d5f500eb23e Mon Sep 17 00:00:00 2001 From: gulasch7742 Date: Tue, 17 Sep 2024 17:18:32 +0200 Subject: [PATCH 14/15] updates --- Warcraft.NET/Files/phys/Enums/BodyType.cs | 6 +++--- Warcraft.NET/Files/phys/Enums/JointType.cs | 12 ++++++------ Warcraft.NET/Files/phys/Enums/ShapeType.cs | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Warcraft.NET/Files/phys/Enums/BodyType.cs b/Warcraft.NET/Files/phys/Enums/BodyType.cs index 5908459..070e59b 100644 --- a/Warcraft.NET/Files/phys/Enums/BodyType.cs +++ b/Warcraft.NET/Files/phys/Enums/BodyType.cs @@ -2,8 +2,8 @@ { public enum BodyType : ushort { - root = 0, - dynamic = 1, - unk = 2, + Root = 0, + Dynamic = 1, + Unk = 2, } } diff --git a/Warcraft.NET/Files/phys/Enums/JointType.cs b/Warcraft.NET/Files/phys/Enums/JointType.cs index e7f605d..0ea6327 100644 --- a/Warcraft.NET/Files/phys/Enums/JointType.cs +++ b/Warcraft.NET/Files/phys/Enums/JointType.cs @@ -2,11 +2,11 @@ { public enum JointType : ushort { - sphericalJoint = 0, - shoulderJoint = 1, - weldJoint = 2, - revoluteJoint = 3, - prismaticJoint = 4, - distanceJoint = 5, + SphericalJoint = 0, + ShoulderJoint = 1, + WeldJoint = 2, + RevoluteJoint = 3, + PrismaticJoint = 4, + DistanceJoint = 5, } } diff --git a/Warcraft.NET/Files/phys/Enums/ShapeType.cs b/Warcraft.NET/Files/phys/Enums/ShapeType.cs index 290f93f..1f599e5 100644 --- a/Warcraft.NET/Files/phys/Enums/ShapeType.cs +++ b/Warcraft.NET/Files/phys/Enums/ShapeType.cs @@ -2,9 +2,9 @@ { public enum ShapeType : short { - box = 0, - caps = 1, - sphere = 2, - polytope = 3, + Box = 0, + Caps = 1, + Sphere = 2, + Polytope = 3, } } From b7e866b6f7582d3454569a88be9e1ea11e8ad04a Mon Sep 17 00:00:00 2001 From: gulasch7742 Date: Tue, 17 Sep 2024 17:22:54 +0200 Subject: [PATCH 15/15] Delete Mat3x4.cs --- Warcraft.NET/Files/Structures/Mat3x4.cs | 54 ------------------------- 1 file changed, 54 deletions(-) delete mode 100644 Warcraft.NET/Files/Structures/Mat3x4.cs diff --git a/Warcraft.NET/Files/Structures/Mat3x4.cs b/Warcraft.NET/Files/Structures/Mat3x4.cs deleted file mode 100644 index 0b28133..0000000 --- a/Warcraft.NET/Files/Structures/Mat3x4.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Warcraft.NET.Files.Interfaces; -using Warcraft.NET.Files.Structures; -using System.Numerics; - -public class Mat3x4 : IFlattenableData -{ - - public C3Vector a { get; set; } - public C3Vector b { get; set; } - public C3Vector c { get; set; } - public C3Vector d { get; set; } - - public Mat3x4(byte[] input) - { - if (input.Length == 48) - { - a = new C3Vector(input.Take(12).ToArray()); - b = new C3Vector(input.Skip(12).Take(12).ToArray()); - c = new C3Vector(input.Skip(24).Take(12).ToArray()); - d = new C3Vector(input.Skip(36).Take(12).ToArray()); - - } - } - - public Mat3x4(float[] input) - { - if (input.Length == 12) - { - a = new C3Vector(input[0], input[1], input[2]); - b = new C3Vector(input[3], input[4], input[5]); - c = new C3Vector(input[6], input[7], input[8]); - d = new C3Vector(input[9], input[10], input[11]); - } - } - public Mat3x4(C3Vector _a, C3Vector _b, C3Vector _c, C3Vector _d) - { - a = _a; - b = _b; - c = _c; - d = _d; - } - - public byte[] asBytes(){ - return a.asBytes().Concat(b.asBytes()).Concat(c.asBytes()).Concat(d.asBytes()).ToArray(); - } - - public IReadOnlyCollection Flatten() - { - return new[] { a.X, a.Y, a.Z, b.X, b.Y, b.Z, c.X, c.Y, c.Z, d.X, d.Y, d.Z }; - } -} \ No newline at end of file