Пример #1
0
 static void Prefix(PawnGraphicSet __instance, ref bool __state)
 {
     Rand.PushState(__instance.pawn.thingIDNumber);
     __state = true;
 }
Пример #2
0
 private static void ResolveApparelGraphics_Postfix(PawnGraphicSet __instance)
 {
     __instance.apparelGraphics = __instance.apparelGraphics
                                  .OrderBy(x => x.sourceApparel.def.apparel.bodyPartGroups[0].listOrder).ToList();
 }
Пример #3
0
 public static Mesh GetHeadMesh(PawnRenderFlags renderFlags, Pawn pawn, Rot4 headFacing, PawnGraphicSet graphics)
 {
     return(null);
 }
Пример #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);
                    }
                }
            }
        }
Пример #5
0
        internal static void ResolveAgeGraphics(PawnGraphicSet graphics)
        {
            LongEventHandler.ExecuteWhenFinished(delegate {
                //if (!graphics.pawn.RaceProps.Humanlike) {
                if (!ChildrenUtility.RaceUsesChildren(graphics.pawn))
                {
                    return;
                }

                // Beards
                String beard = "";
                if (graphics.pawn.story.hairDef != null)
                {
                    if (graphics.pawn.story.hairDef.hairTags.Contains("Beard"))
                    {
                        if (graphics.pawn.apparel.BodyPartGroupIsCovered(BodyPartGroupDefOf.UpperHead) && !graphics.pawn.story.hairDef.hairTags.Contains("DrawUnderHat"))
                        {
                            beard = "_BeardOnly";
                        }
                        if (graphics.pawn.ageTracker.CurLifeStageIndex <= AgeStage.Teenager)
                        {
                            graphics.hairGraphic = GraphicDatabase.Get <Graphic_Multi> (DefDatabase <HairDef> .GetNamed("Mop").texPath, ShaderDatabase.Cutout, Vector2.one, graphics.pawn.story.hairColor);
                        }
                        else
                        {
                            graphics.hairGraphic = GraphicDatabase.Get <Graphic_Multi> (graphics.pawn.story.hairDef.texPath + beard, ShaderDatabase.Cutout, Vector2.one, graphics.pawn.story.hairColor);
                        }
                    }
                    else
                    {
                        graphics.hairGraphic = GraphicDatabase.Get <Graphic_Multi> (graphics.pawn.story.hairDef.texPath, ShaderDatabase.Cutout, Vector2.one, graphics.pawn.story.hairColor);
                    }
                }

                // Reroute the graphics for children
                // For babies and toddlers
                if (graphics.pawn.ageTracker.CurLifeStageIndex <= AgeStage.Baby)
                {
                    string toddler_hair = "Boyish";
                    if (graphics.pawn.gender == Gender.Female)
                    {
                        toddler_hair = "Girlish";
                    }
                    graphics.hairGraphic = GraphicDatabase.Get <Graphic_Multi> ("Things/Pawn/Humanlike/Children/Hairs/Child_" + toddler_hair, ShaderDatabase.Cutout, Vector2.one, graphics.pawn.story.hairColor);
                    graphics.headGraphic = GraphicDatabase.Get <Graphic_Multi> ("Things/Pawn/Humanlike/null", ShaderDatabase.Cutout, Vector2.one, Color.white);

                    // The pawn is a baby
                    if (graphics.pawn.ageTracker.CurLifeStageIndex == AgeStage.Baby)
                    {
                        graphics.nakedGraphic = GraphicDatabase.Get <Graphic_Single> ("Things/Pawn/Humanlike/Children/Bodies/Newborn", ShaderDatabase.CutoutSkin, Vector2.one, graphics.pawn.story.SkinColor);
                    }
                }

                // The pawn is a toddler
                if (graphics.pawn.ageTracker.CurLifeStageIndex == AgeStage.Toddler)
                {
                    string upright = "";
                    if (graphics.pawn.ageTracker.AgeBiologicalYears >= 1)
                    {
                        upright = "Upright";
                    }
                    graphics.nakedGraphic = GraphicDatabase.Get <Graphic_Multi> ("Things/Pawn/Humanlike/Children/Bodies/Toddler" + upright, ShaderDatabase.CutoutSkin, Vector2.one, graphics.pawn.story.SkinColor);
                }
                // The pawn is a child
                else if (graphics.pawn.ageTracker.CurLifeStageIndex == AgeStage.Child)
                {
                    graphics.nakedGraphic = Children_Drawing.GetChildBodyGraphics(graphics, ShaderDatabase.CutoutSkin, graphics.pawn.story.SkinColor);
                    graphics.headGraphic  = Children_Drawing.GetChildHeadGraphics(graphics, ShaderDatabase.CutoutSkin, graphics.pawn.story.SkinColor);
                }
            });
        }
        public static bool Prefix(PawnGraphicSet __instance)
        {
            if (__instance.pawn.RaceProps.Animal)
            {
                bool isCustom = false;
                Pawn pawn     = __instance.pawn;
                PawnKindLifeStage curKindLifeStage = __instance.pawn.ageTracker.CurKindLifeStage;

                Graphic baseGraphic = new Graphic(((pawn.gender == Gender.Female) ?
                                                   curKindLifeStage.femaleGraphicData?.Graphic ?? curKindLifeStage.bodyGraphicData.Graphic :
                                                   curKindLifeStage.bodyGraphicData.Graphic));

                if (baseGraphic is null)
                {
                    Debug.Log("Basegraphic for " + pawn.ThingID + " null");
                    return(true);
                }
                Color color = baseGraphic.color;

                /*if (baseGraphic.Shader.name != ShaderType.Cutout.ToString()) {
                 *  Log.Error("boutta override " + pawn.Label + "'s " + baseGraphic.Shader.name + " with cutoutskin :(");
                 * }*/
                Shader shader = ShaderDatabase.Cutout;
                //has custom colors
                Debug.Log("Checking custom color " + pawn.Label);

                if (__instance.pawn.kindDef.GetModExtension <BPTModExtension>() is BPTModExtension extension)
                {
                    isCustom = true;
                    int colorIndex = (new System.Random(pawn.thingIDNumber)).Next() % extension.colors.Count;
                    color = extension.colors[colorIndex];
                    FieldInfo fieldInfo = typeof(ShaderDatabase).GetField(extension.shaderType, BindingFlags.Static | BindingFlags.Public);
                    shader = (Shader)fieldInfo.GetValue(null);
                    Debug.Log("chose special color " + color + " with shader " + shader);
                    Debug.Log(typeof(ShaderDatabase).GetFields(BindingFlags.Static | BindingFlags.Public).ToStringSafeEnumerable());
                }
                else
                {
                    Debug.Log(__instance.pawn.kindDef.GetModExtension <BPTModExtension>().ToStringSafe());
                }

                string safeTextureIndex = "";
                //has custom texture
                Debug.Log("Checking custom texture " + pawn.Label);
                if (__instance.pawn.ageTracker.CurKindLifeStage.bodyGraphicData.graphicClass == typeof(Graphic))
                {
                    isCustom = true;
                    int availableTextureCount = Graphic.ModTextureCount(baseGraphic.path);
                    if (availableTextureCount > 0)
                    {
                        int textureIndex = (new System.Random(pawn.thingIDNumber * 2)).Next() % availableTextureCount;
                        safeTextureIndex = (1 + textureIndex).ToString();
                    }
                    Debug.Log("chose texture " + safeTextureIndex);
                }


                if (isCustom)
                {
                    __instance.ClearCache();

                    if (curKindLifeStage.dessicatedBodyGraphicData is GraphicData dessicated)
                    {
                        __instance.dessicatedGraphic = dessicated.GraphicColoredFor(__instance.pawn);
                    }

                    //may spawn packs all default colors
                    if (pawn.RaceProps.packAnimal)
                    {
                        Debug.Log("pack animal with shader:" + shader.ToStringSafe() + color.ToStringSafe());
                        __instance.packGraphic = GraphicDatabase.Get <Graphic_Multi>(Graphic.PathBase(baseGraphic.path) + "Pack", shader, baseGraphic.drawSize, color);
                    }
                    __instance.nakedGraphic = (new Graphic(baseGraphic)).GetColoredVersion(shader, color, safeTextureIndex);
                    Debug.Log("Resolved " + __instance.nakedGraphic);
                    return(false);
                }

                return(true);
            }
            return(true);
        }
Пример #7
0
 static void Postfix(PawnGraphicSet __instance)
 {
     __instance.flasher = new ZombieDamageFlasher(__instance.pawn);
 }
        // [HarmonyAfter("net.pardeike.zombieland")]
        public static void ResolveAllGraphics_Postfix(PawnGraphicSet __instance)
        {
            Pawn pawn = __instance.pawn;

            if (pawn == null)
            {
                return;
            }

            pawn.CheckForAddedOrMissingParts();
            pawn.GetCompAnim()?.PawnBodyGraphic?.Initialize();

            // Check if race has face, else return
            if (!pawn.GetCompFace(out CompFace compFace))
            {
                return;
            }

            compFace.IsChild = pawn.ageTracker.AgeBiologicalYearsFloat < 14;

            // Return if child
            if (compFace.IsChild || compFace.Deactivated)
            {
                return;
            }

            __instance.ClearCache();
            pawn.GetComp <CompBodyAnimator>()?.ClearCache();

            GraphicDatabaseHeadRecordsModded.BuildDatabaseIfNecessary();

            // Need: get the traditional habitat of a faction => not suitable, as factions are scattered around the globe
            // if (!faceComp.IsSkinDNAoptimized)
            // {
            // faceComp.DefineSkinDNA();
            // }

            // Custom rotting color, mixed with skin tone
            Color rotColor = pawn.story.SkinColor * FaceTextures.SkinRottingMultiplyColor;

            if (!compFace.InitializeCompFace())
            {
                return;
            }

            __instance.nakedGraphic = GraphicDatabase.Get <Graphic_Multi>(__instance.pawn.story.bodyType.bodyNakedGraphicPath, ShaderDatabase.CutoutSkin, Vector2.one, __instance.pawn.story.SkinColor);
            if (compFace.Props.needsBlankHumanHead)
            {
                __instance.headGraphic =
                    GraphicDatabaseHeadRecordsModded.GetModdedHeadNamed(pawn,
                                                                        pawn.story.SkinColor);
                __instance.desiccatedHeadGraphic =
                    GraphicDatabaseHeadRecordsModded.GetModdedHeadNamed(pawn, rotColor);
                __instance.desiccatedHeadStumpGraphic = GraphicDatabaseHeadRecordsModded.GetStump(rotColor);
            }

            __instance.rottingGraphic =
                GraphicDatabase.Get <Graphic_Multi>(__instance.pawn.story.bodyType.bodyNakedGraphicPath, ShaderDatabase.CutoutSkin, Vector2.one, rotColor);


            __instance.hairGraphic = GraphicDatabase.Get <Graphic_Multi_Four>(
                pawn.story.hairDef.texPath,
                ShaderDatabase.CutoutComplex,
                Vector2.one,
                pawn.story.hairColor);
            PortraitsCache.SetDirty(pawn);
        }
Пример #9
0
        public void InitializeWithPawn(Pawn pawn)
        {
            this.pawn = this.CopyPawn(pawn);

            this.birthTicks = this.pawn.ageTracker.BirthAbsTicks % 3600000L;

            // Set the traits.
            this.traits.Clear();
            for (int i = 0; i < TraitCount; i++)
            {
                this.traits.Add(null);
            }
            List <Trait> pawnTraits = pawn.story.traits.allTraits;

            if (pawnTraits.Count > 0)
            {
                this.traits[0] = pawnTraits[0];
            }
            if (pawnTraits.Count > 1 && this.traits[0] != pawnTraits[1])
            {
                this.traits[1] = pawnTraits[1];
            }
            if (pawnTraits.Count > 2 && this.traits[0] != pawnTraits[2] && this.traits[1] != pawnTraits[2])
            {
                this.traits[2] = pawnTraits[2];
            }

            // Set the skills.
            InitializeSkillLevelsAndPassions();
            ComputeSkillLevelModifiers();

            graphics.Clear();
            colors.Clear();
            PawnGraphicSet pawnGraphics = pawn.Drawer.renderer.graphics;

            graphics.Add(GraphicGetter_NakedHumanlike.GetNakedBodyGraphic(pawn.story.BodyType, ShaderDatabase.CutoutSkin, pawn.story.SkinColor));
            colors.Add(pawn.story.SkinColor);

            graphics.Add(null);
            colors.Add(Color.white);
            graphics.Add(null);
            colors.Add(Color.white);
            graphics.Add(null);
            colors.Add(Color.white);
            graphics.Add(null);
            colors.Add(Color.white);

            graphics.Add(GraphicDatabaseHeadRecords.GetHeadNamed(pawn.story.HeadGraphicPath, pawn.story.SkinColor));
            colors.Add(pawn.story.SkinColor);
            ResetHead();

            graphics.Add(GraphicsCache.Instance.GetHair(pawn.story.hairDef));
            colors.Add(pawn.story.hairColor);

            graphics.Add(null);
            colors.Add(Color.white);
            graphics.Add(null);
            colors.Add(Color.white);

            for (int i = 0; i < PawnLayers.Count; i++)
            {
                selectedApparel.Add(null);
                acceptedApparel.Add(null);
                selectedStuff.Add(null);
            }
            foreach (Apparel current in this.pawn.apparel.WornApparel)
            {
                Graphic graphic = GraphicsCache.Instance.GetApparel(current.def, pawn.story.BodyType);
                Color   color   = current.DrawColor;
                int     layer   = PawnLayers.ToPawnLayerIndex(current.def.apparel);
                if (layer != -1)
                {
                    graphics[layer] = graphic;
                    SetSelectedApparel(layer, current.def);
                    acceptedApparel[layer] = current.def;
                    SetSelectedStuff(layer, current.Stuff);
                    if (ApparelIsTintedByDefault(current.def, current.Stuff))
                    {
                        SetColor(layer, color);
                    }
                }
            }

            ResetIncapableOf();
            pawn.health.capacities.Clear();
        }
        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) { }
        }
Пример #11
0
        private static bool Prefix(PawnGraphicSet __instance)
        {
            if (__instance.pawn.def is RaceAddonThingDef thingDef)
            {
                Pawn          pawn   = __instance.pawn;
                RaceAddonComp racomp = pawn.GetComp <RaceAddonComp>();
                racomp.drawSize = RaceAddonTools.GetPawnDrawSize(pawn, thingDef);
                var drawSize = thingDef.raceAddonSettings.graphicSetting.drawSize[racomp.drawSize];
                // cleaning
                __instance.ClearCache();

                // resolve mesh set
                racomp.bodyMeshSet      = new GraphicMeshSet(1.5f * drawSize.bodySize.x, 1.5f * drawSize.bodySize.y);
                racomp.headMeshSet      = new GraphicMeshSet(1.5f * drawSize.headSize.x, 1.5f * drawSize.headSize.y);
                racomp.equipmentMeshSet = new GraphicMeshSet(drawSize.equipmentSize.x, drawSize.equipmentSize.y);

                // resolve body
                var bodyDef = racomp.savedBodyData.def;
                __instance.pawn.story.bodyType = bodyDef.bodyTypeDef;
                __instance.nakedGraphic        = GraphicDatabase.Get <Graphic_Multi>
                                                     (GetBodyNormalPath(bodyDef), bodyDef.shaderType.Shader, Vector2.one, pawn.story.SkinColor, racomp.savedSkinData.color2);
                __instance.rottingGraphic = GraphicDatabase.Get <Graphic_Multi>
                                                (GetBodyNormalPath(bodyDef), bodyDef.shaderType.Shader, Vector2.one, racomp.savedSkinData.rottingColor);
                __instance.dessicatedGraphic = GraphicDatabase.Get <Graphic_Multi>(GetBodySkullPath(bodyDef), ShaderDatabase.Cutout);

                // resolve head
                var headDef = racomp.savedHeadData.def;
                __instance.pawn.story.crownType = headDef.crownType;
                __instance.headGraphic          = GraphicDatabase.Get <Graphic_Multi>
                                                      (headDef.replacedHeadPath, headDef.shaderType.Shader, Vector2.one, pawn.story.SkinColor, racomp.savedSkinData.color2);
                __instance.desiccatedHeadGraphic = GraphicDatabase.Get <Graphic_Multi>
                                                       (headDef.replacedHeadPath, headDef.shaderType.Shader, Vector2.one, racomp.savedSkinData.rottingColor);
                __instance.skullGraphic = GraphicDatabase.Get <Graphic_Multi>
                                              (headDef.replacedSkullPath, headDef.shaderType.Shader, Vector2.one, Color.white);

                // resolve stump
                __instance.headStumpGraphic = GraphicDatabase.Get <Graphic_Multi>
                                                  (headDef.replacedStumpPath, headDef.shaderType.Shader, Vector2.one, pawn.story.SkinColor, racomp.savedSkinData.color2);
                __instance.desiccatedHeadStumpGraphic = GraphicDatabase.Get <Graphic_Multi>
                                                            (headDef.replacedStumpPath, headDef.shaderType.Shader, Vector2.one, racomp.savedSkinData.rottingColor);

                // resolve hair
                HairDef hairDef = pawn.story.hairDef;
                if (hairDef is ImprovedHairDef advancedHairDef)
                {
                    __instance.hairGraphic = GraphicDatabase.Get <Graphic_Multi>
                                                 (advancedHairDef.texPath, advancedHairDef.shaderType.Shader, Vector2.one, pawn.story.hairColor, racomp.savedHairData.color2);
                    if (advancedHairDef.lowerPath != null)
                    {
                        racomp.improvedHairGraphic = GraphicDatabase.Get <Graphic_Multi>
                                                         (advancedHairDef.lowerPath, advancedHairDef.shaderType.Shader, Vector2.one, pawn.story.hairColor, racomp.savedHairData.color2);
                    }
                }
                else
                {
                    __instance.hairGraphic = GraphicDatabase.Get <Graphic_Multi>
                                                 (hairDef.texPath, ShaderDatabase.Cutout, Vector2.one, pawn.story.hairColor);
                    racomp.improvedHairGraphic = null;
                }

                // resolve upper face
                if (racomp.savedFaceData != null && racomp.savedFaceData.upperDef != null)
                {
                    var upperFaceDef = racomp.savedFaceData.upperDef;
                    racomp.upperFaceGraphicSet = new FaceGraphicSet(pawn, racomp.savedFaceData, upperFaceDef, racomp);
                    racomp.upperFaceGraphicSet.ResolveAllGraphics();
                }

                // resolve lower face
                if (racomp.savedFaceData != null && racomp.savedFaceData.lowerDef != null)
                {
                    var lowerFaceDef = racomp.savedFaceData.lowerDef;
                    racomp.lowerFaceGraphicSet = new FaceGraphicSet(pawn, racomp.savedFaceData, lowerFaceDef, racomp);
                    racomp.lowerFaceGraphicSet.ResolveAllGraphics();
                }

                // resolve addons
                if (racomp.savedAddonDatas != null)
                {
                    racomp.bodyAddonGraphicSets = null;
                    racomp.headAddonGraphicSets = null;
                    foreach (var data in racomp.savedAddonDatas)
                    {
                        if (data.def.drawingToBody)
                        {
                            if (racomp.bodyAddonGraphicSets == null)
                            {
                                racomp.bodyAddonGraphicSets = new List <AddonGraphicSet>();
                            }
                            var set = new AddonGraphicSet(data);
                            set.ResolveAllGraphics(racomp.savedSkinData.rottingColor, pawn.health.hediffSet);
                            racomp.bodyAddonGraphicSets.Add(set);
                        }
                        else
                        {
                            if (racomp.headAddonGraphicSets == null)
                            {
                                racomp.headAddonGraphicSets = new List <AddonGraphicSet>();
                            }
                            var set = new AddonGraphicSet(data);
                            set.ResolveAllGraphics(racomp.savedSkinData.rottingColor, pawn.health.hediffSet);
                            racomp.headAddonGraphicSets.Add(set);
                        }
                    }
                }

                if (!pawn.Dead)
                {
                    // resolve eye blinker
                    if (thingDef.raceAddonSettings.graphicSetting.eyeBlink)
                    {
                        racomp.eyeBlinker = new EyeBlinker();
                        racomp.eyeBlinker.Check(pawn.needs.mood.CurLevel);
                    }

                    // resolve head rotator
                    if (thingDef.raceAddonSettings.graphicSetting.headAnimation)
                    {
                        racomp.headRotator = new HeadRotator();
                        racomp.headRotator.Check();
                    }

                    // resolve head targeter
                    if (thingDef.raceAddonSettings.graphicSetting.headTargeting)
                    {
                        racomp.headTargeter = new HeadTargeter(__instance.pawn);
                        racomp.headTargeter.Check();
                    }
                }

                // resolve apparel
                __instance.ResolveApparelGraphics();

                return(false);
            }
            return(true);
        }
Пример #12
0
        private static Material OverrideMaterialIfNeeded_NewTemp(PawnGraphicSet graphics, Material original, Pawn pawn, bool portrait = false)
        {
            Material baseMat = (!portrait && pawn.IsInvisible()) ? InvisibilityMatPool.GetInvisibleMat(original) : original;

            return(graphics.flasher.GetDamagedMat(baseMat));
        }
Пример #13
0
 public static bool GetPawnHairMesh(ref Mesh __result, bool portrait, Pawn pawn, Rot4 headFacing, PawnGraphicSet graphics)
 {
     __result = pawn.def is ThingDef_AlienRace alienProps
                    ? (pawn.story.crownType == CrownType.Narrow
                           ? (portrait
                                  ? alienProps.alienRace.generalSettings.alienPartGenerator.hairPortraitSetNarrow
                                  : alienProps.alienRace.generalSettings.alienPartGenerator.hairSetNarrow)
                           : (portrait
                                  ? alienProps.alienRace.generalSettings.alienPartGenerator.hairPortraitSetAverage
                                  : alienProps.alienRace.generalSettings.alienPartGenerator.hairSetAverage))
                .MeshAt(headFacing)
                    : graphics.HairMeshSet.MeshAt(headFacing);
     return(false);
 }
Пример #14
0
        // Taken from RenderingTool.RenderPawnInternal in CharacterEditor
        private void RenderPawn()
        {
            PawnGraphicSet graphics   = pawn.Drawer.renderer.graphics;
            Quaternion     quaternion = Quaternion.AngleAxis(0f, Vector3.up);

            Mesh    bodyMesh   = pawn.RaceProps.Humanlike ? MeshPool.humanlikeBodySet.MeshAt(previewRot) : graphics.nakedGraphic.MeshAt(previewRot);
            Vector3 bodyOffset = new Vector3(0f, pawn.Position.y + 0.007575758f, 0f);

            foreach (Material mat in graphics.MatsBodyBaseAt(previewRot))
            {
                Material damagedMat = graphics.flasher.GetDamagedMat(mat);
                GenDraw.DrawMeshNowOrLater(bodyMesh, bodyOffset, quaternion, damagedMat, false);
                bodyOffset.y += 0.00390625f;
                if (!toggleClothesEnabled)
                {
                    break;
                }
            }
            Vector3 vector3 = new Vector3(0f, pawn.Position.y + (previewRot == Rot4.North ? 0.026515152f : 0.022727273f), 0f);
            Vector3 vector4 = new Vector3(0f, pawn.Position.y + (previewRot == Rot4.North ? 0.022727273f : 0.026515152f), 0f);

            if (graphics.headGraphic != null)
            {
                Mesh     mesh2      = MeshPool.humanlikeHeadSet.MeshAt(previewRot);
                Vector3  headOffset = quaternion * pawn.Drawer.renderer.BaseHeadOffsetAt(previewRot);
                Material material   = graphics.HeadMatAt(previewRot);
                GenDraw.DrawMeshNowOrLater(mesh2, vector4 + headOffset, quaternion, material, false);

                Mesh    hairMesh     = graphics.HairMeshSet.MeshAt(previewRot);
                Vector3 hairOffset   = new Vector3(headOffset.x, pawn.Position.y + 0.030303031f, headOffset.z);
                bool    isWearingHat = false;
                if (toggleClothesEnabled)
                {
                    foreach (ApparelGraphicRecord apparel in graphics.apparelGraphics)
                    {
                        if (apparel.sourceApparel.def.apparel.LastLayer == ApparelLayerDefOf.Overhead)
                        {
                            Material hatMat = graphics.flasher.GetDamagedMat(apparel.graphic.MatAt(previewRot));
                            if (apparel.sourceApparel.def.apparel.hatRenderedFrontOfFace)
                            {
                                isWearingHat  = true;
                                hairOffset.y += 0.03f;
                                GenDraw.DrawMeshNowOrLater(hairMesh, hairOffset, quaternion, hatMat, false);
                            }
                            else
                            {
                                Vector3 hatOffset = new Vector3(headOffset.x, pawn.Position.y + (previewRot == Rot4.North ? 0.003787879f : 0.03409091f), headOffset.z);
                                GenDraw.DrawMeshNowOrLater(hairMesh, hatOffset, quaternion, hatMat, false);
                            }
                        }
                    }
                }
                if (!isWearingHat)
                {
                    Material hairMat = graphics.HairMatAt(previewRot);
                    GenDraw.DrawMeshNowOrLater(hairMesh, hairOffset, quaternion, hairMat, false);
                }
            }
            if (toggleClothesEnabled)
            {
                foreach (ApparelGraphicRecord graphicsSet in graphics.apparelGraphics)
                {
                    if (graphicsSet.sourceApparel.def.apparel.LastLayer == ApparelLayerDefOf.Shell)
                    {
                        Material clothingMat = graphics.flasher.GetDamagedMat(graphicsSet.graphic.MatAt(previewRot));
                        GenDraw.DrawMeshNowOrLater(bodyMesh, vector3, quaternion, clothingMat, false);
                    }
                }
            }
            HarmonyPatches.DrawAddons(false, vector3, pawn, quaternion, previewRot, false);
            if (toggleClothesEnabled)
            {
                if (pawn.apparel != null)
                {
                    foreach (Apparel apparel in pawn.apparel.WornApparel)
                    {
                        apparel.DrawWornExtras();
                    }
                }
            }
        }
        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;
            }
        }
Пример #16
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);
            }
        }
Пример #17
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;
            }
        }
        public static bool Prefix(PawnRenderer __instance,
                                  ref Vector3 rootLoc,
                                  Quaternion quat,
                                  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 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;
                                tacheLoc.y += (((headFacing == Rot4.North)) ? -YOffset_Head : 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);
        }
Пример #19
0
        internal static void ResolveAgeGraphics(PawnGraphicSet graphics)
        {
            // Beards
            String beard = "";

            if (graphics.pawn.story.hairDef.hairTags.Contains("Beard"))
            {
                if (graphics.pawn.apparel.BodyPartGroupIsCovered(BodyPartGroupDefOf.UpperHead))
                {
                    beard = "_BeardOnly";
                }
                if (graphics.pawn.ageTracker.CurLifeStageIndex <= 3)
                {
                    graphics.hairGraphic = GraphicDatabase.Get <Graphic_Multi>(DefDatabase <HairDef> .GetNamed("Mop").texPath, ShaderDatabase.Cutout, Vector2.one, graphics.pawn.story.hairColor);
                }
                else
                {
                    graphics.hairGraphic = GraphicDatabase.Get <Graphic_Multi>(graphics.pawn.story.hairDef.texPath + beard, ShaderDatabase.Cutout, Vector2.one, graphics.pawn.story.hairColor);
                }
            }
            else
            {
                graphics.hairGraphic = GraphicDatabase.Get <Graphic_Multi>(graphics.pawn.story.hairDef.texPath, ShaderDatabase.Cutout, Vector2.one, graphics.pawn.story.hairColor);
            }

            // Reroute the graphics for children
            // For babies and toddlers
            if (graphics.pawn.ageTracker.CurLifeStageIndex <= 1)
            {
                string toddler_hair = "Boyish";
                if (graphics.pawn.gender == Gender.Female)
                {
                    toddler_hair = "Girlish";
                }
                graphics.hairGraphic = GraphicDatabase.Get <Graphic_Multi>("Things/Pawn/Humanlike/Children/Hairs/Child_" + toddler_hair, ShaderDatabase.Cutout, Vector2.one, graphics.pawn.story.hairColor);
                graphics.headGraphic = GraphicDatabase.Get <Graphic_Multi>("Things/Pawn/Humanlike/null", ShaderDatabase.Cutout, Vector2.one, Color.white);
            }
            // The pawn is a baby
            if (graphics.pawn.ageTracker.CurLifeStageIndex == 0)
            {
                graphics.nakedGraphic = GraphicDatabase.Get <Graphic_Single>("Things/Pawn/Humanlike/Children/Bodies/Newborn", ShaderDatabase.CutoutSkin, Vector2.one, graphics.pawn.story.SkinColor);
            }
            // The pawn is a toddler
            if (graphics.pawn.ageTracker.CurLifeStageIndex == 1)
            {
                string upright = "";
                if (graphics.pawn.ageTracker.AgeBiologicalYears >= 2)
                {
                    upright = "Upright";
                }
                graphics.nakedGraphic = GraphicDatabase.Get <Graphic_Multi>("Things/Pawn/Humanlike/Children/Bodies/Toddler" + upright, ShaderDatabase.CutoutSkin, Vector2.one, graphics.pawn.story.SkinColor);
            }
            // The pawn is a child
            else if (graphics.pawn.ageTracker.CurLifeStageIndex == 2)
            {
                //              graphics.nakedGraphic = ChildGraphics.GetChildBodyGraphics(graphics, ShaderDatabase.CutoutSkin, graphics.pawn.story.SkinColor);
                //              graphics.headGraphic = ChildGraphics.GetChildHeadGraphics(ShaderDatabase.CutoutSkin, graphics.pawn.story.SkinColor);
            }
            // Otherwise, just use the normal methods
            else if (graphics.pawn.ageTracker.CurLifeStageIndex >= 3)
            {
                graphics.nakedGraphic = GraphicGetter_NakedHumanlike.GetNakedBodyGraphic(graphics.pawn.story.bodyType, ShaderDatabase.CutoutSkin, graphics.pawn.story.SkinColor);
                graphics.headGraphic  = GraphicDatabaseHeadRecords.GetHeadNamed(graphics.pawn.story.HeadGraphicPath, graphics.pawn.story.SkinColor);
            }

            graphics.rottingGraphic        = GraphicGetter_NakedHumanlike.GetNakedBodyGraphic(graphics.pawn.story.bodyType, ShaderDatabase.CutoutSkin, PawnGraphicSet.RottingColor);
            graphics.dessicatedGraphic     = GraphicDatabase.Get <Graphic_Multi>("Things/Pawn/Humanlike/HumanoidDessicated", ShaderDatabase.Cutout);
            graphics.desiccatedHeadGraphic = GraphicDatabaseHeadRecords.GetHeadNamed(graphics.pawn.story.HeadGraphicPath, PawnGraphicSet.RottingColor);
            graphics.skullGraphic          = GraphicDatabaseHeadRecords.GetSkull();
        }
Пример #20
0
 public virtual void Tick(Rot4 bodyFacing, Rot4 headFacing, PawnGraphicSet graphics)
 {
     this.Graphics   = graphics;
     this.BodyFacing = bodyFacing;
     this.HeadFacing = headFacing;
 }
Пример #21
0
 public static Graphic BeardGraphic(this PawnGraphicSet instance)
 {
     return(instance.pawn.Drawer.renderer.graphics.beardGraphic);
 }