public static void RemoveDefaultVanillaHairExtendedBeard(Pawn pawn, Dictionary <string, ThingComp> compLookup, HashSet <string> savedComps)
        {
            // If the pawn was saved when vanilla hair expanded was not enabled, but it was enabled when they load the pawn,
            // then they may end up with a beard by default.  This post-load action clears out that default beard.
            if (!savedComps.Contains("VanillaHairExpanded.CompBeard"))
            {
                if (compLookup.TryGetValue("VanillaHairExpanded.CompBeard", out ThingComp c))
                {
                    HairDef beardDef = ReflectionUtil.GetFieldValue <HairDef>(c, "beardDef");
                    if (beardDef != null && !String.Equals(beardDef, "VHE_BeardCleanShaven"))
                    {
                        HairDef defaultBeardDef = DefDatabase <HairDef> .GetNamedSilentFail("VHE_BeardCleanShaven");

                        if (defaultBeardDef != null)
                        {
                            ReflectionUtil.SetPublicField(c, "beardDef", defaultBeardDef);
                        }
                        else
                        {
                            Logger.Warning("Vanilla Hairs Extended added a default beard because none was saved with the pawn preset.  We tried to remove it but failed.");
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 public static void ResolveAllCrossReferences()
 {
     Scribe.mode = LoadSaveMode.ResolvingCrossRefs;
     using (List <IExposable> .Enumerator enumerator = Scribe.loader.crossRefs.crossReferencingExposables.GetEnumerator()) {
         while (enumerator.MoveNext())
         {
             ILoadReferenceable loadReferenceable = enumerator.Current as ILoadReferenceable;
             if (loadReferenceable != null)
             {
                 LoadedObjectDirectory loadedObjectDirectory = ReflectionUtil.GetFieldValue <LoadedObjectDirectory>(Scribe.loader.crossRefs, "loadedObjectDirectory");
                 if (loadedObjectDirectory != null)
                 {
                     loadedObjectDirectory.RegisterLoaded(loadReferenceable);
                 }
                 else
                 {
                     Logger.Warning("Could not access CrossRefHandler.loadedObjectDirectory in our version of ResolveAllCrossReferences()");
                 }
             }
         }
     }
     foreach (IExposable current in Scribe.loader.crossRefs.crossReferencingExposables)
     {
         try {
             Scribe.loader.curParent          = current;
             Scribe.loader.curPathRelToParent = null;
             current.ExposeData();
         }
         catch (Exception arg) {
             Log.Warning("Could not resolve cross refs: " + arg, false);
         }
     }
     Scribe.loader.curParent          = null;
     Scribe.loader.curPathRelToParent = null;
     Scribe.mode = LoadSaveMode.Inactive;
     Scribe.loader.crossRefs.Clear(false);
 }