Example #1
0
        public override void Read(BinaryReader br)
        {
            int count = br.ReadInt32();

            _blocks = new VLTExpressionBlock[count];
            for (int i = 0; i < count; i++)
            {
                _blocks[i] = new VLTExpressionBlock();
                _blocks[i].Read(br);
            }
        }
Example #2
0
        public void Open(Stream vlt, Stream bin)
        {
            byte[] data = new byte[vlt.Length];
            vlt.Read(data, 0, data.Length);
            _binVlt = new MemoryStream(data);

            _chunks = new ArrayList();
            BinaryReader br = new BinaryReader(_binVlt);

            // Load up the chunks
            VLTBase chunk;

            do
            {
                chunk = ReadChunk(br);
                if (chunk != null)
                {
                    _chunks.Add(chunk);
                }
            } while (chunk != null);

            // Load up expression data
            VLTExpression expChunk = GetChunk(VLTChunkId.Expression) as VLTExpression;

            for (int i = 0; i < expChunk.Count; i++)
            {
                VLTExpressionBlock block = expChunk[i];
                block.ReadData(br);
            }

            // Load up raw bin data
            if (bin == null)
            {
                DirectoryInfo di      = new DirectoryInfo(_baseDir);
                VLTDependency dep     = GetChunk(VLTChunkId.Dependency) as VLTDependency;
                string        binName = dep.GetName(VLTDependency.BinFile);
                FileInfo[]    fi      = di.GetFiles(binName);
                if (fi.Length == 0)
                {
                    throw new Exception("Required file " + binName + " was not found.");
                }
                bin  = new FileStream(fi[0].FullName, FileMode.Open, FileAccess.Read);
                data = new byte[bin.Length];
                bin.Read(data, 0, data.Length);
                bin.Close();
            }
            else
            {
                data = new byte[bin.Length];
                bin.Read(data, 0, data.Length);
            }

            _binRaw = new MemoryStream(data);

            br = new BinaryReader(_binRaw);

            _binRaw.Seek(0, SeekOrigin.Begin);
            chunk = ReadChunk(br);
            chunk.Chunk.GotoStart(_binRaw);
            if (chunk.Chunk.ChunkId == VLTChunkId.StringsRaw)
            {
                int endPos = (int)_binRaw.Position + chunk.Chunk.DataLength;
                while (_binRaw.Position < endPos)
                {
                    string str = NullTerminatedString.Read(br);
                    if (str != "")
                    {
                        HashResolver.AddAuto(str);
                    }
                }
            }

            VLTPointers ptrChunk = GetChunk(VLTChunkId.Pointers) as VLTPointers;

            ptrChunk.ResolveRawPointers(_binRaw);
        }