Example #1
0
        private static RuleDef InitialiseRuleBookAndFinalizeList(On.RoR2.RuleDef.orig_FromDifficulty orig)
        {
            RuleDef ruleChoices = orig();
            var     vanillaDefs = typeof(DifficultyCatalog).GetFieldValue <DifficultyDef[]>("difficultyDefs");

            if (difficultyAlreadyAdded == false)  //Technically this function we are hooking is only called once, but in the weird case it's called multiple times, we don't want to add the definitions again.
            {
                difficultyAlreadyAdded = true;
                for (int i = 0; i < vanillaDefs.Length; i++)
                {
                    difficultyDefinitions.Insert(i, vanillaDefs[i]);
                }
            }

            for (int i = vanillaDefs.Length; i < difficultyDefinitions.Count; i++)  //This basically replicates what the orig does, but that uses the hardcoded enum.Count to end it's loop, instead of the actual array length.
            {
                DifficultyDef difficultyDef = difficultyDefinitions[i];
                RuleChoiceDef choice        = ruleChoices.AddChoice(Language.GetString(difficultyDef.nameToken), null, false);
                choice.spritePath       = difficultyDef.iconPath;
                choice.tooltipNameToken = difficultyDef.nameToken;
                choice.tooltipNameColor = difficultyDef.color;
                choice.tooltipBodyToken = difficultyDef.descriptionToken;
                choice.difficultyIndex  = (DifficultyIndex)i;
            }

            ruleChoices.choices.Sort(delegate(RuleChoiceDef x, RuleChoiceDef y) {
                var xDiffValue = DifficultyCatalog.GetDifficultyDef(x.difficultyIndex).scalingValue;
                var yDiffValue = DifficultyCatalog.GetDifficultyDef(y.difficultyIndex).scalingValue;
                return(xDiffValue.CompareTo(yDiffValue));
            });

            return(ruleChoices);
        }
Example #2
0
        private RuleDef RuleDef_FromDifficulty(On.RoR2.RuleDef.orig_FromDifficulty orig)
        {
            var origReturn = orig();

            EDrule = origReturn.choices.First((def) =>
            {
                return(def.difficultyIndex == EDindex);
            });
            return(origReturn);
        }