Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Luzifix authored Sep 22, 2024
2 parents b7e866b + bbf5448 commit b5ae8e5
Show file tree
Hide file tree
Showing 5 changed files with 450 additions and 17 deletions.
34 changes: 28 additions & 6 deletions Warcraft.NET/Extensions/ExtendedIO.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using Warcraft.NET.Files.Interfaces;
using System;
using System.IO;
using System.Text;
using Warcraft.NET.Files.Structures;
using System;
using System.Collections.Generic;
using System.IO;
using System.Numerics;
using Warcraft.NET.Exceptions;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using Warcraft.NET.Exceptions;
using Warcraft.NET.Files.Interfaces;
using Warcraft.NET.Files.Structures;
using Warcraft.NET.Types;

namespace Warcraft.NET.Extensions
{
Expand Down Expand Up @@ -172,6 +173,16 @@ public static RGBA ReadBGRA(this BinaryReader reader)
};
}

/// <summary>
/// Reads a 2-byte <see cref="HalfFloat"/> from the data stream.
/// </summary>
/// <param name="binaryReader">The reader.</param>
/// <returns>The half.</returns>
public static HalfFloat ReadHalfFloat(this BinaryReader reader)
{
return new HalfFloat(reader.ReadUInt16());
}

/// Reads ab 4.byte <see cref="UVMapEntry"/> from the data stream.
/// </summary>
/// <param name="binaryReader">The reader.</param>
Expand Down Expand Up @@ -396,6 +407,17 @@ public static void WriteNullTerminatedString(this BinaryWriter binaryWriter, str

binaryWriter.Write((char)0);
}

/// <summary>
/// Writes a 2-byte <see cref="HalfFloat"/> to the data stream.
/// </summary>
/// <param name="binaryWriter">The current <see cref="BinaryWriter"/> object.</param>
/// <param name="half"></param>
public static void WriteHalfFloat(this BinaryWriter binaryWriter, HalfFloat half)
{
binaryWriter.Write(half.RawValue);
}

/// <summary>
/// Writes the provided string to the data stream as a C-style null-terminated string.
/// </summary>
Expand Down
32 changes: 21 additions & 11 deletions Warcraft.NET/Files/WDT/Entries/SL/MPL3Entry.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System.IO;
using System;
using System.IO;
using System.Numerics;
using Warcraft.NET.Extensions;
using Warcraft.NET.Files.Structures;
using Warcraft.NET.Files.WDT.Flags;
using Warcraft.NET.Types;

namespace Warcraft.NET.Files.WDT.Entries.SL
{
Expand All @@ -18,7 +21,7 @@ public class MPL3Entry
/// <summary>
/// Color
/// </summary>
public uint Color { get; set; }
public RGBA Color { get; set; }

/// <summary>
/// Position
Expand All @@ -43,7 +46,7 @@ public class MPL3Entry
/// <summary>
/// Unknown/unused vector3, likely rotation from another struct but unused for point lights.
/// </summary>
public Vector3 Unused0 { get; set; }
public Vector3 Unused0 { get; set; } = new Vector3(0.0f, 0.0f, 0.0f);

/// <summary>
/// Map Tile X
Expand All @@ -70,12 +73,19 @@ public class MPL3Entry
/// <summary>
/// Flags
/// </summary>
public ushort Flags { get; set; }
public MPL3Flags Flags { get; set; } = 0;

/// <summary>
/// Scale as half float value
/// Default value is 0.5f
/// </summary>
public HalfFloat Scale { get; set; } = 0.5f;

/// <summary>
/// Unknown value, wiki mentions it is "a packed value". 14336 appears to be the most common value.
/// </summary>
public ushort Unknown1 { get; set; } = 14336;
[Obsolete("Use Scale instead.")]
public ushort Unknown1 { get { return Scale.RawValue; } set { Scale = new HalfFloat(value); } }

public MPL3Entry() { }

Expand All @@ -90,7 +100,7 @@ public MPL3Entry(byte[] data)
using (var br = new BinaryReader(ms))
{
Id = br.ReadUInt32();
Color = br.ReadUInt32();
Color = br.ReadBGRA();
Position = br.ReadVector3(AxisConfiguration.Native);
AttenuationStart = br.ReadSingle();
AttenuationEnd = br.ReadSingle();
Expand All @@ -100,8 +110,8 @@ public MPL3Entry(byte[] data)
TileY = br.ReadUInt16();
MLTAIndex = br.ReadInt16();
MTEXIndex = br.ReadInt16();
Flags = br.ReadUInt16();
Unknown1 = br.ReadUInt16();
Flags = (MPL3Flags)br.ReadUInt16();
Scale = br.ReadHalfFloat();
}
}
}
Expand All @@ -125,7 +135,7 @@ public byte[] Serialize(long offset = 0)
using (var bw = new BinaryWriter(ms))
{
bw.Write(Id);
bw.Write(Color);
bw.WriteBGRA(Color);
bw.WriteVector3(Position, AxisConfiguration.Native);
bw.Write(AttenuationStart);
bw.Write(AttenuationEnd);
Expand All @@ -135,8 +145,8 @@ public byte[] Serialize(long offset = 0)
bw.Write(TileY);
bw.Write(MLTAIndex);
bw.Write(MTEXIndex);
bw.Write(Flags);
bw.Write(Unknown1);
bw.Write((ushort)Flags);
bw.WriteHalfFloat(Scale);

return ms.ToArray();
}
Expand Down
16 changes: 16 additions & 0 deletions Warcraft.NET/Files/WDT/Flags/MPL3Flags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace Warcraft.NET.Files.WDT.Flags
{
/// <summary>
/// Flags for the <see cref="MPHDFlags"/>.
/// </summary>
[Flags]
public enum MPL3Flags : ushort
{
/// <summary>
/// Enable raytracing for this light. (Only visible with enabled D3D12 + min shadowRt level 2)
/// </summary>
Raytraced = 0x1,
}
}
Loading

0 comments on commit b5ae8e5

Please sign in to comment.