public static T executeHook <T>(T baseHook) { MyHook hookToEdit = (MyHook)((MyHook)(object)baseHook).Clone(); bool cancel = false; FieldInfo[] mainFields = hookToEdit.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); List <MyHookListener> safeCopy = new List <MyHookListener>(MyHookSystem.listeners); foreach (MyHookListener listener in safeCopy) { if (!listener.targetHook.Equals(typeof(T))) { continue; } MyHook invokeResult = listener.invokeHook(hookToEdit); if (invokeResult.isCanceled()) { cancel = true; } foreach (FieldInfo field in mainFields) { FieldInfo targetField = invokeResult.GetType().GetField(field.Name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); object mainFieldContent = field.GetValue(hookToEdit); object invokedFieldContent = targetField.GetValue(invokeResult); if (mainFieldContent != invokedFieldContent) { field.SetValue(hookToEdit, invokedFieldContent); } } } hookToEdit.setCanceled(cancel); return((T)(object)hookToEdit); }
public static MyHook executeHook(MyHook hook, Type returnType) { MyHook myHook = (MyHook)hook.Clone(); bool canceled = false; FieldInfo[] fields = myHook.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); List <MyHookListener> list = new List <MyHookListener>(MyHookSystem.listeners); foreach (MyHookListener myHookListener in list) { bool flag = !myHookListener.targetHook.Equals(returnType); if (!flag) { MyHook myHook2 = myHookListener.invokeHook(myHook); bool flag2 = myHook2.isCanceled(); if (flag2) { canceled = true; } } } myHook.setCanceled(canceled); return(myHook); }
public static T executeHook <T>(T baseHook) { MyHook myHook = (MyHook)((MyHook)((object)baseHook)).Clone(); bool canceled = false; FieldInfo[] fields = myHook.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); List <MyHookListener> list = new List <MyHookListener>(MyHookSystem.listeners); foreach (MyHookListener myHookListener in list) { bool flag = !myHookListener.targetHook.Equals(typeof(T)); if (!flag) { MyHook myHook2 = myHookListener.invokeHook(myHook); bool flag2 = myHook2.isCanceled(); if (flag2) { canceled = true; } } } myHook.setCanceled(canceled); return((T)((object)myHook)); }