示例#1
0
        public static bool Prefix(PawnRenderer __instance, Pawn ___pawn, PawnWoundDrawer ___woundOverlays, PawnHeadOverlays ___statusOverlays,
                                  Vector3 rootLoc, float angle, bool renderBody, Rot4 bodyFacing, Rot4 headFacing, RotDrawMode bodyDrawType, bool portrait, bool headStump, bool invisible)
        {
            if (___pawn.def is RaceAddonThingDef thingDef)
            {
                if (!__instance.graphics.AllResolved)
                {
                    __instance.graphics.ResolveAllGraphics();
                }
                RaceAddonComp racomp   = ___pawn.GetComp <RaceAddonComp>();
                Quaternion    bodyQuat = Quaternion.AngleAxis(angle, Vector3.up);
                Quaternion    headQuat = bodyQuat;
                rootLoc.z -= racomp.cachedDrawLocCorrection;
                Vector3 bodyLoc = rootLoc;
                Vector3 headLoc = __instance.BaseHeadOffsetAt(bodyFacing);
                GetModifiedValue(racomp, ref bodyQuat, ref headQuat, ref bodyLoc, ref headLoc, ___pawn, ref renderBody, ref bodyFacing, ref headFacing, portrait);
                // For Resolve Head Targeting Error
                Mesh bodyMesh = racomp.raceAddonGraphicSet.bodyMeshSet.MeshAt(bodyFacing);
                Mesh headMesh = racomp.raceAddonGraphicSet.headMeshSet.MeshAt(headFacing);

                List <ApparelGraphicRecord> apparelGraphics = __instance.graphics.apparelGraphics;

                if (renderBody)
                {
                    List <Material> bodyMatList = __instance.graphics.MatsBodyBaseAt(bodyFacing, bodyDrawType);
                    for (int i = 0; i < bodyMatList.Count; i++)
                    {
                        // Draw Body And Apparel
                        Material mat = OverrideMaterialIfNeeded_NewTemp(__instance.graphics, bodyMatList[i], ___pawn, portrait);
                        GenDraw.DrawMeshNowOrLater(bodyMesh, bodyLoc.SetLayer((i + 3) * 10), bodyQuat, mat, portrait);
                    }
                    if (bodyDrawType == RotDrawMode.Fresh && thingDef.raceAddonSettings.graphicSetting.drawWound)
                    {
                        // Draw Wound
                        ___woundOverlays.RenderOverBody(bodyLoc.SetLayer(60), bodyMesh, bodyQuat, portrait);
                    }
                    for (int k = 0; k < apparelGraphics.Count; k++)
                    {
                        // Draw Shell
                        if (apparelGraphics[k].sourceApparel.def.apparel.LastLayer == ApparelLayerDefOf.Shell && !apparelGraphics[k].sourceApparel.def.apparel.shellRenderedBehindHead)
                        {
                            Material original3 = apparelGraphics[k].graphic.MatAt(bodyFacing);
                            original3 = OverrideMaterialIfNeeded_NewTemp(__instance.graphics, original3, ___pawn, portrait);
                            GenDraw.DrawMeshNowOrLater(bodyMesh, bodyLoc.SetLayer(bodyFacing == Rot4.North ? 80 : 70), bodyQuat, original3, portrait);
                        }
                        // Draw Pack
                        if (PawnRenderer.RenderAsPack(apparelGraphics[k].sourceApparel))
                        {
                            Material original4 = apparelGraphics[k].graphic.MatAt(bodyFacing);
                            original4 = OverrideMaterialIfNeeded_NewTemp(__instance.graphics, original4, ___pawn, portrait);
                            if (apparelGraphics[k].sourceApparel.def.apparel.wornGraphicData != null)
                            {
                                Vector2   vector3 = apparelGraphics[k].sourceApparel.def.apparel.wornGraphicData.BeltOffsetAt(bodyFacing, ___pawn.story.bodyType);
                                Vector2   vector4 = apparelGraphics[k].sourceApparel.def.apparel.wornGraphicData.BeltScaleAt(___pawn.story.bodyType);
                                Matrix4x4 matrix  = Matrix4x4.Translate(bodyLoc.SetLayer(bodyFacing == Rot4.South ? 10 : 90)) * Matrix4x4.Rotate(bodyQuat) * Matrix4x4.Translate(new Vector3(vector3.x, 0f, vector3.y)) * Matrix4x4.Scale(new Vector3(vector4.x, 1f, vector4.y));
                                GenDraw.DrawMeshNowOrLater_NewTemp(bodyMesh, matrix, original4, portrait);
                            }
                            else
                            {
                                GenDraw.DrawMeshNowOrLater(bodyMesh, bodyLoc.SetLayer(bodyFacing == Rot4.North ? 80 : 70), bodyQuat, original4, portrait);
                            }
                        }
                    }
                    //Draw Body Addons
                    if (bodyDrawType != RotDrawMode.Dessicated && racomp.raceAddonGraphicSet.addonGraphics.FindAll(x => x.data.addonDef.drawingToBody) is var list && list.Count > 0)
                    {
                        foreach (var record in list)
                        {
                            if (!___pawn.InBed() || ___pawn.InBed() && record.data.addonDef.drawnInBed)
                            {
                                Material addonMat = OverrideMaterialIfNeeded_NewTemp(__instance.graphics, record.MatAt(bodyFacing, bodyDrawType), ___pawn, portrait);
                                if (addonMat != null)
                                {
                                    Vector3 offset = record.data.addonDef.offsets.GetLoc(bodyFacing);
                                    GenDraw.DrawMeshNowOrLater(bodyMesh, offset + bodyLoc.SetLayer(record.data.addonDef.drawPriority.GetPriority(bodyFacing)), bodyQuat, addonMat, portrait);
                                }
                            }
                        }
                    }
                }
                if (__instance.graphics.headGraphic != null)
                {
                    // Draw Head
                    if (__instance.graphics.HeadMatAt_NewTemp(headFacing, bodyDrawType, headStump, portrait) is var headMat && headMat != null)
                    {
                        GenDraw.DrawMeshNowOrLater(headMesh, headLoc.SetLayer(headFacing == Rot4.North ? 70 : 80), headQuat, headMat, portrait);
                    }
                    // Draw Hat, Mask
                    bool hideHair = false;
                    if (!portrait || !Prefs.HatsOnlyOnMap)
                    {
                        for (int j = 0; j < apparelGraphics.Count; j++)
                        {
                            if (apparelGraphics[j].sourceApparel.def.apparel.LastLayer == ApparelLayerDefOf.Overhead)
                            {
                                hideHair = !apparelGraphics[j].sourceApparel.def.apparel.hatRenderedFrontOfFace;
                                Material mat = OverrideMaterialIfNeeded_NewTemp(__instance.graphics, apparelGraphics[j].graphic.MatAt(headFacing), ___pawn, portrait);
                                GenDraw.DrawMeshNowOrLater(headMesh, headLoc.SetLayer(hideHair ? 120 : (bodyFacing == Rot4.North) ? 10 : 110), headQuat, mat, portrait);
                            }
                        }
                    }
                    if (bodyDrawType != RotDrawMode.Dessicated && !headStump)
                    {
                        bool blinkNow = false;
                        bool winkNow  = false;
                        if (racomp.raceAddonGraphicSet.eyeBlinker != null)
                        {
                            blinkNow = racomp.raceAddonGraphicSet.eyeBlinker.BlinkNow;
                            winkNow  = racomp.raceAddonGraphicSet.eyeBlinker.WinkNow;
                        }
                        // Draw Upper Face
                        if (racomp.raceAddonGraphicSet.upperFaceGraphic != null)
                        {
                            Material faceMat = OverrideMaterialIfNeeded_NewTemp(__instance.graphics, racomp.raceAddonGraphicSet.upperFaceGraphic.MatAt(headFacing, portrait, blinkNow, winkNow), ___pawn);
                            GenDraw.DrawMeshNowOrLater(headMesh, headLoc.SetLayer(105), headQuat, faceMat, portrait);
                        }
                        // Draw Lower Face
                        if (racomp.raceAddonGraphicSet.lowerFaceGraphic != null)
                        {
                            Material faceMat = OverrideMaterialIfNeeded_NewTemp(__instance.graphics, racomp.raceAddonGraphicSet.lowerFaceGraphic.MatAt(headFacing, portrait, blinkNow, winkNow), ___pawn);
                            GenDraw.DrawMeshNowOrLater(headMesh, headLoc.SetLayer(85), headQuat, faceMat, portrait);
                        }
                        // Draw Upper Hair
                        if (!hideHair || racomp.raceAddonGraphicSet.drawUpperHair)
                        {
                            GenDraw.DrawMeshNowOrLater(headMesh, headLoc.SetLayer(100), headQuat, __instance.graphics.HairMatAt_NewTemp(headFacing, portrait), portrait);
                        }
                        // Draw Lower Hair
                        if (racomp.raceAddonGraphicSet.hairGraphic != null && (!hideHair || racomp.raceAddonGraphicSet.drawLowerHair))
                        {
                            if (renderBody || ___pawn.InBed() && (___pawn.story.hairDef as ImprovedHairDef).drawnInBed)
                            {
                                Material mat = racomp.raceAddonGraphicSet.hairGraphic.MatAt(headFacing);
                                mat = OverrideMaterialIfNeeded_NewTemp(__instance.graphics, mat, ___pawn, portrait);
                                GenDraw.DrawMeshNowOrLater(headMesh, headLoc.SetLayer(20), headQuat, mat, portrait);
                            }
                        }
                        // Draw Head Addons
                        if (racomp.raceAddonGraphicSet.addonGraphics.FindAll(x => !x.data.addonDef.drawingToBody) is var list && list.Count > 0)
                        {
                            foreach (var record in list)
                            {
                                if (!___pawn.InBed() || ___pawn.InBed() && record.data.addonDef.drawnInBed)
                                {
                                    Material addonMat = OverrideMaterialIfNeeded_NewTemp(__instance.graphics, record.MatAt(headFacing, bodyDrawType), ___pawn, portrait);
                                    if (addonMat != null)
                                    {
                                        Vector3 offset = record.data.addonDef.offsets.GetLoc(bodyFacing);
                                        GenDraw.DrawMeshNowOrLater(headMesh, offset + headLoc.SetLayer(record.data.addonDef.drawPriority.GetPriority(headFacing)), headQuat, addonMat, portrait);
                                    }
                                }
                            }
                        }
                    }
                }

                /*
                 * if (!portrait)
                 * {
                 *      DrawEquipment(rootLoc, ___pawn, racomp.raceAddonGraphicSet.equipmentMeshSet.MeshAt(bodyFacing));
                 *      if (___pawn.apparel != null)
                 *      {
                 *              List<Apparel> wornApparel = ___pawn.apparel.WornApparel;
                 *              for (int l = 0; l < wornApparel.Count; l++)
                 *              {
                 *                      wornApparel[l].DrawWornExtras();
                 *              }
                 *      }
                 *      ___statusOverlays.RenderStatusOverlays(bodyLoc.SetLayer(130), bodyQuat, MeshPool.humanlikeHeadSet.MeshAt(headFacing));
                 * }
                 * return false;
                 */
            }
            return(true);
        }
        public static void Postfix(ref Apparel apparel, BodyTypeDef bodyType, ref ApparelGraphicRecord rec)
        {
            /*
             * bool Pauldron = apparel.TryGetCompFast<CompPauldronDrawer>() != null;
             * if (Pauldron)
             * {
             * //	Log.Message("Updating pad graphics for "+apparel.LabelShortCap);
             *      for (int i = 0; i < apparel.GetComps<CompPauldronDrawer>().Count(); i++)
             *      {
             *      //	Log.Message("Pauldron drawer "+(i+1));
             *              CompPauldronDrawer comp = apparel.GetComps<CompPauldronDrawer>().ElementAt(i);
             *              if (!comp.activeEntries.NullOrEmpty())
             *              {
             *                      for (int i2 = 0; i2 < comp.activeEntries.Count; i2++)
             *                      {
             *                      //	Log.Message("Entry drawer " + (i2 + 1));
             *                              comp.activeEntries[i2].UpdatePadGraphic();
             *                      }
             *              }
             *      }
             * }
             */
            string mskVariant = "";

            if (apparel is ApparelComposite composite)
            {
                if (!composite.AltGraphics.NullOrEmpty() && composite.ActiveAltGraphic != null)
                {
                    rec.graphic = composite.ActiveAltGraphic.GetGraphic(rec.graphic, true);
                    Graphic graphic = GraphicDatabase.Get <Graphic_Multi>(composite.WornGraphicPath, apparel.def.apparel.useWornGraphicMask ? ShaderDatabase.CutoutComplex : ShaderDatabase.Cutout, apparel.def.graphicData.drawSize, composite.DrawColor, composite.DrawColorTwo);
                    if (!composite.ActiveAltGraphic.maskKey.NullOrEmpty())
                    {
                        mskVariant = "_" + composite.ActiveAltGraphic.maskKey;
                    }
                    rec = new ApparelGraphicRecord(graphic, apparel);
                }
            }
            CompColorableTwo compColorable = apparel.TryGetCompFast <CompColorableTwo>();

            if (compColorable != null)
            {
                //	Log.Message("CompColorableTwo "+ apparel);
                string comptype   = compColorable.GetType().Name;
                string msg        = string.Empty;
                string mskFaction = string.Empty;
                CompColorableTwoFaction factionColors = compColorable as CompColorableTwoFaction;
                Color colorOne = compColorable.Color;
                Color colorTwo = compColorable.ColorTwo;

                if (factionColors != null)
                {
                    if (apparel.Wearer.Faction != null)
                    {
                        if (apparel.Wearer.Faction != Faction.OfPlayer)
                        {
                            factionColors.FactionDef = apparel.Wearer.Faction?.def;
                            msg += " entry for Non Player Pawn using FactionDef " + factionColors.FactionDef;
                        }
                        else
                        {
                            if (factionColors.FactionDef != null)
                            {
                                msg += " entry for Player Pawn using FactionDef " + factionColors.FactionDef;
                            }
                            else
                            {
                                /*
                                 * CompPauldronDrawer pauldrons = apparel.TryGetCompFast<CompPauldronDrawer>();
                                 * if (pauldrons != null)
                                 * {
                                 *      for (int i = 0; i < pauldrons.activeEntries.Count; i++)
                                 *      {
                                 *              ShoulderPadEntry entry = pauldrons.activeEntries[i];
                                 *              if (entry.faction != null && entry.UseFactionTextures || entry.UseFactionColors)
                                 *              {
                                 *                      factionColors.FactionDef = entry.faction;
                                 *                      msg += " entry for Player Pawn using FactionDef " + factionColors.FactionDef;
                                 *                      break;
                                 *              }
                                 *
                                 *      }
                                 * }
                                 * else
                                 * {
                                 *      //	Log.Message("CompFactionColorableTwo Player Pawn no CompPauldronDrawer");
                                 * }
                                 */
                            }
                        }
                    }
                    if (factionColors.Active)
                    {
                        //	Log.Message("factionColors.Active");
                        colorOne = factionColors.Color;
                        apparel.SetColorOne(colorOne);
                    }
                    if (factionColors.ActiveTwo)
                    {
                        //	Log.Message("factionColors.ActiveTwo");
                        colorTwo = factionColors.ColorTwo;
                        apparel.SetColorTwo(colorTwo);
                    }
                    if (factionColors.Extension != null)
                    {
                        //	Log.Message("factionColors.Extension != null");
                        if (factionColors.ActiveTwo || factionColors.Active)
                        {
                            if (!factionColors.Extension.factionMaskTag.NullOrEmpty())
                            {
                                //	Log.Message("factionColors.factionMaskTag");
                                mskFaction = "_" + factionColors.Extension.factionMaskTag;
                                //	Log.Message("factionMaskTag: "+msk);
                            }
                        }
                    }
                    // msg
                    if (factionColors.ActiveFaction)
                    {
                        comptype += "FactionActive: " + factionColors.FactionActive + ", FactionActiveTwo: " + factionColors.FactionActiveTwo;
                    }
                    else
                    {
                        comptype += "Active: " + factionColors.Active + ", ActiveTwo: " + factionColors.ActiveTwo;
                    }
                }
                else
                {
                    comptype += "Active: " + compColorable.Active + ", ActiveTwo: " + compColorable.ActiveTwo;
                }

                //	Log.Message(comptype + msg + " present on " + apparel.Wearer +"'s "+ apparel + " colorOne: " + colorOne + ", colorTwo: " + colorTwo);
                //	Log.Message("New graphic for "+rec.sourceApparel.LabelCap+" worn by "+rec.sourceApparel.Wearer.NameShortColored+ " colorOne: "+colorOne+", colorTwo"+ colorTwo);
                if (rec.graphic != null)
                {
                    Graphic newgraphic = rec.graphic.GetColoredVersion(rec.graphic.Shader, colorOne, colorTwo);
                    bool    replaced   = false;
                    if (!apparel.def.apparel.wornGraphicPath.NullOrEmpty())
                    {
                        Graphic replace = AdeptusApparelUtility.ApplyMask(newgraphic, apparel, colorOne, colorTwo, mskVariant, mskFaction);
                        replaced = replace != null;
                        if (replaced)
                        {
                            newgraphic = replace;
                            rec        = new ApparelGraphicRecord(newgraphic, apparel);
                        }
                    }
                    if (!rec.graphic.path.NullOrEmpty())
                    {
                        Texture texture = ContentFinder <Texture2D> .Get(rec.graphic.path + mskFaction, false);

                        if (texture != null)
                        {
                            newgraphic.MatSingle.SetTexture(ShaderPropertyIDs.MaskTex, texture);
                        }
                        newgraphic.MatEast.SetColor(ShaderPropertyIDs.ColorTwo, colorTwo);
                    }
                }
                //	Log.Message(comptype + msg + " present on " + apparel.Wearer +"'s "+ apparel + " colorOne: " + colorOne + ", colorTwo: " + colorTwo);
            }
            if (!apparel.def.apparel.wornGraphicPath.NullOrEmpty())
            {
                if (apparel.def.GetModExtensionFast <ApparelRestrictionDefExtension>() is ApparelRestrictionDefExtension apparelExt)
                {
                    if (!apparelExt.raceSpecifics.NullOrEmpty())
                    {
                        foreach (var item in apparelExt.raceSpecifics)
                        {
                            ThingDef RaceDef = DefDatabase <ThingDef> .GetNamedSilentFail(item.raceDef);

                            if (RaceDef == null)
                            {
                                continue;
                            }
                            if (RaceDef == apparel.Wearer.def)
                            {
                                if (!item.texPath.NullOrEmpty())
                                {
                                    string path;
                                    if (apparel.def.apparel.LastLayer == ApparelLayerDefOf.Overhead || PawnRenderer.RenderAsPack(apparel) || apparel.def.apparel.wornGraphicPath == BaseContent.PlaceholderImagePath)
                                    {
                                        path = apparel.def.apparel.wornGraphicPath + "_" + item.texPath;
                                    }
                                    else
                                    {
                                        path = apparel.def.apparel.wornGraphicPath + "_" + item.texPath + "_" + bodyType.defName;
                                    }
                                    Graphic graphic = GraphicDatabase.Get <Graphic_Multi>(path, apparel.def.apparel.useWornGraphicMask ? ShaderDatabase.CutoutComplex : ShaderDatabase.Cutout, apparel.def.graphicData.drawSize, rec.graphic.color, rec.graphic.colorTwo);
                                    rec = new ApparelGraphicRecord(graphic, apparel);
                                }
                                break;
                            }
                        }
                    }
                }
            }

            /*
             * for (int i = 0; i < apparel.AllComps.Count; i++)
             * {
             *      CompPauldronDrawer drawer = apparel.AllComps[i] as CompPauldronDrawer;
             * if (drawer != null)
             * {
             *              drawer.
             * }
             *
             * }
             */
            apparel.BroadcastCompSignal(CompPauldronDrawer.UpdateString);
        }
        public static bool TryGetGraphicApparel(Apparel apparel, BodyTypeDef bodyType, out ApparelGraphicRecord rec)
        {
            if (bodyType == null)
            {
                Log.Error("Getting apparel graphic with undefined body type.");
                bodyType = BodyTypeDefOf.Male;
            }
            if (apparel.def.apparel.wornGraphicPath.NullOrEmpty())
            {
                rec = new ApparelGraphicRecord(null, null);
                return(false);
            }
            string path   = ((apparel.def.apparel.LastLayer != ApparelLayerDefOf.Overhead && !PawnRenderer.RenderAsPack(apparel) && !(apparel.def.apparel.wornGraphicPath == BaseContent.PlaceholderImagePath)) ? (apparel.def.apparel.wornGraphicPath + "_" + bodyType.defName) : apparel.def.apparel.wornGraphicPath);
            Shader shader = ShaderDatabase.Cutout;

            if (apparel.def.apparel.useWornGraphicMask)
            {
                shader = ShaderDatabase.CutoutComplex;
            }
            Graphic graphic = GraphicDatabase.Get <Graphic_Multi>(path, shader, apparel.def.graphicData.drawSize, apparel.DrawColor);

            rec = new ApparelGraphicRecord(graphic, apparel);
            return(true);
        }