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 _lod ADT writing + fix bad sizes #10

Merged
merged 1 commit into from
Jul 31, 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
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 @@ -103,7 +103,7 @@
/// <summary>
/// Initializes a new instance of the <see cref="TerrainLOD"/> class.
/// </summary>
public TerrainLOD() : base()

Check warning on line 106 in Warcraft.NET/Files/ADT/TerrainLOD/Legion/TerrainLOD.cs

View workflow job for this annotation

GitHub Actions / tests

Non-nullable property 'Header' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 106 in Warcraft.NET/Files/ADT/TerrainLOD/Legion/TerrainLOD.cs

View workflow job for this annotation

GitHub Actions / tests

Non-nullable property 'Heightmap' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 106 in Warcraft.NET/Files/ADT/TerrainLOD/Legion/TerrainLOD.cs

View workflow job for this annotation

GitHub Actions / tests

Non-nullable property 'Levels' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 106 in Warcraft.NET/Files/ADT/TerrainLOD/Legion/TerrainLOD.cs

View workflow job for this annotation

GitHub Actions / tests

Non-nullable property 'QuadTree' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 106 in Warcraft.NET/Files/ADT/TerrainLOD/Legion/TerrainLOD.cs

View workflow job for this annotation

GitHub Actions / tests

Non-nullable property 'VertexIndices' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 106 in Warcraft.NET/Files/ADT/TerrainLOD/Legion/TerrainLOD.cs

View workflow job for this annotation

GitHub Actions / tests

Non-nullable property 'SkirtIndices' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 106 in Warcraft.NET/Files/ADT/TerrainLOD/Legion/TerrainLOD.cs

View workflow job for this annotation

GitHub Actions / tests

Non-nullable property 'BlendMeshHeaders' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 106 in Warcraft.NET/Files/ADT/TerrainLOD/Legion/TerrainLOD.cs

View workflow job for this annotation

GitHub Actions / tests

Non-nullable property 'BlendMeshBoundingBoxes' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 106 in Warcraft.NET/Files/ADT/TerrainLOD/Legion/TerrainLOD.cs

View workflow job for this annotation

GitHub Actions / tests

Non-nullable property 'BlendMeshIndices' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
{
}

Expand All @@ -117,7 +117,7 @@
}

/// <inheritdoc/>
public void LoadBinaryData(byte[] inData)

Check warning on line 120 in Warcraft.NET/Files/ADT/TerrainLOD/Legion/TerrainLOD.cs

View workflow job for this annotation

GitHub Actions / tests

'TerrainLOD.LoadBinaryData(byte[])' hides inherited member 'ChunkedFile.LoadBinaryData(byte[])'. Use the new keyword if hiding was intended.
{
using var ms = new MemoryStream(inData);
using var br = new BinaryReader(ms);
Expand Down Expand Up @@ -166,6 +166,57 @@
}
}
}

/// <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();
}
}