From 3ae6dadcb431ab85262d77409c52baa476765929 Mon Sep 17 00:00:00 2001 From: Luzifix Date: Mon, 15 Jul 2024 23:14:26 +0200 Subject: [PATCH] Add ChunkIgnore attribute and obsolete LightTable2 property --- Warcraft.NET/Attribute/ChunkAttributes.cs | 8 +++++++- Warcraft.NET/Files/ChunkedFile.cs | 18 ++++++++++-------- .../Files/WDT/Light/Legion/WorldLightTable.cs | 9 ++++++++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Warcraft.NET/Attribute/ChunkAttributes.cs b/Warcraft.NET/Attribute/ChunkAttributes.cs index 152c6ed..68331b1 100644 --- a/Warcraft.NET/Attribute/ChunkAttributes.cs +++ b/Warcraft.NET/Attribute/ChunkAttributes.cs @@ -27,7 +27,6 @@ public ChunkOptionalAttribute(bool optional = true) public bool Optional { get { return optional_; } } } - [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] public sealed class ChunkArrayAttribute : System.Attribute { @@ -39,4 +38,11 @@ public ChunkArrayAttribute([CallerLineNumber]int length = 0) public int Length { get { return length; } } } + + [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] + public sealed class ChunkIgnoreAttribute : System.Attribute + { + private readonly bool optional_; + public ChunkIgnoreAttribute() { } + } } diff --git a/Warcraft.NET/Files/ChunkedFile.cs b/Warcraft.NET/Files/ChunkedFile.cs index 0a48ab6..f88df72 100644 --- a/Warcraft.NET/Files/ChunkedFile.cs +++ b/Warcraft.NET/Files/ChunkedFile.cs @@ -1,11 +1,11 @@ -using Warcraft.NET.Attribute; -using Warcraft.NET.Exceptions; -using Warcraft.NET.Extensions; -using Warcraft.NET.Files.Interfaces; +using System; using System.IO; using System.Linq; using System.Reflection; -using System; +using Warcraft.NET.Attribute; +using Warcraft.NET.Exceptions; +using Warcraft.NET.Extensions; +using Warcraft.NET.Files.Interfaces; namespace Warcraft.NET.Files { @@ -40,11 +40,12 @@ public void LoadBinaryData(byte[] inData) using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) { - var terrainChunkProperties = GetType() + var chunkProperties = GetType() .GetProperties() + .Where(p => (ChunkIgnoreAttribute)p.GetCustomAttribute(typeof(ChunkIgnoreAttribute), false) == null) .OrderBy(p => ((ChunkOrderAttribute)p.GetCustomAttributes(typeof(ChunkOrderAttribute), false).Single()).Order); - foreach (PropertyInfo chunkProperty in terrainChunkProperties) + foreach (PropertyInfo chunkProperty in chunkProperties) { try { @@ -113,6 +114,7 @@ public byte[] Serialize(long offset = 0) { var terrainChunkProperties = GetType() .GetProperties() + .Where(p => (ChunkIgnoreAttribute)p.GetCustomAttribute(typeof(ChunkIgnoreAttribute), false) == null) .OrderBy(p => ((ChunkOrderAttribute)p.GetCustomAttributes(typeof(ChunkOrderAttribute), false).Single()).Order); foreach (PropertyInfo chunkPropertie in terrainChunkProperties) @@ -156,7 +158,7 @@ public byte[] Serialize(long offset = 0) return ms.ToArray(); } } - + public virtual bool IsReverseSignature() { return true; diff --git a/Warcraft.NET/Files/WDT/Light/Legion/WorldLightTable.cs b/Warcraft.NET/Files/WDT/Light/Legion/WorldLightTable.cs index d0952a8..b680982 100644 --- a/Warcraft.NET/Files/WDT/Light/Legion/WorldLightTable.cs +++ b/Warcraft.NET/Files/WDT/Light/Legion/WorldLightTable.cs @@ -1,4 +1,5 @@ -using Warcraft.NET.Attribute; +using System; +using Warcraft.NET.Attribute; using Warcraft.NET.Files.WDT.Chunks.Legion; using WorldLightTableWoD = Warcraft.NET.Files.WDT.Light.WoD.WorldLightTable; @@ -12,6 +13,12 @@ public class WorldLightTable : WorldLightTableWoD [ChunkOrder(2), ChunkOptional] public MPL2 PointLights2 { get; set; } + /// + /// (Obsolete) Legion Point Light Table + /// + [ChunkIgnore, Obsolete("Use PointLights2 instead.")] + public MPL2 LightTable2 { get { return PointLights2; } set { PointLights2 = value; } } + /// /// Texture FileDataIDs ///