Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Phys File Type, Added more M2 chunks (some unfinished), changed some smaller things #11

Merged
merged 17 commits into from
Sep 22, 2024
26 changes: 26 additions & 0 deletions Warcraft.NET.Docs/ChunkAvailability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
4 changes: 4 additions & 0 deletions Warcraft.NET.Docs/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Warcraft.NET.Docs.Steps;
using Warcraft.NET.Files.M2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removes because there are not needed here

using Warcraft.NET.Files.phys;
using Warcraft.NET.Files.SKIN;

namespace Warcraft.NET.Docs
{
Expand Down Expand Up @@ -28,6 +31,7 @@ static void Main(string[] args)
ConvertToMarkdownStep.Process(autoDocData, outputFolder);

Console.WriteLine("Done!");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to reduce unnecessary spaces.

}
}
}
27 changes: 27 additions & 0 deletions Warcraft.NET/Extensions/ExtendedIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Numerics;
using Warcraft.NET.Exceptions;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Warcraft.NET.Extensions
{
Expand Down Expand Up @@ -410,6 +411,32 @@ public static void WriteChunkSignature(this BinaryWriter binaryWriter, string si
}
}

/// <summary>
/// Writes a struct to the BinaryWriter.
/// </summary>
/// <typeparam name="T">The type of struct to write.</typeparam>
/// <param name="binaryWriter">The BinaryWriter instance.</param>
/// <param name="value">The struct value to write.</param>
public static void WriteStruct<T>(this BinaryWriter binaryWriter, T value) where T : struct
{
int size = Marshal.SizeOf<T>();
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);
}

/// <summary>
/// Writes a 12-byte <see cref="Rotator"/> value to the data stream in Pitch/Yaw/Roll order.
/// </summary>
Expand Down
71 changes: 71 additions & 0 deletions Warcraft.NET/Files/M2/Chunks/BfA/LDV1.cs
Original file line number Diff line number Diff line change
@@ -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.BfA
{
[AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterLegion, AutoDocChunkVersionHelper.VersionBeforeBfA)]
public class LDV1 : IIFFChunk, IBinarySerializable
{
/// <summary>
/// Holds the binary chunk signature.
/// </summary>
public const string Signature = "LDV1";

/// <summary>
/// Gets or sets the Skin FileDataId
Luzifix marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public List<LDV1Entry> LDV1Entries = new();

/// <summary>
/// Initializes a new instance of <see cref="LDV1"/>
/// </summary>
public LDV1() { }

/// <summary>
/// Initializes a new instance of <see cref="LDV1"/>
/// </summary>
/// <param name="inData">ExtendedData.</param>
public LDV1(byte[] inData) => LoadBinaryData(inData);

/// <inheritdoc />
public string GetSignature() { return Signature; }

/// <inheritdoc />
public uint GetSize() { return (uint)Serialize().Length; }

/// <inheritdoc />
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())));
}
}
}
}

/// <inheritdoc />
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();
}
}

Luzifix marked this conversation as resolved.
Show resolved Hide resolved
}
}
62 changes: 62 additions & 0 deletions Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs
Original file line number Diff line number Diff line change
@@ -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)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the parsing of the chunk struct is not implemented we dont add the AutoDocChunk.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove
[AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterLegion, AutoDocChunkVersionHelper.VersionBeforeBfA)]

public class WFV1 : IIFFChunk, IBinarySerializable
{
/// <summary>
/// Holds the binary chunk signature.
/// </summary>
public const string Signature = "WFV1";

public byte[] data;
Luzifix marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Initializes a new instance of <see cref="WFV1"/>
/// </summary>
public WFV1() { }

/// <summary>
/// Initializes a new instance of <see cref="WFV1"/>
/// </summary>
/// <param name="inData">ExtendedData.</param>
public WFV1(byte[] inData) => LoadBinaryData(inData);

/// <inheritdoc />
public string GetSignature() { return Signature; }

/// <inheritdoc />
public uint GetSize() { return (uint)Serialize().Length; }

/// <inheritdoc />
public void LoadBinaryData(byte[] inData)
{
{
using (var ms = new MemoryStream(inData))
using (var br = new BinaryReader(ms))
{
data = inData;
Luzifix marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

/// <inheritdoc />
public byte[] Serialize(long offset = 0)
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
bw.Write(data);


Luzifix marked this conversation as resolved.
Show resolved Hide resolved
return ms.ToArray();
}
}

}
}
62 changes: 62 additions & 0 deletions Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs
Original file line number Diff line number Diff line change
@@ -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)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the parsing of the chunk struct is not implemented we dont add the AutoDocChunk.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove
[AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterLegion, AutoDocChunkVersionHelper.VersionBeforeBfA)]

public class WFV2 : IIFFChunk, IBinarySerializable
{
/// <summary>
/// Holds the binary chunk signature.
/// </summary>
public const string Signature = "WFV2";

public byte[] data;
Luzifix marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Initializes a new instance of <see cref="WFV2"/>
/// </summary>
public WFV2() { }

/// <summary>
/// Initializes a new instance of <see cref="WFV2"/>
/// </summary>
/// <param name="inData">ExtendedData.</param>
public WFV2(byte[] inData) => LoadBinaryData(inData);

/// <inheritdoc />
public string GetSignature() { return Signature; }

/// <inheritdoc />
public uint GetSize() { return (uint)Serialize().Length; }

/// <inheritdoc />
public void LoadBinaryData(byte[] inData)
{
{
using (var ms = new MemoryStream(inData))
Luzifix marked this conversation as resolved.
Show resolved Hide resolved
using (var br = new BinaryReader(ms))
{
data = inData;
}
}
}

/// <inheritdoc />
public byte[] Serialize(long offset = 0)
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
bw.Write(data);


Luzifix marked this conversation as resolved.
Show resolved Hide resolved
return ms.ToArray();
}
}

}
}
58 changes: 58 additions & 0 deletions Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs
Original file line number Diff line number Diff line change
@@ -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
Luzifix marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// Holds the binary chunk signature.
/// </summary>
public const string Signature = "AFRA";

/// <summary>
/// Initializes a new instance of <see cref="AFRA"/>
/// </summary>
public AFRA() { }

/// <summary>
/// Initializes a new instance of <see cref="AFRA"/>
/// </summary>
/// <param name="inData">ExtendedData.</param>
public AFRA(byte[] inData) => LoadBinaryData(inData);

/// <inheritdoc />
public string GetSignature() { return Signature; }

/// <inheritdoc />
public uint GetSize() { return (uint)Serialize().Length; }

byte[] data;
Luzifix marked this conversation as resolved.
Show resolved Hide resolved

/// <inheritdoc/>
public void LoadBinaryData(byte[] inData)
{
using (var ms = new MemoryStream(inData))
Luzifix marked this conversation as resolved.
Show resolved Hide resolved
using (var br = new BinaryReader(ms))
{
data = inData;
}
}

/// <inheritdoc/>
public byte[] Serialize(long offset = 0)
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
bw.Write(data);

return ms.ToArray();
}
}
}
}
Loading
Loading