diff --git a/Core/AutoDelegationAttribute.cs b/Core/AutoDelegationAttribute.cs index 28bfd6088..d999340b2 100644 --- a/Core/AutoDelegationAttribute.cs +++ b/Core/AutoDelegationAttribute.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Reflection; using Loot.Core; +using Terraria; +using Terraria.ModLoader; namespace Loot.Modifiers { @@ -29,9 +31,18 @@ public void Attach(ModifierPlayer player, MethodInfo method, ModifierEffect effe { EventInfo evt = player.GetType().GetEvent(type, BindingFlags.Instance | BindingFlags.Public); if (evt != null) - { - Delegate handler = Delegate.CreateDelegate(evt.EventHandlerType, effect, method); - evt.AddEventHandler(player, handler); + { + try + { + Delegate handler = Delegate.CreateDelegate(evt.EventHandlerType, effect, method); + evt.AddEventHandler(player, handler); + } + catch (Exception e) + { + ErrorLogger.Log(e.ToString()); + Main.NewTextMultiline(e.ToString()); + Main.NewText("An error just occurred. Please let the mod author know on the forums and show a screenshot of it", 255, 0, 0); + } } } } @@ -40,11 +51,21 @@ public void Detach(ModifierPlayer player, MethodInfo method, ModifierEffect effe { foreach (string type in _delegationTypes) { + EventInfo evt = player.GetType().GetEvent(type, BindingFlags.Instance | BindingFlags.Public); if (evt != null) - { - Delegate handler = Delegate.CreateDelegate(evt.EventHandlerType, effect, method); - evt.RemoveEventHandler(player, handler); + { + try + { + Delegate handler = Delegate.CreateDelegate(evt.EventHandlerType, effect, method); + evt.RemoveEventHandler(player, handler); + } + catch (Exception e) + { + ErrorLogger.Log(e.ToString()); + Main.NewTextMultiline(e.ToString()); + Main.NewText("An error just occurred. Please let the mod author know on the forums and show a screenshot of it.", 255, 0, 0); + } } } } diff --git a/build.txt b/build.txt index b8a66c89c..791890243 100644 --- a/build.txt +++ b/build.txt @@ -1,5 +1,5 @@ author = Jofairden -version = 0.1.0.8 +version = 0.1.0.9 displayName = Even More Modifiers homepage = https://forums.terraria.org/index.php?threads/even-more-modifiers-relaunch-beta.68438/ hideCode = false