Browse Source

Cleaned and moved a few thigns

pull/46/head
Anairkoen Schno 5 years ago
parent
commit
bfb05ab48a
3 changed files with 33 additions and 26 deletions
  1. +10
    -13
      IPA.Loader/Config/Stores/GeneratedStore.cs
  2. +22
    -11
      IPA.Loader/Loader/Composite/CompositeIPAPlugin.cs
  3. +1
    -2
      IPA.Loader/Loader/PluginManager.cs

+ 10
- 13
IPA.Loader/Config/Stores/GeneratedStore.cs View File

@ -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}<Generated>",
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<ParameterModifier>());
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}<Generated>",
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<Type, FieldInfo>(uniqueConverterTypes.Length);


+ 22
- 11
IPA.Loader/Loader/Composite/CompositeIPAPlugin.cs View File

@ -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<Old.IPlugin> plugins) {
public CompositeIPAPlugin(IEnumerable<Old.IPlugin> 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();


+ 1
- 2
IPA.Loader/Loader/PluginManager.cs View File

@ -412,8 +412,7 @@ namespace IPA.Loader
T OptionalGetPlugin<T>(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
{


Loading…
Cancel
Save