reject mods which reference obsolete StardewModdingAPI.Extensions class (#247)

This commit is contained in:
Jesse Plamondon-Willard 2017-03-12 01:32:30 -05:00
parent 6d2d90b768
commit 9fab0bf58f
3 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,31 @@
using System.Diagnostics.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using StardewModdingAPI.AssemblyRewriters.Framework;
namespace StardewModdingAPI.AssemblyRewriters.Finders
{
/// <summary>Matches CIL instructions that reference the former <c>StardewModdingAPI.Extensions</c> class, which was removed in SMAPI 1.9.</summary>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "This class is not meant to be used directly, and is deliberately named to make it easier to know what it changes at a glance.")]
public class SMAPI_Extensions_MethodFinder : BaseMethodFinder
{
/*********
** Accessors
*********/
/// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
public override string NounPhrase { get; } = "obsolete StardewModdingAPI.Extensions API";
/*********
** 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 == "StardewModdingAPI.Extensions";
}
}
}

View File

@ -66,6 +66,7 @@
<Compile Include="..\GlobalAssemblyInfo.cs"> <Compile Include="..\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link> <Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile> </Compile>
<Compile Include="Finders\SMAPI_Extensions_MethodFinder.cs" />
<Compile Include="Framework\BaseFieldFinder.cs" /> <Compile Include="Framework\BaseFieldFinder.cs" />
<Compile Include="Framework\BaseMethodFinder.cs" /> <Compile Include="Framework\BaseMethodFinder.cs" />
<Compile Include="IInstructionRewriter.cs" /> <Compile Include="IInstructionRewriter.cs" />

View File

@ -4,6 +4,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using StardewModdingAPI.AssemblyRewriters; using StardewModdingAPI.AssemblyRewriters;
using StardewModdingAPI.AssemblyRewriters.Finders;
using StardewModdingAPI.AssemblyRewriters.Rewriters.Crossplatform; using StardewModdingAPI.AssemblyRewriters.Rewriters.Crossplatform;
using StardewModdingAPI.AssemblyRewriters.Rewriters.SDV1_2; using StardewModdingAPI.AssemblyRewriters.Rewriters.SDV1_2;
using StardewValley; using StardewValley;
@ -140,6 +141,8 @@ namespace StardewModdingAPI
{ {
return new IInstructionFinder[] return new IInstructionFinder[]
{ {
// APIs removed in SMAPI 1.9
new SMAPI_Extensions_MethodFinder()
}; };
} }