// 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 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(); }