I was wondering if Jeff's tutorials on Handler and Packet Hooking are still relevant? I tried doing the Handler Hooking Tutorial and it was giving me a couple of errors in Visual Studio 2015. I will post the script that you make in the tutorial I did it exactly as the tutorial said. Hopefully someone can tell me what I did wrong. I was also thinking that it was just such an old tutorial that maybe some things have changed.
I appreciate you time and help.
  • Error CS0103 The name 'EventController' does not exist in the current context
  • Error CS1061 'NotorietyHandlerChain.EventContext' does not contain a definition for 'OverridesHandleNotoriety' and no extension method 'OverridesHandleNotoriety' accepting a first argument of type 'NotorietyHandlerChain.EventContext' could be found (are you missing a using directive or an assembly reference?)
  • Error CS1061 'NotorietyHandlerChain.EventContext' does not contain a definition for 'HandleNotoriety' and no extension method 'HandleNotoriety' accepting a first argument of type 'NotorietyHandlerChain.EventContext' could be found (are you missing a using directive or an assembly reference?)
NotorietyHandlerChain.cs
Code:
using Server;

public abstract class NotorietyHandlerChain
{
    private readonly AllowBeneficialHandler _allowBeneficialHandlerSuccessor;
    private readonly AllowHarmfulHandler _allowHarmfulHandlerSuccessor;
    private readonly NotorietyHandler _notorietyHandlerSuccessor;

    protected NotorietyHandlerChain()
    {
        // Store the original handlers in some read only private variables
        // so we can call them later if need be.
        _notorietyHandlerSuccessor = Notoriety.Handler;
        _allowBeneficialHandlerSuccessor = Mobile.AllowBeneficialHandler;
        _allowHarmfulHandlerSuccessor = Mobile.AllowHarmfulHandler;

        // Set the current handlers to our new chain handlers.
        Notoriety.Handler = HandleNotoriety;
        Mobile.AllowBeneficialHandler = AllowBeneficial;
        Mobile.AllowHarmfulHandler = AllowHarmful;
    }

    protected bool InvokeAllowBeneficialHandlerSuccessor(Mobile source,Mobile target)
    {
        return _allowBeneficialHandlerSuccessor(source,target);
    }

    protected bool InvokeAllowHarmfulHandlerSuccessor(Mobile source,Mobile target)
    {
        return _allowHarmfulHandlerSuccessor(source,target);
    }

    protected int InvokeNotorietyHandlerSuccessor(Mobile source,Mobile target)
    {
        return _notorietyHandlerSuccessor(source,target);
    }

    public virtual bool AllowBeneficial(Mobile source,Mobile target)
    {
        // Call the successor since there is no implementation in this base class.
        return InvokeAllowBeneficialHandlerSuccessor(source,target);
    }

    public virtual bool AllowHarmful(Mobile source,Mobile target)
    {
        // Call the successor since there is no implementation in this base class.
        return InvokeAllowHarmfulHandlerSuccessor(source,target);
    }

    public virtual int HandleNotoriety(Mobile source,Mobile target)
    {
        // Call the successor since there is no implementation in this base class.
        return InvokeNotorietyHandlerSuccessor(source,target);
    }

    public sealed class EventNotorietyChain : NotorietyHandlerChain
    {
        public override int HandleNotoriety(Mobile source,Mobile target)
        {
            EventContext sourceContext = EventController.FindEvent(source);

            if (sourceContext != null && sourceContext.OverridesHandleNotoriety)
                return sourceContext.HandleNotoriety(source,target);

            return base.HandleNotoriety(source,target);
        }

        public override bool AllowBeneficial(Mobile source,Mobile target)
        {
            EventContext sourceContext = EventController.FindEvent(source);

            if (sourceContext != null && sourceContext.OverridesAllowBeneficial)
                return sourceContext.AllowBeneficial(source,target);

            return base.AllowBeneficial(source,target);
        }

        public override bool AllowHarmful(Mobile source,Mobile target)
        {
            EventContext sourceContext = EventController.FindEvent(source);

            if (sourceContext != null && sourceContext.OverridesAllowHarmful)
                return sourceContext.AllowHarmful(source,target);

            return base.AllowHarmful(source,target);
        }
    }

    internal class EventContext
    {
        public static void Initialize()
        {
            new EventNotorietyChain();
        }
    }
}
 
Back