Exemplo n.º 1
0
        public void ReadObject(IWowClientDBReader dbReader, BinaryReader reader, IDBCDataProvider dbcDataProvider, IDBDataProvider dbDataProvider)
        {
            using (BinaryReader br = reader)
            {
                if (dbReader.HasSeparateIndexColumn)
                {
                    Id = br.ReadUInt32();
                }

                if (dbReader.HasInlineStrings)
                {
                    Name = br.ReadStringNull();
                }
                else if (dbReader is STLReader)
                {
                    int offset = br.ReadInt32();
                    Name = (dbReader as STLReader).ReadString(offset);
                }
                else
                {
                    Name = dbReader.StringTable[br.ReadInt32()];
                }
                Data  = br.ReadUInt16();
                Flags = (ScenarioFlags)br.ReadByte();
                Type  = (ScenarioType)br.ReadByte();
            }
        }
Exemplo n.º 2
0
        public void ReadObject(IWowClientDBReader dbReader, BinaryReader binaryReader, IDBCDataProvider dbcDataProvider, IDBDataProvider dbDataProvider)
        {
            _dbcDataProvider = dbcDataProvider;
            _dbDataProvider  = dbDataProvider;

            using (BinaryReader br = binaryReader)
            {
                if (dbReader.HasInlineStrings)
                {
                    Name            = br.ReadStringNull();
                    NameSubtext     = br.ReadStringNull();
                    Description     = br.ReadStringNull();
                    AuraDescription = br.ReadStringNull();
                }
                else if (dbReader is STLReader)
                {
                    Name            = (dbReader as STLReader).ReadString(br.ReadInt32());
                    NameSubtext     = (dbReader as STLReader).ReadString(br.ReadInt32());
                    Description     = (dbReader as STLReader).ReadString(br.ReadInt32());
                    AuraDescription = (dbReader as STLReader).ReadString(br.ReadInt32());
                }
                else
                {
                    Name            = dbReader.StringTable[br.ReadInt32()];
                    NameSubtext     = dbReader.StringTable[br.ReadInt32()];
                    Description     = dbReader.StringTable[br.ReadInt32()];
                    AuraDescription = dbReader.StringTable[br.ReadInt32()];
                }

                MiscId = br.ReadUInt32();
                Id     = br.ReadUInt32();
                DescriptionVariablesId = br.ReadUInt32();
            }
        }
Exemplo n.º 3
0
        public void ReadObject(IWowClientDBReader dbReader, BinaryReader reader, IDBCDataProvider dbcDataProvider, IDBDataProvider dbDataProvider)
        {
            using (BinaryReader br = reader)
            {
                if (dbReader.HasSeparateIndexColumn)
                {
                    Id = reader.ReadUInt32();
                }

                CriteriaId = reader.ReadUInt32();
                Amount     = reader.ReadUInt32();

                if (dbReader.HasInlineStrings)
                {
                    Description = br.ReadStringNull();
                }
                else if (dbReader is STLReader)
                {
                    int offset = br.ReadInt32();
                    Description = (dbReader as STLReader).ReadString(offset);
                }
                else
                {
                    Description = dbReader.StringTable[br.ReadInt32()];
                }

                ParentId   = reader.ReadUInt16();
                Flags      = (CriteriaTreeFlags)reader.ReadUInt16();
                Operator   = (CriteriaTreeOperator)reader.ReadByte();
                OrderIndex = reader.ReadInt16();
            }
        }
Exemplo n.º 4
0
        public void ReadObject(IWowClientDBReader dbReader, BinaryReader reader, IDBCDataProvider dbcDataProvider, IDBDataProvider dbDataProvider)
        {
            using (BinaryReader br = reader)
            {
                if (dbReader.HasSeparateIndexColumn)
                {
                    Id = br.ReadUInt32();
                }

                if (dbReader.HasInlineStrings)
                {
                    Description = br.ReadStringNull();
                }
                else if (dbReader is STLReader)
                {
                    int offset = br.ReadInt32();
                    Description = (dbReader as STLReader).ReadString(offset);
                }
                else
                {
                    Description = dbReader.StringTable[br.ReadInt32()];
                }

                if (dbReader.HasInlineStrings)
                {
                    Name = br.ReadStringNull();
                }
                else if (dbReader is STLReader)
                {
                    int offset = br.ReadInt32();
                    Name = (dbReader as STLReader).ReadString(offset);
                }
                else
                {
                    Name = dbReader.StringTable[br.ReadInt32()];
                }

                CriteriaTreeId = br.ReadUInt16();
                ScenarioId     = (uint)br.ReadInt16();
                PreviousStepId = (uint)br.ReadInt16();
                QuestRewardId  = br.ReadUInt16();
                StepIndex      = br.ReadByte();
                Flags          = (ScenarioStepFlag)br.ReadByte();
                BonusObjectiveRequiredStepId = (uint)br.ReadInt16();
            }
        }
Exemplo n.º 5
0
        public void ReadObject(IWowClientDBReader dbReader, BinaryReader binaryReader, IDBCDataProvider dbcDataProvider, IDBDataProvider dbDataProvider)
        {
            _dbcDataProvider = dbcDataProvider;
            _dbDataProvider  = dbDataProvider;

            using (BinaryReader br = binaryReader)
            {
                Id = br.ReadUInt32();

                Asset                   = br.ReadUInt32();
                StartAsset              = br.ReadUInt32();
                FailAsset               = br.ReadUInt32();
                StartTimer              = br.ReadUInt16();
                ModifierTreeId          = br.ReadUInt16();
                EligibilityWorldStateId = br.ReadUInt16();
                Type       = (CriteriaType)br.ReadByte();
                StartEvent = br.ReadByte();
                FailEvent  = (CriteriaCondition)br.ReadByte();
                Flags      = br.ReadByte();
                EligibilityWorldStateValue = br.ReadByte();
            }
        }
Exemplo n.º 6
0
        public void ReadObject(IWowClientDBReader dbReader, BinaryReader reader, IDBCDataProvider dbcDataProvider, IDBDataProvider dbDataProvider)
        {
            using (BinaryReader br = reader)
            {
                if (dbReader.HasSeparateIndexColumn)
                {
                    Id = br.ReadUInt32();
                }
                else
                {
                    Id = br.ReadUInt32();
                }

                if (dbReader.HasInlineStrings)
                {
                    Name = br.ReadStringNull();
                }
                else if (dbReader is STLReader)
                {
                    int offset = br.ReadInt32();
                    Name = (dbReader as STLReader).ReadString(offset);
                }
                else
                {
                    int something = br.ReadInt32();
                    if (dbReader.StringTable.ContainsKey(something))
                    {
                        Name = dbReader.StringTable[something];
                    }
                }

                CreatureDisplayId = br.ReadUInt32();
                MapId             = br.ReadUInt16();
                SpellIconId       = br.ReadUInt16();
                Bit        = br.ReadByte();
                Flags      = br.ReadByte();
                OrderIndex = br.ReadInt32();
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Please specify file name!");
                return;
            }

            string fileName = args[0];

            if (!File.Exists(fileName))
            {
                Console.WriteLine("File {0} doesn't exist", fileName);
                return;
            }

            LoadDefinitions();

            if (Path.GetExtension(fileName).ToLowerInvariant() == ".dbc")
                m_reader = new DBCReader(fileName);
            else
                m_reader = new DB2Reader(fileName);

            Console.WriteLine("Records: {0}, Fields: {1}, Row Size {2}, String Table Size: {3}", m_reader.RecordsCount, m_reader.FieldsCount, m_reader.RecordSize, m_reader.StringTableSize);

            DBCName = Path.GetFileNameWithoutExtension(fileName);

            XmlElement definition = m_definitions["DBFilesClient"][DBCName];

            if (definition == null)
            {
                Console.WriteLine("Definition for file {0} not found! File name is case sensitive!", fileName);
                return;
            }

            XmlNodeList fields = definition.GetElementsByTagName("field");
            XmlNodeList indexes = definition.GetElementsByTagName("index");

            StreamWriter sqlWriter = new StreamWriter(fileName + ".sql");

            WriteSqlStructure(sqlWriter, fileName, fields, indexes);

            for (int i = 0; i < m_reader.RecordsCount; ++i)
            {
                BinaryReader reader = m_reader[i];

                StringBuilder result = new StringBuilder();
                result.Append("INSERT INTO `dbc_" + DBCName + "` VALUES (");

                int flds = 0;

                foreach (XmlElement field in fields)
                {
                    switch (field.Attributes["type"].Value)
                    {
                        case "long":
                            result.Append(reader.ReadInt64());
                            break;
                        case "ulong":
                            result.Append(reader.ReadUInt64());
                            break;
                        case "int":
                            result.Append(reader.ReadInt32());
                            break;
                        case "uint":
                            result.Append(reader.ReadUInt32());
                            break;
                        case "short":
                            result.Append(reader.ReadInt16());
                            break;
                        case "ushort":
                            result.Append(reader.ReadUInt16());
                            break;
                        case "sbyte":
                            result.Append(reader.ReadSByte());
                            break;
                        case "byte":
                            result.Append(reader.ReadByte());
                            break;
                        case "float":
                            result.Append(reader.ReadSingle().ToString(CultureInfo.InvariantCulture));
                            break;
                        case "double":
                            result.Append(reader.ReadDouble().ToString(CultureInfo.InvariantCulture));
                            break;
                        case "string":
                            result.Append("\"" + StripBadCharacters(m_reader.StringTable[reader.ReadInt32()]) + "\"");
                            break;
                        default:
                            throw new Exception(String.Format("Unknown field type {0}!", field.Attributes["type"].Value));
                    }

                    if (flds != fields.Count - 1)
                        result.Append(", ");

                    flds++;
                }

                result.Append(");");
                sqlWriter.WriteLine(result);

                if (reader.BaseStream.Position != reader.BaseStream.Length)
                {
                    Console.WriteLine("Data under read!!!, diff {0}", reader.BaseStream.Length - reader.BaseStream.Position);
                }

                reader.Close();
            }

            sqlWriter.Flush();
            sqlWriter.Close();
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Spell.dbc to spell_dbc extractor based on code from TOM_RUS (http://mywowtools.googlecode.com/svn/trunk)");
            if (args.Length < 1)
            {
                Console.WriteLine("Please specify spell number!");
                Console.WriteLine("example: spell_dbc_extractor Spell.dbc 7744");
                return;
            }

            string fileName = "Spell.dbc";
            uint   spellNum = Convert.ToUInt32(args[0]);
            bool   found    = false;

            if (!File.Exists(fileName))
            {
                Console.WriteLine("File {0} doesn't exist. Put {0} in work directory!", fileName);
                return;
            }

            LoadDefinitions();

            if (Path.GetExtension(fileName).ToLowerInvariant() == ".dbc")
            {
                m_reader = new DBCReader(fileName);
            }
            else
            {
                m_reader = new DB2Reader(fileName);
            }

            Console.WriteLine("Records: {0}, Fields: {1}, Row Size {2}, String Table Size: {3}", m_reader.RecordsCount, m_reader.FieldsCount, m_reader.RecordSize, m_reader.StringTableSize);

            DBCName = Path.GetFileNameWithoutExtension(fileName);

            XmlElement definition = m_definitions["DBFilesClient"][DBCName];

            if (definition == null)
            {
                Console.WriteLine("Definition for file {0} not found! File name is case sensitive!", fileName);
                return;
            }

            XmlNodeList fields   = definition.GetElementsByTagName("field");
            XmlNodeList indexes  = definition.GetElementsByTagName("index");
            string      _comment = "";

            for (int i = 0; i < m_reader.RecordsCount; ++i)
            {
                BinaryReader  reader = m_reader[i];
                StringBuilder result = new StringBuilder();
                result.Append("VALUES (");

                int flds        = 0;
                int recordIndex = 0;

                foreach (XmlElement field in fields)
                {
                    var status = field.Attributes["method"].Value;

                    if (status != "skip")
                    {
                        if (flds > 0)
                        {
                            result.Append(", ");
                        }

                        switch (field.Attributes["type"].Value)
                        {
                        case "index":
                            recordIndex = reader.ReadInt32();
                            result.Append(recordIndex);
                            break;

                        case "long":
                            result.Append(reader.ReadInt64());
                            break;

                        case "ulong":
                            result.Append(reader.ReadUInt64());
                            break;

                        case "int":
                            result.Append(reader.ReadInt32());
                            break;

                        case "uint":
                            result.Append(reader.ReadUInt32());
                            break;

                        case "short":
                            result.Append(reader.ReadInt16());
                            break;

                        case "ushort":
                            result.Append(reader.ReadUInt16());
                            break;

                        case "sbyte":
                            result.Append(reader.ReadSByte());
                            break;

                        case "byte":
                            result.Append(reader.ReadByte());
                            break;

                        case "float":
                            result.Append(reader.ReadSingle().ToString(CultureInfo.InvariantCulture));
                            break;

                        case "double":
                            result.Append(reader.ReadDouble().ToString(CultureInfo.InvariantCulture));
                            break;

                        case "string":
                            result.Append("\"" + StripBadCharacters(m_reader.StringTable[reader.ReadInt32()]) + "\"");
                            break;

                        case "comment":
                            _comment = "\"" + StripBadCharacters(m_reader.StringTable[reader.ReadInt32()]) + "\"";
                            result.Append(_comment);
                            break;

                        default:
                            throw new Exception(String.Format("Unknown field type {0}!", field.Attributes["type"].Value));
                        }
                        flds++;
                    }
                    else
                    {
                        switch (field.Attributes["type"].Value)
                        {
                        case "uint":
                        case "index":
                        case "int":
                            reader.ReadInt32();
                            break;

                        case "long":
                        case "ulong":
                            reader.ReadInt64();
                            break;

                        case "short":
                        case "ushort":
                            reader.ReadUInt16();
                            break;

                        case "sbyte":
                            reader.ReadSByte();
                            break;

                        case "byte":
                            reader.ReadByte();
                            break;

                        case "float":
                            reader.ReadSingle();
                            break;

                        case "double":
                            reader.ReadDouble();
                            break;

                        case "string":
                        case "comment":
                            StripBadCharacters(m_reader.StringTable[reader.ReadInt32()]);
                            break;

                        default:
                            throw new Exception(String.Format("Unknown field type {0}!", field.Attributes["type"].Value));
                        }
                    }
                }
                result.Append(" );");

                if (recordIndex == spellNum)
                {
                    StreamWriter sqlWriter = new StreamWriter("mr9999_mangos_spell_" + spellNum + "_override.sql");
                    sqlWriter.Write("-- Produced by spell_dbc_extractor by /dev/rsa based on code from TOM_RUS \n");
                    sqlWriter.Write("-- Replace DBC values for spell {0} - {1} \n", spellNum, _comment);
                    sqlWriter.Write("-- \n");
                    sqlWriter.Write("DELETE FROM `spell_dbc` WHERE `Id` = {0};\n", spellNum);
                    sqlWriter.Write("INSERT INTO `spell_dbc` \n");
                    WriteSqlHeader(sqlWriter, fileName, fields, indexes);
                    sqlWriter.Write(result);
                    sqlWriter.Write("\n\n");
                    sqlWriter.Write("-- Put there corrects for spell data values in readable form (example below) \n");
                    sqlWriter.Write("-- UPDATE `spell_dbc` SET \n");
                    sqlWriter.Write("-- `Mechanic` = 0, \n");
                    sqlWriter.Write("-- `Comment` = \'Replacement for spell {0} ({1})\' \n", spellNum, _comment);
                    sqlWriter.Write("-- WHERE `Id` = {0};\n\n", spellNum);

                    found = true;
                    Console.WriteLine("Found spell {0} - {1}, write to SQL...", spellNum, _comment);
                    sqlWriter.Flush();
                    sqlWriter.Close();
                    break;
                }

                reader.Close();
            }


            if (!found)
            {
                Console.WriteLine("Error: NOT Found spell {0} in dbc file.", spellNum);
            }
        }
Exemplo n.º 9
0
        public void ReadObject(IWowClientDBReader dbReader, BinaryReader reader, IDBCDataProvider dbcDataProvider, IDBDataProvider dbDataProvider)
        {
            Id = reader.ReadUInt32();
            for (int i = 0; i < 3; i++)
            {
                Flags[i] = reader.ReadUInt32();
            }
            Unk1           = reader.ReadSingle();
            Unk2           = reader.ReadSingle();
            BuyPrice       = reader.ReadUInt32();
            SellPrice      = reader.ReadUInt32();
            AllowableClass = reader.ReadInt32();
            AllowableRace  = reader.ReadInt32();
            RequiredSpell  = reader.ReadUInt32();
            MaxCount       = reader.ReadUInt32();
            Stackable      = reader.ReadUInt32();
            for (int i = 0; i < 10; i++)
            {
                ItemStatAllocation[i] = reader.ReadInt32();
            }
            for (int i = 0; i < 10; i++)
            {
                ItemStatSocketCostMultiplier[i] = reader.ReadSingle();
            }
            RangedModRange = reader.ReadSingle();

            if (dbReader.HasInlineStrings)
            {
                Name        = reader.ReadStringNull();
                Name2       = reader.ReadStringNull();
                Name3       = reader.ReadStringNull();
                Name4       = reader.ReadStringNull();
                Description = reader.ReadStringNull();
            }
            else if (dbReader is STLReader)
            {
                Name        = (dbReader as STLReader).ReadString(reader.ReadInt32());
                Name2       = (dbReader as STLReader).ReadString(reader.ReadInt32());
                Name3       = (dbReader as STLReader).ReadString(reader.ReadInt32());
                Name4       = (dbReader as STLReader).ReadString(reader.ReadInt32());
                Description = (dbReader as STLReader).ReadString(reader.ReadInt32());
            }
            else
            {
                Name        = dbReader.StringTable[reader.ReadInt32()];
                Name2       = dbReader.StringTable[reader.ReadInt32()];
                Name3       = dbReader.StringTable[reader.ReadInt32()];
                Name4       = dbReader.StringTable[reader.ReadInt32()];
                Description = dbReader.StringTable[reader.ReadInt32()];
            }

            BagFamily                 = reader.ReadUInt32();
            ArmorDamageModifier       = reader.ReadSingle();
            Duration                  = reader.ReadUInt32();
            StatScalingFactor         = reader.ReadSingle();
            ItemLevel                 = reader.ReadUInt16();
            RequiredSkill             = reader.ReadUInt16();
            RequiredReputationFaction = reader.ReadUInt16();
            for (int i = 0; i < 10; i++)
            {
                ItemStatValue[i] = reader.ReadInt16();
            }
            ScalingStatDistribution = reader.ReadUInt16();
            Delay                  = reader.ReadUInt16();
            PageText               = reader.ReadUInt16();
            StartQuest             = reader.ReadUInt16();
            LockId                 = reader.ReadUInt16();
            RandomProperty         = reader.ReadUInt16();
            RandomSuffix           = reader.ReadUInt16();
            ItemSet                = reader.ReadUInt16();
            Area                   = reader.ReadUInt16();
            Map                    = reader.ReadUInt16();
            SocketBonus            = reader.ReadUInt16();
            GemProperties          = reader.ReadUInt16();
            ItemLimitCategory      = reader.ReadUInt16();
            HolidayId              = reader.ReadUInt16();
            ItemNameDescriptionId  = reader.ReadUInt16();
            Quality                = reader.ReadByte();
            BuyCount               = reader.ReadByte();
            InventoryType          = reader.ReadByte();
            RequiredLevel          = reader.ReadSByte();
            RequiredHonorRank      = reader.ReadByte();
            RequiredCityRank       = reader.ReadByte();
            RequiredReputationRank = reader.ReadByte();
            ContainerSlots         = reader.ReadByte();
            for (int i = 0; i < 10; i++)
            {
                ItemStatType[i] = reader.ReadSByte();
            }
            DamageType    = reader.ReadByte();
            Bonding       = reader.ReadByte();
            LanguageId    = reader.ReadByte();
            PageMaterial  = reader.ReadByte();
            Material      = reader.ReadSByte();
            Sheath        = reader.ReadByte();
            TotemCategory = reader.ReadByte();
            for (int i = 0; i < 3; i++)
            {
                SocketColor[i] = reader.ReadByte();
            }
            CurrencySubstitutionId    = reader.ReadByte();
            CurrencySubstitutionCount = reader.ReadByte();
            ArtifactId        = reader.ReadByte();
            RequiredExpansion = reader.ReadByte();
        }
Exemplo n.º 10
0
        private static void processXML(string file)
        {
            try
            {
                m_reader = new DBCReader(file);
            }
            catch (Exception lastE)
            {
                Console.WriteLine(lastE.Message);
                return;
            }

            m_fields = m_definition.GetElementsByTagName("field");

            string[] types = new string[m_fields.Count];

            for (var j = 0; j < m_fields.Count; ++j)
                types[j] = m_fields[j].Attributes["type"].Value;

            XmlDocument acXmlOut = new XmlDocument();
            XmlNode acXmlOutRoot = acXmlOut.CreateElement("table");
            acXmlOut.AppendChild(acXmlOutRoot);

            XmlNode acXmlOutTR = acXmlOut.CreateElement("tr");
            for (var j = 0; j < m_fields.Count; ++j)
            {
                XmlNode acXmlOutTD = acXmlOut.CreateElement("td");
                acXmlOutTD.AppendChild(acXmlOut.CreateTextNode(m_fields[j].Attributes["name"].Value));
                acXmlOutTR.AppendChild(acXmlOutTD);
            }
            acXmlOutRoot.AppendChild(acXmlOutTR);

            for (var i = 0; i < m_reader.RecordsCount; ++i) // Add rows
            {
                var br = m_reader[i];
                acXmlOutTR = acXmlOut.CreateElement("tr");

                for (var j = 0; j < m_fields.Count; ++j)    // Add cells
                {
                    try
                    {
                        System.Object dbcValue = null;
                        switch (types[j])
                        {
                            case "long":
                                dbcValue = br.ReadInt64();
                                break;
                            case "ulong":
                                dbcValue = br.ReadUInt64();
                                break;
                            case "int":
                                dbcValue = br.ReadInt32();
                                break;
                            case "uint":
                                dbcValue = br.ReadUInt32();
                                break;
                            case "short":
                                dbcValue = br.ReadInt16();
                                break;
                            case "ushort":
                                dbcValue = br.ReadUInt16();
                                break;
                            case "sbyte":
                                dbcValue = br.ReadSByte();
                                break;
                            case "byte":
                                dbcValue = br.ReadByte();
                                break;
                            case "float":
                                dbcValue = br.ReadSingle();
                                break;
                            case "double":
                                dbcValue = br.ReadDouble();
                                break;
                            case "string":
                                dbcValue = m_reader is WDBReader ? br.ReadStringNull() : m_reader.StringTable[br.ReadInt32()];
                                break;
                            default:
                                break;
                        }
                        XmlNode acXmlOutTD = acXmlOut.CreateElement("td");
                        acXmlOutTD.AppendChild(acXmlOut.CreateTextNode(dbcValue.ToString()));
                        acXmlOutTR.AppendChild(acXmlOutTD);
                    }
                    catch (System.Exception lastE) { Console.WriteLine(lastE.Message); }
                }
                acXmlOutRoot.AppendChild(acXmlOutTR);
            }
            acXmlOut.Save(Path.Combine(m_workingFolder, Path.GetFileName(file) + ".csv.html"));
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            Console.WriteLine("Spell.dbc to spell_dbc extractor based on code from TOM_RUS (http://mywowtools.googlecode.com/svn/trunk)");
            if (args.Length < 1)
            {
                Console.WriteLine("Please specify spell number!");
                Console.WriteLine("example: spell_dbc_extractor Spell.dbc 7744");
                return;
            }

            string fileName = "Spell.dbc";
            uint    spellNum = Convert.ToUInt32(args[0]);
            bool found = false;

            if (!File.Exists(fileName))
            {
                Console.WriteLine("File {0} doesn't exist. Put {0} in work directory!", fileName);
                return;
            }

            LoadDefinitions();

            if (Path.GetExtension(fileName).ToLowerInvariant() == ".dbc")
                m_reader = new DBCReader(fileName);
            else
                m_reader = new DB2Reader(fileName);

            Console.WriteLine("Records: {0}, Fields: {1}, Row Size {2}, String Table Size: {3}", m_reader.RecordsCount, m_reader.FieldsCount, m_reader.RecordSize, m_reader.StringTableSize);

            DBCName = Path.GetFileNameWithoutExtension(fileName);

            XmlElement definition = m_definitions["DBFilesClient"][DBCName];

            if (definition == null)
            {
                Console.WriteLine("Definition for file {0} not found! File name is case sensitive!", fileName);
                return;
            }

            XmlNodeList fields = definition.GetElementsByTagName("field");
            XmlNodeList indexes = definition.GetElementsByTagName("index");
            string _comment = "";

            for (int i = 0; i < m_reader.RecordsCount; ++i)
            {
                BinaryReader reader = m_reader[i];
                StringBuilder result = new StringBuilder();
                result.Append("VALUES (");

                int flds = 0;
                int recordIndex = 0;

                foreach (XmlElement field in fields)
                {
                    var status = field.Attributes["method"].Value;

                    if (status != "skip")
                    {
                        if (flds > 0)
                        {
                            result.Append(", ");
                        }

                        switch (field.Attributes["type"].Value)
                        {
                            case "index":
                                recordIndex = reader.ReadInt32();
                                result.Append(recordIndex);
                                break;
                            case "long":
                                result.Append(reader.ReadInt64());
                                break;
                            case "ulong":
                                result.Append(reader.ReadUInt64());
                                break;
                            case "int":
                                result.Append(reader.ReadInt32());
                                break;
                            case "uint":
                                result.Append(reader.ReadUInt32());
                                break;
                            case "short":
                                result.Append(reader.ReadInt16());
                                break;
                            case "ushort":
                                result.Append(reader.ReadUInt16());
                                break;
                            case "sbyte":
                                result.Append(reader.ReadSByte());
                                break;
                            case "byte":
                                result.Append(reader.ReadByte());
                                break;
                            case "float":
                                result.Append(reader.ReadSingle().ToString(CultureInfo.InvariantCulture));
                                break;
                            case "double":
                                result.Append(reader.ReadDouble().ToString(CultureInfo.InvariantCulture));
                                break;
                            case "string":
                                result.Append("\"" + StripBadCharacters(m_reader.StringTable[reader.ReadInt32()]) + "\"");
                                break;
                            case "comment":
                                _comment = "\"" + StripBadCharacters(m_reader.StringTable[reader.ReadInt32()]) + "\"";
                                result.Append(_comment);
                                break;
                            default:
                                throw new Exception(String.Format("Unknown field type {0}!", field.Attributes["type"].Value));
                        }
                        flds++;
                    }
                    else
                    {
                        switch (field.Attributes["type"].Value)
                        {
                            case "uint":
                            case "index":
                            case "int":
                                reader.ReadInt32();
                                break;
                            case "long":
                            case "ulong":
                                reader.ReadInt64();
                                break;
                            case "short":
                            case "ushort":
                                reader.ReadUInt16();
                                break;
                            case "sbyte":
                                reader.ReadSByte();
                                break;
                            case "byte":
                                reader.ReadByte();
                                break;
                            case "float":
                                reader.ReadSingle();
                                break;
                            case "double":
                                reader.ReadDouble();
                                break;
                            case "string":
                            case "comment":
                                StripBadCharacters(m_reader.StringTable[reader.ReadInt32()]);
                                break;
                            default:
                                throw new Exception(String.Format("Unknown field type {0}!", field.Attributes["type"].Value));
                        }
                    }
                }
                result.Append(" );");

                if (recordIndex == spellNum)
                {
                    StreamWriter sqlWriter = new StreamWriter("mr9999_mangos_spell_" + spellNum + "_override.sql");
                    sqlWriter.Write("-- Produced by spell_dbc_extractor by /dev/rsa based on code from TOM_RUS \n");
                    sqlWriter.Write("-- Replace DBC values for spell {0} - {1} \n",spellNum,_comment);
                    sqlWriter.Write("-- \n");
                    sqlWriter.Write("DELETE FROM `spell_dbc` WHERE `Id` = {0};\n", spellNum);
                    sqlWriter.Write("INSERT INTO `spell_dbc` \n");
                    WriteSqlHeader(sqlWriter, fileName, fields, indexes);
                    sqlWriter.Write(result);
                    sqlWriter.Write("\n\n");
                    sqlWriter.Write("-- Put there corrects for spell data values in readable form (example below) \n" );
                    sqlWriter.Write("-- UPDATE `spell_dbc` SET \n");
                    sqlWriter.Write("-- `Mechanic` = 0, \n");
                    sqlWriter.Write("-- `Comment` = \'Replacement for spell {0} ({1})\' \n",spellNum, _comment);
                    sqlWriter.Write("-- WHERE `Id` = {0};\n\n", spellNum);

                    found = true;
                    Console.WriteLine("Found spell {0} - {1}, write to SQL...",spellNum, _comment);
                    sqlWriter.Flush();
                    sqlWriter.Close();
                    break;
                }

                reader.Close();
            }

            if (!found)
            {
                Console.WriteLine("Error: NOT Found spell {0} in dbc file.", spellNum);
            }
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Please specify file name!");
                return;
            }

            string fileName = args[0];

            if (!File.Exists(fileName))
            {
                Console.WriteLine("File {0} doesn't exist", fileName);
                return;
            }

            LoadDefinitions();

            if (Path.GetExtension(fileName).ToLowerInvariant() == ".dbc")
            {
                m_reader = new DBCReader(fileName);
            }
            else
            {
                m_reader = new DB2Reader(fileName);
            }

            Console.WriteLine("Records: {0}, Fields: {1}, Row Size {2}, String Table Size: {3}", m_reader.RecordsCount, m_reader.FieldsCount, m_reader.RecordSize, m_reader.StringTableSize);

            DBCName = Path.GetFileNameWithoutExtension(fileName);

            XmlElement definition = m_definitions["DBFilesClient"][DBCName];

            if (definition == null)
            {
                Console.WriteLine("Definition for file {0} not found! File name is case sensitive!", fileName);
                return;
            }

            XmlNodeList fields  = definition.GetElementsByTagName("field");
            XmlNodeList indexes = definition.GetElementsByTagName("index");

            StreamWriter sqlWriter = new StreamWriter(fileName + ".sql");

            WriteSqlStructure(sqlWriter, fileName, fields, indexes);

            for (int i = 0; i < m_reader.RecordsCount; ++i)
            {
                BinaryReader reader = m_reader[i];

                StringBuilder result = new StringBuilder();
                result.Append("INSERT INTO `dbc_" + DBCName + "` VALUES (");

                int flds = 0;

                foreach (XmlElement field in fields)
                {
                    switch (field.Attributes["type"].Value)
                    {
                    case "long":
                        result.Append(reader.ReadInt64());
                        break;

                    case "ulong":
                        result.Append(reader.ReadUInt64());
                        break;

                    case "int":
                        result.Append(reader.ReadInt32());
                        break;

                    case "uint":
                        result.Append(reader.ReadUInt32());
                        break;

                    case "short":
                        result.Append(reader.ReadInt16());
                        break;

                    case "ushort":
                        result.Append(reader.ReadUInt16());
                        break;

                    case "sbyte":
                        result.Append(reader.ReadSByte());
                        break;

                    case "byte":
                        result.Append(reader.ReadByte());
                        break;

                    case "float":
                        result.Append(reader.ReadSingle().ToString(CultureInfo.InvariantCulture));
                        break;

                    case "double":
                        result.Append(reader.ReadDouble().ToString(CultureInfo.InvariantCulture));
                        break;

                    case "string":
                        result.Append("\"" + StripBadCharacters(m_reader.StringTable[reader.ReadInt32()]) + "\"");
                        break;

                    default:
                        throw new Exception(String.Format("Unknown field type {0}!", field.Attributes["type"].Value));
                    }

                    if (flds != fields.Count - 1)
                    {
                        result.Append(", ");
                    }

                    flds++;
                }

                result.Append(");");
                sqlWriter.WriteLine(result);

                if (reader.BaseStream.Position != reader.BaseStream.Length)
                {
                    Console.WriteLine("Data under read!!!, diff {0}", reader.BaseStream.Length - reader.BaseStream.Position);
                }

                reader.Close();
            }

            sqlWriter.Flush();
            sqlWriter.Close();
        }
Exemplo n.º 13
0
        private void ReadDB(string file)
        {
            try
            {
                m_dbreader = DBReaderFactory.GetReader(file);
            }
            catch (Exception ex)
            {
                // e.Cancel = true;
                return;
            }

            m_fields = m_definition.GetElementsByTagName("field");

            string[] types = new string[m_fields.Count];

            for (int j = 0; j < m_fields.Count; ++j)
            {
                types[j] = m_fields[j].Attributes["type"].Value;
            }

            // hack for *.adb files (because they don't have FieldsCount)
            bool notADB = !(m_dbreader is ADBReader);
            // hack for *.wdb files (because they don't have FieldsCount)
            bool notWDB = !(m_dbreader is WDBReader);
            // hack for *.wdb files (because they don't have FieldsCount)
            bool notSTL = !(m_dbreader is STLReader);

            bool notDB5 = !(m_dbreader is DB5Reader);

            int fcount = GetFieldsCount(m_fields);

            if (fcount != m_dbreader.FieldsCount && notADB && notWDB && notSTL && notDB5)
            {
                if (!types[0].Equals("index"))
                {
                    string msg = String.Format(CultureInfo.InvariantCulture, "{0} has invalid definition!\nFields count mismatch: got {1}, expected {2}", Path.GetFileName(file), fcount, m_dbreader.FieldsCount);

                    return;
                }
            }

            m_dataTable        = new PluginInterface.DataTable(Path.GetFileName(file));
            m_dataTable.Locale = CultureInfo.InvariantCulture;

            CreateColumns();                                // Add columns

            CreateIndexes();                                // Add indexes

            //bool extraData = false;

            //   Console.WriteLine(m_dbreader.RecordsCount);

            for (int i = 0; i < m_dbreader.RecordsCount; ++i) // Add rows
            {
                DataRow dataRow = m_dataTable.NewRow();

                //    Console.WriteLine(m_dbreader.RecordsCount);

                using (BinaryReader br = m_dbreader[i])
                {
                    //  Console.WriteLine(m_dbreader[i].BaseStream.Length);

                    for (int j = 0; j < m_fields.Count; ++j)    // Add cells
                    {
                        //  Console.WriteLine(m_fields.Count);

                        switch (types[j])
                        {
                        case "long":
                            dataRow[j] = br.ReadInt64();
                            break;

                        case "ulong":
                            dataRow[j] = br.ReadUInt64();
                            break;

                        case "int":
                            dataRow[j] = br.ReadInt32();
                            break;

                        case "uint":
                            dataRow[j] = br.ReadUInt32();
                            break;

                        case "short":
                            dataRow[j] = br.ReadInt16();
                            break;

                        case "ushort":
                            dataRow[j] = br.ReadUInt16();
                            break;

                        case "sbyte":
                            dataRow[j] = br.ReadSByte();
                            break;

                        case "byte":
                            dataRow[j] = br.ReadByte();
                            break;

                        case "float":
                            dataRow[j] = br.ReadSingle();
                            break;

                        case "double":
                            dataRow[j] = br.ReadDouble();
                            break;

                        case "index":
                            dataRow[j] = m_dbreader.index[i];
                            break;

                        case "int3":
                            byte[] bytes = br.ReadBytes(3);

                            byte[] buffer = new byte[4];

                            Buffer.BlockCopy(bytes, 0, buffer, 0, bytes.Length);

                            dataRow[j] = BitConverter.ToInt32(buffer, 0);

                            break;

                        case "string":
                            if (m_dbreader is WDBReader)
                            {
                                dataRow[j] = br.ReadStringNull();
                            }
                            else if (m_dbreader is STLReader)
                            {
                                int offset = br.ReadInt32();
                                dataRow[j] = (m_dbreader as STLReader).ReadString(offset);
                            }
                            else
                            {
                                try
                                {
                                    dataRow[j] = m_dbreader.StringTable[br.ReadInt32()];
                                }
                                catch
                                {
                                    dataRow[j] = "Invalid string index!";
                                }
                            }
                            break;

                        case "nstring":
                            try
                            {
                                dataRow[j] = br.ReadStringNull();
                            }
                            catch
                            {
                                dataRow[j] = "Invalid string index!";
                            }
                            break;

                        case "cstring":
                            dataRow[j] = br.ReadStringNumber();
                            break;

                        default:
                            throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "Unknown field type {0}!", types[j]));
                        }
                    }
                }

                m_dataTable.Rows.Add(dataRow);

                //int percent = (int)((float)m_dataTable.Rows.Count / (float)m_dbreader.RecordsCount * 100.0f);
                //(sender as BackgroundWorker).ReportProgress(percent);
            }



            Export2SQL.Export2SQL tosql = new Export2SQL.Export2SQL();
            tosql.Run(m_dataTable);

            CloseFile();
        }
Exemplo n.º 14
0
        private XmlElement CreateDefaultDefinition()
        {
            if (reader is DB3Reader)
            {
                if (reader.RecordSize / reader.FieldsCount == 4)
                {
                    var doc = new XmlDocument();

                    XmlElement newnode = doc.CreateElement(DBCName);
                    newnode.SetAttributeNode("build", "").Value = reader.Build.ToString();

                    for (int i = 0; i < reader.FieldsCount; ++i)
                    {
                        XmlElement ele = doc.CreateElement("field");
                        ele.SetAttributeNode("type", "").Value = "int";
                        ele.SetAttributeNode("name", "").Value = String.Format("field{0}", i);
                        newnode.AppendChild(ele);
                    }

                    return(newnode);
                }
                else
                {
                    var doc = new XmlDocument();

                    XmlElement newnode = doc.CreateElement(DBCName);
                    newnode.SetAttributeNode("build", "").Value = reader.Build.ToString();

                    for (int i = 0; i < reader.FieldsCount; ++i)
                    {
                        /*if (i == 0)
                         * {
                         *  XmlElement index = doc.CreateElement("index");
                         *  XmlNode primary = index.AppendChild(doc.CreateElement("primary"));
                         *  primary.InnerText = "field0";
                         *  newnode.AppendChild(index);
                         * }*/

                        XmlElement ele = doc.CreateElement("field");
                        ele.SetAttributeNode("type", "").Value = "ushort";
                        ele.SetAttributeNode("name", "").Value = String.Format("field{0}", i);
                        newnode.AppendChild(ele);
                    }

                    return(newnode);
                }
            }
            else if (reader is DB5Reader)
            {
                DB5Reader db5reader = (DB5Reader)reader;

                var doc = new XmlDocument();

                XmlElement newnode = doc.CreateElement(DBCName);
                newnode.SetAttributeNode("build", "").Value = reader.Build.ToString();

                XmlElement tmpnode = doc.CreateElement(DBCName);

                List <fType> types = new List <fType>();


                for (int i = 0; i < db5reader.typeList.Count; i++)
                {
                    if (i < db5reader.typeList.Count - 1 && ((32 - db5reader.typeList[i][0]) / 8) != db5reader.typeList[i + 1][1] - db5reader.typeList[i][1])
                    {
                        int count = (db5reader.typeList[i + 1][1] - db5reader.typeList[i][1]) / ((32 - db5reader.typeList[i][0]) / 8);


                        fType ftype1;
                        ftype1.typeName = typeCov(((32 - db5reader.typeList[i][0]) / 8));
                        ftype1.isArray  = 1;

                        types.Add(ftype1);

                        for (int j = 0; j < count - 1; j++)
                        {
                            fType ftype;
                            ftype.typeName = typeCov(((32 - db5reader.typeList[i][0]) / 8));
                            ftype.isArray  = 2;

                            types.Add(ftype);
                        }
                    }
                    else
                    {
                        fType ftype;
                        ftype.typeName = typeCov(((32 - db5reader.typeList[i][0]) / 8));
                        ftype.isArray  = 0;
                        types.Add(ftype);
                    }
                }

                int ar = 0;

                int temp = 0;


                for (int i = 0; i < types.Count; i++)
                {
                    XmlElement ele = doc.CreateElement("field");



                    ele.SetAttributeNode("type", "").Value = types[i].typeName;

                    if (types[i].isArray == 1)
                    {
                        ar = 1;
                        ele.SetAttributeNode("name", "").Value = String.Format("field{0}_{1}", i, ar);
                        temp = i;
                    }
                    else if (types[i].isArray == 2)
                    {
                        ar++;
                        ele.SetAttributeNode("name", "").Value = String.Format("field{0}_{1}", temp, ar);
                    }
                    else
                    {
                        ele.SetAttributeNode("name", "").Value = String.Format("field{0}", i);
                        ar   = 0;
                        temp = i;
                    }

                    tmpnode.AppendChild(ele);
                    // i++;
                }

                try
                {
                    dbreader = DBReaderFactory.GetReader(DBCFile);
                }
                catch (Exception ex)
                {
                }

                DataTable dt = new DataTable();

                dt = CreateColumns(dt, tmpnode.ChildNodes);

                for (int i = 0; i < reader.RecordsCount; i++)
                {
                    DataRow dataRow = dt.NewRow();

                    using (BinaryReader br = dbreader[i])
                    {
                        for (int j = 0; j < types.Count; j++)
                        {
                            switch (types[j].typeName)
                            {
                            case "long":
                                dataRow[j] = br.ReadInt64();
                                break;

                            case "ulong":
                                dataRow[j] = br.ReadUInt64();
                                break;

                            case "int":
                                dataRow[j] = br.ReadInt32();
                                break;

                            case "uint":
                                dataRow[j] = br.ReadUInt32();
                                break;

                            case "short":
                                dataRow[j] = br.ReadInt16();
                                break;

                            case "ushort":
                                dataRow[j] = br.ReadUInt16();
                                break;

                            case "sbyte":
                                dataRow[j] = br.ReadSByte();
                                break;

                            case "byte":
                                dataRow[j] = br.ReadByte();
                                break;

                            case "float":
                                dataRow[j] = br.ReadSingle();
                                break;

                            case "double":
                                dataRow[j] = br.ReadDouble();
                                break;

                            case "index":
                                dataRow[j] = m_dbreader.index[i];
                                break;

                            case "int3":
                                byte[] bytes = br.ReadBytes(3);

                                byte[] buffer = new byte[4];

                                Buffer.BlockCopy(bytes, 0, buffer, 0, bytes.Length);

                                dataRow[j] = BitConverter.ToInt32(buffer, 0);

                                break;

                            case "string":
                                if (m_dbreader is WDBReader)
                                {
                                    dataRow[j] = br.ReadStringNull();
                                }
                                else if (m_dbreader is STLReader)
                                {
                                    int offset = br.ReadInt32();
                                    dataRow[j] = (m_dbreader as STLReader).ReadString(offset);
                                }
                                else
                                {
                                    try
                                    {
                                        dataRow[j] = m_dbreader.StringTable[br.ReadInt32()];
                                    }
                                    catch
                                    {
                                        dataRow[j] = "Invalid string index!";
                                    }
                                }
                                break;

                            case "nstring":
                                try
                                {
                                    dataRow[j] = br.ReadStringNull();
                                }
                                catch
                                {
                                    dataRow[j] = "Invalid string index!";
                                }
                                break;

                            case "cstring":
                                dataRow[j] = br.ReadStringNumber();
                                break;

                            default:
                                throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "Unknown field type {0}!", types[j]));
                            }
                        }
                    }
                    dt.Rows.Add(dataRow);
                }



                for (int i = 0; i < types.Count; i++)
                {
                    bool isString = true;

                    if (types[i].typeName.Equals("int"))
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (!reader.StringTable.ContainsKey((int)dr[i]))
                            {
                                isString = false;
                                break;
                            }
                        }
                        if (isString)
                        {
                            fType ft;
                            ft.typeName = "string";
                            ft.isArray  = types[i].isArray;

                            types[i] = ft;
                        }
                    }
                }

                if (db5reader.index.Count > 0)
                {
                    XmlElement elei = doc.CreateElement("field");
                    elei.SetAttributeNode("type", "").Value = "index";
                    elei.SetAttributeNode("name", "").Value = String.Format("m_ID");
                    newnode.AppendChild(elei);
                }


                ar = 0;

                temp = 0;


                for (int i = 0; i < types.Count; i++)
                {
                    XmlElement ele = doc.CreateElement("field");



                    ele.SetAttributeNode("type", "").Value = types[i].typeName;

                    if (types[i].isArray == 1)
                    {
                        ar = 1;
                        ele.SetAttributeNode("name", "").Value = String.Format("field{0}_{1}", i, ar);
                        temp = i;
                    }
                    else if (types[i].isArray == 2)
                    {
                        ar++;
                        ele.SetAttributeNode("name", "").Value = String.Format("field{0}_{1}", temp, ar);
                    }
                    else
                    {
                        ele.SetAttributeNode("name", "").Value = String.Format("field{0}", i);
                        ar   = 0;
                        temp = i;
                    }

                    newnode.AppendChild(ele);
                    // i++;
                }


                return(newnode);
            }
            else
            {
                if (reader.RecordSize % reader.FieldsCount == 0) // only for files with 4 byte fields
                {
                    var doc = new XmlDocument();

                    XmlElement newnode = doc.CreateElement(DBCName);
                    newnode.SetAttributeNode("build", "").Value = reader.Build.ToString();

                    for (int i = 0; i < reader.FieldsCount; ++i)
                    {
                        XmlElement ele = doc.CreateElement("field");
                        ele.SetAttributeNode("type", "").Value = "int";
                        ele.SetAttributeNode("name", "").Value = String.Format("field{0}", i);
                        newnode.AppendChild(ele);
                    }

                    return(newnode);
                }
                else
                {
                    var doc = new XmlDocument();

                    XmlElement newnode = doc.CreateElement(DBCName);
                    newnode.SetAttributeNode("build", "").Value = reader.Build.ToString();

                    for (int i = 0; i < reader.FieldsCount; ++i)
                    {
                        XmlElement ele = doc.CreateElement("field");
                        ele.SetAttributeNode("type", "").Value = "ushort";
                        ele.SetAttributeNode("name", "").Value = String.Format("field{0}", i);
                        newnode.AppendChild(ele);
                    }

                    return(newnode);
                }
            }

            //return null;
        }
Exemplo n.º 15
0
        private void InitDefinitions()
        {
            var m_name = DBCName;

            var file = DBCFile;

            var ext = Path.GetExtension(file).ToUpperInvariant();


            if (ext == ".DBC")
            {
                reader = new DBCReader(file);
            }
            else if (ext == ".DB2")
            {
                try
                {
                    reader = new DB2Reader(file);
                }
                catch
                {
                    try
                    {
                        reader = new DB3Reader(file);
                    }
                    catch
                    {
                        try
                        {
                            reader = new DB4Reader(file);
                        }
                        catch
                        {
                            reader = new DB5Reader(file);
                        }
                    }
                }
            }
            else if (ext == ".ADB")
            {
                try
                {
                    reader = new ADBReader(file);
                }
                catch
                {
                    try
                    {
                        reader = new DB3Reader(file);
                    }
                    catch
                    {
                        reader = new ADB5Reader(file);
                    }
                }
            }
            else if (ext == ".WDB")
            {
                reader = new WDBReader(file);
            }



            XmlElement def = Definition;

            if (def == null)
            {
                def = CreateDefaultDefinition();
                if (def == null)
                {
                    throw new Exception((String.Format("Can't create default definitions for {0}", m_name)));
                }
            }

            this.m_definition = def;

            XmlDocument doc = new XmlDocument();

            string docPath = "dbclayout.xml";

            doc.Load(docPath);

            var newNode = doc.ImportNode(def, true);

            doc["DBFilesClient"].AppendChild(newNode);
            doc.Save(docPath);
        }