static void Main(string[] args) { var sparse = new ADBReader<Item_sparse>("Item-sparse.adb"); var itemDb = new ADBReader<Item>("Item.adb"); using (var writer = new StreamWriter("item_parsed.sql", false)) { writer.Write("REPLACE INTO `item_template` ("); writer.Write("`entry`,`Class`,`SubClass`,`Unk0`,`Name`,`DisplayId`,`Quality`,`Flags`,`FlagsExtra`,`Unk430_1`,`Unk430_2`,`Unk430_3`,`BuyPrice`,`SellPrice`,`InventoryType`,"); writer.Write("`AllowableClass`,`AllowableRace`,`ItemLevel`,`RequiredLevel`,`RequiredSkill`,`RequiredSkillRank`,`RequiredSpell`,`RequiredHonorRank`,"); writer.Write("`RequiredCityRank`,`RequiredReputationFaction`,`RequiredReputationRank`,`MaxCount`,`Stackable`,`ContainerSlots`,"); writer.Write("`stat_type1`,`stat_value1`,`stat_unk1_1`,`stat_unk2_1`,`stat_type2`,`stat_value2`,`stat_unk1_2`,`stat_unk2_2`,"); writer.Write("`stat_type3`,`stat_value3`,`stat_unk1_3`,`stat_unk2_3`,`stat_type4`,`stat_value4`,`stat_unk1_4`,`stat_unk2_4`,"); writer.Write("`stat_type5`,`stat_value5`,`stat_unk1_5`,`stat_unk2_5`,`stat_type6`,`stat_value6`,`stat_unk1_6`,`stat_unk2_6`,"); writer.Write("`stat_type7`,`stat_value7`,`stat_unk1_7`,`stat_unk2_7`,`stat_type8`,`stat_value8`,`stat_unk1_8`,`stat_unk2_8`,"); writer.Write("`stat_type9`,`stat_value9`,`stat_unk1_9`,`stat_unk2_9`,`stat_type10`,`stat_value10`,`stat_unk1_10`,`stat_unk2_10`,"); writer.Write("`ScalingStatDistribution`,`DamageType`,`Delay`,`RangedModRange`,"); writer.Write("`spellid_1`,`spelltrigger_1`,`spellcharges_1`,`spellcooldown_1`,`spellcategory_1`,`spellcategorycooldown_1`,"); writer.Write("`spellid_2`,`spelltrigger_2`,`spellcharges_2`,`spellcooldown_2`,`spellcategory_2`,`spellcategorycooldown_2`,"); writer.Write("`spellid_3`,`spelltrigger_3`,`spellcharges_3`,`spellcooldown_3`,`spellcategory_3`,`spellcategorycooldown_3`,"); writer.Write("`spellid_4`,`spelltrigger_4`,`spellcharges_4`,`spellcooldown_4`,`spellcategory_4`,`spellcategorycooldown_4`,"); writer.Write("`spellid_5`,`spelltrigger_5`,`spellcharges_5`,`spellcooldown_5`,`spellcategory_5`,`spellcategorycooldown_5`,"); writer.Write("`Bonding`,`Description`,`PageText`,`LanguageID`,`PageMaterial`,`StartQuest`,`LockID`,`Material`,"); writer.Write("`Sheath`,`RandomProperty`,`RandomSuffix`,`ItemSet`,`Area`,`Map`,`BagFamily`,`TotemCategory`,"); writer.Write("`SocketColor_1`,`SocketContent_1`,`SocketColor_2`,`SocketContent_2`,`SocketColor_3`,`SocketContent_3`,`SocketBonus`,"); writer.Write("`GemProperties`,`ArmorDamageModifier`,`Duration`,`ItemLimitCategory`,`HolidayId`,`StatScalingFactor`,`Field130`,`Field131`,`WDBVerified`"); writer.WriteLine(") VALUES"); bool first = true; foreach (var item in sparse.Entries) { if (!itemDb.Entries.ContainsKey(item.Key)) continue; if (!first) writer.WriteLine(','); else first = false; writer.Write("{0}", new ItemSqlBuilder(itemDb.Entries[item.Key], item.Value, itemDb.Build).GetInsertQuery()); } writer.WriteLine(';'); } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { var file = (string)e.Argument; try { var ext = Path.GetExtension(file).ToUpperInvariant(); if (ext == ".DBC") m_reader = new DBCReader(file); else if (ext == ".DB2") m_reader = new DB2Reader(file); else if (ext == ".ADB") m_reader = new ADBReader(file); else if (ext == ".WDB") m_reader = new WDBReader(file); else throw new InvalidDataException(String.Format("Unknown file type {0}", ext)); } catch (Exception ex) { ShowErrorMessageBox(ex.Message); e.Cancel = true; 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; // hack for *.adb files (because they don't have FieldsCount) var notADB = !(m_reader is ADBReader); // hack for *.wdb files (because they don't have FieldsCount) var notWDB = !(m_reader is WDBReader); if (GetFieldsCount(m_fields) != m_reader.FieldsCount && notADB && notWDB) { var msg = String.Format(CultureInfo.InvariantCulture, "{0} has invalid definition!\nFields count mismatch: got {1}, expected {2}", Path.GetFileName(file), m_fields.Count, m_reader.FieldsCount); ShowErrorMessageBox(msg); e.Cancel = true; return; } m_dataTable = new DataTable(Path.GetFileName(file)); m_dataTable.Locale = CultureInfo.InvariantCulture; CreateColumns(); // Add columns CreateIndexes(); // Add indexes for (var i = 0; i < m_reader.RecordsCount; ++i) // Add rows { var dataRow = m_dataTable.NewRow(); #region Test //var bytes = m_reader.GetRowAsByteArray(i); //unsafe //{ // fixed (void* b = bytes) // { // IntPtr ptr = new IntPtr(b); // int offset = 0; // for (var j = 0; j < m_fields.Count; ++j) // Add cells // { // switch (types[j]) // { // case "long": // dataRow[j] = *(long*)(ptr + offset); // offset += 8; // break; // case "ulong": // dataRow[j] = *(ulong*)(ptr + offset); // offset += 8; // break; // case "int": // dataRow[j] = *(int*)(ptr + offset); // offset += 4; // break; // case "uint": // dataRow[j] = *(uint*)(ptr + offset); // offset += 4; // break; // case "short": // dataRow[j] = *(short*)(ptr + offset); // offset += 2; // break; // case "ushort": // dataRow[j] = *(ushort*)(ptr + offset); // offset += 2; // break; // case "sbyte": // dataRow[j] = *(sbyte*)(ptr + offset); // offset += 1; // break; // case "byte": // dataRow[j] = *(byte*)(ptr + offset); // offset += 1; // break; // case "float": // dataRow[j] = *(float*)(ptr + offset); // offset += 4; // break; // case "double": // dataRow[j] = *(double*)(ptr + offset); // offset += 8; // break; // case "string": // dataRow[j] = m_reader.StringTable[*(int*)(ptr + offset)]; // offset += 4; // break; // default: // throw new Exception(String.Format("Unknown field type {0}!", m_fields[j].Attributes["type"].Value)); // } // } // } //} #endregion var br = m_reader[i]; for (var j = 0; j < m_fields.Count; ++j) // Add cells { 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 "string": dataRow[j] = m_reader is WDBReader ? br.ReadStringNull() : m_reader.StringTable[br.ReadInt32()]; 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_reader.RecordsCount * 100.0f); (sender as BackgroundWorker).ReportProgress(percent); } if (dataGridView1.InvokeRequired) { SetDataViewDelegate d = new SetDataViewDelegate(SetDataSource); Invoke(d, new object[] { m_dataTable.DefaultView }); } else { SetDataSource(m_dataTable.DefaultView); } e.Result = file; }