Esempio n. 1
0
        private VLTBase ReadChunk(BinaryReader br)
        {
            if (br.BaseStream.Position == br.BaseStream.Length)
            {
                return(null);
            }

            VLTChunk chunk = new VLTChunk();

            chunk.Read(br);

            if (chunk.IsValid)
            {
                VLTBase vltbase = null;
                switch (chunk.ChunkId)
                {
                case VLTChunkId.Dependency:
                    vltbase = new VLTDependency();
                    break;

                case VLTChunkId.Strings:
                    vltbase = new VLTRaw();
                    break;

                case VLTChunkId.Data:
                    vltbase = new VLTRaw();
                    break;

                case VLTChunkId.Expression:
                    vltbase = new VLTExpression();
                    break;

                case VLTChunkId.Pointers:
                    vltbase = new VLTPointers();
                    break;

                default:
                    vltbase = new VLTRaw();
                    break;
                }
                vltbase.Chunk = chunk;
                vltbase.Read(br);
                chunk.SkipChunk(br.BaseStream);
                return(vltbase);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
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>();
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
            public void Add(VLTDataCollectionLoad collLoad, VLTFile vltFile)
            {
                BinaryReader br;

                BinaryReader brR = new BinaryReader(vltFile.RawStream);
                BinaryReader brV = new BinaryReader(vltFile.VltStream);

                VLTDataRow  dataRow  = new VLTDataRow(this._vltClass.FieldCount);
                VLTPointers pointers = vltFile.GetChunk(VLTChunkId.Pointers) as VLTPointers;

                int offset = 0;

#if CARBON
                if (pointers[collLoad.Pointer] == null)
                {
                    /*
                     * Debug.WriteLine(string.Format("Skipped Exp.. class='{0}', name='{1}', num1={2}, exp_ptr={3:x}, ptr_ptr={4:x}",
                     *      HashResolver.Resolve(collLoad.ClassNameHash), HashResolver.Resolve(collLoad.NameHash),
                     *      collLoad.Num1, collLoad.Address, collLoad.Pointer));
                     */
                }
                else
                {
                    offset = pointers[collLoad.Pointer].OffsetDest;
                }
#else
                offset = pointers[collLoad.Pointer].OffsetDest;
#endif

                dataRow.VLTFile        = vltFile;
                dataRow.VLTClass       = this._vltClass;
                dataRow.CollectionLoad = collLoad;

                for (int i = 0; i < this._vltClass.FieldCount; i++)
                {
#if CARBON
                    bool runtimeLink = false;
#endif
                    ClassField field = this._vltClass[i];

                    if (field.IsOptional)
                    {
                        br = null;
                        for (int j = 0; j < collLoad.CountOptional; j++)
                        {
                            if (collLoad[j].NameHash == field.NameHash)
                            {
                                if (collLoad[j].IsDataEmbedded)
                                {
                                    br = brV;
                                    br.BaseStream.Seek(collLoad[j].Pointer, SeekOrigin.Begin);
                                }
                                else
                                {
                                    VLTPointerBlock block = pointers[collLoad[j].Pointer];
#if CARBON
                                    if (block != null)
#endif
                                    {
                                        int localOffset = block.OffsetDest;
                                        br = brR;
                                        br.BaseStream.Seek(localOffset, SeekOrigin.Begin);
                                    }
#if CARBON
                                    else
                                    {
                                        /*
                                         * System.Diagnostics.Debug.WriteLine(
                                         *      string.Format("Runtime Linkage '{0}', name '{1}', field '{2}', req ptr '{3:x}'",
                                         *              HashResolver.Resolve(_vltClass.ClassHash), HashResolver.Resolve(collLoad.NameHash),
                                         *              HashResolver.Resolve(field.NameHash), collLoad[j].Pointer));
                                         */
                                        runtimeLink = true;
                                        br          = brR;
                                    }
#endif
                                }
                            }
                        }
                        if (br == null)
                        {
                            // data is not defined
                            continue;
                        }
                    }
                    else
                    {
                        br = brR;
                        br.BaseStream.Seek(offset + field.Offset, SeekOrigin.Begin);
                    }

                    /*
                     #if !CARBON
                     *                                      if (!field.IsArray && field.Alignment > 0)
                     *                                      {
                     *                                              int align = field.Alignment;
                     *                                              if (br.BaseStream.Position % align != 0)
                     *                                                      br.BaseStream.Position += align - (br.BaseStream.Position % align);
                     *                                      }
                     #endif
                     */

                    Type type = VLTTypeResolver.Resolver.Resolve(field.TypeHash);

                    if (type == null)
                    {
                        type = typeof(VLTTypes.UnknownType);
                    }

                    VLTDataItem dataItem;
                    if (field.IsArray)
                    {
                        dataItem = VLTDataItemArray.Instantiate(field, type);
                    }
                    else
                    {
                        dataItem = VLTDataItem.Instantiate(type);
                        if (dataItem is VLTTypes.UnknownType)
                        {
                            (dataItem as VLTTypes.UnknownType).SetLength(field.Length);
                        }
                    }

                    dataItem.Offset     = 0;
                    dataItem.InlineData = (br == brV);
                    dataItem.TypeHash   = field.TypeHash;
                    dataItem.NameHash   = field.NameHash;
                    dataItem.DataRow    = dataRow;

                    if (offset != 0 && !runtimeLink)
                    {
                        dataItem.Offset = (uint)br.BaseStream.Position;
                        dataItem.Read(br);
                    }

                    dataRow[i] = dataItem;
                }

                this._collection.Add(dataRow);
            }