From 5f612a20c134356a6a4be92b0eeff7d395618fae Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Mon, 10 Apr 2023 20:04:58 +0530 Subject: [PATCH] Patched the checkAction method instead to avoid the patch from executing multiple times --- stardew-access/HarmonyPatches.cs | 4 ++-- .../Patches/MiscPatches/TrashBearPatch.cs | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 4a4ffbd..ab4f304 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -309,8 +309,8 @@ namespace stardew_access ); harmony.Patch( - original: AccessTools.Method(typeof(TrashBear), nameof(TrashBear.draw), new Type[] { typeof(SpriteBatch) }), - prefix: new HarmonyMethod(typeof(TrashBearPatch), nameof(TrashBearPatch.DrawPatch)) + original: AccessTools.Method(typeof(TrashBear), nameof(TrashBear.checkAction)), + postfix: new HarmonyMethod(typeof(TrashBearPatch), nameof(TrashBearPatch.CheckActionPatch)) ); } } diff --git a/stardew-access/Patches/MiscPatches/TrashBearPatch.cs b/stardew-access/Patches/MiscPatches/TrashBearPatch.cs index ad2592a..75a5667 100644 --- a/stardew-access/Patches/MiscPatches/TrashBearPatch.cs +++ b/stardew-access/Patches/MiscPatches/TrashBearPatch.cs @@ -1,22 +1,23 @@ using StardewValley; +using StardewValley.Characters; namespace stardew_access.Patches { internal class TrashBearPatch { - internal static void DrawPatch(int ___itemWantedIndex, int ___showWantBubbleTimer) + internal static void CheckActionPatch(TrashBear __instance, bool __result, int ___itemWantedIndex, int ___showWantBubbleTimer) { try { - if (___showWantBubbleTimer >= 2900) - { - string itemName = Game1.objectInformation[___itemWantedIndex].Split('/')[4]; - MainClass.ScreenReader.Say($"Trash Bear wants {itemName}!", true); - } + if (__result) return; // The true `true` value of __result indicates the bear is interactable i.e. when giving the bear the wanted item + if (__instance.sprite.Value.CurrentAnimation != null) return; + + string itemName = Game1.objectInformation[___itemWantedIndex].Split('/')[4]; + MainClass.ScreenReader.Say($"Trash Bear wants {itemName}!", true); } catch (Exception e) { - MainClass.ErrorLog($"An error occured TrashBearPatch::DrawPatch():\n{e.Message}\n{e.StackTrace}"); + MainClass.ErrorLog($"An error occured TrashBearPatch::CheckActionPatch():\n{e.Message}\n{e.StackTrace}"); } } }