Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[F] Sudden changes in headphone volume #9

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 66 additions & 10 deletions AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using MAI2.Util;
using Manager;
using Monitor;
using Monitor.ModeSelect;
using Process;
using Process.Information;

Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -49,4 +46,63 @@ 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;
}
}
}

[HarmonyPrefix]
[HarmonyPatch(typeof(GameOverProcess), "OnStart")]
public static void GameOverProcessOnStart()
{
for (var i = 0; i < 2; i++)
{
_volumeFadeInState[i] = false;
}
}
}