/// <summary> /// Return true if it succeded getting a property from the query and output it. /// </summary> /// <param name="query"></param> /// <param name="value"></param> /// <returns></returns> public bool TryGetValueFromQuery(string query, out NdfValueWrapper value) { string rest = string.Empty; string next = NdfQueryReader.ParseNextStep(query, out rest); if(!string.IsNullOrEmpty(next)) { NdfPropertyValue nextproperty; if (TryGetProperty(next, out nextproperty)) { switch (nextproperty.Type) { case Types.NdfType.ObjectReference: NdfObjectReference reference = nextproperty.Value as NdfObjectReference; if (string.IsNullOrEmpty(rest)) { value = reference; return true; } return reference.Instance.TryGetValueFromQuery(rest, out value); case Types.NdfType.MapList: NdfMapList mapList = nextproperty.Value as NdfMapList; if (string.IsNullOrEmpty(rest)) { value = mapList; return true; } return mapList.TryGetValueFromQuery(rest, out value); case Types.NdfType.List: NdfCollection list = nextproperty.Value as NdfCollection; if (string.IsNullOrEmpty(rest)) { value = list; return true; } return list.TryGetValueFromQuery(rest, out value); case Types.NdfType.Unknown : break; case Types.NdfType.Unset: break; default: value = nextproperty.Value; return true; } } } value = null; return false; }
private NdfValueWrapper GetCopiedValue(IValueHolder toCopy) { NdfValueWrapper copiedValue = null; switch (toCopy.Value.Type) { case NdfType.ObjectReference: var origInst = toCopy.Value as NdfObjectReference; if (origInst != null && !origInst.Instance.IsTopObject) { copiedValue = new NdfObjectReference(origInst.Class, CopyInstance(origInst.Instance).Id); } else { copiedValue = NdfTypeManager.GetValue(toCopy.Value.GetBytes(), toCopy.Value.Type, toCopy.Manager); } break; case NdfType.List: case NdfType.MapList: var copiedItems = new List <CollectionItemValueHolder>(); var collection = toCopy.Value as NdfCollection; if (collection != null) { copiedItems.AddRange(collection.Select(entry => new CollectionItemValueHolder(GetCopiedValue(entry), toCopy.Manager))); } copiedValue = new NdfCollection(copiedItems); break; case NdfType.Map: var map = toCopy.Value as NdfMap; if (map != null) { copiedValue = new NdfMap(new MapValueHolder(GetCopiedValue(map.Key), toCopy.Manager), new MapValueHolder(GetCopiedValue(map.Value as IValueHolder), toCopy.Manager), toCopy.Manager); } break; default: copiedValue = NdfTypeManager.GetValue(toCopy.Value.GetBytes(), toCopy.Value.Type, toCopy.Manager); break; } return(copiedValue); }
/// <summary> /// Return true if it succeded getting a property from the query and cast it into T, then output it. /// </summary> /// <param name="propertyPath"></param> /// <param name="value"></param> /// <returns></returns> public bool TryGetValueFromQuery<T>(string query, out T value) where T : NdfValueWrapper { NdfValueWrapper val = null; value = null; if (TryGetValueFromQuery(query, out val)) { value = val as T; if(val.Type == Types.NdfType.Map) { NdfMap map = val as NdfMap; MapValueHolder mapval = map.Value as MapValueHolder; value = mapval.Value as T; } if (value != null) return true; } return false; }
public FlatChangeEntry(NdfPropertyValue affectedPropertyValue, NdfValueWrapper newValue) : base(affectedPropertyValue) { NewValue = newValue; }
public MapValueHolder(NdfValueWrapper value, NdfbinManager manager, long instanceOffset) : base(value, manager, instanceOffset) { }
public override DataTemplate SelectTemplate(object item, DependencyObject container) { var element = container as FrameworkElement; if (!(item is IValueHolder) || element == null) { return(null); } var propVal = item as IValueHolder; NdfValueWrapper wrap = propVal.Value; if (wrap == null) { return(null); } switch (wrap.Type) { case NdfType.Float32: case NdfType.Float64: return(element.FindResource("FloatEditingTemplate") as DataTemplate); case NdfType.UInt16: case NdfType.UInt32: return(element.FindResource("UInt32EditingTemplate") as DataTemplate); case NdfType.Int32: case NdfType.Int8: case NdfType.Int16: return(element.FindResource("Int32EditingTemplate") as DataTemplate); case NdfType.Guid: return(element.FindResource("GuidEditingTemplate") as DataTemplate); case NdfType.Boolean: return(element.FindResource("BooleanEditingTemplate") as DataTemplate); case NdfType.Color32: return(element.FindResource("ColorPickerEditingTemplate") as DataTemplate); case NdfType.Vector: return(element.FindResource("VectorEditingTemplate") as DataTemplate); case NdfType.Map: return(element.FindResource("MapEditingTemplate") as DataTemplate); case NdfType.ObjectReference: return(element.FindResource("ObjectReferenceEditingTemplate") as DataTemplate); case NdfType.LocalisationHash: return(element.FindResource("LocaleHashEditingTemplate") as DataTemplate); case NdfType.TableString: case NdfType.TableStringFile: return(element.FindResource("StringTableEditingTemplate") as DataTemplate); case NdfType.TransTableReference: return(element.FindResource("TransTableReferenceEditingTemplate") as DataTemplate); case NdfType.Blob: return(element.FindResource("BlobEditingTemplate") as DataTemplate); case NdfType.EugFloat2: return(element.FindResource("FloatPairEditingTemplate") as DataTemplate); case NdfType.List: return(null); } return(null); }
public MapValueHolder(NdfValueWrapper value, NdfBinary manager) : base(value, manager) { }
/// <summary> /// Reads one object instance. /// </summary> /// <param name="ms"></param> /// <param name="index"></param> /// <param name="owner"></param> /// <returns></returns> protected NdfObject ReadObject(Stream ms, uint index, NdfBinary owner) { var instance = new NdfObject { Id = index }; if (owner.TopObjects.Contains(index)) { instance.IsTopObject = true; } var buffer = new byte[4]; ms.Read(buffer, 0, buffer.Length); int classId = BitConverter.ToInt32(buffer, 0); if (owner.Classes.Count < classId) { throw new InvalidDataException("Object without class found."); } NdfClass cls = instance.Class = owner.Classes[classId]; cls.Instances.Add(instance); // Read properties for (; ;) { ms.Read(buffer, 0, buffer.Length); uint propertyId = BitConverter.ToUInt32(buffer, 0); if (propertyId == 0xABABABAB) { break; } var propVal = new NdfPropertyValue(instance) { Property = cls.Properties.SingleOrDefault(x => x.Id == propertyId) }; if (propVal.Property == null) { // throw new InvalidDataException("Found a value for a property which doens't exist in this class."); foreach (var c in owner.Classes) { foreach (var p in c.Properties) { if (p.Id == propertyId) { propVal.Property = p; break; } } } } instance.PropertyValues.Add(propVal); NdfValueWrapper res = ReadValue(ms, owner); propVal.Value = res; } owner.AddEmptyProperties(instance); return(instance); }
public CollectionItemValueHolder(NdfValueWrapper value, NdfBinary manager) { Value = value; Manager = manager; }
public CollectionItemValueHolder(NdfValueWrapper value, NdfbinManager manager, long instanceOffset) { Value = value; Manager = manager; InstanceOffset = instanceOffset; }