Skip to content

Commit

Permalink
Merge pull request #7 from Marlamin/master
Browse files Browse the repository at this point in the history
Add initial support for LOD ADT
  • Loading branch information
Luzifix committed Jul 16, 2024
2 parents fecbd5d + 51ca8db commit 5fe4919
Show file tree
Hide file tree
Showing 29 changed files with 1,921 additions and 14 deletions.
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

0 comments on commit 5fe4919

Please sign in to comment.