/// <summary> /// Updates references to modified strings/data in the data section for the specified entry. /// </summary> /// <param name="entry">Entry being updated</param> /// <param name="updatedOffsets">Mapping of all changed offsets. Key = original offset, Value = new offset.</param> private void UpdateDataOffsets(BaseDat entry, Dictionary <long, long> updatedOffsets) { var properties = entry.GetType().GetProperties(); foreach (var prop in properties) { object[] customAttributes = prop.GetCustomAttributes(false); if (customAttributes.Length == 0) { continue; } if (customAttributes.Any(n => n is UInt64Index) || customAttributes.Any(n => n is UInt32Index) || customAttributes.Any(n => n is Int32Index)) { continue; } int offset = (int)prop.GetValue(entry, null); if (updatedOffsets.ContainsKey(offset)) { //Console.WriteLine("Updating offset {0} for {1} (now {2})", offset, prop.Name, updatedOffsets[offset]); prop.SetValue(entry, (int)updatedOffsets[offset], null); } } }
/// <summary> /// Finds all known references to strings and other data in the data section and adds them to the DataEntries. /// Accomplished by reading the [StringIndex] and [DataIndex] attributes of our dat structure. /// </summary> /// <param name="entry">Dat parser created from parsing a single entry of the .dat file.</param> /// <param name="inStream">Stream containing contents of .dat file. Stream position not preserved.</param> private void AddDataToTable(BaseDat entry, BinaryReader inStream) { var properties = entry.GetType().GetProperties(); foreach (var prop in properties) { object[] customAttributes = prop.GetCustomAttributes(false); if (customAttributes.Length == 0) { continue; } int offset = (int)prop.GetValue(entry, null); if (DataEntries.ContainsKey(offset) && !DataEntries[offset].ToString().Equals("")) { continue; } if (customAttributes.Any(n => n is StringIndex)) { DataEntries[offset] = new UnicodeString(inStream, offset, DataTableBegin, (customAttributes.Any(n => n is UserStringIndex))); // Console.WriteLine("{0} -> {1}", offset, DataEntries[offset]); } else if (customAttributes.Any(n => n is DataIndex)) { DataEntries[offset] = new UnkownData(inStream, offset, DataTableBegin); } else if (customAttributes.Any(n => n is UInt64Index)) { var propLength = entry.GetType().GetProperties().Where(x => x.Name == prop.Name + "Length").FirstOrDefault(); DataEntries[offset] = new UInt64List(inStream, offset, DataTableBegin, (int)(propLength.GetValue(entry, null))); } else if (customAttributes.Any(n => n is UInt32Index)) { var propLength = entry.GetType().GetProperties().Where(x => x.Name == prop.Name + "Length").FirstOrDefault(); DataEntries[offset] = new UInt32List(inStream, offset, DataTableBegin, (int)(propLength.GetValue(entry, null))); } else if (customAttributes.Any(n => n is Int32Index)) { var propLength = entry.GetType().GetProperties().Where(x => x.Name == prop.Name + "Length").FirstOrDefault(); DataEntries[offset] = new Int32List(inStream, offset, DataTableBegin, (int)(propLength.GetValue(entry, null))); } } }
/// <summary> /// Finds all known references to strings and other data in the data section and adds them to the DataEntries. /// Accomplished by reading the [StringIndex] and [DataIndex] attributes of our dat structure. /// </summary> /// <param name="entry">Dat parser created from parsing a single entry of the .dat file.</param> /// <param name="inStream">Stream containing contents of .dat file. Stream position not preserved.</param> private void AddDataToTable(BaseDat entry, BinaryReader inStream) { var properties = entry.GetType().GetProperties(); foreach (var prop in properties) { object[] customAttributes = prop.GetCustomAttributes(false); if (customAttributes.Length == 0) { continue; } if (customAttributes.Any(n => n is ResourceOnly)) { continue; } if (customAttributes.Any(n => n is Hidden)) { continue; } if (customAttributes.Any(n => n is ExternalReference)) { continue; } if (customAttributes.Any(n => n is ExternalReferenceList)) { continue; } int offset = (int)prop.GetValue(entry, null); if (DataEntries.ContainsKey(offset)) { continue; } if (customAttributes.Any(n => n is StringIndex)) { DataEntries[offset] = new UnicodeString(inStream, offset, DataTableBegin, (customAttributes.Any(n => n is UserStringIndex))); // Console.WriteLine("{0} -> {1}", offset, DataEntries[offset]); } else if (customAttributes.Any(n => n is DataIndex)) { DataEntries[offset] = new UnkownData(inStream, offset, DataTableBegin); } } }
/// <summary> /// Updates references to modified strings/data in the data section for the specified entry. /// </summary> /// <param name="entry">Entry being updated</param> /// <param name="updatedOffsets">Mapping of all changed offsets. Key = original offset, Value = new offset.</param> private void UpdateDataOffsets(BaseDat entry, Dictionary<long, long> updatedOffsets) { var properties = entry.GetType().GetProperties(); foreach (var prop in properties) { object[] customAttributes = prop.GetCustomAttributes(false); if (customAttributes.Length == 0) continue; if (customAttributes.Any(n => n is UInt64Index) || customAttributes.Any(n => n is UInt32Index) || customAttributes.Any(n => n is Int32Index)) continue; int offset = (int)prop.GetValue(entry, null); if (updatedOffsets.ContainsKey(offset)) { //Console.WriteLine("Updating offset {0} for {1} (now {2})", offset, prop.Name, updatedOffsets[offset]); prop.SetValue(entry, (int)updatedOffsets[offset], null); } } }
/// <summary> /// Finds all known references to strings and other data in the data section and adds them to the DataEntries. /// Accomplished by reading the [StringIndex] and [DataIndex] attributes of our dat structure. /// </summary> /// <param name="entry">Dat parser created from parsing a single entry of the .dat file.</param> /// <param name="inStream">Stream containing contents of .dat file. Stream position not preserved.</param> private void AddDataToTable(BaseDat entry, BinaryReader inStream) { var properties = entry.GetType().GetProperties(); foreach (var prop in properties) { object[] customAttributes = prop.GetCustomAttributes(false); if (customAttributes.Length == 0) continue; int offset = (int)prop.GetValue(entry, null); if (DataEntries.ContainsKey(offset) && !DataEntries[offset].ToString().Equals("")) { continue; } if (customAttributes.Any(n => n is StringIndex)) { DataEntries[offset] = new UnicodeString(inStream, offset, DataTableBegin, (customAttributes.Any(n => n is UserStringIndex))); // Console.WriteLine("{0} -> {1}", offset, DataEntries[offset]); } else if (customAttributes.Any(n => n is DataIndex)) { DataEntries[offset] = new UnkownData(inStream, offset, DataTableBegin); } else if (customAttributes.Any(n => n is UInt64Index)) { var propLength = entry.GetType().GetProperties().Where(x => x.Name == prop.Name+"Length").FirstOrDefault(); DataEntries[offset] = new UInt64List(inStream, offset, DataTableBegin, (int)(propLength.GetValue(entry, null))); } else if (customAttributes.Any(n => n is UInt32Index)) { var propLength = entry.GetType().GetProperties().Where(x => x.Name == prop.Name + "Length").FirstOrDefault(); DataEntries[offset] = new UInt32List(inStream, offset, DataTableBegin, (int)(propLength.GetValue(entry, null))); } else if (customAttributes.Any(n => n is Int32Index)) { var propLength = entry.GetType().GetProperties().Where(x => x.Name == prop.Name + "Length").FirstOrDefault(); DataEntries[offset] = new Int32List(inStream, offset, DataTableBegin, (int)(propLength.GetValue(entry, null))); } } }