From 2d638ba5506b4bb538c45e0577e44f5fd3e7c96f Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sun, 5 Apr 2020 01:04:24 -0500 Subject: [PATCH] Added an additional check case for StateTransitionTransaction to skip any behaviour if the transaction was never changed --- IPA.Loader/Loader/PluginManager.cs | 2 ++ IPA.Loader/Loader/StateTransitionTransaction.cs | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/IPA.Loader/Loader/PluginManager.cs b/IPA.Loader/Loader/PluginManager.cs index e3b40c92..62002591 100644 --- a/IPA.Loader/Loader/PluginManager.cs +++ b/IPA.Loader/Loader/PluginManager.cs @@ -82,6 +82,8 @@ namespace IPA.Loader internal static Task CommitTransaction(StateTransitionTransaction transaction) { + if (!transaction.HasStateChanged) return TaskEx.WhenAll(); + if (!UnityGame.OnMainThread) return UnityMainThreadTaskScheduler.Factory.StartNew(() => CommitTransaction(transaction)).Unwrap(); diff --git a/IPA.Loader/Loader/StateTransitionTransaction.cs b/IPA.Loader/Loader/StateTransitionTransaction.cs index 2a6ba652..41f6efef 100644 --- a/IPA.Loader/Loader/StateTransitionTransaction.cs +++ b/IPA.Loader/Loader/StateTransitionTransaction.cs @@ -15,6 +15,7 @@ namespace IPA.Loader private readonly HashSet currentlyDisabled; private readonly HashSet toEnable = new HashSet(); private readonly HashSet toDisable = new HashSet(); + private bool stateChanged = false; internal StateTransitionTransaction(IEnumerable enabled, IEnumerable disabled) { @@ -29,7 +30,14 @@ namespace IPA.Loader /// if this object has been disposed public bool WillNeedRestart => ThrowIfDisposed() - || toEnable.Concat(toDisable).Any(m => m.RuntimeOptions != RuntimeOptions.DynamicInit); + || (stateChanged && toEnable.Concat(toDisable).Any(m => m.RuntimeOptions != RuntimeOptions.DynamicInit)); + + /// + /// Gets whether or not the current state has changed. + /// + /// if the current state of the transaction is different from its construction, otherwise + /// if this object has been disposed + public bool HasStateChanged => ThrowIfDisposed() || stateChanged; internal IEnumerable CurrentlyEnabled => currentlyEnabled; internal IEnumerable CurrentlyDisabled => currentlyDisabled; @@ -41,7 +49,7 @@ namespace IPA.Loader /// /// if this object has been disposed public IEnumerable EnabledPlugins - => ThrowIfDisposed>() ?? DisabledPluginsInternal; + => ThrowIfDisposed>() ?? EnabledPluginsInternal; private IEnumerable EnabledPluginsInternal => currentlyEnabled.Except(toDisable).Concat(toEnable); /// /// Gets a list of plugins that are disabled according to this transaction's current state. @@ -139,6 +147,7 @@ namespace IPA.Loader toDisable.Remove(meta); toEnable.Add(meta); + stateChanged = true; return true; } @@ -195,6 +204,7 @@ namespace IPA.Loader toDisable.Add(meta); toEnable.Remove(meta); + stateChanged = true; return true; }