Use 'original' parameter for the birth outcome patch instead of looking up the function again

This commit is contained in:
lutepickle 2024-05-06 19:22:37 -07:00
parent def0c04838
commit c402f871b6
2 changed files with 2 additions and 4 deletions

Binary file not shown.

View file

@ -175,13 +175,11 @@ namespace RJW_Menstruation
return baby; return baby;
} }
private static readonly MethodInfo ApplyBirthOutcome_NewTemp = typeof(PregnancyUtility).GetMethod(nameof(PregnancyUtility.ApplyBirthOutcome_NewTemp));
private static readonly int birtherThing = ApplyBirthOutcome_NewTemp.GetParameters().FirstIndexOf(parameter => parameter.Name == "birtherThing" && parameter.ParameterType == typeof(Thing));
private static readonly MethodInfo GeneratePawn = typeof(PawnGenerator).GetMethod(nameof(PawnGenerator.GeneratePawn), new Type[] {typeof (PawnGenerationRequest)}); private static readonly MethodInfo GeneratePawn = typeof(PawnGenerator).GetMethod(nameof(PawnGenerator.GeneratePawn), new Type[] {typeof (PawnGenerationRequest)});
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase original)
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{ {
bool methodPatched = false; bool methodPatched = false;
int birtherThing = original.GetParameters().FirstIndexOf(parameter => parameter.Name == "birtherThing" && parameter.ParameterType == typeof(Thing));
if (birtherThing < 0) throw new InvalidOperationException("Could not locate index of birtherThing"); if (birtherThing < 0) throw new InvalidOperationException("Could not locate index of birtherThing");
if (GeneratePawn?.ReturnType != typeof(Pawn)) throw new InvalidOperationException("GeneratePawn not found"); if (GeneratePawn?.ReturnType != typeof(Pawn)) throw new InvalidOperationException("GeneratePawn not found");
foreach (CodeInstruction instruction in instructions) foreach (CodeInstruction instruction in instructions)