From c553b589abbd87d90b995a2e958382f2f6d97b39 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 14:32:43 +0530 Subject: [PATCH] Moved patches related to Game1 and InstanceGame to their own class --- stardew-access/HarmonyPatches.cs | 7 +-- stardew-access/Patches/Game1Patch.cs | 56 +++++++++++++++++++++ stardew-access/Patches/InstanceGamePatch.cs | 11 ++++ stardew-access/Patches/MenuPatches.cs | 48 ------------------ stardew-access/Patches/QuestPatches.cs | 11 ---- 5 files changed, 71 insertions(+), 62 deletions(-) create mode 100644 stardew-access/Patches/Game1Patch.cs create mode 100644 stardew-access/Patches/InstanceGamePatch.cs delete mode 100644 stardew-access/Patches/QuestPatches.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 78d8c22..cb8d85c 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -222,9 +222,10 @@ namespace stardew_access original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.exitThisMenu)), postfix: new HarmonyMethod(typeof(IClickableMenuPatch), nameof(IClickableMenuPatch.ExitThisMenuPatch)) ); + harmony.Patch( original: AccessTools.Method(typeof(Game1), nameof(Game1.exitActiveMenu)), - prefix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.Game1ExitActiveMenuPatch)) + prefix: new HarmonyMethod(typeof(Game1Patch), nameof(Game1Patch.ExitActiveMenuPatch)) ); #endregion @@ -278,12 +279,12 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(Game1), nameof(Game1.playSound)), - prefix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.PlaySoundPatch)) + prefix: new HarmonyMethod(typeof(Game1Patch), nameof(Game1Patch.PlaySoundPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(InstanceGame), nameof(InstanceGame.Exit)), - prefix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ExitEventPatch)) + prefix: new HarmonyMethod(typeof(InstanceGamePatch), nameof(InstanceGamePatch.ExitPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/Game1Patch.cs b/stardew-access/Patches/Game1Patch.cs new file mode 100644 index 0000000..04ba91f --- /dev/null +++ b/stardew-access/Patches/Game1Patch.cs @@ -0,0 +1,56 @@ +using Microsoft.Xna.Framework; +using stardew_access.Features; +using StardewModdingAPI; +using StardewValley; + +namespace stardew_access.Patches +{ + internal class Game1Patch + { + private static Vector2? prevTile = null; + + internal static void ExitActiveMenuPatch() + { + try + { + IClickableMenuPatch.Cleanup(Game1.activeClickableMenu); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static bool PlaySoundPatch(string cueName) + { + try + { + if (!Context.IsPlayerFree) + return true; + + if (!Game1.player.isMoving()) + return true; + + if (cueName == "grassyStep" || cueName == "sandyStep" || cueName == "snowyStep" || cueName == "stoneStep" || cueName == "thudStep" || cueName == "woodyStep") + { + Vector2 nextTile = CurrentPlayer.FacingTile; + if (TileInfo.isCollidingAtTile((int)nextTile.X, (int)nextTile.Y)) + { + if (prevTile != nextTile) + { + prevTile = nextTile; + //Game1.playSound("colliding"); + } + return false; + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + + return true; + } + } +} diff --git a/stardew-access/Patches/InstanceGamePatch.cs b/stardew-access/Patches/InstanceGamePatch.cs new file mode 100644 index 0000000..93affb1 --- /dev/null +++ b/stardew-access/Patches/InstanceGamePatch.cs @@ -0,0 +1,11 @@ +namespace stardew_access.Patches +{ + internal class InstanceGamePatch + { + internal static void ExitPatch() + { + if (MainClass.ScreenReader != null) + MainClass.ScreenReader.CloseScreenReader(); + } + } +} diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 2576c40..1aa61a1 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -17,7 +17,6 @@ namespace stardew_access.Patches internal static string forgeMenuQuery = " "; internal static string itemListMenuQuery = " "; internal static int prevSlotIndex = -999; - public static Vector2? prevTile = null; internal static void ItemListMenuPatch(ItemListMenu __instance, string ___title, int ___currentTab, int ___totalValueOfItems, List ___itemsToList) { @@ -312,37 +311,6 @@ namespace stardew_access.Patches } } - internal static bool PlaySoundPatch(string cueName) - { - try - { - if (!Context.IsPlayerFree) - return true; - - if (!Game1.player.isMoving()) - return true; - - if (cueName == "grassyStep" || cueName == "sandyStep" || cueName == "snowyStep" || cueName == "stoneStep" || cueName == "thudStep" || cueName == "woodyStep") - { - Vector2 nextTile = CurrentPlayer.FacingTile; - if (TileInfo.isCollidingAtTile((int)nextTile.X, (int)nextTile.Y)) - { - if (prevTile != nextTile) - { - prevTile = nextTile; - //Game1.playSound("colliding"); - } - return false; - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - - return true; - } internal static void LanguageSelectionMenuPatch(LanguageSelectionMenu __instance) { @@ -604,22 +572,6 @@ namespace stardew_access.Patches } } - internal static void Game1ExitActiveMenuPatch() - { - try - { - IClickableMenuPatch.Cleanup(Game1.activeClickableMenu); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void ExitEventPatch() - { - if (MainClass.ScreenReader != null) - MainClass.ScreenReader.CloseScreenReader(); - } } } diff --git a/stardew-access/Patches/QuestPatches.cs b/stardew-access/Patches/QuestPatches.cs deleted file mode 100644 index cbe8441..0000000 --- a/stardew-access/Patches/QuestPatches.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.Xna.Framework.Graphics; -using StardewValley; -using StardewValley.Menus; -using StardewValley.Quests; - -namespace stardew_access.Patches -{ - internal class QuestPatches - { - } -}