protected NdfObject ParseObject(byte[] data, uint index, long objOffset) { var instance = new NdfObject { Id = index, Data = data, Offset = objOffset }; using (var ms = new MemoryStream(data)) { var buffer = new byte[4]; ms.Read(buffer, 0, buffer.Length); int classId = BitConverter.ToInt32(buffer, 0); var cls = instance.Class = Classes.SingleOrDefault(x => x.Id == classId); if (cls == null) { throw new InvalidDataException("Object without class found."); } cls.Instances.Add(instance); _allInstances.Add(instance); NdfPropertyValue prop; bool triggerBreak; // Read properties while (ms.Position < ms.Length) { prop = new NdfPropertyValue(instance); instance.PropertyValues.Add(prop); ms.Read(buffer, 0, buffer.Length); prop.Property = cls.Properties.Single(x => x.Id == BitConverter.ToInt32(buffer, 0)); var res = ReadValue(ms, out triggerBreak, prop); //prop.Type = res.Key; prop.Value = res; if (triggerBreak) { break; } } foreach (var property in instance.Class.Properties) { if (instance.PropertyValues.All(x => x.Property != property)) { instance.PropertyValues.Add(new NdfPropertyValue(instance) { Property = property, Value = new NdfNull(0) }); } } } return(instance); }
public bool FilterInstances(object o) { var obj = o as NdfObjectViewModel; if (obj == null) { return(false); } bool ret = true; foreach (PropertyFilterExpression expr in PropertyFilterExpressions) { if (expr.PropertyName == null) { continue; } NdfPropertyValue propVal = obj.PropertyValues.SingleOrDefault(x => x.Property.Name == expr.PropertyName); if (propVal == null) { ret = false; continue; } if (propVal.Value == null) { if (expr.Value.Length > 0) { ret = false; } continue; } if (propVal.Value.ToString().Contains(expr.Value)) { continue; } return(false); } return(ret); }
public FlatChangeEntry(NdfPropertyValue affectedPropertyValue, NdfValueWrapper newValue) : base(affectedPropertyValue) { NewValue = newValue; }
public ChangeEntryBase(NdfPropertyValue affectedPropertyValue) { AffectedPropertyValue = affectedPropertyValue; }
private NdfMapList GetUnitReferences(string faction) { NdfPropertyValue unitIds = tShowRoomDeckSerializer.Instances[0].PropertyValues.Where(prop => prop.Property.Name == faction).First(); return((NdfMapList)unitIds.Value); }
public MapChangeEntry(NdfPropertyValue affectedPropertyValue, MapValueHolder newKey, MapValueHolder newValue) : base(affectedPropertyValue) { NewKey = newKey; NewValue = newValue; }
private void GetValue(IValueHolder valueHolder, NdfObjectViewModel inst, List <NdfPropertyValue> result, NdfPropertyValue propertyValue) { switch (valueHolder.Value.Type) { case NdfType.ObjectReference: var ndfObjectReference = valueHolder.Value as NdfObjectReference; if (ndfObjectReference != null && ndfObjectReference.InstanceId == inst.Object.Id) { result.Add(propertyValue); } break; case NdfType.List: case NdfType.MapList: var ndfCollection = valueHolder.Value as NdfCollection; if (ndfCollection != null) { foreach (var col in ndfCollection) { GetValue(col, inst, result, propertyValue); } } break; case NdfType.Map: var map = valueHolder.Value as NdfMap; if (map != null) { GetValue(map.Key, inst, result, propertyValue); GetValue(map.Value as IValueHolder, inst, result, propertyValue); } break; } }
public ObjectReferenceChangeEntry(NdfPropertyValue affectedPropertyValue, uint classId, uint instanceId) : base(affectedPropertyValue) { ClassId = classId; InstanceId = instanceId; }
/// <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 bool FilterInstances(object o) { var obj = o as NdfObjectViewModel; if (obj == null) { return(false); } foreach (PropertyFilterExpression expr in PropertyFilterExpressions) { if (expr.PropertyName == null) { continue; } NdfPropertyValue propVal = obj.PropertyValues.SingleOrDefault(x => x.Property.Name == expr.PropertyName); if (propVal == null) { return(false); } if (propVal.Value == null || propVal.Value.ToString().ToLower().Equals("null")) { if (expr.Value.Length > 0) { return(false); } } int compare = String.Compare(propVal.Value.ToString(), expr.Value); if (expr.Discriminator == FilterDiscriminator.Equals) { if (compare == 0) { continue; } else { return(false); } } else if (expr.Discriminator == FilterDiscriminator.Smaller) { if (propVal.Value.ToString().Length < expr.Value.Length || (propVal.Value.ToString().Length == expr.Value.Length && compare < 0)) { continue; } else { return(false); } } else if (expr.Discriminator == FilterDiscriminator.Greater) { if (propVal.Value.ToString().Length > expr.Value.Length || (propVal.Value.ToString().Length == expr.Value.Length && compare > 0)) { continue; } else { return(false); } } else if (expr.Discriminator == FilterDiscriminator.Contains) { if (propVal.Value.ToString().Contains(expr.Value)) { continue; } else { return(false); } } else { return(false); } } return(true); }
/// <summary> /// Reads the value of a Property inside a object instance. /// </summary> /// <param name="ms"></param> /// <param name="triggerBreak"></param> /// <param name="prop"></param> /// <returns>A NdfValueWrapper Instance.</returns> protected NdfValueWrapper ReadValue(MemoryStream ms, out bool triggerBreak, NdfPropertyValue prop) { var buffer = new byte[4]; uint contBufferlen; NdfValueWrapper value; triggerBreak = false; ms.Read(buffer, 0, buffer.Length); var type = NdfTypeManager.GetType(buffer); if (type == NdfType.Reference) { ms.Read(buffer, 0, buffer.Length); type = NdfTypeManager.GetType(buffer); } switch (type) { case NdfType.WideString: case NdfType.List: case NdfType.MapList: ms.Read(buffer, 0, buffer.Length); contBufferlen = BitConverter.ToUInt32(buffer, 0); break; default: contBufferlen = NdfTypeManager.SizeofType(type); break; } if (type == NdfType.Unknown) { //var t = _unknownTypes.SingleOrDefault(x => Utils.ByteArrayCompare(x, buffer)); //if (t == default(byte[])) //{ // _unknownTypes.Add(buffer); // _unknownTypesCount.Add(1); //} //else // _unknownTypesCount[_unknownTypes.IndexOf(t)]++; triggerBreak = true; return(new NdfUnkown(buffer, ms.Position)); } if (type == NdfType.List || type == NdfType.MapList) { NdfCollection lstValue; if (type == NdfType.List) { lstValue = new NdfCollection(ms.Position); } else { lstValue = new NdfMapList(ms.Position); } CollectionItemValueHolder res; for (int i = 0; i < contBufferlen; i++) { if (type == NdfType.List) { res = new CollectionItemValueHolder(ReadValue(ms, out triggerBreak, prop), this, prop.InstanceOffset); } else { res = new CollectionItemValueHolder( new NdfMap( new MapValueHolder(ReadValue(ms, out triggerBreak, prop), this, prop.InstanceOffset), new MapValueHolder(ReadValue(ms, out triggerBreak, prop), this, prop.InstanceOffset), ms.Position), this, prop.InstanceOffset); } lstValue.Add(res); if (triggerBreak) { break; } } value = lstValue; } else if (type == NdfType.Map) { value = new NdfMap( new MapValueHolder(ReadValue(ms, out triggerBreak, prop), this, prop.InstanceOffset), new MapValueHolder(ReadValue(ms, out triggerBreak, prop), this, prop.InstanceOffset), ms.Position); } else { var contBuffer = new byte[contBufferlen]; ms.Read(contBuffer, 0, contBuffer.Length); if (prop != null) { prop.ValueData = contBuffer; } value = NdfTypeManager.GetValue(contBuffer, type, this, ms.Position - contBuffer.Length); } return(value); }