rename patch classes for consistency
This commit is contained in:
parent
aa65b2e2f6
commit
4074f697d7
|
@ -29,16 +29,16 @@ namespace StardewModdingAPI.Mods.ErrorHandler
|
|||
|
||||
// apply patches
|
||||
new GamePatcher(this.Monitor).Apply(
|
||||
new DialogueErrorPatch(monitorForGame, this.Helper.Reflection),
|
||||
new DictionaryPatches(this.Helper.Reflection),
|
||||
new EventPatches(monitorForGame),
|
||||
new GameLocationPatches(monitorForGame),
|
||||
new IClickablePatcher(),
|
||||
new ObjectErrorPatch(),
|
||||
new LoadErrorPatch(this.Monitor, this.OnSaveContentRemoved),
|
||||
new ScheduleErrorPatch(monitorForGame),
|
||||
new SpriteBatchValidationPatches(),
|
||||
new UtilityErrorPatches()
|
||||
new DialoguePatcher(monitorForGame, this.Helper.Reflection),
|
||||
new DictionaryPatcher(this.Helper.Reflection),
|
||||
new EventPatcher(monitorForGame),
|
||||
new GameLocationPatcher(monitorForGame),
|
||||
new IClickableMenuPatcher(),
|
||||
new NpcPatcher(monitorForGame),
|
||||
new ObjectPatcher(),
|
||||
new SaveGamePatcher(this.Monitor, this.OnSaveContentRemoved),
|
||||
new SpriteBatchPatcher(),
|
||||
new UtilityPatcher()
|
||||
);
|
||||
|
||||
// hook events
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
/// <remarks>Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments.</remarks>
|
||||
[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 DialogueErrorPatch : IHarmonyPatch
|
||||
internal class DialoguePatcher : IHarmonyPatch
|
||||
{
|
||||
/*********
|
||||
** Fields
|
||||
|
@ -29,10 +29,10 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
/// <summary>Construct an instance.</summary>
|
||||
/// <param name="monitorForGame">Writes messages to the console and log file on behalf of the game.</param>
|
||||
/// <param name="reflector">Simplifies access to private code.</param>
|
||||
public DialogueErrorPatch(IMonitor monitorForGame, IReflectionHelper reflector)
|
||||
public DialoguePatcher(IMonitor monitorForGame, IReflectionHelper reflector)
|
||||
{
|
||||
DialogueErrorPatch.MonitorForGame = monitorForGame;
|
||||
DialogueErrorPatch.Reflection = reflector;
|
||||
DialoguePatcher.MonitorForGame = monitorForGame;
|
||||
DialoguePatcher.Reflection = reflector;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -40,7 +40,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
{
|
||||
harmony.Patch(
|
||||
original: AccessTools.Constructor(typeof(Dialogue), new[] { typeof(string), typeof(NPC) }),
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(DialogueErrorPatch.Finalize_Dialogue_Constructor))
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(DialoguePatcher.Finalize_Dialogue_Constructor))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -60,11 +60,11 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
{
|
||||
// log message
|
||||
string name = !string.IsNullOrWhiteSpace(speaker?.Name) ? speaker.Name : null;
|
||||
DialogueErrorPatch.MonitorForGame.Log($"Failed parsing dialogue string{(name != null ? $" for {name}" : "")}:\n{masterDialogue}\n{__exception.GetLogSummary()}", LogLevel.Error);
|
||||
DialoguePatcher.MonitorForGame.Log($"Failed parsing dialogue string{(name != null ? $" for {name}" : "")}:\n{masterDialogue}\n{__exception.GetLogSummary()}", LogLevel.Error);
|
||||
|
||||
// set default dialogue
|
||||
IReflectedMethod parseDialogueString = DialogueErrorPatch.Reflection.GetMethod(__instance, "parseDialogueString");
|
||||
IReflectedMethod checkForSpecialDialogueAttributes = DialogueErrorPatch.Reflection.GetMethod(__instance, "checkForSpecialDialogueAttributes");
|
||||
IReflectedMethod parseDialogueString = DialoguePatcher.Reflection.GetMethod(__instance, "parseDialogueString");
|
||||
IReflectedMethod checkForSpecialDialogueAttributes = DialoguePatcher.Reflection.GetMethod(__instance, "checkForSpecialDialogueAttributes");
|
||||
parseDialogueString.Invoke("...");
|
||||
checkForSpecialDialogueAttributes.Invoke();
|
||||
}
|
|
@ -13,7 +13,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
/// <remarks>Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments.</remarks>
|
||||
[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 DictionaryPatches : IHarmonyPatch
|
||||
internal class DictionaryPatcher : IHarmonyPatch
|
||||
{
|
||||
/*********
|
||||
** Fields
|
||||
|
@ -27,9 +27,9 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
*********/
|
||||
/// <summary>Construct an instance.</summary>
|
||||
/// <param name="reflector">Simplifies access to private code.</param>
|
||||
public DictionaryPatches(IReflectionHelper reflector)
|
||||
public DictionaryPatcher(IReflectionHelper reflector)
|
||||
{
|
||||
DictionaryPatches.Reflection = reflector;
|
||||
DictionaryPatcher.Reflection = reflector;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -46,7 +46,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(dictionaryType, "get_Item"),
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(DictionaryPatches.Finalize_GetItem))
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(DictionaryPatcher.Finalize_GetItem))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
/// <param name="key">The dictionary key.</param>
|
||||
private static void AddKeyTo(Exception exception, string key)
|
||||
{
|
||||
DictionaryPatches.Reflection
|
||||
DictionaryPatcher.Reflection
|
||||
.GetField<string>(exception, "_message")
|
||||
.SetValue($"{exception.Message}\nkey: '{key}'");
|
||||
}
|
|
@ -10,7 +10,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
/// <remarks>Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments.</remarks>
|
||||
[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 EventPatches : IHarmonyPatch
|
||||
internal class EventPatcher : IHarmonyPatch
|
||||
{
|
||||
/*********
|
||||
** Fields
|
||||
|
@ -24,9 +24,9 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
*********/
|
||||
/// <summary>Construct an instance.</summary>
|
||||
/// <param name="monitorForGame">Writes messages to the console and log file on behalf of the game.</param>
|
||||
public EventPatches(IMonitor monitorForGame)
|
||||
public EventPatcher(IMonitor monitorForGame)
|
||||
{
|
||||
EventPatches.MonitorForGame = monitorForGame;
|
||||
EventPatcher.MonitorForGame = monitorForGame;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -34,7 +34,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
{
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(typeof(Event), nameof(Event.LogErrorAndHalt)),
|
||||
postfix: new HarmonyMethod(this.GetType(), nameof(EventPatches.After_Event_LogErrorAndHalt))
|
||||
postfix: new HarmonyMethod(this.GetType(), nameof(EventPatcher.After_Event_LogErrorAndHalt))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
/// <param name="e">The exception being logged.</param>
|
||||
private static void After_Event_LogErrorAndHalt(Exception e)
|
||||
{
|
||||
EventPatches.MonitorForGame.Log(e.ToString(), LogLevel.Error);
|
||||
EventPatcher.MonitorForGame.Log(e.ToString(), LogLevel.Error);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
/// <remarks>Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments.</remarks>
|
||||
[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 GameLocationPatches : IHarmonyPatch
|
||||
internal class GameLocationPatcher : IHarmonyPatch
|
||||
{
|
||||
/*********
|
||||
** Fields
|
||||
|
@ -25,9 +25,9 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
*********/
|
||||
/// <summary>Construct an instance.</summary>
|
||||
/// <param name="monitorForGame">Writes messages to the console and log file on behalf of the game.</param>
|
||||
public GameLocationPatches(IMonitor monitorForGame)
|
||||
public GameLocationPatcher(IMonitor monitorForGame)
|
||||
{
|
||||
GameLocationPatches.MonitorForGame = monitorForGame;
|
||||
GameLocationPatcher.MonitorForGame = monitorForGame;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -35,11 +35,11 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
{
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.checkEventPrecondition)),
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(GameLocationPatches.Finalize_GameLocation_CheckEventPrecondition))
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(GameLocationPatcher.Finalize_GameLocation_CheckEventPrecondition))
|
||||
);
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.updateSeasonalTileSheets)),
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(GameLocationPatches.Before_GameLocation_UpdateSeasonalTileSheets))
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(GameLocationPatcher.Before_GameLocation_UpdateSeasonalTileSheets))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
if (__exception != null)
|
||||
{
|
||||
__result = -1;
|
||||
GameLocationPatches.MonitorForGame.Log($"Failed parsing event precondition ({precondition}):\n{__exception.InnerException}", LogLevel.Error);
|
||||
GameLocationPatcher.MonitorForGame.Log($"Failed parsing event precondition ({precondition}):\n{__exception.InnerException}", LogLevel.Error);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -71,7 +71,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
private static Exception Before_GameLocation_UpdateSeasonalTileSheets(GameLocation __instance, Map map, Exception __exception)
|
||||
{
|
||||
if (__exception != null)
|
||||
GameLocationPatches.MonitorForGame.Log($"Failed updating seasonal tilesheets for location '{__instance.NameOrUniqueName}': \n{__exception}", LogLevel.Error);
|
||||
GameLocationPatcher.MonitorForGame.Log($"Failed updating seasonal tilesheets for location '{__instance.NameOrUniqueName}': \n{__exception}", LogLevel.Error);
|
||||
|
||||
return null;
|
||||
}
|
|
@ -11,7 +11,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
/// <remarks>Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments.</remarks>
|
||||
[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 IClickablePatcher : IHarmonyPatch
|
||||
internal class IClickableMenuPatcher : IHarmonyPatch
|
||||
{
|
||||
/*********
|
||||
** Public methods
|
||||
|
@ -21,7 +21,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
{
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.drawToolTip)),
|
||||
prefix: new HarmonyMethod(this.GetType(), nameof(IClickablePatcher.Before_IClickableMenu_DrawTooltip))
|
||||
prefix: new HarmonyMethod(this.GetType(), nameof(IClickableMenuPatcher.Before_IClickableMenu_DrawTooltip))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
/// <remarks>Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments.</remarks>
|
||||
[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 ScheduleErrorPatch : IHarmonyPatch
|
||||
internal class NpcPatcher : IHarmonyPatch
|
||||
{
|
||||
/*********
|
||||
** Fields
|
||||
|
@ -26,9 +26,9 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
*********/
|
||||
/// <summary>Construct an instance.</summary>
|
||||
/// <param name="monitorForGame">Writes messages to the console and log file on behalf of the game.</param>
|
||||
public ScheduleErrorPatch(IMonitor monitorForGame)
|
||||
public NpcPatcher(IMonitor monitorForGame)
|
||||
{
|
||||
ScheduleErrorPatch.MonitorForGame = monitorForGame;
|
||||
NpcPatcher.MonitorForGame = monitorForGame;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -36,12 +36,12 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
{
|
||||
harmony.Patch(
|
||||
original: AccessTools.Property(typeof(NPC), nameof(NPC.CurrentDialogue)).GetMethod,
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(ScheduleErrorPatch.Finalize_NPC_CurrentDialogue))
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(NpcPatcher.Finalize_NPC_CurrentDialogue))
|
||||
);
|
||||
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(typeof(NPC), nameof(NPC.parseMasterSchedule)),
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(ScheduleErrorPatch.Finalize_NPC_parseMasterSchedule))
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(NpcPatcher.Finalize_NPC_parseMasterSchedule))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
if (__exception == null)
|
||||
return null;
|
||||
|
||||
ScheduleErrorPatch.MonitorForGame.Log($"Failed loading current dialogue for NPC {__instance.Name}:\n{__exception.GetLogSummary()}", LogLevel.Error);
|
||||
NpcPatcher.MonitorForGame.Log($"Failed loading current dialogue for NPC {__instance.Name}:\n{__exception.GetLogSummary()}", LogLevel.Error);
|
||||
__result = new Stack<Dialogue>();
|
||||
|
||||
return null;
|
||||
|
@ -75,7 +75,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
{
|
||||
if (__exception != null)
|
||||
{
|
||||
ScheduleErrorPatch.MonitorForGame.Log($"Failed parsing schedule for NPC {__instance.Name}:\n{rawData}\n{__exception.GetLogSummary()}", LogLevel.Error);
|
||||
NpcPatcher.MonitorForGame.Log($"Failed parsing schedule for NPC {__instance.Name}:\n{rawData}\n{__exception.GetLogSummary()}", LogLevel.Error);
|
||||
__result = new Dictionary<int, SchedulePathDescription>();
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
/// <remarks>Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments.</remarks>
|
||||
[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 ObjectErrorPatch : IHarmonyPatch
|
||||
internal class ObjectPatcher : IHarmonyPatch
|
||||
{
|
||||
/*********
|
||||
** Public methods
|
||||
|
@ -23,13 +23,13 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
// object.getDescription
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(typeof(SObject), nameof(SObject.getDescription)),
|
||||
prefix: new HarmonyMethod(this.GetType(), nameof(ObjectErrorPatch.Before_Object_GetDescription))
|
||||
prefix: new HarmonyMethod(this.GetType(), nameof(ObjectPatcher.Before_Object_GetDescription))
|
||||
);
|
||||
|
||||
// object.getDisplayName
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(typeof(SObject), "loadDisplayName"),
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(ObjectErrorPatch.Finalize_Object_loadDisplayName))
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(ObjectPatcher.Finalize_Object_loadDisplayName))
|
||||
);
|
||||
}
|
||||
|
|
@ -4,7 +4,6 @@ using System.Diagnostics.CodeAnalysis;
|
|||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using StardewModdingAPI.Framework.Exceptions;
|
||||
using StardewModdingAPI.Framework.Patching;
|
||||
using StardewValley;
|
||||
using StardewValley.Buildings;
|
||||
|
@ -16,7 +15,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
/// <remarks>Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments.</remarks>
|
||||
[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 LoadErrorPatch : IHarmonyPatch
|
||||
internal class SaveGamePatcher : IHarmonyPatch
|
||||
{
|
||||
/*********
|
||||
** Fields
|
||||
|
@ -34,10 +33,10 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
/// <summary>Construct an instance.</summary>
|
||||
/// <param name="monitor">Writes messages to the console and log file.</param>
|
||||
/// <param name="onContentRemoved">A callback invoked when custom content is removed from the save data to avoid a crash.</param>
|
||||
public LoadErrorPatch(IMonitor monitor, Action onContentRemoved)
|
||||
public SaveGamePatcher(IMonitor monitor, Action onContentRemoved)
|
||||
{
|
||||
LoadErrorPatch.Monitor = monitor;
|
||||
LoadErrorPatch.OnContentRemoved = onContentRemoved;
|
||||
SaveGamePatcher.Monitor = monitor;
|
||||
SaveGamePatcher.OnContentRemoved = onContentRemoved;
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,7 +45,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
{
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(typeof(SaveGame), nameof(SaveGame.loadDataToLocations)),
|
||||
prefix: new HarmonyMethod(this.GetType(), nameof(LoadErrorPatch.Before_SaveGame_LoadDataToLocations))
|
||||
prefix: new HarmonyMethod(this.GetType(), nameof(SaveGamePatcher.Before_SaveGame_LoadDataToLocations))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -60,11 +59,11 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
private static bool Before_SaveGame_LoadDataToLocations(List<GameLocation> gamelocations)
|
||||
{
|
||||
bool removedAny =
|
||||
LoadErrorPatch.RemoveBrokenBuildings(gamelocations)
|
||||
| LoadErrorPatch.RemoveInvalidNpcs(gamelocations);
|
||||
SaveGamePatcher.RemoveBrokenBuildings(gamelocations)
|
||||
| SaveGamePatcher.RemoveInvalidNpcs(gamelocations);
|
||||
|
||||
if (removedAny)
|
||||
LoadErrorPatch.OnContentRemoved();
|
||||
SaveGamePatcher.OnContentRemoved();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -85,7 +84,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
}
|
||||
catch (ContentLoadException)
|
||||
{
|
||||
LoadErrorPatch.Monitor.Log($"Removed invalid building type '{building.buildingType.Value}' in {location.Name} ({building.tileX}, {building.tileY}) to avoid a crash when loading save '{Constants.SaveFolderName}'. (Did you remove a custom building mod?)", LogLevel.Warn);
|
||||
SaveGamePatcher.Monitor.Log($"Removed invalid building type '{building.buildingType.Value}' in {location.Name} ({building.tileX}, {building.tileY}) to avoid a crash when loading save '{Constants.SaveFolderName}'. (Did you remove a custom building mod?)", LogLevel.Warn);
|
||||
location.buildings.Remove(building);
|
||||
removedAny = true;
|
||||
}
|
||||
|
@ -102,7 +101,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
bool removedAny = false;
|
||||
|
||||
IDictionary<string, string> data = Game1.content.Load<Dictionary<string, string>>("Data\\NPCDispositions");
|
||||
foreach (GameLocation location in LoadErrorPatch.GetAllLocations(locations))
|
||||
foreach (GameLocation location in SaveGamePatcher.GetAllLocations(locations))
|
||||
{
|
||||
foreach (NPC npc in location.characters.ToArray())
|
||||
{
|
||||
|
@ -114,7 +113,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
}
|
||||
catch
|
||||
{
|
||||
LoadErrorPatch.Monitor.Log($"Removed invalid villager '{npc.Name}' in {location.Name} ({npc.getTileLocation()}) to avoid a crash when loading save '{Constants.SaveFolderName}'. (Did you remove a custom NPC mod?)", LogLevel.Warn);
|
||||
SaveGamePatcher.Monitor.Log($"Removed invalid villager '{npc.Name}' in {location.Name} ({npc.getTileLocation()}) to avoid a crash when loading save '{Constants.SaveFolderName}'. (Did you remove a custom NPC mod?)", LogLevel.Warn);
|
||||
location.characters.Remove(npc);
|
||||
removedAny = true;
|
||||
}
|
|
@ -10,7 +10,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
/// <remarks>Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments.</remarks>
|
||||
[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 SpriteBatchValidationPatches : IHarmonyPatch
|
||||
internal class SpriteBatchPatcher : IHarmonyPatch
|
||||
{
|
||||
/*********
|
||||
** Public methods
|
||||
|
@ -22,7 +22,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
original: Constants.GameFramework == GameFramework.Xna
|
||||
? AccessTools.Method(typeof(SpriteBatch), "InternalDraw")
|
||||
: AccessTools.Method(typeof(SpriteBatch), "CheckValid", new[] { typeof(Texture2D) }),
|
||||
postfix: new HarmonyMethod(this.GetType(), nameof(SpriteBatchValidationPatches.After_SpriteBatch_CheckValid))
|
||||
postfix: new HarmonyMethod(this.GetType(), nameof(SpriteBatchPatcher.After_SpriteBatch_CheckValid))
|
||||
);
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
/// <remarks>Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments.</remarks>
|
||||
[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 UtilityErrorPatches : IHarmonyPatch
|
||||
internal class UtilityPatcher : IHarmonyPatch
|
||||
{
|
||||
/*********
|
||||
** Public methods
|
||||
|
@ -20,7 +20,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
|
|||
{
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(typeof(Utility), nameof(Utility.getItemFromStandardTextDescription)),
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(UtilityErrorPatches.Finalize_Utility_GetItemFromStandardTextDescription))
|
||||
finalizer: new HarmonyMethod(this.GetType(), nameof(UtilityPatcher.Finalize_Utility_GetItemFromStandardTextDescription))
|
||||
);
|
||||
}
|
||||
|
|
@ -255,7 +255,7 @@ namespace StardewModdingAPI.Framework
|
|||
// apply game patches
|
||||
MiniMonoModHotfix.Apply();
|
||||
new GamePatcher(this.Monitor).Apply(
|
||||
new LoadContextPatch(this.Reflection, this.OnLoadStageChanged),
|
||||
new Game1Patcher(this.Reflection, this.OnLoadStageChanged),
|
||||
new TitleMenuPatcher(this.OnLoadStageChanged)
|
||||
);
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace StardewModdingAPI.Patches
|
|||
/// <remarks>Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments.</remarks>
|
||||
[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 LoadContextPatch : IHarmonyPatch
|
||||
internal class Game1Patcher : IHarmonyPatch
|
||||
{
|
||||
/*********
|
||||
** Fields
|
||||
|
@ -35,10 +35,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 LoadContextPatch(Reflector reflection, Action<LoadStage> onStageChanged)
|
||||
public Game1Patcher(Reflector reflection, Action<LoadStage> onStageChanged)
|
||||
{
|
||||
LoadContextPatch.Reflection = reflection;
|
||||
LoadContextPatch.OnStageChanged = onStageChanged;
|
||||
Game1Patcher.Reflection = reflection;
|
||||
Game1Patcher.OnStageChanged = onStageChanged;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -47,20 +47,20 @@ namespace StardewModdingAPI.Patches
|
|||
// detect CreatedInitialLocations and SaveAddedLocations
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(typeof(Game1), nameof(Game1.AddModNPCs)),
|
||||
prefix: new HarmonyMethod(this.GetType(), nameof(LoadContextPatch.Before_Game1_AddModNPCs))
|
||||
prefix: new HarmonyMethod(this.GetType(), nameof(Game1Patcher.Before_Game1_AddModNPCs))
|
||||
);
|
||||
|
||||
// detect CreatedLocations, and track IsInLoadForNewGame
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(typeof(Game1), nameof(Game1.loadForNewGame)),
|
||||
prefix: new HarmonyMethod(this.GetType(), nameof(LoadContextPatch.Before_Game1_LoadForNewGame)),
|
||||
postfix: new HarmonyMethod(this.GetType(), nameof(LoadContextPatch.After_Game1_LoadForNewGame))
|
||||
prefix: new HarmonyMethod(this.GetType(), nameof(Game1Patcher.Before_Game1_LoadForNewGame)),
|
||||
postfix: new HarmonyMethod(this.GetType(), nameof(Game1Patcher.After_Game1_LoadForNewGame))
|
||||
);
|
||||
|
||||
// detect ReturningToTitle
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(typeof(Game1), nameof(Game1.CleanupReturningToTitle)),
|
||||
prefix: new HarmonyMethod(this.GetType(), nameof(LoadContextPatch.Before_Game1_CleanupReturningToTitle))
|
||||
prefix: new HarmonyMethod(this.GetType(), nameof(Game1Patcher.Before_Game1_CleanupReturningToTitle))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -75,9 +75,9 @@ namespace StardewModdingAPI.Patches
|
|||
{
|
||||
// When this method is called from Game1.loadForNewGame, it happens right after adding the vanilla
|
||||
// locations but before initializing them.
|
||||
if (LoadContextPatch.IsInLoadForNewGame)
|
||||
if (Game1Patcher.IsInLoadForNewGame)
|
||||
{
|
||||
LoadContextPatch.OnStageChanged(LoadContextPatch.IsCreating()
|
||||
Game1Patcher.OnStageChanged(Game1Patcher.IsCreating()
|
||||
? LoadStage.CreatedInitialLocations
|
||||
: LoadStage.SaveAddedLocations
|
||||
);
|
||||
|
@ -91,7 +91,7 @@ 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 Before_Game1_CleanupReturningToTitle()
|
||||
{
|
||||
LoadContextPatch.OnStageChanged(LoadStage.ReturningToTitle);
|
||||
Game1Patcher.OnStageChanged(LoadStage.ReturningToTitle);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ 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 Before_Game1_LoadForNewGame()
|
||||
{
|
||||
LoadContextPatch.IsInLoadForNewGame = true;
|
||||
Game1Patcher.IsInLoadForNewGame = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -108,10 +108,10 @@ 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 After_Game1_LoadForNewGame()
|
||||
{
|
||||
LoadContextPatch.IsInLoadForNewGame = false;
|
||||
Game1Patcher.IsInLoadForNewGame = false;
|
||||
|
||||
if (LoadContextPatch.IsCreating())
|
||||
LoadContextPatch.OnStageChanged(LoadStage.CreatedLocations);
|
||||
if (Game1Patcher.IsCreating())
|
||||
Game1Patcher.OnStageChanged(LoadStage.CreatedLocations);
|
||||
}
|
||||
|
||||
/// <summary>Get whether the save file is currently being created.</summary>
|
||||
|
@ -119,7 +119,7 @@ namespace StardewModdingAPI.Patches
|
|||
{
|
||||
return
|
||||
(Game1.currentMinigame is Intro) // creating save with intro
|
||||
|| (Game1.activeClickableMenu is TitleMenu menu && LoadContextPatch.Reflection.GetField<bool>(menu, "transitioningCharacterCreationMenu").GetValue()); // creating save, skipped intro
|
||||
|| (Game1.activeClickableMenu is TitleMenu menu && Game1Patcher.Reflection.GetField<bool>(menu, "transitioningCharacterCreationMenu").GetValue()); // creating save, skipped intro
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue