示例#1
0
        public void ReloadContents()
        {
            var bodyWatch   = new Stopwatch();
            var stringWatch = new Stopwatch();

            bodyWatch.Start();
            Body   = new DBCBody();
            Reader = new DBCReader(_filePath);
            var name    = Path.GetFileNameWithoutExtension(_filePath);
            var binding = BindingManager.GetInstance().FindBinding(name);

            if (binding == null)
            {
                throw new Exception($"Binding not found: {name}.txt");
            }
            Header = Reader.ReadDBCHeader();
            Reader.ReadDBCRecords(Body, name);
            bodyWatch.Stop();
            stringWatch.Start();
            Reader.ReadStringBlock();
            stringWatch.Stop();
            var totalElapsed = stringWatch.ElapsedMilliseconds + bodyWatch.ElapsedMilliseconds;

            Console.WriteLine(
                $"Loaded {name}.dbc into memory in {totalElapsed}ms. Records: {bodyWatch.ElapsedMilliseconds}ms, strings: {stringWatch.ElapsedMilliseconds}ms");
        }
示例#2
0
        /**
         * Reads all the records from the DBC file. It puts each record in a
         * array of key value pairs inside the body. The key value pairs are
         * column name to column value.
         */
        public void ReadDBCRecords <RecordStruct>(DBCBody body, int recordSize)
        {
            if (Header.RecordSize != recordSize)
            {
                throw new Exception($"The DBC [{ filePath }] is not supported! It's version is not 3.3.5a 12340, expected record size [{ Header.RecordSize }] got [{ recordSize }].");
            }

            body.RecordMaps = new Dictionary <string, object> [Header.RecordCount];
            for (int i = 0; i < Header.RecordCount; ++i)
            {
                body.RecordMaps[i] = new Dictionary <string, object>((int)Header.FieldCount);
            }
            byte[] readBuffer;
            using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
            {
                using (BinaryReader reader = new BinaryReader(fileStream))
                {
                    reader.BaseStream.Position = filePosition;
                    for (uint i = 0; i < Header.RecordCount; ++i)
                    {
                        readBuffer = new byte[recordSize];
                        readBuffer = reader.ReadBytes(recordSize);

                        RecordStruct record = ReadStruct <RecordStruct>(reader, readBuffer);

                        var entry = body.RecordMaps[i];
                        foreach (var field in typeof(RecordStruct).GetFields())
                        {
                            entry.Add(field.Name, field.GetValue(record));
                        }
                    }
                    filePosition = reader.BaseStream.Position;
                }
            }
        }
示例#3
0
        public void ReloadContents()
        {
            Body   = new DBCBody();
            Reader = new DBCReader(_filePath);
            var name    = Path.GetFileNameWithoutExtension(_filePath);
            var binding = BindingManager.GetInstance().FindBinding(name);

            if (binding == null)
            {
                throw new Exception($"Binding not found: {name}.txt");
            }
            Header = Reader.ReadDBCHeader();
            Reader.ReadDBCRecords(Body, name);
            Reader.ReadStringBlock();
        }
示例#4
0
        /**
         * Reads all the records from the DBC file. It puts each record in a
         * array of key value pairs inside the body. The key value pairs are
         * column name to column value.
         */
        public void ReadDBCRecords(DBCBody body, string bindingName)
        {
            var binding = BindingManager.GetInstance().FindBinding(bindingName);

            if (binding == null)
            {
                throw new Exception($"Binding not found: {bindingName}.txt");
            }
            if (_header.RecordSize != binding.CalcRecordSize())
            {
                throw new Exception($"Binding [{_filePath}] fields size does not match the DBC header record size; expected record size [{binding.CalcRecordSize()}] got [{_header.RecordSize}].");
            }
            if (_header.FieldCount != binding.CalcFieldCount())
            {
                throw new Exception($"Binding [{_filePath}] field count does not match the DBC field count; expected [{binding.CalcFieldCount()}] got [{_header.FieldCount}].");
            }

            body.RecordMaps = new Dictionary <string, object> [_header.RecordCount];
            for (int i = 0; i < _header.RecordCount; ++i)
            {
                body.RecordMaps[i] = new Dictionary <string, object>((int)_header.FieldCount);
            }
            using (FileStream fileStream = new FileStream(_filePath, FileMode.Open))
            {
                using (BinaryReader reader = new BinaryReader(fileStream))
                {
                    reader.BaseStream.Position = _filePosition;
                    for (uint i = 0; i < _header.RecordCount; ++i)
                    {
                        var entry = body.RecordMaps[i];
                        foreach (var field in binding.Fields)
                        {
                            switch (field.Type)
                            {
                            case BindingType.INT:
                            {
                                entry.Add(field.Name, reader.ReadInt32());
                                break;
                            }

                            case BindingType.STRING_OFFSET:
                            case BindingType.UINT:
                            {
                                entry.Add(field.Name, reader.ReadUInt32());
                                break;
                            }

                            case BindingType.UINT8:
                            {
                                entry.Add(field.Name, reader.ReadByte());
                                break;
                            }

                            case BindingType.FLOAT:
                            {
                                entry.Add(field.Name, reader.ReadSingle());
                                break;
                            }

                            case BindingType.DOUBLE:
                            {
                                entry.Add(field.Name, reader.ReadDouble());
                                break;
                            }

                            default:
                                throw new Exception($"Found unkown field type for column {field.Name} type {field.Type} in binding {binding.Name}");
                            }
                        }
                    }
                    _filePosition = reader.BaseStream.Position;
                }
            }
        }