diff --git a/AquaMai/AquaMai.csproj b/AquaMai/AquaMai.csproj index bd63a1d7..2890dfb4 100644 --- a/AquaMai/AquaMai.csproj +++ b/AquaMai/AquaMai.csproj @@ -35,6 +35,9 @@ Libs\Assembly-CSharp.dll + + Libs\Assembly-CSharp-firstpass.dll + Libs\MelonLoader.dll @@ -274,6 +277,7 @@ + diff --git a/AquaMai/AquaMai.toml b/AquaMai/AquaMai.toml index b4ac7e07..96c21b33 100644 --- a/AquaMai/AquaMai.toml +++ b/AquaMai/AquaMai.toml @@ -24,6 +24,8 @@ QuickSkip=true LoadAssetBundleWithoutManifest=true # Skip "New Event" and "Information" text boxes for new users SkipEventInfo=true +# Random BGM, put Mai2Cue.{acb,awb} of old version of the game in `LocalAssets\Mai2Cue` and rename them +RandomBgm=false [Performance] # Disable some useless delays to speed up the game boot process diff --git a/AquaMai/Config.cs b/AquaMai/Config.cs index 876366b9..c4348be0 100644 --- a/AquaMai/Config.cs +++ b/AquaMai/Config.cs @@ -22,6 +22,7 @@ namespace AquaMai public bool LoadJacketPng { get; set; } public bool LoadAssetBundleWithoutManifest { get; set; } public bool QuickSkip { get; set; } + public bool RandomBgm { get; set; } public string CustomVersionString { get; set; } } diff --git a/AquaMai/Libs/Assembly-CSharp-firstpass.dll b/AquaMai/Libs/Assembly-CSharp-firstpass.dll new file mode 100644 index 00000000..24a80f07 Binary files /dev/null and b/AquaMai/Libs/Assembly-CSharp-firstpass.dll differ diff --git a/AquaMai/UX/RandomBgm.cs b/AquaMai/UX/RandomBgm.cs new file mode 100644 index 00000000..545649e3 --- /dev/null +++ b/AquaMai/UX/RandomBgm.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.IO; +using HarmonyLib; +using Mai2.Mai2Cue; +using MAI2.Util; +using Manager; +using MelonLoader; + +namespace AquaMai.UX +{ + public class RandomBgm + { + private static List _acbs = new List(); + private static Random _rng = new Random(); + private static CriAtomExAcb _originalAcb; + + [HarmonyPostfix] + [HarmonyPatch(typeof(SoundManager), "Initialize")] + public static void Init() + { + var files = Directory.EnumerateFiles(Path.Combine(Environment.CurrentDirectory, "LocalAssets", "Mai2Cue")); + foreach (var file in files) + { + if (!file.EndsWith(".acb")) continue; + _acbs.Add(CriAtomExAcb.LoadAcbFile(null, file, Path.ChangeExtension(file, "awb"))); + } + + MelonLogger.Msg($"Random BGM loaded {_acbs.Count} files"); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(CriAtomExAcb), "LoadAcbFile")] + public static void PostLoadAcbFile(string acbPath, CriAtomExAcb __result) + { + if (acbPath.EndsWith("SoundData/Mai2Cue.acb")) + _originalAcb = __result; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(CriAtomExPlayer), "SetCue")] + [HarmonyPatch(new[] { typeof(CriAtomExAcb), typeof(int) })] + public static void PreSetCue(ref CriAtomExAcb acb, int id) + { + if (acb != _originalAcb) return; + var cueIndex = (Cue)id; + switch (cueIndex) + { + case Cue.BGM_ENTRY: + case Cue.BGM_COLLECTION: + case Cue.BGM_RESULT_CLEAR: + case Cue.BGM_RESULT: + acb = _acbs[_rng.Next(_acbs.Count)]; + MelonLogger.Msg($"Picked random BGM for {cueIndex}"); + return; + default: + return; + } + } + } +} \ No newline at end of file