public static BinTreeObject Serialize <T>(MetaEnvironment environment, uint pathHash, T metaClass) where T : IMetaClass { Type metaClassType = metaClass.GetType(); MetaClassAttribute metaClassAttribute = metaClassType.GetCustomAttribute(typeof(MetaClassAttribute)) as MetaClassAttribute; if (metaClassAttribute is null) { throw new InvalidOperationException("The provided MetaClass does not have a MetaClass Attribute"); } // Create Tree Properties for meta properties List <BinTreeProperty> properties = new(); foreach (PropertyInfo propertyInfo in metaClassType.GetProperties()) { BinTreeProperty treeProperty = ConvertPropertyToTreeProperty(environment, metaClass, propertyInfo); if (treeProperty is not null) { properties.Add(treeProperty); } } BinTreeObject treeObject = new BinTreeObject(metaClassAttribute.NameHash, pathHash, properties); return(treeObject); }
public override bool Equals(BinTreeProperty other) { if (this.NameHash != other.NameHash) { return(false); } if (other is BinTreeUnorderedContainer otherProperty) { if (this._properties.Count != otherProperty._properties.Count) { return(false); } for (int i = 0; i < this._properties.Count; i++) { if (!this._properties[i].Equals(otherProperty._properties[i])) { return(false); } } } return(true); }
public override bool Equals(BinTreeProperty other) { if (this.NameHash != other.NameHash) { return(false); } if (other is BinTreeEmbedded otherProperty) { if (this.MetaClassHash != otherProperty.MetaClassHash) { return(false); } if (this._properties.Count != otherProperty._properties.Count) { return(false); } for (int i = 0; i < this._properties.Count; i++) { if (!this._properties[i].Equals(otherProperty._properties[i])) { return(false); } } } return(true); }
// ------------ PROPERTY DESERIALIZATION ------------ \\ private static object DeserializeTreeProperty(MetaEnvironment environment, BinTreeProperty treeProperty, Type propertyType = null) { BinPropertyType treePropertyType = treeProperty.Type; if (IsPrimitivePropertyType(treePropertyType)) { return(FetchPrimitivePropertyValue(treeProperty)); } else if (treePropertyType == BinPropertyType.Container || treePropertyType == BinPropertyType.UnorderedContainer) { return(DeserializeContainer(environment, propertyType, treeProperty as BinTreeContainer)); } else if (treePropertyType == BinPropertyType.Structure) { return(DeserializeStructure(environment, treeProperty as BinTreeStructure)); } else if (treePropertyType == BinPropertyType.Embedded) { return(DeserializeEmbedded(environment, treeProperty as BinTreeEmbedded)); } else if (treePropertyType == BinPropertyType.Map) { return(DeserializeMap(environment, propertyType, treeProperty as BinTreeMap)); } else if (treePropertyType == BinPropertyType.Optional) { return(DeserializeOptional(environment, propertyType, treeProperty as BinTreeOptional)); } return(null); }
internal BinTreeOptional(BinaryReader br, IBinTreeParent parent, uint nameHash) : base(parent, nameHash) { this.ValueType = BinUtilities.UnpackType((BinPropertyType)br.ReadByte()); bool isSome = br.ReadBoolean(); if (isSome) { this.Value = BinTreeProperty.Read(br, this, this.ValueType); } }
public BinTreeOptional(IBinTreeParent parent, uint nameHash, BinPropertyType type, BinTreeProperty value) : base(parent, nameHash) { this.ValueType = type; this.Value = value; if (value is not null) { value.Parent = this; } }
private static IEnumerable <string> ProcessBinTreeProperty(BinTreeProperty treeProperty) { return(treeProperty switch { BinTreeString property => ProcessBinTreeString(property), BinTreeOptional property => ProcessBinTreeOptional(property), BinTreeContainer property => ProcessBinTreeContainer(property), BinTreeStructure property => ProcessBinTreeStructure(property), BinTreeMap property => ProcessBinTreeMap(property), _ => Enumerable.Empty <string>() });
private void OnBinTreeMapAddItem(object sender, RoutedEventArgs e) { if (e.Source is FrameworkElement frameworkElement && frameworkElement.DataContext is BinTreeMapViewModel mapViewModel) { BinTreeMap map = mapViewModel.TreeProperty as BinTreeMap; BinTreeProperty keyProperty = BinTreeUtilities.BuildProperty("", "", map, map.KeyType, BinPropertyType.None, BinPropertyType.None); BinTreeProperty valueProperty = BinTreeUtilities.BuildProperty("", "", map, map.ValueType, BinPropertyType.None, BinPropertyType.None); BinTreeMapEntryViewModel newEntryViewModel = new BinTreeMapEntryViewModel(mapViewModel, new KeyValuePair <BinTreeProperty, BinTreeProperty>(keyProperty, valueProperty)); mapViewModel.Children.Add(newEntryViewModel); } }
public Material(BinTreeProperty materialProperty, BinTreeProperty submeshProperty, BinTreeProperty textureProperty) { if (materialProperty != null) { Hash = ((BinTreeObjectLink)materialProperty).Value; } if (submeshProperty != null) { Name = ((BinTreeString)submeshProperty).Value.ToLower().Replace('/', '\\'); } if (textureProperty != null) { Texture = ((BinTreeString)textureProperty).Value.ToLower().Replace('/', '\\'); } }
public override bool Equals(BinTreeProperty other) { if (this.NameHash != other.NameHash) { return(false); } if (other is BinTreeOptional otherProperty) { if (this.ValueType != otherProperty.ValueType) { return(false); } return(this.Value.Equals(otherProperty.Value)); } return(true); }
private async void OnBinTreeObjectAddItem(object sender, RoutedEventArgs e) { if (e.Source is FrameworkElement frameworkElement && frameworkElement.DataContext is BinTreeObjectViewModel objectViewModel) { NewBinPropertyViewModel dialogViewModel = await DialogHelper.ShowNewBinPropertyDialog(this.ViewModel.StructureTemplates); if (dialogViewModel is not null) { BinTreeProperty newProperty = dialogViewModel.BuildProperty(objectViewModel.TreeObject); BinTreePropertyViewModel newPropertyViewModel = BinTreeUtilities.ConstructTreePropertyViewModel(objectViewModel, newProperty); if (newPropertyViewModel is not null) { objectViewModel.Children.Add(newPropertyViewModel); } } } }
// ------------ DESERIALIZATION ASSIGNMENT ------------ \\ private static void AssignMetaClassProperties(MetaEnvironment environment, object metaClassObject, Type metaClassType, ICollection <BinTreeProperty> treeProperties) { PropertyInfo[] properties = metaClassType.GetProperties(); foreach (PropertyInfo propertyInfo in properties) { MetaPropertyAttribute metaPropertyAttribute = propertyInfo.GetCustomAttribute(typeof(MetaPropertyAttribute)) as MetaPropertyAttribute; // Ignore non-meta properties if (metaPropertyAttribute is null) { continue; } // Find matching tree property BinTreeProperty treeProperty = treeProperties.FirstOrDefault(x => x.NameHash == metaPropertyAttribute.NameHash); if (treeProperty is not null) // Ignore missing properties { // Assign values to properties AssignMetaProperty(environment, metaClassObject, propertyInfo, treeProperty); } } }
public override bool Equals(BinTreeProperty other) { return(other is BinTreeMatrix44 property && this.NameHash == property.NameHash && this.Value == property.Value); }
public override bool Equals(BinTreeProperty other) { return(other is BinTreeNone property && property.NameHash == this.NameHash); }
public BinTreeOptional(IBinTreeParent parent, uint nameHash, BinPropertyType type, BinTreeProperty value) : base(parent, nameHash) { this.ValueType = type; this.Value = value; }
private static void AssignMetaProperty(MetaEnvironment environment, object metaClassObject, PropertyInfo propertyInfo, BinTreeProperty treeProperty) { propertyInfo.SetValue(metaClassObject, DeserializeTreeProperty(environment, treeProperty, propertyInfo.PropertyType)); }
public static BinTreePropertyViewModel ConstructTreePropertyViewModel(BinTreeParentViewModel parent, BinTreeProperty genericProperty) { return(genericProperty switch { BinTreeNone property => new BinTreePropertyViewModel(parent, property), BinTreeBool property => new BinTreeBoolViewModel(parent, property), BinTreeSByte property => new BinTreeSByteViewModel(parent, property), BinTreeByte property => new BinTreeByteViewModel(parent, property), BinTreeInt16 property => new BinTreeInt16ViewModel(parent, property), BinTreeUInt16 property => new BinTreeUInt16ViewModel(parent, property), BinTreeInt32 property => new BinTreeInt32ViewModel(parent, property), BinTreeUInt32 property => new BinTreeUInt32ViewModel(parent, property), BinTreeInt64 property => new BinTreeInt64ViewModel(parent, property), BinTreeUInt64 property => new BinTreeUInt64ViewModel(parent, property), BinTreeFloat property => new BinTreeFloatViewModel(parent, property), BinTreeVector2 property => new BinTreeVector2ViewModel(parent, property), BinTreeVector3 property => new BinTreeVector3ViewModel(parent, property), BinTreeVector4 property => new BinTreeVector4ViewModel(parent, property), BinTreeMatrix44 property => new BinTreeMatrix44ViewModel(parent, property), BinTreeColor property => new BinTreeColorViewModel(parent, property), BinTreeHash property => new BinTreeHashViewModel(parent, property), BinTreeWadEntryLink property => new BinTreeWadEntryLinkViewModel(parent, property), BinTreeUnorderedContainer property => new BinTreeUnorderedContainerViewModel(parent, property), BinTreeContainer property => new BinTreeContainerViewModel(parent, property), BinTreeString property => new BinTreeStringViewModel(parent, property), BinTreeEmbedded property => new BinTreeEmbeddedViewModel(parent, property), BinTreeStructure property => new BinTreeStructureViewModel(parent, property), BinTreeObjectLink property => new BinTreeObjectLinkViewModel(parent, property), BinTreeOptional property => new BinTreeOptionalViewModel(parent, property), BinTreeMap property => new BinTreeMapViewModel(parent, property), BinTreeBitBool property => new BinTreeBitBoolViewModel(parent, property), _ => null, });
public override bool Equals(BinTreeProperty other) { return(other is BinTreeWadEntryLink property && this.NameHash == property.NameHash && this.Value == property.Value); }