Some mods break SkinColor to the point that even trying to access it throws a null ref, so go work around that

This commit is contained in:
lutepickle 2023-01-25 07:11:00 -08:00
parent aba80efe58
commit 2b0d5dd0e6
4 changed files with 19 additions and 6 deletions

Binary file not shown.

View file

@ -365,7 +365,7 @@ namespace RJW_Menstruation
cachedNipple = baseNipple + nippleProgress * nippleChange;
// For some reason, Props can go null when RJW relocates the chest (e.g. some animals), so catch that
cachedColor = Colors.CMYKLerp(Pawn.story?.SkinColor ?? Color.white, (Props?.BlackNippleColor ?? CompProperties_Breast.DefaultBlacknippleColor.ToColor), Alpha);
cachedColor = Colors.CMYKLerp(Utility.SafeSkinColor(Pawn), (Props?.BlackNippleColor ?? CompProperties_Breast.DefaultBlacknippleColor.ToColor), Alpha);
}
public void CopyBreastProperties(HediffComp_Breast original)

View file

@ -394,7 +394,7 @@ namespace RJW_Menstruation
anal = pawn.GetAnalIcon(showOrigin);
GUI.color = new Color(1.00f, 0.47f, 0.47f, 1);
GUI.Box(rect, "", boxstyle);
GUI.color = pawn.story.SkinColor;
GUI.color = Utility.SafeSkinColor(pawn);
//Widgets.DrawTextureFitted(genitalIconRect, anal, 1.0f);
//Widgets.DrawTextureFitted(genitalIconRect, vagina, 1.0f);
GUI.DrawTexture(genitalIconRect, anal, ScaleMode.ScaleToFit);

View file

@ -209,7 +209,7 @@ namespace RJW_Menstruation
nipple = ContentFinder<Texture2D>.Get("Breasts/Breast_Breast00_Nipple00", false);
areola = ContentFinder<Texture2D>.Get("Breasts/Breast_Breast00_Areola00", false);
GUI.color = pawn.story?.SkinColor ?? Color.white;
GUI.color = SafeSkinColor(pawn);
GUI.DrawTexture(rect, breast, ScaleMode.ScaleToFit);
GUI.color = Color.white;
GUI.DrawTexture(rect, areola, ScaleMode.ScaleToFit);
@ -236,7 +236,7 @@ namespace RJW_Menstruation
breast = ContentFinder<Texture2D>.Get(icon, false);
areola = ContentFinder<Texture2D>.Get(areolaicon, false);
nipple = ContentFinder<Texture2D>.Get(nippleicon, false);
GUI.color = pawn.story.SkinColor;
GUI.color = SafeSkinColor(pawn);
GUI.DrawTexture(rect, breast, ScaleMode.ScaleToFit);
GUI.color = comp.NippleColor;
@ -255,7 +255,7 @@ namespace RJW_Menstruation
nipple = ContentFinder<Texture2D>.Get("Breasts/Breast_Breast00_Nipple00", false);
areola = ContentFinder<Texture2D>.Get("Breasts/Breast_Breast00_Areola00", false);
GUI.color = pawn.story.SkinColor;
GUI.color = SafeSkinColor(pawn);
GUI.DrawTexture(rect, breast, ScaleMode.ScaleToFit);
GUI.color = Color.white;
GUI.DrawTexture(rect, areola, ScaleMode.ScaleToFit);
@ -454,5 +454,18 @@ namespace RJW_Menstruation
if (pawn.IsAnimal() && !Configurations.EnableAnimalCycle) return false;
return true;
}
// Apparently with some mods, even doing pawn.story?.SkinColor can throw a null reference, so we're stuck doing this
public static Color SafeSkinColor(Pawn pawn)
{
try
{
return pawn.story?.SkinColor ?? Color.white;
}
catch (NullReferenceException)
{
return Color.white;
}
}
}
}