add incompatibility finders for events removed in SMAPI 1.9 (#247)

This commit is contained in:
Jesse Plamondon-Willard 2017-03-12 19:05:31 -04:00
parent a93f1e2042
commit ac19a1a85a
3 changed files with 62 additions and 1 deletions

View File

@ -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);
}
}
}

View File

@ -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" />

View File

@ -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"),
};
}