rimworld-animations-patch_m.../Source/Scripts/Patches/HarmonyPatch_VisiblePants.cs
AbstractConcept 8e6918ae70 First commit
2022-09-09 20:22:08 -05:00

76 lines
No EOL
2.8 KiB
C#

using System;
using System.Collections.Generic;
using HarmonyLib;
using RimWorld;
using UnityEngine;
using Verse;
namespace Rimworld_Animations_Patch
{
[StaticConstructorOnStartup]
public static class HarmonyPatch_VisiblePants
{
static HarmonyPatch_VisiblePants()
{
try
{
((Action)(() =>
{
if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "XeoNovaDan.VisiblePants"))
{
(new Harmony("HeyLover")).Patch(AccessTools.Method(typeof(ApparelGraphicRecordGetter), "TryGetGraphicApparel"),
prefix: new HarmonyMethod(AccessTools.Method(typeof(HarmonyPatch_VisiblePants), "Prefix_ApparelGraphicRecordGetter_TryGetGraphicApparel")));
}
}))();
}
catch (TypeLoadException) { }
}
public static bool Prefix_ApparelGraphicRecordGetter_TryGetGraphicApparel(ref bool __result, ref Apparel apparel, ref BodyTypeDef bodyType, out ApparelGraphicRecord rec)
{
rec = new ApparelGraphicRecord(null, null);
if (bodyType == null)
{
Log.Error("Found apparel graphic with undefined body type.");
bodyType = BodyTypeDefOf.Male;
}
if (apparel == null || apparel.WornGraphicPath.NullOrEmpty())
{
rec = new ApparelGraphicRecord(null, null);
__result = false;
return false;
}
string path;
if (apparel.def.apparel.LastLayer == ApparelLayerDefOf.Overhead || apparel.def.apparel.LastLayer == ApparelLayerDefOf.EyeCover || PawnRenderer.RenderAsPack(apparel) || apparel.WornGraphicPath == BaseContent.PlaceholderImagePath || apparel.WornGraphicPath == BaseContent.PlaceholderGearImagePath)
{ path = apparel.WornGraphicPath; }
else
{ path = apparel.WornGraphicPath + "_" + bodyType.defName; }
Shader shader = ShaderDatabase.Cutout;
if (apparel.def.apparel.useWornGraphicMask)
{ shader = ShaderDatabase.CutoutComplex; }
// Load the standard apparel graphic
Graphic graphic = GraphicDatabase.Get<Graphic_Multi>(path, shader, apparel.def.graphicData.drawSize, apparel.DrawColor);
// 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))
{
Graphic graphicWithApparelMask = GraphicDatabase.Get<Graphic_Multi>(path, ShaderDatabase.CutoutComplex, apparel.def.graphicData.drawSize, apparel.DrawColor, apparel.DrawColor, null, "Masks/apparel_shirt_mask_" + bodyType.defName);
graphic = GraphicMaskingUtility.ApplyGraphicWithMasks(graphic, graphicWithApparelMask, true);
//Log.Message("Applying apparel mask: Masks/apparel_shirt_mask_" + bodyType.defName + " to " + apparel.def.defName);
}
rec = new ApparelGraphicRecord(graphic, apparel);
__result = true;
return false;
}
}
}