Skip to content

Commit

Permalink
Merge pull request #9 from Marlamin/master
Browse files Browse the repository at this point in the history
Early fogs WDT support, chunk list util
  • Loading branch information
Luzifix authored Jul 22, 2024
2 parents c258e6c + 5225c02 commit 6448450
Show file tree
Hide file tree
Showing 8 changed files with 478 additions and 0 deletions.
1 change: 1 addition & 0 deletions Warcraft.NET/Attribute/AutoDocAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal static class AutoDocChunkVersionHelper
internal const AutoDocChunkVersion VersionAfterLegion = AutoDocChunkVersion.BfA | AutoDocChunkVersion.SL | AutoDocChunkVersion.DF | AutoDocChunkVersion.TWW;
internal const AutoDocChunkVersion VersionAfterBfA = AutoDocChunkVersion.SL | AutoDocChunkVersion.DF | AutoDocChunkVersion.TWW;
internal const AutoDocChunkVersion VersionAfterSL = AutoDocChunkVersion.DF | AutoDocChunkVersion.TWW;
internal const AutoDocChunkVersion VersionAfterDF = AutoDocChunkVersion.TWW;

internal const AutoDocChunkVersion VersionBeforeLegion = AutoDocChunkVersion.LK | AutoDocChunkVersion.WoD;
internal const AutoDocChunkVersion VersionBeforeBfA = AutoDocChunkVersion.LK | AutoDocChunkVersion.WoD | AutoDocChunkVersion.Legion;
Expand Down
23 changes: 23 additions & 0 deletions Warcraft.NET/Files/ChunkedFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -163,6 +164,28 @@ public virtual bool IsReverseSignature()
{
return true;
}

public static List<string> GetChunkList(byte[] inData)
{
var chunkList = new List<string>();

using (var ms = new MemoryStream(inData))
using (var br = new BinaryReader(ms))
{
while (ms.Position < ms.Length)
{
var stringSig = new string(br.ReadChars(4).Reverse().ToArray());

if(!chunkList.Contains(stringSig))
chunkList.Add(stringSig);

var size = br.ReadUInt32();
br.BaseStream.Position += size;
}
}

return chunkList;
}
}
}

Expand Down
82 changes: 82 additions & 0 deletions Warcraft.NET/Files/WDT/Chunks/BfA/VFOG.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System.Collections.Generic;
using System.IO;
using Warcraft.NET.Attribute;
using Warcraft.NET.Files.Interfaces;
using Warcraft.NET.Files.WDT.Entries.BfA;

namespace Warcraft.NET.Files.WDT.Chunks
{
/// <summary>
/// VFOG Chunk
/// </summary>
[AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterLegion, AutoDocChunkVersionHelper.VersionBeforeBfA)]
public class VFOG : IIFFChunk, IBinarySerializable
{
/// <summary>
/// Holds the binary chunk signature.
/// </summary>
public const string Signature = "VFOG";

/// <summary>
/// VFOG Entries
/// </summary>
public List<VFOGEntry> Entries = [];


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

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

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

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

return ms.ToArray();
}
}
}
}
109 changes: 109 additions & 0 deletions Warcraft.NET/Files/WDT/Chunks/TWW/VFEX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System.Collections.Generic;
using System.IO;
using System.Numerics;
using Warcraft.NET.Attribute;
using Warcraft.NET.Files.Interfaces;

namespace Warcraft.NET.Files.WDT.Chunks.TWW
{
/// <summary>
/// VFEX Chunk
/// </summary>
[AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterDF, AutoDocChunkVersionHelper.VersionBeforeTWW)]
public class VFEX : IIFFChunk, IBinarySerializable
{
/// <summary>
/// Holds the binary chunk signature.
/// </summary>
public const string Signature = "VFEX";

public uint Unknown0 { get; set; }
public float[] Unknown1 { get; set; }

/// <summary>
/// Reference to the ID in the VFOG entry this VFEX belongs to.
/// </summary>
public uint VfogId { get; set; }

public uint Unknown3 { get; set; }
public uint Unknown4 { get; set; }
public uint Unknown5 { get; set; }
public uint Unknown6 { get; set; }
public uint Unknown7 { get; set; }
public uint Unknown8 { get; set; }

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

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

/// <inheritdoc/>
public void LoadBinaryData(byte[] inData)
{
using (var ms = new MemoryStream(inData))
using (var br = new BinaryReader(ms))
{
Unknown0 = br.ReadUInt32();
Unknown1 = new float[16];
for (var i = 0; i < 16; i++)
{
Unknown1[i] = br.ReadSingle();
}

VfogId = br.ReadUInt32();
Unknown3 = br.ReadUInt32();
Unknown4 = br.ReadUInt32();
Unknown5 = br.ReadUInt32();
Unknown6 = br.ReadUInt32();
Unknown7 = br.ReadUInt32();
Unknown8 = 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))
{
bw.Write(Unknown0);
for (var i = 0; i < 16; i++)
{
bw.Write(Unknown1[i]);
}
bw.Write(VfogId);
bw.Write(Unknown3);
bw.Write(Unknown4);
bw.Write(Unknown5);
bw.Write(Unknown6);
bw.Write(Unknown7);
bw.Write(Unknown8);

return ms.ToArray();
}
}
}
}
137 changes: 137 additions & 0 deletions Warcraft.NET/Files/WDT/Entries/BfA/VFOGEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using System.IO;
using System.Numerics;
using Warcraft.NET.Extensions;

namespace Warcraft.NET.Files.WDT.Entries.BfA
{
/// <summary>
/// An entry struct containing volume fog information
/// </summary>
public class VFOGEntry
{
/// <summary>
/// Color.
/// </summary>
public Vector3 Color { get; set; }

/// <summary>
/// Radius-related intensity. Unconfirmed.
/// </summary>
public float[] RadiusRelatedIntensity { get; set; }

/// <summary>
/// Unknown 0.
/// </summary>
public float Unknown0 { get; set; }

/// <summary>
/// Position (server coordinates).
/// </summary>
public Vector3 Position { get; set; }

/// <summary>
/// Unknown 1. Set to 1.0f on loading.
/// </summary>
public float Unknown1 { get; set; }

/// <summary>
/// Rotation.
/// </summary>
public Quaternion Rotation { get; set; }

/// <summary>
/// Fog start radius. Unconfirmed.
/// </summary>
public float[] StartRadius { get; set; }

/// <summary>
/// Fog levels. Unconfirmed.
/// </summary>
public uint[] FogLevels { get; set; }

/// <summary>
/// Model FileDataID.
/// </summary>
public uint ModelFileDataID { get; set; }

/// <summary>
/// Unknown 2. Always 1?
/// </summary>
public uint Unknown2 { get; set; }

/// <summary>
/// ID.
/// </summary>
public uint ID { get; set; }


public VFOGEntry() { }

/// <summary>
/// Initializes a new instance of the <see cref="VFOGEntry"/> class.
/// </summary>
/// <param name="data">ExtendedData.</param>
public VFOGEntry(byte[] data)
{
using (var ms = new MemoryStream(data))
{
using (var br = new BinaryReader(ms))
{
Color = br.ReadVector3(Structures.AxisConfiguration.Native);
RadiusRelatedIntensity = [br.ReadSingle(), br.ReadSingle(), br.ReadSingle()];
Unknown0 = br.ReadSingle();
Position = br.ReadVector3(Structures.AxisConfiguration.Native);
Unknown1 = br.ReadSingle();
Rotation = br.ReadQuaternion();
StartRadius = [br.ReadSingle(), br.ReadSingle(), br.ReadSingle()];
FogLevels = [br.ReadUInt32(), br.ReadUInt32(), br.ReadUInt32(), br.ReadUInt32(), br.ReadUInt32()];
ModelFileDataID = br.ReadUInt32();
Unknown2 = br.ReadUInt32();
ID = br.ReadUInt32();
}
}
}

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

/// <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.WriteVector3(Color, Structures.AxisConfiguration.Native);
bw.Write(RadiusRelatedIntensity[0]);
bw.Write(RadiusRelatedIntensity[1]);
bw.Write(RadiusRelatedIntensity[2]);
bw.Write(Unknown0);
bw.WriteVector3(Position, Structures.AxisConfiguration.Native);
bw.Write(Unknown1);
bw.WriteQuaternion(Rotation);
bw.Write(StartRadius[0]);
bw.Write(StartRadius[1]);
bw.Write(StartRadius[2]);
bw.Write(FogLevels[0]);
bw.Write(FogLevels[1]);
bw.Write(FogLevels[2]);
bw.Write(FogLevels[3]);
bw.Write(FogLevels[4]);
bw.Write(ModelFileDataID);
bw.Write(Unknown2);
bw.Write(ID);

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

0 comments on commit 6448450

Please sign in to comment.