diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-10-17 19:53:40 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-10-17 19:53:40 -0400 |
commit | d578345cfd53df8a91ae8e0e1346b711332a999a (patch) | |
tree | fa9a2e6c855a532dbd99910c7cdac1dc468010da /src/SMAPI.Mods.ErrorHandler | |
parent | ebe41180c41f544919c03fb3bf6029437a7d65a4 (diff) | |
parent | f8c9a2929bb42ef7f71fa3a2d258c5566960aa69 (diff) | |
download | SMAPI-d578345cfd53df8a91ae8e0e1346b711332a999a.tar.gz SMAPI-d578345cfd53df8a91ae8e0e1346b711332a999a.tar.bz2 SMAPI-d578345cfd53df8a91ae8e0e1346b711332a999a.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Mods.ErrorHandler')
-rw-r--r-- | src/SMAPI.Mods.ErrorHandler/Patches/DictionaryPatcher.cs | 33 | ||||
-rw-r--r-- | src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj | 2 | ||||
-rw-r--r-- | src/SMAPI.Mods.ErrorHandler/i18n/pl.json | 4 | ||||
-rw-r--r-- | src/SMAPI.Mods.ErrorHandler/i18n/th.json | 4 | ||||
-rw-r--r-- | src/SMAPI.Mods.ErrorHandler/manifest.json | 4 |
5 files changed, 39 insertions, 8 deletions
diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/DictionaryPatcher.cs b/src/SMAPI.Mods.ErrorHandler/Patches/DictionaryPatcher.cs index 6ad64e16..8ceafcc5 100644 --- a/src/SMAPI.Mods.ErrorHandler/Patches/DictionaryPatcher.cs +++ b/src/SMAPI.Mods.ErrorHandler/Patches/DictionaryPatcher.cs @@ -48,6 +48,11 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches original: AccessTools.Method(dictionaryType, "get_Item") ?? throw new InvalidOperationException($"Can't find method {PatchHelper.GetMethodString(dictionaryType, "get_Item")} to patch."), finalizer: this.GetHarmonyMethod(nameof(DictionaryPatcher.Finalize_GetItem)) ); + + harmony.Patch( + original: AccessTools.Method(dictionaryType, "Add") ?? throw new InvalidOperationException($"Can't find method {PatchHelper.GetMethodString(dictionaryType, "Add")} to patch."), + finalizer: this.GetHarmonyMethod(nameof(DictionaryPatcher.Finalize_Add)) + ); } } } @@ -63,13 +68,31 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches private static Exception Finalize_GetItem(object key, Exception __exception) { if (__exception is KeyNotFoundException) - { - DictionaryPatcher.Reflection - .GetField<string>(__exception, "_message") - .SetValue($"{__exception.Message}\nkey: '{key}'"); - } + DictionaryPatcher.AddKey(__exception, key); return __exception; } + + /// <summary>The method to call after a dictionary insert throws an exception.</summary> + /// <param name="key">The dictionary key being inserted.</param> + /// <param name="__exception">The exception thrown by the wrapped method, if any.</param> + /// <returns>Returns the exception to throw, if any.</returns> + private static Exception Finalize_Add(object key, Exception __exception) + { + if (__exception is ArgumentException) + DictionaryPatcher.AddKey(__exception, key); + + return __exception; + } + + /// <summary>Add the dictionary key to an exception message.</summary> + /// <param name="exception">The exception whose message to edit.</param> + /// <param name="key">The dictionary key.</param> + private static void AddKey(Exception exception, object key) + { + DictionaryPatcher.Reflection + .GetField<string>(exception, "_message") + .SetValue($"{exception.Message}\nkey: '{key}'"); + } } } diff --git a/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj b/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj index eb878bc5..182a978e 100644 --- a/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj +++ b/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj @@ -2,7 +2,7 @@ <PropertyGroup> <AssemblyName>ErrorHandler</AssemblyName> <RootNamespace>StardewModdingAPI.Mods.ErrorHandler</RootNamespace> - <TargetFramework>net45</TargetFramework> + <TargetFramework>net452</TargetFramework> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> </PropertyGroup> diff --git a/src/SMAPI.Mods.ErrorHandler/i18n/pl.json b/src/SMAPI.Mods.ErrorHandler/i18n/pl.json new file mode 100644 index 00000000..05a9d411 --- /dev/null +++ b/src/SMAPI.Mods.ErrorHandler/i18n/pl.json @@ -0,0 +1,4 @@ +{
+ // warning messages
+ "warn.invalid-content-removed": "Nieprawidłowa zawartość została usunięta, aby zapobiec awarii (zobacz konsolę SMAPI po więcej informacji)."
+}
diff --git a/src/SMAPI.Mods.ErrorHandler/i18n/th.json b/src/SMAPI.Mods.ErrorHandler/i18n/th.json new file mode 100644 index 00000000..e2a67dda --- /dev/null +++ b/src/SMAPI.Mods.ErrorHandler/i18n/th.json @@ -0,0 +1,4 @@ +{ + // warning messages + "warn.invalid-content-removed": "ทำการลบเนื้อหาที่ไม่ถูกต้องออก เพื่อป้องกันไฟล์เกมเสียหาย (ดูรายละเอียดที่หน้าคอลโซลของ SMAPI)" +} diff --git a/src/SMAPI.Mods.ErrorHandler/manifest.json b/src/SMAPI.Mods.ErrorHandler/manifest.json index 37a7e9bf..cfbaa661 100644 --- a/src/SMAPI.Mods.ErrorHandler/manifest.json +++ b/src/SMAPI.Mods.ErrorHandler/manifest.json @@ -1,9 +1,9 @@ { "Name": "Error Handler", "Author": "SMAPI", - "Version": "3.12.7", + "Version": "3.12.8", "Description": "Handles some common vanilla errors to log more useful info or avoid breaking the game.", "UniqueID": "SMAPI.ErrorHandler", "EntryDll": "ErrorHandler.dll", - "MinimumApiVersion": "3.12.7" + "MinimumApiVersion": "3.12.8" } |