summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/Finders/GenericEventFinder.cs54
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj1
-rw-r--r--src/StardewModdingAPI/Constants.cs8
3 files changed, 62 insertions, 1 deletions
diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericEventFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericEventFinder.cs
new file mode 100644
index 00000000..c2a981e5
--- /dev/null
+++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericEventFinder.cs
@@ -0,0 +1,54 @@
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+using StardewModdingAPI.AssemblyRewriters.Framework;
+
+namespace StardewModdingAPI.AssemblyRewriters.Finders
+{
+ /// <summary>Finds CIL instructions that reference a given event.</summary>
+ public sealed class GenericEventFinder : BaseMethodFinder
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>The full type name for which to find references.</summary>
+ private readonly string FullTypeName;
+
+ /// <summary>The event name for which to find references.</summary>
+ private readonly string EventName;
+
+
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
+ public override string NounPhrase { get; }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="fullTypeName">The full type name for which to find references.</param>
+ /// <param name="eventName">The event name for which to find references.</param>
+ public GenericEventFinder(string fullTypeName, string eventName)
+ {
+ this.FullTypeName = fullTypeName;
+ this.EventName = eventName;
+ this.NounPhrase = $"obsolete {fullTypeName}.{eventName} event";
+ }
+
+
+ /*********
+ ** Protected methods
+ *********/
+ /// <summary>Get whether a method reference should be rewritten.</summary>
+ /// <param name="instruction">The IL instruction.</param>
+ /// <param name="methodRef">The method reference.</param>
+ /// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
+ protected override bool IsMatch(Instruction instruction, MethodReference methodRef, bool platformChanged)
+ {
+ return methodRef.DeclaringType.FullName == this.FullTypeName
+ && (methodRef.Name == "add_" + this.EventName || methodRef.Name == "remove_" + this.EventName);
+ }
+ }
+}
diff --git a/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj b/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj
index 5089318c..a3322e67 100644
--- a/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj
+++ b/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj
@@ -67,6 +67,7 @@
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Finders\GenericFieldFinder.cs" />
+ <Compile Include="Finders\GenericEventFinder.cs" />
<Compile Include="Finders\GenericMethodFinder.cs" />
<Compile Include="Framework\BaseFieldFinder.cs" />
<Compile Include="Framework\BaseMethodFinder.cs" />
diff --git a/src/StardewModdingAPI/Constants.cs b/src/StardewModdingAPI/Constants.cs
index d86a065b..c0d3e3ae 100644
--- a/src/StardewModdingAPI/Constants.cs
+++ b/src/StardewModdingAPI/Constants.cs
@@ -154,7 +154,13 @@ namespace StardewModdingAPI
new GenericTypeFinder("StardewModdingAPI.Inheritance.SObject"),
new GenericTypeFinder("StardewModdingAPI.LogWriter"),
new GenericTypeFinder("StardewModdingAPI.Manifest"),
- new GenericTypeFinder("StardewModdingAPI.Version")
+ new GenericTypeFinder("StardewModdingAPI.Version"),
+ new GenericEventFinder("StardewModdingAPI.Events.GraphicsEvents", "DrawDebug"),
+ new GenericEventFinder("StardewModdingAPI.Events.GraphicsEvents", "DrawTick"),
+ new GenericEventFinder("StardewModdingAPI.Events.GraphicsEvents", "OnPostRenderHudEventNoCheck"),
+ new GenericEventFinder("StardewModdingAPI.Events.GraphicsEvents", "OnPostRenderGuiEventNoCheck"),
+ new GenericEventFinder("StardewModdingAPI.Events.GraphicsEvents", "OnPreRenderHudEventNoCheck"),
+ new GenericEventFinder("StardewModdingAPI.Events.GraphicsEvents", "OnPreRenderGuiEventNoCheck"),
};
}