public static Dictionary <uint, Property> GetParentProperties(Dictionary <uint, Property> returnProperties, Dictionary <uint, Property> parentProperties) { if (returnProperties == null) { returnProperties = new Dictionary <uint, Property>(); } //add keys that didn't exist yet foreach (uint index in parentProperties.Keys) { if (!returnProperties.ContainsKey(index) && index != 0x00B2CCCB) { //This property specifies behavior bundles to exclude - instead of adding this property, remove all the bundles from the appropriate arrays returnProperties.Add(index, parentProperties[index]); } } if (parentProperties.ContainsKey(0x00B2CCCB)) { Property parentProperty = parentProperties[0x00B2CCCB]; KeyProperty parentPropertyValue = parentProperty as KeyProperty; //search the currently opened package for this type/instance group id. if it doesn't exist, find it in the default simcity packages DatabaseIndex parentIndex = null; //if (DatabaseManager.Instance.Indices.Exists(i => i.InstanceId == parentPropertyValue.InstanceId && i.TypeId == parentPropertyValue.TypeId && i.GroupContainer == parentPropertyValue.GroupContainer)) //{ // parentIndex = DatabaseManager.Instance.Indices.First(i => i.InstanceId == parentPropertyValue.InstanceId && i.TypeId == parentPropertyValue.TypeId && i.GroupContainer == parentPropertyValue.GroupContainer); //} //else //{ parentIndex = DatabaseIndex.FindIndex(parentPropertyValue.TypeId, parentPropertyValue.GroupContainer, null, parentPropertyValue.InstanceId, true, true); //} // if(parentIndex != null) // { byte[] data = parentIndex.GetIndexData(true); using (Stream s = new MemoryStream(data, 0, data.Length)) { PropertyFile propertyFile = new PropertyFile(); propertyFile.Read(s); return(GetParentProperties(returnProperties, propertyFile.Values)); } throw new Exception("Inheritance not found!"); } else { return(returnProperties); } }
private void mnuCopy_Click(object sender, RoutedEventArgs e) { //check if current index is a valid menu item if (this.DataContext.GetType() == typeof(DatabaseIndexData)) { DatabaseIndexData menuItemIndex = (DatabaseIndexData)this.DataContext; menuItemIndex.Index.IsModified = true; if (menuItemIndex.Index.InstanceType == (uint)PropertyFileTypeIds.Menu2) { SaveFileDialog dialog = new SaveFileDialog(); if (dialog.ShowDialog().GetValueOrDefault(false)) { List <DatabaseIndex> indices = new List <DatabaseIndex>(); menuItemIndex.Index.ModifiedInstanceId = TGIRandomGenerator.GetNext(); indices.Add(menuItemIndex.Index); PropertyFile menuFile = new PropertyFile(menuItemIndex.Index); #region Extract Icon if (menuFile.Values.ContainsKey(PropertyConstants.menuIcon)) { KeyProperty iconProperty = (KeyProperty)menuFile.Values[PropertyConstants.menuIcon]; DatabaseIndex iconIndex = DatabaseIndex.FindIndex(iconProperty.TypeId, null, null, iconProperty.InstanceId, true, false); iconIndex.ModifiedInstanceId = TGIRandomGenerator.GetNext(); indices.Add(iconIndex); iconProperty.InstanceId = iconIndex.ModifiedInstanceId.Value; menuItemIndex.Index.ModifiedData = new ModifiedPropertyFile() { PropertyFile = menuFile }; menuFile.Values[PropertyConstants.menuIcon] = iconProperty; } #endregion #region Extract Marquee Image if (menuFile.Values.ContainsKey(PropertyConstants.menuMarqueeImage)) { KeyProperty marqueeProperty = (KeyProperty)menuFile.Values[PropertyConstants.menuMarqueeImage]; DatabaseIndex marqueeIndex = DatabaseIndex.FindIndex(marqueeProperty.TypeId, null, null, marqueeProperty.InstanceId, true, false); marqueeIndex.ModifiedInstanceId = TGIRandomGenerator.GetNext(); indices.Add(marqueeIndex); marqueeProperty.InstanceId = marqueeIndex.ModifiedInstanceId.Value; menuItemIndex.Index.ModifiedData = new ModifiedPropertyFile() { PropertyFile = menuFile }; menuFile.Values[PropertyConstants.menuMarqueeImage] = marqueeProperty; } #endregion #region Extract Ecogame Unit if (menuFile.Values.ContainsKey(PropertyConstants.menuUnit)) { KeyProperty unitProperty = (KeyProperty)menuFile.Values[PropertyConstants.menuUnit]; DatabaseIndex unitIndex = DatabaseIndex.FindIndex((uint)TypeIds.PropertyFile, null, 0xe0, unitProperty.InstanceId, false, true); PropertyFile unitFile = new PropertyFile(unitIndex); unitFile.FlattenParentInheritance(); #region Extract Unit Display if (unitFile.Values.ContainsKey(PropertyConstants.ecoGameUnitDisplayModel)) { KeyProperty unitDisplayProperty = (KeyProperty)unitFile.Values[PropertyConstants.ecoGameUnitDisplayModel]; DatabaseIndex unitDisplayIndex = DatabaseIndex.FindIndex((uint)TypeIds.PropertyFile, null, 0xe1, unitDisplayProperty.InstanceId, false, true); unitDisplayIndex.ModifiedInstanceId = TGIRandomGenerator.GetNext(); unitDisplayProperty.InstanceId = unitDisplayIndex.ModifiedInstanceId.Value; unitFile.Values[PropertyConstants.ecoGameUnitDisplayModel] = unitDisplayProperty; PropertyFile unitDisplayFile = new PropertyFile(unitDisplayIndex); #region Extract LODs if (unitDisplayFile.Values.ContainsKey(PropertyConstants.UnitLOD1)) { KeyProperty LOD1Property = (KeyProperty)unitDisplayFile.Values[PropertyConstants.UnitLOD1]; DatabaseIndex LOD1Index = DatabaseIndex.FindIndex(LOD1Property.TypeId, null, null, LOD1Property.InstanceId, true, false); LOD1Index.ModifiedInstanceId = TGIRandomGenerator.GetNext(); indices.Add(LOD1Index); LOD1Property.InstanceId = LOD1Index.ModifiedInstanceId.Value; unitDisplayFile.Values[PropertyConstants.UnitLOD1] = LOD1Property; } if (unitDisplayFile.Values.ContainsKey(PropertyConstants.UnitLOD2)) { KeyProperty LOD2Property = (KeyProperty)unitDisplayFile.Values[PropertyConstants.UnitLOD2]; DatabaseIndex LOD2Index = DatabaseIndex.FindIndex(LOD2Property.TypeId, null, null, LOD2Property.InstanceId, true, false); LOD2Index.ModifiedInstanceId = TGIRandomGenerator.GetNext(); indices.Add(LOD2Index); LOD2Property.InstanceId = LOD2Index.ModifiedInstanceId.Value; unitDisplayFile.Values[PropertyConstants.UnitLOD2] = LOD2Property; } if (unitDisplayFile.Values.ContainsKey(PropertyConstants.UnitLOD3)) { KeyProperty LOD3Property = (KeyProperty)unitDisplayFile.Values[PropertyConstants.UnitLOD3]; DatabaseIndex LOD3Index = DatabaseIndex.FindIndex(LOD3Property.TypeId, null, null, LOD3Property.InstanceId, true, false); LOD3Index.ModifiedInstanceId = TGIRandomGenerator.GetNext(); indices.Add(LOD3Index); LOD3Property.InstanceId = LOD3Index.ModifiedInstanceId.Value; unitDisplayFile.Values[PropertyConstants.UnitLOD3] = LOD3Property; } if (unitDisplayFile.Values.ContainsKey(PropertyConstants.UnitLOD4)) { KeyProperty LOD4Property = (KeyProperty)unitDisplayFile.Values[PropertyConstants.UnitLOD4]; DatabaseIndex LOD4Index = DatabaseIndex.FindIndex(LOD4Property.TypeId, null, null, LOD4Property.InstanceId, true, false); LOD4Index.ModifiedInstanceId = TGIRandomGenerator.GetNext(); indices.Add(LOD4Index); LOD4Property.InstanceId = LOD4Index.ModifiedInstanceId.Value; unitDisplayFile.Values[PropertyConstants.UnitLOD4] = LOD4Property; } #endregion unitDisplayIndex.ModifiedData = new ModifiedPropertyFile() { PropertyFile = unitDisplayFile }; unitDisplayIndex.IsModified = true; indices.Add(unitDisplayIndex); } #endregion unitIndex.ModifiedInstanceId = TGIRandomGenerator.GetNext(); unitIndex.ModifiedData = new ModifiedPropertyFile() { PropertyFile = unitFile }; unitIndex.IsModified = true; indices.Add(unitIndex); unitProperty.InstanceId = unitIndex.ModifiedInstanceId.Value; menuItemIndex.Index.ModifiedData = new ModifiedPropertyFile() { PropertyFile = menuFile }; menuFile.Values[PropertyConstants.menuUnit] = unitProperty; } #endregion DatabasePackedFile.SaveAs(dialog.FileName, indices); } } else { MessageBox.Show("This only works for menu items..."); } } }