From 2765e3f9b379f0dc2a5732c1ca9ba23dbe2a7f15 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 13 Apr 2022 22:06:07 -0400 Subject: enable nullable annotations in bundled mods (#837) --- src/SMAPI.Mods.ErrorHandler/Patches/DialoguePatcher.cs | 10 ++++------ src/SMAPI.Mods.ErrorHandler/Patches/EventPatcher.cs | 4 +--- src/SMAPI.Mods.ErrorHandler/Patches/GameLocationPatcher.cs | 9 +++------ src/SMAPI.Mods.ErrorHandler/Patches/IClickableMenuPatcher.cs | 2 -- src/SMAPI.Mods.ErrorHandler/Patches/NpcPatcher.cs | 8 +++----- src/SMAPI.Mods.ErrorHandler/Patches/ObjectPatcher.cs | 4 +--- src/SMAPI.Mods.ErrorHandler/Patches/SaveGamePatcher.cs | 10 ++++------ src/SMAPI.Mods.ErrorHandler/Patches/SpriteBatchPatcher.cs | 6 ++---- src/SMAPI.Mods.ErrorHandler/Patches/UtilityPatcher.cs | 4 +--- 9 files changed, 19 insertions(+), 38 deletions(-) (limited to 'src/SMAPI.Mods.ErrorHandler/Patches') diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/DialoguePatcher.cs b/src/SMAPI.Mods.ErrorHandler/Patches/DialoguePatcher.cs index b05c8cca..e98eec3c 100644 --- a/src/SMAPI.Mods.ErrorHandler/Patches/DialoguePatcher.cs +++ b/src/SMAPI.Mods.ErrorHandler/Patches/DialoguePatcher.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Diagnostics.CodeAnalysis; using HarmonyLib; @@ -19,10 +17,10 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches ** Fields *********/ /// Writes messages to the console and log file on behalf of the game. - private static IMonitor MonitorForGame; + private static IMonitor MonitorForGame = null!; /// Simplifies access to private code. - private static IReflectionHelper Reflection; + private static IReflectionHelper Reflection = null!; /********* @@ -56,12 +54,12 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches /// The NPC for which the dialogue is being parsed. /// The exception thrown by the wrapped method, if any. /// Returns the exception to throw, if any. - private static Exception Finalize_Constructor(Dialogue __instance, string masterDialogue, NPC speaker, Exception __exception) + private static Exception? Finalize_Constructor(Dialogue __instance, string masterDialogue, NPC? speaker, Exception? __exception) { if (__exception != null) { // log message - string name = !string.IsNullOrWhiteSpace(speaker?.Name) ? speaker.Name : null; + string? name = !string.IsNullOrWhiteSpace(speaker?.Name) ? speaker.Name : null; DialoguePatcher.MonitorForGame.Log($"Failed parsing dialogue string{(name != null ? $" for {name}" : "")}:\n{masterDialogue}\n{__exception.GetLogSummary()}", LogLevel.Error); // set default dialogue diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/EventPatcher.cs b/src/SMAPI.Mods.ErrorHandler/Patches/EventPatcher.cs index 63674d09..073c62cc 100644 --- a/src/SMAPI.Mods.ErrorHandler/Patches/EventPatcher.cs +++ b/src/SMAPI.Mods.ErrorHandler/Patches/EventPatcher.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Diagnostics.CodeAnalysis; using HarmonyLib; @@ -18,7 +16,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches ** Fields *********/ /// Writes messages to the console and log file on behalf of the game. - private static IMonitor MonitorForGame; + private static IMonitor MonitorForGame = null!; /********* diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/GameLocationPatcher.cs b/src/SMAPI.Mods.ErrorHandler/Patches/GameLocationPatcher.cs index 98aa4a38..9247fa48 100644 --- a/src/SMAPI.Mods.ErrorHandler/Patches/GameLocationPatcher.cs +++ b/src/SMAPI.Mods.ErrorHandler/Patches/GameLocationPatcher.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Diagnostics.CodeAnalysis; using HarmonyLib; @@ -19,8 +17,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches ** Fields *********/ /// Writes messages to the console and log file on behalf of the game. - private static IMonitor MonitorForGame; - + private static IMonitor MonitorForGame = null!; /********* ** Public methods @@ -54,7 +51,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches /// The precondition to be parsed. /// The exception thrown by the wrapped method, if any. /// Returns the exception to throw, if any. - private static Exception Finalize_CheckEventPrecondition(ref int __result, string precondition, Exception __exception) + private static Exception? Finalize_CheckEventPrecondition(ref int __result, string precondition, Exception? __exception) { if (__exception != null) { @@ -70,7 +67,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches /// The map whose tilesheets to update. /// The exception thrown by the wrapped method, if any. /// Returns the exception to throw, if any. - private static Exception Finalize_UpdateSeasonalTileSheets(GameLocation __instance, Map map, Exception __exception) + private static Exception? Finalize_UpdateSeasonalTileSheets(GameLocation __instance, Map map, Exception? __exception) { if (__exception != null) GameLocationPatcher.MonitorForGame.Log($"Failed updating seasonal tilesheets for location '{__instance.NameOrUniqueName}': \n{__exception}", LogLevel.Error); diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/IClickableMenuPatcher.cs b/src/SMAPI.Mods.ErrorHandler/Patches/IClickableMenuPatcher.cs index 85ce8ac4..b65a695a 100644 --- a/src/SMAPI.Mods.ErrorHandler/Patches/IClickableMenuPatcher.cs +++ b/src/SMAPI.Mods.ErrorHandler/Patches/IClickableMenuPatcher.cs @@ -1,5 +1,3 @@ -#nullable disable - using System.Diagnostics.CodeAnalysis; using HarmonyLib; using StardewModdingAPI.Internal.Patching; diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/NpcPatcher.cs b/src/SMAPI.Mods.ErrorHandler/Patches/NpcPatcher.cs index 5354f724..11f7ec69 100644 --- a/src/SMAPI.Mods.ErrorHandler/Patches/NpcPatcher.cs +++ b/src/SMAPI.Mods.ErrorHandler/Patches/NpcPatcher.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -20,7 +18,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches ** Fields *********/ /// Writes messages to the console and log file on behalf of the game. - private static IMonitor MonitorForGame; + private static IMonitor MonitorForGame = null!; /********* @@ -56,7 +54,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches /// The return value of the original method. /// The exception thrown by the wrapped method, if any. /// Returns the exception to throw, if any. - private static Exception Finalize_CurrentDialogue(NPC __instance, ref Stack __result, Exception __exception) + private static Exception? Finalize_CurrentDialogue(NPC __instance, ref Stack __result, Exception? __exception) { if (__exception == null) return null; @@ -73,7 +71,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches /// The patched method's return value. /// The exception thrown by the wrapped method, if any. /// Returns the exception to throw, if any. - private static Exception Finalize_ParseMasterSchedule(string rawData, NPC __instance, ref Dictionary __result, Exception __exception) + private static Exception? Finalize_ParseMasterSchedule(string rawData, NPC __instance, ref Dictionary __result, Exception? __exception) { if (__exception != null) { diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/ObjectPatcher.cs b/src/SMAPI.Mods.ErrorHandler/Patches/ObjectPatcher.cs index 499718b0..09a6fbbd 100644 --- a/src/SMAPI.Mods.ErrorHandler/Patches/ObjectPatcher.cs +++ b/src/SMAPI.Mods.ErrorHandler/Patches/ObjectPatcher.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -59,7 +57,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches /// The patched method's return value. /// The exception thrown by the wrapped method, if any. /// Returns the exception to throw, if any. - private static Exception Finalize_Object_loadDisplayName(ref string __result, Exception __exception) + private static Exception? Finalize_Object_loadDisplayName(ref string __result, Exception? __exception) { if (__exception is KeyNotFoundException) { diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/SaveGamePatcher.cs b/src/SMAPI.Mods.ErrorHandler/Patches/SaveGamePatcher.cs index 1941d2a8..490bbfb6 100644 --- a/src/SMAPI.Mods.ErrorHandler/Patches/SaveGamePatcher.cs +++ b/src/SMAPI.Mods.ErrorHandler/Patches/SaveGamePatcher.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -24,10 +22,10 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches ** Fields *********/ /// Writes messages to the console and log file. - private static IMonitor Monitor; + private static IMonitor Monitor = null!; /// A callback invoked when custom content is removed from the save data to avoid a crash. - private static Action OnContentRemoved; + private static Action OnContentRemoved = null!; /********* @@ -76,7 +74,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches /// The method to call after throws an exception. /// The exception thrown by the wrapped method, if any. /// Returns the exception to throw, if any. - private static Exception Finalize_LoadFarmType(Exception __exception) + private static Exception? Finalize_LoadFarmType(Exception? __exception) { // missing custom farm type if (__exception?.Message.Contains("not a valid farm type") == true && !int.TryParse(SaveGame.loaded.whichFarm, out _)) @@ -110,7 +108,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches /// Remove content which no longer exists in the game data. /// The current game location. /// The NPC data. - private static bool RemoveBrokenContent(GameLocation location, IDictionary npcs) + private static bool RemoveBrokenContent(GameLocation? location, IDictionary npcs) { bool removedAny = false; if (location == null) diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/SpriteBatchPatcher.cs b/src/SMAPI.Mods.ErrorHandler/Patches/SpriteBatchPatcher.cs index b4c03bb9..d369e0ef 100644 --- a/src/SMAPI.Mods.ErrorHandler/Patches/SpriteBatchPatcher.cs +++ b/src/SMAPI.Mods.ErrorHandler/Patches/SpriteBatchPatcher.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Diagnostics.CodeAnalysis; using HarmonyLib; @@ -30,9 +28,9 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches /********* ** Private methods *********/ - /// The method to call after . + /// The method to call after . /// The texture to validate. - private static void After_CheckValid(Texture2D texture) + private static void After_CheckValid(Texture2D? texture) { if (texture?.IsDisposed == true) throw new ObjectDisposedException("Cannot draw this texture because it's disposed."); diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/UtilityPatcher.cs b/src/SMAPI.Mods.ErrorHandler/Patches/UtilityPatcher.cs index 108ed585..6d75a581 100644 --- a/src/SMAPI.Mods.ErrorHandler/Patches/UtilityPatcher.cs +++ b/src/SMAPI.Mods.ErrorHandler/Patches/UtilityPatcher.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Diagnostics.CodeAnalysis; using HarmonyLib; @@ -35,7 +33,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches /// The delimiter by which to split the text description. /// The exception thrown by the wrapped method, if any. /// Returns the exception to throw, if any. - private static Exception Finalize_GetItemFromStandardTextDescription(string description, char delimiter, ref Exception __exception) + private static Exception? Finalize_GetItemFromStandardTextDescription(string description, char delimiter, ref Exception? __exception) { return __exception != null ? new FormatException($"Failed to parse item text description \"{description}\" with delimiter \"{delimiter}\".", __exception) -- cgit