58 lines
2.5 KiB
C#
58 lines
2.5 KiB
C#
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
|
|
{
|
|
static bool _checkedForSizedApparel;
|
|
static bool _isRunningSizedApparel;
|
|
|
|
// Not compatible with SizedApparel - running Graphic.Blit on the resized apparel will cause the pawn to turn invisible for one facing
|
|
public static bool IsRunningSizedApparel
|
|
{
|
|
get
|
|
{
|
|
if (_checkedForSizedApparel == false)
|
|
{
|
|
_isRunningSizedApparel = LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "OTYOTY.SizedApparel");
|
|
_checkedForSizedApparel = true;
|
|
}
|
|
|
|
return _isRunningSizedApparel;
|
|
}
|
|
}
|
|
|
|
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 || IsRunningSizedApparel) 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<GraphicRequest, Graphic> allGraphics = Traverse.Create(typeof(GraphicDatabase)).Field("allGraphics").GetValue() as Dictionary<GraphicRequest, Graphic>;
|
|
GraphicRequest graphicRequest = new GraphicRequest(typeof(Graphic_Multi), graphic.path, ShaderDatabase.CutoutComplex, graphic.drawSize, apparel.DrawColor, apparel.DrawColor, null, 0, null, "Masks/apparel_shirt_mask_" + bodyType.defName);
|
|
|
|
if (allGraphics.TryGetValue(graphicRequest) == null)
|
|
{
|
|
Graphic graphicWithApparelMasks = GraphicDatabase.Get<Graphic_Multi>(graphic.path, ShaderDatabase.CutoutComplex, graphic.drawSize, apparel.DrawColor, apparel.DrawColor, null, "Masks/apparel_shirt_mask_" + bodyType.defName);
|
|
graphic = GraphicMaskingUtility.ApplyGraphicMasks(graphic, graphicWithApparelMasks, true);
|
|
|
|
//DebugMode.Message("Applying apparel mask: Masks/apparel_shirt_mask_" + bodyType.defName + " to " + apparel.def.defName + " (" + graphic.path + ")");
|
|
}
|
|
}
|
|
|
|
rec = new ApparelGraphicRecord(graphic, apparel);
|
|
}
|
|
}
|
|
} |