From 45d80414824e776aa6222b9a32809be2cb47732f Mon Sep 17 00:00:00 2001 From: Becod Date: Sat, 11 Jan 2025 17:52:32 +0800 Subject: [PATCH 1/3] [F] Sudden changes in headphone volume --- .../TimeSaving/EntryToMusicSelection.cs | 68 ++++++++++++++++--- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs b/AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs index 4b00be9..0a62241 100644 --- a/AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs +++ b/AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs @@ -4,6 +4,7 @@ using MAI2.Util; using Manager; using Monitor; +using Monitor.ModeSelect; using Process; using Process.Information; @@ -14,6 +15,12 @@ namespace AquaMai.Mods.Tweaks.TimeSaving; zh: "登录完成后直接进入选歌界面")] public class EntryToMusicSelection { + private static int[] _timers = new int[2]; + + private static CommonValue[] _volumeFadeIns = { new CommonValue(), new CommonValue() }; + + private static readonly bool[] _volumeFadeInState = new bool[2]; + /* * Highly experimental, may well break some stuff * Works by overriding the info screen (where it shows new events and stuff) @@ -25,16 +32,6 @@ public class EntryToMusicSelection public static bool OnUpdate(InformationProcess __instance, ProcessDataContainer ___container) { GameManager.SetMaxTrack(); - // Set headphone volume - for (var i = 0; i < 2; i++) - { - var userData = UserDataManager.Instance.GetUserData(i); - if (userData.IsEntry) - { - OptionHeadphonevolumeID headPhoneVolume = userData.Option.HeadPhoneVolume; - SoundManager.SetHeadPhoneVolume(i, headPhoneVolume.GetValue()); - } - } ___container.processManager.AddProcess(new MusicSelectProcess(___container)); ___container.processManager.ReleaseProcess(__instance); return false; @@ -49,4 +46,53 @@ public static void MapResultMonitorPreInitialize(int monIndex) if (index >= 0) return; userData.MapList.Clear(); } -} + + // Gradually increase headphone volume + [HarmonyPrefix] + [HarmonyPatch(typeof(MusicSelectProcess), "OnUpdate")] + public static void MusicSelectProcessOnUpdate() + { + for (var i = 0; i < 2; i++) + { + if (_volumeFadeInState[i] && _timers[i] == 0) continue; + + if (_timers[i] > 0) + { + _timers[i]--; + } + + if (_volumeFadeInState[i]) + { + if (_timers[i] == 0) + { + SoundManager.SetHeadPhoneVolume(i, _volumeFadeIns[i].end); + } + else if (!_volumeFadeIns[i].UpdateValue()) + { + SoundManager.SetHeadPhoneVolume(i, _volumeFadeIns[i].current); + } + } + else + { + var userData = UserDataManager.Instance.GetUserData(i); + if (!userData.IsEntry) continue; + var value = userData.Option.HeadPhoneVolume.GetValue(); + if (GameManager.IsSelectContinue[i]) + { + _volumeFadeIns[i].start = value; + _volumeFadeIns[i].current = value; + } + else + { + _volumeFadeIns[i].start = 0.05f; + _volumeFadeIns[i].current = 0.05f; + } + + _volumeFadeIns[i].end = value; + _volumeFadeIns[i].diff = (_volumeFadeIns[i].end - _volumeFadeIns[i].start) / 90f; + _timers[i] = 90; + _volumeFadeInState[i] = true; + } + } + } +} \ No newline at end of file From f0be20bc6648decfe1bf2b7654dce72308c1c895 Mon Sep 17 00:00:00 2001 From: Becod Date: Thu, 16 Jan 2025 01:30:57 +0800 Subject: [PATCH 2/3] [F]: Should rst _volumeFadeInState when logging out --- .../Tweaks/TimeSaving/EntryToMusicSelection.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs b/AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs index 0a62241..030728c 100644 --- a/AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs +++ b/AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs @@ -95,4 +95,14 @@ public static void MusicSelectProcessOnUpdate() } } } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ContinueProcess), "OnStart")] + public static void ContinueProcessOnStart() + { + for (var i = 0; i < 2; i++) + { + _volumeFadeInState[i] = false; + } + } } \ No newline at end of file From 73ea5b248452ad9f1a0bc4d8c05848d993073410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91?= Date: Sat, 18 Jan 2025 13:52:15 +0800 Subject: [PATCH 3/3] [F]: Reset _volumeFadeInState in GameOver --- AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs b/AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs index 030728c..cf05cab 100644 --- a/AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs +++ b/AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs @@ -97,12 +97,12 @@ public static void MusicSelectProcessOnUpdate() } [HarmonyPrefix] - [HarmonyPatch(typeof(ContinueProcess), "OnStart")] - public static void ContinueProcessOnStart() + [HarmonyPatch(typeof(GameOverProcess), "OnStart")] + public static void GameOverProcessOnStart() { for (var i = 0; i < 2; i++) { _volumeFadeInState[i] = false; } } -} \ No newline at end of file +}