Patched the checkAction method instead to avoid the patch from executing multiple times

master^2
Mohammad Shoaib Khan 2023-04-10 20:04:58 +05:30
parent 6c14d040be
commit 5f612a20c1
2 changed files with 10 additions and 9 deletions

View File

@ -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))
);
}
}

View File

@ -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)
{
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}");
}
}
}