//    [HarmonyPostfix]
 public static void Postfix(ref Pawn pawn, PawnGenerationRequest request)
 {
     foreach (Apparel thing in pawn.apparel.WornApparel)
     {
         CompColorableTwoFaction FactionColorable = thing.TryGetCompFast <CompColorableTwoFaction>();
         if (FactionColorable != null && pawn.Faction != null)
         {
             FactionColorable.FactionDef = pawn.Faction.def;
         }
     }
 }
Example #2
0
        public static void Prefix(Thing __instance, Graphic __result, ref Graphic ___graphicInt)
        {
            if (__instance != null)
            {
                Pawn pawn = __instance as Pawn;
                if (pawn != null)
                {
                    //    return;
                }

                CompColorableTwo colorableTwo = __instance.TryGetCompFast <CompColorableTwo>();
                if (colorableTwo != null)
                {
                    Color colorOne = colorableTwo.Color;
                    Color colorTwo = colorableTwo.ColorTwo;
                    CompColorableTwoFaction factionColorable = __instance.TryGetCompFast <CompColorableTwoFaction>();
                    if (factionColorable != null)
                    {
                        if (factionColorable.Active)
                        {
                            colorOne = factionColorable.Color;
                        }
                        if (factionColorable.ActiveTwo)
                        {
                            colorTwo = factionColorable.ColorTwo;
                        }
                    }
                    if (___graphicInt == null)
                    {
                        //    Log.Message(__instance.LabelCap + " CompColorableTwo Color: " + colorableTwo.Color+ " ColorTwo: " + colorableTwo.ColorTwo);
                        if (__instance.def.graphicData == null)
                        {
                            ___graphicInt = BaseContent.BadGraphic;
                        }
                        Graphic Graphic = __instance.def.graphicData.GraphicColoredFor(__instance);
                        if (Graphic != null)
                        {
                            //    Log.Message(__instance.LabelCap + " colouring graphic");
                            Graphic = Graphic.GetColoredVersion(ShaderTypeDefOf.CutoutComplex.Shader, colorOne, colorTwo);
                            bool flag = Graphic as Graphic_RandomRotated != null;
                            if (flag)
                            {
                                //    Log.Message(__instance.LabelCap + " setting graphic");
                                ___graphicInt = new Graphic_RandomRotated(Graphic, 35f);
                            }
                            else
                            {
                                ___graphicInt = Graphic;
                            }
                        }
                    }
                }
            }
        }
        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);
        }