public static void ResetMutationCosts()
 {
     foreach (MutationCategory mc in Egcb_MutableMutations.MutationData)
     {
         foreach (MutationEntry me in mc.Entries)
         {
             //reset all mutation costs to the value specified in the core Mutations.xml file
             string opName = Egcb_MutableMutations.GetOptionNameForMutationCost(me);
             Options.SetOption(opName, Egcb_MutableMutations.GetDefaultCostForMutationValueArray(me));
         }
     }
     Debug.Log("Mutable Mutations Mod - Reset all mutation costs to default.");
 }
        private static void CreateOptionsList()
        {
            Egcb_MutableMutations.OptionsList.Clear();
            //create a reset option to restore game defaults
            GameOption resetOp = new GameOption();

            resetOp.ID          = Egcb_MutableMutations.ResetMutationValueOptionID;
            resetOp.DisplayText = "Reset all mutation costs to default (after closing Options)";
            resetOp.Category    = Egcb_MutableMutations.OptionsCategoryName;
            resetOp.Type        = "Checkbox";
            resetOp.Default     = "No";
            Egcb_MutableMutations.OptionsList.Add(resetOp.ID);
            Egcb_MutableMutations.AddNewGameOption(resetOp);
            foreach (MutationCategory mc in Egcb_MutableMutations.MutationData)
            {
                string mutationCategoryName = ConsoleLib.Console.ColorUtility.StripFormatting(mc.DisplayName).TrimEnd('s');
                foreach (MutationEntry me in mc.Entries)
                {
                    string optionName = Egcb_MutableMutations.GetOptionNameForMutationCost(me);
                    Egcb_MutableMutations.OptionsList.Add(optionName);
                    if (Options.OptionsByID.ContainsKey(optionName) || me.Cost == 0) //also skip 0 cost vanilla entries, if they exist, because we won't really know what Values range to use
                    {
                        continue;
                    }
                    //option doesn't exist, so we'll create it
                    GameOption gameOption = new GameOption();
                    gameOption.ID          = optionName;
                    gameOption.DisplayText = Egcb_MutableMutations.GetMutationCostOptionDisplayText(me);
                    gameOption.Category    = Egcb_MutableMutations.OptionsCategoryName;
                    gameOption.Type        = "Combo";
                    gameOption.Values      = Egcb_MutableMutations.GetCostValueArrayForMutation(me);
                    gameOption.Default     = Egcb_MutableMutations.GetDefaultCostForMutationValueArray(me);
                    //add to game Options
                    Egcb_MutableMutations.AddNewGameOption(gameOption);
                }
            }
        }
        private static void ApplyMutationOptions(bool bInitialLoad)
        {
            if (bInitialLoad)
            {
                Debug.Log("Mutable Mutations Mod - Generating initial mutation cost settings...");
            }
            else
            {
                Debug.Log("Mutable Mutations Mod - Regenerating mutation cost settings...");
            }
            Egcb_MutableMutations.CachedOptionValues.Clear();
            using (StreamWriter xmlStream = new StreamWriter(Path.Combine(Egcb_MutableMutations.ModDirectory, "Mutations.xml"), false))
            {
                XmlWriterSettings xmlSettings = new XmlWriterSettings {
                    Indent = true
                };
                using (XmlWriter xmlWriter = XmlWriter.Create(xmlStream, xmlSettings))
                {
                    xmlWriter.WriteStartDocument();
                    xmlWriter.WriteStartElement("mutations");
                    foreach (MutationCategory mc in Egcb_MutableMutations.MutationData)
                    {
                        xmlWriter.WriteStartElement("category");
                        xmlWriter.WriteAttributeString("Name", mc.Name);
                        xmlWriter.WriteAttributeString("DisplayName", mc.DisplayName);
                        if (!String.IsNullOrEmpty(mc.Help))
                        {
                            xmlWriter.WriteAttributeString("Help", mc.Help);
                        }
                        if (!String.IsNullOrEmpty(mc.Stat))
                        {
                            xmlWriter.WriteAttributeString("Stat", mc.Stat);
                        }
                        if (!String.IsNullOrEmpty(mc.Property))
                        {
                            xmlWriter.WriteAttributeString("Property", mc.Property);
                        }
                        if (!String.IsNullOrEmpty(mc.ForceProperty))
                        {
                            xmlWriter.WriteAttributeString("ForceProperty", mc.ForceProperty);
                        }
                        foreach (MutationEntry me in mc.Entries)
                        {
                            xmlWriter.WriteStartElement("mutation");
                            string mutationOptionName = Egcb_MutableMutations.GetOptionNameForMutationCost(me);
                            string mutationOptionCost = Options.GetOption(mutationOptionName, String.Empty).Trim();
                            mutationOptionCost = (String.IsNullOrEmpty(mutationOptionCost) ? me.Cost.ToString() : mutationOptionCost);
                            Egcb_MutableMutations.CachedOptionValues.Add(mutationOptionName, mutationOptionCost);

                            xmlWriter.WriteAttributeString("Name", me.DisplayName);
                            xmlWriter.WriteAttributeString("Cost", mutationOptionCost);
                            if (!String.IsNullOrEmpty(me.Stat))
                            {
                                xmlWriter.WriteAttributeString("Stat", me.Stat);
                            }
                            if (me.Maximum != -999)
                            {
                                xmlWriter.WriteAttributeString("MaxSelected", me.Maximum.ToString());
                            }
                            xmlWriter.WriteAttributeString("Class", me.Class);
                            if (!String.IsNullOrEmpty(me.Constructor))
                            {
                                xmlWriter.WriteAttributeString("Constructor", me.Constructor);
                            }
                            xmlWriter.WriteAttributeString("Exclusions", me.Exclusions);
                            if (me.MaxLevel != -999)
                            {
                                xmlWriter.WriteAttributeString("MaxLevel", me.MaxLevel.ToString());
                            }
                            if (!String.IsNullOrEmpty(me.Property))
                            {
                                xmlWriter.WriteAttributeString("Property", me.Property);
                            }
                            if (!String.IsNullOrEmpty(me.ForceProperty))
                            {
                                xmlWriter.WriteAttributeString("ForceProperty", me.ForceProperty);
                            }
                            if (!String.IsNullOrEmpty(me.BearerDescription))
                            {
                                xmlWriter.WriteAttributeString("BearerDescription", me.BearerDescription);
                            }
                            xmlWriter.WriteAttributeString("Code", me.MutationCode);
                            if (me.Prerelease == true)
                            {
                                xmlWriter.WriteAttributeString("Prerelease", "true");
                            }
                            xmlWriter.WriteFullEndElement(); //important to write FullEndElement, game can't parse self-closing element in Mutations.xml yet
                        }
                        xmlWriter.WriteFullEndElement();
                    }
                    xmlWriter.WriteEndDocument();
                    xmlWriter.Flush();
                    xmlWriter.Close();
                }
                xmlStream.Flush();
                xmlStream.Close();
            }
        }