Exemple #1
0
        public static void __RenderPawnInternalPostFix(PawnRenderer __instance, Vector3 rootLoc, Quaternion quat, bool renderBody, Rot4 bodyFacing, Rot4 headFacing, RotDrawMode bodyDrawType = 0, bool portrait = false)
        {
            Pawn    pawn   = Traverse.Create(__instance).Field("pawn").GetValue <Pawn>();
            Vector3 vector = rootLoc;

            Corruption.CompPsyker         compPsyker     = pawn.TryGetComp <CompPsyker>();
            List <HediffComp_DrawImplant> implantDrawers = HarmonyPatches.implantDrawers(pawn);
            string patronName = "Emperor";
            bool   drawChaos  = false;

            if (compPsyker != null)
            {
                patronName = compPsyker.patronName;
                //        Log.Message("GettingComp: " + patronName);
                if (patronName == "Khorne" || patronName == "Nurgle" || patronName == "Tzeentch" || patronName == "Undivided")
                {
                    //            Log.Message("drawChaos");
                    drawChaos = true;
                }
            }
        }
Exemple #2
0
        private static void RenderPawnInternal(PawnRenderer __instance, Vector3 rootLoc, Quaternion quat, bool renderBody, Rot4 bodyFacing, Rot4 headFacing, RotDrawMode bodyDrawType = RotDrawMode.Fresh, bool portrait = false)
        {
            Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue <Pawn>();

            if (!pawn.def.race.Humanlike)
            {
                return;
            }

            Corruption.CompPsyker         compPsyker     = pawn.TryGetComp <CompPsyker>();
            List <HediffComp_DrawImplant> implantDrawers = HarmonyPatches.implantDrawers(pawn);
            string patronName = "Emperor";
            bool   drawChaos  = false;

            if (compPsyker != null)
            {
                patronName = compPsyker.patronName;
                //        Log.Message("GettingComp: " + patronName);
                if (patronName == "Khorne" || patronName == "Nurgle" || patronName == "Tzeentch" || patronName == "Undivided")
                {
                    //            Log.Message("drawChaos");
                    drawChaos = true;
                }
            }

            if (!__instance.graphics.AllResolved)
            {
                __instance.graphics.ResolveAllGraphics();
            }
            Mesh mesh = null;

            if (renderBody)
            {
                Vector3 loc = rootLoc;
                loc.y += 0.005f;
                if (bodyDrawType == RotDrawMode.Dessicated && !pawn.RaceProps.Humanlike && __instance.graphics.dessicatedGraphic != null && !portrait)
                {
                    __instance.graphics.dessicatedGraphic.Draw(loc, bodyFacing, pawn);
                }
                else
                {
                    ThingDef_AlienRace alienDef = pawn.def as ThingDef_AlienRace;
                    if (alienDef != null)
                    {
                        Mesh mesh2;
                        if (bodyDrawType == RotDrawMode.Rotting)
                        {
                            if (__instance.graphics.dessicatedGraphic.ShouldDrawRotated)
                            {
                                mesh2 = MeshPool.GridPlane(portrait ? alienDef.alienRace.generalSettings.alienPartGenerator.CustomPortraitDrawSize : alienDef.alienRace.generalSettings.alienPartGenerator.CustomDrawSize);
                            }
                            else
                            {
                                Vector2 size = portrait ? alienDef.alienRace.generalSettings.alienPartGenerator.CustomPortraitDrawSize : alienDef.alienRace.generalSettings.alienPartGenerator.CustomDrawSize;
                                if (bodyFacing.IsHorizontal)
                                {
                                    size = size.Rotated();
                                }
                                if (bodyFacing == Rot4.West && (__instance.graphics.dessicatedGraphic.data == null || __instance.graphics.dessicatedGraphic.data.allowFlip))
                                {
                                    mesh = MeshPool.GridPlaneFlip(size);
                                }
                                mesh = MeshPool.GridPlane(size);
                            }
                        }
                        else
                        {
                            mesh = (portrait ? alienDef.alienRace.generalSettings.alienPartGenerator.bodyPortraitSet.MeshAt(bodyFacing) : alienDef.alienRace.generalSettings.alienPartGenerator.bodySet.MeshAt(bodyFacing));
                        }
                    }
                    else
                    {
                        if (pawn.RaceProps.Humanlike)
                        {
                            mesh = MeshPool.humanlikeBodySet.MeshAt(bodyFacing);
                        }
                        else
                        {
                            mesh = __instance.graphics.nakedGraphic.MeshAt(bodyFacing);
                        }
                    }
                    List <Material> list = __instance.graphics.MatsBodyBaseAt(bodyFacing, bodyDrawType);
                    for (int i = 0; i < list.Count; i++)
                    {
                        //               Material damagedMat = __instance.graphics.flasher.GetDamagedMat(list[i]);
                        //               GenDraw.DrawMeshNowOrLater(mesh, loc, quat, damagedMat, portrait);
                        loc.y += 0.005f;
                        if (i == 0)
                        {
                            if (drawChaos)
                            {
                                Material markMat = (Corruption.AfflictionDrawerUtility.GetBodyOverlay(pawn.story.bodyType, patronName).MatAt(bodyFacing));
                                if (pawn.ageTracker.CurLifeStageIndex == 2 && pawn.RaceProps.Humanlike)
                                {
                                    markMat.mainTextureScale  = new Vector2(1, 1.3f);
                                    markMat.mainTextureOffset = new Vector2(0, -0.2f);
                                    if (bodyFacing == Rot4.West || bodyFacing == Rot4.East)
                                    {
                                        markMat.mainTextureOffset = new Vector2(-0.015f, -0.2f);
                                    }
                                }
                                GenDraw.DrawMeshNowOrLater(mesh, loc, quat, markMat, portrait);
                                loc.y += 0.005f;
                            }
                        }

                        if (bodyDrawType == RotDrawMode.Fresh)
                        {
                            Vector3 drawLoc = rootLoc;
                            drawLoc.y += 0.02f;
                            //                    Traverse.Create(__instance).Field("woundOverlays").GetValue<PawnWoundDrawer>().RenderOverBody(drawLoc, mesh, quat, portrait);
                        }
                    }
                }
                Vector3 vector = rootLoc;
                Vector3 a      = rootLoc;
                if (bodyFacing != Rot4.North)
                {
                    a.y      += 0.03f;
                    vector.y += 0.0249999985f;
                }
                else
                {
                    a.y      += 0.0249999985f;
                    vector.y += 0.03f;
                }
                if (__instance.graphics.headGraphic != null)
                {
                    Vector3  b     = quat * __instance.BaseHeadOffsetAt(headFacing);
                    Mesh     mesh2 = MeshPool.humanlikeHeadSet.MeshAt(headFacing);
                    Material mat   = __instance.graphics.HeadMatAt(headFacing, bodyDrawType);
                    //            GenDraw.DrawMeshNowOrLater(mesh2, a + b, quat, mat, portrait);
                    if (drawChaos)
                    {
                        Material headMarkMat = (AfflictionDrawerUtility.GetHeadGraphic(pawn, patronName).MatAt(bodyFacing));
                        //   vector.y += 0.005f;
                        GenDraw.DrawMeshNowOrLater(mesh2, a + b + new Vector3(0f, 0.004f, 0f), quat, headMarkMat, portrait);
                    }

                    Vector3 loc2 = rootLoc + b;
                    loc2.y += 0.035f;
                    bool flag  = false;
                    Mesh mesh3 = __instance.graphics.HairMeshSet.MeshAt(headFacing);
                    List <ApparelGraphicRecord> apparelGraphics = __instance.graphics.apparelGraphics;
                    for (int j = 0; j < apparelGraphics.Count; j++)
                    {
                        if (apparelGraphics[j].sourceApparel.def.apparel.LastLayer == ApparelLayer.Overhead)
                        {
                            flag = true;
                            Material material = apparelGraphics[j].graphic.MatAt(bodyFacing, null);
                            material = __instance.graphics.flasher.GetDamagedMat(material);
                            //               GenDraw.DrawMeshNowOrLater(mesh3, loc2, quat, material, portrait);
                        }

                        if (!flag && bodyDrawType != RotDrawMode.Dessicated)
                        {
                            Mesh     mesh4 = __instance.graphics.HairMeshSet.MeshAt(headFacing);
                            Material mat2  = __instance.graphics.HairMatAt(headFacing);
                            //                   GenDraw.DrawMeshNowOrLater(mesh4, loc2, quat, mat2, portrait);
                        }
                    }
                    if (renderBody)
                    {
                        for (int k = 0; k < __instance.graphics.apparelGraphics.Count; k++)
                        {
                            Material pauldronMat;
                            if (CompPauldronDrawer.ShouldDrawPauldron(pawn, __instance.graphics.apparelGraphics[k].sourceApparel, bodyFacing, out pauldronMat))
                            {
                                if (pawn.ageTracker.CurLifeStageIndex == 2)
                                {
                                    pauldronMat.mainTextureScale  = new Vector2(1.00f, 1.22f);
                                    pauldronMat.mainTextureOffset = new Vector2(0, -0.1f);
                                }
                                vector.y += 0.035f;
                                GenDraw.DrawMeshNowOrLater(mesh, vector, quat, pauldronMat, portrait);
                            }
                            ApparelGraphicRecord apparelGraphicRecord = __instance.graphics.apparelGraphics[k];
                            if (apparelGraphicRecord.sourceApparel.def.apparel.LastLayer == ApparelLayer.Shell)
                            {
                                //           Material material2 = apparelGraphicRecord.graphic.MatAt(bodyFacing, null);
                                //           material2 = __instance.graphics.flasher.GetDamagedMat(material2);
                                //           GenDraw.DrawMeshNowOrLater(mesh, vector, quat, material2, portrait);
                            }
                            if (!pawn.Dead)
                            {
                                for (int l = 0; l < pawn.health.hediffSet.hediffs.Count; l++)
                                {
                                    HediffComp_DrawImplant drawer;
                                    if ((drawer = pawn.health.hediffSet.hediffs[l].TryGetComp <HediffComp_DrawImplant>()) != null)
                                    {
                                        if (drawer.implantDrawProps.implantDrawerType != ImplantDrawerType.Head)
                                        {
                                            vector.y += 0.005f;
                                            if (bodyFacing == Rot4.South && drawer.implantDrawProps.implantDrawerType == ImplantDrawerType.Backpack)
                                            {
                                                vector.y -= 0.3f;
                                            }
                                            Material implantMat = drawer.ImplantMaterial(pawn, bodyFacing);
                                            GenDraw.DrawMeshNowOrLater(mesh, vector, quat, implantMat, portrait);
                                            vector.y += 0.005f;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        public static bool _RenderPawnInternal(PawnRenderer __instance, Vector3 rootLoc, Quaternion quat, bool renderBody, Rot4 bodyFacing, Rot4 headFacing, RotDrawMode bodyDrawType = 0, bool portrait = false)
        {
            Log.Message("Calling");
            PawnRenderer renderer = __instance;

            if (!renderer.graphics.AllResolved)
            {
                renderer.graphics.ResolveAllGraphics();
            }
            Mesh mesh = null;
            Pawn pawn = (Pawn)HarmonyPatches.pawnInfo.GetValue(renderer);

            if (pawn is AlienPawn && (pawn as AlienPawn).bodySet == null)
            {
                (pawn as AlienPawn).UpdateSets();
            }

            Corruption.CompPsyker         compPsyker     = pawn.TryGetComp <CompPsyker>();
            List <HediffComp_DrawImplant> implantDrawers = HarmonyPatches.implantDrawers(pawn);
            string patronName = "Emperor";
            bool   drawChaos  = false;

            if (compPsyker != null)
            {
                patronName = compPsyker.patronName;
                //        Log.Message("GettingComp: " + patronName);
                if (patronName == "Khorne" || patronName == "Nurgle" || patronName == "Tzeentch" || patronName == "Undivided")
                {
                    //            Log.Message("drawChaos");
                    drawChaos = true;
                }
            }

            if (renderBody || (pawn.InBed() && pawn.ageTracker.CurLifeStageIndex <= 1))
            {
                if (pawn.RaceProps.Humanlike)
                {
                    if (pawn.ageTracker.CurLifeStageIndex == 2)
                    {
                        rootLoc.z -= 0.15f;
                    }
                    if (pawn.ageTracker.CurLifeStageIndex < 2 && pawn.InBed() && !portrait)
                    {
                        // Undo the offset for babies/toddlers in bed
                        Building_Bed building_bed = pawn.CurrentBed();
                        Vector3      offset       = new Vector3(0, 0, 0.5f).RotatedBy(building_bed.Rotation.AsAngle);
                        rootLoc -= offset;
                    }
                }
                Vector3 vector = rootLoc;
                vector.y += 0.005f;

                if (bodyDrawType == RotDrawMode.Dessicated && !pawn.RaceProps.Humanlike && renderer.graphics.dessicatedGraphic != null && !portrait)
                {
                    renderer.graphics.dessicatedGraphic.Draw(vector, bodyFacing, pawn);
                }
                else
                {
                    bool humanlike = pawn.RaceProps.Humanlike;
                    if (humanlike)
                    {
                        mesh = ((pawn is AlienPawn) ? (pawn as AlienPawn).bodySet : MeshPool.humanlikeBodySet).MeshAt(bodyFacing);
                    }
                    else
                    {
                        mesh = renderer.graphics.nakedGraphic.MeshAt(bodyFacing);
                    }

                    List <Material> list = renderer.graphics.MatsBodyBaseAt(bodyFacing, bodyDrawType);
                    for (int i = 0; i < list.Count; i++)
                    {
                        Material damagedMat = renderer.graphics.flasher.GetDamagedMat(list[i]);
                        if (pawn.ageTracker.CurLifeStageIndex == 2 && pawn.RaceProps.Humanlike)
                        {
                            damagedMat.mainTextureScale  = new Vector2(1, 1.3f);
                            damagedMat.mainTextureOffset = new Vector2(0, -0.2f);
                            if (bodyFacing == Rot4.West || bodyFacing == Rot4.East)
                            {
                                damagedMat.mainTextureOffset = new Vector2(-0.015f, -0.2f);
                            }
                        }

                        GenDraw.DrawMeshNowOrLater(mesh, vector, quat, damagedMat, portrait);
                        vector.y += 0.003f;
                        if (i == 0)
                        {
                            if (drawChaos)
                            {
                                Material markMat = (Corruption.AfflictionDrawerUtility.GetBodyOverlay(pawn.story.bodyType, patronName).MatAt(bodyFacing));
                                if (pawn.ageTracker.CurLifeStageIndex == 2 && pawn.RaceProps.Humanlike)
                                {
                                    markMat.mainTextureScale  = new Vector2(1, 1.3f);
                                    markMat.mainTextureOffset = new Vector2(0, -0.2f);
                                    if (bodyFacing == Rot4.West || bodyFacing == Rot4.East)
                                    {
                                        markMat.mainTextureOffset = new Vector2(-0.015f, -0.2f);
                                    }
                                }
                                GenDraw.DrawMeshNowOrLater(mesh, vector, quat, markMat, portrait);
                                vector.y += 0.003f;
                            }
                        }
                    }

                    if (bodyDrawType == 0)
                    {
                        Vector3 vector2 = rootLoc;
                        vector2.y += 0.02f;
                        ((PawnWoundDrawer)HarmonyPatches.woundInfo.GetValue(renderer)).RenderOverBody(vector2, mesh, quat, portrait);
                    }
                }
            }
            Vector3 vector3 = rootLoc;
            Vector3 vector4 = rootLoc;

            if (bodyFacing != Rot4.North)
            {
                vector4.y += 0.03f;
                vector3.y += 0.0249999985f;
            }
            else
            {
                vector4.y += 0.0249999985f;
                vector3.y += 0.03f;
            }

            if (renderer.graphics.headGraphic != null && pawn.ageTracker.CurLifeStageIndex >= 1)
            {
                Vector3  vector5  = quat * renderer.BaseHeadOffsetAt(headFacing);
                Mesh     mesh2    = ((pawn is AlienPawn) ? (pawn as AlienPawn).headSet : MeshPool.humanlikeHeadSet).MeshAt(headFacing);
                Material material = renderer.graphics.HeadMatAt(headFacing, bodyDrawType);
                GenDraw.DrawMeshNowOrLater(mesh2, vector4 + vector5, quat, material, portrait);

                if (drawChaos)
                {
                    Material headMarkMat = (AfflictionDrawerUtility.GetHeadGraphic(pawn, patronName).MatAt(bodyFacing));
                    vector5.y += 0.005f;
                    GenDraw.DrawMeshNowOrLater(mesh2, vector4 + vector5, quat, headMarkMat, portrait);
                }

                Vector3 vector6 = rootLoc + vector5;
                vector6.y += 0.035f;
                bool flag7 = false;
                if (pawn.ageTracker.CurLifeStageIndex >= 2)
                {
                    Mesh mesh3 = HarmonyPatches.HairMeshSet(pawn).MeshAt(headFacing);
                    List <ApparelGraphicRecord> apparelGraphics = renderer.graphics.apparelGraphics;
                    for (int j = 0; j < apparelGraphics.Count; j++)
                    {
                        if (apparelGraphics[j].sourceApparel.def.apparel.LastLayer == ApparelLayer.Overhead)
                        {
                            if ((!pawn.story.hairDef.hairTags.Contains("DrawUnderHat") && !pawn.story.hairDef.hairTags.Contains("Beard")) || pawn.apparel.BodyPartGroupIsCovered(BodyPartGroupDefOf.FullHead))
                            {
                                flag7 = true; // flag=true stops the hair from being drawn
                            }
                            Material material2 = apparelGraphics[j].graphic.MatAt(bodyFacing, null);
                            material2 = renderer.graphics.flasher.GetDamagedMat(material2);
                            if (pawn.ageTracker.CurLifeStageIndex == 2)
                            {
                                material2.mainTextureOffset    = new Vector2(0, 0.018f);
                                material2.mainTexture.wrapMode = TextureWrapMode.Clamp;
                            }
                            GenDraw.DrawMeshNowOrLater(mesh3, vector6, quat, material2, portrait);
                            Material detailMat;
                            if (ApparelDetailDrawer.GetDetailGraphic(pawn, apparelGraphics[j].sourceApparel, bodyFacing, out detailMat))
                            {
                                Vector3 vectorDet = vector6;
                                vectorDet.y += 0.005f;
                                GenDraw.DrawMeshNowOrLater(mesh3, vectorDet, quat, detailMat, portrait);
                            }
                        }
                    }
                }

                if (!flag7 && bodyDrawType != RotDrawMode.Dessicated)
                {
                    Mesh     mesh4     = HarmonyPatches.HairMeshSet(pawn).MeshAt(headFacing);
                    Material material3 = renderer.graphics.HairMatAt(headFacing);
                    // Hopefully stops graphic issues from modifying texture offset/scale
                    material3.mainTexture.wrapMode = TextureWrapMode.Clamp;

                    // Scale down the child hair to fit the head
                    if (pawn.ageTracker.CurLifeStageIndex <= 2)
                    {
                        material3.mainTextureScale  = new Vector2(1.13f, 1.13f);
                        material3.mainTextureOffset = new Vector2(-0.065f, -0.045f);
                    }
                    // Scale down the toddler hair to fit the head
                    if (pawn.ageTracker.CurLifeStageIndex == 1)
                    {
                        //	mat2.mainTextureScale = new Vector2 (1.25f, 1.25f);
                        material3.mainTextureOffset = new Vector2(-0.07f, 0.12f);
                    }
                    GenDraw.DrawMeshNowOrLater(mesh4, vector6, quat, material3, portrait);
                }
            }

            if (renderBody)
            {
                for (int k = 0; k < renderer.graphics.apparelGraphics.Count; k++)
                {
                    ApparelGraphicRecord apparelGraphicRecord = renderer.graphics.apparelGraphics[k];
                    if (apparelGraphicRecord.sourceApparel.def.apparel.LastLayer == ApparelLayer.Shell)
                    {
                        Material material4 = apparelGraphicRecord.graphic.MatAt(bodyFacing, null);
                        material4 = renderer.graphics.flasher.GetDamagedMat(material4);
                        if (pawn.ageTracker.CurLifeStageIndex == 2)
                        {
                            material4.mainTextureScale  = new Vector2(1.00f, 1.22f);
                            material4.mainTextureOffset = new Vector2(0, -0.1f);
                        }

                        GenDraw.DrawMeshNowOrLater(mesh, vector3, quat, material4, portrait);
                    }
                    Material pauldronMat;
                    if (CompPauldronDrawer.ShouldDrawPauldron(pawn, renderer.graphics.apparelGraphics[k].sourceApparel, bodyFacing, out pauldronMat))
                    {
                        if (pawn.ageTracker.CurLifeStageIndex == 2)
                        {
                            pauldronMat.mainTextureScale  = new Vector2(1.00f, 1.22f);
                            pauldronMat.mainTextureOffset = new Vector2(0, -0.1f);
                        }
                        vector3.y += 0.005f;
                        GenDraw.DrawMeshNowOrLater(mesh, vector3, quat, pauldronMat, portrait);
                    }
                }

                if (!pawn.Dead)
                {
                    for (int l = 0; l < pawn.health.hediffSet.hediffs.Count; l++)
                    {
                        HediffComp_DrawImplant drawer;
                        if ((drawer = pawn.health.hediffSet.hediffs[l].TryGetComp <HediffComp_DrawImplant>()) != null)
                        {
                            if (drawer.implantDrawProps.implantDrawerType != ImplantDrawerType.Head)
                            {
                                vector3.y += 0.005f;
                                if (bodyFacing == Rot4.South && drawer.implantDrawProps.implantDrawerType == ImplantDrawerType.Backpack)
                                {
                                    vector3.y -= 0.3f;
                                }
                                Material implantMat = drawer.ImplantMaterial(pawn, bodyFacing);
                                GenDraw.DrawMeshNowOrLater(mesh, vector3, quat, implantMat, portrait);
                                vector3.y += 0.005f;
                            }
                        }
                    }
                }
            }

            if (!portrait && pawn.RaceProps.Animal && pawn.inventory != null && pawn.inventory.innerContainer.Count() > 0)
            {
                Graphics.DrawMesh(mesh, vector3, quat, renderer.graphics.packGraphic.MatAt(pawn.Rotation, null), 0);
            }
            if (!portrait)
            {
                HarmonyPatches.equipInfo.Invoke(renderer, new object[]
                {
                    rootLoc
                });
                if (pawn.apparel != null)
                {
                    List <Apparel> wornApparel = pawn.apparel.WornApparel;
                    for (int l = 0; l < wornApparel.Count; l++)
                    {
                        wornApparel[l].DrawWornExtras();
                    }
                }
                Vector3 vector7 = rootLoc;
                vector7.y += 0.0449999981f;
                ((PawnHeadOverlays)HarmonyPatches.statusInfo.GetValue(renderer)).RenderStatusOverlays(vector7, quat, ((pawn is AlienPawn) ? (pawn as AlienPawn).headSet : MeshPool.humanlikeHeadSet).MeshAt(headFacing));
            }
            return(false);
        }