Make the transpiler noisier when it hits an error. Hopefully it'll make breakages more obvious.

This commit is contained in:
lutepickle 2022-05-10 17:44:35 -07:00
parent c0041947d3
commit e377f01a7d
2 changed files with 6 additions and 2 deletions

Binary file not shown.

View file

@ -229,7 +229,7 @@ namespace RJW_Menstruation
private static readonly FieldInfo MinimumRelationshipToHookup = AccessTools.Field(typeof(RJWHookupSettings), nameof(RJWHookupSettings.MinimumRelationshipToHookup)); private static readonly FieldInfo MinimumRelationshipToHookup = AccessTools.Field(typeof(RJWHookupSettings), nameof(RJWHookupSettings.MinimumRelationshipToHookup));
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{ {
object pawn_index = null; LocalBuilder pawn_index = null;
// Like in the last one, we're only interested in the first of each // Like in the last one, we're only interested in the first of each
bool found_first_attractiveness = false; bool found_first_attractiveness = false;
bool found_first_relationship = false; bool found_first_relationship = false;
@ -238,11 +238,13 @@ namespace RJW_Menstruation
// Get where the compiler decided to index the pawn at // Get where the compiler decided to index the pawn at
if (pawn_index is null && instruction.opcode == OpCodes.Stloc_S) // the first stloc.s in the IL is the pawn being loaded out of the list if (pawn_index is null && instruction.opcode == OpCodes.Stloc_S) // the first stloc.s in the IL is the pawn being loaded out of the list
{ // a future RJW or compiler update might change this, or maybe another mod's patch { // a future RJW or compiler update might change this, or maybe another mod's patch
pawn_index = instruction.operand; pawn_index = (LocalBuilder)instruction.operand;
yield return instruction; yield return instruction;
} }
else if (!found_first_attractiveness && instruction.LoadsField(MinimumAttractivenessToHookup)) else if (!found_first_attractiveness && instruction.LoadsField(MinimumAttractivenessToHookup))
{ {
if (pawn_index?.LocalType != typeof(Pawn))
throw new System.InvalidOperationException($"pawn_index is not a Pawn ({pawn_index?.LocalType})");
found_first_attractiveness = true; found_first_attractiveness = true;
yield return new CodeInstruction(OpCodes.Ldarg_0); yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Ldloc_S, pawn_index); yield return new CodeInstruction(OpCodes.Ldloc_S, pawn_index);
@ -250,6 +252,8 @@ namespace RJW_Menstruation
} }
else if (!found_first_relationship && instruction.LoadsField(MinimumRelationshipToHookup)) else if (!found_first_relationship && instruction.LoadsField(MinimumRelationshipToHookup))
{ {
if (pawn_index?.LocalType != typeof(Pawn))
throw new System.InvalidOperationException($"pawn_index is not a Pawn ({pawn_index?.LocalType})");
found_first_relationship = true; found_first_relationship = true;
yield return new CodeInstruction(OpCodes.Ldarg_0); yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Ldloc_S, pawn_index); yield return new CodeInstruction(OpCodes.Ldloc_S, pawn_index);