diff --git a/src/SMAPI/Patches/StringPatcher.cs b/src/SMAPI/Patches/StringPatcher.cs
index f879fcc7..f1b1a633 100644
--- a/src/SMAPI/Patches/StringPatcher.cs
+++ b/src/SMAPI/Patches/StringPatcher.cs
@@ -1,13 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
-using System.Reflection;
using HarmonyLib;
-using StardewModdingAPI.Enums;
using StardewModdingAPI.Framework.Reflection;
using StardewModdingAPI.Internal.Patching;
using StardewValley;
-using StardewValley.Menus;
-using StardewValley.Minigames;
namespace StardewModdingAPI.Patches
{
@@ -38,22 +34,25 @@ namespace StardewModdingAPI.Patches
///
public override void Apply(Harmony harmony, IMonitor monitor)
{
- // detect CreatedInitialLocations and SaveAddedLocations
harmony.Patch(
original: this.RequireMethod(nameof(string.Split), new []{typeof(char), typeof(StringSplitOptions)}),
- prefix: this.GetHarmonyMethod(nameof(StringPatcher.Before_Split))
+ prefix: this.GetHarmonyMethod(nameof(StringPatcher.Before_Split)),
+ postfix: this.GetHarmonyMethod(nameof(StringPatcher.After_Split))
);
harmony.Patch(
original: this.RequireMethod(nameof(string.Split), new []{typeof(string), typeof(StringSplitOptions)}),
- prefix: this.GetHarmonyMethod(nameof(StringPatcher.Before_Split))
+ prefix: this.GetHarmonyMethod(nameof(StringPatcher.Before_Split)),
+ postfix: this.GetHarmonyMethod(nameof(StringPatcher.After_Split))
);
harmony.Patch(
original: this.RequireMethod(nameof(string.Split), new []{typeof(char), typeof(int), typeof(StringSplitOptions)}),
- prefix: this.GetHarmonyMethod(nameof(StringPatcher.Before_Split))
+ prefix: this.GetHarmonyMethod(nameof(StringPatcher.Before_Split)),
+ postfix: this.GetHarmonyMethod(nameof(StringPatcher.After_Split))
);
harmony.Patch(
original: this.RequireMethod(nameof(string.Split), new []{typeof(string), typeof(int), typeof(StringSplitOptions)}),
- prefix: this.GetHarmonyMethod(nameof(StringPatcher.Before_Split))
+ prefix: this.GetHarmonyMethod(nameof(StringPatcher.Before_Split)),
+ postfix: this.GetHarmonyMethod(nameof(StringPatcher.After_Split))
);
}
@@ -64,18 +63,22 @@ namespace StardewModdingAPI.Patches
/// The method to call before .
/// Returns whether to execute the original method.
/// This method must be static for Harmony to work correctly. See the Harmony documentation before renaming arguments.
- private static bool Before_Split(string __instance, ref StringSplitOptions options)
+ private static bool Before_Split(ref StringSplitOptions options, out bool __state)
{
- if (3 == (uint)options)
+ __state = false;
+ if ((0x02 & (uint)options) != 0)
{
- options = StringSplitOptions.RemoveEmptyEntries;
- }
- else if(2 == (uint)options)
- {
- options = StringSplitOptions.None;
+ options = (StringSplitOptions)(0xfffffffd & (uint)options);
+ __state = true;
}
return true;
}
+ private static void After_Split(bool __state, ref string[] __result)
+ {
+ if (__state)
+ for (int i = 0; i < __result.Length; i++)
+ __result[i] = __result[i].Trim();
+ }
}
}