reject mods which reference obsolete Game1.borderFont and Game1.smoothFont fields (#247)
This commit is contained in:
parent
9fab0bf58f
commit
fae362723f
|
@ -0,0 +1,35 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
using StardewModdingAPI.AssemblyRewriters.Framework;
|
||||
using StardewValley;
|
||||
|
||||
namespace StardewModdingAPI.AssemblyRewriters.Finders
|
||||
{
|
||||
/// <summary>Finds CIL instructions that reference the former <c>Game1.borderFont</c> field, which was removed in Stardew Valley 1.2.3–1.2.6.</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 Game1_borderFont_FieldFinder : BaseFieldFinder
|
||||
{
|
||||
/*********
|
||||
** Accessors
|
||||
*********/
|
||||
/// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
|
||||
public override string NounPhrase { get; } = $"obsolete {nameof(Game1)}.borderFont field";
|
||||
|
||||
|
||||
/*********
|
||||
** Protected methods
|
||||
*********/
|
||||
/// <summary>Get whether a field reference should be rewritten.</summary>
|
||||
/// <param name="instruction">The IL instruction.</param>
|
||||
/// <param name="fieldRef">The field reference.</param>
|
||||
/// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
|
||||
protected override bool IsMatch(Instruction instruction, FieldReference fieldRef, bool platformChanged)
|
||||
{
|
||||
return
|
||||
this.IsStaticField(instruction)
|
||||
&& fieldRef.DeclaringType.FullName == typeof(Game1).FullName
|
||||
&& fieldRef.Name == "borderFont";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
using StardewModdingAPI.AssemblyRewriters.Framework;
|
||||
using StardewValley;
|
||||
|
||||
namespace StardewModdingAPI.AssemblyRewriters.Finders
|
||||
{
|
||||
/// <summary>Finds CIL instructions that reference the former <c>Game1.smoothFont</c> field, which was removed in Stardew Valley 1.2.3–1.2.6.</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 Game1_smoothFont_FieldFinder : BaseFieldFinder
|
||||
{
|
||||
/*********
|
||||
** Accessors
|
||||
*********/
|
||||
/// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
|
||||
public override string NounPhrase { get; } = $"obsolete {nameof(Game1)}.smoothFont field";
|
||||
|
||||
|
||||
/*********
|
||||
** Protected methods
|
||||
*********/
|
||||
/// <summary>Get whether a field reference should be rewritten.</summary>
|
||||
/// <param name="instruction">The IL instruction.</param>
|
||||
/// <param name="fieldRef">The field reference.</param>
|
||||
/// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
|
||||
protected override bool IsMatch(Instruction instruction, FieldReference fieldRef, bool platformChanged)
|
||||
{
|
||||
return
|
||||
this.IsStaticField(instruction)
|
||||
&& fieldRef.DeclaringType.FullName == typeof(Game1).FullName
|
||||
&& fieldRef.Name == "smoothFont";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ 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>
|
||||
/// <summary>Finds 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
|
||||
{
|
||||
|
|
|
@ -35,5 +35,12 @@ namespace StardewModdingAPI.AssemblyRewriters.Framework
|
|||
/// <param name="fieldRef">The field reference.</param>
|
||||
/// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
|
||||
protected abstract bool IsMatch(Instruction instruction, FieldReference fieldRef, bool platformChanged);
|
||||
|
||||
/// <summary>Whether an instruction is a static field reference.</summary>
|
||||
/// <param name="instruction">The IL instruction.</param>
|
||||
protected bool IsStaticField(Instruction instruction)
|
||||
{
|
||||
return instruction.OpCode == OpCodes.Ldsfld || instruction.OpCode == OpCodes.Stsfld;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace StardewModdingAPI.AssemblyRewriters.Rewriters.SDV1_2
|
|||
protected override bool IsMatch(Instruction instruction, FieldReference fieldRef, bool platformChanged)
|
||||
{
|
||||
return
|
||||
(instruction.OpCode == OpCodes.Ldsfld || instruction.OpCode == OpCodes.Stsfld) // static field
|
||||
this.IsStaticField(instruction)
|
||||
&& fieldRef.DeclaringType.FullName == typeof(Game1).FullName
|
||||
&& fieldRef.Name == nameof(Game1.activeClickableMenu);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace StardewModdingAPI.AssemblyRewriters.Rewriters.SDV1_2
|
|||
protected override bool IsMatch(Instruction instruction, FieldReference fieldRef, bool platformChanged)
|
||||
{
|
||||
return
|
||||
(instruction.OpCode == OpCodes.Ldsfld || instruction.OpCode == OpCodes.Stsfld) // static field
|
||||
this.IsStaticField(instruction)
|
||||
&& fieldRef.DeclaringType.FullName == typeof(Game1).FullName
|
||||
&& fieldRef.Name == nameof(Game1.gameMode);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace StardewModdingAPI.AssemblyRewriters.Rewriters.SDV1_2
|
|||
protected override bool IsMatch(Instruction instruction, FieldReference fieldRef, bool platformChanged)
|
||||
{
|
||||
return
|
||||
(instruction.OpCode == OpCodes.Ldsfld || instruction.OpCode == OpCodes.Stsfld) // static field
|
||||
this.IsStaticField(instruction)
|
||||
&& fieldRef.DeclaringType.FullName == typeof(Game1).FullName
|
||||
&& fieldRef.Name == nameof(Game1.player);
|
||||
}
|
||||
|
|
|
@ -66,6 +66,8 @@
|
|||
<Compile Include="..\GlobalAssemblyInfo.cs">
|
||||
<Link>Properties\GlobalAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Finders\Game1_smoothFont_FieldFinder.cs" />
|
||||
<Compile Include="Finders\Game1_borderFont_FieldFinder.cs" />
|
||||
<Compile Include="Finders\SMAPI_Extensions_MethodFinder.cs" />
|
||||
<Compile Include="Framework\BaseFieldFinder.cs" />
|
||||
<Compile Include="Framework\BaseMethodFinder.cs" />
|
||||
|
|
|
@ -141,6 +141,10 @@ namespace StardewModdingAPI
|
|||
{
|
||||
return new IInstructionFinder[]
|
||||
{
|
||||
// changes in Stardew Valley 1.2
|
||||
new Game1_borderFont_FieldFinder(),
|
||||
new Game1_smoothFont_FieldFinder(),
|
||||
|
||||
// APIs removed in SMAPI 1.9
|
||||
new SMAPI_Extensions_MethodFinder()
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue