From fae362723f1390cb7758bd151d50889cf6c999a9 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 12 Mar 2017 03:23:20 -0400 Subject: reject mods which reference obsolete Game1.borderFont and Game1.smoothFont fields (#247) --- .../Finders/Game1_borderFont_FieldFinder.cs | 35 ++++++++++++++++++++++ .../Finders/Game1_smoothFont_FieldFinder.cs | 35 ++++++++++++++++++++++ .../Finders/SMAPI_Extensions_MethodFinder.cs | 2 +- 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/StardewModdingAPI.AssemblyRewriters/Finders/Game1_borderFont_FieldFinder.cs create mode 100644 src/StardewModdingAPI.AssemblyRewriters/Finders/Game1_smoothFont_FieldFinder.cs (limited to 'src/StardewModdingAPI.AssemblyRewriters/Finders') diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/Game1_borderFont_FieldFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/Game1_borderFont_FieldFinder.cs new file mode 100644 index 00000000..e25cc544 --- /dev/null +++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/Game1_borderFont_FieldFinder.cs @@ -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 +{ + /// Finds CIL instructions that reference the former Game1.borderFont field, which was removed in Stardew Valley 1.2.3–1.2.6. + [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 + *********/ + /// A brief noun phrase indicating what the instruction finder matches. + public override string NounPhrase { get; } = $"obsolete {nameof(Game1)}.borderFont field"; + + + /********* + ** Protected methods + *********/ + /// Get whether a field reference should be rewritten. + /// The IL instruction. + /// The field reference. + /// Whether the mod was compiled on a different platform. + protected override bool IsMatch(Instruction instruction, FieldReference fieldRef, bool platformChanged) + { + return + this.IsStaticField(instruction) + && fieldRef.DeclaringType.FullName == typeof(Game1).FullName + && fieldRef.Name == "borderFont"; + } + } +} diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/Game1_smoothFont_FieldFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/Game1_smoothFont_FieldFinder.cs new file mode 100644 index 00000000..b852f10d --- /dev/null +++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/Game1_smoothFont_FieldFinder.cs @@ -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 +{ + /// Finds CIL instructions that reference the former Game1.smoothFont field, which was removed in Stardew Valley 1.2.3–1.2.6. + [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 + *********/ + /// A brief noun phrase indicating what the instruction finder matches. + public override string NounPhrase { get; } = $"obsolete {nameof(Game1)}.smoothFont field"; + + + /********* + ** Protected methods + *********/ + /// Get whether a field reference should be rewritten. + /// The IL instruction. + /// The field reference. + /// Whether the mod was compiled on a different platform. + protected override bool IsMatch(Instruction instruction, FieldReference fieldRef, bool platformChanged) + { + return + this.IsStaticField(instruction) + && fieldRef.DeclaringType.FullName == typeof(Game1).FullName + && fieldRef.Name == "smoothFont"; + } + } +} diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/SMAPI_Extensions_MethodFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/SMAPI_Extensions_MethodFinder.cs index f359b595..4abcbc13 100644 --- a/src/StardewModdingAPI.AssemblyRewriters/Finders/SMAPI_Extensions_MethodFinder.cs +++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/SMAPI_Extensions_MethodFinder.cs @@ -5,7 +5,7 @@ using StardewModdingAPI.AssemblyRewriters.Framework; namespace StardewModdingAPI.AssemblyRewriters.Finders { - /// Matches CIL instructions that reference the former StardewModdingAPI.Extensions class, which was removed in SMAPI 1.9. + /// Finds CIL instructions that reference the former StardewModdingAPI.Extensions class, which was removed in SMAPI 1.9. [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 { -- cgit