Moved patches related to Game1 and InstanceGame to their own class

master
Mohammad Shoaib Khan 2023-03-10 14:32:43 +05:30
parent 50e8afc78c
commit c553b589ab
No known key found for this signature in database
GPG Key ID: D8040D966320B620
5 changed files with 71 additions and 62 deletions

View File

@ -222,9 +222,10 @@ namespace stardew_access
original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.exitThisMenu)), original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.exitThisMenu)),
postfix: new HarmonyMethod(typeof(IClickableMenuPatch), nameof(IClickableMenuPatch.ExitThisMenuPatch)) postfix: new HarmonyMethod(typeof(IClickableMenuPatch), nameof(IClickableMenuPatch.ExitThisMenuPatch))
); );
harmony.Patch( harmony.Patch(
original: AccessTools.Method(typeof(Game1), nameof(Game1.exitActiveMenu)), 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 #endregion
@ -278,12 +279,12 @@ namespace stardew_access
harmony.Patch( harmony.Patch(
original: AccessTools.Method(typeof(Game1), nameof(Game1.playSound)), 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( harmony.Patch(
original: AccessTools.Method(typeof(InstanceGame), nameof(InstanceGame.Exit)), 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( harmony.Patch(

View File

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

View File

@ -0,0 +1,11 @@
namespace stardew_access.Patches
{
internal class InstanceGamePatch
{
internal static void ExitPatch()
{
if (MainClass.ScreenReader != null)
MainClass.ScreenReader.CloseScreenReader();
}
}
}

View File

@ -17,7 +17,6 @@ namespace stardew_access.Patches
internal static string forgeMenuQuery = " "; internal static string forgeMenuQuery = " ";
internal static string itemListMenuQuery = " "; internal static string itemListMenuQuery = " ";
internal static int prevSlotIndex = -999; internal static int prevSlotIndex = -999;
public static Vector2? prevTile = null;
internal static void ItemListMenuPatch(ItemListMenu __instance, string ___title, int ___currentTab, int ___totalValueOfItems, List<Item> ___itemsToList) internal static void ItemListMenuPatch(ItemListMenu __instance, string ___title, int ___currentTab, int ___totalValueOfItems, List<Item> ___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) 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();
}
} }
} }

View File

@ -1,11 +0,0 @@
using Microsoft.Xna.Framework.Graphics;
using StardewValley;
using StardewValley.Menus;
using StardewValley.Quests;
namespace stardew_access.Patches
{
internal class QuestPatches
{
}
}