Esempio n. 1
0
        public void UpdateDifficultySelection()
        {
            int ID = Int32.Parse(mySQL.query(String.Format("SELECT `SpellDifficultyID` FROM `{0}` WHERE `ID` = '{1}'", mySQL.Table, main.selectedID)).Rows[0][0].ToString());

            if (ID == 0)
            {
                main.Difficulty.threadSafeIndex = 0;

                return;
            }

            for (int i = 0; i < body.lookup.Count; ++i)
            {
                if (ID == body.lookup[i].ID)
                {
                    main.Difficulty.threadSafeIndex = body.lookup[i].comboBoxIndex;

                    break;
                }
            }
        }
Esempio n. 2
0
        public Task export(MySQL.MySQL mySQL, MainWindow.UpdateProgressFunc updateProgress)
        {
            return(Task.Run(() =>
            {
                var rows = mySQL.query(String.Format("SELECT * FROM `{0}` ORDER BY `ID`", mySQL.Table)).Rows;
                uint numRows = UInt32.Parse(rows.Count.ToString());
                // Hardcode for 3.3.5a 12340
                header = new DBC_Header();
                header.FieldCount = 234;
                header.Magic = 1128416343;
                header.RecordCount = numRows;
                header.RecordSize = 936;
                header.StringBlockSize = 0;

                body.records = new Spell_DBC_RecordMap[numRows];
                for (int i = 0; i < numRows; ++i)
                {
                    body.records[i] = new Spell_DBC_RecordMap();
                    if (i % 250 == 0)
                    {
                        updateProgress((double)i / (double)numRows);
                    }
                    body.records[i].record = new Spell_DBC_Record();
                    body.records[i].spellName = new String[9];
                    body.records[i].spellDesc = new String[9];
                    body.records[i].spellRank = new String[9];
                    body.records[i].spellTool = new String[9];
                    body.records[i].record.SpellName = new UInt32[9];
                    body.records[i].record.SpellDescription = new UInt32[9];
                    body.records[i].record.SpellRank = new UInt32[9];
                    body.records[i].record.SpellToolTip = new UInt32[9];
                    body.records[i].record.SpellNameFlag = new UInt32[8];
                    body.records[i].record.SpellDescriptionFlags = new UInt32[8];
                    body.records[i].record.SpellRankFlags = new UInt32[8];
                    body.records[i].record.SpellToolTipFlags = new UInt32[8];
                    var fields = body.records[i].record.GetType().GetFields();
                    foreach (var f in fields)
                    {
                        switch (Type.GetTypeCode(f.FieldType))
                        {
                        case TypeCode.UInt32:
                        case TypeCode.Int32:
                            {
                                f.SetValueForValueType(ref body.records[i].record, rows[i][f.Name]);
                                break;
                            }

                        case TypeCode.Single:
                            {
                                f.SetValueForValueType(ref body.records[i].record, Single.Parse(rows[i][f.Name].ToString()));
                                break;
                            }

                        case TypeCode.Object:
                            {
                                var attr = f.GetCustomAttribute <HandleField>();
                                if (attr != null)
                                {
                                    if (attr.Method == 1)
                                    {
                                        switch (attr.Type)
                                        {
                                        case 1:
                                            {
                                                for (int j = 0; j < attr.Count; ++j)
                                                {
                                                    body.records[i].spellName[j] = rows[i]["SpellName" + j].ToString();
                                                }
                                                break;
                                            }

                                        case 2:
                                            {
                                                for (int j = 0; j < attr.Count; ++j)
                                                {
                                                    body.records[i].spellRank[j] = rows[i]["SpellRank" + j].ToString();
                                                }
                                                break;
                                            }

                                        case 3:
                                            {
                                                for (int j = 0; j < attr.Count; ++j)
                                                {
                                                    body.records[i].spellDesc[j] = rows[i]["SpellDescription" + j].ToString();
                                                }
                                                break;
                                            }

                                        case 4:
                                            {
                                                for (int j = 0; j < attr.Count; ++j)
                                                {
                                                    body.records[i].spellTool[j] = rows[i]["SpellToolTip" + j].ToString();
                                                }
                                                break;
                                            }

                                        default:
                                            throw new Exception("ERROR: Unhandled type: " + f.FieldType + " on field: " + f.Name + " TYPE: " + attr.Type);
                                        }
                                        break;
                                    }
                                    else if (attr.Method == 2)
                                    {
                                        switch (attr.Type)
                                        {
                                        case 1:
                                            {
                                                for (int j = 0; j < attr.Count; ++j)
                                                {
                                                    body.records[i].record.SpellNameFlag[j] = UInt32.Parse(rows[i]["SpellNameFlag" + j].ToString());
                                                }
                                                break;
                                            }

                                        case 2:
                                            {
                                                for (int j = 0; j < attr.Count; ++j)
                                                {
                                                    body.records[i].record.SpellRankFlags[j] = UInt32.Parse(rows[i]["SpellRankFlags" + j].ToString());
                                                }
                                                break;
                                            }

                                        case 3:
                                            {
                                                for (int j = 0; j < attr.Count; ++j)
                                                {
                                                    body.records[i].record.SpellDescriptionFlags[j] = UInt32.Parse(rows[i]["SpellDescriptionFlags" + j].ToString());
                                                }
                                                break;
                                            }

                                        case 4:
                                            {
                                                for (int j = 0; j < attr.Count; ++j)
                                                {
                                                    body.records[i].record.SpellToolTipFlags[j] = UInt32.Parse(rows[i]["SpellToolTipFlags" + j].ToString());
                                                }
                                                break;
                                            }

                                        default:
                                            throw new Exception("ERROR: Unhandled type: " + f.FieldType + " on field: " + f.Name + " TYPE: " + attr.Type);
                                        }
                                        break;
                                    }
                                }
                                goto default;
                            }

                        default:
                            throw new Exception("Unhandled type: " + Type.GetTypeCode(f.FieldType).ToString() + ", field: " + f.Name);
                        }
                    }
                }
                SaveDBCFile();
            }));
        }