예제 #1
0
        private static System.Xml.Linq.XElement BodyLoadout_ToXml(On.RoR2.Loadout.BodyLoadoutManager.BodyLoadout.orig_ToXml orig, System.Object self, String elementName)
        {
            var bodyIndex          = self.GetFieldValue <int>("bodyIndex");
            var bodySkinController = BodyCatalog.GetBodyPrefab(bodyIndex).GetComponent <ModelLocator>().modelTransform.GetComponent <ModelSkinController>();
            var skinPreference     = self.GetFieldValue <uint>("skinPreference");

            if (addedSkins.Contains(bodySkinController.skins[skinPreference]))
            {
                self.SetFieldValue <uint>("skinPreference", 0u);
            }
            var skillPreferences    = self.GetFieldValue <uint[]>("skillPreferences");
            var allBodyInfosObj     = typeof(Loadout.BodyLoadoutManager).GetFieldValue <object>("allBodyInfos");
            var allBodyInfos        = ((Array)allBodyInfosObj).Cast <object>().ToArray();
            var currentInfo         = allBodyInfos[bodyIndex];
            var prefabSkillSlotsObj = currentInfo.GetFieldValue <object>("prefabSkillSlots");
            var prefabSkillSlots    = ((Array)prefabSkillSlotsObj).Cast <object>().ToArray();
            var skillFamilyIndices  = currentInfo.GetFieldValue <int[]>("skillFamilyIndices");

            for (int i = 0; i < prefabSkillSlots.Length; i++)
            {
                var         skillFamilyIndex = skillFamilyIndices[i];
                SkillFamily family           = SkillCatalog.GetSkillFamily(skillFamilyIndex);
                SkillDef    def = family.variants[skillPreferences[i]].skillDef;
                if (addedSkills.Contains(def))
                {
                    skillPreferences[i] = 0u;
                }
            }
            return(orig(self, elementName));
        }
예제 #2
0
    //Set an object's Property or Field by the provided name to a value
    public static bool SetObjectValue(this System.Object obj, string name, System.Object value)
    {
        if (obj.GetField(name) != null)
        {
            return(obj.SetFieldValue(name, value));
        }
        else if (obj.GetProperty(name) != null)
        {
            return(obj.SetPropertyValue(name, value));
        }

        Debug.LogWarning("ReflectionF.SetObjectValue: No field or property named " + name + " exists on instance of " + obj.GetType().ShortName());
        return(false);
    }