using System; using System.Collections.Generic; using HarmonyLib; using RimWorld; using UnityEngine; using Verse; namespace Rimworld_Animations_Patch { [StaticConstructorOnStartup] [HarmonyPatch(typeof(ApparelGraphicRecordGetter), "TryGetGraphicApparel")] public static class HarmonyPatch_ApparelGraphicRecordGetter_TryGetGraphicApparel { public static void Postfix(ref bool __result, ref Apparel apparel, ref BodyTypeDef bodyType, ref ApparelGraphicRecord rec) { if (__result == false || apparel == null || bodyType == null || rec.graphic == null || ApparelSettings.cropApparel == false) { return; } // Get graphic Graphic graphic = rec.graphic; // This graphic may need to be masked if the apparel sits on the skin layer and does not cover the legs if (apparel.def.apparel.LastLayer == ApparelLayerDefOf.OnSkin && apparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso) && !apparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Legs)) { Dictionary allGraphics = Traverse.Create(typeof(GraphicDatabase)).Field("allGraphics").GetValue() as Dictionary; GraphicRequest graphicRequest = new GraphicRequest(typeof(Graphic_Multi), graphic.path, ShaderDatabase.CutoutComplex, apparel.def.graphicData.drawSize, apparel.DrawColor, apparel.DrawColor, null, 0, null, "Masks/apparel_shirt_mask_" + bodyType.defName); if (allGraphics.TryGetValue(graphicRequest) == null) { Graphic graphicWithApparelMask = GraphicDatabase.Get(graphic.path, ShaderDatabase.CutoutComplex, apparel.def.graphicData.drawSize, apparel.DrawColor, apparel.DrawColor, null, "Masks/apparel_shirt_mask_" + bodyType.defName); graphic = GraphicMaskingUtility.ApplyGraphicWithMasks(graphic, graphicWithApparelMask, true); DebugMode.Message("Applying apparel mask: Masks/apparel_shirt_mask_" + bodyType.defName + " to " + apparel.def.defName + " (" + graphic.path + ")"); } } rec = new ApparelGraphicRecord(graphic, apparel); } } }