Пример #1
0
 /// <summary>
 /// Tries to map the filenames of all the AFS file entries with the give IDX file.
 /// </summary>
 public void MapIDXFile(IDX idx)
 {
     for (int i = 0; i < idx.Entries.Count; i++)
     {
         IDXEntry entry = idx.Entries[i];
         if (i >= Entries.Count)
         {
             break;
         }
         Entries[i].IDXFilename = entry.Filename;
     }
 }
Пример #2
0
        protected override void _Read(BinaryReader reader)
        {
            long baseOffset = reader.BaseStream.Position;

            Signature = reader.ReadUInt32();
            if (!IsValid(Signature))
            {
                throw new InvalidFileSignatureException();
            }
            FileCount = reader.ReadUInt32();
            Entries.Clear();

            //read file offsets (table of content)
            uint index = 0;

            for (int i = 0; i < FileCount; i++)
            {
                AFSEntry entry = new AFSEntry();
                entry.ReadOffset(reader);
                entry.Index = index;
                Entries.Add(entry);
                index++;
            }

            //Read filename table offset
            //This limit is just a guess, needs testing
            if (FileCount > 1016)
            {
                reader.BaseStream.Seek(baseOffset + 0x0008000 - 8, SeekOrigin.Begin);
                FilenameSectionOffset = reader.ReadUInt32();
                FilenameSectionSize   = reader.ReadUInt32();
            }
            else
            {
                long offset = reader.BaseStream.Position + 0x0800 - (reader.BaseStream.Position % 0x0800);
                reader.BaseStream.Seek(baseOffset + offset - 8, SeekOrigin.Begin);
                FilenameSectionOffset = reader.ReadUInt32();
                FilenameSectionSize   = reader.ReadUInt32();
            }

            if (FilenameSectionOffset == 0)
            {
                //Set incrementing filenames if table of content is missing.
                for (int i = 0; i < FileCount; i++)
                {
                    Entries[i].Filename = "file_" + i;
                }
            }
            else
            {
                //Read table of contents
                reader.BaseStream.Seek(baseOffset + FilenameSectionOffset, SeekOrigin.Begin);
                for (int i = 0; i < FileCount; i++)
                {
                    Entries[i].ReadFilename(reader);
                }
            }

            //Read file data
            foreach (AFSEntry entry in Entries)
            {
                reader.BaseStream.Seek(baseOffset + entry.Offset, SeekOrigin.Begin);
                entry.ReadData(reader);
            }

            if (AutomaticLoadIDX)
            {
                if (typeof(FileStream).IsAssignableFrom(reader.BaseStream.GetType()))
                {
                    FileStream fs      = (FileStream)reader.BaseStream;
                    string     idxPath = Path.ChangeExtension(fs.Name, ".IDX");
                    if (File.Exists(idxPath))
                    {
                        IDX idx = new IDX(idxPath);
                        MapIDXFile(idx);
                    }
                }
            }
        }