using System.Collections.Generic; using System.IO; namespace ACE.DatLoader { static class UnpackableExtensions { /// /// A SmartArray uses a Compressed UInt32 for the length. /// public static void UnpackSmartArray(this List value, BinaryReader reader) { var totalObjects = reader.ReadCompressedUInt32(); for (int i = 0; i < totalObjects; i++) { var item = reader.ReadInt32(); value.Add(item); } } /// /// A SmartArray uses a Compressed UInt32 for the length. /// public static void UnpackSmartArray(this List value, BinaryReader reader) { var totalObjects = reader.ReadCompressedUInt32(); for (int i = 0; i < totalObjects; i++) { var item = reader.ReadUInt32(); value.Add(item); } } /// /// A SmartArray uses a Compressed UInt32 for the length. /// public static void UnpackSmartArray(this List value, BinaryReader reader) where T : IUnpackable, new() { var totalObjects = reader.ReadCompressedUInt32(); for (int i = 0; i < totalObjects; i++) { var item = new T(); item.Unpack(reader); value.Add(item); } } /// /// A SmartArray uses a Compressed UInt32 for the length. /// public static void UnpackSmartArray(this Dictionary value, BinaryReader reader) where T : IUnpackable, new() { var totalObjects = reader.ReadCompressedUInt32(); for (int i = 0; i < totalObjects; i++) { var key = reader.ReadUInt16(); var item = new T(); item.Unpack(reader); value.Add(key, item); } } /// /// A SmartArray uses a Compressed UInt32 for the length. /// public static void UnpackSmartArray(this Dictionary value, BinaryReader reader) where T : IUnpackable, new() { var totalObjects = reader.ReadCompressedUInt32(); for (int i = 0; i < totalObjects; i++) { var key = reader.ReadInt32(); var item = new T(); item.Unpack(reader); value.Add(key, item); } } /// /// A SmartArray uses a Compressed UInt32 for the length. /// public static void UnpackSmartArray(this Dictionary value, BinaryReader reader) where T : IUnpackable, new() { var totalObjects = reader.ReadCompressedUInt32(); for (int i = 0; i < totalObjects; i++) { var key = reader.ReadUInt32(); var item = new T(); item.Unpack(reader); value.Add(key, item); } } /// /// A PackedHashTable uses a UInt16 for length, and a UInt16 for bucket size. /// We don't need to worry about the bucket size with C#. /// public static void UnpackPackedHashTable(this Dictionary value, BinaryReader reader) { var totalObjects = reader.ReadUInt16(); /*var bucketSize = */ reader.ReadUInt16(); for (int i = 0; i < totalObjects; i++) value.Add(reader.ReadUInt32(), reader.ReadUInt32()); } /// /// A PackedHashTable uses a UInt16 for length, and a UInt16 for bucket size. /// We don't need to worry about the bucket size with C#. /// public static void UnpackPackedHashTable(this Dictionary value, BinaryReader reader) where T : IUnpackable, new() { var totalObjects = reader.ReadUInt16(); /*var bucketSize = */reader.ReadUInt16(); for (int i = 0; i < totalObjects; i++) { var key = reader.ReadUInt32(); var item = new T(); item.Unpack(reader); value.Add(key, item); } } /// /// A PackedHashTable uses a UInt16 for length, and a UInt16 for bucket size. /// We don't need to worry about the bucket size with C#. /// public static void UnpackPackedHashTable(this SortedDictionary value, BinaryReader reader) where T : IUnpackable, new() { var totalObjects = reader.ReadUInt16(); /*var bucketSize = */ reader.ReadUInt16(); for (int i = 0; i < totalObjects; i++) { var key = reader.ReadUInt32(); var item = new T(); item.Unpack(reader); value.Add(key, item); } } /// /// A list that uses a Int32 for the length. /// public static void Unpack(this List value, BinaryReader reader) { var totalObjects = reader.ReadInt32(); for (int i = 0; i < totalObjects; i++) { var item = reader.ReadUInt32(); value.Add(item); } } /// /// A list that uses a UInt32 for the length. /// public static void Unpack(this List value, BinaryReader reader) where T : IUnpackable, new() { var totalObjects = reader.ReadUInt32(); for (int i = 0; i < totalObjects; i++) { var item = new T(); item.Unpack(reader); value.Add(item); } } public static void Unpack(this List value, BinaryReader reader, uint fixedQuantity) where T : IUnpackable, new() { for (int i = 0; i < fixedQuantity; i++) { var item = new T(); item.Unpack(reader); value.Add(item); } } public static void Unpack(this Dictionary value, BinaryReader reader, uint fixedQuantity) where T : IUnpackable, new() { for (int i = 0; i < fixedQuantity; i++) { var key = reader.ReadUInt16(); var item = new T(); item.Unpack(reader); value.Add(key, item); } } /// /// A Dictionary that uses a Int32 for the length. /// public static void Unpack(this Dictionary value, BinaryReader reader) where T : IUnpackable, new() { var totalObjects = reader.ReadInt32(); for (int i = 0; i < totalObjects; i++) { var key = reader.ReadInt32(); var item = new T(); item.Unpack(reader); value.Add(key, item); } } /// /// A Dictionary that uses a Int32 for the length. /// public static void Unpack(this Dictionary value, BinaryReader reader) where T : IUnpackable, new() { var totalObjects = reader.ReadUInt32(); for (int i = 0; i < totalObjects; i++) { var key = reader.ReadUInt32(); var item = new T(); item.Unpack(reader); value.Add(key, item); } } public static void Unpack(this Dictionary value, BinaryReader reader, uint fixedQuantity) where T : IUnpackable, new() { for (int i = 0; i < fixedQuantity; i++) { var key = reader.ReadUInt32(); var item = new T(); item.Unpack(reader); value.Add(key, item); } } /// /// A Dictionary that uses a Int32 for the length. /// public static void Unpack(this Dictionary> value, BinaryReader reader) where T : IUnpackable, new() { var totalObjects = reader.ReadUInt32(); for (int i = 0; i < totalObjects; i++) { var key = reader.ReadUInt32(); var values = new Dictionary(); values.Unpack(reader); value.Add(key, values); } } } }