Example #1
0
        /// <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)));
                }
            }
        }
Example #2
0
 /// <summary>
 /// Reads the resources section of the file (after 0xBBbbBBbbBBbbBBbb)
 /// </summary>
 /// <returns></returns>
 public virtual void ReadResources(BinaryReader inStream, long dataTableBegin)
 {
     foreach (var propInfo in this.GetType().GetProperties())
     {
         if (propInfo.GetCustomAttributes(false).Any(n => n is ResourceOnly))
         {
             if (propInfo.PropertyType == typeof(UnicodeString))
             {
                 var           propOffset = this.GetType().GetProperties().Where(x => x.Name == propInfo.Name.Replace("StringData", "StringOffset")).FirstOrDefault();
                 UnicodeString newVal     = new UnicodeString(inStream, (int)(propOffset.GetValue(this, null)), dataTableBegin, false);
                 propInfo.SetValue(this, newVal, null);
             }
             else if (propInfo.PropertyType == typeof(UInt64List))
             {
                 var        propOffset = this.GetType().GetProperties().Where(x => x.Name == propInfo.Name.Replace("ListData", "ListOffset")).FirstOrDefault();
                 var        propLength = this.GetType().GetProperties().Where(x => x.Name == propInfo.Name.Replace("ListData", "ListLength")).FirstOrDefault();
                 UInt64List newVal     = new UInt64List(inStream, (int)(propOffset.GetValue(this, null)), dataTableBegin, (int)(propLength.GetValue(this, null)));
                 propInfo.SetValue(this, newVal, null);
             }
             else if (propInfo.PropertyType == typeof(UInt32List))
             {
                 var        propOffset = this.GetType().GetProperties().Where(x => x.Name == propInfo.Name.Replace("ListData", "ListOffset")).FirstOrDefault();
                 var        propLength = this.GetType().GetProperties().Where(x => x.Name == propInfo.Name.Replace("ListData", "ListLength")).FirstOrDefault();
                 UInt32List newVal     = new UInt32List(inStream, (int)(propOffset.GetValue(this, null)), dataTableBegin, (int)(propLength.GetValue(this, null)));
                 propInfo.SetValue(this, newVal, null);
             }
             else if (propInfo.PropertyType == typeof(Int32List))
             {
                 var       propOffset = this.GetType().GetProperties().Where(x => x.Name == propInfo.Name.Replace("ListData", "ListOffset")).FirstOrDefault();
                 var       propLength = this.GetType().GetProperties().Where(x => x.Name == propInfo.Name.Replace("ListData", "ListLength")).FirstOrDefault();
                 Int32List newVal     = new Int32List(inStream, (int)(propOffset.GetValue(this, null)), dataTableBegin, (int)(propLength.GetValue(this, null)));
                 propInfo.SetValue(this, newVal, null);
             }
             else if (propInfo.PropertyType == typeof(IndirectStringList))
             {
                 var propOffset            = this.GetType().GetProperties().Where(x => x.Name == propInfo.Name.Replace("ListData", "ListOffset")).FirstOrDefault();
                 var propLength            = this.GetType().GetProperties().Where(x => x.Name == propInfo.Name.Replace("ListData", "ListLength")).FirstOrDefault();
                 IndirectStringList newVal = new IndirectStringList(inStream, (int)(propOffset.GetValue(this, null)), dataTableBegin, (int)(propLength.GetValue(this, null)));
                 propInfo.SetValue(this, newVal, null);
             }
         }
     }
 }
Example #3
0
        /// <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)));
                }
            }
        }