summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModLoading/Finders
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/Finders')
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/EventFinder.cs10
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs10
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/MethodFinder.cs10
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/PropertyFinder.cs10
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs10
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs17
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/TypeAssemblyFinder.cs6
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/TypeFinder.cs6
8 files changed, 17 insertions, 62 deletions
diff --git a/src/SMAPI/Framework/ModLoading/Finders/EventFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/EventFinder.cs
index e1476b73..01ed153b 100644
--- a/src/SMAPI/Framework/ModLoading/Finders/EventFinder.cs
+++ b/src/SMAPI/Framework/ModLoading/Finders/EventFinder.cs
@@ -1,4 +1,3 @@
-using System;
using Mono.Cecil;
using Mono.Cecil.Cil;
using StardewModdingAPI.Framework.ModLoading.Framework;
@@ -36,13 +35,8 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
this.Result = result;
}
- /// <summary>Rewrite a CIL instruction reference if needed.</summary>
- /// <param name="module">The assembly module containing the instruction.</param>
- /// <param name="cil">The CIL processor.</param>
- /// <param name="instruction">The CIL instruction to handle.</param>
- /// <param name="replaceWith">Replaces the CIL instruction with a new one.</param>
- /// <returns>Returns whether the instruction was changed.</returns>
- public override bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, Action<Instruction> replaceWith)
+ /// <inheritdoc />
+ public override bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction)
{
if (!this.Flags.Contains(this.Result) && this.IsMatch(instruction))
this.MarkFlag(this.Result);
diff --git a/src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs
index c157ed9b..2c062243 100644
--- a/src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs
+++ b/src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs
@@ -1,4 +1,3 @@
-using System;
using Mono.Cecil;
using Mono.Cecil.Cil;
using StardewModdingAPI.Framework.ModLoading.Framework;
@@ -36,13 +35,8 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
this.Result = result;
}
- /// <summary>Rewrite a CIL instruction reference if needed.</summary>
- /// <param name="module">The assembly module containing the instruction.</param>
- /// <param name="cil">The CIL processor.</param>
- /// <param name="instruction">The CIL instruction to handle.</param>
- /// <param name="replaceWith">Replaces the CIL instruction with a new one.</param>
- /// <returns>Returns whether the instruction was changed.</returns>
- public override bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, Action<Instruction> replaceWith)
+ /// <inheritdoc />
+ public override bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction)
{
if (!this.Flags.Contains(this.Result) && RewriteHelper.IsFieldReferenceTo(instruction, this.FullTypeName, this.FieldName))
this.MarkFlag(this.Result);
diff --git a/src/SMAPI/Framework/ModLoading/Finders/MethodFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/MethodFinder.cs
index 82c93a7c..d2340f01 100644
--- a/src/SMAPI/Framework/ModLoading/Finders/MethodFinder.cs
+++ b/src/SMAPI/Framework/ModLoading/Finders/MethodFinder.cs
@@ -1,4 +1,3 @@
-using System;
using Mono.Cecil;
using Mono.Cecil.Cil;
using StardewModdingAPI.Framework.ModLoading.Framework;
@@ -36,13 +35,8 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
this.Result = result;
}
- /// <summary>Rewrite a CIL instruction reference if needed.</summary>
- /// <param name="module">The assembly module containing the instruction.</param>
- /// <param name="cil">The CIL processor.</param>
- /// <param name="instruction">The CIL instruction to handle.</param>
- /// <param name="replaceWith">Replaces the CIL instruction with a new one.</param>
- /// <returns>Returns whether the instruction was changed.</returns>
- public override bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, Action<Instruction> replaceWith)
+ /// <inheritdoc />
+ public override bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction)
{
if (!this.Flags.Contains(this.Result) && this.IsMatch(instruction))
this.MarkFlag(this.Result);
diff --git a/src/SMAPI/Framework/ModLoading/Finders/PropertyFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/PropertyFinder.cs
index c96d61a2..99344848 100644
--- a/src/SMAPI/Framework/ModLoading/Finders/PropertyFinder.cs
+++ b/src/SMAPI/Framework/ModLoading/Finders/PropertyFinder.cs
@@ -1,4 +1,3 @@
-using System;
using Mono.Cecil;
using Mono.Cecil.Cil;
using StardewModdingAPI.Framework.ModLoading.Framework;
@@ -36,13 +35,8 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
this.Result = result;
}
- /// <summary>Rewrite a CIL instruction reference if needed.</summary>
- /// <param name="module">The assembly module containing the instruction.</param>
- /// <param name="cil">The CIL processor.</param>
- /// <param name="instruction">The CIL instruction to handle.</param>
- /// <param name="replaceWith">Replaces the CIL instruction with a new one.</param>
- /// <returns>Returns whether the instruction was changed.</returns>
- public override bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, Action<Instruction> replaceWith)
+ /// <inheritdoc />
+ public override bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction)
{
if (!this.Flags.Contains(this.Result) && this.IsMatch(instruction))
this.MarkFlag(this.Result);
diff --git a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs
index a67cfa4f..b01a3240 100644
--- a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs
+++ b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs
@@ -1,4 +1,3 @@
-using System;
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;
@@ -29,13 +28,8 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
this.ValidateReferencesToAssemblies = new HashSet<string>(validateReferencesToAssemblies);
}
- /// <summary>Rewrite a CIL instruction reference if needed.</summary>
- /// <param name="module">The assembly module containing the instruction.</param>
- /// <param name="cil">The CIL processor.</param>
- /// <param name="instruction">The CIL instruction to handle.</param>
- /// <param name="replaceWith">Replaces the CIL instruction with a new one.</param>
- /// <returns>Returns whether the instruction was changed.</returns>
- public override bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, Action<Instruction> replaceWith)
+ /// <inheritdoc />
+ public override bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction)
{
// field reference
FieldReference fieldRef = RewriteHelper.AsFieldReference(instruction);
diff --git a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs
index ebb62948..b64a255e 100644
--- a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs
+++ b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs
@@ -1,6 +1,4 @@
-using System;
using System.Collections.Generic;
-using System.Linq;
using Mono.Cecil;
using Mono.Cecil.Cil;
using StardewModdingAPI.Framework.ModLoading.Framework;
@@ -29,20 +27,15 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
this.ValidateReferencesToAssemblies = new HashSet<string>(validateReferencesToAssemblies);
}
- /// <summary>Rewrite a CIL instruction reference if needed.</summary>
- /// <param name="module">The assembly module containing the instruction.</param>
- /// <param name="cil">The CIL processor.</param>
- /// <param name="instruction">The CIL instruction to handle.</param>
- /// <param name="replaceWith">Replaces the CIL instruction with a new one.</param>
- /// <returns>Returns whether the instruction was changed.</returns>
- public override bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, Action<Instruction> replaceWith)
+ /// <inheritdoc />
+ public override bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction)
{
// field reference
FieldReference fieldRef = RewriteHelper.AsFieldReference(instruction);
if (fieldRef != null && this.ShouldValidate(fieldRef.DeclaringType))
{
- FieldDefinition target = fieldRef.DeclaringType.Resolve()?.Fields.FirstOrDefault(p => p.Name == fieldRef.Name);
- if (target == null)
+ FieldDefinition target = fieldRef.Resolve();
+ if (target == null || target.HasConstant)
{
this.MarkFlag(InstructionHandleResult.NotCompatible, $"reference to {fieldRef.DeclaringType.FullName}.{fieldRef.Name} (no such field)");
return false;
@@ -56,7 +49,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
MethodDefinition target = methodRef.Resolve();
if (target == null)
{
- string phrase = null;
+ string phrase;
if (this.IsProperty(methodRef))
phrase = $"reference to {methodRef.DeclaringType.FullName}.{methodRef.Name.Substring(4)} (no such property)";
else if (methodRef.Name == ".ctor")
diff --git a/src/SMAPI/Framework/ModLoading/Finders/TypeAssemblyFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/TypeAssemblyFinder.cs
index a1ade536..24ab2eca 100644
--- a/src/SMAPI/Framework/ModLoading/Finders/TypeAssemblyFinder.cs
+++ b/src/SMAPI/Framework/ModLoading/Finders/TypeAssemblyFinder.cs
@@ -35,11 +35,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
this.ShouldIgnore = shouldIgnore;
}
- /// <summary>Rewrite a type reference if needed.</summary>
- /// <param name="module">The assembly module containing the instruction.</param>
- /// <param name="type">The type definition to handle.</param>
- /// <param name="replaceWith">Replaces the type reference with a new one.</param>
- /// <returns>Returns whether the type was changed.</returns>
+ /// <inheritdoc />
public override bool Handle(ModuleDefinition module, TypeReference type, Action<TypeReference> replaceWith)
{
if (type.Scope.Name == this.AssemblyName && this.ShouldIgnore?.Invoke(type) != true)
diff --git a/src/SMAPI/Framework/ModLoading/Finders/TypeFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/TypeFinder.cs
index c285414a..bbd081e8 100644
--- a/src/SMAPI/Framework/ModLoading/Finders/TypeFinder.cs
+++ b/src/SMAPI/Framework/ModLoading/Finders/TypeFinder.cs
@@ -35,11 +35,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
this.ShouldIgnore = shouldIgnore;
}
- /// <summary>Rewrite a type reference if needed.</summary>
- /// <param name="module">The assembly module containing the instruction.</param>
- /// <param name="type">The type definition to handle.</param>
- /// <param name="replaceWith">Replaces the type reference with a new one.</param>
- /// <returns>Returns whether the type was changed.</returns>
+ /// <inheritdoc />
public override bool Handle(ModuleDefinition module, TypeReference type, Action<TypeReference> replaceWith)
{
if (type.FullName == this.FullTypeName && this.ShouldIgnore?.Invoke(type) != true)