// End Other public SpellIconDBC(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(); } }
// 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 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 SpellCastTimes(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].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 = 1; main.CastTime.Items.Add(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; 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 SpellFocusObject(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].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 = Encoding.UTF8.GetString(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[0]; if (offset == 0) { continue; } int returnValue = offset; string toAdd = ""; while (body.StringBlock[offset] != '\0') { toAdd += body.StringBlock[offset++]; } SpellFocusObjectLookup temp; temp.ID = (int)body.records[i].ID; temp.offset = returnValue; temp.stringHash = toAdd.GetHashCode(); temp.comboBoxIndex = boxIndex; main.RequiresSpellFocus.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 SpellRange(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].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 = Encoding.UTF8.GetString(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[0]; 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; string toAdd = ""; while (body.StringBlock[offset] != 0) { toAdd += body.StringBlock[offset++]; } SpellRangeLookup temp; temp.ID = (int)body.records[i].ID; temp.comboBoxIndex = boxIndex; main.Range.Items.Add(toAdd + "\t\t - " + "Hostile: " + MinimumRangeHostile + " - " + MaximumRangeHostile + "\t Friend: " + MinimumRangeFriend + " - " + MaximumRangeFriend); body.lookup.Add(temp); boxIndex++; } }
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(); })); }
public Task import(MySQL.MySQL mySQL, SpellEditor.MainWindow.UpdateProgressFunc UpdateProgress) { return(Task.Run(() => { UInt32 currentRecord = 0; try { UInt32 count = header.RecordCount; UInt32 index = 0; StringBuilder q = null; foreach (Spell_DBC_RecordMap r in body.records) { if (index == 0 || index % 250 == 0) { if (q != null) { q.Remove(q.Length - 2, 2); mySQL.execute(q.ToString()); } q = new StringBuilder(); q.Append(String.Format("INSERT INTO `{0}` VALUES ", mySQL.Table)); } if (++index % 1000 == 0) { double percent = (double)index / (double)count; UpdateProgress(percent); } currentRecord = r.record.ID; q.Append("("); foreach (var f in r.record.GetType().GetFields()) { switch (Type.GetTypeCode(f.FieldType)) { case TypeCode.UInt32: case TypeCode.Int32: { q.Append(String.Format("'{0}', ", f.GetValue(r.record))); break; } case TypeCode.Single: { q.Append(String.Format("REPLACE('{0}', ',', '.'), ", f.GetValue(r.record))); break; } case TypeCode.Object: { var attr = f.GetCustomAttribute <HandleField>(); if (attr != null) { if (attr.Method == 1) { switch (attr.Type) { case 1: { for (int i = 0; i < attr.Count; ++i) { q.Append(String.Format("\"{0}\", ", MySqlHelper.EscapeString(r.spellName[i]))); } break; } case 2: { for (int i = 0; i < attr.Count; ++i) { q.Append(String.Format("\"{0}\", ", MySqlHelper.EscapeString(r.spellRank[i]))); } break; } case 3: { for (int i = 0; i < attr.Count; ++i) { q.Append(String.Format("\"{0}\", ", MySqlHelper.EscapeString(r.spellDesc[i]))); } break; } case 4: { for (int i = 0; i < attr.Count; ++i) { q.Append(String.Format("\"{0}\", ", MySqlHelper.EscapeString(r.spellTool[i]))); } 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 i = 0; i < attr.Count; ++i) { q.Append(String.Format("\"{0}\", ", r.record.SpellNameFlag[i])); } break; } case 2: { for (int i = 0; i < attr.Count; ++i) { q.Append(String.Format("\"{0}\", ", r.record.SpellRankFlags[i])); } break; } case 3: { for (int i = 0; i < attr.Count; ++i) { q.Append(String.Format("\"{0}\", ", r.record.SpellDescriptionFlags[i])); } break; } case 4: { for (int i = 0; i < attr.Count; ++i) { q.Append(String.Format("\"{0}\", ", r.record.SpellToolTipFlags[i])); } break; } default: throw new Exception("ERROR: Unhandled type: " + f.FieldType + " on field: " + f.Name + " TYPE: " + attr.Type); } break; } } goto default; } default: throw new Exception("ERROR: Unhandled type: " + f.FieldType + " on field: " + f.Name); } } q.Remove(q.Length - 2, 2); q.Append("), "); } if (q.Length > 0) { q.Remove(q.Length - 2, 2); mySQL.execute(q.ToString()); } } catch (Exception e) { ErrorMessage = "ERROR on around spell ID " + currentRecord + ": " + e.Message + "\n\nNot all the data would have been imported because of this error. Considering truncating the table and trying again."; } })); }
// End DBCs public SpellRange(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].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 = Encoding.UTF8.GetString(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[0]; 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; string toAdd = ""; while (body.StringBlock[offset] != 0) { toAdd += body.StringBlock[offset++]; } SpellRangeLookup temp; temp.ID = (int)body.records[i].ID; temp.comboBoxIndex = boxIndex; main.Range.Items.Add(toAdd + "\t\t - " + "Hostile: " + MinimumRangeHostile + " - " + MaximumRangeHostile + "\t Friend: " + MinimumRangeFriend + " - " + MaximumRangeFriend); body.lookup.Add(temp); boxIndex++; } }
// End DBCs public SpellRadius(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].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 AreaGroup(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].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; temp.ID = id; temp.comboBoxIndex = boxIndex; main.AreaGroup.Items.Add(id); body.lookup.Add(temp); boxIndex++; } }