Beispiel #1
0
        public override void Read(BinaryReader br)
        {
            this._allBlocks = new List <VLTPointerBlock>();
            this._vltBlocks = new Dictionary <int, VLTPointerBlock>();
            this._rawBlocks = new List <VLTPointerBlock>();
            bool loadVlt = false;
            bool loadRaw = false;

            while (true)
            {
                VLTPointerBlock bk = new VLTPointerBlock();
                bk.Read(br);
                if (bk.Type != VLTPointerBlock.BlockType.Load)
                {
                    Debug.Write(string.Format("{0:x}\t", br.BaseStream.Position - 0xC));
                    Debug.WriteLine(bk.ToString());
                }
                this._allBlocks.Add(bk);
                if (bk.Type == VLTPointerBlock.BlockType.Switch && (bk.Identifier == 0 || bk.Identifier == 1))
                {
                    if (bk.Identifier == 1)
                    {
                        loadVlt = false;
                        loadRaw = true;
                    }
                    else if (bk.Identifier == 0)
                    {
                        loadVlt = true;
                        loadRaw = false;
                    }
                }
                else if (bk.Type == VLTPointerBlock.BlockType.RuntimeLink)
                {
                    // Linked at runtime.
                    if (loadVlt)
                    {
                        this._vltBlocks[bk.OffsetSource] = bk;
                    }

                    if (loadRaw)
                    {
                        this._rawBlocks.Add(bk);
                    }
                }
                else if (bk.Type == VLTPointerBlock.BlockType.Load && bk.Identifier == 1)
                {
                    if (loadVlt)
                    {
                        this._vltBlocks[bk.OffsetSource] = bk;
                    }

                    if (loadRaw)
                    {
                        this._rawBlocks.Add(bk);
                    }
                }
                else if (bk.Type == VLTPointerBlock.BlockType.Done)
                {
                    break;
                }
                else
                {
                    throw new Exception("Unknown ptr type.");
                }
            }
        }
Beispiel #2
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);
            }