Ejemplo n.º 1
0
 public static void UnHookEvent(WoWEventsType eventType, Expression <CallBack> method, bool requestFireCount = false)
 {
     try
     {
         Logging.WriteDebug("Init UnHookEvent for event: " + eventType + " with CallBack: " + method + " and requestFireCount: " + requestFireCount);
         lock (_ourLock)
         {
             HookedEventInfo toRemove = null;
             foreach (HookedEventInfo current in _hookedEvents)
             {
                 if (current.EventType == eventType && current.CallBackName == method.ToString() && current.SendsFireCount == requestFireCount)
                 {
                     toRemove = current;
                     break;
                 }
             }
             if (toRemove != null)
             {
                 _hookedEvents.Remove(toRemove);
             }
         }
     }
     catch (Exception err)
     {
         Logging.WriteError("UnHookEvent(WoWEventsType eventType, string methodName, bool requestFireCount = false): " + err);
     }
 }
Ejemplo n.º 2
0
 public static void HookEvent(WoWEventsType eventType, Expression <CallBack> method, bool requestFireCount = false, bool ignoreAlreadyDone = false)
 {
     try
     {
         Logging.WriteDebug("Init HookEvent for event: " + eventType + " with CallBack: " + method + " and requestFireCount: " + requestFireCount);
         if (IsAttached(eventType, method.ToString(), requestFireCount))
         {
             if (!ignoreAlreadyDone)
             {
                 Logging.WriteError("The event " + eventType + " with method " + method + " and parameter requestFireCount set to " + requestFireCount +
                                    " is already hooked in the exact same way, duplicates of HookEvent is a bad code manner, make sure to UnHook your event when your Stop() your plugin.");
             }
             return;
         }
         lock (_ourLock)
         {
             CallBack callBack = method.Compile();
             _hookedEvents.Add(new HookedEventInfo(callBack, eventType, GetEventFireCount(eventType), method.ToString(), requestFireCount));
         }
         if (_threadHookEvent == null || !_threadHookEvent.IsAlive)
         {
             _threadHookEvent = new Thread(Hook)
             {
                 Name = "Hook of Events"
             };
             _threadHookEvent.Start();
         }
     }
     catch (Exception arg)
     {
         Logging.WriteError("HookEvent(WoWEventsType eventType, Expression<CallBack> method, bool requestFireCount = false): " + arg);
     }
 }
Ejemplo n.º 3
0
 internal HookedEventInfo(CallBack callBack, WoWEventsType id, int idUsedLastCount, string callBackName, bool sendsFireCount)
 {
     _callBack = callBack;
     EventType = id;
     PreviousCurrentEventFireCount = idUsedLastCount;
     CallBackName   = callBackName;
     SendsFireCount = sendsFireCount;
 }
Ejemplo n.º 4
0
 private static uint GetWoWEventsTypeValue(WoWEventsType eventsType)
 {
     try
     {
         lock (WoWEventsType)
         {
             if (WoWEventsType.Count > 0)
             {
                 return(WoWEventsType.ContainsKey(eventsType.ToString()) ? WoWEventsType[eventsType.ToString()] : 0);
             }
             // Already generated then immediatly return the value.
             Logging.WriteDebug("Loading WoWEventsLUA database...");
             int count = 0;
             for (uint i = 0; i <= EventsCount - 1; i++)
             {
                 Application.DoEvents();
                 uint ptrCurrentEvent = Memory.WowMemory.Memory.ReadUInt(PtrFirstEvent + 0x4 * i);
                 if (ptrCurrentEvent > 0)
                 {
                     uint ptrCurrentEventName = Memory.WowMemory.Memory.ReadUInt(ptrCurrentEvent + (uint)Addresses.EventsListener.EventOffsetName);
                     if (ptrCurrentEventName <= 0)
                     {
                         continue;
                     }
                     string currentEventName = Memory.WowMemory.Memory.ReadUTF8String((ptrCurrentEventName));
                     if (currentEventName == "")
                     {
                         continue;
                     }
                     if (WoWEventsType.ContainsKey(currentEventName))
                     {
                         continue;
                     }
                     WoWEventsType.Add(currentEventName, i);
                     count++;
                 }
             }
             Logging.WriteDebug("WoWEventsLUA database loaded with " + count + ".");
         }
         // return the value after the generation.
         return(WoWEventsType.ContainsKey(eventsType.ToString()) ? WoWEventsType[eventsType.ToString()] : 0);
     }
     catch (Exception e)
     {
         Logging.WriteDebug("WoWEventsLUA database loading failed.");
         Logging.WriteError("GetWoWEventsTypeValue(WoWEventsType eventsType): " + e);
         WoWEventsType.Clear();
         return(0);
     }
 }
Ejemplo n.º 5
0
        private static int GetEventFireCount(WoWEventsType eventType)
        {
            uint eventId = GetWoWEventsTypeValue(eventType);

            if (eventId > EventsCount)
            {
                return(0);
            }
            uint ptrCurrentEvent = Memory.WowMemory.Memory.ReadUInt(PtrFirstEvent + 4 * eventId);

            if (ptrCurrentEvent <= 0)
            {
                return(0);
            }
            uint currentEventNamePtr = Memory.WowMemory.Memory.ReadUInt(ptrCurrentEvent + (uint)Addresses.EventsListener.EventOffsetName);

            return(currentEventNamePtr > 0 ? Memory.WowMemory.Memory.ReadInt(ptrCurrentEvent + (uint)Addresses.EventsListener.EventOffsetCount) : 0);
        }
Ejemplo n.º 6
0
 private static bool IsAttached(WoWEventsType eventType, string callBack, bool sendsFireCount = false)
 {
     try
     {
         lock (_ourLock)
         {
             foreach (HookedEventInfo c in _hookedEvents)
             {
                 if (c.EventType == eventType && c.CallBackName == callBack && c.SendsFireCount == sendsFireCount)
                 {
                     return(true);
                 }
             }
         }
         return(false);
     }
     catch (Exception arg)
     {
         Logging.WriteError("IsAttached(string id, MethodDelegate method): " + arg);
     }
     return(false);
 }