-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82a1c86
commit 28a79cd
Showing
5 changed files
with
526 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System.Text.RegularExpressions; | ||
using BepInEx; | ||
using BepInEx.Logging; | ||
using BepInEx.Unity.IL2CPP; | ||
using BepisPlugins; | ||
using HarmonyLib; | ||
using UnityEngine; | ||
using UnityEngine.SceneManagement; | ||
|
||
namespace BGMLoader | ||
{ | ||
/// <summary> | ||
/// Place .wav files in BepInEx/plugins/introclips folder to load them in place of startup sounds | ||
/// </summary> | ||
[BepInProcess(Constants.GameProcessName)] | ||
[BepInPlugin(GUID, PluginName, Version)] | ||
public class BGMLoader : BasePlugin | ||
{ | ||
public const string GUID = "com.bepis.bgmloader"; | ||
public const string PluginName = "BGM Loader"; | ||
public const string Version = Metadata.PluginsVersion; | ||
public static string IntroClipsDirectory = Path.Combine(Paths.PluginPath, "introclips"); | ||
|
||
private static ManualLogSource Logger = null!; | ||
private static FileInfo[] _clips = null!; | ||
|
||
public override void Load() | ||
{ | ||
Logger = Log; | ||
|
||
Task.Run(() => | ||
{ | ||
try | ||
{ | ||
var dir = Directory.CreateDirectory(IntroClipsDirectory); | ||
_clips = dir.GetFiles("*.wav", SearchOption.AllDirectories); | ||
Logger.LogInfo("Found " + _clips.Length + " custom intro clips"); | ||
Harmony.CreateAndPatchAll(typeof(BGMLoader), GUID); | ||
} | ||
catch (Exception e) | ||
{ | ||
Logger.LogError("Failed to load custom intro clips - " + e); | ||
} | ||
}); | ||
} | ||
|
||
[HarmonyPrefix] | ||
[HarmonyPatch(typeof(Manager.Sound), nameof(Manager.Sound.Play), typeof(Manager.Sound.Type), typeof(AudioClip), typeof(float))] | ||
private static void TitleCallOverride(Manager.Sound.Type type, ref AudioClip clip) | ||
{ | ||
if (type == Manager.Sound.Type.SystemSE && clip.name != null && Regex.IsMatch(clip.name, @"^sv_\d\d\d_se_\d\d\d_\d\d\d$")) | ||
{ | ||
try | ||
{ | ||
// Need to make sure it's not some other sound effect, this seems to work (map000 is title screen itself) | ||
var sceneName = SceneManager.GetActiveScene().name; | ||
if (sceneName != "Logo" && sceneName != "map000") return; | ||
|
||
var pick = _clips[UnityEngine.Random.Range(0, _clips.Length)]; | ||
var clipData = File.ReadAllBytes(pick.FullName); | ||
|
||
// BUG Some clips are not giving sound, but they are playing | ||
clip = WavUtility.ToAudioClip(clipData); // slowest step mostly because of AudioClip calls | ||
|
||
Logger.LogInfo("Playing custom intro clip - " + pick.Name); | ||
} | ||
catch (Exception e) | ||
{ | ||
Logger.LogError("Failed to play custom intro clip - " + e); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<RootNamespace>BGMLoader</RootNamespace> | ||
<OutputPath>..\..\bin\BepInEx\plugins\SVS_BepisPlugins\</OutputPath> | ||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> | ||
<DebugType>embedded</DebugType> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<GenerateAssemblyInfo>False</GenerateAssemblyInfo> | ||
<DefineConstants>$(DefineConstants);SVS</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<GenerateAssemblyInfo>False</GenerateAssemblyInfo> | ||
<DefineConstants>$(DefineConstants);SVS</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> | ||
<Delete Files="$(OutputPath)\SVS_BGMLoader.deps.json" /> | ||
</Target> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.668" /> | ||
<PackageReference Include="BepInEx.Unity.Mono.Preloader" Version="6.0.0-be.668" /> | ||
<PackageReference Include="IllusionLibs.SamabakeScramble.Assembly-CSharp" Version="2024.8.30.1" /> | ||
<PackageReference Include="IllusionLibs.SamabakeScramble.Il2Cppmscorlib" Version="2024.8.30.1" /> | ||
<PackageReference Include="IllusionLibs.SamabakeScramble.UnityEngine" Version="2021.3.33.1" /> | ||
<PackageReference Include="IllusionLibs.SamabakeScramble.UnityEngine.AudioModule" Version="2021.3.33.1" /> | ||
<PackageReference Include="IllusionLibs.SamabakeScramble.UnityEngine.UI" Version="2021.3.33.1" /> | ||
</ItemGroup> | ||
|
||
<Import Project="..\Shared\Shared.projitems" Label="Shared" /> | ||
</Project> |
Oops, something went wrong.