Fix the transpiler for FindBestPartner

This commit is contained in:
lutepickle 2022-05-09 22:36:53 -07:00
parent d9ab6cdcde
commit 52f9a10496
3 changed files with 11 additions and 3 deletions

Binary file not shown.

View file

@ -229,23 +229,30 @@ 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;
// 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;
foreach(CodeInstruction instruction in instructions) foreach(CodeInstruction instruction in instructions)
{ {
if (!found_first_attractiveness && instruction.LoadsField(MinimumAttractivenessToHookup)) // 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
{ // a future RJW or compiler update might change this, or maybe another mod's patch
pawn_index = instruction.operand;
yield return instruction;
}
else if (!found_first_attractiveness && instruction.LoadsField(MinimumAttractivenessToHookup))
{ {
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.Ldarg_1); yield return new CodeInstruction(OpCodes.Ldloc_S, pawn_index);
yield return CodeInstruction.Call(typeof(FindBestPartner_Patch), nameof(AttractivenessThreshold)); yield return CodeInstruction.Call(typeof(FindBestPartner_Patch), nameof(AttractivenessThreshold));
} }
else if (!found_first_relationship && instruction.LoadsField(MinimumRelationshipToHookup)) else if (!found_first_relationship && instruction.LoadsField(MinimumRelationshipToHookup))
{ {
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.Ldarg_1); yield return new CodeInstruction(OpCodes.Ldloc_S, pawn_index);
yield return CodeInstruction.Call(typeof(FindBestPartner_Patch), nameof(RelationshipThreshold)); yield return CodeInstruction.Call(typeof(FindBestPartner_Patch), nameof(RelationshipThreshold));
} }
else yield return instruction; else yield return instruction;

View file

@ -1,4 +1,5 @@
Version 1.0.6.2 Version 1.0.6.2
- Fix error when a pawn in estrus (with hookup override enabled) looks for partners.
- Teratophiles get the "I came inside" mood buff for ugly partners instead of pretty ones. - Teratophiles get the "I came inside" mood buff for ugly partners instead of pretty ones.
- Locked absorbers (e.g. that guests have) won't get dirty or cause infections. - Locked absorbers (e.g. that guests have) won't get dirty or cause infections.