Пример #1
0
        /// <summary>
        /// Parses a level rules file bytes.
        /// </summary>
        /// <param name="fileBytes">The bytes of the level rules to parse.</param>
        public override void ParseFileBytes(byte[] fileBytes)
        {
            // sanity check
            if (fileBytes == null)
            {
                throw new ArgumentNullException("fileBytes", "File bytes cannot be null!");
            }
            _mliStruct = new MLIStruct();

            // file header checks
            int    offset        = 0;
            UInt32 fileMagicWord = FileTools.ByteArrayToUInt32(fileBytes, ref offset);

            if (fileMagicWord != FileMagicWord)
            {
                throw new Exceptions.UnexpectedMagicWordException();
            }

            UInt32 fileVersion = FileTools.ByteArrayToUInt32(fileBytes, ref offset);

            if (fileVersion != RequiredVersion)
            {
                throw new Exceptions.NotSupportedFileVersionException();
            }

            // first block
            int flag  = FileTools.ByteArrayToInt32(fileBytes, ref offset);
            int count = FileTools.ByteArrayToInt32(fileBytes, ref offset);

            if (flag == 1)
            {
                _mliStruct.UnknownStruct1Array = FileTools.ByteArrayToArray <UnknownStruct1>(fileBytes, ref offset, count);
            }

            if (flag == 1 && _mliStruct.UnknownStruct1Array[0].UnknownInt321 == 0x0A)
            {
                // shorts block
                int shortCount = FileTools.ByteArrayToInt32(fileBytes, ref offset);
                if (shortCount > 0)
                {
                    _mliStruct.UnknownShortArray = FileTools.ByteArrayToShortArray(fileBytes, ref offset, shortCount);
                }

                // floats block
                int floatTripletCount = FileTools.ByteArrayToInt32(fileBytes, ref offset);
                if (floatTripletCount > 0)
                {
                    _mliStruct.UnknownStruct2Array = FileTools.ByteArrayToArray <UnknownStruct2>(fileBytes, ref offset, floatTripletCount);
                }
            }

            // last two unknown blocks
            int count1 = FileTools.ByteArrayToInt32(fileBytes, fileBytes.Length - 8);
            int count2 = FileTools.ByteArrayToInt32(fileBytes, fileBytes.Length - 4);

            if (count1 > 0)
            {
                _mliStruct.UnknownStruct3Array1 = FileTools.ByteArrayToArray <UnknownStruct3>(fileBytes, ref offset, count1);
            }
            if (count2 > 0)
            {
                _mliStruct.UnknownStruct3Array2 = FileTools.ByteArrayToArray <UnknownStruct3>(fileBytes, ref offset, count2);
            }
            offset += 8; // for 2x count fields

            // final debug check
            Debug.Assert(offset == fileBytes.Length);
        }