diff --git a/OpenKh.Kh2/Idx.cs b/OpenKh.Kh2/Idx.cs index c1c1dcc2e..5c7408c9b 100644 --- a/OpenKh.Kh2/Idx.cs +++ b/OpenKh.Kh2/Idx.cs @@ -1,4 +1,5 @@ -using System; +using OpenKh.Common; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -98,6 +99,9 @@ [Data] public int Length [Data] public List Items { get; set; } + public static bool IsValid(Stream stream) => + stream.Length == new BinaryReader(stream.SetPosition(0)).ReadInt32() * 0x10 + 4; + /// /// Deserialize an IDX from a stream /// @@ -106,14 +110,14 @@ [Data] public int Length public static Idx Read(Stream stream) { BinaryMapping.SetMemberLengthMapping(nameof(Items), (o, m) => o.Length); - return BinaryMapping.ReadObject(stream); + return BinaryMapping.ReadObject(stream.SetPosition(0)); } /// /// Serialize an IDX to a stream /// /// Writable stream that will contain the IDX data - public void Write(Stream stream) => BinaryMapping.WriteObject(stream, this); + public void Write(Stream stream) => BinaryMapping.WriteObject(stream.SetPosition(0), this); /// /// Try to get an entry form a file name