diff --git a/stardew-access/Features/Other.cs b/stardew-access/Features/Other.cs index a518787..6876480 100644 --- a/stardew-access/Features/Other.cs +++ b/stardew-access/Features/Other.cs @@ -67,9 +67,8 @@ namespace stardew_access.Features Game1.setMousePosition(x, y); } - public static async void narrateHudMessages() + public static void narrateHudMessages() { - MainClass.isNarratingHudMessage = true; try { if (Game1.hudMessages.Count > 0) @@ -99,8 +98,6 @@ namespace stardew_access.Features MainClass.ErrorLog($"Unable to narrate hud messages:\n{e.Message}\n{e.StackTrace}"); } - await Task.Delay(300); - MainClass.isNarratingHudMessage = false; } } } diff --git a/stardew-access/Features/Radar.cs b/stardew-access/Features/Radar.cs index e0a708e..62b4c27 100644 --- a/stardew-access/Features/Radar.cs +++ b/stardew-access/Features/Radar.cs @@ -96,12 +96,11 @@ namespace stardew_access.Features */ } - public async void Run() + public void Run() { if (MainClass.radarDebug) MainClass.DebugLog($"\n\nRead Tile started"); - isRunning = true; Vector2 currPosition = Game1.player.getTileLocation(); closed.Clear(); @@ -112,9 +111,6 @@ namespace stardew_access.Features if (MainClass.radarDebug) MainClass.DebugLog($"\nRead Tile stopped\n\n"); - - await Task.Delay(delay); - isRunning = false; } /// diff --git a/stardew-access/Features/ReadTile.cs b/stardew-access/Features/ReadTile.cs index acf3117..c02fcb1 100644 --- a/stardew-access/Features/ReadTile.cs +++ b/stardew-access/Features/ReadTile.cs @@ -22,10 +22,8 @@ namespace stardew_access.Features isReadingTile = false; } - public static async void run(bool manuallyTriggered = false, bool playersPosition = false) + public static void run(bool manuallyTriggered = false, bool playersPosition = false) { - isReadingTile = true; - try { Vector2 tile; @@ -82,9 +80,6 @@ namespace stardew_access.Features { MainClass.ErrorLog($"Error in Read Tile:\n{e.Message}\n{e.StackTrace}"); } - - await Task.Delay(100); - isReadingTile = false; } ///Returns the name of the object at tile alongwith it's category's name diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index d060b90..a145139 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -170,7 +170,7 @@ namespace stardew_access #region Chat Menu Patches harmony.Patch( original: AccessTools.Method(typeof(ChatBox), nameof(ChatBox.update), new Type[] { typeof(GameTime) }), - postfix: new HarmonyMethod(typeof(ChatManuPatches), nameof(ChatManuPatches.ChatBoxPatch)) + postfix: new HarmonyMethod(typeof(ChatMenuPatches), nameof(ChatMenuPatches.ChatBoxPatch)) ); #endregion diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 8deeb5d..c982f3c 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -120,14 +120,24 @@ namespace stardew_access Other.SnapMouseToPlayer(); if (!ReadTile.isReadingTile && Config.ReadTile) + { + ReadTile.isReadingTile = true; ReadTile.run(); + Task.Delay(100).ContinueWith(_ => { ReadTile.isReadingTile = false; }); + } if (!RadarFeature.isRunning && Config.Radar) + { + RadarFeature.isRunning = true; RadarFeature.Run(); + Task.Delay(RadarFeature.delay).ContinueWith(_ => { RadarFeature.isRunning = false; }); + } if (!isNarratingHudMessage) { + isNarratingHudMessage = true; Other.narrateHudMessages(); + Task.Delay(300).ContinueWith(_ => { isNarratingHudMessage = false; }); } } diff --git a/stardew-access/Patches/ChatManuPatches.cs b/stardew-access/Patches/ChatMenuPatches.cs similarity index 86% rename from stardew-access/Patches/ChatManuPatches.cs rename to stardew-access/Patches/ChatMenuPatches.cs index e30427e..6b3a07a 100644 --- a/stardew-access/Patches/ChatManuPatches.cs +++ b/stardew-access/Patches/ChatMenuPatches.cs @@ -1,10 +1,9 @@ -using StardewModdingAPI; -using StardewValley; +using StardewValley; using StardewValley.Menus; namespace stardew_access.Patches { - internal class ChatManuPatches + internal class ChatMenuPatches { private static int currentChatMessageIndex = 0; private static bool isChatRunning = false; @@ -25,11 +24,15 @@ namespace stardew_access.Patches #region To narrate previous and next chat messages if (isNextArrowPressed && !isChatRunning) { + isChatRunning = true; CycleThroughChatMessages(true, ___messages); + Task.Delay(200).ContinueWith(_ => { isChatRunning = false; }); } else if (isPrevArrowPressed && !isChatRunning) { + isChatRunning = true; CycleThroughChatMessages(false, ___messages); + Task.Delay(200).ContinueWith(_ => { isChatRunning = false; }); } #endregion } @@ -52,9 +55,8 @@ namespace stardew_access.Patches } } - private static async void CycleThroughChatMessages(bool increase, List ___messages) + private static void CycleThroughChatMessages(bool increase, List ___messages) { - isChatRunning = true; string toSpeak = " "; if (increase) { @@ -78,8 +80,6 @@ namespace stardew_access.Patches }); MainClass.GetScreenReader().Say(toSpeak, true); - await Task.Delay(200); - isChatRunning = false; } } } diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index e3f17ca..90481a7 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -1,5 +1,4 @@ -using StardewModdingAPI; -using StardewValley; +using StardewValley; using StardewValley.Locations; using StardewValley.Menus; using StardewValley.Objects; @@ -104,15 +103,21 @@ namespace stardew_access.Patches if (isIPressed && !isUsingCustomButtons) { + isUsingCustomButtons = true; JunimoNoteCustomButtons(__instance, ___currentPageBundle, 0, isLeftShiftPressed); + Task.Delay(200).ContinueWith(_ => { isUsingCustomButtons = false; }); } else if (isVPressed && !isUsingCustomButtons) { + isUsingCustomButtons = true; JunimoNoteCustomButtons(__instance, ___currentPageBundle, 1, isLeftShiftPressed); + Task.Delay(200).ContinueWith(_ => { isUsingCustomButtons = false; }); } else if (isCPressed && !isUsingCustomButtons) { + isUsingCustomButtons = true; JunimoNoteCustomButtons(__instance, ___currentPageBundle, 2, isLeftShiftPressed); + Task.Delay(200).ContinueWith(_ => { isUsingCustomButtons = false; }); } else if (isBackPressed && __instance.backButton != null && !__instance.backButton.containsPoint(x, y)) { @@ -133,9 +138,8 @@ namespace stardew_access.Patches } } - private static async void JunimoNoteCustomButtons(JunimoNoteMenu __instance, Bundle ___currentPageBundle, int signal, bool isLeftShiftPressed = false) + private static void JunimoNoteCustomButtons(JunimoNoteMenu __instance, Bundle ___currentPageBundle, int signal, bool isLeftShiftPressed = false) { - isUsingCustomButtons = true; try { @@ -291,9 +295,6 @@ namespace stardew_access.Patches { MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); } - - await Task.Delay(200); - isUsingCustomButtons = false; } internal static void SocialPagePatch(SocialPage __instance, List ___sprites, int ___slotPosition, List ___kidsNames) @@ -955,7 +956,9 @@ namespace stardew_access.Patches } else if (isCPressed && !isSelectingRecipe) { - _ = CycleThroughRecipies(__instance.pagesOfCraftingRecipes, ___currentCraftingPage, __instance); + isSelectingRecipe = true; + CycleThroughRecipies(__instance.pagesOfCraftingRecipes, ___currentCraftingPage, __instance); + Task.Delay(200).ContinueWith(_ => { isSelectingRecipe = false; }); } #region Narrate buttons in the menu @@ -1103,19 +1106,14 @@ namespace stardew_access.Patches } } - private static async Task CycleThroughRecipies(List> pagesOfCraftingRecipes, int ___currentCraftingPage, CraftingPage __instance) + private static void CycleThroughRecipies(List> pagesOfCraftingRecipes, int ___currentCraftingPage, CraftingPage __instance) { - isSelectingRecipe = true; - currentSelectedCraftingRecipe++; if (currentSelectedCraftingRecipe < 0 || currentSelectedCraftingRecipe >= pagesOfCraftingRecipes[0].Count) currentSelectedCraftingRecipe = 0; __instance.setCurrentlySnappedComponentTo(pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.myID); pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.snapMouseCursorToCenter(); - - await Task.Delay(200); - isSelectingRecipe = false; } // This method is used to get the inventory items to check if the player has enough ingredients for a recipe diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 06d325b..40180dc 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -481,41 +481,12 @@ namespace stardew_access.Patches } } + #region Cleanup on exitting a menu internal static void Game1ExitActiveMenuPatch() { try { - if (Game1.activeClickableMenu is GameMenu) - { - GameMenuPatches.gameMenuQueryKey = ""; - GameMenuPatches.craftingPageQueryKey = ""; - GameMenuPatches.inventoryPageQueryKey = ""; - GameMenuPatches.exitPageQueryKey = ""; - GameMenuPatches.optionsPageQueryKey = ""; - GameMenuPatches.socialPageQuery = ""; - GameMenuPatches.currentSelectedCraftingRecipe = -1; - GameMenuPatches.isSelectingRecipe = false; - } - - if (Game1.activeClickableMenu is JunimoNoteMenu) - { - GameMenuPatches.currentIngredientListItem = -1; - GameMenuPatches.currentIngredientInputSlot = -1; - GameMenuPatches.currentInventorySlot = -1; - GameMenuPatches.junimoNoteMenuQuery = ""; - } - - if (Game1.activeClickableMenu is ShopMenu) - { - GameMenuPatches.shopMenuQueryKey = ""; - } - - if (Game1.activeClickableMenu is ItemGrabMenu) - { - GameMenuPatches.itemGrabMenuQueryKey = ""; - } - - GameMenuPatches.hoveredItemQueryKey = ""; + Cleanup(Game1.activeClickableMenu); } catch (Exception e) { @@ -527,46 +498,7 @@ namespace stardew_access.Patches { try { - if (__instance is GeodeMenu) - { - GameMenuPatches.geodeMenuQueryKey = ""; - } - - if (__instance is ItemGrabMenu) - { - GameMenuPatches.itemGrabMenuQueryKey = ""; - } - - if (__instance is ShopMenu) - { - GameMenuPatches.shopMenuQueryKey = ""; - } - - if (__instance is CarpenterMenu) - { - BuildingNAnimalMenuPatches.carpenterMenuQuery = ""; - BuildingNAnimalMenuPatches.isUpgrading = false; - BuildingNAnimalMenuPatches.isDemolishing = false; - BuildingNAnimalMenuPatches.isPainting = false; - BuildingNAnimalMenuPatches.isMoving = false; - BuildingNAnimalMenuPatches.isConstructing = false; - BuildingNAnimalMenuPatches.carpenterMenu = null; - } - - if (__instance is PurchaseAnimalsMenu) - { - BuildingNAnimalMenuPatches.purchaseAnimalMenuQuery = ""; - BuildingNAnimalMenuPatches.firstTimeInNamingMenu = true; - BuildingNAnimalMenuPatches.purchaseAnimalsMenu = null; - } - - if (__instance is DialogueBox) - { - DialoguePatches.isDialogueAppearingFirstTime = true; - DialoguePatches.currentDialogue = " "; - } - - GameMenuPatches.hoveredItemQueryKey = ""; + Cleanup(__instance); } catch (Exception e) { @@ -574,6 +506,71 @@ namespace stardew_access.Patches } } + private static void Cleanup(IClickableMenu menu) + { + if (menu is GameMenu) + { + GameMenuPatches.gameMenuQueryKey = ""; + GameMenuPatches.craftingPageQueryKey = ""; + GameMenuPatches.inventoryPageQueryKey = ""; + GameMenuPatches.exitPageQueryKey = ""; + GameMenuPatches.optionsPageQueryKey = ""; + GameMenuPatches.socialPageQuery = ""; + GameMenuPatches.currentSelectedCraftingRecipe = -1; + GameMenuPatches.isSelectingRecipe = false; + } + + if (menu is JunimoNoteMenu) + { + GameMenuPatches.currentIngredientListItem = -1; + GameMenuPatches.currentIngredientInputSlot = -1; + GameMenuPatches.currentInventorySlot = -1; + GameMenuPatches.junimoNoteMenuQuery = ""; + } + + if (menu is ShopMenu) + { + GameMenuPatches.shopMenuQueryKey = ""; + } + + if (menu is ItemGrabMenu) + { + GameMenuPatches.itemGrabMenuQueryKey = ""; + } + + if (menu is GeodeMenu) + { + GameMenuPatches.geodeMenuQueryKey = ""; + } + + if (menu is CarpenterMenu) + { + BuildingNAnimalMenuPatches.carpenterMenuQuery = ""; + BuildingNAnimalMenuPatches.isUpgrading = false; + BuildingNAnimalMenuPatches.isDemolishing = false; + BuildingNAnimalMenuPatches.isPainting = false; + BuildingNAnimalMenuPatches.isMoving = false; + BuildingNAnimalMenuPatches.isConstructing = false; + BuildingNAnimalMenuPatches.carpenterMenu = null; + } + + if (menu is PurchaseAnimalsMenu) + { + BuildingNAnimalMenuPatches.purchaseAnimalMenuQuery = ""; + BuildingNAnimalMenuPatches.firstTimeInNamingMenu = true; + BuildingNAnimalMenuPatches.purchaseAnimalsMenu = null; + } + + if (menu is DialogueBox) + { + DialoguePatches.isDialogueAppearingFirstTime = true; + DialoguePatches.currentDialogue = " "; + } + + GameMenuPatches.hoveredItemQueryKey = ""; + } + #endregion + internal static void ExitEventPatch() { if (MainClass.GetScreenReader() != null) diff --git a/stardew-access/Patches/TitleMenuPatches.cs b/stardew-access/Patches/TitleMenuPatches.cs index 6324855..066014e 100644 --- a/stardew-access/Patches/TitleMenuPatches.cs +++ b/stardew-access/Patches/TitleMenuPatches.cs @@ -178,11 +178,15 @@ namespace stardew_access.Patches if (isNextArrowPressed && !isRunning) { - _ = CycleThroughItems(true, __instance, ___skipIntro); + isRunning = true; + CycleThroughItems(true, __instance, ___skipIntro); + Task.Delay(200).ContinueWith(_ => { isRunning = false; }); } else if (isPrevArrowPressed && !isRunning) { - _ = CycleThroughItems(false, __instance, ___skipIntro); + isRunning = true; + CycleThroughItems(false, __instance, ___skipIntro); + Task.Delay(200).ContinueWith(_ => { isRunning = false; }); } } catch (Exception e) @@ -191,9 +195,8 @@ namespace stardew_access.Patches } } - private static async Task CycleThroughItems(bool increase, CharacterCustomization __instance, bool ___skipIntro) + private static void CycleThroughItems(bool increase, CharacterCustomization __instance, bool ___skipIntro) { - isRunning = true; string toSpeak = " "; if (increase) @@ -650,9 +653,6 @@ namespace stardew_access.Patches { MainClass.GetScreenReader().Say(toSpeak, true); } - - await Task.Delay(200); - isRunning = false; } private static string getFarmHoverText(ClickableTextureComponent farm) diff --git a/stardew-access/ScreenReader/ScreenReaderLinux.cs b/stardew-access/ScreenReader/ScreenReaderLinux.cs index 8b85f68..d058cd6 100644 --- a/stardew-access/ScreenReader/ScreenReaderLinux.cs +++ b/stardew-access/ScreenReader/ScreenReaderLinux.cs @@ -1,3 +1,8 @@ +/* + Linux speech dispatcher library used: + https://github.com/shoaib11120/libspeechdwrapper +*/ + using System.Runtime.InteropServices; namespace stardew_access.ScreenReader