44 lines
1.5 KiB
C#
44 lines
1.5 KiB
C#
using HarmonyLib;
|
|
using rjw;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Reflection.Emit;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Verse;
|
|
|
|
namespace rjwquirks.HarmonyPatches
|
|
{
|
|
[HarmonyPatch(typeof(Hediff_PartBaseArtifical))]
|
|
public class Patch_Hediff_PartBaseArtifical
|
|
{
|
|
[HarmonyTranspiler]
|
|
[HarmonyPatch(nameof(Hediff_PartBaseArtifical.Tick))]
|
|
public static IEnumerable<CodeInstruction> ChangeMaxEggsSize(IEnumerable<CodeInstruction> instructions)
|
|
{
|
|
FieldInfo Pawn = AccessTools.Field(typeof(Hediff_PartBaseArtifical), nameof(Hediff_PartBaseArtifical.pawn));
|
|
MethodInfo EggSize = AccessTools.Method(typeof(Patch_Hediff_PartBaseArtifical), nameof(EditMaxEggsSize));
|
|
|
|
foreach (CodeInstruction i in instructions)
|
|
{
|
|
if (i.opcode == OpCodes.Ldc_R4 && i.operand as string == "0.0")
|
|
{
|
|
yield return new CodeInstruction(OpCodes.Ldfld, Pawn);
|
|
yield return new CodeInstruction(OpCodes.Ldloc_3);
|
|
yield return new CodeInstruction(OpCodes.Call, EggSize);
|
|
}
|
|
|
|
yield return i;
|
|
}
|
|
}
|
|
|
|
public static void EditMaxEggsSize(Pawn pawn, float eggsSize)
|
|
{
|
|
if (pawn.GetQuirks() != null)
|
|
pawn.GetQuirks().ApplyValueModifiers("maxEggsSize", ref eggsSize);
|
|
}
|
|
}
|
|
}
|