From b89a8f205d7f5cb99bfe5953c5dfcdf871698b97 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Sun, 12 Feb 2023 15:14:46 +0530 Subject: [PATCH] Added progress sound when catching a fish --- stardew-access/HarmonyPatches.cs | 6 +++ .../Patches/FishingMiniGamePatch.cs | 38 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 stardew-access/Patches/FishingMiniGamePatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index dcdc7bd..fd7be52 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -274,6 +274,12 @@ namespace stardew_access original: AccessTools.Method(typeof(GrandpaStory), nameof(GrandpaStory.draw), new Type[] { typeof(SpriteBatch) }), postfix: new HarmonyMethod(typeof(MiniGamesPatches), nameof(MiniGamesPatches.GrandpaStoryPatch)) ); + + harmony.Patch( + original: AccessTools.Method(typeof(BobberBar), nameof(BobberBar.update)), + postfix: new HarmonyMethod(typeof(FishingMiniGamePatch), nameof(FishingMiniGamePatch.BobberBarPatch)) + ); + #endregion harmony.Patch( diff --git a/stardew-access/Patches/FishingMiniGamePatch.cs b/stardew-access/Patches/FishingMiniGamePatch.cs new file mode 100644 index 0000000..e7fd725 --- /dev/null +++ b/stardew-access/Patches/FishingMiniGamePatch.cs @@ -0,0 +1,38 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches { + internal class FishingMiniGamePatch { + private static ICue? progressSound = null; + + internal static void BobberBarPatch(BobberBar __instance, float ___distanceFromCatching, float ___bobberPosition, float ___bobberBarPos, bool ___bobberInBar, bool ___fadeOut, bool ___fadeIn) { + try { + handleProgressBarSound(___distanceFromCatching, ___fadeOut, ___fadeIn); + // MainClass.DebugLog($"dist: {___distanceFromCatching}\tbobPos: {___bobberPosition}\tbobbarpos{___bobberBarPos}"); + } catch (System.Exception e) { + MainClass.ErrorLog($"An error occured while patching bobber bar:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static void handleProgressBarSound(float ___distanceFromCatching, bool ___fadeOut, bool ___fadeIn) { + if(Game1.soundBank == null) return; + + if (progressSound == null) { + progressSound = Game1.soundBank.GetCue("SinWave"); + } + + progressSound.SetVariable("Pitch", 2400f * ___distanceFromCatching); + // progressSound.SetVariable("Volume", 300f); + + if (___fadeIn && !progressSound.IsPlaying) { + // Start playing the sound on menu open + progressSound.Play(); + } + + if(___fadeOut && progressSound.IsPlaying) { + // Stop playing the sound on menu close + progressSound.Stop(Microsoft.Xna.Framework.Audio.AudioStopOptions.Immediate); + } + } + } +}