Пример #1
0
        public void Load(BinaryReader br, Database database, PackLoadingOptions loadingOptions = null)
        {
            string name = new string(br.ReadChars(0x2C)).Trim('\0');

            int binOffset = br.ReadInt32();
            int binSize   = br.ReadInt32();
            int vltOffset = br.ReadInt32();
            int vltSize   = br.ReadInt32();
            int fileSize  = br.ReadInt32();

            if (fileSize != br.BaseStream.Length)
            {
                throw new InvalidDataException("Corrupted file");
            }

            Vault vault                  = new Vault(name);
            DatabaseLoadedFile file      = new DatabaseLoadedFile();
            ByteOrder          byteOrder = loadingOptions?.ByteOrder ?? ByteOrder.Little;

            br.BaseStream.Seek(binOffset, SeekOrigin.Begin);
            byte[] binBuffer = new byte[binSize];
            if (br.Read(binBuffer, 0, binBuffer.Length) != binBuffer.Length)
            {
                throw new Exception($"Failed to read {binBuffer.Length} bytes of BIN data");
            }
            br.BaseStream.Seek(vltOffset, SeekOrigin.Begin);
            byte[] vltBuffer = new byte[vltSize];
            if (br.Read(vltBuffer, 0, vltBuffer.Length) != vltBuffer.Length)
            {
                throw new Exception($"Failed to read {vltBuffer.Length} bytes of VLT data");
            }
            vault.BinStream = new MemoryStream(binBuffer);
            vault.VltStream = new MemoryStream(vltBuffer);
            using (VaultLoadingWrapper loadingWrapper = new VaultLoadingWrapper(vault, byteOrder))
                database.LoadVault(file, vault, loadingWrapper);
            database.LoadFile(file);
        }
Пример #2
0
 public IList <Vault> Load(BinaryReader br, Database database, PackLoadingOptions loadingOptions = null)
 {
     throw new System.NotImplementedException();
 }
Пример #3
0
        public IList <Vault> Load(BinaryReader br, Database database, PackLoadingOptions loadingOptions = null)
        {
            if (br.ReadUInt32() != 0x73795341)
            {
                throw new InvalidDataException("Cannot process this stream: Invalid header magic");
            }

            uint numFiles = br.ReadUInt32();

            if (numFiles != 2)
            {
                throw new InvalidDataException("Cannot process this stream: Invalid file count");
            }

            uint nameTableLength = br.ReadUInt32();

            br.ReadUInt32();

            uint vltSize = br.ReadUInt32();

            br.ReadUInt32();
            uint vltOffset = br.ReadUInt32();

            br.ReadUInt32();

            uint binSize = br.ReadUInt32();

            br.ReadUInt32();
            uint binOffset = br.ReadUInt32();

            br.ReadUInt32();

            var fileNames = new List <string>();

            for (int i = 0; i < numFiles; i++)
            {
                fileNames.Add(NullTerminatedString.Read(br));
            }

            long endOffset = br.BaseStream.Position;

            byte[] vltData = new byte[vltSize];
            br.BaseStream.Position = endOffset + vltOffset;

            if (br.Read(vltData, 0, vltData.Length) != vltData.Length)
            {
                throw new Exception("could not read VLT data");
            }

            byte[] binData = new byte[binSize];
            br.BaseStream.Position = endOffset + binOffset;

            if (br.Read(binData, 0, binData.Length) != binData.Length)
            {
                throw new Exception("could not read BIN data");
            }

            Vault vault = new Vault(fileNames[0].Substring(0, fileNames[0].IndexOf('.')))
            {
                BinStream = new MemoryStream(binData),
                VltStream = new MemoryStream(vltData)
            };

            using (VaultLoadingWrapper loadingWrapper = new VaultLoadingWrapper(vault, loadingOptions?.ByteOrder ?? ByteOrder.Little))
            {
                database.LoadVault(vault, loadingWrapper);
            }

            return(new ReadOnlyCollection <Vault>(new List <Vault>(new[] { vault })));
        }