Skip to content

Commit 8fc53a4

Browse files
committed
Fix not detecting plugins if HideManagerGameObject = true
1 parent 04ec8f6 commit 8fc53a4

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

ConfigurationManager/Utilities/Utilities.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using BepInEx.Logging;
1212
using UnityEngine;
1313
using Object = UnityEngine.Object;
14+
using BepInEx.Bootstrap;
1415

1516
namespace ConfigurationManager.Utilities
1617
{
@@ -34,9 +35,18 @@ public static string ToProperCase(this string str)
3435
return result;
3536
}
3637

37-
// Search for instances of BaseUnityPlugin to also find dynamically loaded plugins. Doing this makes checking Chainloader.PluginInfos redundant.
38-
// Have to use FindObjectsOfType(Type) instead of FindObjectsOfType<T> because the latter is not available in some older unity versions.
39-
public static BaseUnityPlugin[] FindPlugins() => Array.ConvertAll(Object.FindObjectsOfType(typeof(BaseUnityPlugin)), input => (BaseUnityPlugin)input);
38+
/// <summary>
39+
/// Search for all instances of BaseUnityPlugin loaded by chainloader or other means.
40+
/// </summary>
41+
public static BaseUnityPlugin[] FindPlugins()
42+
{
43+
// Search for instances of BaseUnityPlugin to also find dynamically loaded plugins.
44+
// Have to use FindObjectsOfType(Type) instead of FindObjectsOfType<T> because the latter is not available in some older unity versions.
45+
// Still look inside Chainloader.PluginInfos in case the BepInEx_Manager GameObject uses HideFlags.HideAndDontSave, which hides it from Object.Find methods.
46+
return Chainloader.PluginInfos.Values.Select(x => x.Instance)
47+
.Union(Object.FindObjectsOfType(typeof(BaseUnityPlugin)).Cast<BaseUnityPlugin>())
48+
.ToArray();
49+
}
4050

4151
public static string AppendZero(this string s)
4252
{

0 commit comments

Comments
 (0)