Example #1
0
 public static bool Prefix(PawnGraphicSet __instance)
 {
     if (__instance.pawn.def is RaceAddonThingDef thingDef)
     {
         Pawn          pawn   = __instance.pawn;
         RaceAddonComp racomp = pawn.GetComp <RaceAddonComp>();
         if (racomp.raceAddonGraphicSet == null)
         {
             racomp.raceAddonGraphicSet = new RaceAddonGraphicSet(pawn, racomp);
         }
         TorsoDef torsoDef = racomp.torsoDef;
         __instance.ClearCache();
         RenewalBodyGraphic(__instance, torsoDef.bodyPath.normal, torsoDef.shaderType.Shader, racomp, thingDef.raceAddonSettings.graphicSetting.rottingColor);
         RenewalHeadGraphic(__instance, torsoDef.headPath.normal, torsoDef.shaderType.Shader, racomp, thingDef.raceAddonSettings.graphicSetting.rottingColor);
         __instance.dessicatedGraphic          = GraphicDatabase.Get <Graphic_Multi>(torsoDef.bodyType.bodyDessicatedGraphicPath, ShaderDatabase.Cutout);
         __instance.skullGraphic               = GraphicDatabase.Get <Graphic_Multi>(torsoDef.skullPath, ShaderDatabase.Cutout);
         __instance.headStumpGraphic           = GraphicDatabase.Get <Graphic_Multi>(torsoDef.stumpPath, torsoDef.shaderType.Shader, Vector2.one, racomp.skinColor_Main, racomp.skinColor_Sub);
         __instance.desiccatedHeadStumpGraphic = GraphicDatabase.Get <Graphic_Multi>(torsoDef.stumpPath, torsoDef.shaderType.Shader, Vector2.one, thingDef.raceAddonSettings.graphicSetting.rottingColor);
         if (pawn.story.hairDef is ImprovedHairDef hairDef)
         {
             __instance.hairGraphic = GraphicDatabase.Get <Graphic_Multi>(hairDef.texPath, hairDef.shaderType.Shader, Vector2.one, pawn.story.hairColor, racomp.hairColor_Sub);
             racomp.raceAddonGraphicSet.hairGraphic = GraphicDatabase.Get <Graphic_Multi>(hairDef.lowerPath, hairDef.shaderType.Shader, Vector2.one, pawn.story.hairColor, racomp.hairColor_Sub);
         }
         else
         {
             __instance.hairGraphic = GraphicDatabase.Get <Graphic_Multi>(pawn.story.hairDef.texPath, ShaderDatabase.Cutout, Vector2.one, pawn.story.hairColor);
             racomp.raceAddonGraphicSet.hairGraphic = null;
         }
         __instance.ResolveApparelGraphics();
         return(false);
     }
     return(true);
 }
 private static void ResolveHatDraw(RaceAddonComp racomp, RaceAddonThingDef thingDef, Apparel apparel)
 {
     if (racomp.raceAddonGraphicSet.presentAgeSetting.hideHat)
     {
         racomp.raceAddonGraphicSet.drawHat = false;
         return;
     }
     if (thingDef.raceAddonSettings.graphicSetting.drawHat)
     {
         if (thingDef.raceAddonSettings.graphicSetting.drawHat_Exceptions.Contains(apparel.def))
         {
             racomp.raceAddonGraphicSet.drawHat = false;
         }
         else
         {
             racomp.raceAddonGraphicSet.drawHat = true;
         }
     }
     else
     {
         if (thingDef.raceAddonSettings.graphicSetting.drawHat_Exceptions.Contains(apparel.def))
         {
             racomp.raceAddonGraphicSet.drawHat = true;
         }
         else
         {
             racomp.raceAddonGraphicSet.drawHat = false;
         }
     }
 }
Example #3
0
        private static void GetModifiedValue(RaceAddonComp racomp, ref Quaternion bodyQuat, ref Quaternion headQuat, ref Vector3 bodyLoc, ref Vector3 headLoc,
                                             Pawn pawn, ref bool renderBody, ref Rot4 bodyFacing, ref Rot4 headFacing, bool portrait)
        {
            bool headAnimation = false;

            if (!portrait && pawn.Awake())
            {
                if (racomp.raceAddonGraphicSet.headRotator != null && !pawn.Drafted)
                {
                    headQuat *= racomp.raceAddonGraphicSet.headRotator.GetQuat();
                }
                if (racomp.raceAddonGraphicSet.headTargeter != null && !pawn.Downed)
                {
                    var initialRot = headFacing;
                    headFacing.Rotate(racomp.raceAddonGraphicSet.headTargeter.RotDirection);
                    if (initialRot != headFacing)
                    {
                        headAnimation = true;
                    }
                }
            }
            if (!portrait && headAnimation)
            {
                racomp.torsoDef.headTargetingOffsets.Correction(ref headLoc, bodyFacing, headFacing);
            }
            if (portrait || renderBody)
            {
                headLoc.x *= racomp.raceAddonGraphicSet.presentAgeSetting.drawSize.head.x;
                headLoc.z *= racomp.raceAddonGraphicSet.presentAgeSetting.drawSize.head.y;
            }
            headLoc = bodyLoc + (bodyQuat * headLoc);
        }
Example #4
0
 public FaceGraphicSet(Pawn pawn, SavedFaceData data, FaceDef def, RaceAddonComp racomp)
 {
     this.pawn   = pawn;
     this.data   = data;
     this.def    = def;
     this.racomp = racomp;
 }
 private static void ResolveHairDraw(RaceAddonComp racomp, RaceAddonThingDef thingDef, Apparel apparel)
 {
     if (racomp.raceAddonGraphicSet.drawHat)
     {
         if (thingDef.raceAddonSettings.graphicSetting.drawHair)
         {
             if (thingDef.raceAddonSettings.graphicSetting.drawHair_Exceptions.Find(x => x.thingDef == apparel.def) is var preset && preset != null)
             {
                 if (preset.hairOption == 0)
                 {
                     racomp.raceAddonGraphicSet.drawUpperHair = false;
                     racomp.raceAddonGraphicSet.drawLowerHair = false;
                 }
                 else if (preset.hairOption == 1)
                 {
                     racomp.raceAddonGraphicSet.drawUpperHair = false;
                     racomp.raceAddonGraphicSet.drawLowerHair = true;
                 }
                 else if (preset.hairOption == 2)
                 {
                     racomp.raceAddonGraphicSet.drawUpperHair = true;
                     racomp.raceAddonGraphicSet.drawLowerHair = false;
                 }
             }
             else
             {
                 racomp.raceAddonGraphicSet.drawUpperHair = true;
                 racomp.raceAddonGraphicSet.drawLowerHair = true;
             }
         }
         else
         {
             if (thingDef.raceAddonSettings.graphicSetting.drawHair_Exceptions.Find(x => x.thingDef == apparel.def) is var preset && preset != null)
             {
                 if (preset.hairOption == 0)
                 {
                     racomp.raceAddonGraphicSet.drawUpperHair = true;
                     racomp.raceAddonGraphicSet.drawLowerHair = true;
                 }
                 else if (preset.hairOption == 1)
                 {
                     racomp.raceAddonGraphicSet.drawUpperHair = true;
                     racomp.raceAddonGraphicSet.drawLowerHair = false;
                 }
                 else if (preset.hairOption == 2)
                 {
                     racomp.raceAddonGraphicSet.drawUpperHair = false;
                     racomp.raceAddonGraphicSet.drawLowerHair = true;
                 }
             }
        public static void Postfix(PawnGraphicSet __instance)
        {
            if (__instance.pawn.def is RaceAddonThingDef thingDef)
            {
                Pawn          pawn   = __instance.pawn;
                RaceAddonComp racomp = pawn.GetComp <RaceAddonComp>();

                if (pawn.apparel.WornApparel.Find((Apparel x) => x.def.apparel.LastLayer == ApparelLayerDefOf.Overhead) is Apparel apparel)
                {
                    ResolveHatDraw(racomp, thingDef, apparel);
                    ResolveHairDraw(racomp, thingDef, apparel);
                }
            }
        }
Example #7
0
 private static bool Prefix(Pawn ___pawn, ref Color __result)
 {
     if (___pawn.def is RaceAddonThingDef)
     {
         RaceAddonComp racomp = ___pawn.GetComp <RaceAddonComp>();
         if (racomp.savedSkinData != null)
         {
             __result = racomp.savedSkinData.color1;
         }
         else
         {
             __result = Color.white;
         }
         return(false);
     }
     return(true);
 }
Example #8
0
        public RaceAddonGraphicSet(Pawn pawn, RaceAddonComp racomp)
        {
            if (pawn.def is RaceAddonThingDef thingDef)
            {
                this.pawn   = pawn;
                this.racomp = racomp;

                presentAgeSetting = thingDef.raceAddonSettings.ageSettings.GetPresent(pawn);

                headMeshSet = new GraphicMeshSet((1.5f * presentAgeSetting.drawSize.head.x) * racomp.drawSizeDeviation, (1.5f * presentAgeSetting.drawSize.head.y) * racomp.drawSizeDeviation);
                bodyMeshSet = new GraphicMeshSet((1.5f * presentAgeSetting.drawSize.body.x) * racomp.drawSizeDeviation, (1.5f * presentAgeSetting.drawSize.body.y) * racomp.drawSizeDeviation);
                //equipmentMeshSet = new GraphicMeshSet(presentAgeSetting.drawSize.equipment.x, presentAgeSetting.drawSize.equipment.y);
                racomp.cachedDrawLocCorrection = 0f;
                if (thingDef.raceAddonSettings.graphicSetting.footPositionCorrection_DrawSize)
                {
                    racomp.cachedDrawLocCorrection += (1.5f - (1.5f * presentAgeSetting.drawSize.body.y)) / 2f;
                }
                if (thingDef.raceAddonSettings.graphicSetting.footPositionCorrection_DrawSizeCurve)
                {
                    racomp.cachedDrawLocCorrection += (1.5f - (1.5f * racomp.drawSizeDeviation)) / 2f;
                }

                eyeBlinker   = thingDef.raceAddonSettings.graphicSetting.eyeBlink ? new EyeBlinker() : null;
                headRotator  = thingDef.raceAddonSettings.graphicSetting.headAnimation ? new HeadRotator() : null;
                headTargeter = thingDef.raceAddonSettings.graphicSetting.headTargeting ? new HeadTargeter(pawn) : null;

                upperFaceGraphic = racomp.upperFaceDef == null ? null : new FaceGraphicRecord(pawn, racomp.upperFaceDef, racomp.faceColor_Main, racomp.faceColor_Sub, thingDef.raceAddonSettings.graphicSetting.fixedUpperFace);
                lowerFaceGraphic = racomp.lowerFaceDef == null ? null : new FaceGraphicRecord(pawn, racomp.lowerFaceDef, racomp.faceColor_Main, racomp.faceColor_Sub, thingDef.raceAddonSettings.graphicSetting.fixedLowerFace);
                foreach (var addonData in racomp.addonDatas)
                {
                    var linkedBodyPart = addonData.addonDef.linkedBodyPart.GetBodyPartRecord(pawn.def.race.body);
                    addonGraphics.Add(new AddonGraphicRecord(addonData, linkedBodyPart, thingDef.raceAddonSettings.graphicSetting.rottingColor));
                }
            }
            else
            {
                RaceAddon.Notify("RaceAddonGraphicSet Init failure, Unkown ThingDef => " + pawn.Name.ToStringShort, true);
            }
        }
Example #9
0
        private static void Postfix(ref Pawn __result, ref PawnGenerationRequest request)
        {
            RaceAddonComp racomp = null;

            if (__result.def is RaceAddonThingDef thingDef)
            {
                // get backstorydef
                SimpleBackstoryDef simpleBackstoryDef = null;
                foreach (var backstory in __result.story.AllBackstories)
                {
                    if (DefDatabase <SimpleBackstoryDef> .AllDefsListForReading.Find(x => x.defName == backstory.identifier) is var def && def != null)
                    {
                        simpleBackstoryDef = def;
                    }
                }

                // make default setting
                racomp = __result.GetComp <RaceAddonComp>();

                float maleChance = (simpleBackstoryDef != null && simpleBackstoryDef.maleChance >= 0) ? simpleBackstoryDef.maleChance : thingDef.raceAddonSettings.basicSetting.maleChance;
                __result.gender = GetGender(maleChance, request.FixedGender);
                var gender = __result.gender;

                __result.Name = PawnBioAndNameGenerator.GeneratePawnName(__result, NameStyle.Full, request.FixedLastName);

                racomp.drawSize = RaceAddonTools.GetPawnDrawSize(__result, thingDef);
                var drawSize = thingDef.raceAddonSettings.graphicSetting.drawSize[racomp.drawSize];

                AppearanceDef appearanceDef = null;
                var           list          = (simpleBackstoryDef != null && simpleBackstoryDef.raceAppearances != null) ? simpleBackstoryDef.raceAppearances : thingDef.raceAddonSettings.graphicSetting.raceAppearances;
                if (drawSize.apparanceOverwrite.FindAll(x => x.gender == Gender.None || x.gender == gender) is var list2 && list2.Count > 0)
                {
                    appearanceDef = list2.RandomElementByWeight(x => x.weight).appearanceDef;
                }
                else if (list.FindAll(x => x.gender == Gender.None || x.gender == gender) is var list3 && list3.Count > 0)
                {
                    appearanceDef = list3.RandomElementByWeight(x => x.weight).appearanceDef;
                }
Example #10
0
 public static void RenewalHeadGraphic(PawnGraphicSet pawnGraphicSet, string headPath, Shader shader, RaceAddonComp racomp, Color rottingColor)
 {
     pawnGraphicSet.headGraphic           = GraphicDatabase.Get <Graphic_Multi>(headPath, shader, Vector2.one, racomp.skinColor_Main, racomp.skinColor_Sub);
     pawnGraphicSet.desiccatedHeadGraphic = GraphicDatabase.Get <Graphic_Multi>(headPath, shader, Vector2.one, rottingColor);
 }
Example #11
0
 public static void RenewalBodyGraphic(PawnGraphicSet pawnGraphicSet, string bodyPath, Shader shader, RaceAddonComp racomp, Color rottingColor)
 {
     pawnGraphicSet.nakedGraphic   = GraphicDatabase.Get <Graphic_Multi>(bodyPath, shader, Vector2.one, racomp.skinColor_Main, racomp.skinColor_Sub);
     pawnGraphicSet.rottingGraphic = GraphicDatabase.Get <Graphic_Multi>(bodyPath, shader, Vector2.one, rottingColor);
     Traverse.Create(pawnGraphicSet).Field <int>("cachedMatsBodyBaseHash").Value = -1;
 }
 private 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;
         var        flag1    = false;
         if (!portrait && ___pawn.Awake())
         {
             if (racomp.headRotator != null && !___pawn.Drafted)
             {
                 headQuat *= racomp.headRotator.GetQuat();
             }
             if (racomp.headTargeter != null && !___pawn.Downed)
             {
                 var initialRot = headFacing;
                 headFacing.Rotate(racomp.headTargeter.RotDirection);
                 if (initialRot != headFacing)
                 {
                     flag1 = true;
                 }
             }
         }
         //====================================================================================================
         Mesh bodyMesh = racomp.bodyMeshSet.MeshAt(bodyFacing);
         //====================================================================================================
         Mesh headMesh = racomp.headMeshSet.MeshAt(headFacing);
         //====================================================================================================
         Vector3 bodyLoc = rootLoc;
         //bodyLoc.y += 0.022482f;
         bodyLoc.y += 0.022482f;
         //====================================================================================================
         Vector3 headLoc = __instance.BaseHeadOffsetAt(bodyFacing);
         if (portrait || renderBody)
         {
             headLoc.x *= thingDef.raceAddonSettings.graphicSetting.drawSize[racomp.drawSize].headSize.x;
             headLoc.z *= thingDef.raceAddonSettings.graphicSetting.drawSize[racomp.drawSize].headSize.y;
         }
         if (!portrait && flag1)
         {
             if (headFacing == Rot4.South)
             {
                 headLoc += racomp.savedHeadData.def.headTargetingOffsets.south;
             }
             else if (headFacing == Rot4.East)
             {
                 headLoc += racomp.savedHeadData.def.headTargetingOffsets.east;
             }
             else if (headFacing == Rot4.West)
             {
                 headLoc += racomp.savedHeadData.def.headTargetingOffsets.west;
             }
             else
             {
                 headLoc += racomp.savedHeadData.def.headTargetingOffsets.north;
             }
         }
         headLoc = bodyLoc + (bodyQuat * headLoc);
         //====================================================================================================
         List <int> shell = new List <int>();
         List <int> hat   = new List <int>();
         List <ApparelGraphicRecord> apparelGraphics = __instance.graphics.apparelGraphics;
         for (int i = 0; i < apparelGraphics.Count; i++)
         {
             if (apparelGraphics[i].sourceApparel.def.apparel.LastLayer == ApparelLayerDefOf.Shell)
             {
                 shell.Add(i);
             }
             if (apparelGraphics[i].sourceApparel.def.apparel.LastLayer == ApparelLayerDefOf.Overhead)
             {
                 hat.Add(i);
             }
         }
         //====================================================================================================
         Vector3 drawLoc = new Vector3();
         if (renderBody)
         {
             //Draw Body, Apparel
             drawLoc = DrawLoc(bodyLoc, 0.0002f);
             List <Material> list = __instance.graphics.MatsBodyBaseAt(bodyFacing, bodyDrawType);
             for (int i = 0; i < list.Count; i++)
             {
                 Material mat = OverrideMaterialIfNeeded(list[i], ___pawn, __instance.graphics);
                 GenDraw.DrawMeshNowOrLater(bodyMesh, drawLoc, bodyQuat, mat, portrait);
                 drawLoc.y += 0.0001f;
             }
             //Draw Shell
             if (shell.Count() > 0)
             {
                 drawLoc = DrawLoc(bodyLoc, 0.0009f);
                 foreach (int i in shell)
                 {
                     Material mat = apparelGraphics[i].graphic.MatAt(bodyFacing);
                     mat = OverrideMaterialIfNeeded(mat, ___pawn, __instance.graphics);
                     GenDraw.DrawMeshNowOrLater(bodyMesh, drawLoc, bodyQuat, mat, portrait);
                 }
             }
             //Draw Wound
             drawLoc = DrawLoc(bodyLoc, 0.0020f);
             if (bodyDrawType == RotDrawMode.Fresh)
             {
                 ___woundOverlays.RenderOverBody(drawLoc, bodyMesh, bodyQuat, portrait);
             }
             //Draw Body Addons
             if (racomp.bodyAddonGraphicSets != null)
             {
                 foreach (var set in racomp.bodyAddonGraphicSets)
                 {
                     if (set.draw)
                     {
                         drawLoc = bodyLoc;
                         ResolveAddonLoc(ref drawLoc, set.data.def, bodyFacing);
                         Material mat = set.MatAt(bodyFacing, bodyDrawType);
                         if (mat != null)
                         {
                             mat = OverrideMaterialIfNeeded(mat, ___pawn, __instance.graphics);
                             GenDraw.DrawMeshNowOrLater(bodyMesh, drawLoc, bodyQuat, mat, portrait);
                         }
                     }
                 }
             }
         }
         if (__instance.graphics.headGraphic != null)
         {
             //Draw Head
             Material headMat = __instance.graphics.HeadMatAt(headFacing, bodyDrawType, headStump);
             if (headMat != null)
             {
                 drawLoc = DrawLoc(headLoc, 0.0011f);
                 GenDraw.DrawMeshNowOrLater(headMesh, drawLoc, headQuat, headMat, portrait);
             }
             //Draw Hat or Mask
             bool flag2 = false;
             if (!portrait || !Prefs.HatsOnlyOnMap)
             {
                 if (hat.Count() > 0 && racomp.drawHat)
                 {
                     foreach (int i in hat)
                     {
                         if (apparelGraphics[i].sourceApparel.def.apparel.hatRenderedFrontOfFace)                                 //Mask
                         {
                             flag2   = true;
                             drawLoc = headFacing == Rot4.North ? DrawLoc(headLoc, -0.0001f) : DrawLoc(headLoc, 0.0017f);
                         }
                         else
                         {
                             drawLoc = DrawLoc(headLoc, 0.0015f);                                     //Hat
                         }
                         Material mat = apparelGraphics[i].graphic.MatAt(headFacing);
                         mat = OverrideMaterialIfNeeded(mat, ___pawn, __instance.graphics);
                         GenDraw.DrawMeshNowOrLater(headMesh, drawLoc, headQuat, mat, portrait);
                     }
                 }
             }
             if (bodyDrawType != RotDrawMode.Dessicated && !headStump)
             {
                 //Draw Face
                 if (racomp.upperFaceGraphicSet != null)
                 {
                     drawLoc = DrawLoc(headLoc, 0.0014f);
                     Material mat = OverrideMaterialIfNeeded(racomp.upperFaceGraphicSet.MatAt(headFacing, portrait), ___pawn, __instance.graphics);
                     GenDraw.DrawMeshNowOrLater(headMesh, drawLoc, headQuat, mat, portrait);
                 }
                 if (racomp.lowerFaceGraphicSet != null)
                 {
                     drawLoc = DrawLoc(headLoc, 0.0012f);
                     Material mat = OverrideMaterialIfNeeded(racomp.lowerFaceGraphicSet.MatAt(headFacing, portrait), ___pawn, __instance.graphics);
                     GenDraw.DrawMeshNowOrLater(headMesh, drawLoc, headQuat, mat, portrait);
                 }
                 //Draw Hair
                 if (flag2 || racomp.drawUpperHair)
                 {
                     drawLoc = DrawLoc(headLoc, 0.0013f);
                     Material mat = __instance.graphics.HairMatAt(headFacing);
                     mat = OverrideMaterialIfNeeded(mat, ___pawn, __instance.graphics);
                     GenDraw.DrawMeshNowOrLater(headMesh, drawLoc, headQuat, mat, portrait);
                 }
                 if (racomp.improvedHairGraphic != null)
                 {
                     if (flag2 || racomp.drawLowerHair)
                     {
                         if (___pawn.InBed() && ((___pawn.story.hairDef as ImprovedHairDef).drawnInBed) || renderBody)
                         {
                             drawLoc = DrawLoc(headLoc, 0.0001f);
                             Material mat = racomp.improvedHairGraphic.MatAt(headFacing);
                             mat = OverrideMaterialIfNeeded(mat, ___pawn, __instance.graphics);
                             GenDraw.DrawMeshNowOrLater(headMesh, drawLoc, headQuat, mat, portrait);
                         }
                     }
                 }
                 //Draw Head Addons
                 if (racomp.headAddonGraphicSets != null)
                 {
                     foreach (var set in racomp.headAddonGraphicSets)
                     {
                         if (set.draw)
                         {
                             drawLoc = headLoc;
                             ResolveAddonLoc(ref drawLoc, set.data.def, headFacing);
                             Material mat = set.MatAt(headFacing, bodyDrawType);
                             if (mat != null)
                             {
                                 mat = OverrideMaterialIfNeeded(mat, ___pawn, __instance.graphics);
                                 GenDraw.DrawMeshNowOrLater(headMesh, drawLoc, headQuat, mat, portrait);
                             }
                         }
                     }
                 }
             }
         }
         if (!portrait)
         {
             drawLoc = DrawLoc(bodyLoc, 0.01f);
             DrawEquipment(___pawn, racomp.equipmentMeshSet.MeshAt(bodyFacing), drawLoc);
             //Draw Apparel Extras
             if (___pawn.apparel != null)
             {
                 List <Apparel> wornApparel = ___pawn.apparel.WornApparel;
                 for (int l = 0; l < wornApparel.Count; l++)
                 {
                     wornApparel[l].DrawWornExtras();
                 }
             }
             //Draw Overlays
             drawLoc = DrawLoc(bodyLoc, 0.02f);
             ___statusOverlays.RenderStatusOverlays(drawLoc, bodyQuat, headMesh);
         }
         return(false);
     }
     return(true);
 }
Example #13
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);
        }
Example #14
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);
        }