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

Add initial support for LOD ADT #7

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions Warcraft.NET/Files/ADT/Chunks/Legion/MBBB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System.Collections.Generic;
using System.IO;
using Warcraft.NET.Files.ADT.Entries.Legion;
using Warcraft.NET.Files.Interfaces;

namespace Warcraft.NET.Files.ADT.Chunks.Legion
{
/// <summary>
/// MBBB Chunk - Level of detail
/// </summary>
public class MBBB : IIFFChunk, IBinarySerializable
{
/// <summary>
/// Holds the binary chunk signature.
/// </summary>
public const string Signature = "MBBB";

/// <summary>
/// Gets or sets <see cref="MBBBEntry"/>s.
/// </summary>
public List<MBBBEntry> MBBBEntries { get; set; } = [];

/// <summary>
/// Initializes a new instance of the <see cref="MBBB"/> class.
/// </summary>
public MBBB()
{
}

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

/// <inheritdoc/>
public void LoadBinaryData(byte[] inData)
{
using (var ms = new MemoryStream(inData))
using (var br = new BinaryReader(ms))
{
var mbbbCount = br.BaseStream.Length / MBBBEntry.GetSize();
for (var i = 0; i < mbbbCount; ++i)
{
MBBBEntries.Add(new MBBBEntry(br.ReadBytes(MBBBEntry.GetSize())));
}
}
}

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

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

/// <inheritdoc/>
public byte[] Serialize(long offset = 0)
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
foreach (var mbbb in MBBBEntries)
{
bw.Write(mbbb.Serialize());
}
return ms.ToArray();
}
}
}
}
78 changes: 78 additions & 0 deletions Warcraft.NET/Files/ADT/Chunks/Legion/MBMB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System.Collections.Generic;
using System.IO;
using Warcraft.NET.Files.Interfaces;

namespace Warcraft.NET.Files.ADT.Chunks.Legion
{
/// <summary>
/// MBMB Chunk - Level of detail
/// </summary>
public class MBMB : IIFFChunk, IBinarySerializable
{
/// <summary>
/// Holds the binary chunk signature.
/// </summary>
public const string Signature = "MBMB";

/// <summary>
/// Unknown array with 20 byte elements.
/// </summary>
public List<byte[]> Entries = [];

/// <summary>
/// Initializes a new instance of the <see cref="MBMB"/> class.
/// </summary>
public MBMB()
{
}

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

/// <inheritdoc/>
public void LoadBinaryData(byte[] inData)
{
using (var ms = new MemoryStream(inData))
using (var br = new BinaryReader(ms))
{
var mbmbCount = br.BaseStream.Length / 20;
for (var i = 0; i < mbmbCount; ++i)
{
Entries.Add(br.ReadBytes(20));
}
}
}

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

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

/// <inheritdoc/>
public byte[] Serialize(long offset = 0)
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
foreach (var entry in Entries)
{
bw.Write(entry);
}
return ms.ToArray();
}
}
}
}
80 changes: 80 additions & 0 deletions Warcraft.NET/Files/ADT/Chunks/Legion/MBMH.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System.Collections.Generic;
using System.IO;
using Warcraft.NET.Files.ADT.Entries.Legion;
using Warcraft.NET.Files.Interfaces;

namespace Warcraft.NET.Files.ADT.Chunks.Legion
{
/// <summary>
/// MBMH Chunk - Level of detail
/// </summary>
public class MBMH : IIFFChunk, IBinarySerializable
{
/// <summary>
/// Holds the binary chunk signature.
/// </summary>
public const string Signature = "MBMH";

/// <summary>
/// Gets or sets <see cref="MBMHEntry"/>s.
/// </summary>
public List<MBMHEntry> MBMHEntries { get; set; } = [];

/// <summary>
/// Initializes a new instance of the <see cref="MBMH"/> class.
/// </summary>
public MBMH()
{
}

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

/// <inheritdoc/>
public void LoadBinaryData(byte[] inData)
{
using (var ms = new MemoryStream(inData))
using (var br = new BinaryReader(ms))
{
var objCount = br.BaseStream.Length / MBMHEntry.GetSize();

for (var i = 0; i < objCount; ++i)
{
MBMHEntries.Add(new MBMHEntry(br.ReadBytes(MBMHEntry.GetSize())));
}
}
}

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

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

/// <inheritdoc/>
public byte[] Serialize(long offset = 0)
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
foreach (var mbmhEntry in MBMHEntries)
{
bw.Write(mbmhEntry.Serialize());
}
return ms.ToArray();
}
}
}
}
79 changes: 79 additions & 0 deletions Warcraft.NET/Files/ADT/Chunks/Legion/MBMI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System.IO;
using Warcraft.NET.Files.Interfaces;

namespace Warcraft.NET.Files.ADT.Chunks.Legion
{
/// <summary>
/// MBMI Chunk - Level of detail
/// </summary>
public class MBMI : IIFFChunk, IBinarySerializable
{
/// <summary>
/// Holds the binary chunk signature.
/// </summary>
public const string Signature = "MBMI";

/// <summary>
/// Blend Mesh indices.
/// </summary>
public ushort[] BlendMeshIndices { get; set; }


/// <summary>
/// Initializes a new instance of the <see cref="MBMI"/> class.
/// </summary>
public MBMI()
{
}

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

/// <inheritdoc/>
public void LoadBinaryData(byte[] inData)
{
using (var ms = new MemoryStream(inData))
using (var br = new BinaryReader(ms))
{
var count = (int)(ms.Length / 2);
BlendMeshIndices = new ushort[count];
for (var i = 0; i < count; i++)
{
BlendMeshIndices[i] = br.ReadUInt16();
}
}
}

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

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

/// <inheritdoc/>
public byte[] Serialize(long offset = 0)
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
foreach (var index in BlendMeshIndices)
{
bw.Write(index);
}
return ms.ToArray();
}
}
}
}
Loading