/// <summary> /// Check if this hook's functionality is equal to that of another. /// Used when deciding which hooks can be omitted (optimised out). /// Note: Different parameters typically infer different functionalities, here only the parameters in the <see cref="ParameterRegistry"/> are checked. /// If your custom hook for any reason requires any additional parameters that alter its behaviour you should add your own checks to this method. /// </summary> /// <param name="other">The hook to check.</param> /// <returns>A boolean indicating whether or not the other hook does the same that this one does.</returns> public bool FunctionallyEquals(IHook other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } BaseHook otherAsBaseHook = other as BaseHook; bool otherParametersEqual = otherAsBaseHook == null || ParameterRegistry.RegistryContentEquals(otherAsBaseHook.ParameterRegistry); return(GetType() == other.GetType() && TimeStep.StepEquals(other.TimeStep) && otherParametersEqual); }
/// <summary> /// Call the specified event. /// This will cause all registrants to be called that /// have typeof(e) events in their signature. /// If there is no registrant for the given event then nothing will happen. /// </summary> /// <param name="e">Event to raise.</param> public void Call <T>(IHook e) where T : IHook { Delegate d; if (registrants.TryGetValue(e.GetType(), out d)) { Callback <T> callback = d as Callback <T>; if (callback != null) { callback((T)e); } } }
internal static Guid GetIdOfHook(this IHook currentHook) { Guid id = Guid.Empty; if (currentHook.Id != Guid.Empty) // first try to get the Id within instance { id = currentHook.Id; } else // if not found, take the attribute value { Type type = currentHook.GetType(); if (type.HasIdentifierAttribute() == false) { throw new NotImplementedException("Hook neither has a HookIdentifier attribute, nor its Id property is set. One of this mandatory for standard HookRepository"); } else { id = type.GetHookIdenfier(); } } return(id); }
void RegisterHook(IHook hook) { hook.OnRegister(this); Harmony.CreateAndPatchAll(hook.GetType()); hooks.Add(hook); }
public ScriptLogger(IHook instance) { _tag = $"[Script] {instance.GetType().Name}: "; }