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

More _lgt.wdt reading, empty WDT constructors, make BLP mipmaps optional #6

Merged
merged 7 commits into from
Jul 15, 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
17 changes: 11 additions & 6 deletions Warcraft.NET/Files/BLP/BLP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ public BLP(Image<Rgba32> image, TextureCompressionType compressionType)
/// </summary>
/// <param name="image">Image.</param>
/// <param name="pixelFormat">Only DXT pixel format!</param>
public BLP(Image<Rgba32> image, BLPPixelFormat pixelFormat)
/// <param name="makeMipMaps">If set to true, make mipmaps.</param>
public BLP(Image<Rgba32> image, BLPPixelFormat pixelFormat, bool makeMipMaps = true)
{
if (pixelFormat != BLPPixelFormat.DXT1 && pixelFormat != BLPPixelFormat.DXT3 && pixelFormat != BLPPixelFormat.DXT5)
throw new ArgumentException("This constructor only support DXT pixel format!");
Expand All @@ -256,7 +257,7 @@ public BLP(Image<Rgba32> image, BLPPixelFormat pixelFormat)
Header.Resolution = new Resolution((uint)image.Width, (uint)image.Height);

// It's now time to compress the image
_rawMipMaps = CompressImage(image);
_rawMipMaps = CompressImage(image, makeMipMaps);

// Calculate the offsets and sizes
var mipOffset = (uint)(Header.GetSize() + (_palette.Count * 4));
Expand Down Expand Up @@ -534,7 +535,8 @@ private Image<Rgba32> DecompressMipMap(byte[] inData, uint mipLevel)
/// </summary>
/// <returns>The compressed image data.</returns>
/// <param name="inImage">The image to be compressed.</param>
private List<byte[]> CompressImage(Image<Rgba32> inImage)
/// <param name="makeMipMaps">If set to true, make mipmaps.</param>
private List<byte[]> CompressImage(Image<Rgba32> inImage, bool makeMipMaps = true)
{
var mipMaps = new List<byte[]>();

Expand All @@ -548,10 +550,13 @@ private List<byte[]> CompressImage(Image<Rgba32> inImage)
// Add the original image as the first mipmap
mipMaps.Add(CompressImage(inImage, 0));

// Then, compress the image N amount of times into mipmaps
for (uint i = 1; i < GetNumReasonableMipMapLevels(); ++i)
// Then, if needed, compress the image N amount of times into mipmaps
if (makeMipMaps)
{
mipMaps.Add(CompressImage(inImage, i));
for (uint i = 1; i < GetNumReasonableMipMapLevels(); ++i)
{
mipMaps.Add(CompressImage(inImage, i));
}
}

return mipMaps;
Expand Down
80 changes: 80 additions & 0 deletions Warcraft.NET/Files/WDT/Chunks/Legion/MLTA.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Warcraft.NET.Files.Interfaces;
using Warcraft.NET.Files.WDT.Entries.Legion;

namespace Warcraft.NET.Files.WDT.Chunks.Legion
{
/// <summary>
/// MLTA Chunk - Contains light animations
/// </summary>
public class MLTA : IIFFChunk, IBinarySerializable
{
/// <summary>
/// Holds the binary chunk signature.
/// </summary>
public const string Signature = "MLTA";

public List<MLTAEntry> Entries = new();

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

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

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

for (var i = 0; i < mltaCount; ++i)
{
Entries.Add(new MLTAEntry(br.ReadBytes(MLTAEntry.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 (MLTAEntry mltaEntry in Entries)
{
bw.Write(mltaEntry.Serialize());
}

return ms.ToArray();
}
}
}
}
8 changes: 4 additions & 4 deletions Warcraft.NET/Files/WDT/Chunks/Legion/MPL2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Warcraft.NET.Files.WDT.Chunks.Legion
{
/// <summary>
/// MPLT Chunk - Contains Legion light placement information
/// MPL2 Chunk - Contains Legion point light information
/// </summary>
public class MPL2 : IIFFChunk, IBinarySerializable
{
Expand All @@ -15,7 +15,7 @@ public class MPL2 : IIFFChunk, IBinarySerializable
/// </summary>
public const string Signature = "MPL2";

public List<MPL2Entry> Entries = new();
public List<MPL2Entry> Entries = [];

/// <summary>
/// Initializes a new instance of the <see cref="MPL2"/> class.
Expand All @@ -39,9 +39,9 @@ public void LoadBinaryData(byte[] inData)
using (var ms = new MemoryStream(inData))
using (var br = new BinaryReader(ms))
{
var mpltCount = br.BaseStream.Length / MPL2Entry.GetSize();
var mpl2Count = br.BaseStream.Length / MPL2Entry.GetSize();

for (var i = 0; i < mpltCount; ++i)
for (var i = 0; i < mpl2Count; ++i)
{
Entries.Add(new MPL2Entry(br.ReadBytes(MPL2Entry.GetSize())));
}
Expand Down
77 changes: 77 additions & 0 deletions Warcraft.NET/Files/WDT/Chunks/Legion/MTEX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System.Collections.Generic;
using System.IO;
using Warcraft.NET.Files.Interfaces;

namespace Warcraft.NET.Files.WDT.Chunks.Legion
{
/// <summary>
/// MTEX Chunk - Contains textures used for lights
/// </summary>
public class MTEX : IIFFChunk, IBinarySerializable
{
/// <summary>
/// Holds the binary chunk signature.
/// </summary>
public const string Signature = "MTEX";

public List<uint> Entries = [];

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

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

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

for (var i = 0; i < textureCount; ++i)
{
Entries.Add(br.ReadUInt32());
}
}
}

/// <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 texture in Entries)
{
bw.Write(texture);
}

return ms.ToArray();
}
}
}
}
78 changes: 78 additions & 0 deletions Warcraft.NET/Files/WDT/Chunks/SL/MPL3.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;
using Warcraft.NET.Files.WDT.Entries.SL;

namespace Warcraft.NET.Files.WDT.Chunks.SL
{
/// <summary>
/// MPL3 Chunk - Contains Shadowlands point light information
/// </summary>
public class MPL3 : IIFFChunk, IBinarySerializable
{
/// <summary>
/// Holds the binary chunk signature.
/// </summary>
public const string Signature = "MPL3";

public List<MPL3Entry> Entries = new();

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

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

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

for (var i = 0; i < mpl3Count; ++i)
{
Entries.Add(new MPL3Entry(br.ReadBytes(MPL3Entry.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 (MPL3Entry mpl3Entry in Entries)
{
bw.Write(mpl3Entry.Serialize());
}

return ms.ToArray();
}
}
}
}
2 changes: 1 addition & 1 deletion Warcraft.NET/Files/WDT/Chunks/WoD/MAOI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Warcraft.NET.Files.WDT.Chunks.WoD
{
/// <summary>
/// MAOH Chunk - Contains occlusion heighmap
/// MAOH Chunk - Contains occlusion heightmap
/// </summary>
public class MAOH : IIFFChunk, IBinarySerializable
{
Expand Down
71 changes: 71 additions & 0 deletions Warcraft.NET/Files/WDT/Entries/Legion/MLTAEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System.IO;

namespace Warcraft.NET.Files.WDT.Entries.Legion
{
/// <summary>
/// An entry struct containing light animations
/// </summary>
public class MLTAEntry
{
/// <summary>
/// Flicker intensity
/// </summary>
public float FlickerIntensity { get; set; }

/// <summary>
/// Flicker intensity
/// </summary>
public float FlickerSpeed { get; set; }

/// <summary>
/// Flicker mode
/// 0 = off, 1 = sine curve, 2 = noise curve, 3 = noise step curve
/// </summary>
public int FlickerMode { get; set; }

public MLTAEntry() { }

/// <summary>
/// Initializes a new instance of the <see cref="MLTAEntry"/> class.
/// </summary>
/// <param name="data">ExtendedData.</param>
public MLTAEntry(byte[] data)
{
using (var ms = new MemoryStream(data))
{
using (var br = new BinaryReader(ms))
{
FlickerIntensity = br.ReadSingle();
FlickerSpeed = br.ReadSingle();
FlickerMode = br.ReadInt32();
}
}
}

/// <summary>
/// Gets the size of an entry.
/// </summary>
/// <returns>The size.</returns>
public static int GetSize()
{
return 12;
}

/// <summary>
/// Gets the size of the data contained in this chunk.
/// </summary>
/// <returns>The size.</returns>
public byte[] Serialize(long offset = 0)
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
bw.Write(FlickerIntensity);
bw.Write(FlickerSpeed);
bw.Write(FlickerMode);

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