Skip to content

Commit

Permalink
Merge pull request #10 from Marlamin/master
Browse files Browse the repository at this point in the history
Add _lod ADT writing + fix bad sizes
  • Loading branch information
Luzifix committed Jul 31, 2024
2 parents 95ed3d8 + fa40a15 commit b9d363f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Warcraft.NET/Files/ADT/Chunks/Legion/MLSI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void LoadBinaryData(byte[] inData)
using (var ms = new MemoryStream(inData))
using (var br = new BinaryReader(ms))
{
var mlsiCount = br.BaseStream.Length / sizeof(uint);
var mlsiCount = br.BaseStream.Length / sizeof(ushort);
SkirtIndices = new ushort[mlsiCount];
for (var i = 0; i < mlsiCount; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion Warcraft.NET/Files/ADT/Chunks/Legion/MLVI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void LoadBinaryData(byte[] inData)
using (var ms = new MemoryStream(inData))
using (var br = new BinaryReader(ms))
{
var mlviCount = br.BaseStream.Length / sizeof(uint);
var mlviCount = br.BaseStream.Length / sizeof(ushort);
VertexIndices = new ushort[mlviCount];
for (var i = 0; i < mlviCount; i++)
{
Expand Down
51 changes: 51 additions & 0 deletions Warcraft.NET/Files/ADT/TerrainLOD/Legion/TerrainLOD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,57 @@ public void LoadBinaryData(byte[] inData)
}
}
}

/// <inheritdoc/>
public override byte[] Serialize()
{
using var ms = new MemoryStream();
using (var bw = new BinaryWriter(ms))
{
bw.WriteIFFChunk(Version);
bw.WriteIFFChunk(Header);
bw.WriteIFFChunk(Heightmap);
bw.WriteIFFChunk(Levels);
bw.WriteIFFChunk(QuadTree);
bw.WriteIFFChunk(VertexIndices);
bw.WriteIFFChunk(SkirtIndices);

if (BlendMeshHeaders != null)
bw.WriteIFFChunk(BlendMeshHeaders);

if (BlendMeshBoundingBoxes != null)
bw.WriteIFFChunk(BlendMeshBoundingBoxes);

if (BlendMeshIndices != null)
bw.WriteIFFChunk(BlendMeshIndices);

if (BlendMeshVertices != null)
bw.WriteIFFChunk(BlendMeshVertices);

if (BlendMeshBatches != null)
bw.WriteIFFChunk(BlendMeshBatches);

if (LiquidData != null)
bw.WriteIFFChunk(LiquidData);

foreach (var liquidN in LiquidN)
{
bw.WriteIFFChunk(liquidN);
}

foreach (var liquidIndex in LiquidIndices)
{
bw.WriteIFFChunk(liquidIndex);
}

foreach (var liquidVertex in LiquidVertices)
{
bw.WriteIFFChunk(liquidVertex);
}

return ms.ToArray();
}
}
}
#nullable disable
}
3 changes: 3 additions & 0 deletions Warcraft.NET/Files/ADT/TerrainLOD/TerrainLODBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ public TerrainLODBase() : base()
public TerrainLODBase(byte[] inData) : base(inData)
{
}

/// <inheritdoc/>
public abstract byte[] Serialize();
}
}

0 comments on commit b9d363f

Please sign in to comment.