public static void RemoveDefaultFacialStuff(Pawn pawn, Dictionary <string, ThingComp> compLookup, HashSet <string> savedComps)
 {
     // If the pawn was saved when facial stuff was not enabled, but it was enabled when they load the pawn,
     // then the pawn will end up with random facial stuff settings, possibly including facial hair.  This post-load action clears
     // out as much of those random settings as possible.
     if (!savedComps.Contains("FacialStuff.CompFace"))
     {
         if (compLookup.TryGetValue("FacialStuff.CompFace", out ThingComp c))
         {
             ReflectionUtil.InvokeActionMethod(c, "InitializeCompFace");
             object pawnFace = ReflectionUtil.GetPropertyValue <object>(c, "PawnFace");
             if (pawnFace == null)
             {
                 //Logger.Debug("Couldn't get the PawnFace value from the comp with class " + c.GetType().FullName);
                 return;
             }
             Type beardDefType = ReflectionUtil.TypeByName("FacialStuff.Defs.BeardDef");
             if (beardDefType == null)
             {
                 //Logger.Debug("Didn't find the beard definition type");
             }
             else
             {
                 Def defaultBeardDef = GenDefDatabase.GetDef(beardDefType, "Beard_Shaved", false);
                 if (defaultBeardDef == null)
                 {
                     //Logger.Debug("Didn't find the default beard definition");
                 }
                 else
                 {
                     ReflectionUtil.SetFieldValue(pawnFace, "_beardDef", defaultBeardDef);
                 }
             }
             Type stacheDefType = ReflectionUtil.TypeByName("FacialStuff.Defs.MoustacheDef");
             if (stacheDefType == null)
             {
                 //Logger.Debug("Didn't find the moustache definition type");
             }
             else
             {
                 Def defaultStacheDef = GenDefDatabase.GetDef(stacheDefType, "Shaved", false);
                 if (defaultStacheDef == null)
                 {
                     //Logger.Debug("Didn't find the default moustache definition");
                 }
                 else
                 {
                     ReflectionUtil.SetFieldValue(pawnFace, "_moustacheDef", defaultStacheDef);
                 }
             }
         }
     }
 }
Exemple #2
0
 static HarmonyPatches()
 {
     try {
         Type            pageConfigureStartingPawnsType = ReflectionUtil.TypeByName("RimWorld.Page_ConfigureStartingPawns");
         Type            gameType = ReflectionUtil.TypeByName("Verse.Game");
         HarmonyInstance harmony  = HarmonyInstance.Create("EdB.PrepareCarefully");
         if (pageConfigureStartingPawnsType != null)
         {
             if (harmony.Patch(pageConfigureStartingPawnsType.GetMethod("PreOpen"),
                               new HarmonyMethod(null),
                               new HarmonyMethod(typeof(HarmonyPatches).GetMethod("PreOpenPostfix"))) == null)
             {
                 Log.Warning("Prepare Carefully did not successfully patch the Page_ConfigureStartingPawns.PreOpen method. The Prepare Carefully button may not appear properly.");
             }
             if (harmony.Patch(pageConfigureStartingPawnsType.GetMethod("DoWindowContents"),
                               new HarmonyMethod(null),
                               new HarmonyMethod(typeof(HarmonyPatches).GetMethod("DoWindowContentsPostfix"))) == null)
             {
                 Log.Warning("Prepare Carefully did not successfully patch the Page_ConfigureStartingPawns.DoWindowContentsPostfix method. The Prepare Carefully button may not appear properly.");
             }
         }
         else
         {
             Log.Warning("Could not add the Prepare Carefully button to the configure pawns page.  Could not find the required type.");
         }
         if (gameType != null)
         {
             if (harmony.Patch(gameType.GetMethod("InitNewGame"),
                               new HarmonyMethod(null),
                               new HarmonyMethod(typeof(HarmonyPatches).GetMethod("InitNewGamePostfix"))) == null)
             {
                 Log.Warning("Prepare Carefully did not successfully patch the Game.InitNewGame method. Prepare Carefully may not properly spawn pawns and items onto the map.");
             }
         }
         else
         {
             Log.Warning("Could not modify the game initialization routine as needed for Prepare Carefully.  Could not find the required type.");
         }
     }
     catch (Exception e) {
         Log.Warning("Failed to patch the game code as needed for Prepare Carefully.  There was an unexpected exception. \n" + e.StackTrace);
     }
 }