diff --git a/BindingMap.h b/BindingMap.h index 6a786c2417..a484089df4 100644 --- a/BindingMap.h +++ b/BindingMap.h @@ -18,12 +18,16 @@ extern "C" #include "lauxlib.h" }; +class BaseBindingMap { +public: + virtual ~BaseBindingMap() = default; +}; /* * A set of bindings from keys of type `K` to Lua references. */ template -class BindingMap +class BindingMap : public BaseBindingMap { private: lua_State* L; diff --git a/LuaEngine.cpp b/LuaEngine.cpp index a12b0ccf10..2f7a9b6db4 100644 --- a/LuaEngine.cpp +++ b/LuaEngine.cpp @@ -50,33 +50,10 @@ Eluna::Eluna(Map* map) : event_level(0), push_counter(0), boundMap(map), - -L(NULL), -eventMgr(NULL), - -ServerEventBindings(NULL), -PlayerEventBindings(NULL), -GuildEventBindings(NULL), -GroupEventBindings(NULL), -VehicleEventBindings(NULL), -BGEventBindings(NULL), - -PacketEventBindings(NULL), -CreatureEventBindings(NULL), -CreatureGossipBindings(NULL), -GameObjectEventBindings(NULL), -GameObjectGossipBindings(NULL), -SpellEventBindings(NULL), -ItemEventBindings(NULL), -ItemGossipBindings(NULL), -PlayerGossipBindings(NULL), -MapEventBindings(NULL), -InstanceEventBindings(NULL), - -CreatureUniqueBindings(NULL) +L(NULL) { OpenLua(); - eventMgr = new EventMgr(this); + eventMgr = std::make_unique(this); // if the script cache is ready, run scripts, otherwise flag state for reload if (sElunaLoader->GetCacheState() == SCRIPT_CACHE_READY) @@ -88,8 +65,6 @@ CreatureUniqueBindings(NULL) Eluna::~Eluna() { CloseLua(); - delete eventMgr; - eventMgr = NULL; } void Eluna::CloseLua() @@ -178,71 +153,31 @@ void Eluna::CreateBindStores() { DestroyBindStores(); - ServerEventBindings = new BindingMap< EventKey >(L); - PlayerEventBindings = new BindingMap< EventKey >(L); - GuildEventBindings = new BindingMap< EventKey >(L); - GroupEventBindings = new BindingMap< EventKey >(L); - VehicleEventBindings = new BindingMap< EventKey >(L); - BGEventBindings = new BindingMap< EventKey >(L); + CreateBinding>(Hooks::REGTYPE_SERVER); + CreateBinding>(Hooks::REGTYPE_PLAYER); + CreateBinding>(Hooks::REGTYPE_GUILD); + CreateBinding>(Hooks::REGTYPE_GROUP); + CreateBinding>(Hooks::REGTYPE_VEHICLE); + CreateBinding>(Hooks::REGTYPE_BG); - PacketEventBindings = new BindingMap< EntryKey >(L); - CreatureEventBindings = new BindingMap< EntryKey >(L); - CreatureGossipBindings = new BindingMap< EntryKey >(L); - GameObjectEventBindings = new BindingMap< EntryKey >(L); - GameObjectGossipBindings = new BindingMap< EntryKey >(L); - SpellEventBindings = new BindingMap< EntryKey >(L); - ItemEventBindings = new BindingMap< EntryKey >(L); - ItemGossipBindings = new BindingMap< EntryKey >(L); - PlayerGossipBindings = new BindingMap< EntryKey >(L); - MapEventBindings = new BindingMap< EntryKey >(L); - InstanceEventBindings = new BindingMap< EntryKey >(L); + CreateBinding>(Hooks::REGTYPE_PACKET); + CreateBinding>(Hooks::REGTYPE_CREATURE); + CreateBinding>(Hooks::REGTYPE_CREATURE_GOSSIP); + CreateBinding>(Hooks::REGTYPE_GAMEOBJECT); + CreateBinding>(Hooks::REGTYPE_GAMEOBJECT_GOSSIP); + CreateBinding>(Hooks::REGTYPE_SPELL); + CreateBinding>(Hooks::REGTYPE_ITEM); + CreateBinding>(Hooks::REGTYPE_ITEM_GOSSIP); + CreateBinding>(Hooks::REGTYPE_PLAYER_GOSSIP); + CreateBinding>(Hooks::REGTYPE_MAP); + CreateBinding>(Hooks::REGTYPE_INSTANCE); - CreatureUniqueBindings = new BindingMap< UniqueObjectKey >(L); + CreateBinding>(Hooks::REGTYPE_CREATURE_UNIQUE); } void Eluna::DestroyBindStores() { - delete ServerEventBindings; - delete PlayerEventBindings; - delete GuildEventBindings; - delete GroupEventBindings; - delete VehicleEventBindings; - - delete PacketEventBindings; - delete CreatureEventBindings; - delete CreatureGossipBindings; - delete GameObjectEventBindings; - delete GameObjectGossipBindings; - delete SpellEventBindings; - delete ItemEventBindings; - delete ItemGossipBindings; - delete PlayerGossipBindings; - delete BGEventBindings; - delete MapEventBindings; - delete InstanceEventBindings; - - delete CreatureUniqueBindings; - - ServerEventBindings = NULL; - PlayerEventBindings = NULL; - GuildEventBindings = NULL; - GroupEventBindings = NULL; - VehicleEventBindings = NULL; - - PacketEventBindings = NULL; - CreatureEventBindings = NULL; - CreatureGossipBindings = NULL; - GameObjectEventBindings = NULL; - GameObjectGossipBindings = NULL; - SpellEventBindings = NULL; - ItemEventBindings = NULL; - ItemGossipBindings = NULL; - PlayerGossipBindings = NULL; - BGEventBindings = NULL; - MapEventBindings = NULL; - InstanceEventBindings = NULL; - - CreatureUniqueBindings = NULL; + bindingMaps.clear(); } void Eluna::RunScripts() @@ -726,71 +661,72 @@ static void createCancelCallback(Eluna* e, uint64 bindingID, BindingMap* bind // Stack: cancel_callback } -// Saves the function reference ID given to the register type's store for given entry under the given event -int Eluna::Register(uint8 regtype, uint32 entry, ObjectGuid guid, uint32 instanceId, uint32 event_id, int functionRef, uint32 shots) +template +int RegisterBasicBinding(Eluna* e, std::underlying_type_t regtype, uint32 event_id, int functionRef, uint32 shots) +{ + typedef EventKey Key; + auto binding = e->GetBinding(regtype); + auto key = Key(static_cast(event_id)); + uint64 bindingID = binding->Insert(key, functionRef, shots); + createCancelCallback(e, bindingID, binding); + return 1; // Stack: callback +} + +template +int RegisterEntryBinding(Eluna* e, std::underlying_type_t regtype, uint32 entry, uint32 event_id, int functionRef, uint32 shots) { - uint64 bindingID; + typedef EntryKey Key; + auto binding = e->GetBinding(regtype); + auto key = Key(static_cast(event_id), entry); + uint64 bindingID = binding->Insert(key, functionRef, shots); + createCancelCallback(e, bindingID, binding); + return 1; // Stack: callback +} +template +int RegisterUniqueBinding(Eluna* e, std::underlying_type_t regtype, ObjectGuid guid, uint32 instanceId, uint32 event_id, int functionRef, uint32 shots) +{ + typedef UniqueObjectKey Key; + auto binding = e->GetBinding(regtype); + auto key = Key(static_cast(event_id), guid, instanceId); + uint64 bindingID = binding->Insert(key, functionRef, shots); + createCancelCallback(e, bindingID, binding); + return 1; // Stack: callback +} + +// Saves the function reference ID given to the register type's store for given entry under the given event +int Eluna::Register(std::underlying_type_t regtype, uint32 entry, ObjectGuid guid, uint32 instanceId, uint32 event_id, int functionRef, uint32 shots) +{ switch (regtype) { case Hooks::REGTYPE_SERVER: if (event_id < Hooks::SERVER_EVENT_COUNT) - { - auto key = EventKey((Hooks::ServerEvents)event_id); - bindingID = ServerEventBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, ServerEventBindings); - return 1; // Stack: callback - } + return RegisterBasicBinding(this, regtype, event_id, functionRef, shots); break; case Hooks::REGTYPE_PLAYER: if (event_id < Hooks::PLAYER_EVENT_COUNT) - { - auto key = EventKey((Hooks::PlayerEvents)event_id); - bindingID = PlayerEventBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, PlayerEventBindings); - return 1; // Stack: callback - } + return RegisterBasicBinding(this, regtype, event_id, functionRef, shots); break; case Hooks::REGTYPE_GUILD: if (event_id < Hooks::GUILD_EVENT_COUNT) - { - auto key = EventKey((Hooks::GuildEvents)event_id); - bindingID = GuildEventBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, GuildEventBindings); - return 1; // Stack: callback - } + return RegisterBasicBinding(this, regtype, event_id, functionRef, shots); break; case Hooks::REGTYPE_GROUP: if (event_id < Hooks::GROUP_EVENT_COUNT) - { - auto key = EventKey((Hooks::GroupEvents)event_id); - bindingID = GroupEventBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, GroupEventBindings); - return 1; // Stack: callback - } + return RegisterBasicBinding(this, regtype, event_id, functionRef, shots); break; case Hooks::REGTYPE_VEHICLE: if (event_id < Hooks::VEHICLE_EVENT_COUNT) - { - auto key = EventKey((Hooks::VehicleEvents)event_id); - bindingID = VehicleEventBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, VehicleEventBindings); - return 1; // Stack: callback - } + return RegisterBasicBinding(this, regtype, event_id, functionRef, shots); break; case Hooks::REGTYPE_BG: if (event_id < Hooks::BG_EVENT_COUNT) - { - auto key = EventKey((Hooks::BGEvents)event_id); - bindingID = BGEventBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, BGEventBindings); - return 1; // Stack: callback - } + return RegisterBasicBinding(this, regtype, event_id, functionRef, shots); break; case Hooks::REGTYPE_PACKET: @@ -802,44 +738,33 @@ int Eluna::Register(uint8 regtype, uint32 entry, ObjectGuid guid, uint32 instanc luaL_error(L, "Couldn't find a creature with (ID: %d)!", entry); return 0; // Stack: (empty) } - - auto key = EntryKey((Hooks::PacketEvents)event_id, entry); - bindingID = PacketEventBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, PacketEventBindings); - return 1; // Stack: callback + return RegisterEntryBinding(this, regtype, entry, event_id, functionRef, shots); } break; case Hooks::REGTYPE_CREATURE: if (event_id < Hooks::CREATURE_EVENT_COUNT) { - if (entry != 0) + if (!eObjectMgr->GetCreatureTemplate(entry)) { - if (!eObjectMgr->GetCreatureTemplate(entry)) - { - luaL_unref(L, LUA_REGISTRYINDEX, functionRef); - luaL_error(L, "Couldn't find a creature with (ID: %d)!", entry); - return 0; // Stack: (empty) - } - - auto key = EntryKey((Hooks::CreatureEvents)event_id, entry); - bindingID = CreatureEventBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, CreatureEventBindings); + luaL_unref(L, LUA_REGISTRYINDEX, functionRef); + luaL_error(L, "Couldn't find a creature with (ID: %d)!", entry); + return 0; // Stack: (empty) } - else + return RegisterEntryBinding(this, regtype, entry, event_id, functionRef, shots); + } + break; + + case Hooks::REGTYPE_CREATURE_UNIQUE: + if (event_id < Hooks::CREATURE_EVENT_COUNT) + { + if (guid.IsEmpty()) { - if (guid.IsEmpty()) - { - luaL_unref(L, LUA_REGISTRYINDEX, functionRef); - luaL_error(L, "guid was 0!"); - return 0; // Stack: (empty) - } - - auto key = UniqueObjectKey((Hooks::CreatureEvents)event_id, guid, instanceId); - bindingID = CreatureUniqueBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, CreatureUniqueBindings); + luaL_unref(L, LUA_REGISTRYINDEX, functionRef); + luaL_error(L, "guid was 0!"); + return 0; // Stack: (empty) } - return 1; // Stack: callback + return RegisterUniqueBinding(this, regtype, guid, instanceId, event_id, functionRef, shots); } break; @@ -852,11 +777,7 @@ int Eluna::Register(uint8 regtype, uint32 entry, ObjectGuid guid, uint32 instanc luaL_error(L, "Couldn't find a creature with (ID: %d)!", entry); return 0; // Stack: (empty) } - - auto key = EntryKey((Hooks::GossipEvents)event_id, entry); - bindingID = CreatureGossipBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, CreatureGossipBindings); - return 1; // Stack: callback + return RegisterEntryBinding(this, regtype, entry, event_id, functionRef, shots); } break; @@ -869,11 +790,7 @@ int Eluna::Register(uint8 regtype, uint32 entry, ObjectGuid guid, uint32 instanc luaL_error(L, "Couldn't find a gameobject with (ID: %d)!", entry); return 0; // Stack: (empty) } - - auto key = EntryKey((Hooks::GameObjectEvents)event_id, entry); - bindingID = GameObjectEventBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, GameObjectEventBindings); - return 1; // Stack: callback + return RegisterEntryBinding(this, regtype, entry, event_id, functionRef, shots); } break; @@ -886,22 +803,13 @@ int Eluna::Register(uint8 regtype, uint32 entry, ObjectGuid guid, uint32 instanc luaL_error(L, "Couldn't find a gameobject with (ID: %d)!", entry); return 0; // Stack: (empty) } - - auto key = EntryKey((Hooks::GossipEvents)event_id, entry); - bindingID = GameObjectGossipBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, GameObjectGossipBindings); - return 1; // Stack: callback + return RegisterEntryBinding(this, regtype, entry, event_id, functionRef, shots); } break; case Hooks::REGTYPE_SPELL: if (event_id < Hooks::SPELL_EVENT_COUNT) - { - auto key = EntryKey((Hooks::SpellEvents)event_id, entry); - bindingID = SpellEventBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, SpellEventBindings); - return 1; // Stack: callback - } + return RegisterEntryBinding(this, regtype, entry, event_id, functionRef, shots); break; case Hooks::REGTYPE_ITEM: @@ -913,11 +821,7 @@ int Eluna::Register(uint8 regtype, uint32 entry, ObjectGuid guid, uint32 instanc luaL_error(L, "Couldn't find a item with (ID: %d)!", entry); return 0; // Stack: (empty) } - - auto key = EntryKey((Hooks::ItemEvents)event_id, entry); - bindingID = ItemEventBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, ItemEventBindings); - return 1; // Stack: callback + return RegisterEntryBinding(this, regtype, entry, event_id, functionRef, shots); } break; @@ -930,45 +834,24 @@ int Eluna::Register(uint8 regtype, uint32 entry, ObjectGuid guid, uint32 instanc luaL_error(L, "Couldn't find a item with (ID: %d)!", entry); return 0; // Stack: (empty) } - - auto key = EntryKey((Hooks::GossipEvents)event_id, entry); - bindingID = ItemGossipBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, ItemGossipBindings); - return 1; // Stack: callback + return RegisterEntryBinding(this, regtype, entry, event_id, functionRef, shots); } break; case Hooks::REGTYPE_PLAYER_GOSSIP: if (event_id < Hooks::GOSSIP_EVENT_COUNT) - { - auto key = EntryKey((Hooks::GossipEvents)event_id, entry); - bindingID = PlayerGossipBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, PlayerGossipBindings); - return 1; // Stack: callback - } + return RegisterEntryBinding(this, regtype, entry, event_id, functionRef, shots); break; + case Hooks::REGTYPE_MAP: - if (event_id < Hooks::INSTANCE_EVENT_COUNT) - { - auto key = EntryKey((Hooks::InstanceEvents)event_id, entry); - bindingID = MapEventBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, MapEventBindings); - return 1; // Stack: callback - } - break; case Hooks::REGTYPE_INSTANCE: if (event_id < Hooks::INSTANCE_EVENT_COUNT) - { - auto key = EntryKey((Hooks::InstanceEvents)event_id, entry); - bindingID = InstanceEventBindings->Insert(key, functionRef, shots); - createCancelCallback(this, bindingID, InstanceEventBindings); - return 1; // Stack: callback - } + return RegisterEntryBinding(this, regtype, entry, event_id, functionRef, shots); break; } luaL_unref(L, LUA_REGISTRYINDEX, functionRef); std::ostringstream oss; - oss << "regtype " << static_cast(regtype) << ", event " << event_id << ", entry " << entry << ", guid " << + oss << "regtype " << static_cast(regtype) << ", event " << event_id << ", entry " << entry << ", guid " << #if defined ELUNA_TRINITY guid.ToHexString() #else @@ -1045,11 +928,17 @@ CreatureAI* Eluna::GetAI(Creature* creature) { Hooks::CreatureEvents event_id = (Hooks::CreatureEvents)i; - auto entryKey = EntryKey(event_id, creature->GetEntry()); - auto uniqueKey = UniqueObjectKey(event_id, creature->GET_GUID(), creature->GetInstanceId()); + typedef EntryKey EKey; + typedef UniqueObjectKey UKey; + + auto entryKey = EKey(event_id, creature->GetEntry()); + auto uniqueKey = UKey(event_id, creature->GET_GUID(), creature->GetInstanceId()); - if (CreatureEventBindings->HasBindingsFor(entryKey) || - CreatureUniqueBindings->HasBindingsFor(uniqueKey)) + auto CreatureEBindings = GetBinding(Hooks::REGTYPE_CREATURE); + auto CreatureUBindings = GetBinding(Hooks::REGTYPE_CREATURE_UNIQUE); + + if (CreatureEBindings->HasBindingsFor(entryKey) || + CreatureUBindings->HasBindingsFor(uniqueKey)) return new ElunaCreatureAI(creature); } @@ -1062,10 +951,15 @@ InstanceData* Eluna::GetInstanceData(Map* map) { Hooks::InstanceEvents event_id = (Hooks::InstanceEvents)i; - auto key = EntryKey(event_id, map->GetId()); + typedef EntryKey Key; + + auto key = Key(event_id, map->GetId()); - if (MapEventBindings->HasBindingsFor(key) || - InstanceEventBindings->HasBindingsFor(key)) + auto MapBindings = GetBinding(Hooks::REGTYPE_MAP); + auto InstanceBindings = GetBinding(Hooks::REGTYPE_INSTANCE); + + if (MapBindings->HasBindingsFor(key) || + InstanceBindings->HasBindingsFor(key)) return new ElunaInstanceAI(map); } @@ -1121,7 +1015,12 @@ void Eluna::FreeInstanceId(uint32 instanceId) { for (int i = 1; i < Hooks::INSTANCE_EVENT_COUNT; ++i) { - auto key = EntryKey((Hooks::InstanceEvents)i, instanceId); + typedef EntryKey Key; + + auto key = Key((Hooks::InstanceEvents)i, instanceId); + + auto MapEventBindings = GetBinding(Hooks::REGTYPE_MAP); + auto InstanceEventBindings = GetBinding(Hooks::REGTYPE_INSTANCE); if (MapEventBindings->HasBindingsFor(key)) MapEventBindings->Clear(key); diff --git a/LuaEngine.h b/LuaEngine.h index 2735e4c8b2..104e825956 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -103,6 +103,7 @@ typedef VehicleInfo Vehicle; struct lua_State; class EventMgr; class ElunaObject; +class BaseBindingMap; template class ElunaTemplate; template class BindingMap; @@ -150,8 +151,6 @@ enum MethodFlags : uint32 class ELUNA_GAME_API Eluna { public: - typedef std::list ScriptList; - typedef std::recursive_mutex LockType; void ReloadEluna() { reload = true; } bool ExecuteCall(int params, int res); @@ -183,6 +182,14 @@ class ELUNA_GAME_API Eluna // Map from map ID -> Lua table ref std::unordered_map continentDataRefs; + std::unordered_map, std::unique_ptr> bindingMaps; + + template + void CreateBinding(Hooks::RegisterTypes type) + { + bindingMaps[std::underlying_type_t(type)] = std::make_unique>(L); + } + void OpenLua(); void CloseLua(); void DestroyBindStores(); @@ -240,34 +247,13 @@ class ELUNA_GAME_API Eluna public: lua_State* L; - EventMgr* eventMgr; + std::unique_ptr eventMgr; #if defined ELUNA_TRINITY QueryCallbackProcessor queryProcessor; QueryCallbackProcessor& GetQueryProcessor() { return queryProcessor; } #endif - BindingMap< EventKey >* ServerEventBindings; - BindingMap< EventKey >* PlayerEventBindings; - BindingMap< EventKey >* GuildEventBindings; - BindingMap< EventKey >* GroupEventBindings; - BindingMap< EventKey >* VehicleEventBindings; - BindingMap< EventKey >* BGEventBindings; - - BindingMap< EntryKey >* PacketEventBindings; - BindingMap< EntryKey >* CreatureEventBindings; - BindingMap< EntryKey >* CreatureGossipBindings; - BindingMap< EntryKey >* GameObjectEventBindings; - BindingMap< EntryKey >* GameObjectGossipBindings; - BindingMap< EntryKey >* SpellEventBindings; - BindingMap< EntryKey >* ItemEventBindings; - BindingMap< EntryKey >* ItemGossipBindings; - BindingMap< EntryKey >* PlayerGossipBindings; - BindingMap< EntryKey >* MapEventBindings; - BindingMap< EntryKey >* InstanceEventBindings; - - BindingMap< UniqueObjectKey >* CreatureUniqueBindings; - static int StackTrace(lua_State* _L); static void Report(lua_State* _L); @@ -337,7 +323,7 @@ class ELUNA_GAME_API Eluna #if !defined TRACKABLE_PTR_NAMESPACE uint64 GetCallstackId() const { return callstackid; } #endif - int Register(uint8 reg, uint32 entry, ObjectGuid guid, uint32 instanceId, uint32 event_id, int functionRef, uint32 shots); + int Register(std::underlying_type_t regtype, uint32 entry, ObjectGuid guid, uint32 instanceId, uint32 event_id, int functionRef, uint32 shots); void UpdateEluna(uint32 diff); // Checks @@ -374,6 +360,20 @@ class ELUNA_GAME_API Eluna return 0; } + template + BindingMap* GetBinding(std::underlying_type_t type) + { + auto it = bindingMaps.find(type); + if (it == bindingMaps.end()) return nullptr; + return dynamic_cast*>(it->second.get()); + } + + template + BindingMap* GetBinding(Hooks::RegisterTypes type) + { + return GetBinding(static_cast>(type)); + } + Eluna(Map * map); ~Eluna(); diff --git a/hooks/BattleGroundHooks.cpp b/hooks/BattleGroundHooks.cpp index 292ba431aa..117727fad3 100644 --- a/hooks/BattleGroundHooks.cpp +++ b/hooks/BattleGroundHooks.cpp @@ -13,8 +13,9 @@ using namespace Hooks; #define START_HOOK(EVENT) \ + auto binding = GetBinding>(REGTYPE_BG);\ auto key = EventKey(EVENT);\ - if (!BGEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return; void Eluna::OnBGStart(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId) @@ -23,7 +24,7 @@ void Eluna::OnBGStart(BattleGround* bg, BattleGroundTypeId bgId, uint32 instance HookPush(bg); HookPush(bgId); HookPush(instanceId); - CallAllFunctions(BGEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnBGEnd(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId, Team winner) @@ -33,7 +34,7 @@ void Eluna::OnBGEnd(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId HookPush(bgId); HookPush(instanceId); HookPush(winner); - CallAllFunctions(BGEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnBGCreate(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId) @@ -42,7 +43,7 @@ void Eluna::OnBGCreate(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanc HookPush(bg); HookPush(bgId); HookPush(instanceId); - CallAllFunctions(BGEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnBGDestroy(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId) @@ -51,5 +52,5 @@ void Eluna::OnBGDestroy(BattleGround* bg, BattleGroundTypeId bgId, uint32 instan HookPush(bg); HookPush(bgId); HookPush(instanceId); - CallAllFunctions(BGEventBindings, key); + CallAllFunctions(binding, key); } diff --git a/hooks/CreatureHooks.cpp b/hooks/CreatureHooks.cpp index dbf2ad3745..e0c59a3869 100644 --- a/hooks/CreatureHooks.cpp +++ b/hooks/CreatureHooks.cpp @@ -14,6 +14,8 @@ using namespace Hooks; #define START_HOOK(EVENT, CREATURE) \ + auto CreatureEventBindings = GetBinding>(REGTYPE_CREATURE);\ + auto CreatureUniqueBindings = GetBinding>(REGTYPE_CREATURE_UNIQUE);\ auto entry_key = EntryKey(EVENT, CREATURE->GetEntry());\ auto unique_key = UniqueObjectKey(EVENT, CREATURE->GET_GUID(), CREATURE->GetInstanceId());\ if (!CreatureEventBindings->HasBindingsFor(entry_key))\ @@ -21,6 +23,8 @@ using namespace Hooks; return; #define START_HOOK_WITH_RETVAL(EVENT, CREATURE, RETVAL) \ + auto CreatureEventBindings = GetBinding>(REGTYPE_CREATURE);\ + auto CreatureUniqueBindings = GetBinding>(REGTYPE_CREATURE_UNIQUE);\ auto entry_key = EntryKey(EVENT, CREATURE->GetEntry());\ auto unique_key = UniqueObjectKey(EVENT, CREATURE->GET_GUID(), CREATURE->GetInstanceId());\ if (!CreatureEventBindings->HasBindingsFor(entry_key))\ diff --git a/hooks/GameObjectHooks.cpp b/hooks/GameObjectHooks.cpp index 654811334f..8982f5e0c0 100644 --- a/hooks/GameObjectHooks.cpp +++ b/hooks/GameObjectHooks.cpp @@ -15,13 +15,15 @@ using namespace Hooks; #define START_HOOK(EVENT, ENTRY) \ + auto binding = GetBinding>(REGTYPE_GAMEOBJECT);\ auto key = EntryKey(EVENT, ENTRY);\ - if (!GameObjectEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return; #define START_HOOK_WITH_RETVAL(EVENT, ENTRY, RETVAL) \ + auto binding = GetBinding>(REGTYPE_GAMEOBJECT);\ auto key = EntryKey(EVENT, ENTRY);\ - if (!GameObjectEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return RETVAL; void Eluna::OnDummyEffect(WorldObject* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget) @@ -31,7 +33,7 @@ void Eluna::OnDummyEffect(WorldObject* pCaster, uint32 spellId, SpellEffIndex ef HookPush(spellId); HookPush(effIndex); HookPush(pTarget); - CallAllFunctions(GameObjectEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::UpdateAI(GameObject* pGameObject, uint32 diff) @@ -39,7 +41,7 @@ void Eluna::UpdateAI(GameObject* pGameObject, uint32 diff) START_HOOK(GAMEOBJECT_EVENT_ON_AIUPDATE, pGameObject->GetEntry()); HookPush(pGameObject); HookPush(diff); - CallAllFunctions(GameObjectEventBindings, key); + CallAllFunctions(binding, key); } bool Eluna::OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) @@ -48,7 +50,7 @@ bool Eluna::OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest const* HookPush(pPlayer); HookPush(pGameObject); HookPush(pQuest); - return CallAllFunctionsBool(GameObjectEventBindings, key); + return CallAllFunctionsBool(binding, key); } bool Eluna::OnQuestReward(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest, uint32 opt) @@ -58,7 +60,7 @@ bool Eluna::OnQuestReward(Player* pPlayer, GameObject* pGameObject, Quest const* HookPush(pGameObject); HookPush(pQuest); HookPush(opt); - return CallAllFunctionsBool(GameObjectEventBindings, key); + return CallAllFunctionsBool(binding, key); } void Eluna::GetDialogStatus(const Player* pPlayer, const GameObject* pGameObject) @@ -66,7 +68,7 @@ void Eluna::GetDialogStatus(const Player* pPlayer, const GameObject* pGameObject START_HOOK(GAMEOBJECT_EVENT_ON_DIALOG_STATUS, pGameObject->GetEntry()); HookPush(pPlayer); HookPush(pGameObject); - CallAllFunctions(GameObjectEventBindings, key); + CallAllFunctions(binding, key); } #if ELUNA_EXPANSION >= EXP_WOTLK @@ -75,7 +77,7 @@ void Eluna::OnDestroyed(GameObject* pGameObject, WorldObject* attacker) START_HOOK(GAMEOBJECT_EVENT_ON_DESTROYED, pGameObject->GetEntry()); HookPush(pGameObject); HookPush(attacker); - CallAllFunctions(GameObjectEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnDamaged(GameObject* pGameObject, WorldObject* attacker) @@ -83,7 +85,7 @@ void Eluna::OnDamaged(GameObject* pGameObject, WorldObject* attacker) START_HOOK(GAMEOBJECT_EVENT_ON_DAMAGED, pGameObject->GetEntry()); HookPush(pGameObject); HookPush(attacker); - CallAllFunctions(GameObjectEventBindings, key); + CallAllFunctions(binding, key); } #endif @@ -92,7 +94,7 @@ void Eluna::OnLootStateChanged(GameObject* pGameObject, uint32 state) START_HOOK(GAMEOBJECT_EVENT_ON_LOOT_STATE_CHANGE, pGameObject->GetEntry()); HookPush(pGameObject); HookPush(state); - CallAllFunctions(GameObjectEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnGameObjectStateChanged(GameObject* pGameObject, uint32 state) @@ -100,28 +102,28 @@ void Eluna::OnGameObjectStateChanged(GameObject* pGameObject, uint32 state) START_HOOK(GAMEOBJECT_EVENT_ON_GO_STATE_CHANGED, pGameObject->GetEntry()); HookPush(pGameObject); HookPush(state); - CallAllFunctions(GameObjectEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnSpawn(GameObject* pGameObject) { START_HOOK(GAMEOBJECT_EVENT_ON_SPAWN, pGameObject->GetEntry()); HookPush(pGameObject); - CallAllFunctions(GameObjectEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnAddToWorld(GameObject* pGameObject) { START_HOOK(GAMEOBJECT_EVENT_ON_ADD, pGameObject->GetEntry()); HookPush(pGameObject); - CallAllFunctions(GameObjectEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnRemoveFromWorld(GameObject* pGameObject) { START_HOOK(GAMEOBJECT_EVENT_ON_REMOVE, pGameObject->GetEntry()); HookPush(pGameObject); - CallAllFunctions(GameObjectEventBindings, key); + CallAllFunctions(binding, key); } bool Eluna::OnGameObjectUse(Player* pPlayer, GameObject* pGameObject) @@ -129,5 +131,5 @@ bool Eluna::OnGameObjectUse(Player* pPlayer, GameObject* pGameObject) START_HOOK_WITH_RETVAL(GAMEOBJECT_EVENT_ON_USE, pGameObject->GetEntry(), false); HookPush(pGameObject); HookPush(pPlayer); - return CallAllFunctionsBool(GameObjectEventBindings, key); + return CallAllFunctionsBool(binding, key); } diff --git a/hooks/GossipHooks.cpp b/hooks/GossipHooks.cpp index 22399e721b..748a50ec2e 100644 --- a/hooks/GossipHooks.cpp +++ b/hooks/GossipHooks.cpp @@ -13,19 +13,21 @@ using namespace Hooks; -#define START_HOOK(BINDINGS, EVENT, ENTRY) \ +#define START_HOOK(REGTYPE, EVENT, ENTRY) \ + auto binding = GetBinding>(REGTYPE);\ auto key = EntryKey(EVENT, ENTRY);\ - if (!BINDINGS->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return; -#define START_HOOK_WITH_RETVAL(BINDINGS, EVENT, ENTRY, RETVAL) \ +#define START_HOOK_WITH_RETVAL(REGTYPE, EVENT, ENTRY, RETVAL) \ + auto binding = GetBinding>(REGTYPE);\ auto key = EntryKey(EVENT, ENTRY);\ - if (!BINDINGS->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return RETVAL; bool Eluna::OnGossipHello(Player* pPlayer, GameObject* pGameObject) { - START_HOOK_WITH_RETVAL(GameObjectGossipBindings, GOSSIP_EVENT_ON_HELLO, pGameObject->GetEntry(), false); + START_HOOK_WITH_RETVAL(REGTYPE_GAMEOBJECT_GOSSIP, GOSSIP_EVENT_ON_HELLO, pGameObject->GetEntry(), false); #if defined ELUNA_CMANGOS && ELUNA_EXPANSION < EXP_CATA pPlayer->GetPlayerMenu()->ClearMenus(); #else @@ -33,12 +35,12 @@ bool Eluna::OnGossipHello(Player* pPlayer, GameObject* pGameObject) #endif HookPush(pPlayer); HookPush(pGameObject); - return CallAllFunctionsBool(GameObjectGossipBindings, key, true); + return CallAllFunctionsBool(binding, key, true); } bool Eluna::OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action) { - START_HOOK_WITH_RETVAL(GameObjectGossipBindings, GOSSIP_EVENT_ON_SELECT, pGameObject->GetEntry(), false); + START_HOOK_WITH_RETVAL(REGTYPE_GAMEOBJECT_GOSSIP, GOSSIP_EVENT_ON_SELECT, pGameObject->GetEntry(), false); #if defined ELUNA_CMANGOS && ELUNA_EXPANSION < EXP_CATA pPlayer->GetPlayerMenu()->ClearMenus(); #else @@ -48,12 +50,12 @@ bool Eluna::OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 send HookPush(pGameObject); HookPush(sender); HookPush(action); - return CallAllFunctionsBool(GameObjectGossipBindings, key, true); + return CallAllFunctionsBool(binding, key, true); } bool Eluna::OnGossipSelectCode(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action, const char* code) { - START_HOOK_WITH_RETVAL(GameObjectGossipBindings, GOSSIP_EVENT_ON_SELECT, pGameObject->GetEntry(), false); + START_HOOK_WITH_RETVAL(REGTYPE_GAMEOBJECT_GOSSIP, GOSSIP_EVENT_ON_SELECT, pGameObject->GetEntry(), false); #if defined ELUNA_CMANGOS && ELUNA_EXPANSION < EXP_CATA pPlayer->GetPlayerMenu()->ClearMenus(); #else @@ -64,12 +66,12 @@ bool Eluna::OnGossipSelectCode(Player* pPlayer, GameObject* pGameObject, uint32 HookPush(sender); HookPush(action); HookPush(code); - return CallAllFunctionsBool(GameObjectGossipBindings, key, true); + return CallAllFunctionsBool(binding, key, true); } void Eluna::HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, const std::string& code) { - START_HOOK(PlayerGossipBindings, GOSSIP_EVENT_ON_SELECT, menuId); + START_HOOK(REGTYPE_PLAYER_GOSSIP, GOSSIP_EVENT_ON_SELECT, menuId); #if defined ELUNA_CMANGOS && ELUNA_EXPANSION < EXP_CATA pPlayer->GetPlayerMenu()->ClearMenus(); #else @@ -85,12 +87,12 @@ void Eluna::HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 send else HookPush(code); - CallAllFunctions(PlayerGossipBindings, key); + CallAllFunctions(binding, key); } bool Eluna::OnItemGossip(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/) { - START_HOOK_WITH_RETVAL(ItemGossipBindings, GOSSIP_EVENT_ON_HELLO, pItem->GetEntry(), true); + START_HOOK_WITH_RETVAL(REGTYPE_ITEM_GOSSIP, GOSSIP_EVENT_ON_HELLO, pItem->GetEntry(), true); #if defined ELUNA_CMANGOS && ELUNA_EXPANSION < EXP_CATA pPlayer->GetPlayerMenu()->ClearMenus(); #else @@ -98,12 +100,12 @@ bool Eluna::OnItemGossip(Player* pPlayer, Item* pItem, SpellCastTargets const& / #endif HookPush(pPlayer); HookPush(pItem); - return CallAllFunctionsBool(ItemGossipBindings, key, true); + return CallAllFunctionsBool(binding, key, true); } void Eluna::HandleGossipSelectOption(Player* pPlayer, Item* pItem, uint32 sender, uint32 action, const std::string& code) { - START_HOOK(ItemGossipBindings, GOSSIP_EVENT_ON_SELECT, pItem->GetEntry()); + START_HOOK(REGTYPE_ITEM_GOSSIP, GOSSIP_EVENT_ON_SELECT, pItem->GetEntry()); #if defined ELUNA_CMANGOS && ELUNA_EXPANSION < EXP_CATA pPlayer->GetPlayerMenu()->ClearMenus(); #else @@ -119,12 +121,12 @@ void Eluna::HandleGossipSelectOption(Player* pPlayer, Item* pItem, uint32 sender else HookPush(code); - CallAllFunctions(ItemGossipBindings, key); + CallAllFunctions(binding, key); } bool Eluna::OnGossipHello(Player* pPlayer, Creature* pCreature) { - START_HOOK_WITH_RETVAL(CreatureGossipBindings, GOSSIP_EVENT_ON_HELLO, pCreature->GetEntry(), false); + START_HOOK_WITH_RETVAL(REGTYPE_CREATURE_GOSSIP, GOSSIP_EVENT_ON_HELLO, pCreature->GetEntry(), false); #if defined ELUNA_CMANGOS && ELUNA_EXPANSION < EXP_CATA pPlayer->GetPlayerMenu()->ClearMenus(); #else @@ -132,12 +134,12 @@ bool Eluna::OnGossipHello(Player* pPlayer, Creature* pCreature) #endif HookPush(pPlayer); HookPush(pCreature); - return CallAllFunctionsBool(CreatureGossipBindings, key, true); + return CallAllFunctionsBool(binding, key, true); } bool Eluna::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action) { - START_HOOK_WITH_RETVAL(CreatureGossipBindings, GOSSIP_EVENT_ON_SELECT, pCreature->GetEntry(), false); + START_HOOK_WITH_RETVAL(REGTYPE_CREATURE_GOSSIP, GOSSIP_EVENT_ON_SELECT, pCreature->GetEntry(), false); #if defined ELUNA_CMANGOS && ELUNA_EXPANSION < EXP_CATA auto original_menu = *pPlayer->GetPlayerMenu(); pPlayer->GetPlayerMenu()->ClearMenus(); @@ -149,7 +151,7 @@ bool Eluna::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, HookPush(pCreature); HookPush(sender); HookPush(action); - auto preventDefault = CallAllFunctionsBool(CreatureGossipBindings, key, true); + auto preventDefault = CallAllFunctionsBool(binding, key, true); if (!preventDefault) { #if defined ELUNA_CMANGOS && ELUNA_EXPANSION < EXP_CATA *pPlayer->GetPlayerMenu() = original_menu; @@ -162,7 +164,7 @@ bool Eluna::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, bool Eluna::OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code) { - START_HOOK_WITH_RETVAL(CreatureGossipBindings, GOSSIP_EVENT_ON_SELECT, pCreature->GetEntry(), false); + START_HOOK_WITH_RETVAL(REGTYPE_CREATURE_GOSSIP, GOSSIP_EVENT_ON_SELECT, pCreature->GetEntry(), false); #if defined ELUNA_CMANGOS && ELUNA_EXPANSION < EXP_CATA auto original_menu = *pPlayer->GetPlayerMenu(); pPlayer->GetPlayerMenu()->ClearMenus(); @@ -175,7 +177,7 @@ bool Eluna::OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 send HookPush(sender); HookPush(action); HookPush(code); - auto preventDefault = CallAllFunctionsBool(CreatureGossipBindings, key, true); + auto preventDefault = CallAllFunctionsBool(binding, key, true); if (!preventDefault) { #if defined ELUNA_CMANGOS && ELUNA_EXPANSION < EXP_CATA *pPlayer->GetPlayerMenu() = original_menu; diff --git a/hooks/GroupHooks.cpp b/hooks/GroupHooks.cpp index 542081246b..91948ae7cd 100644 --- a/hooks/GroupHooks.cpp +++ b/hooks/GroupHooks.cpp @@ -13,13 +13,15 @@ using namespace Hooks; #define START_HOOK(EVENT) \ + auto binding = GetBinding>(REGTYPE_GROUP);\ auto key = EventKey(EVENT);\ - if (!GroupEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return; #define START_HOOK_WITH_RETVAL(EVENT, RETVAL) \ + auto binding = GetBinding>(REGTYPE_GROUP);\ auto key = EventKey(EVENT);\ - if (!GroupEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return RETVAL; void Eluna::OnAddMember(Group* group, ObjectGuid guid) @@ -27,7 +29,7 @@ void Eluna::OnAddMember(Group* group, ObjectGuid guid) START_HOOK(GROUP_EVENT_ON_MEMBER_ADD); HookPush(group); HookPush(guid); - CallAllFunctions(GroupEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnInviteMember(Group* group, ObjectGuid guid) @@ -35,7 +37,7 @@ void Eluna::OnInviteMember(Group* group, ObjectGuid guid) START_HOOK(GROUP_EVENT_ON_MEMBER_INVITE); HookPush(group); HookPush(guid); - CallAllFunctions(GroupEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnRemoveMember(Group* group, ObjectGuid guid, uint8 method) @@ -44,7 +46,7 @@ void Eluna::OnRemoveMember(Group* group, ObjectGuid guid, uint8 method) HookPush(group); HookPush(guid); HookPush(method); - CallAllFunctions(GroupEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnChangeLeader(Group* group, ObjectGuid newLeaderGuid, ObjectGuid oldLeaderGuid) @@ -53,14 +55,14 @@ void Eluna::OnChangeLeader(Group* group, ObjectGuid newLeaderGuid, ObjectGuid ol HookPush(group); HookPush(newLeaderGuid); HookPush(oldLeaderGuid); - CallAllFunctions(GroupEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnDisband(Group* group) { START_HOOK(GROUP_EVENT_ON_DISBAND); HookPush(group); - CallAllFunctions(GroupEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnCreate(Group* group, ObjectGuid leaderGuid, GroupType groupType) @@ -69,7 +71,7 @@ void Eluna::OnCreate(Group* group, ObjectGuid leaderGuid, GroupType groupType) HookPush(group); HookPush(leaderGuid); HookPush(groupType); - CallAllFunctions(GroupEventBindings, key); + CallAllFunctions(binding, key); } bool Eluna::OnMemberAccept(Group* group, Player* player) @@ -77,5 +79,5 @@ bool Eluna::OnMemberAccept(Group* group, Player* player) START_HOOK_WITH_RETVAL(GROUP_EVENT_ON_MEMBER_ACCEPT, true); HookPush(group); HookPush(player); - return CallAllFunctionsBool(GroupEventBindings, key, true); + return CallAllFunctionsBool(binding, key, true); } diff --git a/hooks/GuildHooks.cpp b/hooks/GuildHooks.cpp index 6018507948..75bcefb457 100644 --- a/hooks/GuildHooks.cpp +++ b/hooks/GuildHooks.cpp @@ -13,8 +13,9 @@ using namespace Hooks; #define START_HOOK(EVENT) \ + auto binding = GetBinding>(REGTYPE_GUILD);\ auto key = EventKey(EVENT);\ - if (!GuildEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return; void Eluna::OnAddMember(Guild* guild, Player* player, uint32 plRank) @@ -23,7 +24,7 @@ void Eluna::OnAddMember(Guild* guild, Player* player, uint32 plRank) HookPush(guild); HookPush(player); HookPush(plRank); - CallAllFunctions(GuildEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnRemoveMember(Guild* guild, Player* player, bool isDisbanding) @@ -32,7 +33,7 @@ void Eluna::OnRemoveMember(Guild* guild, Player* player, bool isDisbanding) HookPush(guild); HookPush(player); HookPush(isDisbanding); - CallAllFunctions(GuildEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnMOTDChanged(Guild* guild, const std::string& newMotd) @@ -40,7 +41,7 @@ void Eluna::OnMOTDChanged(Guild* guild, const std::string& newMotd) START_HOOK(GUILD_EVENT_ON_MOTD_CHANGE); HookPush(guild); HookPush(newMotd); - CallAllFunctions(GuildEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnInfoChanged(Guild* guild, const std::string& newInfo) @@ -48,7 +49,7 @@ void Eluna::OnInfoChanged(Guild* guild, const std::string& newInfo) START_HOOK(GUILD_EVENT_ON_INFO_CHANGE); HookPush(guild); HookPush(newInfo); - CallAllFunctions(GuildEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnCreate(Guild* guild, Player* leader, const std::string& name) @@ -57,14 +58,14 @@ void Eluna::OnCreate(Guild* guild, Player* leader, const std::string& name) HookPush(guild); HookPush(leader); HookPush(name); - CallAllFunctions(GuildEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnDisband(Guild* guild) { START_HOOK(GUILD_EVENT_ON_DISBAND); HookPush(guild); - CallAllFunctions(GuildEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnMemberWitdrawMoney(Guild* guild, Player* player, uint32& amount, bool isRepair) @@ -75,7 +76,7 @@ void Eluna::OnMemberWitdrawMoney(Guild* guild, Player* player, uint32& amount, b HookPush(amount); HookPush(isRepair); // isRepair not a part of Mangos, implement? int amountIndex = lua_gettop(L) - 1; - int n = SetupStack(GuildEventBindings, key, 4); + int n = SetupStack(binding, key, 4); while (n > 0) { @@ -103,7 +104,7 @@ void Eluna::OnMemberWitdrawMoney(Guild* guild, Player* player, uint64& amount, b HookPush(amount); HookPush(isRepair); // isRepair not a part of Mangos, implement? int amountIndex = lua_gettop(L) - 1; - int n = SetupStack(GuildEventBindings, key, 4); + int n = SetupStack(binding, key, 4); while (n > 0) { @@ -130,7 +131,7 @@ void Eluna::OnMemberDepositMoney(Guild* guild, Player* player, uint32& amount) HookPush(player); HookPush(amount); int amountIndex = lua_gettop(L); - int n = SetupStack(GuildEventBindings, key, 3); + int n = SetupStack(binding, key, 3); while (n > 0) { @@ -157,7 +158,7 @@ void Eluna::OnMemberDepositMoney(Guild* guild, Player* player, uint64& amount) HookPush(player); HookPush(amount); int amountIndex = lua_gettop(L); - int n = SetupStack(GuildEventBindings, key, 3); + int n = SetupStack(binding, key, 3); while (n > 0) { @@ -190,7 +191,7 @@ void Eluna::OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank HookPush(isDestBank); HookPush(destContainer); HookPush(destSlotId); - CallAllFunctions(GuildEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnEvent(Guild* guild, uint8 eventType, uint32 playerGuid1, uint32 playerGuid2, uint8 newRank) @@ -201,7 +202,7 @@ void Eluna::OnEvent(Guild* guild, uint8 eventType, uint32 playerGuid1, uint32 pl HookPush(playerGuid1); HookPush(playerGuid2); HookPush(newRank); - CallAllFunctions(GuildEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, uint32 playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId) @@ -214,5 +215,5 @@ void Eluna::OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, uint32 playe HookPush(itemOrMoney); HookPush(itemStackCount); HookPush(destTabId); - CallAllFunctions(GuildEventBindings, key); + CallAllFunctions(binding, key); } diff --git a/hooks/Hooks.h b/hooks/Hooks.h index 0abf9dc1c0..00f1ecb32d 100644 --- a/hooks/Hooks.h +++ b/hooks/Hooks.h @@ -68,7 +68,7 @@ namespace Hooks { - enum RegisterTypes + enum RegisterTypes : uint8 { REGTYPE_PACKET, REGTYPE_SERVER, @@ -76,6 +76,7 @@ namespace Hooks REGTYPE_GUILD, REGTYPE_GROUP, REGTYPE_CREATURE, + REGTYPE_CREATURE_UNIQUE, REGTYPE_VEHICLE, REGTYPE_CREATURE_GOSSIP, REGTYPE_GAMEOBJECT, diff --git a/hooks/InstanceHooks.cpp b/hooks/InstanceHooks.cpp index 9dcd95bf3d..a592b8565e 100644 --- a/hooks/InstanceHooks.cpp +++ b/hooks/InstanceHooks.cpp @@ -15,6 +15,8 @@ using namespace Hooks; #define START_HOOK(EVENT, AI) \ + auto MapEventBindings = GetBinding>(REGTYPE_MAP);\ + auto InstanceEventBindings = GetBinding>(REGTYPE_INSTANCE);\ auto mapKey = EntryKey(EVENT, AI->instance->GetId());\ auto instanceKey = EntryKey(EVENT, AI->instance->GetInstanceId());\ if (!MapEventBindings->HasBindingsFor(mapKey) && !InstanceEventBindings->HasBindingsFor(instanceKey))\ @@ -23,6 +25,8 @@ using namespace Hooks; HookPush(AI->instance) #define START_HOOK_WITH_RETVAL(EVENT, AI, RETVAL) \ + auto MapEventBindings = GetBinding>(REGTYPE_MAP);\ + auto InstanceEventBindings = GetBinding>(REGTYPE_INSTANCE);\ auto mapKey = EntryKey(EVENT, AI->instance->GetId());\ auto instanceKey = EntryKey(EVENT, AI->instance->GetInstanceId());\ if (!MapEventBindings->HasBindingsFor(mapKey) && !InstanceEventBindings->HasBindingsFor(instanceKey))\ diff --git a/hooks/ItemHooks.cpp b/hooks/ItemHooks.cpp index a7cd3c4a6c..d03d6094a0 100644 --- a/hooks/ItemHooks.cpp +++ b/hooks/ItemHooks.cpp @@ -14,13 +14,15 @@ using namespace Hooks; #define START_HOOK(EVENT, ENTRY) \ + auto binding = GetBinding>(REGTYPE_ITEM);\ auto key = EntryKey(EVENT, ENTRY);\ - if (!ItemEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return; #define START_HOOK_WITH_RETVAL(EVENT, ENTRY, RETVAL) \ + auto binding = GetBinding>(REGTYPE_ITEM);\ auto key = EntryKey(EVENT, ENTRY);\ - if (!ItemEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return RETVAL; void Eluna::OnDummyEffect(WorldObject* pCaster, uint32 spellId, SpellEffIndex effIndex, Item* pTarget) @@ -30,7 +32,7 @@ void Eluna::OnDummyEffect(WorldObject* pCaster, uint32 spellId, SpellEffIndex ef HookPush(spellId); HookPush(effIndex); HookPush(pTarget); - CallAllFunctions(ItemEventBindings, key); + CallAllFunctions(binding, key); } bool Eluna::OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest) @@ -39,7 +41,7 @@ bool Eluna::OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest) HookPush(pPlayer); HookPush(pItem); HookPush(pQuest); - return CallAllFunctionsBool(ItemEventBindings, key); + return CallAllFunctionsBool(binding, key); } bool Eluna::OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets) @@ -98,7 +100,7 @@ bool Eluna::OnItemUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targ HookPush(); #endif - return CallAllFunctionsBool(ItemEventBindings, key, true); + return CallAllFunctionsBool(binding, key, true); } bool Eluna::OnExpire(Player* pPlayer, ItemTemplate const* pProto) @@ -106,7 +108,7 @@ bool Eluna::OnExpire(Player* pPlayer, ItemTemplate const* pProto) START_HOOK_WITH_RETVAL(ITEM_EVENT_ON_EXPIRE, pProto->ItemId, false); HookPush(pPlayer); HookPush(pProto->ItemId); - return CallAllFunctionsBool(ItemEventBindings, key); + return CallAllFunctionsBool(binding, key); } bool Eluna::OnRemove(Player* pPlayer, Item* pItem) @@ -114,7 +116,7 @@ bool Eluna::OnRemove(Player* pPlayer, Item* pItem) START_HOOK_WITH_RETVAL(ITEM_EVENT_ON_REMOVE, pItem->GetEntry(), false); HookPush(pPlayer); HookPush(pItem); - return CallAllFunctionsBool(ItemEventBindings, key); + return CallAllFunctionsBool(binding, key); } void Eluna::OnAdd(Player* pPlayer, Item* pItem) @@ -122,7 +124,7 @@ void Eluna::OnAdd(Player* pPlayer, Item* pItem) START_HOOK(ITEM_EVENT_ON_ADD, pItem->GetEntry()); HookPush(pPlayer); HookPush(pItem); - CallAllFunctions(ItemEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnItemEquip(Player* pPlayer, Item* pItem, uint8 slot) @@ -131,7 +133,7 @@ void Eluna::OnItemEquip(Player* pPlayer, Item* pItem, uint8 slot) HookPush(pPlayer); HookPush(pItem); HookPush(slot); - CallAllFunctions(ItemEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnItemUnEquip(Player* pPlayer, Item* pItem, uint8 slot) @@ -140,5 +142,5 @@ void Eluna::OnItemUnEquip(Player* pPlayer, Item* pItem, uint8 slot) HookPush(pPlayer); HookPush(pItem); HookPush(slot); - CallAllFunctions(ItemEventBindings, key); + CallAllFunctions(binding, key); } diff --git a/hooks/PacketHooks.cpp b/hooks/PacketHooks.cpp index bf5fd37383..60c0f8f84f 100644 --- a/hooks/PacketHooks.cpp +++ b/hooks/PacketHooks.cpp @@ -14,13 +14,15 @@ using namespace Hooks; #define START_HOOK_SERVER(EVENT) \ + auto binding = GetBinding>(REGTYPE_SERVER);\ auto key = EventKey(EVENT);\ - if (!ServerEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return; #define START_HOOK_PACKET(EVENT, OPCODE) \ + auto binding = GetBinding>(REGTYPE_PACKET);\ auto key = EntryKey(EVENT, OPCODE);\ - if (!PacketEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return; bool Eluna::OnPacketSend(WorldSession* session, const WorldPacket& packet) @@ -38,7 +40,7 @@ void Eluna::OnPacketSendAny(Player* player, const WorldPacket& packet, bool& res START_HOOK_SERVER(SERVER_EVENT_ON_PACKET_SEND); HookPush(&packet); // pushing pointer to local is fine, a copy of value will be stored, not pointer itself HookPush(player); - int n = SetupStack(ServerEventBindings, key, 2); + int n = SetupStack(binding, key, 2); while (n > 0) { @@ -58,7 +60,7 @@ void Eluna::OnPacketSendOne(Player* player, const WorldPacket& packet, bool& res START_HOOK_PACKET(PACKET_EVENT_ON_PACKET_SEND, packet.GetOpcode()); HookPush(&packet); // pushing pointer to local is fine, a copy of value will be stored, not pointer itself HookPush(player); - int n = SetupStack(PacketEventBindings, key, 2); + int n = SetupStack(binding, key, 2); while (n > 0) { @@ -89,7 +91,7 @@ void Eluna::OnPacketReceiveAny(Player* player, WorldPacket& packet, bool& result START_HOOK_SERVER(SERVER_EVENT_ON_PACKET_RECEIVE); HookPush(&packet); // pushing pointer to local is fine, a copy of value will be stored, not pointer itself HookPush(player); - int n = SetupStack(ServerEventBindings, key, 2); + int n = SetupStack(binding, key, 2); while (n > 0) { @@ -119,7 +121,7 @@ void Eluna::OnPacketReceiveOne(Player* player, WorldPacket& packet, bool& result START_HOOK_PACKET(PACKET_EVENT_ON_PACKET_RECEIVE, packet.GetOpcode()); HookPush(&packet); // pushing pointer to local is fine, a copy of value will be stored, not pointer itself HookPush(player); - int n = SetupStack(PacketEventBindings, key, 2); + int n = SetupStack(binding, key, 2); while (n > 0) { diff --git a/hooks/PlayerHooks.cpp b/hooks/PlayerHooks.cpp index b319d66386..cb11b76c18 100644 --- a/hooks/PlayerHooks.cpp +++ b/hooks/PlayerHooks.cpp @@ -17,13 +17,15 @@ using namespace Hooks; #define START_HOOK(EVENT) \ + auto binding = GetBinding>(REGTYPE_PLAYER);\ auto key = EventKey(EVENT);\ - if (!PlayerEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return; #define START_HOOK_WITH_RETVAL(EVENT, RETVAL) \ + auto binding = GetBinding>(REGTYPE_PLAYER);\ auto key = EventKey(EVENT);\ - if (!PlayerEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return RETVAL; void Eluna::OnLearnTalents(Player* pPlayer, uint32 talentId, uint32 talentRank, uint32 spellid) @@ -33,7 +35,7 @@ void Eluna::OnLearnTalents(Player* pPlayer, uint32 talentId, uint32 talentRank, HookPush(talentId); HookPush(talentRank); HookPush(spellid); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnSkillChange(Player* pPlayer, uint32 skillId, uint32 skillValue) @@ -43,7 +45,7 @@ void Eluna::OnSkillChange(Player* pPlayer, uint32 skillId, uint32 skillValue) HookPush(skillId); HookPush(skillValue); int valueIndex = lua_gettop(L) - 1; - int n = SetupStack(PlayerEventBindings, key, 3); + int n = SetupStack(binding, key, 3); while (n > 0) { @@ -67,7 +69,7 @@ void Eluna::OnLearnSpell(Player* pPlayer, uint32 spellId) START_HOOK(PLAYER_EVENT_ON_LEARN_SPELL); HookPush(pPlayer); HookPush(spellId); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } bool Eluna::OnCommand(Player* player, const char* text) @@ -94,7 +96,7 @@ bool Eluna::OnCommand(Player* player, const char* text) START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_COMMAND, true); HookPush(player); HookPush(text); - return CallAllFunctionsBool(PlayerEventBindings, key, true); + return CallAllFunctionsBool(binding, key, true); } void Eluna::OnLootItem(Player* pPlayer, Item* pItem, uint32 count, ObjectGuid guid) @@ -104,7 +106,7 @@ void Eluna::OnLootItem(Player* pPlayer, Item* pItem, uint32 count, ObjectGuid gu HookPush(pItem); HookPush(count); HookPush(guid); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnLootMoney(Player* pPlayer, uint32 amount) @@ -112,28 +114,28 @@ void Eluna::OnLootMoney(Player* pPlayer, uint32 amount) START_HOOK(PLAYER_EVENT_ON_LOOT_MONEY); HookPush(pPlayer); HookPush(amount); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnFirstLogin(Player* pPlayer) { START_HOOK(PLAYER_EVENT_ON_FIRST_LOGIN); HookPush(pPlayer); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnRepop(Player* pPlayer) { START_HOOK(PLAYER_EVENT_ON_REPOP); HookPush(pPlayer); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnResurrect(Player* pPlayer) { START_HOOK(PLAYER_EVENT_ON_RESURRECT); HookPush(pPlayer); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnQuestAbandon(Player* pPlayer, uint32 questId) @@ -141,7 +143,7 @@ void Eluna::OnQuestAbandon(Player* pPlayer, uint32 questId) START_HOOK(PLAYER_EVENT_ON_QUEST_ABANDON); HookPush(pPlayer); HookPush(questId); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnQuestStatusChanged(Player* pPlayer, uint32 questId, uint8 status) @@ -150,7 +152,7 @@ void Eluna::OnQuestStatusChanged(Player* pPlayer, uint32 questId, uint8 status) HookPush(pPlayer); HookPush(questId); HookPush(status); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnEquip(Player* pPlayer, Item* pItem, uint8 bag, uint8 slot) @@ -160,7 +162,7 @@ void Eluna::OnEquip(Player* pPlayer, Item* pItem, uint8 bag, uint8 slot) HookPush(pItem); HookPush(bag); HookPush(slot); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } InventoryResult Eluna::OnCanUseItem(const Player* pPlayer, uint32 itemEntry) @@ -169,7 +171,7 @@ InventoryResult Eluna::OnCanUseItem(const Player* pPlayer, uint32 itemEntry) InventoryResult result = EQUIP_ERR_OK; HookPush(pPlayer); HookPush(itemEntry); - int n = SetupStack(PlayerEventBindings, key, 2); + int n = SetupStack(binding, key, 2); while (n > 0) { @@ -189,14 +191,14 @@ void Eluna::OnPlayerEnterCombat(Player* pPlayer, Unit* pEnemy) START_HOOK(PLAYER_EVENT_ON_ENTER_COMBAT); HookPush(pPlayer); HookPush(pEnemy); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnPlayerLeaveCombat(Player* pPlayer) { START_HOOK(PLAYER_EVENT_ON_LEAVE_COMBAT); HookPush(pPlayer); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnPVPKill(Player* pKiller, Player* pKilled) @@ -204,7 +206,7 @@ void Eluna::OnPVPKill(Player* pKiller, Player* pKilled) START_HOOK(PLAYER_EVENT_ON_KILL_PLAYER); HookPush(pKiller); HookPush(pKilled); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnCreatureKill(Player* pKiller, Creature* pKilled) @@ -212,7 +214,7 @@ void Eluna::OnCreatureKill(Player* pKiller, Creature* pKilled) START_HOOK(PLAYER_EVENT_ON_KILL_CREATURE); HookPush(pKiller); HookPush(pKilled); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnPlayerKilledByCreature(Creature* pKiller, Player* pKilled) @@ -220,7 +222,7 @@ void Eluna::OnPlayerKilledByCreature(Creature* pKiller, Player* pKilled) START_HOOK(PLAYER_EVENT_ON_KILLED_BY_CREATURE); HookPush(pKiller); HookPush(pKilled); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnPlayerKilledByEnvironment(Player* pKilled, uint8 damageType) @@ -228,7 +230,7 @@ void Eluna::OnPlayerKilledByEnvironment(Player* pKilled, uint8 damageType) START_HOOK(PLAYER_EVENT_ON_ENVIRONMENTAL_DEATH); HookPush(pKilled); HookPush(damageType); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnLevelChanged(Player* pPlayer, uint8 oldLevel) @@ -236,7 +238,7 @@ void Eluna::OnLevelChanged(Player* pPlayer, uint8 oldLevel) START_HOOK(PLAYER_EVENT_ON_LEVEL_CHANGE); HookPush(pPlayer); HookPush(oldLevel); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnFreeTalentPointsChanged(Player* pPlayer, uint32 newPoints) @@ -244,7 +246,7 @@ void Eluna::OnFreeTalentPointsChanged(Player* pPlayer, uint32 newPoints) START_HOOK(PLAYER_EVENT_ON_TALENTS_CHANGE); HookPush(pPlayer); HookPush(newPoints); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnTalentsReset(Player* pPlayer, bool noCost) @@ -252,7 +254,7 @@ void Eluna::OnTalentsReset(Player* pPlayer, bool noCost) START_HOOK(PLAYER_EVENT_ON_TALENTS_RESET); HookPush(pPlayer); HookPush(noCost); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnMoneyChanged(Player* pPlayer, int32& amount) @@ -261,7 +263,7 @@ void Eluna::OnMoneyChanged(Player* pPlayer, int32& amount) HookPush(pPlayer); HookPush(amount); int amountIndex = lua_gettop(L); - int n = SetupStack(PlayerEventBindings, key, 2); + int n = SetupStack(binding, key, 2); while (n > 0) { @@ -287,7 +289,7 @@ void Eluna::OnMoneyChanged(Player* pPlayer, int64& amount) HookPush(pPlayer); HookPush(amount); int amountIndex = lua_gettop(L); - int n = SetupStack(PlayerEventBindings, key, 2); + int n = SetupStack(binding, key, 2); while (n > 0) { @@ -314,7 +316,7 @@ void Eluna::OnGiveXP(Player* pPlayer, uint32& amount, Unit* pVictim) HookPush(amount); HookPush(pVictim); int amountIndex = lua_gettop(L) - 1; - int n = SetupStack(PlayerEventBindings, key, 3); + int n = SetupStack(binding, key, 3); while (n > 0) { @@ -341,7 +343,7 @@ void Eluna::OnReputationChange(Player* pPlayer, uint32 factionID, int32& standin HookPush(standing); HookPush(incremental); int standingIndex = lua_gettop(L) - 1; - int n = SetupStack(PlayerEventBindings, key, 4); + int n = SetupStack(binding, key, 4); while (n > 0) { @@ -365,7 +367,7 @@ void Eluna::OnDuelRequest(Player* pTarget, Player* pChallenger) START_HOOK(PLAYER_EVENT_ON_DUEL_REQUEST); HookPush(pTarget); HookPush(pChallenger); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnDuelStart(Player* pStarter, Player* pChallenger) @@ -373,7 +375,7 @@ void Eluna::OnDuelStart(Player* pStarter, Player* pChallenger) START_HOOK(PLAYER_EVENT_ON_DUEL_START); HookPush(pStarter); HookPush(pChallenger); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnDuelEnd(Player* pWinner, Player* pLoser, DuelCompleteType type) @@ -382,7 +384,7 @@ void Eluna::OnDuelEnd(Player* pWinner, Player* pLoser, DuelCompleteType type) HookPush(pWinner); HookPush(pLoser); HookPush(type); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnEmote(Player* pPlayer, uint32 emote) @@ -390,7 +392,7 @@ void Eluna::OnEmote(Player* pPlayer, uint32 emote) START_HOOK(PLAYER_EVENT_ON_EMOTE); HookPush(pPlayer); HookPush(emote); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnTextEmote(Player* pPlayer, uint32 textEmote, uint32 emoteNum, ObjectGuid guid) @@ -400,7 +402,7 @@ void Eluna::OnTextEmote(Player* pPlayer, uint32 textEmote, uint32 emoteNum, Obje HookPush(textEmote); HookPush(emoteNum); HookPush(guid); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnSpellCast(Player* pPlayer, Spell* pSpell, bool skipCheck) @@ -409,42 +411,42 @@ void Eluna::OnSpellCast(Player* pPlayer, Spell* pSpell, bool skipCheck) HookPush(pPlayer); HookPush(pSpell); HookPush(skipCheck); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnLogin(Player* pPlayer) { START_HOOK(PLAYER_EVENT_ON_LOGIN); HookPush(pPlayer); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnLogout(Player* pPlayer) { START_HOOK(PLAYER_EVENT_ON_LOGOUT); HookPush(pPlayer); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnCreate(Player* pPlayer) { START_HOOK(PLAYER_EVENT_ON_CHARACTER_CREATE); HookPush(pPlayer); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnDelete(uint32 guidlow) { START_HOOK(PLAYER_EVENT_ON_CHARACTER_DELETE); HookPush(guidlow); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnSave(Player* pPlayer) { START_HOOK(PLAYER_EVENT_ON_SAVE); HookPush(pPlayer); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnBindToInstance(Player* pPlayer, Difficulty difficulty, uint32 mapid, bool permanent) @@ -454,7 +456,7 @@ void Eluna::OnBindToInstance(Player* pPlayer, Difficulty difficulty, uint32 mapi HookPush(difficulty); HookPush(mapid); HookPush(permanent); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea) @@ -463,7 +465,7 @@ void Eluna::OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea) HookPush(pPlayer); HookPush(newZone); HookPush(newArea); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnUpdateArea(Player* pPlayer, uint32 oldArea, uint32 newArea) @@ -472,14 +474,14 @@ void Eluna::OnUpdateArea(Player* pPlayer, uint32 oldArea, uint32 newArea) HookPush(pPlayer); HookPush(oldArea); HookPush(newArea); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnMapChanged(Player* player) { START_HOOK(PLAYER_EVENT_ON_MAP_CHANGE); HookPush(player); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnAchievementComplete(Player* player, uint32 achievementId) @@ -487,7 +489,7 @@ void Eluna::OnAchievementComplete(Player* player, uint32 achievementId) START_HOOK(PLAYER_EVENT_ON_ACHIEVEMENT_COMPLETE); HookPush(player); HookPush(achievementId); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } bool Eluna::OnTradeInit(Player* trader, Player* tradee) @@ -495,7 +497,7 @@ bool Eluna::OnTradeInit(Player* trader, Player* tradee) START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_TRADE_INIT, true); HookPush(trader); HookPush(tradee); - return CallAllFunctionsBool(PlayerEventBindings, key, true); + return CallAllFunctionsBool(binding, key, true); } bool Eluna::OnTradeAccept(Player* trader, Player* tradee) @@ -503,7 +505,7 @@ bool Eluna::OnTradeAccept(Player* trader, Player* tradee) START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_TRADE_ACCEPT, true); HookPush(trader); HookPush(tradee); - return CallAllFunctionsBool(PlayerEventBindings, key, true); + return CallAllFunctionsBool(binding, key, true); } bool Eluna::OnSendMail(Player* sender, ObjectGuid recipientGuid) @@ -511,7 +513,7 @@ bool Eluna::OnSendMail(Player* sender, ObjectGuid recipientGuid) START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_SEND_MAIL, true); HookPush(sender); HookPush(recipientGuid); - return CallAllFunctionsBool(PlayerEventBindings, key, true); + return CallAllFunctionsBool(binding, key, true); } void Eluna::OnDiscoverArea(Player* player, uint32 area) @@ -519,7 +521,7 @@ void Eluna::OnDiscoverArea(Player* player, uint32 area) START_HOOK(PLAYER_EVENT_ON_DISCOVER_AREA); HookPush(player); HookPush(area); - CallAllFunctions(PlayerEventBindings, key); + CallAllFunctions(binding, key); } bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg) @@ -533,7 +535,7 @@ bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg) HookPush(msg); HookPush(type); HookPush(lang); - int n = SetupStack(PlayerEventBindings, key, 4); + int n = SetupStack(binding, key, 4); while (n > 0) { @@ -564,7 +566,7 @@ bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, HookPush(type); HookPush(lang); HookPush(pGroup); - int n = SetupStack(PlayerEventBindings, key, 5); + int n = SetupStack(binding, key, 5); while (n > 0) { @@ -595,7 +597,7 @@ bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, HookPush(type); HookPush(lang); HookPush(pGuild); - int n = SetupStack(PlayerEventBindings, key, 5); + int n = SetupStack(binding, key, 5); while (n > 0) { @@ -626,7 +628,7 @@ bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, HookPush(type); HookPush(lang); HookPush(pChannel->GetChannelId()); - int n = SetupStack(PlayerEventBindings, key, 5); + int n = SetupStack(binding, key, 5); while (n > 0) { @@ -657,7 +659,7 @@ bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, HookPush(type); HookPush(lang); HookPush(pReceiver); - int n = SetupStack(PlayerEventBindings, key, 5); + int n = SetupStack(binding, key, 5); while (n > 0) { diff --git a/hooks/ServerHooks.cpp b/hooks/ServerHooks.cpp index f1a4c5e145..46c979de55 100644 --- a/hooks/ServerHooks.cpp +++ b/hooks/ServerHooks.cpp @@ -15,13 +15,15 @@ using namespace Hooks; #define START_HOOK(EVENT) \ + auto binding = GetBinding>(REGTYPE_SERVER);\ auto key = EventKey(EVENT);\ - if (!ServerEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return; #define START_HOOK_WITH_RETVAL(EVENT, RETVAL) \ + auto binding = GetBinding>(REGTYPE_SERVER);\ auto key = EventKey(EVENT);\ - if (!ServerEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return RETVAL; bool Eluna::OnAddonMessage(Player* sender, uint32 type, std::string& msg, Player* receiver, Guild* guild, Group* group, Channel* channel) @@ -55,7 +57,7 @@ bool Eluna::OnAddonMessage(Player* sender, uint32 type, std::string& msg, Player else HookPush(); - return CallAllFunctionsBool(ServerEventBindings, key, true); + return CallAllFunctionsBool(binding, key, true); } void Eluna::OnTimedEvent(int funcRef, uint32 delay, uint32 calls, WorldObject* obj) @@ -84,26 +86,26 @@ void Eluna::OnGameEventStart(uint32 eventid) { START_HOOK(GAME_EVENT_START); HookPush(eventid); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnGameEventStop(uint32 eventid) { START_HOOK(GAME_EVENT_STOP); HookPush(eventid); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnLuaStateClose() { START_HOOK(ELUNA_EVENT_ON_LUA_STATE_CLOSE); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnLuaStateOpen() { START_HOOK(ELUNA_EVENT_ON_LUA_STATE_OPEN); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } // AreaTrigger @@ -117,7 +119,7 @@ bool Eluna::OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* pTrigger) HookPush(pTrigger->id); #endif - return CallAllFunctionsBool(ServerEventBindings, key); + return CallAllFunctionsBool(binding, key); } // Weather @@ -127,7 +129,7 @@ void Eluna::OnChange(Weather* /*weather*/, uint32 zone, WeatherState state, floa HookPush(zone); HookPush(state); HookPush(grade); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } // Auction House @@ -155,7 +157,7 @@ void Eluna::OnAdd(AuctionHouseObject* /*ah*/, AuctionEntry* entry) HookPush(entry->startbid); HookPush(entry->bid); HookPush(entry->bidder); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnRemove(AuctionHouseObject* /*ah*/, AuctionEntry* entry) @@ -183,7 +185,7 @@ void Eluna::OnRemove(AuctionHouseObject* /*ah*/, AuctionEntry* entry) HookPush(entry->startbid); HookPush(entry->bid); HookPush(entry->bidder); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnSuccessful(AuctionHouseObject* /*ah*/, AuctionEntry* entry) @@ -210,7 +212,7 @@ void Eluna::OnSuccessful(AuctionHouseObject* /*ah*/, AuctionEntry* entry) HookPush(entry->startbid); HookPush(entry->bid); HookPush(entry->bidder); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnExpire(AuctionHouseObject* /*ah*/, AuctionEntry* entry) @@ -237,21 +239,21 @@ void Eluna::OnExpire(AuctionHouseObject* /*ah*/, AuctionEntry* entry) HookPush(entry->startbid); HookPush(entry->bid); HookPush(entry->bidder); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnOpenStateChange(bool open) { START_HOOK(WORLD_EVENT_ON_OPEN_STATE_CHANGE); HookPush(open); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnConfigLoad(bool reload) { START_HOOK(WORLD_EVENT_ON_CONFIG_LOAD); HookPush(reload); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask) @@ -259,32 +261,32 @@ void Eluna::OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask) START_HOOK(WORLD_EVENT_ON_SHUTDOWN_INIT); HookPush(code); HookPush(mask); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnShutdownCancel() { START_HOOK(WORLD_EVENT_ON_SHUTDOWN_CANCEL); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnWorldUpdate(uint32 diff) { START_HOOK(WORLD_EVENT_ON_UPDATE); HookPush(diff); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnStartup() { START_HOOK(WORLD_EVENT_ON_STARTUP); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnShutdown() { START_HOOK(WORLD_EVENT_ON_SHUTDOWN); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } /* Map */ @@ -292,14 +294,14 @@ void Eluna::OnCreate(Map* map) { START_HOOK(MAP_EVENT_ON_CREATE); HookPush(map); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnDestroy(Map* map) { START_HOOK(MAP_EVENT_ON_DESTROY); HookPush(map); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnPlayerEnter(Map* map, Player* player) @@ -307,7 +309,7 @@ void Eluna::OnPlayerEnter(Map* map, Player* player) START_HOOK(MAP_EVENT_ON_PLAYER_ENTER); HookPush(map); HookPush(player); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnPlayerLeave(Map* map, Player* player) @@ -315,7 +317,7 @@ void Eluna::OnPlayerLeave(Map* map, Player* player) START_HOOK(MAP_EVENT_ON_PLAYER_LEAVE); HookPush(map); HookPush(player); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnMapUpdate(Map* map, uint32 diff) @@ -323,19 +325,19 @@ void Eluna::OnMapUpdate(Map* map, uint32 diff) START_HOOK(MAP_EVENT_ON_UPDATE); HookPush(map); HookPush(diff); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnRemove(GameObject* gameobject) { START_HOOK(WORLD_EVENT_ON_DELETE_GAMEOBJECT); HookPush(gameobject); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnRemove(Creature* creature) { START_HOOK(WORLD_EVENT_ON_DELETE_CREATURE); HookPush(creature); - CallAllFunctions(ServerEventBindings, key); + CallAllFunctions(binding, key); } diff --git a/hooks/SpellHooks.cpp b/hooks/SpellHooks.cpp index f377078f21..a5ef8a30a6 100644 --- a/hooks/SpellHooks.cpp +++ b/hooks/SpellHooks.cpp @@ -14,13 +14,15 @@ using namespace Hooks; #define START_HOOK(EVENT, SPELL) \ + auto binding = GetBinding>(REGTYPE_SPELL);\ auto key = EntryKey(EVENT, SPELL->m_spellInfo->Id);\ - if (!SpellEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return; #define START_HOOK_WITH_RETVAL(EVENT, SPELL, RETVAL) \ + auto binding = GetBinding>(REGTYPE_SPELL);\ auto key = EntryKey(EVENT, SPELL->m_spellInfo->Id);\ - if (!SpellEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return RETVAL; void Eluna::OnSpellCast(Spell* pSpell, bool skipCheck) @@ -28,5 +30,5 @@ void Eluna::OnSpellCast(Spell* pSpell, bool skipCheck) START_HOOK(SPELL_EVENT_ON_CAST, pSpell); HookPush(pSpell); HookPush(skipCheck); - CallAllFunctions(SpellEventBindings, key); + CallAllFunctions(binding, key); } diff --git a/hooks/VehicleHooks.cpp b/hooks/VehicleHooks.cpp index 932f6baea3..3bbc6d5024 100644 --- a/hooks/VehicleHooks.cpp +++ b/hooks/VehicleHooks.cpp @@ -15,22 +15,23 @@ using namespace Hooks; #define START_HOOK(EVENT) \ + auto binding = GetBinding>(REGTYPE_VEHICLE);\ auto key = EventKey(EVENT);\ - if (!VehicleEventBindings->HasBindingsFor(key))\ + if (!binding->HasBindingsFor(key))\ return; void Eluna::OnInstall(Vehicle* vehicle) { START_HOOK(VEHICLE_EVENT_ON_INSTALL); HookPush(vehicle); - CallAllFunctions(VehicleEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnUninstall(Vehicle* vehicle) { START_HOOK(VEHICLE_EVENT_ON_UNINSTALL); HookPush(vehicle); - CallAllFunctions(VehicleEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnInstallAccessory(Vehicle* vehicle, Creature* accessory) @@ -38,7 +39,7 @@ void Eluna::OnInstallAccessory(Vehicle* vehicle, Creature* accessory) START_HOOK(VEHICLE_EVENT_ON_INSTALL_ACCESSORY); HookPush(vehicle); HookPush(accessory); - CallAllFunctions(VehicleEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnAddPassenger(Vehicle* vehicle, Unit* passenger, int8 seatId) @@ -47,7 +48,7 @@ void Eluna::OnAddPassenger(Vehicle* vehicle, Unit* passenger, int8 seatId) HookPush(vehicle); HookPush(passenger); HookPush(seatId); - CallAllFunctions(VehicleEventBindings, key); + CallAllFunctions(binding, key); } void Eluna::OnRemovePassenger(Vehicle* vehicle, Unit* passenger) @@ -55,7 +56,7 @@ void Eluna::OnRemovePassenger(Vehicle* vehicle, Unit* passenger) START_HOOK(VEHICLE_EVENT_ON_REMOVE_PASSENGER); HookPush(vehicle); HookPush(passenger); - CallAllFunctions(VehicleEventBindings, key); + CallAllFunctions(binding, key); } #endif diff --git a/methods/CMangos/GlobalMethods.h b/methods/CMangos/GlobalMethods.h index ed725b701d..13e08024c4 100644 --- a/methods/CMangos/GlobalMethods.h +++ b/methods/CMangos/GlobalMethods.h @@ -1200,7 +1200,7 @@ namespace LuaGlobalFunctions */ int RegisterUniqueCreatureEvent(Eluna* E) { - return RegisterUniqueHelper(E, Hooks::REGTYPE_CREATURE); + return RegisterUniqueHelper(E, Hooks::REGTYPE_CREATURE_UNIQUE); } /** @@ -2686,15 +2686,16 @@ namespace LuaGlobalFunctions int ClearBattleGroundEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_BG); if (lua_isnoneornil(E->L, 1)) { - E->BGEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->BGEventBindings->Clear(Key((Hooks::BGEvents)event_type)); + binding->Clear(Key((Hooks::BGEvents)event_type)); } return 0; } @@ -2717,19 +2718,20 @@ namespace LuaGlobalFunctions int ClearCreatureEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_CREATURE); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::CREATURE_EVENT_COUNT; ++i) - E->CreatureEventBindings->Clear(Key((Hooks::CreatureEvents)i, entry)); + binding->Clear(Key((Hooks::CreatureEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->CreatureEventBindings->Clear(Key((Hooks::CreatureEvents)event_type, entry)); + binding->Clear(Key((Hooks::CreatureEvents)event_type, entry)); } return 0; } @@ -2753,6 +2755,7 @@ namespace LuaGlobalFunctions int ClearUniqueCreatureEvents(Eluna* E) { typedef UniqueObjectKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_CREATURE_UNIQUE); if (lua_isnoneornil(E->L, 3)) { @@ -2760,14 +2763,14 @@ namespace LuaGlobalFunctions uint32 instanceId = E->CHECKVAL(2); for (uint32 i = 1; i < Hooks::CREATURE_EVENT_COUNT; ++i) - E->CreatureUniqueBindings->Clear(Key((Hooks::CreatureEvents)i, guid, instanceId)); + binding->Clear(Key((Hooks::CreatureEvents)i, guid, instanceId)); } else { ObjectGuid guid = E->CHECKVAL(1); uint32 instanceId = E->CHECKVAL(2); uint32 event_type = E->CHECKVAL(3); - E->CreatureUniqueBindings->Clear(Key((Hooks::CreatureEvents)event_type, guid, instanceId)); + binding->Clear(Key((Hooks::CreatureEvents)event_type, guid, instanceId)); } return 0; } @@ -2790,19 +2793,20 @@ namespace LuaGlobalFunctions int ClearCreatureGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_CREATURE_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->CreatureGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->CreatureGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -2825,19 +2829,20 @@ namespace LuaGlobalFunctions int ClearGameObjectEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GAMEOBJECT); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::GAMEOBJECT_EVENT_COUNT; ++i) - E->GameObjectEventBindings->Clear(Key((Hooks::GameObjectEvents)i, entry)); + binding->Clear(Key((Hooks::GameObjectEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->GameObjectEventBindings->Clear(Key((Hooks::GameObjectEvents)event_type, entry)); + binding->Clear(Key((Hooks::GameObjectEvents)event_type, entry)); } return 0; } @@ -2860,19 +2865,20 @@ namespace LuaGlobalFunctions int ClearGameObjectGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GAMEOBJECT_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->GameObjectGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->GameObjectGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -2891,15 +2897,16 @@ namespace LuaGlobalFunctions int ClearGroupEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GROUP); if (lua_isnoneornil(E->L, 1)) { - E->GroupEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->GroupEventBindings->Clear(Key((Hooks::GroupEvents)event_type)); + binding->Clear(Key((Hooks::GroupEvents)event_type)); } return 0; } @@ -2918,15 +2925,16 @@ namespace LuaGlobalFunctions int ClearGuildEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GUILD); if (lua_isnoneornil(E->L, 1)) { - E->GuildEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->GuildEventBindings->Clear(Key((Hooks::GuildEvents)event_type)); + binding->Clear(Key((Hooks::GuildEvents)event_type)); } return 0; } @@ -2949,19 +2957,20 @@ namespace LuaGlobalFunctions int ClearItemEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_ITEM); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::ITEM_EVENT_COUNT; ++i) - E->ItemEventBindings->Clear(Key((Hooks::ItemEvents)i, entry)); + binding->Clear(Key((Hooks::ItemEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->ItemEventBindings->Clear(Key((Hooks::ItemEvents)event_type, entry)); + binding->Clear(Key((Hooks::ItemEvents)event_type, entry)); } return 0; } @@ -2984,19 +2993,20 @@ namespace LuaGlobalFunctions int ClearItemGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_ITEM_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->ItemGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->ItemGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -3016,19 +3026,20 @@ namespace LuaGlobalFunctions int ClearPacketEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_PACKET); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::PACKET_EVENT_COUNT; ++i) - E->PacketEventBindings->Clear(Key((Hooks::PacketEvents)i, entry)); + binding->Clear(Key((Hooks::PacketEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->PacketEventBindings->Clear(Key((Hooks::PacketEvents)event_type, entry)); + binding->Clear(Key((Hooks::PacketEvents)event_type, entry)); } return 0; } @@ -3047,15 +3058,16 @@ namespace LuaGlobalFunctions int ClearPlayerEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_PLAYER); if (lua_isnoneornil(E->L, 1)) { - E->PlayerEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->PlayerEventBindings->Clear(Key((Hooks::PlayerEvents)event_type)); + binding->Clear(Key((Hooks::PlayerEvents)event_type)); } return 0; } @@ -3075,19 +3087,20 @@ namespace LuaGlobalFunctions int ClearPlayerGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_PLAYER_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->PlayerGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->PlayerGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -3106,15 +3119,16 @@ namespace LuaGlobalFunctions int ClearServerEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_SERVER); if (lua_isnoneornil(E->L, 1)) { - E->ServerEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->ServerEventBindings->Clear(Key((Hooks::ServerEvents)event_type)); + binding->Clear(Key((Hooks::ServerEvents)event_type)); } return 0; } @@ -3134,19 +3148,20 @@ namespace LuaGlobalFunctions int ClearMapEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_MAP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::INSTANCE_EVENT_COUNT; ++i) - E->MapEventBindings->Clear(Key((Hooks::InstanceEvents)i, entry)); + binding->Clear(Key((Hooks::InstanceEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->MapEventBindings->Clear(Key((Hooks::InstanceEvents)event_type, entry)); + binding->Clear(Key((Hooks::InstanceEvents)event_type, entry)); } return 0; @@ -3167,19 +3182,20 @@ namespace LuaGlobalFunctions int ClearInstanceEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_INSTANCE); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::INSTANCE_EVENT_COUNT; ++i) - E->InstanceEventBindings->Clear(Key((Hooks::InstanceEvents)i, entry)); + binding->Clear(Key((Hooks::InstanceEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->InstanceEventBindings->Clear(Key((Hooks::InstanceEvents)event_type, entry)); + binding->Clear(Key((Hooks::InstanceEvents)event_type, entry)); } return 0; diff --git a/methods/Mangos/GlobalMethods.h b/methods/Mangos/GlobalMethods.h index 0260a75d39..1aeabfa98d 100644 --- a/methods/Mangos/GlobalMethods.h +++ b/methods/Mangos/GlobalMethods.h @@ -1128,7 +1128,7 @@ namespace LuaGlobalFunctions */ int RegisterUniqueCreatureEvent(Eluna* E) { - return RegisterUniqueHelper(E, Hooks::REGTYPE_CREATURE); + return RegisterUniqueHelper(E, Hooks::REGTYPE_CREATURE_UNIQUE); } /** @@ -2443,15 +2443,16 @@ namespace LuaGlobalFunctions int ClearBattleGroundEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_BG); if (lua_isnoneornil(E->L, 1)) { - E->BGEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->BGEventBindings->Clear(Key((Hooks::BGEvents)event_type)); + binding->Clear(Key((Hooks::BGEvents)event_type)); } return 0; } @@ -2474,18 +2475,20 @@ namespace LuaGlobalFunctions int ClearCreatureEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_CREATURE); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); + for (uint32 i = 1; i < Hooks::CREATURE_EVENT_COUNT; ++i) - E->CreatureEventBindings->Clear(Key((Hooks::CreatureEvents)i, entry)); + binding->Clear(Key((Hooks::CreatureEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->CreatureEventBindings->Clear(Key((Hooks::CreatureEvents)event_type, entry)); + binding->Clear(Key((Hooks::CreatureEvents)event_type, entry)); } return 0; } @@ -2509,20 +2512,22 @@ namespace LuaGlobalFunctions int ClearUniqueCreatureEvents(Eluna* E) { typedef UniqueObjectKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_CREATURE_UNIQUE); if (lua_isnoneornil(E->L, 3)) { ObjectGuid guid = E->CHECKVAL(1); uint32 instanceId = E->CHECKVAL(2); + for (uint32 i = 1; i < Hooks::CREATURE_EVENT_COUNT; ++i) - E->CreatureUniqueBindings->Clear(Key((Hooks::CreatureEvents)i, guid, instanceId)); + binding->Clear(Key((Hooks::CreatureEvents)i, guid, instanceId)); } else { ObjectGuid guid = E->CHECKVAL(1); uint32 instanceId = E->CHECKVAL(2); uint32 event_type = E->CHECKVAL(3); - E->CreatureUniqueBindings->Clear(Key((Hooks::CreatureEvents)event_type, guid, instanceId)); + binding->Clear(Key((Hooks::CreatureEvents)event_type, guid, instanceId)); } return 0; } @@ -2545,18 +2550,20 @@ namespace LuaGlobalFunctions int ClearCreatureGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_CREATURE_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); + for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->CreatureGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->CreatureGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -2579,18 +2586,20 @@ namespace LuaGlobalFunctions int ClearGameObjectEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GAMEOBJECT); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); + for (uint32 i = 1; i < Hooks::GAMEOBJECT_EVENT_COUNT; ++i) - E->GameObjectEventBindings->Clear(Key((Hooks::GameObjectEvents)i, entry)); + binding->Clear(Key((Hooks::GameObjectEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->GameObjectEventBindings->Clear(Key((Hooks::GameObjectEvents)event_type, entry)); + binding->Clear(Key((Hooks::GameObjectEvents)event_type, entry)); } return 0; } @@ -2613,18 +2622,20 @@ namespace LuaGlobalFunctions int ClearGameObjectGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GAMEOBJECT_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); + for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->GameObjectGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->GameObjectGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -2643,15 +2654,16 @@ namespace LuaGlobalFunctions int ClearGroupEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GROUP); if (lua_isnoneornil(E->L, 1)) { - E->GroupEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->GroupEventBindings->Clear(Key((Hooks::GroupEvents)event_type)); + binding->Clear(Key((Hooks::GroupEvents)event_type)); } return 0; } @@ -2670,15 +2682,16 @@ namespace LuaGlobalFunctions int ClearGuildEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GUILD); if (lua_isnoneornil(E->L, 1)) { - E->GuildEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->GuildEventBindings->Clear(Key((Hooks::GuildEvents)event_type)); + binding->Clear(Key((Hooks::GuildEvents)event_type)); } return 0; } @@ -2701,18 +2714,20 @@ namespace LuaGlobalFunctions int ClearItemEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_ITEM); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); + for (uint32 i = 1; i < Hooks::ITEM_EVENT_COUNT; ++i) - E->ItemEventBindings->Clear(Key((Hooks::ItemEvents)i, entry)); + binding->Clear(Key((Hooks::ItemEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->ItemEventBindings->Clear(Key((Hooks::ItemEvents)event_type, entry)); + binding->Clear(Key((Hooks::ItemEvents)event_type, entry)); } return 0; } @@ -2735,18 +2750,20 @@ namespace LuaGlobalFunctions int ClearItemGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_ITEM_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); + for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->ItemGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->ItemGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -2766,18 +2783,20 @@ namespace LuaGlobalFunctions int ClearPacketEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_PACKET); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); + for (uint32 i = 1; i < Hooks::PACKET_EVENT_COUNT; ++i) - E->PacketEventBindings->Clear(Key((Hooks::PacketEvents)i, entry)); + binding->Clear(Key((Hooks::PacketEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->PacketEventBindings->Clear(Key((Hooks::PacketEvents)event_type, entry)); + binding->Clear(Key((Hooks::PacketEvents)event_type, entry)); } return 0; } @@ -2796,15 +2815,16 @@ namespace LuaGlobalFunctions int ClearPlayerEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_PLAYER); if (lua_isnoneornil(E->L, 1)) { - E->PlayerEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->PlayerEventBindings->Clear(Key((Hooks::PlayerEvents)event_type)); + binding->Clear(Key((Hooks::PlayerEvents)event_type)); } return 0; } @@ -2824,18 +2844,20 @@ namespace LuaGlobalFunctions int ClearPlayerGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_PLAYER_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); + for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->PlayerGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->PlayerGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -2854,15 +2876,16 @@ namespace LuaGlobalFunctions int ClearServerEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_SERVER); if (lua_isnoneornil(E->L, 1)) { - E->ServerEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->ServerEventBindings->Clear(Key((Hooks::ServerEvents)event_type)); + binding->Clear(Key((Hooks::ServerEvents)event_type)); } return 0; } @@ -2882,18 +2905,20 @@ namespace LuaGlobalFunctions int ClearMapEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_MAP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); + for (uint32 i = 1; i < Hooks::INSTANCE_EVENT_COUNT; ++i) - E->MapEventBindings->Clear(Key((Hooks::InstanceEvents)i, entry)); + binding->Clear(Key((Hooks::InstanceEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->MapEventBindings->Clear(Key((Hooks::InstanceEvents)event_type, entry)); + binding->Clear(Key((Hooks::InstanceEvents)event_type, entry)); } return 0; @@ -2914,18 +2939,20 @@ namespace LuaGlobalFunctions int ClearInstanceEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_INSTANCE); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); + for (uint32 i = 1; i < Hooks::INSTANCE_EVENT_COUNT; ++i) - E->InstanceEventBindings->Clear(Key((Hooks::InstanceEvents)i, entry)); + binding->Clear(Key((Hooks::InstanceEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->InstanceEventBindings->Clear(Key((Hooks::InstanceEvents)event_type, entry)); + binding->Clear(Key((Hooks::InstanceEvents)event_type, entry)); } return 0; diff --git a/methods/TrinityCore/GlobalMethods.h b/methods/TrinityCore/GlobalMethods.h index fa150f7281..758803736a 100644 --- a/methods/TrinityCore/GlobalMethods.h +++ b/methods/TrinityCore/GlobalMethods.h @@ -1157,7 +1157,7 @@ namespace LuaGlobalFunctions */ int RegisterUniqueCreatureEvent(Eluna* E) { - return RegisterUniqueHelper(E, Hooks::REGTYPE_CREATURE); + return RegisterUniqueHelper(E, Hooks::REGTYPE_CREATURE_UNIQUE); } /** @@ -2568,15 +2568,16 @@ namespace LuaGlobalFunctions int ClearBattleGroundEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_BG); if (lua_isnoneornil(E->L, 1)) { - E->BGEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->BGEventBindings->Clear(Key((Hooks::BGEvents)event_type)); + binding->Clear(Key((Hooks::BGEvents)event_type)); } return 0; } @@ -2599,19 +2600,20 @@ namespace LuaGlobalFunctions int ClearCreatureEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_CREATURE); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::CREATURE_EVENT_COUNT; ++i) - E->CreatureEventBindings->Clear(Key((Hooks::CreatureEvents)i, entry)); + binding->Clear(Key((Hooks::CreatureEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->CreatureEventBindings->Clear(Key((Hooks::CreatureEvents)event_type, entry)); + binding->Clear(Key((Hooks::CreatureEvents)event_type, entry)); } return 0; } @@ -2635,6 +2637,7 @@ namespace LuaGlobalFunctions int ClearUniqueCreatureEvents(Eluna* E) { typedef UniqueObjectKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_CREATURE_UNIQUE); if (lua_isnoneornil(E->L, 3)) { @@ -2642,14 +2645,14 @@ namespace LuaGlobalFunctions uint32 instanceId = E->CHECKVAL(2); for (uint32 i = 1; i < Hooks::CREATURE_EVENT_COUNT; ++i) - E->CreatureUniqueBindings->Clear(Key((Hooks::CreatureEvents)i, guid, instanceId)); + binding->Clear(Key((Hooks::CreatureEvents)i, guid, instanceId)); } else { ObjectGuid guid = E->CHECKVAL(1); uint32 instanceId = E->CHECKVAL(2); uint32 event_type = E->CHECKVAL(3); - E->CreatureUniqueBindings->Clear(Key((Hooks::CreatureEvents)event_type, guid, instanceId)); + binding->Clear(Key((Hooks::CreatureEvents)event_type, guid, instanceId)); } return 0; } @@ -2672,19 +2675,20 @@ namespace LuaGlobalFunctions int ClearCreatureGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_CREATURE_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->CreatureGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->CreatureGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -2707,19 +2711,20 @@ namespace LuaGlobalFunctions int ClearGameObjectEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GAMEOBJECT); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::GAMEOBJECT_EVENT_COUNT; ++i) - E->GameObjectEventBindings->Clear(Key((Hooks::GameObjectEvents)i, entry)); + binding->Clear(Key((Hooks::GameObjectEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->GameObjectEventBindings->Clear(Key((Hooks::GameObjectEvents)event_type, entry)); + binding->Clear(Key((Hooks::GameObjectEvents)event_type, entry)); } return 0; } @@ -2742,19 +2747,20 @@ namespace LuaGlobalFunctions int ClearGameObjectGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GAMEOBJECT_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->GameObjectGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->GameObjectGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -2773,15 +2779,16 @@ namespace LuaGlobalFunctions int ClearGroupEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GROUP); if (lua_isnoneornil(E->L, 1)) { - E->GroupEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->GroupEventBindings->Clear(Key((Hooks::GroupEvents)event_type)); + binding->Clear(Key((Hooks::GroupEvents)event_type)); } return 0; } @@ -2800,15 +2807,16 @@ namespace LuaGlobalFunctions int ClearGuildEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GUILD); if (lua_isnoneornil(E->L, 1)) { - E->GuildEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->GuildEventBindings->Clear(Key((Hooks::GuildEvents)event_type)); + binding->Clear(Key((Hooks::GuildEvents)event_type)); } return 0; } @@ -2831,19 +2839,20 @@ namespace LuaGlobalFunctions int ClearItemEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_ITEM); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::ITEM_EVENT_COUNT; ++i) - E->ItemEventBindings->Clear(Key((Hooks::ItemEvents)i, entry)); + binding->Clear(Key((Hooks::ItemEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->ItemEventBindings->Clear(Key((Hooks::ItemEvents)event_type, entry)); + binding->Clear(Key((Hooks::ItemEvents)event_type, entry)); } return 0; } @@ -2866,19 +2875,20 @@ namespace LuaGlobalFunctions int ClearItemGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_ITEM_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->ItemGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->ItemGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -2898,19 +2908,20 @@ namespace LuaGlobalFunctions int ClearPacketEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_PACKET); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::PACKET_EVENT_COUNT; ++i) - E->PacketEventBindings->Clear(Key((Hooks::PacketEvents)i, entry)); + binding->Clear(Key((Hooks::PacketEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->PacketEventBindings->Clear(Key((Hooks::PacketEvents)event_type, entry)); + binding->Clear(Key((Hooks::PacketEvents)event_type, entry)); } return 0; } @@ -2929,15 +2940,16 @@ namespace LuaGlobalFunctions int ClearPlayerEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_PLAYER); if (lua_isnoneornil(E->L, 1)) { - E->PlayerEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->PlayerEventBindings->Clear(Key((Hooks::PlayerEvents)event_type)); + binding->Clear(Key((Hooks::PlayerEvents)event_type)); } return 0; } @@ -2957,19 +2969,20 @@ namespace LuaGlobalFunctions int ClearPlayerGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_PLAYER_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->PlayerGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->PlayerGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -2988,15 +3001,16 @@ namespace LuaGlobalFunctions int ClearServerEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_SERVER); if (lua_isnoneornil(E->L, 1)) { - E->ServerEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->ServerEventBindings->Clear(Key((Hooks::ServerEvents)event_type)); + binding->Clear(Key((Hooks::ServerEvents)event_type)); } return 0; } @@ -3016,19 +3030,20 @@ namespace LuaGlobalFunctions int ClearMapEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_MAP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::INSTANCE_EVENT_COUNT; ++i) - E->MapEventBindings->Clear(Key((Hooks::InstanceEvents)i, entry)); + binding->Clear(Key((Hooks::InstanceEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->MapEventBindings->Clear(Key((Hooks::InstanceEvents)event_type, entry)); + binding->Clear(Key((Hooks::InstanceEvents)event_type, entry)); } return 0; @@ -3049,19 +3064,20 @@ namespace LuaGlobalFunctions int ClearInstanceEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_INSTANCE); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::INSTANCE_EVENT_COUNT; ++i) - E->InstanceEventBindings->Clear(Key((Hooks::InstanceEvents)i, entry)); + binding->Clear(Key((Hooks::InstanceEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->InstanceEventBindings->Clear(Key((Hooks::InstanceEvents)event_type, entry)); + binding->Clear(Key((Hooks::InstanceEvents)event_type, entry)); } return 0; diff --git a/methods/VMangos/GlobalMethods.h b/methods/VMangos/GlobalMethods.h index e7e55b54e9..b77ec26255 100644 --- a/methods/VMangos/GlobalMethods.h +++ b/methods/VMangos/GlobalMethods.h @@ -1130,7 +1130,7 @@ namespace LuaGlobalFunctions */ int RegisterUniqueCreatureEvent(Eluna* E) { - return RegisterUniqueHelper(E, Hooks::REGTYPE_CREATURE); + return RegisterUniqueHelper(E, Hooks::REGTYPE_CREATURE_UNIQUE); } /** @@ -2386,15 +2386,16 @@ namespace LuaGlobalFunctions int ClearBattleGroundEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_BG); if (lua_isnoneornil(E->L, 1)) { - E->BGEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->BGEventBindings->Clear(Key((Hooks::BGEvents)event_type)); + binding->Clear(Key((Hooks::BGEvents)event_type)); } return 0; } @@ -2417,19 +2418,20 @@ namespace LuaGlobalFunctions int ClearCreatureEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_CREATURE); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::CREATURE_EVENT_COUNT; ++i) - E->CreatureEventBindings->Clear(Key((Hooks::CreatureEvents)i, entry)); + binding->Clear(Key((Hooks::CreatureEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->CreatureEventBindings->Clear(Key((Hooks::CreatureEvents)event_type, entry)); + binding->Clear(Key((Hooks::CreatureEvents)event_type, entry)); } return 0; } @@ -2453,6 +2455,7 @@ namespace LuaGlobalFunctions int ClearUniqueCreatureEvents(Eluna* E) { typedef UniqueObjectKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_CREATURE_UNIQUE); if (lua_isnoneornil(E->L, 3)) { @@ -2460,14 +2463,14 @@ namespace LuaGlobalFunctions uint32 instanceId = E->CHECKVAL(2); for (uint32 i = 1; i < Hooks::CREATURE_EVENT_COUNT; ++i) - E->CreatureUniqueBindings->Clear(Key((Hooks::CreatureEvents)i, guid, instanceId)); + binding->Clear(Key((Hooks::CreatureEvents)i, guid, instanceId)); } else { ObjectGuid guid = E->CHECKVAL(1); uint32 instanceId = E->CHECKVAL(2); uint32 event_type = E->CHECKVAL(3); - E->CreatureUniqueBindings->Clear(Key((Hooks::CreatureEvents)event_type, guid, instanceId)); + binding->Clear(Key((Hooks::CreatureEvents)event_type, guid, instanceId)); } return 0; } @@ -2490,19 +2493,20 @@ namespace LuaGlobalFunctions int ClearCreatureGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_CREATURE_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->CreatureGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->CreatureGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -2525,19 +2529,20 @@ namespace LuaGlobalFunctions int ClearGameObjectEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GAMEOBJECT); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::GAMEOBJECT_EVENT_COUNT; ++i) - E->GameObjectEventBindings->Clear(Key((Hooks::GameObjectEvents)i, entry)); + binding->Clear(Key((Hooks::GameObjectEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->GameObjectEventBindings->Clear(Key((Hooks::GameObjectEvents)event_type, entry)); + binding->Clear(Key((Hooks::GameObjectEvents)event_type, entry)); } return 0; } @@ -2560,19 +2565,20 @@ namespace LuaGlobalFunctions int ClearGameObjectGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GAMEOBJECT_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->GameObjectGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->GameObjectGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -2591,15 +2597,16 @@ namespace LuaGlobalFunctions int ClearGroupEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GROUP); if (lua_isnoneornil(E->L, 1)) { - E->GroupEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->GroupEventBindings->Clear(Key((Hooks::GroupEvents)event_type)); + binding->Clear(Key((Hooks::GroupEvents)event_type)); } return 0; } @@ -2618,15 +2625,16 @@ namespace LuaGlobalFunctions int ClearGuildEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_GUILD); if (lua_isnoneornil(E->L, 1)) { - E->GuildEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->GuildEventBindings->Clear(Key((Hooks::GuildEvents)event_type)); + binding->Clear(Key((Hooks::GuildEvents)event_type)); } return 0; } @@ -2649,19 +2657,20 @@ namespace LuaGlobalFunctions int ClearItemEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_ITEM); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::ITEM_EVENT_COUNT; ++i) - E->ItemEventBindings->Clear(Key((Hooks::ItemEvents)i, entry)); + binding->Clear(Key((Hooks::ItemEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->ItemEventBindings->Clear(Key((Hooks::ItemEvents)event_type, entry)); + binding->Clear(Key((Hooks::ItemEvents)event_type, entry)); } return 0; } @@ -2684,19 +2693,20 @@ namespace LuaGlobalFunctions int ClearItemGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_ITEM_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->ItemGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->ItemGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -2716,19 +2726,20 @@ namespace LuaGlobalFunctions int ClearPacketEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_PACKET); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::PACKET_EVENT_COUNT; ++i) - E->PacketEventBindings->Clear(Key((Hooks::PacketEvents)i, entry)); + binding->Clear(Key((Hooks::PacketEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->PacketEventBindings->Clear(Key((Hooks::PacketEvents)event_type, entry)); + binding->Clear(Key((Hooks::PacketEvents)event_type, entry)); } return 0; } @@ -2747,15 +2758,16 @@ namespace LuaGlobalFunctions int ClearPlayerEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_PLAYER); if (lua_isnoneornil(E->L, 1)) { - E->PlayerEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->PlayerEventBindings->Clear(Key((Hooks::PlayerEvents)event_type)); + binding->Clear(Key((Hooks::PlayerEvents)event_type)); } return 0; } @@ -2775,19 +2787,20 @@ namespace LuaGlobalFunctions int ClearPlayerGossipEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_PLAYER_GOSSIP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->PlayerGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); + binding->Clear(Key((Hooks::GossipEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->PlayerGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); + binding->Clear(Key((Hooks::GossipEvents)event_type, entry)); } return 0; } @@ -2806,15 +2819,16 @@ namespace LuaGlobalFunctions int ClearServerEvents(Eluna* E) { typedef EventKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_SERVER); if (lua_isnoneornil(E->L, 1)) { - E->ServerEventBindings->Clear(); + binding->Clear(); } else { uint32 event_type = E->CHECKVAL(1); - E->ServerEventBindings->Clear(Key((Hooks::ServerEvents)event_type)); + binding->Clear(Key((Hooks::ServerEvents)event_type)); } return 0; } @@ -2834,19 +2848,20 @@ namespace LuaGlobalFunctions int ClearMapEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_MAP); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::INSTANCE_EVENT_COUNT; ++i) - E->MapEventBindings->Clear(Key((Hooks::InstanceEvents)i, entry)); + binding->Clear(Key((Hooks::InstanceEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->MapEventBindings->Clear(Key((Hooks::InstanceEvents)event_type, entry)); + binding->Clear(Key((Hooks::InstanceEvents)event_type, entry)); } return 0; @@ -2867,19 +2882,20 @@ namespace LuaGlobalFunctions int ClearInstanceEvents(Eluna* E) { typedef EntryKey Key; + auto binding = E->GetBinding(Hooks::REGTYPE_INSTANCE); if (lua_isnoneornil(E->L, 2)) { uint32 entry = E->CHECKVAL(1); for (uint32 i = 1; i < Hooks::INSTANCE_EVENT_COUNT; ++i) - E->InstanceEventBindings->Clear(Key((Hooks::InstanceEvents)i, entry)); + binding->Clear(Key((Hooks::InstanceEvents)i, entry)); } else { uint32 entry = E->CHECKVAL(1); uint32 event_type = E->CHECKVAL(2); - E->InstanceEventBindings->Clear(Key((Hooks::InstanceEvents)event_type, entry)); + binding->Clear(Key((Hooks::InstanceEvents)event_type, entry)); } return 0;