示例#1
0
        public override void ReadValue(EndianReader reader)
        {
            IsBusy    = true;
            IsEnabled = true;

            try
            {
                //force block index dropdown to reset
                blockIndex = -1;
                RaisePropertyChanged(nameof(BlockIndex));

                Children.Clear();
                BlockLabels.Clear();
                reader.Seek(ValueAddress, SeekOrigin.Begin);

                var expander = (context.Cache as IMccCacheFile)?.PointerExpander;
                BlockCount   = reader.ReadInt32();
                BlockAddress = new Pointer(reader.ReadInt32(), context.Cache.DefaultAddressTranslator, expander).Address;

                if (BlockCount <= 0 || BlockAddress < 0 || BlockAddress + BlockCount * BlockSize > reader.BaseStream.Length)
                {
                    IsEnabled = false;
                    return;
                }

                blockIndex = 0;
                foreach (XmlNode n in node.ChildNodes)
                {
                    Children.Add(GetMetaValue(n, context, BlockAddress));
                }

                var entryOffset = node.GetIntAttribute("entryName", "entryOffset", "label");
                var isExplicit  = entryOffset.HasValue;
                entryOffset = entryOffset ?? 0;

                labelValue = Children.FirstOrDefault(c => c.Offset == entryOffset);
                if ((isExplicit && labelValue is SimpleValue) || labelValue is StringValue || labelValue is TagReferenceValue)
                {
                    var labels = new List <string>();
                    for (int i = BlockCount - 1; i >= 0; i--) //end at 0 so the first entry is displayed when done
                    {
                        labelValue.BaseAddress = BlockAddress + i * BlockSize;
                        labelValue.ReadValue(reader);
                        labels.Insert(0, GetEntryString(i, labelValue));
                    }
                    BlockLabels.AddRange(labels);
                }
                else
                {
                    labelValue = null;
                    BlockLabels.AddRange(Enumerable.Range(0, BlockCount).Select(i => $"Block {i:D2}"));
                }

                RaisePropertyChanged(nameof(BlockIndex));
                RaisePropertyChanged(nameof(HasChildren));
            }
            catch { IsEnabled = false; }

            IsBusy = false;
        }
示例#2
0
 private string GetEntryString(int index, MetaValue value)
 {
     if (value.EntryString == null)
     {
         return($"Block {index:D2}");
     }
     else
     {
         return($"{index:D2} : {value.EntryString}");
     }
 }
示例#3
0
 internal void AddValue(XmlNode node, MetaValue value)
 {
     if (valuesByNode.ContainsKey(node))
     {
         valuesByNode[node] = value;
     }
     else
     {
         valuesByNode.Add(node, value);
     }
 }