GetSize() публичный статический Метод

Gets the size of a DBC header in bytes.
public static GetSize ( ) : int
Результат int
Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DBC"/> class.
        /// </summary>
        /// <param name="inVersion">In version.</param>
        /// <param name="data">ExtendedData.</param>
        public DBC(WarcraftVersion inVersion, byte[] data)
        {
            this.Version          = inVersion;
            this.DatabaseContents = data;

            using (BinaryReader databaseReader = new BinaryReader(new MemoryStream(this.DatabaseContents)))
            {
                this.Header = new DBCHeader(databaseReader.ReadBytes(DBCHeader.GetSize()));

                // Seek to and read the string block
                databaseReader.BaseStream.Seek(this.Header.RecordCount * this.Header.RecordSize, SeekOrigin.Current);
                this.StringBlockOffset = databaseReader.BaseStream.Position;
                while (databaseReader.BaseStream.Position != databaseReader.BaseStream.Length)
                {
                    this.Strings.Add(databaseReader.BaseStream.Position - this.StringBlockOffset, databaseReader.ReadNullTerminatedString());
                }
            }

            this.Records = new List <T>(this.Count);

            // Initialize the record list with null values
            for (int i = 0; i < this.Count; ++i)
            {
                this.Records.Add(null);
            }
        }
Пример #2
0
        /*
         *      Indexing implementation
         */

        /// <inheritdoc />
        public T this[int i]
        {
            get
            {
                if (HasCachedRecordAtIndex(i))
                {
                    return(this.Records[i]);
                }

                using (BinaryReader databaseReader = new BinaryReader(new MemoryStream(this.DatabaseContents)))
                {
                    long recordOffset = DBCHeader.GetSize() + this.Header.RecordSize * i;
                    databaseReader.BaseStream.Seek(recordOffset, SeekOrigin.Begin);

                    T record = databaseReader.ReadRecord <T>((int)this.Header.FieldCount, (int)this.Header.RecordSize, this.Version);

                    foreach (var stringReference in record.GetStringReferences())
                    {
                        ResolveStringReference(stringReference);
                    }

                    this.Records[i] = record;

                    return(record);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DBC{TRecord}"/> class.
        /// </summary>
        /// <param name="inVersion">In version.</param>
        /// <param name="data">ExtendedData.</param>
        public DBC(WarcraftVersion inVersion, byte[] data)
        {
            Version           = inVersion;
            _databaseContents = data;

            using (var databaseReader = new BinaryReader(new MemoryStream(_databaseContents)))
            {
                _header = new DBCHeader(databaseReader.ReadBytes(DBCHeader.GetSize()));

                // Seek to and read the string block
                databaseReader.BaseStream.Seek(_header.RecordCount * _header.RecordSize, SeekOrigin.Current);
                _stringBlockOffset = databaseReader.BaseStream.Position;
                while (databaseReader.BaseStream.Position != databaseReader.BaseStream.Length)
                {
                    Strings.Add(databaseReader.BaseStream.Position - _stringBlockOffset, databaseReader.ReadNullTerminatedString());
                }
            }

            _records = new List <TRecord?>(Count);

            // Initialize the record list with null values
            for (var i = 0; i < Count; ++i)
            {
                _records.Add(null);
            }
        }
Пример #4
0
        /*
         *  Indexing implementation
         */

        /// <inheritdoc />
        public TRecord this[int i]
        {
            get
            {
                if (HasCachedRecordAtIndex(i))
                {
                    return(_records[i] !);
                }

                using var databaseReader = new BinaryReader(new MemoryStream(_databaseContents));
                var recordOffset = DBCHeader.GetSize() + (_header.RecordSize * i);
                databaseReader.BaseStream.Seek(recordOffset, SeekOrigin.Begin);

                var record = databaseReader.ReadRecord <TRecord>((int)_header.FieldCount, (int)_header.RecordSize, Version);

                foreach (var stringReference in record.GetStringReferences())
                {
                    ResolveStringReference(stringReference);
                }

                _records[i] = record;

                return(record);
            }
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DBCEnumerator{TRecord}"/> class.
        /// </summary>
        /// <param name="database">The database.</param>
        /// <param name="data">The data to load.</param>
        /// <param name="stringBlockOffset">The offset of the string block.</param>
        public DBCEnumerator(DBC <TRecord> database, byte[] data, long stringBlockOffset)
        {
            _parentDatabase    = database;
            _stringBlockOffset = stringBlockOffset;
            _databaseReader    = new BinaryReader(new MemoryStream(data));
            _recordIndex       = 0;

            // Seek to the start of the record block
            _databaseReader.BaseStream.Seek(DBCHeader.GetSize(), SeekOrigin.Begin);
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DBC"/> class.
        /// </summary>
        /// <param name="inVersion">In version.</param>
        /// <param name="data">Data.</param>
        public DBC(WarcraftVersion inVersion, byte[] data)
        {
            this.Version = inVersion;

            using (MemoryStream ms = new MemoryStream(data))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    this.Header = new DBCHeader(br.ReadBytes(DBCHeader.GetSize()));

                    for (int i = 0; i < this.Header.RecordCount; ++i)
                    {
                        byte[] rawRecord = br.ReadBytes((int)this.Header.RecordSize);

                        T record = Activator.CreateInstance <T>();
                        record.SetVersion(inVersion);

                        // If the record is of the UnknownRecord type,
                        // this DBC file will just load the data without sanity checking it.
                        if (!(record is UnknownRecord))
                        {
                            // Make sure the provided record type is valid for this database file
                            if (record.GetRecordSize() != this.Header.RecordSize)
                            {
                                throw new ArgumentException("The provided record type is not valid for this database file.");
                            }
                            if (record.GetFieldCount() != this.Header.FieldCount)
                            {
                                throw new ArgumentException("The provided record type is not valid for this database file.");
                            }
                        }

                        record.PostLoad(rawRecord);

                        this.Records.Add(record);
                    }

                    while (br.BaseStream.Position != br.BaseStream.Length)
                    {
                        this.Strings.Add(br.ReadNullTerminatedString());
                    }
                }
            }
        }
Пример #7
0
 /// <inheritdoc />
 public void Reset()
 {
     _databaseReader.BaseStream.Seek(DBCHeader.GetSize(), SeekOrigin.Begin);
     _recordIndex = 0;
     Current      = null;
 }
Пример #8
0
 /// <inheritdoc />
 public void Reset()
 {
     this.DatabaseReader.BaseStream.Seek(DBCHeader.GetSize(), SeekOrigin.Begin);
     this.RecordIndex = 0;
     this.Current     = null;
 }