/// <summary>
        ///  Extracts the KIFINT entry file from the the entry's open KIFINT archive stream and saves it to the output
        ///  <paramref name="directory"/>.
        /// </summary>
        /// <param name="kifintStream">The stream to the open KIFINT archive.</param>
        /// <param name="entry">The KIFINT entry used to locate the file.</param>
        /// <param name="directory">
        ///  The directory to save the file to. The file name will be <see cref="KifintEntry.FileName"/>.
        /// </param>
        ///
        /// <exception cref="ArgumentNullException">
        ///  <paramref name="kifintStream"/>, <paramref name="entry"/>, or <paramref name="directory"/> is null.
        /// </exception>
        public static void ExtractToDirectory(KifintStream kifintStream, KifintEntry entry, string directory)
        {
            if (kifintStream == null)
            {
                throw new ArgumentNullException(nameof(kifintStream));
            }
            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }
            if (directory == null)
            {
                throw new ArgumentNullException(nameof(directory));
            }
            var kifint = entry.Kifint;

            kifintStream.Open(kifint);
            BinaryReader reader = new BinaryReader(kifintStream);

            kifintStream.Position = entry.Offset;
            byte[] buffer = reader.ReadBytes(entry.Length);

            if (kifint.IsEncrypted)
            {
                DecryptData(buffer, entry.Length, kifint.FileKey);
            }
            File.WriteAllBytes(Path.Combine(directory, entry.FileName), buffer);
        }
 /// <summary>
 ///  Extracts the KIFINT entry file from the the entry's KIFINT archive.
 /// </summary>
 /// <param name="entry">The KIFINT entry to open the KIFINT archive from and locate the file.</param>
 /// <returns>A byte array containing the extracted KIFINT entry's file data.</returns>
 ///
 /// <exception cref="ArgumentNullException">
 ///  <paramref name="entry"/> is null.
 /// </exception>
 public static byte[] Extract(KifintEntry entry)
 {
     if (entry == null)
     {
         throw new ArgumentNullException(nameof(entry));
     }
     using (KifintStream kifintStream = new KifintStream())
         return(Extract(kifintStream, entry));
 }
 /// <summary>
 ///  Extracts the KIFINT entry file from the the entry's KIFINT archive and saves it to the output
 ///  <paramref name="directory"/>.
 /// </summary>
 /// <param name="entry">The KIFINT entry used to locate the file.</param>
 /// <param name="directory">
 ///  The directory to save the file to. The file name will be <see cref="KifintEntry.FileName"/>.
 /// </param>
 ///
 /// <exception cref="ArgumentNullException">
 ///  <paramref name="entry"/> or <paramref name="directory"/> is null.
 /// </exception>
 public static void ExtractToDirectory(KifintEntry entry, string directory)
 {
     if (entry == null)
     {
         throw new ArgumentNullException(nameof(entry));
     }
     using (KifintStream kifintStream = new KifintStream())
         ExtractToDirectory(kifintStream, entry, directory);
 }
 /// <summary>
 ///  Extracts the KIFINT entry file from the the entry's KIFINT archive and saves it to the output
 ///  <paramref name="filePath"/>.
 /// </summary>
 /// <param name="entry">The KIFINT entry used to locate the file.</param>
 /// <param name="filePath">The path to save the file to.</param>
 ///
 /// <exception cref="ArgumentNullException">
 ///  <paramref name="entry"/> or <paramref name="filePath"/> is null.
 /// </exception>
 public static void ExtractToFile(KifintEntry entry, string filePath)
 {
     if (entry == null)
     {
         throw new ArgumentNullException(nameof(entry));
     }
     using (KifintStream kifintStream = new KifintStream())
         ExtractToFile(kifintStream, entry, filePath);
 }
 /// <summary>
 ///  Extracts the HG-3 image information from the KIFINT entry and saves all images to the output
 ///  <paramref name="directory"/>.
 /// </summary>
 /// <param name="entry">The KIFINT entry information used to extract the HG-3 file.</param>
 /// <param name="directory">The output directory to save the images to.</param>
 /// <param name="expand">True if the images are expanded to their full size when saving.</param>
 /// <returns>The extracted <see cref="Hg3"/> information.</returns>
 ///
 /// <exception cref="ArgumentNullException">
 ///  <paramref name="entry"/> or <paramref name="directory"/> is null.
 /// </exception>
 public static Hg3 ExtractHg3AndImages(KifintEntry entry, string directory, bool expand)
 {
     if (entry == null)
     {
         throw new ArgumentNullException(nameof(entry));
     }
     using (KifintStream kifintStream = new KifintStream())
         return(ExtractHg3AndImages(kifintStream, entry, directory, expand));
 }
 /// <summary>
 ///  Extracts the HG-3 image information from the KIFINT entry's open KIFINT archive stream and saves all
 ///  images to the output <paramref name="directory"/>.
 /// </summary>
 /// <param name="kifintStream">The stream to the open KIFINT archive.</param>
 /// <param name="entry">The KIFINT entry information used to extract the HG-3 file.</param>
 /// <param name="directory">The output directory to save the images to.</param>
 /// <param name="expand">True if the images are expanded to their full size when saving.</param>
 /// <returns>The extracted <see cref="Hg3"/> information.</returns>
 ///
 /// <exception cref="ArgumentNullException">
 ///  <paramref name="kifintStream"/>, <paramref name="entry"/>, or <paramref name="directory"/> is null.
 /// </exception>
 public static Hg3 ExtractHg3AndImages(KifintStream kifintStream, KifintEntry entry, string directory,
                                       bool expand)
 {
     if (directory == null)
     {
         throw new ArgumentNullException(nameof(directory));
     }
     byte[] buffer = Extract(kifintStream, entry);
     using (MemoryStream ms = new MemoryStream(buffer))
         return(Hg3.ExtractImages(ms, entry.FileName, directory, expand));
 }
        /// <summary>
        ///  Extracts the KIFINT entry file from the the entry's KIFINT archive.
        /// </summary>
        /// <param name="kifintStream">The stream to the open KIFINT archive.</param>
        /// <param name="entry">The KIFINT entry used to locate the file.</param>
        /// <returns>A byte array containing the extracted KIFINT entry's file data.</returns>
        ///
        /// <exception cref="ArgumentNullException">
        ///  <paramref name="kifintStream"/> or <paramref name="entry"/> is null.
        /// </exception>
        public static byte[] Extract(KifintStream kifintStream, KifintEntry entry)
        {
            if (kifintStream == null)
            {
                throw new ArgumentNullException(nameof(kifintStream));
            }
            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }
            var kifint = entry.Kifint;

            kifintStream.Open(kifint);
            BinaryReader reader = new BinaryReader(kifintStream);

            kifintStream.Position = entry.Offset;
            byte[] buffer = reader.ReadBytes(entry.Length);

            if (kifint.IsEncrypted)
            {
                DecryptData(buffer, entry.Length, kifint.FileKey);
            }
            return(buffer);
        }
 /// <summary>
 ///  Extracts the ANM animation information from the open KIFINT archive stream.
 /// </summary>
 /// <param name="kifintStream">The stream to the open KIFINT archive.</param>
 /// <param name="entry">The KIFINT entry used to locate the file.</param>
 /// <returns>The extracted <see cref="Anm"/> animation information.</returns>
 ///
 /// <exception cref="ArgumentNullException">
 ///  <paramref name="kifintStream"/> or <paramref name="entry"/> is null.
 /// </exception>
 public static Anm ExtractAnm(KifintStream kifintStream, KifintEntry entry)
 {
     byte[] buffer = Extract(kifintStream, entry);
     using (MemoryStream ms = new MemoryStream(buffer))
         return(Anm.Extract(ms, entry.FileName));
 }