예제 #1
0
        /// <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);
        }
예제 #2
0
    /// <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);
            }
        }
    }
예제 #3
0
        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);
        }
예제 #4
0
 void RegisterHook(IHook hook)
 {
     hook.OnRegister(this);
     Harmony.CreateAndPatchAll(hook.GetType());
     hooks.Add(hook);
 }
예제 #5
0
 public ScriptLogger(IHook instance)
 {
     _tag = $"[Script] {instance.GetType().Name}: ";
 }