Exemplo n.º 1
0
            public void Init(VltRowRecord rowRecord, TableEndBlock block, BinaryReader vltReader,
                             BinaryReader binReader)
            {
                var info = new VltInfo(_vltClass.ClassRecord.NumFields);

                DebugUtil.EnsureCondition(
                    block.InfoDictionary.ContainsKey(rowRecord.Position),
                    () => "Uh oh.");

                var basePosition = block.InfoDictionary[rowRecord.Position].Address2;

                info.BlockContainer = block;
                info.Class          = _vltClass;
                info.RowRecord      = rowRecord;

                for (var i = 0; i < _vltClass.ClassRecord.NumFields; ++i)
                {
                    var          field = _vltClass.Fields[i];
                    BinaryReader br;

                    if (!field.IsOptional())
                    {
                        br = binReader;
                        br.BaseStream.Seek(basePosition + field.Offset, SeekOrigin.Begin);
                    }
                    else
                    {
                        br = null;

                        foreach (var row in rowRecord.Rows)
                        {
                            if (row.Hash == field.Hash)
                            {
                                if (row.IsInVlt())
                                {
                                    br = vltReader;
                                    br.BaseStream.Seek(row.Position, SeekOrigin.Begin);
                                }
                                else
                                {
                                    br = binReader;
                                    br.BaseStream.Seek(block.InfoDictionary[row.Position].Address2,
                                                       SeekOrigin.Begin);
                                }
                            }
                        }

                        if (br == null)
                        {
                            continue;
                        }
                    }

                    var type = VltTypeMap.Instance.GetTypeForKey(field.TypeHash);

                    if (type == null)
                    {
                        type = typeof(RawType);
                    }

                    VltType vltType;

                    if (field.IsArray())
                    {
                        vltType = new ArrayType(field, type);
                    }
                    else
                    {
                        vltType      = VltType.Create(type);
                        vltType.Size = field.Length;

                        if (vltType is RawType rt)
                        {
                            rt.Length = field.Length;
                        }
                    }

                    vltType.Address  = (uint)br.BaseStream.Position;
                    vltType.IsVlt    = br == vltReader;
                    vltType.TypeHash = field.TypeHash;
                    vltType.Hash     = field.Hash;
                    vltType.Info     = info;
                    vltType.Read(br);

                    if (vltType is ArrayType va)
                    {
                        Console.WriteLine($"Class: 0x{_vltClass.Hash:X8} | Field: 0x{field.Hash:X8} | Array of {va.Type} (original: 0x{field.TypeHash:X8}) with {va.Entries}/{va.MaxEntries} entries");

                        foreach (var av in va.Types)
                        {
                            Console.WriteLine($"\tValue: {av}");
                        }
                    }
                    else
                    {
                        if (!(vltType is RawType))
                        {
                            Console.WriteLine(
                                $"Class: 0x{_vltClass.Hash:X8} | Field: 0x{field.Hash:X8} | {vltType.GetType()} -> {vltType}");
                        }
                    }

                    info.Set(i, vltType);
                }

                _infoList.Add(info);
            }
Exemplo n.º 2
0
 public void Set(int index, VltType type)
 {
     TypesPresent[index] = true;
     Types[index]        = type;
 }