public void Write(Stream savePath) { base.AcceptChanges(); using (DatabaseBinaryWriter writer = new DatabaseBinaryWriter(EndianBitConverter.Little, savePath)) { byte[] bytes = Encoding.UTF8.GetBytes("LBT"); List<byte> list = new List<byte>(); Dictionary<string, int> dictionary = new Dictionary<string, int>(StringComparer.Ordinal); uint num = 0; foreach (string str in base.DataSetName.Split(new char[] { ';' })) { writer.Write(Convert.ToUInt32(str)); num = Convert.ToUInt32(str); } for (int i = 0; i < base.Tables.Count; i++) { if (num == 0x3e8) { writer.Write((ushort)i); writer.Write((ushort)0x2a2b); } else { writer.Write(Convert.ToByte(i)); writer.Write(Encoding.UTF8.GetBytes("LBT")); } writer.Write(base.Tables[i].Rows.Count); foreach (DataRow row in base.Tables[i].Rows) { if (num == 0x3e8) { writer.Write((ushort)0x2a2d); writer.Write((ushort)i); } else { writer.Write(Encoding.UTF8.GetBytes("ITM")); writer.Write(Convert.ToByte(i)); } for (int j = 0; j < base.Tables[i].Columns.Count; j++) { if (base.Tables[i].Columns[j].DataType == typeof(float)) { writer.Write((float)row.ItemArray[j]); } else if (base.Tables[i].Columns[j].DataType == typeof(int)) { writer.Write((int)row.ItemArray[j]); } else if (base.Tables[i].Columns[j].DataType == typeof(string)) { if (num == 0x3e8) { if (dictionary.ContainsKey((string)row.ItemArray[j])) { writer.Write(dictionary[(string)row.ItemArray[j]]); } else { writer.Write(list.Count); dictionary.Add((string)row.ItemArray[j], list.Count); list.AddRange(Encoding.UTF8.GetBytes((string)row.ItemArray[j])); list.Add(0); } } else { writer.WriteDatabaseString((string)row.ItemArray[j], base.Tables[i].Columns[j].MaxLength); } } else if (base.Tables[i].Columns[j].DataType == typeof(bool)) { writer.Write((bool)row.ItemArray[j]); writer.Write(new byte[3]); } } } } if (num == 0x3e8) { writer.Write(Encoding.UTF8.GetBytes("PRTS")); writer.Write(list.Count); writer.Write(list.ToArray()); } } }
public void Write(Stream savePath) { base.AcceptChanges(); using (DatabaseBinaryWriter writer = new DatabaseBinaryWriter(EndianBitConverter.Little, savePath)) { byte[] bytes = Encoding.UTF8.GetBytes("LBT"); List <byte> list = new List <byte>(); Dictionary <string, int> dictionary = new Dictionary <string, int>(StringComparer.Ordinal); uint schemaVersion = 0; foreach (string str in base.DataSetName.Split(new char[] { ';' })) { writer.Write(Convert.ToUInt32(str)); schemaVersion = Convert.ToUInt32(str); } for (int i = 0; i < base.Tables.Count; i++) { if (schemaVersion == 1000 || schemaVersion == 1407330540) { writer.Write((ushort)i); writer.Write((ushort)0x2a2b); } else { writer.Write(Convert.ToByte(i)); writer.Write(Encoding.UTF8.GetBytes("LBT")); } writer.Write(base.Tables[i].Rows.Count); foreach (DataRow row in base.Tables[i].Rows) { if (schemaVersion == 1000 || schemaVersion == 1407330540) { writer.Write((ushort)0x2a2d); writer.Write((ushort)i); } else { writer.Write(Encoding.UTF8.GetBytes("ITM")); writer.Write(Convert.ToByte(i)); } for (int j = 0; j < base.Tables[i].Columns.Count; j++) { if (base.Tables[i].Columns[j].DataType == typeof(float)) { writer.Write((float)row.ItemArray[j]); } else if (base.Tables[i].Columns[j].DataType == typeof(int)) { writer.Write((int)row.ItemArray[j]); } else if (base.Tables[i].Columns[j].DataType == typeof(string)) { if (schemaVersion == 1000 || schemaVersion == 1407330540) { if (dictionary.ContainsKey((string)row.ItemArray[j])) { writer.Write(dictionary[(string)row.ItemArray[j]]); } else { writer.Write(list.Count); dictionary.Add((string)row.ItemArray[j], list.Count); list.AddRange(Encoding.UTF8.GetBytes((string)row.ItemArray[j])); list.Add(0); } } else { writer.WriteDatabaseString((string)row.ItemArray[j], base.Tables[i].Columns[j].MaxLength); } } else if (base.Tables[i].Columns[j].DataType == typeof(bool)) { writer.Write((bool)row.ItemArray[j]); writer.Write(new byte[3]); } } } } if (schemaVersion == 1000 || schemaVersion == 1407330540) { writer.Write(Encoding.UTF8.GetBytes("PRTS")); writer.Write(list.Count); writer.Write(list.ToArray()); } } }
public void Write(Stream savePath) { base.AcceptChanges(); using (DatabaseBinaryWriter writer = new DatabaseBinaryWriter(EndianBitConverter.Little, savePath)) { byte[] bytes = Encoding.UTF8.GetBytes("LBT"); List <byte> list = new List <byte>(); Dictionary <string, int> dictionary = new Dictionary <string, int>(StringComparer.Ordinal); uint schemaVersion = 0; foreach (string str in base.DataSetName.Split(new char[] { ';' })) { writer.Write(Convert.ToUInt32(str)); schemaVersion = Convert.ToUInt32(str); } // Old style games, and Dirt 3's version don't have the table bool hasStringTable = schemaVersion != 1313096275 && schemaVersion != 3934935529; // Begin writing each table's data for (int i = 0; i < base.Tables.Count; i++) { if (hasStringTable) { writer.Write((ushort)i); writer.Write((ushort)0x2a2b); } else { writer.Write(Convert.ToByte(i)); writer.Write(Encoding.UTF8.GetBytes("LBT")); } writer.Write(base.Tables[i].Rows.Count); // Write each itm/row foreach (DataRow row in base.Tables[i].Rows) { if (hasStringTable) { writer.Write((ushort)0x2a2d); writer.Write((ushort)i); } else { writer.Write(Encoding.UTF8.GetBytes("ITM")); writer.Write(Convert.ToByte(i)); } // Write the itm/row's data for (int j = 0; j < base.Tables[i].Columns.Count; j++) { if (base.Tables[i].Columns[j].DataType == typeof(float)) { writer.Write(row.Items <float>(j)); } else if (base.Tables[i].Columns[j].DataType == typeof(int)) { writer.Write(row.Items <int>(j)); } else if (base.Tables[i].Columns[j].DataType == typeof(string)) { if (hasStringTable) { if (dictionary.ContainsKey(row.Itemc <string>(j))) { writer.Write(dictionary[row.Itemc <string>(j)]); } else { writer.Write(list.Count); dictionary.Add(row.Itemc <string>(j), list.Count); list.AddRange(Encoding.UTF8.GetBytes(row.Itemc <string>(j))); list.Add(0); } } else { writer.WriteDatabaseString(row.Itemc <string>(j), base.Tables[i].Columns[j].MaxLength); } } else if (base.Tables[i].Columns[j].DataType == typeof(bool)) { writer.Write(row.Items <bool>(j)); writer.Write(new byte[3]); } } } } // Write the string table if (hasStringTable) { writer.Write(Encoding.UTF8.GetBytes("PRTS")); writer.Write(list.Count); writer.Write(list.ToArray()); } } }