public Task LoadImages(double margin) { return (new TaskFactory()).StartNew(() => { if (!File.Exists("DBC/SpellIcon.dbc")) { main.HandleErrorMessage("SpellIcon.dbc was not found!"); return; } FileStream fileStream; try { fileStream = new FileStream("DBC/SpellIcon.dbc", FileMode.Open); } catch (IOException) { return; } int count = Marshal.SizeOf(typeof(DBC_Header)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); header = (DBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Header)); handle.Free(); body.records = new Icon_DBC_Record[header.RecordCount]; for (UInt32 i = 0; i < header.RecordCount; ++i) { count = Marshal.SizeOf(typeof(Icon_DBC_Record)); readBuffer = new byte[count]; reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); body.records[i] = (Icon_DBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Icon_DBC_Record)); handle.Free(); } body.StringBlock = Encoding.UTF8.GetString(reader.ReadBytes(header.StringBlockSize)); reader.Close(); fileStream.Close(); UpdateMainWindowIcons(margin); }); }
// End DBCs public CreatureDisplayInfo() { if (!File.Exists("Import\\CreatureDisplayInfo.dbc")) { throw new Exception("Import\\CreatureDisplayInfo.dbc does not exist."); } FileStream fileStream = new FileStream("Import\\CreatureDisplayInfo.dbc", FileMode.Open); int count = Marshal.SizeOf(typeof(DBC_Header)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); header = (DBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Header)); handle.Free(); count = Marshal.SizeOf(typeof(DBC_Record)); if (header.RecordSize != count) { throw new Exception("This DBC version is not supported! It is not 3.3.5a."); } body.records = new DBC_Record[header.RecordCount]; for (UInt32 i = 0; i < header.RecordCount; ++i) { count = Marshal.SizeOf(typeof(DBC_Record)); readBuffer = new byte[count]; reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); body.records[i] = (DBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Record)); handle.Free(); } body.StringBlock = Encoding.UTF8.GetString(reader.ReadBytes(header.StringBlockSize)); reader.Close(); fileStream.Close(); }
// End DBCs public SpellFocusObject(MainWindow window, DBAdapter adapter) { this.main = window; this.adapter = adapter; for (UInt32 i = 0; i < header.RecordCount; ++i) { body.records[i].ID = new UInt32(); body.records[i].Name = new UInt32[16]; body.records[i].Flags = new UInt32(); } if (!File.Exists("DBC/SpellFocusObject.dbc")) { main.HandleErrorMessage("SpellFocusObject.dbc was not found!"); return; } FileStream fileStream = new FileStream("DBC/SpellFocusObject.dbc", FileMode.Open); int count = Marshal.SizeOf(typeof(DBC_Header)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); header = (DBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Header)); handle.Free(); body.records = new SpellFocusObject_DBC_Record[header.RecordCount]; for (UInt32 i = 0; i < header.RecordCount; ++i) { count = Marshal.SizeOf(typeof(SpellFocusObject_DBC_Record)); readBuffer = new byte[count]; reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); body.records[i] = (SpellFocusObject_DBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SpellFocusObject_DBC_Record)); handle.Free(); } body.StringBlock = reader.ReadBytes(header.StringBlockSize); reader.Close(); fileStream.Close(); body.lookup = new List <SpellFocusObjectLookup>(); int boxIndex = 1; main.RequiresSpellFocus.Items.Add("None"); SpellFocusObjectLookup t; t.ID = 0; t.offset = 0; t.stringHash = "None".GetHashCode(); t.comboBoxIndex = 0; body.lookup.Add(t); for (UInt32 i = 0; i < header.RecordCount; ++i) { int offset = (int)body.records[i].Name[window.GetLanguage()]; if (offset == 0) { continue; } int returnValue = offset; System.Collections.ArrayList al = new System.Collections.ArrayList(); while (body.StringBlock[offset] != '\0') { al.Add(body.StringBlock[offset++]); } byte[] toAdd = new byte[al.Count]; int n = 0; foreach (byte o in al) { toAdd[n++] = o; } SpellFocusObjectLookup temp; temp.ID = (int)body.records[i].ID; temp.offset = returnValue; temp.stringHash = Encoding.UTF8.GetString(toAdd).GetHashCode(); temp.comboBoxIndex = boxIndex; main.RequiresSpellFocus.Items.Add(Encoding.UTF8.GetString(toAdd)); body.lookup.Add(temp); boxIndex++; } }
// End DBCs public SpellDifficulty(MainWindow window, MySQL.MySQL mySQLConn) { main = window; mySQL = mySQLConn; for (UInt32 i = 0; i < header.RecordCount; ++i) { body.records[i].ID = new UInt32(); body.records[i].Difficulties = new UInt32[4]; } if (!File.Exists("DBC/SpellDifficulty.dbc")) { main.HandleErrorMessage("SpellDifficulty.dbc was not found!"); return; } FileStream fileStream = new FileStream("DBC/SpellDifficulty.dbc", FileMode.Open); int count = Marshal.SizeOf(typeof(DBC_Header)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); header = (DBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Header)); handle.Free(); body.records = new SpellDifficulty_DBC_Record[header.RecordCount]; for (UInt32 i = 0; i < header.RecordCount; ++i) { count = Marshal.SizeOf(typeof(SpellDifficulty_DBC_Record)); readBuffer = new byte[count]; reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); body.records[i] = (SpellDifficulty_DBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SpellDifficulty_DBC_Record)); handle.Free(); } reader.Close(); fileStream.Close(); body.lookup = new List <SpellDifficultyLookup>(); int boxIndex = 1; main.Difficulty.Items.Add(0); SpellDifficultyLookup t; t.ID = 0; t.comboBoxIndex = 0; body.lookup.Add(t); for (UInt32 i = 0; i < header.RecordCount; ++i) { int id = (int)body.records[i].ID; SpellDifficultyLookup temp; temp.ID = id; temp.comboBoxIndex = boxIndex; main.Difficulty.Items.Add(id); body.lookup.Add(temp); boxIndex++; } }
// End DBCs public CreatureModelData() { if (!File.Exists("Import\\CreatureModelData.dbc")) { throw new Exception("Import\\CreatureModelData.dbc does not exist."); } FileStream fileStream = new FileStream("Import\\CreatureModelData.dbc", FileMode.Open); int count = Marshal.SizeOf(typeof(DBC_Header)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); header = (DBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Header)); handle.Free(); count = Marshal.SizeOf(typeof(DBC_Record)); if (header.RecordSize != count) { throw new Exception("This DBC version is not supported! It is not 3.3.5a."); } body.records = new DBC_Record[header.RecordCount]; for (UInt32 i = 0; i < header.RecordCount; ++i) { count = Marshal.SizeOf(typeof(DBC_Record)); readBuffer = new byte[count]; reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); body.records[i] = (DBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Record)); handle.Free(); } body.StringBlock = Encoding.UTF8.GetString(reader.ReadBytes(header.StringBlockSize)); reader.Close(); fileStream.Close(); body.pathStrings = new String[header.RecordCount]; for (UInt32 i = 0; i < header.RecordCount; ++i) { int offset = (int)body.records[i].ModelPath; if (offset == 0) { continue; } int returnValue = offset; string toAdd = ""; while (body.StringBlock[offset] != '\0') { toAdd += body.StringBlock[offset++]; } body.pathStrings[i] = toAdd; } }
// End DBCs public ItemClass(MainWindow window, MySQL.MySQL mySQLConn) { main = window; mySQL = mySQLConn; for (UInt32 i = 0; i < header.RecordCount; ++i) { body.records[i].ID = new UInt32(); body.records[i].SecondaryID = new UInt32(); body.records[i].IsWeapon = new UInt32(); body.records[i].Name = new UInt32[16]; body.records[i].Flags = new UInt32(); } if (!File.Exists("DBC/ItemClass.dbc")) { main.HandleErrorMessage("ItemClass.dbc was not found!"); return; } FileStream fileStream = new FileStream("DBC/ItemClass.dbc", FileMode.Open); int count = Marshal.SizeOf(typeof(DBC_Header)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); header = (DBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Header)); handle.Free(); body.records = new ItemClass_DBC_Record[header.RecordCount]; for (UInt32 i = 0; i < header.RecordCount; ++i) { count = Marshal.SizeOf(typeof(ItemClass_DBC_Record)); readBuffer = new byte[count]; reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); body.records[i] = (ItemClass_DBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(ItemClass_DBC_Record)); handle.Free(); } body.StringBlock = Encoding.UTF8.GetString(reader.ReadBytes(header.StringBlockSize)); reader.Close(); fileStream.Close(); body.lookup = new List <ItemClassLookup>(); int boxIndex = 1; main.EquippedItemClass.Items.Add("None"); ItemClassLookup t; t.ID = -1; t.comboBoxIndex = -1; body.lookup.Add(t); for (UInt32 i = 0; i < header.RecordCount; ++i) { int offset = (int)body.records[i].Name[0]; if (offset == 0) { continue; } int returnValue = offset; string toAdd = ""; while (body.StringBlock[offset] != 0) { toAdd += body.StringBlock[offset++]; } ItemClassLookup temp; temp.ID = (int)body.records[i].ID; temp.comboBoxIndex = boxIndex; main.EquippedItemClass.Items.Add(toAdd); body.lookup.Add(temp); boxIndex++; } }
// End DBCs public SpellMechanic(MainWindow window, MySQL.MySQL mySQLConn) { main = window; mySQL = mySQLConn; for (UInt32 i = 0; i < header.RecordCount; ++i) { body.records[i].ID = new UInt32(); body.records[i].Name = new UInt32[16]; body.records[i].NameFlags = new UInt32(); } if (!File.Exists("DBC/SpellMechanic.dbc")) { main.HandleErrorMessage("SpellMechanic.dbc was not found!"); return; } FileStream fileStream = new FileStream("DBC/SpellMechanic.dbc", FileMode.Open); int count = Marshal.SizeOf(typeof(DBC_Header)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); header = (DBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Header)); handle.Free(); body.records = new Mechanic_DBC_Record[header.RecordCount]; for (UInt32 i = 0; i < header.RecordCount; ++i) { count = Marshal.SizeOf(typeof(Mechanic_DBC_Record)); readBuffer = new byte[count]; reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); body.records[i] = (Mechanic_DBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Mechanic_DBC_Record)); handle.Free(); } body.StringBlock = Encoding.UTF8.GetString(reader.ReadBytes(header.StringBlockSize)); reader.Close(); fileStream.Close(); body.lookup = new List <MechanicLookup>(); int boxIndex = 1; main.MechanicType.Items.Add("None"); MechanicLookup t; t.ID = 0; t.offset = 0; t.stringHash = "None".GetHashCode(); t.comboBoxIndex = 0; body.lookup.Add(t); for (UInt32 i = 0; i < header.RecordCount; ++i) { int offset = (int)body.records[i].Name[0]; if (offset == 0) { continue; } int returnValue = offset; string toAdd = ""; while (body.StringBlock[offset] != '\0') { toAdd += body.StringBlock[offset++]; } MechanicLookup temp; temp.ID = (int)body.records[i].ID; temp.offset = returnValue; temp.stringHash = toAdd.GetHashCode(); temp.comboBoxIndex = boxIndex; main.MechanicType.Items.Add(toAdd.Remove(1).ToUpper() + toAdd.Substring(1)); body.lookup.Add(temp); boxIndex++; } }
// End DBCs public AreaGroup(MainWindow window, DBAdapter adapter) { this.main = window; this.adapter = adapter; for (UInt32 i = 0; i < header.RecordCount; ++i) { body.records[i].ID = new UInt32(); body.records[i].AreaID = new UInt32[6]; body.records[i].NextGroup = new UInt32(); } if (!File.Exists("DBC/AreaGroup.dbc")) { main.HandleErrorMessage("AreaGroup.dbc was not found!"); return; } FileStream fileStream = new FileStream("DBC/AreaGroup.dbc", FileMode.Open); int count = Marshal.SizeOf(typeof(DBC_Header)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); header = (DBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Header)); handle.Free(); body.records = new AreaGroup_DBC_Record[header.RecordCount]; for (UInt32 i = 0; i < header.RecordCount; ++i) { count = Marshal.SizeOf(typeof(AreaGroup_DBC_Record)); readBuffer = new byte[count]; reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); body.records[i] = (AreaGroup_DBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(AreaGroup_DBC_Record)); handle.Free(); } reader.Close(); fileStream.Close(); body.lookup = new List <AreaGroupLookup>(); int boxIndex = 1; main.AreaGroup.Items.Add(0); AreaGroupLookup t; t.ID = 0; t.comboBoxIndex = 0; body.lookup.Add(t); for (UInt32 i = 0; i < header.RecordCount; ++i) { int id = (int)body.records[i].ID; AreaGroupLookup temp; AreaGroup_DBC_Record agTemp = body.records[i]; System.Collections.ArrayList al = new System.Collections.ArrayList(); do { foreach (UInt32 val in agTemp.AreaID) { if (val != 0) { al.Add(val); } } agTemp = FindAreaGroup(agTemp.NextGroup); } while (agTemp.NextGroup != 0); temp.ID = id; temp.comboBoxIndex = boxIndex; Label areaGroupLab = new Label(); areaGroupLab.Content = id.ToString() + "\t\t"; String areaList_str = ""; foreach (UInt32 val in al) { areaList_str += "AreaId:"; areaList_str += val; areaList_str += "\t\t"; areaList_str += window.GetAreaTableName(val); areaList_str += "\n"; } areaGroupLab.ToolTip = areaList_str; main.AreaGroup.Items.Add(areaGroupLab); body.lookup.Add(temp); boxIndex++; } }
public bool LoadDBCFile(MainWindow window) { main = window; try { FileStream fileStream = new FileStream("DBC/Spell.dbc", FileMode.Open); fileSize = fileStream.Length; int count = Marshal.SizeOf(typeof(DBC_Header)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); header = (DBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Header)); handle.Free(); body.records = new Spell_DBC_RecordMap[header.RecordCount]; count = Marshal.SizeOf(typeof(Spell_DBC_Record)); if (header.RecordSize != count) { throw new Exception("This Spell DBC version is not supported! It is not 3.3.5a."); } for (UInt32 i = 0; i < header.RecordCount; ++i) { readBuffer = new byte[count]; readBuffer = reader.ReadBytes(count); handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); body.records[i].record = (Spell_DBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Spell_DBC_Record)); handle.Free(); } string StringBlock; Dictionary <UInt32, VirtualStrTableEntry> strings = new Dictionary <UInt32, VirtualStrTableEntry>(); StringBlock = Encoding.UTF8.GetString(reader.ReadBytes(header.StringBlockSize)); string temp = ""; UInt32 lastString = 0; UInt32 counter = 0; Int32 length = new System.Globalization.StringInfo(StringBlock).LengthInTextElements; while (counter < length) { var t = StringBlock[(int)counter]; if (t == '\0') { VirtualStrTableEntry n = new VirtualStrTableEntry(); n.Value = temp; n.NewValue = 0; strings.Add(lastString, n); lastString += (UInt32)Encoding.UTF8.GetByteCount(temp) + 1; temp = ""; } else { temp += t; } ++counter; } StringBlock = null; for (int i = 0; i < body.records.Length; ++i) { body.records[i].spellName = new string[9]; body.records[i].spellRank = new string[9]; body.records[i].spellDesc = new string[9]; body.records[i].spellTool = new string[9]; for (int j = 0; j < 9; ++j) { body.records[i].spellName[j] = strings[body.records[i].record.SpellName[j]].Value; body.records[i].spellRank[j] = strings[body.records[i].record.SpellRank[j]].Value; body.records[i].spellDesc[j] = strings[body.records[i].record.SpellDescription[j]].Value; body.records[i].spellTool[j] = strings[body.records[i].record.SpellToolTip[j]].Value; } } reader.Close(); fileStream.Close(); foreach (Spell_DBC_RecordMap map in body.records) { tryGenerate(map, 0, window); } } catch (Exception ex) { main.HandleErrorMessage(ex.Message); return(false); } return(true); }
public Task export(DBAdapter adapter, MainWindow.UpdateProgressFunc updateProgress) { return(Task.Run(() => { var rows = adapter.query(string.Format("SELECT * FROM `{0}` ORDER BY `ID`", adapter.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: { f.SetValueForValueType(ref body.records[i].record, UInt32.Parse(rows[i][f.Name].ToString())); break; } case TypeCode.Int32: { f.SetValueForValueType(ref body.records[i].record, Int32.Parse(rows[i][f.Name].ToString())); 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(); })); }
// End DBCs public SpellCastTimes(MainWindow window, DBAdapter adapter) { this.main = window; this.adapter = adapter; for (UInt32 i = 0; i < header.RecordCount; ++i) { body.records[i].ID = new UInt32(); body.records[i].CastingTime = new Int32(); body.records[i].CastingTimePerLevel = new float(); body.records[i].MinimumCastingTime = new Int32(); } if (!File.Exists("DBC/SpellCastTimes.dbc")) { main.HandleErrorMessage("SpellCastTimes.dbc was not found!"); return; } FileStream fileStream = new FileStream("DBC/SpellCastTimes.dbc", FileMode.Open); int count = Marshal.SizeOf(typeof(DBC_Header)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); header = (DBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Header)); handle.Free(); body.records = new SpellCastTimes_DBC_Record[header.RecordCount]; for (UInt32 i = 0; i < header.RecordCount; ++i) { count = Marshal.SizeOf(typeof(SpellCastTimes_DBC_Record)); readBuffer = new byte[count]; reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); body.records[i] = (SpellCastTimes_DBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SpellCastTimes_DBC_Record)); handle.Free(); } reader.Close(); fileStream.Close(); body.lookup = new List <SpellCastTimeLookup>(); int boxIndex = 0; SpellCastTimeLookup t; t.ID = 0; t.comboBoxIndex = 0; body.lookup.Add(t); for (UInt32 i = 0; i < header.RecordCount; ++i) { //int castTime = (int)body.records[i].CastingTime; Label castTime = new Label(); castTime.Content = body.records[i].CastingTime.ToString() + "\t"; castTime.ToolTip = "CastTime\t\t" + body.records[i].CastingTime + "\n" + "PerLevel\t\t" + body.records[i].CastingTimePerLevel.ToString() + "\n" + "MinimumCastingTime\t" + body.records[i].MinimumCastingTime + "\n"; SpellCastTimeLookup temp; temp.ID = (int)body.records[i].ID; temp.comboBoxIndex = boxIndex; main.CastTime.Items.Add(castTime); body.lookup.Add(temp); boxIndex++; } }
// End DBCs public SpellRange(MainWindow window, DBAdapter adapter) { this.main = window; this.adapter = adapter; for (UInt32 i = 0; i < header.RecordCount; ++i) { body.records[i].ID = new UInt32(); body.records[i].MinimumRangeHostile = new float(); body.records[i].MinimumRangeFriend = new float(); body.records[i].MaximumRangeHostile = new float(); body.records[i].MaximumRangeFriend = new float(); body.records[i].Type = new Int32(); body.records[i].Name = new UInt32[16]; body.records[i].NameFlags = new UInt32(); body.records[i].ShortName = new UInt32[16]; body.records[i].ShortNameFlags = new UInt32(); } if (!File.Exists("DBC/SpellRange.dbc")) { main.HandleErrorMessage("SpellRange.dbc was not found!"); return; } FileStream fileStream = new FileStream("DBC/SpellRange.dbc", FileMode.Open); int count = Marshal.SizeOf(typeof(DBC_Header)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); header = (DBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Header)); handle.Free(); body.records = new SpellRange_DBC_Record[header.RecordCount]; for (UInt32 i = 0; i < header.RecordCount; ++i) { count = Marshal.SizeOf(typeof(SpellRange_DBC_Record)); readBuffer = new byte[count]; reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); body.records[i] = (SpellRange_DBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SpellRange_DBC_Record)); handle.Free(); } body.StringBlock = reader.ReadBytes(header.StringBlockSize); reader.Close(); fileStream.Close(); body.lookup = new List <SpellRangeLookup>(); int boxIndex = 0; for (UInt32 i = 0; i < header.RecordCount; ++i) { int offset = (int)body.records[i].Name[window.GetLanguage()]; int MinimumRangeHostile = (int)body.records[i].MinimumRangeHostile; int MaximumRangeHostile = (int)body.records[i].MaximumRangeHostile; int MinimumRangeFriend = (int)body.records[i].MinimumRangeFriend; int MaximumRangeFriend = (int)body.records[i].MaximumRangeFriend; if (offset == 0) { continue; } int returnValue = offset; System.Collections.ArrayList al = new System.Collections.ArrayList(); while (body.StringBlock[offset] != 0) { al.Add(body.StringBlock[offset++]); } byte[] toAdd = new byte[al.Count]; int n = 0; foreach (byte o in al) { toAdd[n++] = o; } SpellRangeLookup temp; temp.ID = (int)body.records[i].ID; temp.comboBoxIndex = boxIndex; main.Range.Items.Add(Encoding.UTF8.GetString(toAdd) + "\t\t - " + "Hostile: " + MinimumRangeHostile + " - " + MaximumRangeHostile + "\t Friend: " + MinimumRangeFriend + " - " + MaximumRangeFriend); body.lookup.Add(temp); boxIndex++; } }
// End DBCs public SpellRadius(MainWindow window, DBAdapter adapter) { this.main = window; this.adapter = adapter; for (UInt32 i = 0; i < header.RecordCount; ++i) { body.records[i].ID = new UInt32(); body.records[i].Radius = new float(); body.records[i].RadiusPerLevel = new float(); body.records[i].MaximumRadius = new float(); } if (!File.Exists("DBC/SpellRadius.dbc")) { main.HandleErrorMessage("SpellRadius.dbc was not found!"); return; } FileStream fileStream = new FileStream("DBC/SpellRadius.dbc", FileMode.Open); int count = Marshal.SizeOf(typeof(DBC_Header)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); header = (DBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Header)); handle.Free(); body.records = new SpellRadiusRecord[header.RecordCount]; for (UInt32 i = 0; i < header.RecordCount; ++i) { count = Marshal.SizeOf(typeof(SpellRadiusRecord)); readBuffer = new byte[count]; reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); body.records[i] = (SpellRadiusRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SpellRadiusRecord)); handle.Free(); } reader.Close(); fileStream.Close(); body.lookup = new List <RadiusLookup>(); int boxIndex = 1; main.RadiusIndex1.Items.Add("0 - 0"); main.RadiusIndex2.Items.Add("0 - 0"); main.RadiusIndex3.Items.Add("0 - 0"); RadiusLookup t; t.ID = 0; t.comboBoxIndex = 0; body.lookup.Add(t); for (UInt32 i = 0; i < header.RecordCount; ++i) { int radius = (int)body.records[i].Radius; int maximumRadius = (int)body.records[i].MaximumRadius; RadiusLookup temp; temp.ID = (int)body.records[i].ID; temp.comboBoxIndex = boxIndex; main.RadiusIndex1.Items.Add(radius + " - " + maximumRadius); main.RadiusIndex2.Items.Add(radius + " - " + maximumRadius); main.RadiusIndex3.Items.Add(radius + " - " + maximumRadius); body.lookup.Add(temp); boxIndex++; } }
// End DBCs public AreaTable(MainWindow window, DBAdapter adapter) { this.main = window; this.adapter = adapter; if (!File.Exists("DBC/AreaTable.dbc")) { main.HandleErrorMessage("AreaTable.dbc was not found!"); return; } FileStream fileStream = new FileStream("DBC/AreaTable.dbc", FileMode.Open); int count = Marshal.SizeOf(typeof(DBC_Header)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); header = (DBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Header)); handle.Free(); body.records = new AreaTable_DBC_Record[header.RecordCount]; for (UInt32 i = 0; i < header.RecordCount; ++i) { body.records[i].ID = new UInt32(); body.records[i].Map = new UInt32(); body.records[i].zone = new UInt32(); body.records[i].exploreFlag = new UInt32(); body.records[i].Flags = new UInt32(); body.records[i].SoundPreferences = new UInt32(); body.records[i].SoundPreferencesUnderwater = new UInt32(); body.records[i].SoundAmbience = new UInt32(); body.records[i].ZoneMusic = new UInt32(); body.records[i].zoneIntroMusic = new UInt32(); body.records[i].area_level = new UInt32(); body.records[i].LiquidType = new UInt32[4]; body.records[i].MinElevation = new float(); body.records[i].AmbientMultiplier = new float(); body.records[i].Light = new UInt32(); body.records[i].Name = new UInt32[16]; body.records[i].NameFlag = new UInt32(); body.records[i].FactionGroup = new UInt32(); } for (UInt32 i = 0; i < header.RecordCount; ++i) { count = Marshal.SizeOf(typeof(AreaTable_DBC_Record)); readBuffer = new byte[count]; reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); body.records[i] = (AreaTable_DBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(AreaTable_DBC_Record)); handle.Free(); } body.StringBlock = reader.ReadBytes(header.StringBlockSize); reader.Close(); fileStream.Close(); body.lookup = new Dictionary <uint, AreaTableLookup>(); for (UInt32 i = 0; i < header.RecordCount; ++i) { int offset = (int)body.records[i].Name[window.GetLanguage()]; if (offset == 0) { continue; } int returnValue = offset; System.Collections.ArrayList al = new System.Collections.ArrayList(); while (body.StringBlock[offset] != 0) { al.Add(body.StringBlock[offset++]); } byte[] toAdd = new byte[al.Count]; int n = 0; foreach (byte o in al) { toAdd[n++] = o; } AreaTableLookup temp; temp.ID = (int)body.records[i].ID; temp.AreaName = Encoding.UTF8.GetString(toAdd);; body.lookup.Add(body.records[i].ID, temp); } }
// End DBCs public ItemSubClass(MainWindow window, DBAdapter adapter) { this.main = window; this.adapter = adapter; if (!File.Exists("DBC/ItemSubClass.dbc")) { main.HandleErrorMessage("ItemSubClass.dbc was not found!"); return; } FileStream fileStream = new FileStream("DBC/ItemSubClass.dbc", FileMode.Open); int count = Marshal.SizeOf(typeof(DBC_Header)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); header = (DBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBC_Header)); handle.Free(); body.records = new ItemSubClass_DBC_Record[header.RecordCount]; for (UInt32 i = 0; i < header.RecordCount; ++i) { body.records[i].Class = new UInt32(); body.records[i].subClass = new UInt32(); body.records[i].prerequisiteProficiency = new UInt32(); body.records[i].postrequisiteProficiency = new UInt32(); body.records[i].flags = new UInt32(); body.records[i].displayFlags = new UInt32(); body.records[i].weaponParrySeq = new UInt32(); body.records[i].weaponReadySeq = new UInt32(); body.records[i].weaponAttackSeq = new UInt32(); body.records[i].WeaponSwingSize = new UInt32(); body.records[i].displayName = new UInt32[16]; body.records[i].displayNameFlag = new UInt32(); body.records[i].verboseName = new UInt32[16]; body.records[i].verboseNameFlag = new UInt32(); } for (UInt32 i = 0; i < header.RecordCount; ++i) { count = Marshal.SizeOf(typeof(ItemSubClass_DBC_Record)); readBuffer = new byte[count]; reader = new BinaryReader(fileStream); readBuffer = reader.ReadBytes(count); handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); body.records[i] = (ItemSubClass_DBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(ItemSubClass_DBC_Record)); handle.Free(); } body.StringBlock = reader.ReadBytes(header.StringBlockSize); reader.Close(); fileStream.Close(); body.lookup = new ItemSubClassLookup[29, 32]; for (UInt32 i = 0; i < header.RecordCount; ++i) { int offset = (int)body.records[i].displayName[window.GetLanguage()]; if (offset == 0) { continue; } if ((int)body.records[i].verboseName[window.GetLanguage()] != 0) { offset = (int)body.records[i].verboseName[window.GetLanguage()]; } int returnValue = offset; System.Collections.ArrayList al = new System.Collections.ArrayList(); while (body.StringBlock[offset] != 0) { al.Add(body.StringBlock[offset++]); } byte[] toAdd = new byte[al.Count]; int n = 0; foreach (byte o in al) { toAdd[n++] = o; } ItemSubClassLookup temp; temp.ID = body.records[i].subClass; temp.Name = Encoding.UTF8.GetString(toAdd); body.lookup[(int)body.records[i].Class, (int)body.records[i].subClass] = temp; } }