From 7bee872a658156694c9079d1c182d913080cc325 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Mon, 23 Dec 2019 17:48:27 -0600 Subject: [PATCH] Cleaned and moved a few thigns --- IPA.Loader/Config/Stores/GeneratedStore.cs | 23 ++++++------- .../Loader/Composite/CompositeIPAPlugin.cs | 33 ++++++++++++------- IPA.Loader/Loader/PluginManager.cs | 3 +- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/IPA.Loader/Config/Stores/GeneratedStore.cs b/IPA.Loader/Config/Stores/GeneratedStore.cs index 1ba65445..6b739e35 100644 --- a/IPA.Loader/Config/Stores/GeneratedStore.cs +++ b/IPA.Loader/Config/Stores/GeneratedStore.cs @@ -290,16 +290,6 @@ namespace IPA.Config.Stores if (baseCtor == null) throw new ArgumentException("Config type does not have a public parameterless constructor"); - var typeBuilder = Module.DefineType($"{type.FullName}", - TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Class, type); - - var typeField = typeBuilder.DefineField("<>_type", typeof(Type), FieldAttributes.Private | FieldAttributes.InitOnly); - var implField = typeBuilder.DefineField("<>_impl", typeof(Impl), FieldAttributes.Private | FieldAttributes.InitOnly); - var parentField = typeBuilder.DefineField("<>_parent", typeof(IGeneratedStore), FieldAttributes.Private | FieldAttributes.InitOnly); - - - // none of this can be Expressions because CompileToMethod requires a static target method for some dumbass reason - #region Parse base object structure var baseChanged = type.GetMethod("Changed", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, Array.Empty()); if (baseChanged != null && !baseChanged.IsVirtual) baseChanged = null; // limit this to just the one thing @@ -381,15 +371,15 @@ namespace IPA.Config.Stores member.HasConverter = true; } - endConverterAttr: + endConverterAttr: return true; } - + // only looks at public/protected properties foreach (var prop in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { - if (prop.GetSetMethod(true)?.IsPrivate ?? true) + if (prop.GetSetMethod(true)?.IsPrivate ?? true) { // we enter this block if the setter is inacessible or doesn't exist continue; // ignore props without setter } @@ -431,6 +421,13 @@ namespace IPA.Config.Stores } #endregion + var typeBuilder = Module.DefineType($"{type.FullName}", + TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Class, type); + + var typeField = typeBuilder.DefineField("<>_type", typeof(Type), FieldAttributes.Private | FieldAttributes.InitOnly); + var implField = typeBuilder.DefineField("<>_impl", typeof(Impl), FieldAttributes.Private | FieldAttributes.InitOnly); + var parentField = typeBuilder.DefineField("<>_parent", typeof(IGeneratedStore), FieldAttributes.Private | FieldAttributes.InitOnly); + #region Converter fields var uniqueConverterTypes = structure.Where(m => m.HasConverter).Select(m => m.Converter).Distinct().ToArray(); var converterFields = new Dictionary(uniqueConverterTypes.Length); diff --git a/IPA.Loader/Loader/Composite/CompositeIPAPlugin.cs b/IPA.Loader/Loader/Composite/CompositeIPAPlugin.cs index 6817eb8e..37beeb6a 100644 --- a/IPA.Loader/Loader/Composite/CompositeIPAPlugin.cs +++ b/IPA.Loader/Loader/Composite/CompositeIPAPlugin.cs @@ -1,6 +1,7 @@ using IPA.Old; using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; using Logger = IPA.Logging.Logger; namespace IPA.Loader.Composite @@ -12,34 +13,43 @@ namespace IPA.Loader.Composite private delegate void CompositeCall(Old.IPlugin plugin); - public CompositeIPAPlugin(IEnumerable plugins) { + public CompositeIPAPlugin(IEnumerable plugins) + { this.plugins = plugins; } - public void OnApplicationStart() { + public void OnApplicationStart() + { Invoke(plugin => plugin.OnApplicationStart()); } - public void OnApplicationQuit() { + public void OnApplicationQuit() + { Invoke(plugin => plugin.OnApplicationQuit()); } - private void Invoke(CompositeCall callback) { - foreach (var plugin in plugins) { - try { + private void Invoke(CompositeCall callback, [CallerMemberName] string member = "") + { + foreach (var plugin in plugins) + { + try + { callback(plugin); } - catch (Exception ex) { - Logger.log.Error($"{plugin.Name}: {ex}"); + catch (Exception ex) + { + Logger.log.Error($"{plugin.Name} {member}: {ex}"); } } } - public void OnUpdate() { + public void OnUpdate() + { Invoke(plugin => plugin.OnUpdate()); } - public void OnFixedUpdate() { + public void OnFixedUpdate() + { Invoke(plugin => plugin.OnFixedUpdate()); } @@ -47,7 +57,8 @@ namespace IPA.Loader.Composite public string Version => throw new InvalidOperationException(); - public void OnLateUpdate() { + public void OnLateUpdate() + { Invoke(plugin => { if (plugin is Old.IEnhancedPlugin saberPlugin) saberPlugin.OnLateUpdate(); diff --git a/IPA.Loader/Loader/PluginManager.cs b/IPA.Loader/Loader/PluginManager.cs index 75fd68ce..03d57dca 100644 --- a/IPA.Loader/Loader/PluginManager.cs +++ b/IPA.Loader/Loader/PluginManager.cs @@ -412,8 +412,7 @@ namespace IPA.Loader T OptionalGetPlugin(Type t) where T : class { - // use typeof() to allow for easier renaming (in an ideal world this compiles to a string, but ¯\_(ツ)_/¯) - if (t.GetInterface(typeof(T).Name) != null) + if (t.FindInterfaces((t, o) => t == (o as Type), typeof(T)).Length > 0) { try {