[+] Random old version maimai BGM

pull/35/head
Clansty 2024-05-15 21:01:19 +08:00
parent fb72317c6f
commit 991442d5c0
5 changed files with 68 additions and 0 deletions

View File

@ -35,6 +35,9 @@
<Reference Include="Assembly-CSharp">
<HintPath>Libs\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>Libs\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="MelonLoader">
<HintPath>Libs\MelonLoader.dll</HintPath>
</Reference>
@ -274,6 +277,7 @@
<Compile Include="UX\LoadJacketPng.cs" />
<Compile Include="UX\LoadAssetBundleWithoutManifest.cs" />
<Compile Include="UX\QuickSkip.cs" />
<Compile Include="UX\RandomBgm.cs" />
<Compile Include="UX\SinglePlayer.cs" />
<Compile Include="UX\SkipEventInfo.cs" />
<Compile Include="UX\SkipWarningScreen.cs" />

View File

@ -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

View File

@ -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; }
}

Binary file not shown.

View File

@ -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<CriAtomExAcb> _acbs = new List<CriAtomExAcb>();
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;
}
}
}
}