summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/ModLoading/Framework/RecursiveRewriter.cs50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/SMAPI/Framework/ModLoading/Framework/RecursiveRewriter.cs b/src/SMAPI/Framework/ModLoading/Framework/RecursiveRewriter.cs
index 3b8cda88..a0f075bd 100644
--- a/src/SMAPI/Framework/ModLoading/Framework/RecursiveRewriter.cs
+++ b/src/SMAPI/Framework/ModLoading/Framework/RecursiveRewriter.cs
@@ -82,6 +82,9 @@ namespace StardewModdingAPI.Framework.ModLoading.Framework
foreach (ParameterDefinition parameter in method.Parameters)
anyRewritten |= this.RewriteTypeReference(parameter.ParameterType, newType => parameter.ParameterType = newType);
+ foreach (var methodOverride in method.Overrides)
+ anyRewritten |= this.RewriteMethodReference(methodOverride);
+
if (method.HasBody)
{
foreach (VariableDefinition variable in method.Body.Variables)
@@ -133,25 +136,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Framework
// method reference
MethodReference methodRef = RewriteHelper.AsMethodReference(instruction);
if (methodRef != null)
- {
- rewritten |= this.RewriteTypeReference(methodRef.DeclaringType, newType =>
- {
- // note: generic methods are wrapped into a MethodSpecification which doesn't allow changing the
- // declaring type directly. For our purposes we want to change all generic versions of a matched
- // method anyway, so we can use GetElementMethod to get the underlying method here.
- methodRef.GetElementMethod().DeclaringType = newType;
- });
- rewritten |= this.RewriteTypeReference(methodRef.ReturnType, newType => methodRef.ReturnType = newType);
-
- foreach (var parameter in methodRef.Parameters)
- rewritten |= this.RewriteTypeReference(parameter.ParameterType, newType => parameter.ParameterType = newType);
-
- if (methodRef is GenericInstanceMethod genericRef)
- {
- for (int i = 0; i < genericRef.GenericArguments.Count; i++)
- rewritten |= this.RewriteTypeReference(genericRef.GenericArguments[i], newType => genericRef.GenericArguments[i] = newType);
- }
- }
+ this.RewriteMethodReference(methodRef);
// type reference
if (instruction.Operand is TypeReference typeRef)
@@ -169,6 +154,33 @@ namespace StardewModdingAPI.Framework.ModLoading.Framework
return rewritten;
}
+ /// <summary>Rewrite a method reference if needed.</summary>
+ /// <param name="methodRef">The current method reference.</param>
+ private bool RewriteMethodReference(MethodReference methodRef)
+ {
+ bool rewritten = false;
+
+ rewritten |= this.RewriteTypeReference(methodRef.DeclaringType, newType =>
+ {
+ // note: generic methods are wrapped into a MethodSpecification which doesn't allow changing the
+ // declaring type directly. For our purposes we want to change all generic versions of a matched
+ // method anyway, so we can use GetElementMethod to get the underlying method here.
+ methodRef.GetElementMethod().DeclaringType = newType;
+ });
+ rewritten |= this.RewriteTypeReference(methodRef.ReturnType, newType => methodRef.ReturnType = newType);
+
+ foreach (var parameter in methodRef.Parameters)
+ rewritten |= this.RewriteTypeReference(parameter.ParameterType, newType => parameter.ParameterType = newType);
+
+ if (methodRef is GenericInstanceMethod genericRef)
+ {
+ for (int i = 0; i < genericRef.GenericArguments.Count; i++)
+ rewritten |= this.RewriteTypeReference(genericRef.GenericArguments[i], newType => genericRef.GenericArguments[i] = newType);
+ }
+
+ return rewritten;
+ }
+
/// <summary>Rewrite a type reference if needed.</summary>
/// <param name="type">The current type reference.</param>
/// <param name="replaceWith">Replaces the type reference with a new one.</param>