From b3994aeb2dd5aff96ccf9b0c3567d41a01b4dd1d Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Mon, 25 Oct 2021 15:41:12 -0500 Subject: [PATCH] Add NoEnableDisableAttribute to indicate that a plugin does not need an OnEnable and OnDisable method --- IPA.Loader/Loader/PluginExecutor.cs | 8 ++++++-- .../Attributes/LifecycleAttributes.cs | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/IPA.Loader/Loader/PluginExecutor.cs b/IPA.Loader/Loader/PluginExecutor.cs index 90b54582..8073c4fd 100644 --- a/IPA.Loader/Loader/PluginExecutor.cs +++ b/IPA.Loader/Loader/PluginExecutor.cs @@ -122,6 +122,7 @@ namespace IPA.Loader // TODO: make enable and disable able to take a bool indicating which it is private static Action MakeLifecycleEnableFunc(Type type, string name) { + var noEnableDisable = type.GetCustomAttribute() is not null; var enableMethods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance) .Select(m => (m, attrs: m.GetCustomAttributes(typeof(IEdgeLifecycleAttribute), false))) .Select(t => (t.m, attrs: t.attrs.Cast())) @@ -129,7 +130,8 @@ namespace IPA.Loader .Select(t => t.m).ToArray(); if (enableMethods.Length == 0) { - Logger.loader.Notice($"Plugin {name} has no methods marked [OnStart] or [OnEnable]. Is this intentional?"); + if (!noEnableDisable) + Logger.loader.Notice($"Plugin {name} has no methods marked [OnStart] or [OnEnable]. Is this intentional?"); return o => { }; } @@ -153,6 +155,7 @@ namespace IPA.Loader } private static Func MakeLifecycleDisableFunc(Type type, string name) { + var noEnableDisable = type.GetCustomAttribute() is not null; var disableMethods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance) .Select(m => (m, attrs: m.GetCustomAttributes(typeof(IEdgeLifecycleAttribute), false))) .Select(t => (t.m, attrs: t.attrs.Cast())) @@ -160,7 +163,8 @@ namespace IPA.Loader .Select(t => t.m).ToArray(); if (disableMethods.Length == 0) { - Logger.loader.Notice($"Plugin {name} has no methods marked [OnExit] or [OnDisable]. Is this intentional?"); + if (!noEnableDisable) + Logger.loader.Notice($"Plugin {name} has no methods marked [OnExit] or [OnDisable]. Is this intentional?"); return o => TaskEx.WhenAll(); } diff --git a/IPA.Loader/PluginInterfaces/Attributes/LifecycleAttributes.cs b/IPA.Loader/PluginInterfaces/Attributes/LifecycleAttributes.cs index 3cd4ca6f..a525eee4 100644 --- a/IPA.Loader/PluginInterfaces/Attributes/LifecycleAttributes.cs +++ b/IPA.Loader/PluginInterfaces/Attributes/LifecycleAttributes.cs @@ -109,4 +109,20 @@ namespace IPA { EdgeLifecycleType IEdgeLifecycleAttribute.Type => EdgeLifecycleType.Disable; } + + /// + /// Indicates that the applied plugin class does not need or + /// methods. + /// + /// + /// This is typically only the ccase when some other utility mod handles their lifecycle for + /// them, such as with SiraUtil and Zenject. + /// + /// + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + public sealed class NoEnableDisableAttribute : Attribute + { + + } }