mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
Only redirect music if it exists
This commit is contained in:
1 parent
7ba7f0fba0
commit
5be1da2fec
1 file changed
+31
-23
@@ -3,6 +3,7 @@ using Harmony;
|
||||
using Illusion.Game;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
@@ -56,20 +57,10 @@ namespace ResourceRedirector
|
||||
public static FieldInfo f_typeObjects = typeof(Manager.Sound).GetField("typeObjects", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
public static FieldInfo f_settingObjects = typeof(Manager.Sound).GetField("settingObjects", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
public static PropertyInfo f_clip = typeof(LoadAudioBase).GetProperty("clip", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
|
||||
|
||||
|
||||
|
||||
public static void BindPreHook(ref LoadSound script)
|
||||
{
|
||||
if (script.audioSource == null)
|
||||
{
|
||||
int type = (int)script.type;
|
||||
|
||||
Transform[] typeObjects = (Transform[])f_typeObjects.GetValue(Manager.Game.Instance);
|
||||
GameObject[] settingObjects = (GameObject[])f_settingObjects.GetValue(Manager.Game.Instance);
|
||||
|
||||
Manager.Sound.Instance.SetParent(typeObjects[type], script, settingObjects[type]);
|
||||
}
|
||||
|
||||
if (script.clip.name.StartsWith("bgm"))
|
||||
{
|
||||
string path;
|
||||
@@ -78,29 +69,46 @@ namespace ResourceRedirector
|
||||
{
|
||||
case BGM.Title:
|
||||
default:
|
||||
path = "file://" + BepInEx.Common.Utility.PluginsDirectory.Replace('\\', '/') + "/title.wav";
|
||||
path = $"{BepInEx.Common.Utility.PluginsDirectory}\\title.wav";
|
||||
break;
|
||||
case BGM.Custom:
|
||||
path = "file://" + BepInEx.Common.Utility.PluginsDirectory.Replace('\\', '/') + "/custom.wav";
|
||||
path = $"{BepInEx.Common.Utility.PluginsDirectory}\\custom.wav";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!File.Exists(path))
|
||||
return;
|
||||
|
||||
Console.WriteLine($"Loaded {path}");
|
||||
WWW loadGachi = new WWW(path);
|
||||
|
||||
|
||||
AudioClip clip = loadGachi.GetAudioClip(false);
|
||||
Console.WriteLine($"Loading {path}");
|
||||
|
||||
//force single threaded loading instead of using a coroutine
|
||||
while (!clip.isReadyToPlay) { }
|
||||
path = $"file://{path.Replace('\\', '/')}";
|
||||
|
||||
|
||||
script.audioSource.clip = clip;
|
||||
if (script.audioSource == null)
|
||||
{
|
||||
int type = (int)script.type;
|
||||
|
||||
f_clip.SetValue(script, clip, null);
|
||||
|
||||
loadGachi.Dispose();
|
||||
Transform[] typeObjects = (Transform[])f_typeObjects.GetValue(Manager.Game.Instance);
|
||||
GameObject[] settingObjects = (GameObject[])f_settingObjects.GetValue(Manager.Game.Instance);
|
||||
|
||||
Manager.Sound.Instance.SetParent(typeObjects[type], script, settingObjects[type]);
|
||||
}
|
||||
|
||||
|
||||
using (WWW loadGachi = new WWW(path))
|
||||
{
|
||||
AudioClip clip = loadGachi.GetAudioClipCompressed(false, AudioType.WAV);
|
||||
|
||||
|
||||
//force single threaded loading instead of using a coroutine
|
||||
while (!clip.isReadyToPlay) { }
|
||||
|
||||
|
||||
script.audioSource.clip = clip;
|
||||
|
||||
f_clip.SetValue(script, clip, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user