Skip to content

Commit

Permalink
Print error on delegation attach/detach error
Browse files Browse the repository at this point in the history
  • Loading branch information
Jofairden committed Jul 13, 2018
1 parent dd9d335 commit a946573
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
33 changes: 27 additions & 6 deletions Core/AutoDelegationAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Reflection;
using Loot.Core;
using Terraria;
using Terraria.ModLoader;

namespace Loot.Modifiers
{
Expand Down Expand Up @@ -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);
}
}
}
}
Expand All @@ -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);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit a946573

Please sign in to comment.