|
6 | 6 | using System.Linq; |
7 | 7 | using System.Reflection; |
8 | 8 | using BepInEx.Bootstrap; |
| 9 | +using UnityEngine; |
9 | 10 |
|
10 | 11 | namespace ConfigurationManager |
11 | 12 | { |
@@ -49,39 +50,48 @@ public static void CollectSettings(out IEnumerable<SettingEntryBase> results, ou |
49 | 50 |
|
50 | 51 | foreach (var plugin in FindPlugins()) |
51 | 52 | { |
52 | | - var type = plugin.GetType(); |
| 53 | + try |
| 54 | + { |
| 55 | + var type = plugin.GetType(); |
53 | 56 |
|
54 | | - var pluginInfo = plugin.Info.Metadata; |
55 | | - var pluginName = pluginInfo?.Name ?? plugin.GetType().FullName; |
| 57 | + var pluginInfo = plugin.Info.Metadata; |
| 58 | + var pluginName = pluginInfo?.Name ?? plugin.GetType().FullName; |
56 | 59 |
|
57 | | - if (type.GetCustomAttributes(typeof(BrowsableAttribute), false).Cast<BrowsableAttribute>() |
58 | | - .Any(x => !x.Browsable)) |
59 | | - { |
60 | | - modsWithoutSettings.Add(pluginName); |
61 | | - continue; |
62 | | - } |
| 60 | + if (type.GetCustomAttributes(typeof(BrowsableAttribute), false).Cast<BrowsableAttribute>() |
| 61 | + .Any(x => !x.Browsable)) |
| 62 | + { |
| 63 | + modsWithoutSettings.Add(pluginName); |
| 64 | + continue; |
| 65 | + } |
63 | 66 |
|
64 | | - var detected = new List<SettingEntryBase>(); |
| 67 | + var detected = new List<SettingEntryBase>(); |
65 | 68 |
|
66 | | - detected.AddRange(GetPluginConfig(plugin).Cast<SettingEntryBase>()); |
| 69 | + detected.AddRange(GetPluginConfig(plugin).Cast<SettingEntryBase>()); |
67 | 70 |
|
68 | | - detected.RemoveAll(x => x.Browsable == false); |
| 71 | + detected.RemoveAll(x => x.Browsable == false); |
69 | 72 |
|
70 | | - if (detected.Count == 0) |
71 | | - modsWithoutSettings.Add(pluginName); |
| 73 | + if (detected.Count == 0) |
| 74 | + modsWithoutSettings.Add(pluginName); |
72 | 75 |
|
73 | | - // Allow to enable/disable plugin if it uses any update methods ------ |
74 | | - if (showDebug && type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Any(x => _updateMethodNames.Contains(x.Name))) |
| 76 | + // Allow to enable/disable plugin if it uses any update methods ------ |
| 77 | + if (showDebug && type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Any(x => _updateMethodNames.Contains(x.Name))) |
| 78 | + { |
| 79 | + var enabledSetting = new PropertySettingEntry(plugin, type.GetProperty("enabled"), plugin); |
| 80 | + enabledSetting.DispName = "!Allow plugin to run on every frame"; |
| 81 | + enabledSetting.Description = "Disabling this will disable some or all of the plugin's functionality.\nHooks and event-based functionality will not be disabled.\nThis setting will be lost after game restart."; |
| 82 | + enabledSetting.IsAdvanced = true; |
| 83 | + detected.Add(enabledSetting); |
| 84 | + } |
| 85 | + |
| 86 | + if (detected.Count > 0) |
| 87 | + results = results.Concat(detected); |
| 88 | + } |
| 89 | + catch (Exception ex) |
75 | 90 | { |
76 | | - var enabledSetting = new PropertySettingEntry(plugin, type.GetProperty("enabled"), plugin); |
77 | | - enabledSetting.DispName = "!Allow plugin to run on every frame"; |
78 | | - enabledSetting.Description = "Disabling this will disable some or all of the plugin's functionality.\nHooks and event-based functionality will not be disabled.\nThis setting will be lost after game restart."; |
79 | | - enabledSetting.IsAdvanced = true; |
80 | | - detected.Add(enabledSetting); |
| 91 | + string pluginName = plugin?.Info?.Metadata?.Name ?? plugin?.GetType().FullName; |
| 92 | + ConfigurationManager.Logger.LogError($"Failed to collect settings of the following plugin: {pluginName}"); |
| 93 | + ConfigurationManager.Logger.LogError(ex); |
81 | 94 | } |
82 | | - |
83 | | - if (detected.Count > 0) |
84 | | - results = results.Concat(detected); |
85 | 95 | } |
86 | 96 | } |
87 | 97 |
|
|
0 commit comments