/// <summary>
        ///  Extracts the ANM animation from an ANM file stream.
        /// </summary>
        /// <param name="stream">The stream to extract the ANM from.</param>
        /// <param name="fileName">The path or name of the ANM file being extracted.</param>
        /// <returns>The extracted ANM animation.</returns>
        ///
        /// <exception cref="ArgumentNullException">
        ///  <paramref name="stream"/> or <paramref name="fileName"/> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///  The <paramref name="stream"/> is closed.
        /// </exception>
        public static Anm Extract(Stream stream, string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }
            BinaryReader reader = new BinaryReader(stream);

            ANMHDR hdr = reader.ReadUnmanaged <ANMHDR>();

            if (hdr.Signature != "ANM")
            {
                throw new UnexpectedFileTypeException(fileName, "ANM");
            }
            reader.ReadBytes(20);             // Unused (?)

            ANMFRM[] frames = new ANMFRM[hdr.FrameCount];
            for (int i = 0; i < hdr.FrameCount; i++)
            {
                frames[i] = reader.ReadUnmanaged <ANMFRM>();
                reader.ReadInt32();                 // Padding (Probably)
            }

            return(new Anm(Path.GetFileName(fileName), hdr, frames));
        }
Beispiel #2
0
 /// <summary>
 ///  Constructs an ANM animation script with the specified file name, header, and script lines.
 /// </summary>
 /// <param name="fileName">The file name of the ANM animation with the .anm extension.</param>
 /// <param name="hdr">The ANMHDR containing extra information on the ANM animation.</param>
 /// <param name="lines">The ANMFRM struct array containing script line information.</param>
 private AnmAnimation(string fileName, ANMHDR hdr, ANMLINE[] lines)
 {
     FileName = Path.GetFileName(fileName);
     Unknown  = hdr.Unknown;
     AnmLine[] newLines = new AnmLine[lines.Length];
     for (int i = 0; i < lines.Length; i++)
     {
         newLines[i] = new AnmLine(lines[i]);
     }
     Lines = newLines.AsReadOnly();
 }
        /// <summary>
        ///  Extracts the ANM animation from an ANM file stream.
        /// </summary>
        /// <param name="stream">The stream to extract the ANM from.</param>
        /// <param name="fileName">The path or name of the ANM file being extracted.</param>
        /// <returns>The extracted ANM animation.</returns>
        ///
        /// <exception cref="ArgumentNullException">
        ///  <paramref name="stream"/> or <paramref name="fileName"/> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///  The <paramref name="stream"/> is closed.
        /// </exception>
        public static AnmAnimation Extract(Stream stream, string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }
            BinaryReader reader = new BinaryReader(stream);

            ANMHDR hdr = reader.ReadUnmanaged <ANMHDR>();

            UnexpectedFileTypeException.ThrowIfInvalid(hdr.Signature, ANMHDR.ExpectedSignature);

            reader.ReadBytes(20);             // Unused (?)

            ANMLINE[] frames = new ANMLINE[hdr.LineCount];
            for (int i = 0; i < hdr.LineCount; i++)
            {
                frames[i] = reader.ReadUnmanaged <ANMLINE>();
            }

            return(new AnmAnimation(Path.GetFileName(fileName), hdr, frames));
        }