summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModLoading/Finders
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-05 20:53:02 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-05 21:02:33 -0400
commitf4192663d78c7a45418f07f0bf4acb67b11291fe (patch)
tree6b5108ce0162123d2c71ee2798204feb0eb75a42 /src/SMAPI/Framework/ModLoading/Finders
parent2d37fe6819dd15a6e995ea55d625179106c22cd7 (diff)
downloadSMAPI-f4192663d78c7a45418f07f0bf4acb67b11291fe.tar.gz
SMAPI-f4192663d78c7a45418f07f0bf4acb67b11291fe.tar.bz2
SMAPI-f4192663d78c7a45418f07f0bf4acb67b11291fe.zip
add Harmony 2.0 rewriters (#711)
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/Finders')
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/TypeAssemblyFinder.cs25
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/TypeFinder.cs25
2 files changed, 50 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/ModLoading/Finders/TypeAssemblyFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/TypeAssemblyFinder.cs
new file mode 100644
index 00000000..5301186b
--- /dev/null
+++ b/src/SMAPI/Framework/ModLoading/Finders/TypeAssemblyFinder.cs
@@ -0,0 +1,25 @@
+using System;
+using Mono.Cecil;
+using StardewModdingAPI.Framework.ModLoading.Framework;
+
+namespace StardewModdingAPI.Framework.ModLoading.Finders
+{
+ /// <summary>Finds incompatible CIL instructions that reference types in a given assembly.</summary>
+ internal class TypeAssemblyFinder : BaseTypeFinder
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="assemblyName">The full assembly name to which to find references.</param>
+ /// <param name="result">The result to return for matching instructions.</param>
+ /// <param name="shouldIgnore">A lambda which overrides a matched type.</param>
+ public TypeAssemblyFinder(string assemblyName, InstructionHandleResult result, Func<TypeReference, bool> shouldIgnore = null)
+ : base(
+ isMatch: type => type.Scope.Name == assemblyName && (shouldIgnore == null || !shouldIgnore(type)),
+ result: result,
+ nounPhrase: $"{assemblyName} assembly"
+ )
+ { }
+ }
+}
diff --git a/src/SMAPI/Framework/ModLoading/Finders/TypeFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/TypeFinder.cs
new file mode 100644
index 00000000..3adc31c7
--- /dev/null
+++ b/src/SMAPI/Framework/ModLoading/Finders/TypeFinder.cs
@@ -0,0 +1,25 @@
+using System;
+using Mono.Cecil;
+using StardewModdingAPI.Framework.ModLoading.Framework;
+
+namespace StardewModdingAPI.Framework.ModLoading.Finders
+{
+ /// <summary>Finds incompatible CIL instructions that reference a given type.</summary>
+ internal class TypeFinder : BaseTypeFinder
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="fullTypeName">The full type name to match.</param>
+ /// <param name="result">The result to return for matching instructions.</param>
+ /// <param name="shouldIgnore">A lambda which overrides a matched type.</param>
+ public TypeFinder(string fullTypeName, InstructionHandleResult result, Func<TypeReference, bool> shouldIgnore = null)
+ : base(
+ isMatch: type => type.FullName == fullTypeName && (shouldIgnore == null || !shouldIgnore(type)),
+ result: result,
+ nounPhrase: $"{fullTypeName} type"
+ )
+ { }
+ }
+}