From 07ee892b43fd44daec0a970fd7c7d1f97315f1bf Mon Sep 17 00:00:00 2001 From: akanyan Date: Tue, 30 Jul 2024 02:22:25 +0900 Subject: [PATCH] feat: implement SelectBGM --- Mu3Mods.csproj | 2 +- Mu3Mods.sln | 6 +++ SelectBGM/MU3.Game/patch_GameBGM.cs | 14 +++++++ SelectBGM/MU3.Sequence/patch_Play.cs | 38 +++++++++++++++++++ ...tch_Scene_32_PrePlayMusic_ChapterSelect.cs | 22 +++++++++++ SelectBGM/SelectBGM.csproj | 7 ++++ 6 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 SelectBGM/MU3.Game/patch_GameBGM.cs create mode 100644 SelectBGM/MU3.Sequence/patch_Play.cs create mode 100644 SelectBGM/MU3/patch_Scene_32_PrePlayMusic_ChapterSelect.cs create mode 100644 SelectBGM/SelectBGM.csproj diff --git a/Mu3Mods.csproj b/Mu3Mods.csproj index cb73045..5123fa0 100644 --- a/Mu3Mods.csproj +++ b/Mu3Mods.csproj @@ -2,7 +2,7 @@ net35 7EVENDAYS⇔HOLIDAYS - 2.1.0 + 2.2.0 true latest x64 diff --git a/Mu3Mods.sln b/Mu3Mods.sln index 9c71b3d..7b7b8e2 100644 --- a/Mu3Mods.sln +++ b/Mu3Mods.sln @@ -41,6 +41,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlatinumTiming", "PlatinumT EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AttractVideoPlayer", "AttractVideoPlayer\AttractVideoPlayer.csproj", "{6889330F-2E7E-4778-ADFF-70AF036F1BD5}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SelectBGM", "SelectBGM\SelectBGM.csproj", "{07C01DA1-7ABF-4759-A1C2-9DCD04298E85}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -123,6 +125,10 @@ Global {6889330F-2E7E-4778-ADFF-70AF036F1BD5}.Debug|x64.Build.0 = Debug|x64 {6889330F-2E7E-4778-ADFF-70AF036F1BD5}.Release|x64.ActiveCfg = Release|x64 {6889330F-2E7E-4778-ADFF-70AF036F1BD5}.Release|x64.Build.0 = Release|x64 + {07C01DA1-7ABF-4759-A1C2-9DCD04298E85}.Debug|x64.ActiveCfg = Debug|x64 + {07C01DA1-7ABF-4759-A1C2-9DCD04298E85}.Debug|x64.Build.0 = Debug|x64 + {07C01DA1-7ABF-4759-A1C2-9DCD04298E85}.Release|x64.ActiveCfg = Release|x64 + {07C01DA1-7ABF-4759-A1C2-9DCD04298E85}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SelectBGM/MU3.Game/patch_GameBGM.cs b/SelectBGM/MU3.Game/patch_GameBGM.cs new file mode 100644 index 0000000..708d771 --- /dev/null +++ b/SelectBGM/MU3.Game/patch_GameBGM.cs @@ -0,0 +1,14 @@ +using MU3.Sound; + +namespace MU3.Game; + +class patch_GameBGM: GameBGM { + public static bool WithholdPlay = false; + public extern void orig_playBGM(SoundManager.ACBData acbData, int soundId, int selectorID, bool forcePlay = false); + public new void playBGM(SoundManager.ACBData acbData, int soundId, int selectorID, bool forcePlay = false) { + // Prevents theme music from being restarted + if(!WithholdPlay) { + orig_playBGM(acbData, soundId, selectorID, forcePlay); + } + } +} \ No newline at end of file diff --git a/SelectBGM/MU3.Sequence/patch_Play.cs b/SelectBGM/MU3.Sequence/patch_Play.cs new file mode 100644 index 0000000..65237aa --- /dev/null +++ b/SelectBGM/MU3.Sequence/patch_Play.cs @@ -0,0 +1,38 @@ +using MU3.Data; +using MU3.Game; +using MU3.Util; +using System; + +namespace MU3.Sequence; +class patch_Play: Play { + private LocalSessionInfo _localSessionInfo; + + public static int RecentID = 6; + private extern void orig_Enter_Login(); + private void Enter_Login() { + orig_Enter_Login(); + using IniFile iniFile = new("mu3.ini"); + var index = iniFile.getIntValue("Extra", "BGM", 6); + if(index == 0) { + var rnd = new Random(); + index = rnd.Next(1, 7); + } + if(index < 0 || index > 6) { + index = 6; + } + RecentID = index; + Singleton.instance.gameBGM.playBGM(233, index); + } + + private extern void orig_Enter_ChapterSelect(); + private void Enter_ChapterSelect() { + patch_GameBGM.WithholdPlay = true; + orig_Enter_ChapterSelect(); + patch_GameBGM.WithholdPlay = false; + + int selectorID = SingletonStateMachine.instance.getMemoryChapterData( + _localSessionInfo.chapterSelection.memoryChapterId + )?.getMemoryChapterSelectorID() ?? RecentID; + Singleton.instance.gameBGM.playBGM(233, selectorID); + } +} diff --git a/SelectBGM/MU3/patch_Scene_32_PrePlayMusic_ChapterSelect.cs b/SelectBGM/MU3/patch_Scene_32_PrePlayMusic_ChapterSelect.cs new file mode 100644 index 0000000..62c2b18 --- /dev/null +++ b/SelectBGM/MU3/patch_Scene_32_PrePlayMusic_ChapterSelect.cs @@ -0,0 +1,22 @@ +using MU3.Game; +using MU3.Sequence; +using MU3.Util; +using MU3.ViewData; + +namespace MU3; +class patch_Scene_32_PrePlayMusic_ChapterSelect: Scene_32_PrePlayMusic_ChapterSelect { + private ChapterSelectorItemViewData _selectItemViewData; + private extern void orig_onChangeElement(int index, int indexRaw); + private void onChangeElement(int index, int indexRaw) { + patch_GameBGM.WithholdPlay = true; + orig_onChangeElement(index, indexRaw); + patch_GameBGM.WithholdPlay = false; + + int selectorID = ( + (_selectItemViewData.memoryChapterViewData == null) + ? null + : _selectItemViewData.memoryChapterViewData.memoryChapterData + )?.getMemoryChapterSelectorID() ?? patch_Play.RecentID; + Singleton.instance.gameBGM.playBGM(233, selectorID); + } +} diff --git a/SelectBGM/SelectBGM.csproj b/SelectBGM/SelectBGM.csproj new file mode 100644 index 0000000..9b2115e --- /dev/null +++ b/SelectBGM/SelectBGM.csproj @@ -0,0 +1,7 @@ + + + Assembly-CSharp.SelectBGM.mm + Select main menu BGM + + + \ No newline at end of file