Exemplo n.º 1
0
        public override void Read(BinaryReader br)
        {
            int[] offsets;
            long  position;

            this._count  = br.ReadInt32();
            this._hashes = new uint[this._count];
            this._names  = new string[this._count];
            offsets      = new int[this._count];
            for (int i = 0; i < this._count; i++)
            {
                this._hashes[i] = br.ReadUInt32();
            }

            for (int i = 0; i < this._count; i++)
            {
                offsets[i] = br.ReadInt32();
            }

            position = br.BaseStream.Position;
            for (int i = 0; i < this._count; i++)
            {
                br.BaseStream.Seek(position + offsets[i], SeekOrigin.Begin);
                this._names[i] = NullTerminatedString.Read(br);
            }
        }
Exemplo n.º 2
0
        public override void Write(BinaryWriter bw)
        {
            int length = 0;

            bw.Write(this._count);
            for (int i = 0; i < this._count; i++)
            {
                bw.Write(this._hashes[i]);
            }

            for (int i = 0; i < this._count; i++)
            {
                bw.Write(length);
                length += this._names[i].Length + 1;
            }
            for (int i = 0; i < this._count; i++)
            {
                NullTerminatedString.Write(bw, this._names[i]);
            }
        }
Exemplo n.º 3
0
        public void LoadDatabase(VLTDataDatabaseLoad dbLoad, VLTFile vltFile)
        {
            VLTPointers vltPointers = vltFile.GetChunk(VLTChunkId.Pointers) as VLTPointers;
            int         offset      = vltPointers[dbLoad.Pointer].OffsetDest;

            vltFile.RawStream.Seek(offset, SeekOrigin.Begin);
            BinaryReader br = new BinaryReader(vltFile.RawStream);

            this._types = new Dictionary <uint, VLTType>(dbLoad.Count);

            for (int i = 0; i < dbLoad.Count; i++)
            {
                VLTType type = new VLTType();
                type.TypeName = NullTerminatedString.Read(br);
                type.Length   = dbLoad[i];
                type.Hash     = JenkinsHash.getHash32(type.TypeName);
                this._types.Add(type.Hash, type);
                HashResolver.AddAuto(type.TypeName);
            }

            this._classes = new Dictionary <uint, VLTClass>();
        }
Exemplo n.º 4
0
        public void Open(Stream vlt, Stream bin)
        {
            byte[] data = new byte[vlt.Length];
            vlt.Read(data, 0, data.Length);
            this._binVlt = new MemoryStream(data);

            this._chunks = new List <VLTBase>();
            BinaryReader br = new BinaryReader(this._binVlt);

            // Load up the chunks
            VLTBase chunk;

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

            // Load up expression data
            VLTExpression expChunk = this.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(this._baseDir);
                VLTDependency dep     = this.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);
            }

            this._binRaw = new MemoryStream(data);

            br = new BinaryReader(this._binRaw);

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

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

            ptrChunk.ResolveRawPointers(this._binRaw);
        }