Пример #1
0
        public static void LoadFiles()
        {
            Spell = new DBCFile<SpellEntry>("DBFilesClient\\Spell.dbc");
            Spell.LoadData();
            SkillLineAbility = new DBCFile<DBC.SkillLineAbility>(@"DBFilesClient\SkillLineAbility.dbc");
            SkillLineAbility.LoadData();
            string str = "Non 0 entries:\n";
            var qry = from dbc in SkillLineAbility.Records
                      where
                          dbc.chrRaces != 0
                      select
                      dbc.ID;

            foreach (var entry in qry)
            {
                if (Spell.ContainsKey(entry))
                    str += Spell[entry].Name + ", ";
            }

            System.Windows.Forms.MessageBox.Show(str);
            Map = new DBCFile<MapEntry>("DBFilesClient\\Map.dbc");
            LoadingScreen = new DBCFile<LoadingScreenEntry>("DBFilesClient\\LoadingScreens.dbc");
            AreaTable = new DBCFile<AreaTableEntry>("DBFilesClient\\AreaTable.dbc");
            Light = new DBCFile<DBC.Light>("DBFilesClient\\Light.dbc");
            if (Game.GameManager.IsPandaria == false)
            {
                LightIntBand = new DBCFile<DBC.LightIntBand>("DBFilesClient\\LightIntBand.dbc");
                LightFloatBand = new DBCFile<DBC.LightFloatBand>("DBFilesClient\\LightFloatBand.dbc");
            }
            LightParams = new DBCFile<DBC.LightParams>("DBFilesClient\\LightParams.dbc");
            LightSkyBox = new DBCFile<DBC.LightSkyBox>("DBFilesClient\\LightSkybox.dbc");

            if (Game.GameManager.BuildNumber > 12340)
                Map.SetLoadType(MapConverter.GetRawType(), new MapConverter());

            Map.LoadData();
            LoadingScreen.LoadData();

            if (Game.GameManager.BuildNumber > 12340)
                AreaTable.SetLoadType(AreaTableConverter.GetRawType(), new AreaTableConverter());
            AreaTable.LoadData();
            Light.LoadData();
            if (Game.GameManager.IsPandaria == false)
            {
                LightFloatBand.LoadData();
                LightIntBand.LoadData();
            }

            if (Game.GameManager.BuildNumber > 12340)
                LightParams.SetLoadType(typeof(LightParams_4), new LightParamsConverter());
            LightParams.LoadData();
            LightSkyBox.LoadData();
        }
Пример #2
0
        public void WriteDBC(DBCFile <T> file)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(file.FileName));
            mFile = file;

            FileStream   strm = File.OpenWrite(file.FileName);
            BinaryWriter bw   = new BinaryWriter(strm);

            byte[] bytes = Encoding.UTF8.GetBytes("WDBC");
            bw.Write(bytes);
            bw.Write(file.Records.Count);
            Type type       = typeof(T);
            var  fields     = type.GetFields();
            int  fieldCount = 0;

            foreach (var field in fields)
            {
                switch (Type.GetTypeCode(field.FieldType))
                {
                case TypeCode.String:
                {
                    var attribs = field.GetCustomAttributes(typeof(LocalizedAttribute), false);
                    if (attribs == null || attribs.Length == 0)
                    {
                        ++fieldCount;
                    }
                    else
                    {
                        fieldCount += 17;
                    }
                    break;
                }

                case TypeCode.Object:
                {
                    if (field.FieldType.IsArray)
                    {
                        var attribs = field.GetCustomAttributes(typeof(ArrayAttribute), false);
                        if (attribs == null || attribs.Length == 0)
                        {
                            throw new InvalidOperationException("For arrays the [Array] attribute must set with the desired size of the array!");
                        }

                        fieldCount += (int)(attribs[0] as ArrayAttribute).Length;
                    }
                }
                break;

                default:
                    ++fieldCount;
                    break;
                }
            }

            bw.Write(fieldCount);
            bw.Write(fieldCount * 4);
            bw.Write(0);

            foreach (var rec in file.Records)
            {
                foreach (var field in fields)
                {
                    switch (Type.GetTypeCode(field.FieldType))
                    {
                    case TypeCode.Int32:
                    {
                        int value = (int)field.GetValue(rec);
                        bw.Write(value);
                        break;
                    }

                    case TypeCode.UInt32:
                    {
                        uint uvalue = (uint)field.GetValue(rec);
                        bw.Write(uvalue);
                        break;
                    }

                    case TypeCode.String:
                    {
                        var attribs = field.GetCustomAttributes(typeof(LocalizedAttribute), false);
                        if (attribs.Length == 0)
                        {
                            string str = field.GetValue(rec) as string;
                            bw.Write(AddStringToTable(str));
                        }
                        else
                        {
                            int pos = AddStringToTable(field.GetValue(rec) as string);
                            for (uint j = 0; j < file.LocalePosition; ++j)
                            {
                                bw.Write((int)0);
                            }

                            bw.Write(pos);
                            for (uint j = file.LocalePosition + 1; j < 17; ++j)
                            {
                                bw.Write((int)0);
                            }
                        }
                        break;
                    }

                    case TypeCode.Single:
                    {
                        float fvalue = (float)field.GetValue(rec);
                        bw.Write(fvalue);
                        break;
                    }

                    case TypeCode.Object:
                    {
                        // Info: Checks if type is array already made where numFields is calculated.
                        Type  atype   = field.FieldType.GetElementType();
                        var   attribs = field.GetCustomAttributes(typeof(ArrayAttribute), false);
                        int   len     = (int)(attribs[0] as ArrayAttribute).Length;
                        Array array   = field.GetValue(rec) as Array;
                        for (int q = 0; q < len; ++q)
                        {
                            switch (Type.GetTypeCode(atype))
                            {
                            case TypeCode.Int32:
                                bw.Write((int)array.GetValue(q));
                                break;

                            case TypeCode.UInt32:
                                bw.Write((uint)array.GetValue(q));
                                break;

                            case TypeCode.Single:
                                bw.Write((float)array.GetValue(q));
                                break;
                            }
                        }
                    }
                    break;
                    }
                }
            }

            foreach (var str in mStringTable.Values)
            {
                bytes = Encoding.UTF8.GetBytes(str);
                bw.Write(bytes);
                bw.Write((byte)0);
            }

            bw.BaseStream.Position = 16;
            if (mStringTable.Count > 0)
            {
                bw.Write(mStringTable.Last().Key + Encoding.UTF8.GetByteCount(mStringTable.Last().Value) + 1);
            }
        }