-
-
Notifications
You must be signed in to change notification settings - Fork 565
Description
Describe the bug
CodeMatch.Calls(MethodInfo) does not accept a ConstructorInfo/MethodBase, nor does it check for the Newobj opcode.
This contradicts the XML docs/summary, which states that it tests for a constructor.
Harmony/Harmony/Tools/CodeMatch.cs
Lines 195 to 199 in d0ebd09
| /// <summary>Tests if the code instruction calls the method/constructor</summary> | |
| /// <param name="method">The method</param> | |
| /// <returns>A new code match</returns> | |
| /// | |
| public static CodeMatch Calls(MethodInfo method) => WithOpcodes(CodeInstructionExtensions.opcodesCalling, method); |
CodeMatch.Calls uses opcodesCalling, which only includes Call and Callvirt opcodes.
To Reproduce
Situation 1 (matching any call):
- Create a
CodeMatcher - Call one of the matching methods while passing
CodeMatch.Calls((MethodInfo)null) - The matcher will only match
CallandCallvirtopcodes, ignoring anyNewobjopcodes
Situation 2 (matching specific constructor):
- Create a
CodeMatcher - Get a
ConstructorInfoobject - Call one of the matching methods while passing
CodeMatch.Calls(constructorInfo) - Code cannot compile as there's no matching method signature
Expected behavior
I've expected that either of those 2 would be true:
CodeMatch.Callssummary does not mention testing for a constructorCodeMatch.CallsacceptsMethodBase/ConstructorInfo(possibly as an overload) and matchesNewobjopcode
Screenshots / Code
The following code will go through all instructions and log all matches for CodeMatch.Calls (with null as argument). It'll log every instruction using Call and Callvirt opcodes, but none using Newobj opcodes.
var matcher = new CodeMatcher(instr);
while (true)
{
matcher.MatchEndForward(CodeMatch.Calls((MethodInfo)null));
if (matcher.IsValid)
Console.WriteLine($"{matcher.Instruction}");
else
break;
matcher.Advance();
}Runtime environment (please complete the following information):
- OS: Windows 10, 64bit
- .NET Framework 4.8
- Harmony version 2.4.1
- Name of game or host application: RimWorld