diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 52978e8d..210cbe4e 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -273,7 +273,6 @@ namespace StardewModdingAPI.Framework new ScheduleErrorPatch(this.MonitorForGame), new SaveBackupPatch(this.EventManager), new JunimoHarvesterPatch(this.Monitor), - new LinqEnumerablePatch(this.Monitor), new SpriteFontPatch(this.Monitor) ); diff --git a/src/SMAPI/Patches/LinqEnumerablePatch.cs b/src/SMAPI/Patches/LinqEnumerablePatch.cs deleted file mode 100644 index 319d3b14..00000000 --- a/src/SMAPI/Patches/LinqEnumerablePatch.cs +++ /dev/null @@ -1,212 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using System.Reflection; -using System.Reflection.Emit; -using Harmony; -using Microsoft.Xna.Framework; -using StardewModdingAPI.Framework.Patching; -using StardewValley; -using StardewValley.Buildings; -using StardewValley.Characters; - -namespace StardewModdingAPI.Patches -{ - /// A Harmony patch for which intercepts crashes due to invalid schedule data. - /// Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments. - [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Argument names are defined by Harmony and methods are named for clarity.")] - [SuppressMessage("ReSharper", "IdentifierTypo", Justification = "Argument names are defined by Harmony and methods are named for clarity.")] - internal class LinqEnumerablePatch : IHarmonyPatch - { - /********* - ** Fields - *********/ - - /********* - ** Fields - *********/ - /// Writes messages to the console and log file. - private static IMonitor Monitor; - - /********* - ** Accessors - *********/ - /// A unique name for this patch. - public string Name => nameof(LinqEnumerablePatch); - - - /********* - ** Public methods - *********/ - /// Construct an instance. - /// Writes messages to the console and log file on behalf of the game. - public LinqEnumerablePatch(IMonitor monitor) - { - Monitor = monitor; - } - - /// Apply the Harmony patch. - /// The Harmony instance. - public void Apply(HarmonyInstance harmony) - { - MethodInfo methodInfo = AccessTools.FirstMethod(typeof(System.Linq.Enumerable), method => method.Name == "FirstOrDefault" && method.GetParameters().Length == 2).MakeGenericMethod(new Type[] { typeof(Item) }); - harmony.Patch( - original: methodInfo, - prefix: new HarmonyMethod(this.GetType(), nameof(LinqEnumerablePatch.Before_LinqEnumerablePatch_FirstOrDefault)) - ); - methodInfo = AccessTools.FirstMethod(typeof(System.Linq.Enumerable), method => method.Name == "Any" && method.GetParameters().Length == 2).MakeGenericMethod(new Type[] { typeof(Item) }); - harmony.Patch( - original: methodInfo, - prefix: new HarmonyMethod(this.GetType(), nameof(LinqEnumerablePatch.Before_LinqEnumerablePatch_Any)) - ); - methodInfo = AccessTools.FirstMethod(typeof(System.Linq.Enumerable), method => method.Name == "TryGetFirst" && method.GetParameters().Length == 3).MakeGenericMethod(new Type[] { typeof(Item) }); - harmony.Patch( - original: methodInfo, - prefix: new HarmonyMethod(this.GetType(), nameof(LinqEnumerablePatch.Before_LinqEnumerablePatch_TryGetFirst)) - ); - } - - - /********* - ** Private methods - *********/ - /// The method to call instead of . - /// The instance being patched. - /// The method being wrapped. - /// Returns whether to execute the original method. - private static bool Before_LinqEnumerablePatch_FirstOrDefault(IEnumerable source, Func predicate, ref object __result) - { - if (source == null) - { - throw new ArgumentNullException("source"); - } - if (predicate == null) - { - throw new ArgumentNullException("predicate"); - } - foreach (object local in source) - { - if (local == null) - { - try - { - if (predicate(local)) - { - __result = local; - return false; - } - } - catch - { - continue; - } - } - else - { - if (!(local is StardewValley.Item)) - { - return true; - } - if (predicate(local)) - { - __result = local; - return false; - } - } - } - __result = default(Item); - return false; - } - private static bool Before_LinqEnumerablePatch_Any(IEnumerable source, Func predicate, ref object __result) - { - if (source == null) - { - throw new ArgumentNullException("source"); - } - if (predicate == null) - { - throw new ArgumentNullException("predicate"); - } - foreach (object local in source) - { - if (local == null) - { - try - { - if (predicate(local)) - { - __result = local; - return false; - } - } - catch - { - continue; - } - } - else - { - if (!(local is StardewValley.Item)) - { - return true; - } - if (predicate(local)) - { - __result = local; - return false; - } - } - } - __result = null; - return false; - } - private static bool Before_LinqEnumerablePatch_TryGetFirst(IEnumerable source, Func predicate, ref bool found, ref object __result, MethodBase __originalMethod) - { - if (source == null) - { - throw new ArgumentNullException("source"); - } - if (predicate == null) - { - throw new ArgumentNullException("predicate"); - } - foreach (object local in source) - { - if (local == null) - { - try - { - if (predicate(local)) - { - __result = local; - found = true; - return false; - } - } - catch - { - continue; - } - } - else - { - if (!(local is StardewValley.Item)) - { - return true; - } - if (predicate(local)) - { - __result = local; - found = true; - return false; - } - } - } - found = false; - __result = default(Item); - return false; - } - } -} diff --git a/src/SMAPI/SMAPI.csproj b/src/SMAPI/SMAPI.csproj index 8285a606..3113edc5 100644 --- a/src/SMAPI/SMAPI.csproj +++ b/src/SMAPI/SMAPI.csproj @@ -355,7 +355,6 @@ -