/// <summary>
        /// Read and preprocess header information
        /// </summary>
        private void ReadPreprocess()
        {
            char[] gtag;
            #region Endian Switch
            ushort us_temp = InputStream.ReadUInt16();
            if (us_temp == HeaderEndian)
            {
                SetEndianState(IO.EndianState.Little);
            }
            else if (us_temp == HeaderEndianSwap)
            {
                SetEndianState(IO.EndianState.Big);
            }
            else
            {
                throw new Debug.ExceptionLog("File: Invalid switch! {0:X4}", us_temp);
            }
            #endregion

            #region Version
            us_temp = InputStream.ReadUInt16();
            Debug.Assert.If(us_temp == HeaderVersion,
                            "File: mismatching file version! [{0}, !{1}",
                            HeaderVersion, us_temp);
            #endregion
            #region Signature
            gtag = InputStream.ReadTag();
            Debug.Assert.If(TagGroup.Test(gtag, (char[])IO.TagGroups.BlamLib),
                            "File: invalid signature! [{0} !{1}]",
                            IO.TagGroups.BlamLib.TagToString(), new string(gtag));
            #endregion
            flags.Reset((uint)(InputStream.ReadUInt16() << 16) | flags);

            #region Data Version
            us_temp = InputStream.ReadUInt16();
            Debug.Assert.If(us_temp == data.Attribute.Version,
                            "File: mismatching data version! [{0}, !{1}",
                            data.Attribute.Version, us_temp);
            #endregion
            #region Data Signature
            gtag = InputStream.ReadTag();
            Debug.Assert.If(TagGroup.Test(gtag, (char[])data.GroupTag),
                            "File: invalid data signature! [{0} !{1}]",
                            data.GroupTag.TagToString(), new string(gtag));
            #endregion

            #region Data Directories
            InputStream.ReadInt32();
            InputStream.ReadInt32();
            #endregion
            #region Data
            InputStream.ReadInt32();
            int data_offset = InputStream.ReadInt32();
            #endregion

            Debug.Assert.If(InputStream.Position == HeaderSize,
                            "File: Update header size! [{0}, !{1}]", HeaderSize, InputStream.Position);

            InputStream.Seek(data_offset);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Determines the <see cref="BlamVersion"/> from the provided four character code
 /// </summary>
 /// <param name="group_tag">game four character code</param>
 /// <returns></returns>
 /// <exception cref="Debug.Exceptions.UnreachableException"><paramref name="group_tag"/> doesn't match any expected groups</exception>
 public static BlamVersion VersionFromTag(char[] group_tag)
 {
     if (TagGroup.Test(group_tag, (char[])blam))
     {
         return(BlamVersion.Halo1);
     }
     else if (TagGroup.Test(group_tag, (char[])blam2a))
     {
         return(BlamVersion.Halo2);
     }
     else if (TagGroup.Test(group_tag, (char[])blam2b))
     {
         return(BlamVersion.Halo2);
     }
     else if (TagGroup.Test(group_tag, (char[])blam2c))
     {
         return(BlamVersion.Halo2);
     }
     else if (TagGroup.Test(group_tag, (char[])blam2d))
     {
         return(BlamVersion.Halo2);
     }
     else if (TagGroup.Test(group_tag, (char[])blm2))
     {
         return(BlamVersion.Halo2);
     }
     else if (TagGroup.Test(group_tag, (char[])blm3))
     {
         return(BlamVersion.Halo3);
     }
     else if (TagGroup.Test(group_tag, (char[])stub))
     {
         return(BlamVersion.Stubbs);
     }
     else
     {
         throw new Debug.Exceptions.UnreachableException();
     }
 }