Exemple #1
0
        /// <summary>
        /// Read a single entry from JMP.
        /// </summary>
        /// <param name="br">Binary Reader to use.</param>
        /// <param name="fields">List of fields in JMP.</param>
        public JEntry(DhBinaryReader br, List <JField> fields)
        {
            // Save the current position.
            long currentPosition = br.Position();

            // Define a new object array to hold entry's values.
            Values = new object[fields.Count];

            // Loop through each field in the JMP.
            for (int i = 0; i < fields.Count; i++)
            {
                // Seek from the current position to value's offset in the entry.
                br.Sail(fields[i].Offset);

                // Define a new object to hold our data.
                object value;

                // Check which type the current value is.
                switch (fields[i].Type)
                {
                case JFieldType.INTEGER:
                    // Read the data as a integer.
                    value = ((br.ReadS32() & fields[i].Bitmask) >> fields[i].Shift);
                    break;

                case JFieldType.STRING:
                    // Read the data as a 32-byte long string.
                    value = br.ReadStr32();
                    break;

                case JFieldType.FLOAT:
                    // Read the data as a float32.
                    value = br.ReadF32();
                    break;

                default:
                    // Something went horribly wrong.
                    throw new InvalidDataException();
                }
                // Set the value of this entry's value's data to the value we just read.
                Values[i] = value;

                // Seek back to the position we saved earlier.
                br.Goto(currentPosition);
            }
        }