public BSIPAModCell(ModListController list, PluginLoader.PluginInfo plugin) : base($"{plugin.Metadata.Name} <size=60%>v{plugin.Metadata.Version}", plugin.Metadata.Manifest.Author, null) { Plugin = plugin; this.list = list; if (string.IsNullOrWhiteSpace(subtext)) { subtext = "<color=#BFBFBF><i>Unspecified Author</i>"; } icon = plugin.Metadata.GetIcon(); }
/// <summary> /// Check if a BSIPA plugin is enabled /// </summary> public static bool IsPluginEnabled(string PluginName) { if (!IsPluginPresent(PluginName)) { return(false); } PluginLoader.PluginInfo pluginInfo = PluginManager.GetPluginFromId(PluginName); if (pluginInfo?.Metadata != null) { return(PluginManager.IsEnabled(pluginInfo.Metadata)); } return(false); }
private static void PluginManager_PluginEnabled(PluginLoader.PluginInfo plugin, bool needsRestart, WeakReference <BSIPAModCell> _self, PluginManager.PluginEnableDelegate ownDel) { if (!_self.TryGetTarget(out var self)) { PluginManager.PluginEnabled -= ownDel; return; } if (plugin.Metadata != self.Plugin) { return; } self.Update(true, needsRestart); }
internal static void Inject(MethodInfo init, PluginLoader.PluginInfo info) { var instance = info.Plugin; var meta = info.Metadata; var initArgs = new List <object>(); var initParams = init.GetParameters(); Dictionary <Tuple <Type, InjectParameter>, object> previousValues = new Dictionary <Tuple <Type, InjectParameter>, object>(injectors.Count); foreach (var param in initParams) { var paramType = param.ParameterType; var value = paramType.GetDefault(); foreach (var pair in injectors.Where(t => paramType.IsAssignableFrom(t.Item1))) { object prev = null; if (previousValues.ContainsKey(pair)) { prev = previousValues[pair]; } var val = pair.Item2?.Invoke(prev, param, meta); if (previousValues.ContainsKey(pair)) { previousValues[pair] = val; } else { previousValues.Add(pair, val); } if (val == null) { continue; } value = val; break; } initArgs.Add(value); } init.Invoke(instance, initArgs.ToArray()); }
public void OnApplicationStart() { logger.Info("Looking for BeatSaberMultiplayer"); PluginLoader.PluginInfo beatsabermultiplayer = PluginManager.GetPluginFromId("BeatSaberMultiplayer"); if (beatsabermultiplayer != null) { Type multiplayerClientType = beatsabermultiplayer.Metadata.Assembly.GetType("BeatSaberMultiplayer.Client"); if (multiplayerClientType != null) { clientInstanceField = multiplayerClientType.GetField("instance", (BindingFlags)(-1)); clientInstanceInroomField = multiplayerClientType.GetField("inRoom", (BindingFlags)(-1)); logger.Info("BeatSaberMultiplayer found and linked."); } else { logger.Warn("Found BeatSaberMultiplayer, but not type BeatSaberMultiplayer.Client. Multiplayer won't be shown on discord."); } } logger.Info("Looking for YURFit (IPA)"); #pragma warning disable CS0618 IPlugin yurfit = PluginManager.Plugins.FirstOrDefault((IPlugin x) => x.Name == "YURfitMod"); if (yurfit != null) { Type yurpresence = yurfit.GetType().Assembly.GetType("YURfitMod.RPC.YURpresence"); if (yurpresence != null) { harmonyInstance.Patch(yurpresence.GetMethod("Awake", (BindingFlags)(-1)), GetVoidPatch(), null, null); harmonyInstance.Patch(yurpresence.GetMethod("Menu", (BindingFlags)(-1)), GetVoidPatch(), null, null); logger.Info("YURFit found as IPA Plugin and patched."); } else { logger.Warn("Found YURFit as IPA Plugin, but not type YURfitMod.RPC.YURpresence. There may be some conflivts between the two mods."); } } //Menu scene loaded Presence.details = "In Menu"; Presence.state = string.Empty; Presence.startTimestamp = default(long); Presence.largeImageKey = "default"; Presence.largeImageText = "Beat Saber"; Presence.smallImageKey = ""; Presence.smallImageText = ""; DiscordRpc.UpdatePresence(Presence); #pragma warning restore CS0618 }
/// <summary> /// Called after a plugin has been fully initialized, whether or not there is an `Init` method. This should never throw an exception. /// </summary> /// <param name="plugin">the plugin that was just initialized</param> public virtual void AfterInit(PluginLoader.PluginInfo plugin) { }
/// <summary> /// Called after a plugin has been fully initialized, whether or not there is an `Init` method. This should never throw an exception. /// </summary> /// <param name="plugin">the plugin that was just initialized</param> /// <param name="pluginInstance">the instance of the plugin being initialized</param> public virtual void AfterInit(PluginLoader.PluginInfo plugin, IBeatSaberPlugin pluginInstance) => AfterInit(plugin);
/// <summary> /// Called before a plugin's `Init` method is called. This will not be called if there is no `Init` method. This should never throw an exception. An exception will abort the loading of the plugin with an error. /// </summary> /// <param name="plugin">the plugin to be initialized</param> /// <returns>whether or not to call the Init method</returns> public virtual bool BeforeInit(PluginLoader.PluginInfo plugin) => true;