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