private static void LoadBaseUnityPlugins() { BaseUnityPlugin[] plugins = FindObjectsOfType <BaseUnityPlugin>(); if (plugins.Length < 1) { return; } foreach (BaseUnityPlugin plugin in plugins) { OptionInterface itf; // Load ITF try { var method = plugin.GetType().GetMethod("LoadOI"); if (method == null || method.GetParameters().Length > 0 || method.ContainsGenericParameters) { // Mod didn't attempt to interface with CompletelyOptional, don't bother logging it. itf = new UnconfiguableOI(plugin, UnconfiguableOI.Reason.NoInterface); } else if (method.Invoke(plugin, null) is OptionInterface oi) { itf = oi; //Your code Debug.Log($"Loaded OptionInterface from {itf.rwMod.ModID} (type: {itf.GetType()})"); } else { itf = new UnconfiguableOI(plugin, UnconfiguableOI.Reason.NoInterface); Debug.Log($"{itf.rwMod.ModID} did not return an OptionInterface in LoadOI."); } } catch (Exception ex) { itf = new UnconfiguableOI(plugin, UnconfiguableOI.Reason.NoInterface); if (blackList.Contains(itf.rwMod.ModID) || itf.rwMod.ModID.Substring(0, 1) == "_") { continue; } Debug.Log($"{itf.rwMod.ModID} threw an exception in LoadOI: {ex.Message}"); } if (itf is UnconfiguableOI && plugin.Config.Keys.Count > 0) { // Use BepInEx Configuration itf = new GeneratedOI(itf.rwMod, plugin.Config); } // Initialize the interface try { itf.Initialize(); } catch (Exception ex) { // Try-catch better itf = new UnconfiguableOI(itf.rwMod, new GeneralInitializeException(ex)); itf.Initialize(); } if (itf.Tabs == null || itf.Tabs.Length < 1) { itf = new UnconfiguableOI(itf.rwMod, new NoTabException(itf.rwMod.ModID)); itf.Initialize(); // OptionScript.loadedInterfaceDict.Remove(mod.ModID); // OptionScript.loadedInterfaceDict.Add(mod.ModID, itf); } else if (itf.Configuable()) { if (itf.LoadConfig()) { Debug.Log($"{itf.rwMod.ModID} config has been loaded."); } else { Debug.Log($"{itf.rwMod.ModID} does not have config.txt."); //itf.Initialize(); try { itf.SaveConfig(itf.GrabConfig()); Debug.Log($"{itf.rwMod.ModID} uses default config."); } catch (Exception e) { Debug.Log("Saving Default Config Failed."); Debug.Log(e); } } } loadedInterfaces.Add(itf); loadedInterfaceDict.Add(itf.rwMod.ModID, itf); } }
#pragma warning restore IDE0060 #pragma warning restore CA1822 public override void Initialize() { if (this.reason == Reason.TooManyMod) { ListMods(); return; } Tabs = new OpTab[1]; Tabs[0] = new OpTab(); if (this.reason == Reason.NoMod) { TutoInit(); return; } GeneratedOI.AddBasicProfile(Tabs[0], rwMod); switch (this.reason) { case Reason.NoInterface: if (rwMod.description != RainWorldMod.authorNull) { Tabs[0].AddItems(new OpLabelLong(new Vector2(50f, 200f), new Vector2(500f, 250f), rwMod.description, alignment: FLabelAlignment.Center)); labelSluggo0 = new OpLabel(new Vector2(100f, 150f), new Vector2(400f, 20f), InternalTranslator.Translate(rwMod.type == RainWorldMod.Type.PartialityMod ? "This Partiality Mod has no Option Interface." : "This BepInEx Plugin has no Option Interface.")); } else { labelSluggo0 = new OpLabel(new Vector2(100f, 350f), new Vector2(400f, 20f), InternalTranslator.Translate(rwMod.type == RainWorldMod.Type.PartialityMod ? "This Partiality Mod has no Option Interface." : "This BepInEx Plugin has no Option Interface.")); } Tabs[0].AddItems(labelSluggo0); break; case Reason.InitError: blue = new OpRect(new Vector2(30f, 20f), new Vector2(540f, 420f)) { alpha = 0.7f, colorFill = new Color(0.121568627f, 0.40392156862f, 0.69411764705f, 1f) }; Color white = Menu.Menu.MenuRGB(Menu.Menu.MenuColors.White); oof = new OpLabel(new Vector2(100f, 380f), new Vector2(30f, 40f), ":(", FLabelAlignment.Left, true) { color = white }; labelSluggo0 = new OpLabel(new Vector2(150f, 390f), new Vector2(300f, 20f), InternalTranslator.Translate("There was an issue initializing OptionInterface.")) { color = white }; labelSluggo1 = new OpLabelLong(new Vector2(50f, 40f), new Vector2(500f, 320f), exception) { color = white, allowOverflow = false }; labelVersion = new OpLabel(new Vector2(50f, 480f), new Vector2(100f, 20f), string.Concat(Environment.NewLine, "Config Machine ", MenuTab.GetCMVersion()), FLabelAlignment.Left); Tabs[0].AddItems(blue, oof, labelSluggo0, labelSluggo1, labelVersion); break; } }