using System.Xml.Linq; namespace Harmony.ProgressionFromXmlPatches { [HarmonyPatch(typeof(ProgressionFromXml))] //[HarmonyPatch(new[] { typeof(XElement), typeof(int), typeof(int), typeof(int), typeof(float), typeof(float), typeof(float) })] [HarmonyPatch("parseProgressionItem")] public class parseProgressionItemPatch { public static bool Prefix(ProgressionFromXml __instance, XElement childElement, int max_level, int min_level, int base_cost, float cost_multiplier_per_level, float max_level_ratio_to_parent, ref float order) { ProgressionType progressionType = ProgressionType.None; if (childElement.Name == (XName)"attribute") progressionType = ProgressionType.Attribute; else if (childElement.Name == (XName)"skill") progressionType = ProgressionType.Skill; else if (childElement.Name == (XName)"perk") progressionType = ProgressionType.Perk; else if (childElement.Name == (XName)"book") progressionType = ProgressionType.Book; else if (childElement.Name == (XName)"book_group") progressionType = ProgressionType.BookGroup; else if (childElement.Name == (XName)"crafting_skill") progressionType = ProgressionType.Crafting; if (progressionType == ProgressionType.None) return false; if (childElement.HasAttribute((XName)nameof(min_level))) min_level = int.Parse(childElement.GetAttribute((XName)nameof(min_level))); if (childElement.HasAttribute((XName)nameof(max_level))) max_level = int.Parse(childElement.GetAttribute((XName)nameof(max_level))); if (childElement.HasAttribute((XName)nameof(max_level_ratio_to_parent))) max_level_ratio_to_parent = StringParsers.ParseFloat(childElement.GetAttribute((XName)nameof(max_level_ratio_to_parent))); if (childElement.HasAttribute((XName)"base_skill_point_cost")) base_cost = int.Parse(childElement.GetAttribute((XName)"base_skill_point_cost")); else if (childElement.HasAttribute((XName)"base_exp_cost")) base_cost = int.Parse(childElement.GetAttribute((XName)"base_exp_cost")); if (childElement.HasAttribute((XName)nameof(cost_multiplier_per_level))) cost_multiplier_per_level = StringParsers.ParseFloat(childElement.GetAttribute((XName)nameof(cost_multiplier_per_level))); if (!childElement.HasAttribute((XName)"name")) return false; //Log.Out("ProgressionFromXmlPatches-parseProgressionItem SCENARIO: " + RebirthVariables.customScenario); if (RebirthVariables.customScenario == "hive") { if (progressionType == ProgressionType.Attribute && !(childElement.GetAttribute((XName)"name").ToLower() == "attfortitude")) { return false; } if (progressionType == ProgressionType.Skill) { string skillName = childElement.GetAttribute((XName)"name"); bool isValid = skillName == "FuriousRamsaySkillStrength" || skillName == "FuriousRamsaySkillDexterity" || skillName == "FuriousRamsaySkillConstitution" || skillName == "FuriousRamsaySkillIntelligence" || skillName == "FuriousRamsaySkillCharisma"; if (!isValid) { return false; } } if (progressionType == ProgressionType.Perk && !(childElement.GetAttribute((XName)"name").ToLower().StartsWith("perk"))) { return false; } } ProgressionClass progressionClass = new ProgressionClass(childElement.GetAttribute((XName)"name").ToLower()) { MinLevel = min_level, MaxLevel = max_level, Type = progressionType, BaseCostToLevel = base_cost, CostMultiplier = (double)cost_multiplier_per_level > 0.0 ? cost_multiplier_per_level : 1f, ParentMaxLevelRatio = max_level_ratio_to_parent }; progressionClass.ListSortOrder = order; ++order; if (childElement.HasAttribute((XName)"parent")) progressionClass.ParentName = childElement.GetAttribute((XName)"parent").ToLower(); if (childElement.HasAttribute((XName)"name_key")) progressionClass.NameKey = childElement.GetAttribute((XName)"name_key"); if (childElement.HasAttribute((XName)nameof(max_level_ratio_to_parent))) progressionClass.ParentMaxLevelRatio = StringParsers.ParseFloat(childElement.GetAttribute((XName)nameof(max_level_ratio_to_parent))); if (childElement.HasAttribute((XName)"desc_key")) progressionClass.DescKey = childElement.GetAttribute((XName)"desc_key"); if (childElement.HasAttribute((XName)"long_desc_key")) progressionClass.LongDescKey = childElement.GetAttribute((XName)"long_desc_key"); if (childElement.HasAttribute((XName)"icon")) progressionClass.Icon = childElement.GetAttribute((XName)"icon"); foreach (XElement element1 in childElement.Elements()) { if (element1.Name == (XName)"level_requirements") { int _level = 0; if (element1.HasAttribute((XName)"level")) _level = StringParsers.ParseSInt32(element1.GetAttribute((XName)"level")); LevelRequirement _lr = new LevelRequirement(_level); if (element1.HasElements) { foreach (XElement element2 in element1.Elements((XName)"requirement")) { IRequirement requirement = RequirementBase.ParseRequirement(element2); if (requirement != null) _lr.AddRequirement(requirement); } } progressionClass.AddLevelRequirement(_lr); } else if (element1.Name == (XName)"display_entry") { string[] strArray1 = element1.GetAttribute((XName)"unlock_level").Split(',', StringSplitOptions.None); int[] _qualityStarts = new int[strArray1.Length]; string str = ""; string[] _customName = (string[])null; string[] _customIcon = (string[])null; string[] _customIconTint = (string[])null; bool _customHasQuality = false; for (int index = 0; index < strArray1.Length; ++index) _qualityStarts[index] = StringParsers.ParseSInt32(strArray1[index]); if (element1.HasAttribute((XName)"item")) str = element1.GetAttribute((XName)"item"); if (element1.HasAttribute((XName)"has_quality")) _customHasQuality = StringParsers.ParseBool(element1.GetAttribute((XName)"has_quality")); if (element1.HasAttribute((XName)"icon")) _customIcon = element1.GetAttribute((XName)"icon").Split(',', StringSplitOptions.None); if (_customIcon != null) _customIconTint = !element1.HasAttribute((XName)"icontint") ? new string[_customIcon.Length] : element1.GetAttribute((XName)"icontint").Split(',', StringSplitOptions.None); if (element1.HasAttribute((XName)"name")) _customName = element1.GetAttribute((XName)"name").Split(',', StringSplitOptions.None); if (element1.HasAttribute((XName)"name_key")) { string[] strArray2 = element1.GetAttribute((XName)"name_key").Split(',', StringSplitOptions.None); for (int index = 0; index < strArray2.Length; ++index) strArray2[index] = Localization.Get(strArray2[index]); _customName = strArray2; } ProgressionClass.DisplayData displayData = progressionClass.AddDisplayData(str, _qualityStarts, _customIcon, _customIconTint, _customName, _customHasQuality); if (displayData.ItemName != "") displayData.AddUnlockData(displayData.ItemName, 0, (string[])null); if (element1.HasElements) { foreach (XElement element3 in element1.Elements((XName)"unlock_entry")) { int unlockTier = 0; if (element3.HasAttribute((XName)"unlock_tier")) unlockTier = StringParsers.ParseSInt32(element3.GetAttribute((XName)"unlock_tier")) - 1; string[] recipeList = (string[])null; if (element3.HasAttribute((XName)"recipes")) recipeList = element3.GetAttribute((XName)"recipes").Split(',', StringSplitOptions.None); if (element3.HasAttribute((XName)"item")) { foreach (string itemName in element3.GetAttribute((XName)"item").Split(',', StringSplitOptions.None)) displayData.AddUnlockData(itemName, unlockTier, recipeList); } } } } } progressionClass.Effects = MinEffectController.ParseXml(childElement, _type: MinEffectController.SourceParentType.ProgressionClass, _parentPointer: (object)progressionClass.Name); Progression.ProgressionClasses.Add(progressionClass.Name, progressionClass); return false; } } }