public static void ResolveApparelGraphics_Postfix(PawnGraphicSet __instance)
        {
            Pawn pawn = __instance.pawn;

            // Set up the hair cut graphic
            if (Controller.settings.MergeHair)
            {
                HairCutPawn hairPawn = CutHairDB.GetHairCache(pawn);

                List <Apparel> wornApparel = pawn.apparel.WornApparel
                                             .Where(x => x.def.apparel.LastLayer == ApparelLayerDefOf.Overhead).ToList();
                HeadCoverage coverage = HeadCoverage.None;
                if (!wornApparel.NullOrEmpty())
                {
                    if (wornApparel.Any(x => x.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.UpperHead)))
                    {
                        coverage = HeadCoverage.UpperHead;
                    }

                    if (wornApparel.Any(x => x.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.FullHead)))
                    {
                        coverage = HeadCoverage.FullHead;
                    }
                }

                if (coverage != 0)
                {
                    hairPawn.HairCutGraphic = CutHairDB.Get <Graphic_Multi_Four>(
                        pawn.story.hairDef.texPath,
                        ShaderDatabase.Cutout,
                        Vector2.one,
                        pawn.story.hairColor, coverage);
                }
            }
        }
        public override void DrawHairAndHeadGear(Vector3 hairLoc, Vector3 headgearLoc,
                                                 RotDrawMode bodyDrawType,
                                                 Quaternion headQuat,
                                                 bool renderBody,
                                                 bool portrait, Vector3 hatInFrontOfFace)
        {
            Mesh hairMesh = this.GetPawnHairMesh(portrait);
            List <ApparelGraphicRecord> apparelGraphics  = this.Graphics.apparelGraphics;
            List <ApparelGraphicRecord> headgearGraphics = null;

            if (!apparelGraphics.NullOrEmpty())
            {
                headgearGraphics = apparelGraphics
                                   .Where(x => x.sourceApparel.def.apparel.LastLayer == ApparelLayerDefOf.Overhead ||
                                          x.sourceApparel.def.apparel.LastLayer == DefDatabase <ApparelLayerDef> .GetNamedSilentFail("OnHead") ||
                                          x.sourceApparel.def.apparel.LastLayer == DefDatabase <ApparelLayerDef> .GetNamedSilentFail("StrappedHead") ||
                                          x.sourceApparel.def.apparel.LastLayer == DefDatabase <ApparelLayerDef> .GetNamedSilentFail("MiddleHead")).ToList();
            }

            CompBodyAnimator animator = this.CompAnimator;

            bool noRenderGoggles = Controller.settings.FilterHats;

            bool showRoyalHeadgear = this.Pawn.royalty?.MostSeniorTitle != null && Controller.settings.ShowRoyalHeadgear;
            bool noRenderRoofed    = animator != null && animator.HideHat && !showRoyalHeadgear;
            bool noRenderBed       = Controller.settings.HideHatInBed && !renderBody && !showRoyalHeadgear;

            if (!headgearGraphics.NullOrEmpty())
            {
                bool filterHeadgear = portrait && Prefs.HatsOnlyOnMap || !portrait && noRenderRoofed;

                // Draw regular hair if appparel or environment allows it (FS feature)
                if (bodyDrawType != RotDrawMode.Dessicated)
                {
                    // draw full or partial hair
                    bool apCoversFullHead =
                        headgearGraphics.Any(
                            x => x.sourceApparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf
                                                                                     .FullHead) &&
                            !x.sourceApparel.def.apparel.hatRenderedFrontOfFace);

                    bool apCoversUpperHead =
                        headgearGraphics.Any(
                            x => x.sourceApparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf
                                                                                     .UpperHead) &&
                            !x.sourceApparel.def.apparel.hatRenderedFrontOfFace);

                    if (this.CompFace.Props.hasOrganicHair || noRenderBed || filterHeadgear ||
                        (!apCoversFullHead && !apCoversUpperHead && noRenderGoggles))
                    {
                        Material mat = this.Graphics.HairMatAt(this.HeadFacing);
                        GenDraw.DrawMeshNowOrLater(hairMesh, hairLoc, headQuat, mat, portrait);
                    }
                    else if (Controller.settings.MergeHair) // && !apCoversFullHead)
                    {
                        // If not, display the hair cut
                        HairCutPawn hairPawn   = CutHairDB.GetHairCache(this.Pawn);
                        Material    hairCutMat = hairPawn.HairCutMatAt(this.HeadFacing);
                        if (hairCutMat != null)
                        {
                            GenDraw.DrawMeshNowOrLater(hairMesh, hairLoc, headQuat, hairCutMat, portrait);
                        }
                    }
                }
                else
                {
                    filterHeadgear = false;
                }

                if (filterHeadgear)
                {
                    // Filter the head gear to only show non-hats, show nothing while in bed
                    if (noRenderGoggles)
                    {
                        headgearGraphics = headgearGraphics
                                           .Where(
                            x =>
                            !x.sourceApparel.def.apparel.bodyPartGroups
                            .Contains(BodyPartGroupDefOf.FullHead) &&
                            !x.sourceApparel.def.apparel.bodyPartGroups.Contains(
                                BodyPartGroupDefOf
                                .UpperHead))
                                           .ToList();
                    }
                    else
                    {
                        // Clear if nothing to show
                        headgearGraphics?.Clear();
                    }
                }

                if (noRenderBed && !showRoyalHeadgear)
                {
                    headgearGraphics?.Clear();
                }

                // headgearGraphics = headgearGraphics
                // .OrderBy(x => x.sourceApparel.def.apparel.bodyPartGroups.Max(y => y.listOrder)).ToList();
                if (headgearGraphics.NullOrEmpty())
                {
                    return;
                }

                for (int index = 0; index < headgearGraphics?.Count; index++)
                {
                    ApparelGraphicRecord headgearGraphic = headgearGraphics[index];
                    Material             headGearMat     = headgearGraphic.graphic.MatAt(this.HeadFacing);
                    headGearMat = this.Graphics.flasher.GetDamagedMat(headGearMat);

                    if (headgearGraphic.sourceApparel.def.apparel.hatRenderedFrontOfFace)
                    {
                        headgearLoc = hatInFrontOfFace;
                    }

                    GenDraw.DrawMeshNowOrLater(hairMesh, headgearLoc, headQuat, headGearMat, portrait);
                    headgearLoc.y += Offsets.YOffsetInterval_Clothes;
                }
            }
            else
            {
                // Draw regular hair if no hat worn
                if (bodyDrawType != RotDrawMode.Dessicated)
                {
                    Material hairMat = this.Graphics.HairMatAt(this.HeadFacing);
                    GenDraw.DrawMeshNowOrLater(hairMesh, hairLoc, headQuat, hairMat, portrait);
                }
            }
        }