Ejemplo n.º 1
0
        public static Vector2 ForPawn(Pawn pawn)
        {
            if (pawn.RaceProps.Humanlike)
            {
                PawnRenderer   renderer   = pawn.Drawer.renderer;
                PawnGraphicSet graphicSet = renderer.graphics;

                if (!graphicSet.AllResolved)
                {
                    graphicSet.ResolveAllGraphics();
                }

                if (pawn.IsDessicated() && graphicSet.dessicatedGraphic != null)
                {
                    return(BoundMap(
                               graphicSet.dessicatedGraphic,
                               GraphicType.Pawn,
                               graphicSet.desiccatedHeadGraphic,
                               new Vector2(renderer.BaseHeadOffsetAt(Rot4.South).x,
                                           renderer.BaseHeadOffsetAt(Rot4.East).z)));
                }

                return(BoundMap(
                           graphicSet.nakedGraphic,
                           GraphicType.Pawn,
                           graphicSet.headGraphic,
                           new Vector2(renderer.BaseHeadOffsetAt(Rot4.South).x,
                                       renderer.BaseHeadOffsetAt(Rot4.East).z)));
            }
            else
            {
                PawnKindLifeStage lifeStage = pawn.ageTracker.CurKindLifeStage;

                GraphicData graphicData;

                if (pawn.IsDessicated() && lifeStage.dessicatedBodyGraphicData != null)
                {
                    graphicData = lifeStage.dessicatedBodyGraphicData;
                }
                else if (pawn.gender == Gender.Female && lifeStage.femaleGraphicData != null)
                {
                    graphicData = lifeStage.femaleGraphicData;
                }
                else
                {
                    graphicData = lifeStage.bodyGraphicData;
                }

                return(Vector2.Scale(BoundMap(graphicData.Graphic, GraphicType.Pawn), graphicData.drawSize));
            }
        }
Ejemplo n.º 2
0
        public static bool Prefix(PawnRenderer __instance,
                                  ref Vector3 rootLoc,
                                  float angle,
                                  bool renderBody,
                                  Rot4 bodyFacing,
                                  Rot4 headFacing,
                                  RotDrawMode bodyDrawType,
                                  bool portrait,
                                  bool headStump)
        {
            // Pawn pawn = (Pawn)PawnFieldInfo?.GetValue(__instance);
            PawnGraphicSet graphics = __instance.graphics;

            Pawn pawn = graphics.pawn;

            if (!pawn.RaceProps.Humanlike && !Controller.settings.UsePaws)
            {
                return(true);
            }

            if (!graphics.AllResolved)
            {
                graphics.ResolveAllGraphics();
            }

            CompFace compFace = pawn.GetCompFace();
            bool     hasFace  = compFace != null;

            // Let vanilla do the job if no FacePawn or pawn not a teenager or any other known mod accessing the renderer
            if (hasFace)
            {
                if (compFace.IsChild || compFace.Deactivated)
                {
                    return(true);
                }
            }

            CompBodyAnimator compAnim = pawn.GetCompAnim();
            bool             showFeet = compAnim != null && Controller.settings.UseFeet;

            // No face, no animator, return
            if (!hasFace && compAnim == null)
            {
                return(true);
            }

            PawnWoundDrawer woundDrawer = (PawnWoundDrawer)WoundOverlayFieldInfo?.GetValue(__instance);

            // if (Patches2.Plants)
            // {
            //     if (pawn.Spawned)
            //     {
            //         Plant plant = (pawn.Position + IntVec3.South).GetPlant(pawn.Map);
            //         if (plant != null && Patches2.plantMoved.Contains(plant))
            //         {
            //             rootLoc.y = plant.DrawPos.y - (Patches2.steps / 2);
            //         }
            //     }
            // }

            // Try to move the y position behind while another pawn is standing near
            if (compAnim != null && (!portrait && pawn.Spawned && !compAnim.IsRider))
            {
                RecalcRootLocY(ref rootLoc, pawn, compAnim);
            }

            Vector3 baseDrawLoc = rootLoc;
            // Let's save the basic location for later
            Vector3 footPos = baseDrawLoc;



            // No face => must be animal, simplify it
            Quaternion quat     = Quaternion.AngleAxis(angle, Vector3.up);
            Quaternion bodyQuat = quat;
            Quaternion footQuat = bodyQuat;


            if (MainTabWindow_WalkAnimator.IsOpen)
            {
                bodyFacing = MainTabWindow_BaseAnimator.BodyRot;
                headFacing = MainTabWindow_BaseAnimator.HeadRot;
            }

            compFace?.TickDrawers(bodyFacing, headFacing, graphics);

            compAnim?.TickDrawers(bodyFacing, graphics);

            // Use the basic quat
            Quaternion headQuat = bodyQuat;

            // Rotate head if possible and wobble around
            if (!portrait || MainTabWindow_WalkAnimator.IsOpen)
            {
                if (showFeet)
                {
                    compAnim.ApplyBodyWobble(ref baseDrawLoc, ref footPos, ref bodyQuat);
                }

                // Reset the quat as it has been changed
                headQuat = bodyQuat;
                compFace?.ApplyHeadRotation(renderBody, ref headQuat);
            }

            // Regular FacePawn rendering 14+ years

            // Render body
            // if (renderBody)
            compAnim?.DrawBody(baseDrawLoc, bodyQuat, bodyDrawType, woundDrawer, renderBody, portrait);

            Vector3 bodyPos = baseDrawLoc;
            Vector3 headPos = baseDrawLoc;

            if (bodyFacing == Rot4.North)
            {
                headPos.y += YOffset_Shell;
                bodyPos.y += YOffset_Head;
            }
            else
            {
                headPos.y += YOffset_Head;
                bodyPos.y += YOffset_Shell;
            }


            if (graphics.headGraphic != null)
            {
                // Rendererd pawn faces

                Vector3 offsetAt = !hasFace
                                   ? __instance.BaseHeadOffsetAt(bodyFacing)
                                   : compFace.BaseHeadOffsetAt(portrait);

                Vector3 b           = bodyQuat * offsetAt;
                Vector3 headDrawLoc = headPos + b;

                if (!hasFace)
                {
                    Material material = graphics.HeadMatAt(headFacing, bodyDrawType, headStump);
                    if (material != null)
                    {
                        Mesh mesh2 = MeshPool.humanlikeHeadSet.MeshAt(headFacing);
                        GenDraw.DrawMeshNowOrLater(mesh2, headDrawLoc, quat, material, portrait);
                    }
                }
                else
                {
                    compFace.DrawBasicHead(out bool headDrawn, bodyDrawType, portrait, headStump, headDrawLoc, headQuat);
                    if (headDrawn)
                    {
                        if (bodyDrawType != RotDrawMode.Dessicated && !headStump)
                        {
                            if (compFace.Props.hasWrinkles)
                            {
                                Vector3 wrinkleLoc = headDrawLoc;
                                wrinkleLoc.y += YOffset_Wrinkles;
                                compFace.DrawWrinkles(bodyDrawType, wrinkleLoc, headQuat, portrait);
                            }

                            if (compFace.Props.hasEyes)
                            {
                                Vector3 eyeLoc = headDrawLoc;
                                eyeLoc.y += YOffset_Eyes;

                                compFace.DrawNaturalEyes(eyeLoc, portrait, headQuat);

                                Vector3 browLoc = headDrawLoc;
                                browLoc.y += YOffset_Brows;
                                // the brow above
                                compFace.DrawBrows(browLoc, headQuat, portrait);

                                // and now the added eye parts
                                Vector3 unnaturalEyeLoc = headDrawLoc;
                                unnaturalEyeLoc.y += YOffset_UnnaturalEyes;
                                compFace.DrawUnnaturalEyeParts(unnaturalEyeLoc, headQuat, portrait);
                            }

                            // Portrait obviously ignores the y offset, thus render the beard after the body apparel (again)
                            if (compFace.Props.hasBeard)
                            {
                                Vector3 beardLoc = headDrawLoc;
                                Vector3 tacheLoc = headDrawLoc;

                                beardLoc.y += headFacing == Rot4.North ? -YOffset_Head - YOffset_Beard : YOffset_Beard;
                                tacheLoc.y += headFacing == Rot4.North ? -YOffset_Head - YOffset_Tache : YOffset_Tache;

                                compFace.DrawBeardAndTache(beardLoc, tacheLoc, portrait, headQuat);
                            }

                            if (compFace.Props.hasMouth)
                            {
                                Vector3 mouthLoc = headDrawLoc;
                                mouthLoc.y += YOffset_Mouth;
                                compFace.DrawNaturalMouth(mouthLoc, portrait, headQuat);
                            }
                            // Deactivated, looks kinda crappy ATM
                            // if (pawn.Dead)
                            // {
                            // Material deadEyeMat = faceComp.DeadEyeMatAt(headFacing, bodyDrawType);
                            // if (deadEyeMat != null)
                            // {
                            // GenDraw.DrawMeshNowOrLater(mesh2, locFacialY, headQuat, deadEyeMat, portrait);
                            // locFacialY.y += YOffsetInterval_OnFace;
                            // }

                            // }
                            // else
                        }
                    }
                }


                if (!headStump)
                {
                    Vector3 overHead = baseDrawLoc + b;
                    overHead.y += YOffset_OnHead;

                    Vector3 hairLoc          = overHead;
                    Vector3 headgearLoc      = overHead;
                    Vector3 hatInFrontOfFace = baseDrawLoc + b;


                    hairLoc.y          += YOffset_HairOnHead;
                    headgearLoc.y      += YOffset_GearOnHead;
                    hatInFrontOfFace.y += ((!(headFacing == Rot4.North)) ? YOffset_PostHead : YOffset_Behind);

                    compFace?.DrawHairAndHeadGear(hairLoc, headgearLoc,
                                                  bodyDrawType,
                                                  portrait,
                                                  renderBody,
                                                  headQuat, hatInFrontOfFace);

                    compFace?.DrawAlienHeadAddons(headPos, portrait, headQuat, overHead);
                }
            }

            if (!portrait)
            {
                //   Traverse.Create(__instance).Method("DrawEquipment", rootLoc).GetValue();

                DrawEquipmentMethodInfo?.Invoke(__instance, new object[] { baseDrawLoc });
            }

            if (!portrait)
            {
                if (pawn.apparel != null)
                {
                    List <Apparel> wornApparel = pawn.apparel.WornApparel;
                    foreach (Apparel ap in wornApparel)
                    {
                        DrawPos_Patch.offset        = baseDrawLoc;
                        DrawPos_Patch.offsetEnabled = true;
                        ap.DrawWornExtras();
                        DrawPos_Patch.offsetEnabled = false;
                    }
                }

                Vector3 bodyLoc = baseDrawLoc;
                bodyLoc.y += YOffset_Status;

                PawnHeadOverlays headOverlays = (PawnHeadOverlays)PawnHeadOverlaysFieldInfo?.GetValue(__instance);
                if (headOverlays != null)
                {
                    compFace?.DrawHeadOverlays(headOverlays, bodyLoc, headQuat);
                }
            }


            compAnim?.DrawApparel(bodyQuat, bodyPos, portrait, renderBody);

            compAnim?.DrawAlienBodyAddons(bodyQuat, bodyPos, portrait, renderBody, bodyFacing);

            if (!portrait && pawn.RaceProps.Animal && pawn.inventory != null && pawn.inventory.innerContainer.Count > 0 &&
                graphics.packGraphic != null)
            {
                Mesh mesh = graphics.nakedGraphic.MeshAt(bodyFacing);
                Graphics.DrawMesh(mesh, bodyPos, quat, graphics.packGraphic.MatAt(bodyFacing), 0);
            }

            // No wobble for equipment, looks funnier - nah!
            // Vector3 equipPos = rootLoc;
            // equipPos.y = drawPos.y;

            //compAnim.DrawEquipment(drawPos, portrait);



            bool    showHands = Controller.settings.UseHands;
            Vector3 handPos   = bodyPos;

            if (renderBody || Controller.settings.IgnoreRenderBody)
            {
                if (showHands)
                {
                    // Reset the position for the hands
                    handPos.y = baseDrawLoc.y;
                    compAnim?.DrawHands(bodyQuat, handPos, portrait);
                }

                if (showFeet)
                {
                    compAnim.DrawFeet(bodyQuat, footQuat, footPos, portrait);
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
        public static Vector2 ForPawn(Pawn pawn)
        {
            if (pawn.RaceProps.Humanlike)
            {
                PawnRenderer   renderer   = pawn.Drawer.renderer;
                PawnGraphicSet graphicSet = renderer.graphics;

                if (!graphicSet.AllResolved)
                {
                    graphicSet.ResolveAllGraphics();
                }

                try
                {
                    if (pawn.IsDessicated() && graphicSet.dessicatedGraphic != null)
                    {
                        return(BoundMap(
                                   graphicSet.dessicatedGraphic,
                                   GraphicType.Pawn,
                                   graphicSet.desiccatedHeadGraphic,
                                   new Vector2(renderer.BaseHeadOffsetAt(Rot4.South).x,
                                               renderer.BaseHeadOffsetAt(Rot4.East).z)));
                    }

                    return(BoundMap(
                               graphicSet.nakedGraphic,
                               GraphicType.Pawn,
                               graphicSet.headGraphic,
                               new Vector2(renderer.BaseHeadOffsetAt(Rot4.South).x,
                                           renderer.BaseHeadOffsetAt(Rot4.East).z)));
                }
                catch (ArgumentException e) { throw new ArgumentException(pawn + ".graphics." + (pawn.IsDessicated() ? "dessicated/dessicatedHead" : "naked/head") + "Graphic", e); }
            }
            else
            {
                PawnKindLifeStage lifeStage = pawn.ageTracker.CurKindLifeStage;

                try
                {
                    if (pawn.IsDessicated() && lifeStage.dessicatedBodyGraphicData != null)
                    {
                        return(Vector2.Scale(BoundMap(lifeStage.dessicatedBodyGraphicData.Graphic, GraphicType.Pawn), lifeStage.dessicatedBodyGraphicData.drawSize));
                    }
                }
                catch (ArgumentException e) { throw new ArgumentException(pawn + ".lifeStage[" + pawn.ageTracker.CurLifeStageIndex + "].dessicatedBodyGraphicData", e); }

                try
                {
                    if (pawn.gender == Gender.Female && lifeStage.femaleGraphicData != null)
                    {
                        return(Vector2.Scale(BoundMap(lifeStage.femaleGraphicData.Graphic, GraphicType.Pawn), lifeStage.femaleGraphicData.drawSize));
                    }
                }
                catch (ArgumentException e) { throw new ArgumentException(pawn + ".lifeStage[" + pawn.ageTracker.CurLifeStageIndex + "].femaleGraphicData", e); }

                try { if (lifeStage.bodyGraphicData != null)
                      {
                          return(Vector2.Scale(BoundMap(lifeStage.bodyGraphicData.Graphic, GraphicType.Pawn), lifeStage.bodyGraphicData.drawSize));
                      }
                }
                catch (ArgumentException e) { throw new ArgumentException(pawn + ".lifeStage[" + pawn.ageTracker.CurLifeStageIndex + "].bodyGraphicData", e); }

                return(Vector2.zero);
            }
        }
Ejemplo n.º 4
0
        public static void DrawBackHairLayer(PawnRenderer __instance,
                                             ref Vector3 rootLoc,
                                             ref float angle,
                                             ref Rot4 headFacing,
                                             ref RotDrawMode bodyDrawType,
                                             ref bool portrait,
                                             ref bool headStump)
        {
            PawnGraphicSet graphics = __instance.graphics;

            if (!graphics.AllResolved)
            {
                graphics.ResolveAllGraphics();
            }
            Graphic_Multi_BHair hairGraphicExtended = graphics.hairGraphic as Graphic_Multi_BHair;

            //if has head and hair graphics
            if (graphics.headGraphic != null && hairGraphicExtended != null)
            {
                Material hairMat = hairGraphicExtended.BackMatAt(headFacing);

                if (hairMat != null)
                {
                    //-------------------------REPLICATED VANILLA CODE-------------------------
                    Quaternion quaternion = Quaternion.AngleAxis(angle, new Vector3(0f, 1f, 0f));
                    Vector3    b          = quaternion * __instance.BaseHeadOffsetAt(headFacing);
                    Vector3    loc2       = rootLoc + b;
                    //-------------------------REPLICATED VANILLA CODE-------------------------


                    //loc2.y -= 0.0303030312f;    //changed from original, used to be +=


                    bool hideHair = false;
                    if (!portrait || !Prefs.HatsOnlyOnMap)
                    {
                        List <ApparelGraphicRecord> apparelGraphics = graphics.apparelGraphics;
                        for (int j = 0; j < apparelGraphics.Count; j++)
                        {
                            if (apparelGraphics[j].sourceApparel.def.apparel.LastLayer == ApparelLayerDefOf.Overhead)
                            {
                                if (!apparelGraphics[j].sourceApparel.def.apparel.hatRenderedFrontOfFace)
                                {
                                    if (HarmonyPatches_BHair.loadedShowHair)
                                    {
                                        hideHair = Compat_ShowHair.SHCompat_ShouldHideHair(graphics.pawn, apparelGraphics[j].sourceApparel.def, portrait);
                                    }
                                    else if (HarmonyPatches_BHair.loadedHatDisplaySelection)
                                    {
                                        hideHair = Compat_HatDisplaySelection.HDCompat_ShouldHideHair(graphics.pawn, apparelGraphics[j].sourceApparel.def.defName);
                                    }
                                    else
                                    {
                                        hideHair = true;
                                    }
                                }
                            }
                        }
                    }

                    if (!hideHair && bodyDrawType != RotDrawMode.Dessicated && !headStump)
                    {
                        if (graphics.pawn.IsInvisible())
                        {
                            hairMat = InvisibilityMatPool.GetInvisibleMat(hairMat);
                        }
                        Material resultMat = graphics.flasher.GetDamagedMat(hairMat);

                        Mesh hairMesh = null;
                        if (HarmonyPatches_BHair.loadedAlienRace)
                        {
                            //use modified hair mesh after processed by Alien Race/Babies And Children
                            hairMesh = Patch_AlienRace.ARCompat_GetCopiedMesh();
                        }

                        if (HarmonyPatches_BHair.loadedRimWorldChildren)
                        {
                            //use modified hair mesh after processed by RimWorldChildren
                            hairMesh  = Patch_RimWorldChildren.RCCompat_GetCopiedMesh();
                            resultMat = Patch_RimWorldChildren.RCCompat_ModifyHairForChild(resultMat, graphics.pawn);

                            //alternate calling method for manual calling
                            //hairMesh = Compat_RimWorldChildren.RCCompat_GetModifiedPawnHairMesh(graphics, graphics.pawn, headFacing);
                        }

                        if (hairMesh == null)
                        {
                            //default
                            hairMesh = graphics.HairMeshSet.MeshAt(headFacing);
                        }

                        GenDraw.DrawMeshNowOrLater(mesh: hairMesh, mat: resultMat, loc: loc2, quat: quaternion, drawNow: portrait);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public virtual void DrawInnerThing(Pawn pawn, Vector3 rootLoc, float angle, bool renderBody, Rot4 bodyFacing, Rot4 headFacing, RotDrawMode bodyDrawType, bool portrait, bool headStump)
        {
            PawnGraphicSet graphics = pawn.Drawer.renderer.graphics;
            PawnRenderer   renderer = pawn.Drawer.renderer;

            if (!graphics.AllResolved)
            {
                graphics.ResolveAllGraphics();
            }
            Quaternion quaternion = Quaternion.AngleAxis(angle, Vector3.up);
            Mesh       mesh       = null;

            if (renderBody)
            {
                Vector3 loc = rootLoc;
                loc.y += 0.0078125f;
                if (bodyDrawType == RotDrawMode.Dessicated && !pawn.RaceProps.Humanlike && graphics.dessicatedGraphic != null && !portrait)
                {
                    graphics.dessicatedGraphic.Draw(loc, bodyFacing, pawn, angle);
                }
                else
                {
                    if (pawn.RaceProps.Humanlike)
                    {
                        mesh = MeshPool.humanlikeBodySet.MeshAt(bodyFacing);
                    }
                    else
                    {
                        mesh = graphics.nakedGraphic.MeshAt(bodyFacing);
                    }
                    List <Material> list = graphics.MatsBodyBaseAt(bodyFacing, bodyDrawType);
                    for (int i = 0; i < list.Count; i++)
                    {
                        Material damagedMat = graphics.flasher.GetDamagedMat(list[i]);
                        GenDraw.DrawMeshNowOrLater(mesh, loc, quaternion, damagedMat, portrait);
                        loc.y += 0.00390625f;
                    }
                }
            }
            Vector3 vector = rootLoc;
            Vector3 a      = rootLoc;

            if (bodyFacing != Rot4.North)
            {
                a.y      += 0.02734375f;
                vector.y += 0.0234375f;
            }
            else
            {
                a.y      += 0.0234375f;
                vector.y += 0.02734375f;
            }
            if (graphics.headGraphic != null)
            {
                Vector3  b        = quaternion * renderer.BaseHeadOffsetAt(headFacing);
                Material material = graphics.HeadMatAt(headFacing, bodyDrawType, headStump);
                if (material != null)
                {
                    Mesh mesh2 = MeshPool.humanlikeHeadSet.MeshAt(headFacing);
                    GenDraw.DrawMeshNowOrLater(mesh2, a + b, quaternion, material, portrait);
                }
                Vector3 loc2 = rootLoc + b;
                loc2.y += 0.03125f;
                bool flag = false;
                if (!portrait || !Prefs.HatsOnlyOnMap)
                {
                    Mesh mesh3 = graphics.HairMeshSet.MeshAt(headFacing);
                    List <ApparelGraphicRecord> apparelGraphics = graphics.apparelGraphics;
                    for (int j = 0; j < apparelGraphics.Count; j++)
                    {
                        if (apparelGraphics[j].sourceApparel.def.apparel.LastLayer == ApparelLayerDefOf.Overhead)
                        {
                            if (!apparelGraphics[j].sourceApparel.def.apparel.hatRenderedFrontOfFace)
                            {
                                flag = true;
                                Material material2 = apparelGraphics[j].graphic.MatAt(bodyFacing, null);
                                material2 = graphics.flasher.GetDamagedMat(material2);
                                GenDraw.DrawMeshNowOrLater(mesh3, loc2, quaternion, material2, portrait);
                            }
                            else
                            {
                                Material material3 = apparelGraphics[j].graphic.MatAt(bodyFacing, null);
                                material3 = graphics.flasher.GetDamagedMat(material3);
                                Vector3 loc3 = rootLoc + b;
                                loc3.y += ((!(bodyFacing == Rot4.North)) ? 0.03515625f : 0.00390625f);
                                GenDraw.DrawMeshNowOrLater(mesh3, loc3, quaternion, material3, portrait);
                            }
                        }
                    }
                }
                if (!flag && bodyDrawType != RotDrawMode.Dessicated && !headStump)
                {
                    Mesh     mesh4 = graphics.HairMeshSet.MeshAt(headFacing);
                    Material mat   = graphics.HairMatAt(headFacing);
                    GenDraw.DrawMeshNowOrLater(mesh4, loc2, quaternion, mat, portrait);
                }
            }
            if (renderBody)
            {
                for (int k = 0; k < graphics.apparelGraphics.Count; k++)
                {
                    ApparelGraphicRecord apparelGraphicRecord = graphics.apparelGraphics[k];
                    if (apparelGraphicRecord.sourceApparel.def.apparel.LastLayer == ApparelLayerDefOf.Shell)
                    {
                        Material material4 = apparelGraphicRecord.graphic.MatAt(bodyFacing, null);
                        material4 = graphics.flasher.GetDamagedMat(material4);
                        GenDraw.DrawMeshNowOrLater(mesh, vector, quaternion, material4, portrait);
                    }
                }
            }
            if (!portrait && pawn.RaceProps.Animal && pawn.inventory != null && pawn.inventory.innerContainer.Count > 0 && graphics.packGraphic != null)
            {
                Graphics.DrawMesh(mesh, vector, quaternion, graphics.packGraphic.MatAt(bodyFacing, null), 0);
            }
            if (!portrait)
            {
                if (pawn.apparel != null)
                {
                    List <Apparel> wornApparel = pawn.apparel.WornApparel;
                    for (int l = 0; l < wornApparel.Count; l++)
                    {
                        wornApparel[l].DrawWornExtras();
                    }
                }
                Vector3 bodyLoc = rootLoc;
                bodyLoc.y += 0.04296875f;
            }
        }
        protected void RenderSlot(TrackedColonist slot, Vector2 position)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            Rot4           south    = Rot4.South;
            Pawn           pawn     = slot.Pawn;
            PawnGraphicSet graphics = pawn.drawer.renderer.graphics;

            if (!graphics.AllResolved)
            {
                graphics.ResolveAllGraphics();
            }
            bool       flag        = slot.Dead || slot.Missing;
            bool       cryptosleep = slot.Cryptosleep;
            Quaternion identity    = Quaternion.identity;
            Vector3    one         = Vector3.one;

            Graphics.DrawMesh(this.backgroundMesh, Matrix4x4.TRS(new Vector3(position.x + ColonistBarDrawer.BackgroundOffset.x, position.y + ColonistBarDrawer.BackgroundOffset.y, 0f), identity, one), ColonistBarDrawer.SlotBackgroundMat, 1, this.camera, 0, null);
            MaterialPropertyBlock properties = null;

            if (flag)
            {
                properties = this.deadPropertyBlock;
            }
            else if (slot.Cryptosleep)
            {
                properties = this.cryptosleepPropertyBlock;
            }
            float    num = 1f;
            Material material;

            foreach (Material current in graphics.MatsBodyBaseAt(south, RotDrawMode.Fresh))
            {
                material = current;
                if (flag)
                {
                    material = this.GetDeadMaterial(current);
                }
                else if (cryptosleep)
                {
                    material = this.GetFrozenMaterial(current);
                }
                Graphics.DrawMesh(this.bodyMesh, Matrix4x4.TRS(new Vector3(position.x + ColonistBarDrawer.PortraitOffset.x, position.y + ColonistBarDrawer.PortraitOffset.y, num), identity, one), material, 1, this.camera, 0, properties);
                num += 1f;
            }
            Material material2;

            for (int i = 0; i < graphics.apparelGraphics.Count; i++)
            {
                ApparelGraphicRecord apparelGraphicRecord = graphics.apparelGraphics[i];
                if (apparelGraphicRecord.sourceApparel.def.apparel.LastLayer == ApparelLayer.Shell)
                {
                    material2 = apparelGraphicRecord.graphic.MatAt(south, null);
                    material2 = graphics.flasher.GetDamagedMat(material2);
                    material  = material2;
                    if (flag)
                    {
                        material = this.GetDeadMaterial(material2);
                    }
                    else if (cryptosleep)
                    {
                        material = this.GetFrozenMaterial(material2);
                    }
                    Graphics.DrawMesh(this.bodyMesh, Matrix4x4.TRS(new Vector3(position.x + ColonistBarDrawer.PortraitOffset.x, position.y + ColonistBarDrawer.PortraitOffset.y, num), identity, one), material, 1, this.camera, 0, properties);
                    num += 1f;
                }
            }
            Graphics.DrawMesh(this.backgroundMesh, Matrix4x4.TRS(new Vector3(position.x + ColonistBarDrawer.BackgroundOffset.x, position.y + ColonistBarDrawer.BackgroundOffset.y, num), identity, one), ColonistBarDrawer.SlotBordersMat, 1, this.camera);
            num += 1f;
            if ((slot.Corpse != null) ? Find.Selector.IsSelected(slot.Corpse) : Find.Selector.IsSelected(pawn))
            {
                Graphics.DrawMesh(this.backgroundMesh, Matrix4x4.TRS(new Vector3(position.x + ColonistBarDrawer.BackgroundOffset.x, position.y + ColonistBarDrawer.BackgroundOffset.y, num), identity, one), ColonistBarDrawer.SlotSelectedMat, 1, this.camera);
                num += 1f;
            }
            material2 = pawn.drawer.renderer.graphics.HeadMatAt(south, RotDrawMode.Fresh);
            material  = material2;
            if (flag)
            {
                material = this.GetDeadMaterial(material2);
            }
            else if (cryptosleep)
            {
                material = this.GetFrozenMaterial(material2);
            }
            Graphics.DrawMesh(this.headMesh, Matrix4x4.TRS(new Vector3(position.x + ColonistBarDrawer.HeadOffset.x, position.y + ColonistBarDrawer.HeadOffset.y, num), identity, one), material, 1, this.camera, 0, properties);
            num += 1f;
            bool flag2 = false;
            List <ApparelGraphicRecord> apparelGraphics = graphics.apparelGraphics;

            for (int j = 0; j < apparelGraphics.Count; j++)
            {
                if (apparelGraphics[j].sourceApparel.def.apparel.LastLayer == ApparelLayer.Overhead)
                {
                    flag2     = true;
                    material2 = apparelGraphics[j].graphic.MatAt(south, null);
                    material2 = graphics.flasher.GetDamagedMat(material2);
                    material  = material2;
                    if (flag)
                    {
                        material = this.GetDeadMaterial(material2);
                    }
                    else if (cryptosleep)
                    {
                        material = this.GetFrozenMaterial(material2);
                    }
                    Graphics.DrawMesh(this.headMesh, Matrix4x4.TRS(new Vector3(position.x + ColonistBarDrawer.HeadOffset.x, position.y + ColonistBarDrawer.HeadOffset.y, num), identity, one), material, 1, this.camera, 0, properties);
                    num += 1f;
                }
            }
            if (!flag2 && slot.Pawn.story.hairDef != null)
            {
                material2 = graphics.HairMatAt(south);
                material  = material2;
                if (flag)
                {
                    material = this.GetDeadMaterial(material2);
                }
                else if (cryptosleep)
                {
                    material = this.GetFrozenMaterial(material2);
                }
                Graphics.DrawMesh(this.headMesh, Matrix4x4.TRS(new Vector3(position.x + ColonistBarDrawer.HeadOffset.x, position.y + ColonistBarDrawer.HeadOffset.y, num), identity, one), material, 1, this.camera, 0, properties);
                num += 1f;
            }
        }
        public static void FSCompat_DrawBackHairLayer(object __instance,
                                                      ref Vector3 hairLoc,
                                                      RotDrawMode bodyDrawType,
                                                      Quaternion headQuat,
                                                      ref bool renderBody,
                                                      ref bool portrait)
        //FacialStuff.HumanHeadDrawer __instance
        {
            Type t_HumanHeadDrawer = GenTypes.GetTypeInAnyAssembly("FacialStuff.HumanHeadDrawer");

            try
            {
                if (t_HumanHeadDrawer != null)
                {
                    FacialStuff.HumanHeadDrawer this_HumanHeadDrawer = (FacialStuff.HumanHeadDrawer)__instance;
                    //-------------------------REPLICATED FACIAL STUFF CODE-------------------------
                    PawnGraphicSet curGraphics = Traverse.Create(this_HumanHeadDrawer).Field("Graphics").GetValue <PawnGraphicSet>();
                    if (!curGraphics.AllResolved)
                    {
                        curGraphics.ResolveAllGraphics();
                    }

                    Graphic_Multi_BHair hairGraphicExtended = curGraphics.hairGraphic as Graphic_Multi_BHair;
                    if (hairGraphicExtended != null)
                    {
                        Mesh     hairMesh      = this_HumanHeadDrawer.GetPawnHairMesh(portrait);
                        Rot4     curHeadFacing = Traverse.Create(this_HumanHeadDrawer).Field("HeadFacing").GetValue <Rot4>();
                        Material hairMat       = hairGraphicExtended.BackMatAt(curHeadFacing);

                        if (hairMat != null)
                        {
                            List <ApparelGraphicRecord> apparelGraphics  = curGraphics.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();
                            }

                            FacialStuff.CompBodyAnimator animator = this_HumanHeadDrawer.CompAnimator;

                            bool noRenderGoggles = FacialStuff.Controller.settings.FilterHats;

                            bool showRoyalHeadgear = this_HumanHeadDrawer.Pawn.royalty?.MostSeniorTitle != null && FacialStuff.Controller.settings.ShowRoyalHeadgear;
                            bool noRenderRoofed    = animator != null && animator.HideHat && !showRoyalHeadgear;
                            bool noRenderBed       = FacialStuff.Controller.settings.HideHatInBed && !renderBody && !showRoyalHeadgear;
                            //-------------------------REPLICATED FACIAL STUFF CODE-------------------------



                            hairLoc.y        = tempBaseDrawLocY;
                            tempBaseDrawLocY = 0;



                            if (!headgearGraphics.NullOrEmpty())
                            {
                                //-------------------------REPLICATED FACIAL STUFF CODE-------------------------
                                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);
                                    //-------------------------REPLICATED FACIAL STUFF CODE-------------------------

                                    if (this_HumanHeadDrawer.CompFace.Props.hasOrganicHair || noRenderBed || filterHeadgear ||
                                        (!apCoversFullHead && !apCoversUpperHead && noRenderGoggles))
                                    {
                                        GenDraw.DrawMeshNowOrLater(hairMesh, hairLoc, headQuat, hairMat, portrait);
                                    }

                                    /*
                                     * else if (FacialStuff.Controller.settings.MergeHair) // && !apCoversFullHead)
                                     * {
                                     *  // If not, display the hair cut
                                     *  FacialStuff.HairCut.HairCutPawn hairPawn = FacialStuff.HairCut.CutHairDB.GetHairCache(this_HumanHeadDrawer.Pawn);
                                     *  Material hairCutMat = hairPawn.HairCutMatAt(curHeadFacing);
                                     *  if (hairCutMat != null)
                                     *  {
                                     *      GenDraw.DrawMeshNowOrLater(hairMesh, hairLoc, headQuat, hairCutMat, portrait);
                                     *  }
                                     * }
                                     */
                                }
                            }
                            else
                            {
                                // Draw regular hair if no hat worn
                                if (bodyDrawType != RotDrawMode.Dessicated)
                                {
                                    GenDraw.DrawMeshNowOrLater(hairMesh, hairLoc, headQuat, hairMat, portrait);
                                }
                            }
                        }
                    }
                }
            }
            catch (TypeLoadException) { }
        }