summaryrefslogtreecommitdiff
path: root/src/SMAPI/Patches
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-05-10 23:25:07 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-09-13 15:46:46 -0400
commit8595a2a6faffe7af81c6401cd6308f84fbefdd01 (patch)
tree34555b3a5e217289ed74e5cdab9d7aefdb7cc9c6 /src/SMAPI/Patches
parente3a2c56a6d8c827240a2bd4ead86c7b412e826ab (diff)
downloadSMAPI-8595a2a6faffe7af81c6401cd6308f84fbefdd01.tar.gz
SMAPI-8595a2a6faffe7af81c6401cd6308f84fbefdd01.tar.bz2
SMAPI-8595a2a6faffe7af81c6401cd6308f84fbefdd01.zip
make Harmony patch names more consistent
Diffstat (limited to 'src/SMAPI/Patches')
-rw-r--r--src/SMAPI/Patches/EventErrorPatch.cs (renamed from src/SMAPI/Patches/CheckEventPreconditionErrorPatch.cs)18
-rw-r--r--src/SMAPI/Patches/LoadContextPatch.cs (renamed from src/SMAPI/Patches/LoadForNewGamePatch.cs)32
2 files changed, 25 insertions, 25 deletions
diff --git a/src/SMAPI/Patches/CheckEventPreconditionErrorPatch.cs b/src/SMAPI/Patches/EventErrorPatch.cs
index c2a16391..b0074356 100644
--- a/src/SMAPI/Patches/CheckEventPreconditionErrorPatch.cs
+++ b/src/SMAPI/Patches/EventErrorPatch.cs
@@ -7,7 +7,7 @@ using StardewValley;
namespace StardewModdingAPI.Patches
{
/// <summary>A Harmony patch for the <see cref="Dialogue"/> constructor which intercepts invalid dialogue lines and logs an error instead of crashing.</summary>
- internal class CheckEventPreconditionErrorPatch : IHarmonyPatch
+ internal class EventErrorPatch : IHarmonyPatch
{
/*********
** Fields
@@ -23,7 +23,7 @@ namespace StardewModdingAPI.Patches
** Accessors
*********/
/// <summary>A unique name for this patch.</summary>
- public string Name => $"{nameof(CheckEventPreconditionErrorPatch)}";
+ public string Name => $"{nameof(EventErrorPatch)}";
/*********
@@ -31,9 +31,9 @@ namespace StardewModdingAPI.Patches
*********/
/// <summary>Construct an instance.</summary>
/// <param name="monitorForGame">Writes messages to the console and log file on behalf of the game.</param>
- public CheckEventPreconditionErrorPatch(IMonitor monitorForGame)
+ public EventErrorPatch(IMonitor monitorForGame)
{
- CheckEventPreconditionErrorPatch.MonitorForGame = monitorForGame;
+ EventErrorPatch.MonitorForGame = monitorForGame;
}
/// <summary>Apply the Harmony patch.</summary>
@@ -42,7 +42,7 @@ namespace StardewModdingAPI.Patches
{
harmony.Patch(
original: AccessTools.Method(typeof(GameLocation), "checkEventPrecondition"),
- prefix: new HarmonyMethod(this.GetType(), nameof(CheckEventPreconditionErrorPatch.Prefix))
+ prefix: new HarmonyMethod(this.GetType(), nameof(EventErrorPatch.Prefix))
);
}
@@ -60,24 +60,24 @@ namespace StardewModdingAPI.Patches
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Argument names are defined by Harmony.")]
private static bool Prefix(GameLocation __instance, ref int __result, string precondition, MethodInfo __originalMethod)
{
- if (CheckEventPreconditionErrorPatch.IsIntercepted)
+ if (EventErrorPatch.IsIntercepted)
return true;
try
{
- CheckEventPreconditionErrorPatch.IsIntercepted = true;
+ EventErrorPatch.IsIntercepted = true;
__result = (int)__originalMethod.Invoke(__instance, new object[] { precondition });
return false;
}
catch (TargetInvocationException ex)
{
__result = -1;
- CheckEventPreconditionErrorPatch.MonitorForGame.Log($"Failed parsing event precondition ({precondition}):\n{ex.InnerException}", LogLevel.Error);
+ EventErrorPatch.MonitorForGame.Log($"Failed parsing event precondition ({precondition}):\n{ex.InnerException}", LogLevel.Error);
return false;
}
finally
{
- CheckEventPreconditionErrorPatch.IsIntercepted = false;
+ EventErrorPatch.IsIntercepted = false;
}
}
}
diff --git a/src/SMAPI/Patches/LoadForNewGamePatch.cs b/src/SMAPI/Patches/LoadContextPatch.cs
index def7134d..43e09573 100644
--- a/src/SMAPI/Patches/LoadForNewGamePatch.cs
+++ b/src/SMAPI/Patches/LoadContextPatch.cs
@@ -12,7 +12,7 @@ namespace StardewModdingAPI.Patches
{
/// <summary>A Harmony patch for <see cref="Game1.loadForNewGame"/> which notifies SMAPI for save creation load stages.</summary>
/// <remarks>This patch hooks into <see cref="Game1.loadForNewGame"/>, checks if <c>TitleMenu.transitioningCharacterCreationMenu</c> is true (which means the player is creating a new save file), then raises <see cref="LoadStage.CreatedBasicInfo"/> after the location list is cleared twice (the second clear happens right before locations are created), and <see cref="LoadStage.CreatedLocations"/> when the method ends.</remarks>
- internal class LoadForNewGamePatch : IHarmonyPatch
+ internal class LoadContextPatch : IHarmonyPatch
{
/*********
** Fields
@@ -34,7 +34,7 @@ namespace StardewModdingAPI.Patches
** Accessors
*********/
/// <summary>A unique name for this patch.</summary>
- public string Name => $"{nameof(LoadForNewGamePatch)}";
+ public string Name => $"{nameof(LoadContextPatch)}";
/*********
@@ -43,10 +43,10 @@ namespace StardewModdingAPI.Patches
/// <summary>Construct an instance.</summary>
/// <param name="reflection">Simplifies access to private code.</param>
/// <param name="onStageChanged">A callback to invoke when the load stage changes.</param>
- public LoadForNewGamePatch(Reflector reflection, Action<LoadStage> onStageChanged)
+ public LoadContextPatch(Reflector reflection, Action<LoadStage> onStageChanged)
{
- LoadForNewGamePatch.Reflection = reflection;
- LoadForNewGamePatch.OnStageChanged = onStageChanged;
+ LoadContextPatch.Reflection = reflection;
+ LoadContextPatch.OnStageChanged = onStageChanged;
}
/// <summary>Apply the Harmony patch.</summary>
@@ -55,8 +55,8 @@ namespace StardewModdingAPI.Patches
{
harmony.Patch(
original: AccessTools.Method(typeof(Game1), nameof(Game1.loadForNewGame)),
- prefix: new HarmonyMethod(this.GetType(), nameof(LoadForNewGamePatch.Prefix)),
- postfix: new HarmonyMethod(this.GetType(), nameof(LoadForNewGamePatch.Postfix))
+ prefix: new HarmonyMethod(this.GetType(), nameof(LoadContextPatch.Prefix)),
+ postfix: new HarmonyMethod(this.GetType(), nameof(LoadContextPatch.Postfix))
);
}
@@ -69,13 +69,13 @@ namespace StardewModdingAPI.Patches
/// <remarks>This method must be static for Harmony to work correctly. See the Harmony documentation before renaming arguments.</remarks>
private static bool Prefix()
{
- LoadForNewGamePatch.IsCreating = Game1.activeClickableMenu is TitleMenu menu && LoadForNewGamePatch.Reflection.GetField<bool>(menu, "transitioningCharacterCreationMenu").GetValue();
- LoadForNewGamePatch.TimesLocationsCleared = 0;
- if (LoadForNewGamePatch.IsCreating)
+ LoadContextPatch.IsCreating = Game1.activeClickableMenu is TitleMenu menu && LoadContextPatch.Reflection.GetField<bool>(menu, "transitioningCharacterCreationMenu").GetValue();
+ LoadContextPatch.TimesLocationsCleared = 0;
+ if (LoadContextPatch.IsCreating)
{
// raise CreatedBasicInfo after locations are cleared twice
ObservableCollection<GameLocation> locations = (ObservableCollection<GameLocation>)Game1.locations;
- locations.CollectionChanged += LoadForNewGamePatch.OnLocationListChanged;
+ locations.CollectionChanged += LoadContextPatch.OnLocationListChanged;
}
return true;
@@ -85,14 +85,14 @@ namespace StardewModdingAPI.Patches
/// <remarks>This method must be static for Harmony to work correctly. See the Harmony documentation before renaming arguments.</remarks>
private static void Postfix()
{
- if (LoadForNewGamePatch.IsCreating)
+ if (LoadContextPatch.IsCreating)
{
// clean up
ObservableCollection<GameLocation> locations = (ObservableCollection<GameLocation>)Game1.locations;
- locations.CollectionChanged -= LoadForNewGamePatch.OnLocationListChanged;
+ locations.CollectionChanged -= LoadContextPatch.OnLocationListChanged;
// raise stage changed
- LoadForNewGamePatch.OnStageChanged(LoadStage.CreatedLocations);
+ LoadContextPatch.OnStageChanged(LoadStage.CreatedLocations);
}
}
@@ -101,8 +101,8 @@ namespace StardewModdingAPI.Patches
/// <param name="e">The event arguments.</param>
private static void OnLocationListChanged(object sender, NotifyCollectionChangedEventArgs e)
{
- if (++LoadForNewGamePatch.TimesLocationsCleared == 2)
- LoadForNewGamePatch.OnStageChanged(LoadStage.CreatedBasicInfo);
+ if (++LoadContextPatch.TimesLocationsCleared == 2)
+ LoadContextPatch.OnStageChanged(LoadStage.CreatedBasicInfo);
}
}
}