Exemple #1
0
        public Farc(byte[] data)
        {
            using var accessor = new BinaryFile(data);
            Magic             = accessor.ReadInt32(0);
            UnknownHeaderData = accessor.ReadArray(4, 0x1C);
            FarcVersion       = accessor.ReadInt32(0x20);
            if (FarcVersion != 5)
            {
                throw new NotSupportedException("Only FARC version 5 is supported");
            }

            var fatOffset  = accessor.ReadInt32(0x24);
            var fatLength  = accessor.ReadInt32(0x28);
            var dataOffset = accessor.ReadInt32(0x2C);
            var dataLength = accessor.ReadInt32(0x30);

            var fat = new FarcFat(data, fatOffset, fatLength);

            var files = new ConcurrentDictionary <uint, byte[]>();

            foreach (var file in fat.Entries)
            {
                files[file.Hash] = accessor.ReadArray(dataOffset + file.DataOffset, file.DataLength);
            }
            Files = files;
        }
Exemple #2
0
        public byte[] ToByteArray()
        {
            var  file   = new BinaryFile(new byte[Entries.Count * EntrySize]);
            long offset = 0;

            foreach (var entry in Entries.ToImmutableSortedDictionary())
            {
                entry.Value.Write(file.Slice(offset, EntrySize));
                offset += EntrySize;
            }
            return(file.ReadArray());
        }