chore: align structure with master
This commit is contained in:
62
src/LuaEngine/hooks/BattleGroundHooks.cpp
Normal file
62
src/LuaEngine/hooks/BattleGroundHooks.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
|
||||
* This program is free software licensed under GPL version 3
|
||||
* Please see the included DOCS/LICENSE.md for more information
|
||||
*/
|
||||
|
||||
#include "Hooks.h"
|
||||
#include "HookHelpers.h"
|
||||
#include "LuaEngine.h"
|
||||
#include "BindingMap.h"
|
||||
#include "ElunaTemplate.h"
|
||||
|
||||
using namespace Hooks;
|
||||
|
||||
#define START_HOOK(EVENT) \
|
||||
if (!IsEnabled())\
|
||||
return;\
|
||||
auto key = EventKey<BGEvents>(EVENT);\
|
||||
if (!BGEventBindings->HasBindingsFor(key))\
|
||||
return;\
|
||||
LOCK_ELUNA
|
||||
|
||||
void Eluna::OnBGStart(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId)
|
||||
{
|
||||
START_HOOK(BG_EVENT_ON_START);
|
||||
Push(bg);
|
||||
Push(bgId);
|
||||
Push(instanceId);
|
||||
CallAllFunctions(BGEventBindings, key);
|
||||
}
|
||||
|
||||
#if AZEROTHCORE
|
||||
void Eluna::OnBGEnd(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId, TeamId winner)
|
||||
#else
|
||||
void Eluna::OnBGEnd(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId, Team winner)
|
||||
#endif
|
||||
{
|
||||
START_HOOK(BG_EVENT_ON_END);
|
||||
Push(bg);
|
||||
Push(bgId);
|
||||
Push(instanceId);
|
||||
Push(winner);
|
||||
CallAllFunctions(BGEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnBGCreate(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId)
|
||||
{
|
||||
START_HOOK(BG_EVENT_ON_CREATE);
|
||||
Push(bg);
|
||||
Push(bgId);
|
||||
Push(instanceId);
|
||||
CallAllFunctions(BGEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnBGDestroy(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId)
|
||||
{
|
||||
START_HOOK(BG_EVENT_ON_PRE_DESTROY);
|
||||
Push(bg);
|
||||
Push(bgId);
|
||||
Push(instanceId);
|
||||
CallAllFunctions(BGEventBindings, key);
|
||||
}
|
||||
333
src/LuaEngine/hooks/CreatureHooks.cpp
Normal file
333
src/LuaEngine/hooks/CreatureHooks.cpp
Normal file
@@ -0,0 +1,333 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
|
||||
* This program is free software licensed under GPL version 3
|
||||
* Please see the included DOCS/LICENSE.md for more information
|
||||
*/
|
||||
|
||||
#include "Hooks.h"
|
||||
#include "HookHelpers.h"
|
||||
#include "LuaEngine.h"
|
||||
#include "BindingMap.h"
|
||||
#include "ElunaIncludes.h"
|
||||
#include "ElunaTemplate.h"
|
||||
|
||||
using namespace Hooks;
|
||||
|
||||
#define START_HOOK(EVENT, CREATURE) \
|
||||
if (!IsEnabled())\
|
||||
return;\
|
||||
auto entry_key = EntryKey<CreatureEvents>(EVENT, CREATURE->GetEntry());\
|
||||
auto unique_key = UniqueObjectKey<CreatureEvents>(EVENT, CREATURE->GET_GUID(), CREATURE->GetInstanceId());\
|
||||
if (!CreatureEventBindings->HasBindingsFor(entry_key))\
|
||||
if (!CreatureUniqueBindings->HasBindingsFor(unique_key))\
|
||||
return;\
|
||||
LOCK_ELUNA
|
||||
|
||||
#define START_HOOK_WITH_RETVAL(EVENT, CREATURE, RETVAL) \
|
||||
if (!IsEnabled())\
|
||||
return RETVAL;\
|
||||
auto entry_key = EntryKey<CreatureEvents>(EVENT, CREATURE->GetEntry());\
|
||||
auto unique_key = UniqueObjectKey<CreatureEvents>(EVENT, CREATURE->GET_GUID(), CREATURE->GetInstanceId());\
|
||||
if (!CreatureEventBindings->HasBindingsFor(entry_key))\
|
||||
if (!CreatureUniqueBindings->HasBindingsFor(unique_key))\
|
||||
return RETVAL;\
|
||||
LOCK_ELUNA
|
||||
|
||||
void Eluna::OnDummyEffect(WorldObject* pCaster, uint32 spellId, SpellEffIndex effIndex, Creature* pTarget)
|
||||
{
|
||||
START_HOOK(CREATURE_EVENT_ON_DUMMY_EFFECT, pTarget);
|
||||
Push(pCaster);
|
||||
Push(spellId);
|
||||
Push(effIndex);
|
||||
Push(pTarget);
|
||||
CallAllFunctions(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
bool Eluna::OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_QUEST_ACCEPT, pCreature, false);
|
||||
Push(pPlayer);
|
||||
Push(pCreature);
|
||||
Push(pQuest);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
bool Eluna::OnQuestReward(Player* pPlayer, Creature* pCreature, Quest const* pQuest, uint32 opt)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_QUEST_REWARD, pCreature, false);
|
||||
Push(pPlayer);
|
||||
Push(pCreature);
|
||||
Push(pQuest);
|
||||
Push(opt);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
void Eluna::GetDialogStatus(const Player* pPlayer, const Creature* pCreature)
|
||||
{
|
||||
START_HOOK(CREATURE_EVENT_ON_DIALOG_STATUS, pCreature);
|
||||
Push(pPlayer);
|
||||
Push(pCreature);
|
||||
CallAllFunctions(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
void Eluna::OnAddToWorld(Creature* pCreature)
|
||||
{
|
||||
START_HOOK(CREATURE_EVENT_ON_ADD, pCreature);
|
||||
Push(pCreature);
|
||||
CallAllFunctions(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
void Eluna::OnRemoveFromWorld(Creature* pCreature)
|
||||
{
|
||||
START_HOOK(CREATURE_EVENT_ON_REMOVE, pCreature);
|
||||
Push(pCreature);
|
||||
CallAllFunctions(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
bool Eluna::OnSummoned(Creature* pCreature, Unit* pSummoner)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_SUMMONED, pCreature, false);
|
||||
Push(pCreature);
|
||||
Push(pSummoner);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
bool Eluna::UpdateAI(Creature* me, const uint32 diff)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_AIUPDATE, me, false);
|
||||
Push(me);
|
||||
Push(diff);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
//Called for reaction at enter to combat if not in combat yet (enemy can be NULL)
|
||||
//Called at creature aggro either by MoveInLOS or Attack Start
|
||||
bool Eluna::EnterCombat(Creature* me, Unit* target)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_ENTER_COMBAT, me, false);
|
||||
Push(me);
|
||||
Push(target);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
// Called at any Damage from any attacker (before damage apply)
|
||||
bool Eluna::DamageTaken(Creature* me, Unit* attacker, uint32& damage)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_DAMAGE_TAKEN, me, false);
|
||||
bool result = false;
|
||||
Push(me);
|
||||
Push(attacker);
|
||||
Push(damage);
|
||||
int damageIndex = lua_gettop(L);
|
||||
int n = SetupStack(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key, 3);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 3, 2);
|
||||
|
||||
if (lua_isboolean(L, r + 0) && lua_toboolean(L, r + 0))
|
||||
result = true;
|
||||
|
||||
if (lua_isnumber(L, r + 1))
|
||||
{
|
||||
damage = Eluna::CHECKVAL<uint32>(L, r + 1);
|
||||
// Update the stack for subsequent calls.
|
||||
ReplaceArgument(damage, damageIndex);
|
||||
}
|
||||
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
CleanUpStack(3);
|
||||
return result;
|
||||
}
|
||||
|
||||
//Called at creature death
|
||||
bool Eluna::JustDied(Creature* me, Unit* killer)
|
||||
{
|
||||
On_Reset(me);
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_DIED, me, false);
|
||||
Push(me);
|
||||
Push(killer);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
//Called at creature killing another unit
|
||||
bool Eluna::KilledUnit(Creature* me, Unit* victim)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_TARGET_DIED, me, false);
|
||||
Push(me);
|
||||
Push(victim);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
// Called when the creature summon successfully other creature
|
||||
bool Eluna::JustSummoned(Creature* me, Creature* summon)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE, me, false);
|
||||
Push(me);
|
||||
Push(summon);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
// Called when a summoned creature is despawned
|
||||
bool Eluna::SummonedCreatureDespawn(Creature* me, Creature* summon)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN, me, false);
|
||||
Push(me);
|
||||
Push(summon);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
//Called at waypoint reached or PointMovement end
|
||||
bool Eluna::MovementInform(Creature* me, uint32 type, uint32 id)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_REACH_WP, me, false);
|
||||
Push(me);
|
||||
Push(type);
|
||||
Push(id);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
// Called before EnterCombat even before the creature is in combat.
|
||||
bool Eluna::AttackStart(Creature* me, Unit* target)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_PRE_COMBAT, me, false);
|
||||
Push(me);
|
||||
Push(target);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
// Called for reaction at stopping attack at no attackers or targets
|
||||
bool Eluna::EnterEvadeMode(Creature* me)
|
||||
{
|
||||
On_Reset(me);
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_LEAVE_COMBAT, me, false);
|
||||
Push(me);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
// Called when creature is spawned or respawned (for reseting variables)
|
||||
bool Eluna::JustRespawned(Creature* me)
|
||||
{
|
||||
On_Reset(me);
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_SPAWN, me, false);
|
||||
Push(me);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
// Called at reaching home after evade
|
||||
bool Eluna::JustReachedHome(Creature* me)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_REACH_HOME, me, false);
|
||||
Push(me);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
// Called at text emote receive from player
|
||||
bool Eluna::ReceiveEmote(Creature* me, Player* player, uint32 emoteId)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_RECEIVE_EMOTE, me, false);
|
||||
Push(me);
|
||||
Push(player);
|
||||
Push(emoteId);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
// called when the corpse of this creature gets removed
|
||||
bool Eluna::CorpseRemoved(Creature* me, uint32& respawnDelay)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_CORPSE_REMOVED, me, false);
|
||||
bool result = false;
|
||||
Push(me);
|
||||
Push(respawnDelay);
|
||||
int respawnDelayIndex = lua_gettop(L);
|
||||
int n = SetupStack(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key, 2);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 2, 2);
|
||||
|
||||
if (lua_isboolean(L, r + 0) && lua_toboolean(L, r + 0))
|
||||
result = true;
|
||||
|
||||
if (lua_isnumber(L, r + 1))
|
||||
{
|
||||
respawnDelay = Eluna::CHECKVAL<uint32>(L, r + 1);
|
||||
// Update the stack for subsequent calls.
|
||||
ReplaceArgument(respawnDelay, respawnDelayIndex);
|
||||
}
|
||||
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
CleanUpStack(2);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Eluna::MoveInLineOfSight(Creature* me, Unit* who)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_MOVE_IN_LOS, me, false);
|
||||
Push(me);
|
||||
Push(who);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
// Called on creature initial spawn, respawn, death, evade (leave combat)
|
||||
void Eluna::On_Reset(Creature* me) // Not an override, custom
|
||||
{
|
||||
START_HOOK(CREATURE_EVENT_ON_RESET, me);
|
||||
Push(me);
|
||||
CallAllFunctions(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
// Called when hit by a spell
|
||||
bool Eluna::SpellHit(Creature* me, WorldObject* caster, SpellInfo const* spell)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_HIT_BY_SPELL, me, false);
|
||||
Push(me);
|
||||
Push(caster);
|
||||
Push(spell->Id); // Pass spell object?
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
// Called when spell hits a target
|
||||
bool Eluna::SpellHitTarget(Creature* me, WorldObject* target, SpellInfo const* spell)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_SPELL_HIT_TARGET, me, false);
|
||||
Push(me);
|
||||
Push(target);
|
||||
Push(spell->Id); // Pass spell object?
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
#if defined TRINITY || AZEROTHCORE
|
||||
|
||||
bool Eluna::SummonedCreatureDies(Creature* me, Creature* summon, Unit* killer)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED, me, false);
|
||||
Push(me);
|
||||
Push(summon);
|
||||
Push(killer);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
// Called when owner takes damage
|
||||
bool Eluna::OwnerAttackedBy(Creature* me, Unit* attacker)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_OWNER_ATTACKED_AT, me, false);
|
||||
Push(me);
|
||||
Push(attacker);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
// Called when owner attacks something
|
||||
bool Eluna::OwnerAttacked(Creature* me, Unit* target)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_OWNER_ATTACKED, me, false);
|
||||
Push(me);
|
||||
Push(target);
|
||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||
}
|
||||
|
||||
#endif // TRINITY
|
||||
142
src/LuaEngine/hooks/GameObjectHooks.cpp
Normal file
142
src/LuaEngine/hooks/GameObjectHooks.cpp
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
|
||||
* This program is free software licensed under GPL version 3
|
||||
* Please see the included DOCS/LICENSE.md for more information
|
||||
*/
|
||||
|
||||
#include "Hooks.h"
|
||||
#include "HookHelpers.h"
|
||||
#include "LuaEngine.h"
|
||||
#include "BindingMap.h"
|
||||
#include "ElunaIncludes.h"
|
||||
#include "ElunaEventMgr.h"
|
||||
#include "ElunaTemplate.h"
|
||||
|
||||
using namespace Hooks;
|
||||
|
||||
#define START_HOOK(EVENT, ENTRY) \
|
||||
if (!IsEnabled())\
|
||||
return;\
|
||||
auto key = EntryKey<GameObjectEvents>(EVENT, ENTRY);\
|
||||
if (!GameObjectEventBindings->HasBindingsFor(key))\
|
||||
return;\
|
||||
LOCK_ELUNA
|
||||
|
||||
#define START_HOOK_WITH_RETVAL(EVENT, ENTRY, RETVAL) \
|
||||
if (!IsEnabled())\
|
||||
return RETVAL;\
|
||||
auto key = EntryKey<GameObjectEvents>(EVENT, ENTRY);\
|
||||
if (!GameObjectEventBindings->HasBindingsFor(key))\
|
||||
return RETVAL;\
|
||||
LOCK_ELUNA
|
||||
|
||||
void Eluna::OnDummyEffect(WorldObject* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget)
|
||||
{
|
||||
START_HOOK(GAMEOBJECT_EVENT_ON_DUMMY_EFFECT, pTarget->GetEntry());
|
||||
Push(pCaster);
|
||||
Push(spellId);
|
||||
Push(effIndex);
|
||||
Push(pTarget);
|
||||
CallAllFunctions(GameObjectEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::UpdateAI(GameObject* pGameObject, uint32 diff)
|
||||
{
|
||||
pGameObject->elunaEvents->Update(diff);
|
||||
START_HOOK(GAMEOBJECT_EVENT_ON_AIUPDATE, pGameObject->GetEntry());
|
||||
Push(pGameObject);
|
||||
Push(diff);
|
||||
CallAllFunctions(GameObjectEventBindings, key);
|
||||
}
|
||||
|
||||
bool Eluna::OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(GAMEOBJECT_EVENT_ON_QUEST_ACCEPT, pGameObject->GetEntry(), false);
|
||||
Push(pPlayer);
|
||||
Push(pGameObject);
|
||||
Push(pQuest);
|
||||
return CallAllFunctionsBool(GameObjectEventBindings, key);
|
||||
}
|
||||
|
||||
bool Eluna::OnQuestReward(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest, uint32 opt)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(GAMEOBJECT_EVENT_ON_QUEST_REWARD, pGameObject->GetEntry(), false);
|
||||
Push(pPlayer);
|
||||
Push(pGameObject);
|
||||
Push(pQuest);
|
||||
Push(opt);
|
||||
return CallAllFunctionsBool(GameObjectEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::GetDialogStatus(const Player* pPlayer, const GameObject* pGameObject)
|
||||
{
|
||||
START_HOOK(GAMEOBJECT_EVENT_ON_DIALOG_STATUS, pGameObject->GetEntry());
|
||||
Push(pPlayer);
|
||||
Push(pGameObject);
|
||||
CallAllFunctions(GameObjectEventBindings, key);
|
||||
}
|
||||
|
||||
#ifndef CLASSIC
|
||||
#ifndef TBC
|
||||
void Eluna::OnDestroyed(GameObject* pGameObject, WorldObject* attacker)
|
||||
{
|
||||
START_HOOK(GAMEOBJECT_EVENT_ON_DESTROYED, pGameObject->GetEntry());
|
||||
Push(pGameObject);
|
||||
Push(attacker);
|
||||
CallAllFunctions(GameObjectEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnDamaged(GameObject* pGameObject, WorldObject* attacker)
|
||||
{
|
||||
START_HOOK(GAMEOBJECT_EVENT_ON_DAMAGED, pGameObject->GetEntry());
|
||||
Push(pGameObject);
|
||||
Push(attacker);
|
||||
CallAllFunctions(GameObjectEventBindings, key);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void Eluna::OnLootStateChanged(GameObject* pGameObject, uint32 state)
|
||||
{
|
||||
START_HOOK(GAMEOBJECT_EVENT_ON_LOOT_STATE_CHANGE, pGameObject->GetEntry());
|
||||
Push(pGameObject);
|
||||
Push(state);
|
||||
CallAllFunctions(GameObjectEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnGameObjectStateChanged(GameObject* pGameObject, uint32 state)
|
||||
{
|
||||
START_HOOK(GAMEOBJECT_EVENT_ON_GO_STATE_CHANGED, pGameObject->GetEntry());
|
||||
Push(pGameObject);
|
||||
Push(state);
|
||||
CallAllFunctions(GameObjectEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnSpawn(GameObject* pGameObject)
|
||||
{
|
||||
START_HOOK(GAMEOBJECT_EVENT_ON_SPAWN, pGameObject->GetEntry());
|
||||
Push(pGameObject);
|
||||
CallAllFunctions(GameObjectEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnAddToWorld(GameObject* pGameObject)
|
||||
{
|
||||
START_HOOK(GAMEOBJECT_EVENT_ON_ADD, pGameObject->GetEntry());
|
||||
Push(pGameObject);
|
||||
CallAllFunctions(GameObjectEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnRemoveFromWorld(GameObject* pGameObject)
|
||||
{
|
||||
START_HOOK(GAMEOBJECT_EVENT_ON_REMOVE, pGameObject->GetEntry());
|
||||
Push(pGameObject);
|
||||
CallAllFunctions(GameObjectEventBindings, key);
|
||||
}
|
||||
|
||||
bool Eluna::OnGameObjectUse(Player* pPlayer, GameObject* pGameObject)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(GAMEOBJECT_EVENT_ON_USE, pGameObject->GetEntry(), false);
|
||||
Push(pGameObject);
|
||||
Push(pPlayer);
|
||||
return CallAllFunctionsBool(GameObjectEventBindings, key);
|
||||
}
|
||||
147
src/LuaEngine/hooks/GossipHooks.cpp
Normal file
147
src/LuaEngine/hooks/GossipHooks.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
|
||||
* This program is free software licensed under GPL version 3
|
||||
* Please see the included DOCS/LICENSE.md for more information
|
||||
*/
|
||||
|
||||
#include "Hooks.h"
|
||||
#include "HookHelpers.h"
|
||||
#include "LuaEngine.h"
|
||||
#include "BindingMap.h"
|
||||
#include "ElunaIncludes.h"
|
||||
#include "ElunaTemplate.h"
|
||||
|
||||
using namespace Hooks;
|
||||
|
||||
#define START_HOOK(BINDINGS, EVENT, ENTRY) \
|
||||
if (!IsEnabled())\
|
||||
return;\
|
||||
auto key = EntryKey<GossipEvents>(EVENT, ENTRY);\
|
||||
if (!BINDINGS->HasBindingsFor(key))\
|
||||
return;\
|
||||
LOCK_ELUNA
|
||||
|
||||
#define START_HOOK_WITH_RETVAL(BINDINGS, EVENT, ENTRY, RETVAL) \
|
||||
if (!IsEnabled())\
|
||||
return RETVAL;\
|
||||
auto key = EntryKey<GossipEvents>(EVENT, ENTRY);\
|
||||
if (!BINDINGS->HasBindingsFor(key))\
|
||||
return RETVAL;\
|
||||
LOCK_ELUNA
|
||||
|
||||
bool Eluna::OnGossipHello(Player* pPlayer, GameObject* pGameObject)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(GameObjectGossipBindings, GOSSIP_EVENT_ON_HELLO, pGameObject->GetEntry(), false);
|
||||
pPlayer->PlayerTalkClass->ClearMenus();
|
||||
Push(pPlayer);
|
||||
Push(pGameObject);
|
||||
return CallAllFunctionsBool(GameObjectGossipBindings, 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);
|
||||
pPlayer->PlayerTalkClass->ClearMenus();
|
||||
Push(pPlayer);
|
||||
Push(pGameObject);
|
||||
Push(sender);
|
||||
Push(action);
|
||||
return CallAllFunctionsBool(GameObjectGossipBindings, 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);
|
||||
pPlayer->PlayerTalkClass->ClearMenus();
|
||||
Push(pPlayer);
|
||||
Push(pGameObject);
|
||||
Push(sender);
|
||||
Push(action);
|
||||
Push(code);
|
||||
return CallAllFunctionsBool(GameObjectGossipBindings, 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);
|
||||
pPlayer->PlayerTalkClass->ClearMenus();
|
||||
|
||||
Push(pPlayer); // receiver
|
||||
Push(pPlayer); // sender, just not to mess up the amount of args.
|
||||
Push(sender);
|
||||
Push(action);
|
||||
if (code.empty())
|
||||
Push();
|
||||
else
|
||||
Push(code);
|
||||
|
||||
CallAllFunctions(PlayerGossipBindings, key);
|
||||
}
|
||||
|
||||
bool Eluna::OnItemGossip(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(ItemGossipBindings, GOSSIP_EVENT_ON_HELLO, pItem->GetEntry(), true);
|
||||
pPlayer->PlayerTalkClass->ClearMenus();
|
||||
Push(pPlayer);
|
||||
Push(pItem);
|
||||
return CallAllFunctionsBool(ItemGossipBindings, 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());
|
||||
pPlayer->PlayerTalkClass->ClearMenus();
|
||||
|
||||
Push(pPlayer);
|
||||
Push(pItem);
|
||||
Push(sender);
|
||||
Push(action);
|
||||
if (code.empty())
|
||||
Push();
|
||||
else
|
||||
Push(code);
|
||||
|
||||
CallAllFunctions(ItemGossipBindings, key);
|
||||
}
|
||||
|
||||
bool Eluna::OnGossipHello(Player* pPlayer, Creature* pCreature)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(CreatureGossipBindings, GOSSIP_EVENT_ON_HELLO, pCreature->GetEntry(), false);
|
||||
pPlayer->PlayerTalkClass->ClearMenus();
|
||||
Push(pPlayer);
|
||||
Push(pCreature);
|
||||
return CallAllFunctionsBool(CreatureGossipBindings, 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);
|
||||
auto originalMenu = *pPlayer->PlayerTalkClass;
|
||||
pPlayer->PlayerTalkClass->ClearMenus();
|
||||
Push(pPlayer);
|
||||
Push(pCreature);
|
||||
Push(sender);
|
||||
Push(action);
|
||||
auto preventDefault = CallAllFunctionsBool(CreatureGossipBindings, key, true);
|
||||
if (!preventDefault) {
|
||||
*pPlayer->PlayerTalkClass = originalMenu;
|
||||
}
|
||||
return preventDefault;
|
||||
}
|
||||
|
||||
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);
|
||||
auto originalMenu = *pPlayer->PlayerTalkClass;
|
||||
pPlayer->PlayerTalkClass->ClearMenus();
|
||||
Push(pPlayer);
|
||||
Push(pCreature);
|
||||
Push(sender);
|
||||
Push(action);
|
||||
Push(code);
|
||||
auto preventDefault = CallAllFunctionsBool(CreatureGossipBindings, key, true);
|
||||
if (!preventDefault) {
|
||||
*pPlayer->PlayerTalkClass = originalMenu;
|
||||
}
|
||||
return preventDefault;
|
||||
}
|
||||
71
src/LuaEngine/hooks/GroupHooks.cpp
Normal file
71
src/LuaEngine/hooks/GroupHooks.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
|
||||
* This program is free software licensed under GPL version 3
|
||||
* Please see the included DOCS/LICENSE.md for more information
|
||||
*/
|
||||
|
||||
#include "Hooks.h"
|
||||
#include "HookHelpers.h"
|
||||
#include "LuaEngine.h"
|
||||
#include "BindingMap.h"
|
||||
#include "ElunaTemplate.h"
|
||||
|
||||
using namespace Hooks;
|
||||
|
||||
#define START_HOOK(EVENT) \
|
||||
if (!IsEnabled())\
|
||||
return;\
|
||||
auto key = EventKey<GroupEvents>(EVENT);\
|
||||
if (!GroupEventBindings->HasBindingsFor(key))\
|
||||
return;\
|
||||
LOCK_ELUNA
|
||||
|
||||
void Eluna::OnAddMember(Group* group, ObjectGuid guid)
|
||||
{
|
||||
START_HOOK(GROUP_EVENT_ON_MEMBER_ADD);
|
||||
Push(group);
|
||||
Push(guid);
|
||||
CallAllFunctions(GroupEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnInviteMember(Group* group, ObjectGuid guid)
|
||||
{
|
||||
START_HOOK(GROUP_EVENT_ON_MEMBER_INVITE);
|
||||
Push(group);
|
||||
Push(guid);
|
||||
CallAllFunctions(GroupEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnRemoveMember(Group* group, ObjectGuid guid, uint8 method)
|
||||
{
|
||||
START_HOOK(GROUP_EVENT_ON_MEMBER_REMOVE);
|
||||
Push(group);
|
||||
Push(guid);
|
||||
Push(method);
|
||||
CallAllFunctions(GroupEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnChangeLeader(Group* group, ObjectGuid newLeaderGuid, ObjectGuid oldLeaderGuid)
|
||||
{
|
||||
START_HOOK(GROUP_EVENT_ON_LEADER_CHANGE);
|
||||
Push(group);
|
||||
Push(newLeaderGuid);
|
||||
Push(oldLeaderGuid);
|
||||
CallAllFunctions(GroupEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnDisband(Group* group)
|
||||
{
|
||||
START_HOOK(GROUP_EVENT_ON_DISBAND);
|
||||
Push(group);
|
||||
CallAllFunctions(GroupEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnCreate(Group* group, ObjectGuid leaderGuid, GroupType groupType)
|
||||
{
|
||||
START_HOOK(GROUP_EVENT_ON_CREATE);
|
||||
Push(group);
|
||||
Push(leaderGuid);
|
||||
Push(groupType);
|
||||
CallAllFunctions(GroupEventBindings, key);
|
||||
}
|
||||
164
src/LuaEngine/hooks/GuildHooks.cpp
Normal file
164
src/LuaEngine/hooks/GuildHooks.cpp
Normal file
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
|
||||
* This program is free software licensed under GPL version 3
|
||||
* Please see the included DOCS/LICENSE.md for more information
|
||||
*/
|
||||
|
||||
#include "Hooks.h"
|
||||
#include "HookHelpers.h"
|
||||
#include "LuaEngine.h"
|
||||
#include "BindingMap.h"
|
||||
#include "ElunaTemplate.h"
|
||||
|
||||
using namespace Hooks;
|
||||
|
||||
#define START_HOOK(EVENT) \
|
||||
if (!IsEnabled())\
|
||||
return;\
|
||||
auto key = EventKey<GuildEvents>(EVENT);\
|
||||
if (!GuildEventBindings->HasBindingsFor(key))\
|
||||
return;\
|
||||
LOCK_ELUNA
|
||||
|
||||
void Eluna::OnAddMember(Guild* guild, Player* player, uint32 plRank)
|
||||
{
|
||||
START_HOOK(GUILD_EVENT_ON_ADD_MEMBER);
|
||||
Push(guild);
|
||||
Push(player);
|
||||
Push(plRank);
|
||||
CallAllFunctions(GuildEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnRemoveMember(Guild* guild, Player* player, bool isDisbanding)
|
||||
{
|
||||
START_HOOK(GUILD_EVENT_ON_REMOVE_MEMBER);
|
||||
Push(guild);
|
||||
Push(player);
|
||||
Push(isDisbanding);
|
||||
CallAllFunctions(GuildEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnMOTDChanged(Guild* guild, const std::string& newMotd)
|
||||
{
|
||||
START_HOOK(GUILD_EVENT_ON_MOTD_CHANGE);
|
||||
Push(guild);
|
||||
Push(newMotd);
|
||||
CallAllFunctions(GuildEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnInfoChanged(Guild* guild, const std::string& newInfo)
|
||||
{
|
||||
START_HOOK(GUILD_EVENT_ON_INFO_CHANGE);
|
||||
Push(guild);
|
||||
Push(newInfo);
|
||||
CallAllFunctions(GuildEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnCreate(Guild* guild, Player* leader, const std::string& name)
|
||||
{
|
||||
START_HOOK(GUILD_EVENT_ON_CREATE);
|
||||
Push(guild);
|
||||
Push(leader);
|
||||
Push(name);
|
||||
CallAllFunctions(GuildEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnDisband(Guild* guild)
|
||||
{
|
||||
START_HOOK(GUILD_EVENT_ON_DISBAND);
|
||||
Push(guild);
|
||||
CallAllFunctions(GuildEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnMemberWitdrawMoney(Guild* guild, Player* player, uint32& amount, bool isRepair)
|
||||
{
|
||||
START_HOOK(GUILD_EVENT_ON_MONEY_WITHDRAW);
|
||||
Push(guild);
|
||||
Push(player);
|
||||
Push(amount);
|
||||
Push(isRepair); // isRepair not a part of Mangos, implement?
|
||||
int amountIndex = lua_gettop(L) - 1;
|
||||
int n = SetupStack(GuildEventBindings, key, 4);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 4, 1);
|
||||
|
||||
if (lua_isnumber(L, r))
|
||||
{
|
||||
amount = CHECKVAL<uint32>(L, r);
|
||||
// Update the stack for subsequent calls.
|
||||
ReplaceArgument(amount, amountIndex);
|
||||
}
|
||||
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
CleanUpStack(4);
|
||||
}
|
||||
|
||||
void Eluna::OnMemberDepositMoney(Guild* guild, Player* player, uint32& amount)
|
||||
{
|
||||
START_HOOK(GUILD_EVENT_ON_MONEY_DEPOSIT);
|
||||
Push(guild);
|
||||
Push(player);
|
||||
Push(amount);
|
||||
int amountIndex = lua_gettop(L);
|
||||
int n = SetupStack(GuildEventBindings, key, 3);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 3, 1);
|
||||
|
||||
if (lua_isnumber(L, r))
|
||||
{
|
||||
amount = CHECKVAL<uint32>(L, r);
|
||||
// Update the stack for subsequent calls.
|
||||
ReplaceArgument(amount, amountIndex);
|
||||
}
|
||||
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
CleanUpStack(3);
|
||||
}
|
||||
|
||||
void Eluna::OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId,
|
||||
bool isDestBank, uint8 destContainer, uint8 destSlotId)
|
||||
{
|
||||
START_HOOK(GUILD_EVENT_ON_ITEM_MOVE);
|
||||
Push(guild);
|
||||
Push(player);
|
||||
Push(pItem);
|
||||
Push(isSrcBank);
|
||||
Push(srcContainer);
|
||||
Push(srcSlotId);
|
||||
Push(isDestBank);
|
||||
Push(destContainer);
|
||||
Push(destSlotId);
|
||||
CallAllFunctions(GuildEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnEvent(Guild* guild, uint8 eventType, uint32 playerGuid1, uint32 playerGuid2, uint8 newRank)
|
||||
{
|
||||
START_HOOK(GUILD_EVENT_ON_EVENT);
|
||||
Push(guild);
|
||||
Push(eventType);
|
||||
Push(playerGuid1);
|
||||
Push(playerGuid2);
|
||||
Push(newRank);
|
||||
CallAllFunctions(GuildEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, uint32 playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId)
|
||||
{
|
||||
START_HOOK(GUILD_EVENT_ON_BANK_EVENT);
|
||||
Push(guild);
|
||||
Push(eventType);
|
||||
Push(tabId);
|
||||
Push(playerGuid);
|
||||
Push(itemOrMoney);
|
||||
Push(itemStackCount);
|
||||
Push(destTabId);
|
||||
CallAllFunctions(GuildEventBindings, key);
|
||||
}
|
||||
83
src/LuaEngine/hooks/InstanceHooks.cpp
Normal file
83
src/LuaEngine/hooks/InstanceHooks.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
|
||||
* This program is free software licensed under GPL version 3
|
||||
* Please see the included DOCS/LICENSE.md for more information
|
||||
*/
|
||||
|
||||
#include "Hooks.h"
|
||||
#include "HookHelpers.h"
|
||||
#include "LuaEngine.h"
|
||||
#include "BindingMap.h"
|
||||
#include "ElunaIncludes.h"
|
||||
#include "ElunaTemplate.h"
|
||||
#include "ElunaInstanceAI.h"
|
||||
|
||||
using namespace Hooks;
|
||||
|
||||
#define START_HOOK(EVENT, AI) \
|
||||
if (!IsEnabled())\
|
||||
return;\
|
||||
auto mapKey = EntryKey<InstanceEvents>(EVENT, AI->instance->GetId());\
|
||||
auto instanceKey = EntryKey<InstanceEvents>(EVENT, AI->instance->GetInstanceId());\
|
||||
if (!MapEventBindings->HasBindingsFor(mapKey) && !InstanceEventBindings->HasBindingsFor(instanceKey))\
|
||||
return;\
|
||||
LOCK_ELUNA;\
|
||||
PushInstanceData(L, AI);\
|
||||
Push(AI->instance)
|
||||
|
||||
#define START_HOOK_WITH_RETVAL(EVENT, AI, RETVAL) \
|
||||
if (!IsEnabled())\
|
||||
return RETVAL;\
|
||||
auto mapKey = EntryKey<InstanceEvents>(EVENT, AI->instance->GetId());\
|
||||
auto instanceKey = EntryKey<InstanceEvents>(EVENT, AI->instance->GetInstanceId());\
|
||||
if (!MapEventBindings->HasBindingsFor(mapKey) && !InstanceEventBindings->HasBindingsFor(instanceKey))\
|
||||
return RETVAL;\
|
||||
LOCK_ELUNA;\
|
||||
PushInstanceData(L, AI);\
|
||||
Push(AI->instance)
|
||||
|
||||
void Eluna::OnInitialize(ElunaInstanceAI* ai)
|
||||
{
|
||||
START_HOOK(INSTANCE_EVENT_ON_INITIALIZE, ai);
|
||||
CallAllFunctions(MapEventBindings, InstanceEventBindings, mapKey, instanceKey);
|
||||
}
|
||||
|
||||
void Eluna::OnLoad(ElunaInstanceAI* ai)
|
||||
{
|
||||
START_HOOK(INSTANCE_EVENT_ON_LOAD, ai);
|
||||
CallAllFunctions(MapEventBindings, InstanceEventBindings, mapKey, instanceKey);
|
||||
}
|
||||
|
||||
void Eluna::OnUpdateInstance(ElunaInstanceAI* ai, uint32 diff)
|
||||
{
|
||||
START_HOOK(INSTANCE_EVENT_ON_UPDATE, ai);
|
||||
Push(diff);
|
||||
CallAllFunctions(MapEventBindings, InstanceEventBindings, mapKey, instanceKey);
|
||||
}
|
||||
|
||||
void Eluna::OnPlayerEnterInstance(ElunaInstanceAI* ai, Player* player)
|
||||
{
|
||||
START_HOOK(INSTANCE_EVENT_ON_PLAYER_ENTER, ai);
|
||||
Push(player);
|
||||
CallAllFunctions(MapEventBindings, InstanceEventBindings, mapKey, instanceKey);
|
||||
}
|
||||
|
||||
void Eluna::OnCreatureCreate(ElunaInstanceAI* ai, Creature* creature)
|
||||
{
|
||||
START_HOOK(INSTANCE_EVENT_ON_CREATURE_CREATE, ai);
|
||||
Push(creature);
|
||||
CallAllFunctions(MapEventBindings, InstanceEventBindings, mapKey, instanceKey);
|
||||
}
|
||||
|
||||
void Eluna::OnGameObjectCreate(ElunaInstanceAI* ai, GameObject* gameobject)
|
||||
{
|
||||
START_HOOK(INSTANCE_EVENT_ON_GAMEOBJECT_CREATE, ai);
|
||||
Push(gameobject);
|
||||
CallAllFunctions(MapEventBindings, InstanceEventBindings, mapKey, instanceKey);
|
||||
}
|
||||
|
||||
bool Eluna::OnCheckEncounterInProgress(ElunaInstanceAI* ai)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(INSTANCE_EVENT_ON_CHECK_ENCOUNTER_IN_PROGRESS, ai, false);
|
||||
return CallAllFunctionsBool(MapEventBindings, InstanceEventBindings, mapKey, instanceKey);
|
||||
}
|
||||
133
src/LuaEngine/hooks/ItemHooks.cpp
Normal file
133
src/LuaEngine/hooks/ItemHooks.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
|
||||
* This program is free software licensed under GPL version 3
|
||||
* Please see the included DOCS/LICENSE.md for more information
|
||||
*/
|
||||
|
||||
#include "Hooks.h"
|
||||
#include "HookHelpers.h"
|
||||
#include "LuaEngine.h"
|
||||
#include "BindingMap.h"
|
||||
#include "ElunaIncludes.h"
|
||||
#include "ElunaTemplate.h"
|
||||
|
||||
using namespace Hooks;
|
||||
|
||||
#define START_HOOK(EVENT, ENTRY) \
|
||||
if (!IsEnabled())\
|
||||
return;\
|
||||
auto key = EntryKey<ItemEvents>(EVENT, ENTRY);\
|
||||
if (!ItemEventBindings->HasBindingsFor(key))\
|
||||
return;\
|
||||
LOCK_ELUNA
|
||||
|
||||
#define START_HOOK_WITH_RETVAL(EVENT, ENTRY, RETVAL) \
|
||||
if (!IsEnabled())\
|
||||
return RETVAL;\
|
||||
auto key = EntryKey<ItemEvents>(EVENT, ENTRY);\
|
||||
if (!ItemEventBindings->HasBindingsFor(key))\
|
||||
return RETVAL;\
|
||||
LOCK_ELUNA
|
||||
|
||||
void Eluna::OnDummyEffect(WorldObject* pCaster, uint32 spellId, SpellEffIndex effIndex, Item* pTarget)
|
||||
{
|
||||
START_HOOK(ITEM_EVENT_ON_DUMMY_EFFECT, pTarget->GetEntry());
|
||||
Push(pCaster);
|
||||
Push(spellId);
|
||||
Push(effIndex);
|
||||
Push(pTarget);
|
||||
CallAllFunctions(ItemEventBindings, key);
|
||||
}
|
||||
|
||||
bool Eluna::OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(ITEM_EVENT_ON_QUEST_ACCEPT, pItem->GetEntry(), false);
|
||||
Push(pPlayer);
|
||||
Push(pItem);
|
||||
Push(pQuest);
|
||||
return CallAllFunctionsBool(ItemEventBindings, key);
|
||||
}
|
||||
|
||||
bool Eluna::OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets)
|
||||
{
|
||||
ObjectGuid guid = pItem->GET_GUID();
|
||||
bool castSpell = true;
|
||||
|
||||
if (!OnItemUse(pPlayer, pItem, targets))
|
||||
castSpell = false;
|
||||
|
||||
pItem = pPlayer->GetItemByGuid(guid);
|
||||
if (pItem)
|
||||
{
|
||||
if (!OnItemGossip(pPlayer, pItem, targets))
|
||||
castSpell = false;
|
||||
pItem = pPlayer->GetItemByGuid(guid);
|
||||
}
|
||||
|
||||
if (pItem && castSpell)
|
||||
return true;
|
||||
|
||||
// Send equip error that shows no message
|
||||
// This is a hack fix to stop spell casting visual bug when a spell is not cast on use
|
||||
WorldPacket data(SMSG_INVENTORY_CHANGE_FAILURE, 18);
|
||||
data << uint8(59); // EQUIP_ERR_NONE / EQUIP_ERR_CANT_BE_DISENCHANTED
|
||||
data << guid;
|
||||
data << ObjectGuid(uint64(0));
|
||||
data << uint8(0);
|
||||
#ifdef CMANGOS
|
||||
pPlayer->GetSession()->SendPacket(data);
|
||||
#else
|
||||
pPlayer->GetSession()->SendPacket(&data);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Eluna::OnItemUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(ITEM_EVENT_ON_USE, pItem->GetEntry(), true);
|
||||
Push(pPlayer);
|
||||
Push(pItem);
|
||||
#if defined TRINITY || AZEROTHCORE
|
||||
if (GameObject* target = targets.GetGOTarget())
|
||||
Push(target);
|
||||
else if (Item* target = targets.GetItemTarget())
|
||||
Push(target);
|
||||
else if (Corpse* target = targets.GetCorpseTarget())
|
||||
Push(target);
|
||||
else if (Unit* target = targets.GetUnitTarget())
|
||||
Push(target);
|
||||
else if (WorldObject* target = targets.GetObjectTarget())
|
||||
Push(target);
|
||||
else
|
||||
Push();
|
||||
#else
|
||||
if (GameObject* target = targets.getGOTarget())
|
||||
Push(target);
|
||||
else if (Item* target = targets.getItemTarget())
|
||||
Push(target);
|
||||
else if (Corpse* target = pPlayer->GetMap()->GetCorpse(targets.getCorpseTargetGuid()))
|
||||
Push(target);
|
||||
else if (Unit* target = targets.getUnitTarget())
|
||||
Push(target);
|
||||
else
|
||||
Push();
|
||||
#endif
|
||||
|
||||
return CallAllFunctionsBool(ItemEventBindings, key, true);
|
||||
}
|
||||
|
||||
bool Eluna::OnExpire(Player* pPlayer, ItemTemplate const* pProto)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(ITEM_EVENT_ON_EXPIRE, pProto->ItemId, false);
|
||||
Push(pPlayer);
|
||||
Push(pProto->ItemId);
|
||||
return CallAllFunctionsBool(ItemEventBindings, key);
|
||||
}
|
||||
|
||||
bool Eluna::OnRemove(Player* pPlayer, Item* pItem)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(ITEM_EVENT_ON_REMOVE, pItem->GetEntry(), false);
|
||||
Push(pPlayer);
|
||||
Push(pItem);
|
||||
return CallAllFunctionsBool(ItemEventBindings, key);
|
||||
}
|
||||
139
src/LuaEngine/hooks/PacketHooks.cpp
Normal file
139
src/LuaEngine/hooks/PacketHooks.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
|
||||
* This program is free software licensed under GPL version 3
|
||||
* Please see the included DOCS/LICENSE.md for more information
|
||||
*/
|
||||
|
||||
#include "Hooks.h"
|
||||
#include "HookHelpers.h"
|
||||
#include "LuaEngine.h"
|
||||
#include "BindingMap.h"
|
||||
#include "ElunaIncludes.h"
|
||||
#include "ElunaTemplate.h"
|
||||
|
||||
using namespace Hooks;
|
||||
|
||||
#define START_HOOK_SERVER(EVENT) \
|
||||
if (!IsEnabled())\
|
||||
return;\
|
||||
auto key = EventKey<ServerEvents>(EVENT);\
|
||||
if (!ServerEventBindings->HasBindingsFor(key))\
|
||||
return;\
|
||||
LOCK_ELUNA
|
||||
|
||||
#define START_HOOK_PACKET(EVENT, OPCODE) \
|
||||
if (!IsEnabled())\
|
||||
return;\
|
||||
auto key = EntryKey<PacketEvents>(EVENT, OPCODE);\
|
||||
if (!PacketEventBindings->HasBindingsFor(key))\
|
||||
return;\
|
||||
LOCK_ELUNA
|
||||
|
||||
bool Eluna::OnPacketSend(WorldSession* session, const WorldPacket& packet)
|
||||
{
|
||||
bool result = true;
|
||||
Player* player = NULL;
|
||||
if (session)
|
||||
player = session->GetPlayer();
|
||||
OnPacketSendAny(player, packet, result);
|
||||
OnPacketSendOne(player, packet, result);
|
||||
return result;
|
||||
}
|
||||
void Eluna::OnPacketSendAny(Player* player, const WorldPacket& packet, bool& result)
|
||||
{
|
||||
START_HOOK_SERVER(SERVER_EVENT_ON_PACKET_SEND);
|
||||
Push(new WorldPacket(packet));
|
||||
Push(player);
|
||||
int n = SetupStack(ServerEventBindings, key, 2);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 2, 1);
|
||||
|
||||
if (lua_isboolean(L, r + 0) && !lua_toboolean(L, r + 0))
|
||||
result = false;
|
||||
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
CleanUpStack(2);
|
||||
}
|
||||
|
||||
void Eluna::OnPacketSendOne(Player* player, const WorldPacket& packet, bool& result)
|
||||
{
|
||||
START_HOOK_PACKET(PACKET_EVENT_ON_PACKET_SEND, packet.GetOpcode());
|
||||
Push(new WorldPacket(packet));
|
||||
Push(player);
|
||||
int n = SetupStack(PacketEventBindings, key, 2);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 2, 1);
|
||||
|
||||
if (lua_isboolean(L, r + 0) && !lua_toboolean(L, r + 0))
|
||||
result = false;
|
||||
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
CleanUpStack(2);
|
||||
}
|
||||
|
||||
bool Eluna::OnPacketReceive(WorldSession* session, WorldPacket& packet)
|
||||
{
|
||||
bool result = true;
|
||||
Player* player = NULL;
|
||||
if (session)
|
||||
player = session->GetPlayer();
|
||||
OnPacketReceiveAny(player, packet, result);
|
||||
OnPacketReceiveOne(player, packet, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Eluna::OnPacketReceiveAny(Player* player, WorldPacket& packet, bool& result)
|
||||
{
|
||||
START_HOOK_SERVER(SERVER_EVENT_ON_PACKET_RECEIVE);
|
||||
Push(new WorldPacket(packet));
|
||||
Push(player);
|
||||
int n = SetupStack(ServerEventBindings, key, 2);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 2, 2);
|
||||
|
||||
if (lua_isboolean(L, r + 0) && !lua_toboolean(L, r + 0))
|
||||
result = false;
|
||||
|
||||
if (lua_isuserdata(L, r + 1))
|
||||
if (WorldPacket* data = CHECKOBJ<WorldPacket>(L, r + 1, false))
|
||||
packet = *data;
|
||||
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
CleanUpStack(2);
|
||||
}
|
||||
|
||||
void Eluna::OnPacketReceiveOne(Player* player, WorldPacket& packet, bool& result)
|
||||
{
|
||||
START_HOOK_PACKET(PACKET_EVENT_ON_PACKET_RECEIVE, packet.GetOpcode());
|
||||
Push(new WorldPacket(packet));
|
||||
Push(player);
|
||||
int n = SetupStack(PacketEventBindings, key, 2);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 2, 2);
|
||||
|
||||
if (lua_isboolean(L, r + 0) && !lua_toboolean(L, r + 0))
|
||||
result = false;
|
||||
|
||||
if (lua_isuserdata(L, r + 1))
|
||||
if (WorldPacket* data = CHECKOBJ<WorldPacket>(L, r + 1, false))
|
||||
packet = *data;
|
||||
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
CleanUpStack(2);
|
||||
}
|
||||
708
src/LuaEngine/hooks/PlayerHooks.cpp
Normal file
708
src/LuaEngine/hooks/PlayerHooks.cpp
Normal file
@@ -0,0 +1,708 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
|
||||
* This program is free software licensed under GPL version 3
|
||||
* Please see the included DOCS/LICENSE.md for more information
|
||||
*/
|
||||
|
||||
#include "Hooks.h"
|
||||
#include "HookHelpers.h"
|
||||
#include "LuaEngine.h"
|
||||
#include "BindingMap.h"
|
||||
#include "ElunaIncludes.h"
|
||||
#include "ElunaTemplate.h"
|
||||
|
||||
using namespace Hooks;
|
||||
|
||||
#define START_HOOK(EVENT) \
|
||||
if (!IsEnabled())\
|
||||
return;\
|
||||
auto key = EventKey<PlayerEvents>(EVENT);\
|
||||
if (!PlayerEventBindings->HasBindingsFor(key))\
|
||||
return;\
|
||||
LOCK_ELUNA
|
||||
|
||||
#define START_HOOK_WITH_RETVAL(EVENT, RETVAL) \
|
||||
if (!IsEnabled())\
|
||||
return RETVAL;\
|
||||
auto key = EventKey<PlayerEvents>(EVENT);\
|
||||
if (!PlayerEventBindings->HasBindingsFor(key))\
|
||||
return RETVAL;\
|
||||
LOCK_ELUNA
|
||||
|
||||
void Eluna::OnLearnTalents(Player* pPlayer, uint32 talentId, uint32 talentRank, uint32 spellid)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_LEARN_TALENTS);
|
||||
Push(pPlayer);
|
||||
Push(talentId);
|
||||
Push(talentRank);
|
||||
Push(spellid);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
bool Eluna::OnCommand(ChatHandler& handler, const char* text)
|
||||
{
|
||||
Player* player = handler.IsConsole() ? nullptr : handler.GetSession()->GetPlayer();
|
||||
// If from console, player is NULL
|
||||
if (!player || player->GetSession()->GetSecurity() >= SEC_ADMINISTRATOR)
|
||||
{
|
||||
std::string reload = text;
|
||||
std::transform(reload.begin(), reload.end(), reload.begin(), ::tolower);
|
||||
if (reload.find("reload eluna") == 0)
|
||||
{
|
||||
ReloadEluna();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_COMMAND, true);
|
||||
Push(player);
|
||||
Push(text);
|
||||
Push(&handler);
|
||||
return CallAllFunctionsBool(PlayerEventBindings, key, true);
|
||||
}
|
||||
|
||||
void Eluna::OnLootItem(Player* pPlayer, Item* pItem, uint32 count, ObjectGuid guid)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_LOOT_ITEM);
|
||||
Push(pPlayer);
|
||||
Push(pItem);
|
||||
Push(count);
|
||||
Push(guid);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnLootMoney(Player* pPlayer, uint32 amount)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_LOOT_MONEY);
|
||||
Push(pPlayer);
|
||||
Push(amount);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnFirstLogin(Player* pPlayer)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_FIRST_LOGIN);
|
||||
Push(pPlayer);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnRepop(Player* pPlayer)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_REPOP);
|
||||
Push(pPlayer);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnResurrect(Player* pPlayer)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_RESURRECT);
|
||||
Push(pPlayer);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnQuestAbandon(Player* pPlayer, uint32 questId)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_QUEST_ABANDON);
|
||||
Push(pPlayer);
|
||||
Push(questId);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnEquip(Player* pPlayer, Item* pItem, uint8 bag, uint8 slot)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_EQUIP);
|
||||
Push(pPlayer);
|
||||
Push(pItem);
|
||||
Push(bag);
|
||||
Push(slot);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
InventoryResult Eluna::OnCanUseItem(const Player* pPlayer, uint32 itemEntry)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_CAN_USE_ITEM, EQUIP_ERR_OK);
|
||||
InventoryResult result = EQUIP_ERR_OK;
|
||||
Push(pPlayer);
|
||||
Push(itemEntry);
|
||||
int n = SetupStack(PlayerEventBindings, key, 2);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 2, 1);
|
||||
|
||||
if (lua_isnumber(L, r))
|
||||
result = (InventoryResult)CHECKVAL<uint32>(L, r);
|
||||
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
CleanUpStack(2);
|
||||
return result;
|
||||
}
|
||||
void Eluna::OnPlayerEnterCombat(Player* pPlayer, Unit* pEnemy)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_ENTER_COMBAT);
|
||||
Push(pPlayer);
|
||||
Push(pEnemy);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnPlayerLeaveCombat(Player* pPlayer)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_LEAVE_COMBAT);
|
||||
Push(pPlayer);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnPVPKill(Player* pKiller, Player* pKilled)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_KILL_PLAYER);
|
||||
Push(pKiller);
|
||||
Push(pKilled);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnCreatureKill(Player* pKiller, Creature* pKilled)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_KILL_CREATURE);
|
||||
Push(pKiller);
|
||||
Push(pKilled);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnPlayerKilledByCreature(Creature* pKiller, Player* pKilled)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_KILLED_BY_CREATURE);
|
||||
Push(pKiller);
|
||||
Push(pKilled);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnLevelChanged(Player* pPlayer, uint8 oldLevel)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_LEVEL_CHANGE);
|
||||
Push(pPlayer);
|
||||
Push(oldLevel);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnFreeTalentPointsChanged(Player* pPlayer, uint32 newPoints)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_TALENTS_CHANGE);
|
||||
Push(pPlayer);
|
||||
Push(newPoints);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnTalentsReset(Player* pPlayer, bool noCost)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_TALENTS_RESET);
|
||||
Push(pPlayer);
|
||||
Push(noCost);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnMoneyChanged(Player* pPlayer, int32& amount)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_MONEY_CHANGE);
|
||||
Push(pPlayer);
|
||||
Push(amount);
|
||||
int amountIndex = lua_gettop(L);
|
||||
int n = SetupStack(PlayerEventBindings, key, 2);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 2, 1);
|
||||
|
||||
if (lua_isnumber(L, r))
|
||||
{
|
||||
amount = CHECKVAL<int32>(L, r);
|
||||
// Update the stack for subsequent calls.
|
||||
ReplaceArgument(amount, amountIndex);
|
||||
}
|
||||
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
CleanUpStack(2);
|
||||
}
|
||||
|
||||
void Eluna::OnGiveXP(Player* pPlayer, uint32& amount, Unit* pVictim, uint8 xpSource)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_GIVE_XP);
|
||||
Push(pPlayer);
|
||||
Push(amount);
|
||||
Push(pVictim);
|
||||
Push(xpSource);
|
||||
int amountIndex = lua_gettop(L) - 1;
|
||||
int n = SetupStack(PlayerEventBindings, key, 4);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 4, 1);
|
||||
|
||||
if (lua_isnumber(L, r))
|
||||
{
|
||||
amount = CHECKVAL<uint32>(L, r);
|
||||
// Update the stack for subsequent calls.
|
||||
ReplaceArgument(amount, amountIndex);
|
||||
}
|
||||
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
CleanUpStack(4);
|
||||
}
|
||||
|
||||
bool Eluna::OnReputationChange(Player* pPlayer, uint32 factionID, int32& standing, bool incremental)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_REPUTATION_CHANGE, true);
|
||||
bool result = true;
|
||||
Push(pPlayer);
|
||||
Push(factionID);
|
||||
Push(standing);
|
||||
Push(incremental);
|
||||
int standingIndex = lua_gettop(L) - 1;
|
||||
int n = SetupStack(PlayerEventBindings, key, 4);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 4, 1);
|
||||
|
||||
if (lua_isnumber(L, r))
|
||||
{
|
||||
standing = CHECKVAL<int32>(L, r);
|
||||
if (standing == -1)
|
||||
result = false;
|
||||
// Update the stack for subsequent calls.
|
||||
ReplaceArgument(standing, standingIndex);
|
||||
}
|
||||
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
CleanUpStack(4);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Eluna::OnDuelRequest(Player* pTarget, Player* pChallenger)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_DUEL_REQUEST);
|
||||
Push(pTarget);
|
||||
Push(pChallenger);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnDuelStart(Player* pStarter, Player* pChallenger)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_DUEL_START);
|
||||
Push(pStarter);
|
||||
Push(pChallenger);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnDuelEnd(Player* pWinner, Player* pLoser, DuelCompleteType type)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_DUEL_END);
|
||||
Push(pWinner);
|
||||
Push(pLoser);
|
||||
Push(type);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnEmote(Player* pPlayer, uint32 emote)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_EMOTE);
|
||||
Push(pPlayer);
|
||||
Push(emote);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnTextEmote(Player* pPlayer, uint32 textEmote, uint32 emoteNum, ObjectGuid guid)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_TEXT_EMOTE);
|
||||
Push(pPlayer);
|
||||
Push(textEmote);
|
||||
Push(emoteNum);
|
||||
Push(guid);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnSpellCast(Player* pPlayer, Spell* pSpell, bool skipCheck)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_SPELL_CAST);
|
||||
Push(pPlayer);
|
||||
Push(pSpell);
|
||||
Push(skipCheck);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnLogin(Player* pPlayer)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_LOGIN);
|
||||
Push(pPlayer);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnLogout(Player* pPlayer)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_LOGOUT);
|
||||
Push(pPlayer);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnCreate(Player* pPlayer)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_CHARACTER_CREATE);
|
||||
Push(pPlayer);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnDelete(uint32 guidlow)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_CHARACTER_DELETE);
|
||||
Push(guidlow);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnSave(Player* pPlayer)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_SAVE);
|
||||
Push(pPlayer);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnBindToInstance(Player* pPlayer, Difficulty difficulty, uint32 mapid, bool permanent)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_BIND_TO_INSTANCE);
|
||||
Push(pPlayer);
|
||||
Push(difficulty);
|
||||
Push(mapid);
|
||||
Push(permanent);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnUpdateArea(Player* pPlayer, uint32 oldArea, uint32 newArea)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_UPDATE_AREA);
|
||||
Push(pPlayer);
|
||||
Push(oldArea);
|
||||
Push(newArea);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_UPDATE_ZONE);
|
||||
Push(pPlayer);
|
||||
Push(newZone);
|
||||
Push(newArea);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnMapChanged(Player* player)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_MAP_CHANGE);
|
||||
Push(player);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg)
|
||||
{
|
||||
if (lang == LANG_ADDON)
|
||||
return OnAddonMessage(pPlayer, type, msg, NULL, NULL, NULL, NULL);
|
||||
|
||||
START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_CHAT, true);
|
||||
bool result = true;
|
||||
Push(pPlayer);
|
||||
Push(msg);
|
||||
Push(type);
|
||||
Push(lang);
|
||||
int n = SetupStack(PlayerEventBindings, key, 4);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 4, 2);
|
||||
|
||||
if (lua_isboolean(L, r + 0) && !lua_toboolean(L, r + 0))
|
||||
result = false;
|
||||
|
||||
if (lua_isstring(L, r + 1))
|
||||
msg = std::string(lua_tostring(L, r + 1));
|
||||
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
CleanUpStack(4);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Group* pGroup)
|
||||
{
|
||||
if (lang == LANG_ADDON)
|
||||
return OnAddonMessage(pPlayer, type, msg, NULL, NULL, pGroup, NULL);
|
||||
|
||||
START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_GROUP_CHAT, true);
|
||||
bool result = true;
|
||||
Push(pPlayer);
|
||||
Push(msg);
|
||||
Push(type);
|
||||
Push(lang);
|
||||
Push(pGroup);
|
||||
int n = SetupStack(PlayerEventBindings, key, 5);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 5, 2);
|
||||
|
||||
if (lua_isboolean(L, r + 0) && !lua_toboolean(L, r + 0))
|
||||
result = false;
|
||||
|
||||
if (lua_isstring(L, r + 1))
|
||||
msg = std::string(lua_tostring(L, r + 1));
|
||||
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
CleanUpStack(5);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Guild* pGuild)
|
||||
{
|
||||
if (lang == LANG_ADDON)
|
||||
return OnAddonMessage(pPlayer, type, msg, NULL, pGuild, NULL, NULL);
|
||||
|
||||
START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_GUILD_CHAT, true);
|
||||
bool result = true;
|
||||
Push(pPlayer);
|
||||
Push(msg);
|
||||
Push(type);
|
||||
Push(lang);
|
||||
Push(pGuild);
|
||||
int n = SetupStack(PlayerEventBindings, key, 5);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 5, 2);
|
||||
|
||||
if (lua_isboolean(L, r + 0) && !lua_toboolean(L, r + 0))
|
||||
result = false;
|
||||
|
||||
if (lua_isstring(L, r + 1))
|
||||
msg = std::string(lua_tostring(L, r + 1));
|
||||
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
CleanUpStack(5);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Channel* pChannel)
|
||||
{
|
||||
if (lang == LANG_ADDON)
|
||||
return OnAddonMessage(pPlayer, type, msg, NULL, NULL, NULL, pChannel);
|
||||
|
||||
START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_CHANNEL_CHAT, true);
|
||||
bool result = true;
|
||||
Push(pPlayer);
|
||||
Push(msg);
|
||||
Push(type);
|
||||
Push(lang);
|
||||
Push(pChannel->IsConstant() ? static_cast<int32>(pChannel->GetChannelId()) : -static_cast<int32>(pChannel->GetChannelDBId()));
|
||||
int n = SetupStack(PlayerEventBindings, key, 5);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 5, 2);
|
||||
|
||||
if (lua_isboolean(L, r + 0) && !lua_toboolean(L, r + 0))
|
||||
result = false;
|
||||
|
||||
if (lua_isstring(L, r + 1))
|
||||
msg = std::string(lua_tostring(L, r + 1));
|
||||
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
CleanUpStack(5);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Player* pReceiver)
|
||||
{
|
||||
if (lang == LANG_ADDON)
|
||||
return OnAddonMessage(pPlayer, type, msg, pReceiver, NULL, NULL, NULL);
|
||||
|
||||
START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_WHISPER, true);
|
||||
bool result = true;
|
||||
Push(pPlayer);
|
||||
Push(msg);
|
||||
Push(type);
|
||||
Push(lang);
|
||||
Push(pReceiver);
|
||||
int n = SetupStack(PlayerEventBindings, key, 5);
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int r = CallOneFunction(n--, 5, 2);
|
||||
|
||||
if (lua_isboolean(L, r + 0) && !lua_toboolean(L, r + 0))
|
||||
result = false;
|
||||
|
||||
if (lua_isstring(L, r + 1))
|
||||
msg = std::string(lua_tostring(L, r + 1));
|
||||
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
CleanUpStack(5);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Eluna::OnPetAddedToWorld(Player* player, Creature* pet)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_PET_ADDED_TO_WORLD);
|
||||
Push(player);
|
||||
Push(pet);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnLearnSpell(Player* player, uint32 spellId)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_LEARN_SPELL);
|
||||
Push(player);
|
||||
Push(spellId);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnAchiComplete(Player* player, AchievementEntry const* achievement)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_ACHIEVEMENT_COMPLETE);
|
||||
Push(player);
|
||||
Push(achievement);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnFfaPvpStateUpdate(Player* player, bool hasFfaPvp)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_FFAPVP_CHANGE);
|
||||
Push(player);
|
||||
Push(hasFfaPvp);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
bool Eluna::OnCanInitTrade(Player* player, Player* target)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_CAN_INIT_TRADE, true);
|
||||
Push(player);
|
||||
Push(target);
|
||||
return CallAllFunctionsBool(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
bool Eluna::OnCanSendMail(Player* player, ObjectGuid receiverGuid, ObjectGuid mailbox, std::string& subject, std::string& body, uint32 money, uint32 cod, Item* item)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_CAN_SEND_MAIL, true);
|
||||
Push(player);
|
||||
Push(receiverGuid);
|
||||
Push(mailbox);
|
||||
Push(subject);
|
||||
Push(body);
|
||||
Push(money);
|
||||
Push(cod);
|
||||
Push(item);
|
||||
return CallAllFunctionsBool(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
bool Eluna::OnCanJoinLfg(Player* player, uint8 roles, lfg::LfgDungeonSet& dungeons, const std::string& comment)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_CAN_JOIN_LFG, true);
|
||||
Push(player);
|
||||
Push(roles);
|
||||
|
||||
lua_newtable(L);
|
||||
int table = lua_gettop(L);
|
||||
uint32 counter = 1;
|
||||
for (uint32 dungeon : dungeons)
|
||||
{
|
||||
Eluna::Push(L, dungeon);
|
||||
lua_rawseti(L, table, counter);
|
||||
++counter;
|
||||
}
|
||||
lua_settop(L, table);
|
||||
++push_counter;
|
||||
|
||||
Push(comment);
|
||||
return CallAllFunctionsBool(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnQuestRewardItem(Player* player, Item* item, uint32 count)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_QUEST_REWARD_ITEM);
|
||||
Push(player);
|
||||
Push(item);
|
||||
Push(count);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnCreateItem(Player* player, Item* item, uint32 count)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_CREATE_ITEM);
|
||||
Push(player);
|
||||
Push(item);
|
||||
Push(count);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnStoreNewItem(Player* player, Item* item, uint32 count)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_STORE_NEW_ITEM);
|
||||
Push(player);
|
||||
Push(item);
|
||||
Push(count);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnPlayerCompleteQuest(Player* player, Quest const* quest)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_COMPLETE_QUEST);
|
||||
Push(player);
|
||||
Push(quest);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
bool Eluna::OnCanGroupInvite(Player* player, std::string& memberName)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_CAN_GROUP_INVITE, true);
|
||||
Push(player);
|
||||
Push(memberName);
|
||||
return CallAllFunctionsBool(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnGroupRollRewardItem(Player* player, Item* item, uint32 count, RollVote voteType, Roll* roll)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_GROUP_ROLL_REWARD_ITEM);
|
||||
Push(player);
|
||||
Push(item);
|
||||
Push(count);
|
||||
Push(voteType);
|
||||
Push(roll);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnBattlegroundDesertion(Player* player, const BattlegroundDesertionType type)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_BG_DESERTION);
|
||||
Push(player);
|
||||
Push(type);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnCreatureKilledByPet(Player* player, Creature* killed)
|
||||
{
|
||||
START_HOOK(PLAYER_EVENT_ON_PET_KILL);
|
||||
Push(player);
|
||||
Push(killed);
|
||||
CallAllFunctions(PlayerEventBindings, key);
|
||||
}
|
||||
397
src/LuaEngine/hooks/ServerHooks.cpp
Normal file
397
src/LuaEngine/hooks/ServerHooks.cpp
Normal file
@@ -0,0 +1,397 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
|
||||
* This program is free software licensed under GPL version 3
|
||||
* Please see the included DOCS/LICENSE.md for more information
|
||||
*/
|
||||
|
||||
#include "Hooks.h"
|
||||
#include "HookHelpers.h"
|
||||
#include "LuaEngine.h"
|
||||
#include "BindingMap.h"
|
||||
#include "ElunaEventMgr.h"
|
||||
#include "ElunaIncludes.h"
|
||||
#include "ElunaTemplate.h"
|
||||
|
||||
using namespace Hooks;
|
||||
|
||||
#define START_HOOK(EVENT) \
|
||||
if (!IsEnabled())\
|
||||
return;\
|
||||
auto key = EventKey<ServerEvents>(EVENT);\
|
||||
if (!ServerEventBindings->HasBindingsFor(key))\
|
||||
return;\
|
||||
LOCK_ELUNA
|
||||
|
||||
#define START_HOOK_WITH_RETVAL(EVENT, RETVAL) \
|
||||
if (!IsEnabled())\
|
||||
return RETVAL;\
|
||||
auto key = EventKey<ServerEvents>(EVENT);\
|
||||
if (!ServerEventBindings->HasBindingsFor(key))\
|
||||
return RETVAL;\
|
||||
LOCK_ELUNA
|
||||
|
||||
bool Eluna::OnAddonMessage(Player* sender, uint32 type, std::string& msg, Player* receiver, Guild* guild, Group* group, Channel* channel)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(ADDON_EVENT_ON_MESSAGE, true);
|
||||
Push(sender);
|
||||
Push(type);
|
||||
|
||||
auto delimeter_position = msg.find('\t');
|
||||
if (delimeter_position == std::string::npos)
|
||||
{
|
||||
Push(msg); // prefix
|
||||
Push(); // msg
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string prefix = msg.substr(0, delimeter_position);
|
||||
std::string content = msg.substr(delimeter_position + 1, std::string::npos);
|
||||
Push(prefix);
|
||||
Push(content);
|
||||
}
|
||||
|
||||
if (receiver)
|
||||
Push(receiver);
|
||||
else if (guild)
|
||||
Push(guild);
|
||||
else if (group)
|
||||
Push(group);
|
||||
else if (channel)
|
||||
Push(channel->GetChannelId());
|
||||
else
|
||||
Push();
|
||||
|
||||
return CallAllFunctionsBool(ServerEventBindings, key, true);
|
||||
}
|
||||
|
||||
void Eluna::OnTimedEvent(int funcRef, uint32 delay, uint32 calls, WorldObject* obj)
|
||||
{
|
||||
LOCK_ELUNA;
|
||||
ASSERT(!event_level);
|
||||
|
||||
// Get function
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, funcRef);
|
||||
|
||||
// Push parameters
|
||||
Push(L, funcRef);
|
||||
Push(L, delay);
|
||||
Push(L, calls);
|
||||
Push(L, obj);
|
||||
|
||||
// Call function
|
||||
ExecuteCall(4, 0);
|
||||
|
||||
ASSERT(!event_level);
|
||||
InvalidateObjects();
|
||||
}
|
||||
|
||||
void Eluna::OnGameEventStart(uint32 eventid)
|
||||
{
|
||||
START_HOOK(GAME_EVENT_START);
|
||||
Push(eventid);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnGameEventStop(uint32 eventid)
|
||||
{
|
||||
START_HOOK(GAME_EVENT_STOP);
|
||||
Push(eventid);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnLuaStateClose()
|
||||
{
|
||||
START_HOOK(ELUNA_EVENT_ON_LUA_STATE_CLOSE);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnLuaStateOpen()
|
||||
{
|
||||
START_HOOK(ELUNA_EVENT_ON_LUA_STATE_OPEN);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
// AreaTrigger
|
||||
bool Eluna::OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* pTrigger)
|
||||
{
|
||||
START_HOOK_WITH_RETVAL(TRIGGER_EVENT_ON_TRIGGER, false);
|
||||
Push(pPlayer);
|
||||
#ifdef TRINITY
|
||||
Push(pTrigger->ID);
|
||||
#elif AZEROTHCORE
|
||||
Push(pTrigger->entry);
|
||||
#else
|
||||
Push(pTrigger->id);
|
||||
|
||||
#endif
|
||||
return CallAllFunctionsBool(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
// Weather
|
||||
void Eluna::OnChange(Weather* /*weather*/, uint32 zone, WeatherState state, float grade)
|
||||
{
|
||||
START_HOOK(WEATHER_EVENT_ON_CHANGE);
|
||||
Push(zone);
|
||||
Push(state);
|
||||
Push(grade);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
// Auction House
|
||||
void Eluna::OnAdd(AuctionHouseObject* /*ah*/, AuctionEntry* entry)
|
||||
{
|
||||
#ifdef AZEROTHCORE
|
||||
Player* owner = eObjectAccessor()FindPlayer(entry->owner);
|
||||
#else
|
||||
Player* owner = eObjectAccessor()FindPlayer(MAKE_NEW_GUID(entry->owner, 0, HIGHGUID_PLAYER));
|
||||
#endif
|
||||
|
||||
#ifdef TRINITY
|
||||
Item* item = eAuctionMgr->GetAItem(entry->itemGUIDLow);
|
||||
uint32 expiretime = entry->expire_time;
|
||||
#elif AZEROTHCORE
|
||||
Item* item = eAuctionMgr->GetAItem(entry->item_guid);
|
||||
uint32 expiretime = entry->expire_time;
|
||||
#else
|
||||
Item* item = eAuctionMgr->GetAItem(entry->itemGuidLow);
|
||||
uint32 expiretime = entry->expireTime;
|
||||
#endif
|
||||
|
||||
if (!owner || !item)
|
||||
return;
|
||||
|
||||
START_HOOK(AUCTION_EVENT_ON_ADD);
|
||||
Push(entry->Id);
|
||||
Push(owner);
|
||||
Push(item);
|
||||
Push(expiretime);
|
||||
Push(entry->buyout);
|
||||
Push(entry->startbid);
|
||||
Push(entry->bid);
|
||||
Push(entry->bidder);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnRemove(AuctionHouseObject* /*ah*/, AuctionEntry* entry)
|
||||
{
|
||||
#ifdef AZEROTHCORE
|
||||
Player* owner = eObjectAccessor()FindPlayer(entry->owner);
|
||||
#else
|
||||
Player* owner = eObjectAccessor()FindPlayer(MAKE_NEW_GUID(entry->owner, 0, HIGHGUID_PLAYER));
|
||||
#endif
|
||||
|
||||
#ifdef TRINITY
|
||||
Item* item = eAuctionMgr->GetAItem(entry->itemGUIDLow);
|
||||
uint32 expiretime = entry->expire_time;
|
||||
#elif AZEROTHCORE
|
||||
Item* item = eAuctionMgr->GetAItem(entry->item_guid);
|
||||
uint32 expiretime = entry->expire_time;
|
||||
#else
|
||||
Item* item = eAuctionMgr->GetAItem(entry->itemGuidLow);
|
||||
uint32 expiretime = entry->expireTime;
|
||||
#endif
|
||||
|
||||
|
||||
if (!owner || !item)
|
||||
return;
|
||||
|
||||
START_HOOK(AUCTION_EVENT_ON_REMOVE);
|
||||
Push(entry->Id);
|
||||
Push(owner);
|
||||
Push(item);
|
||||
Push(expiretime);
|
||||
Push(entry->buyout);
|
||||
Push(entry->startbid);
|
||||
Push(entry->bid);
|
||||
Push(entry->bidder);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnSuccessful(AuctionHouseObject* /*ah*/, AuctionEntry* entry)
|
||||
{
|
||||
#ifdef AZEROTHCORE
|
||||
Player* owner = eObjectAccessor()FindPlayer(entry->owner);
|
||||
#else
|
||||
Player* owner = eObjectAccessor()FindPlayer(MAKE_NEW_GUID(entry->owner, 0, HIGHGUID_PLAYER));
|
||||
#endif
|
||||
|
||||
#ifdef TRINITY
|
||||
Item* item = eAuctionMgr->GetAItem(entry->itemGUIDLow);
|
||||
uint32 expiretime = entry->expire_time;
|
||||
#elif AZEROTHCORE
|
||||
Item* item = eAuctionMgr->GetAItem(entry->item_guid);
|
||||
uint32 expiretime = entry->expire_time;
|
||||
#else
|
||||
Item* item = eAuctionMgr->GetAItem(entry->itemGuidLow);
|
||||
uint32 expiretime = entry->expireTime;
|
||||
#endif
|
||||
|
||||
|
||||
if (!owner || !item)
|
||||
return;
|
||||
|
||||
START_HOOK(AUCTION_EVENT_ON_SUCCESSFUL);
|
||||
Push(entry->Id);
|
||||
Push(owner);
|
||||
Push(item);
|
||||
Push(expiretime);
|
||||
Push(entry->buyout);
|
||||
Push(entry->startbid);
|
||||
Push(entry->bid);
|
||||
Push(entry->bidder);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnExpire(AuctionHouseObject* /*ah*/, AuctionEntry* entry)
|
||||
{
|
||||
#ifdef AZEROTHCORE
|
||||
Player* owner = eObjectAccessor()FindPlayer(entry->owner);
|
||||
#else
|
||||
Player* owner = eObjectAccessor()FindPlayer(MAKE_NEW_GUID(entry->owner, 0, HIGHGUID_PLAYER));
|
||||
#endif
|
||||
|
||||
#ifdef TRINITY
|
||||
Item* item = eAuctionMgr->GetAItem(entry->itemGUIDLow);
|
||||
uint32 expiretime = entry->expire_time;
|
||||
#elif AZEROTHCORE
|
||||
Item* item = eAuctionMgr->GetAItem(entry->item_guid);
|
||||
uint32 expiretime = entry->expire_time;
|
||||
#else
|
||||
Item* item = eAuctionMgr->GetAItem(entry->itemGuidLow);
|
||||
uint32 expiretime = entry->expireTime;
|
||||
#endif
|
||||
|
||||
|
||||
if (!owner || !item)
|
||||
return;
|
||||
|
||||
START_HOOK(AUCTION_EVENT_ON_EXPIRE);
|
||||
Push(entry->Id);
|
||||
Push(owner);
|
||||
Push(item);
|
||||
Push(expiretime);
|
||||
Push(entry->buyout);
|
||||
Push(entry->startbid);
|
||||
Push(entry->bid);
|
||||
Push(entry->bidder);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnOpenStateChange(bool open)
|
||||
{
|
||||
START_HOOK(WORLD_EVENT_ON_OPEN_STATE_CHANGE);
|
||||
Push(open);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
#ifndef AZEROTHCORE
|
||||
void Eluna::OnConfigLoad(bool reload)
|
||||
#else
|
||||
void Eluna::OnConfigLoad(bool reload, bool isBefore)
|
||||
#endif
|
||||
{
|
||||
START_HOOK(WORLD_EVENT_ON_CONFIG_LOAD);
|
||||
Push(reload);
|
||||
#ifdef AZEROTHCORE
|
||||
Push(isBefore);
|
||||
#endif
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask)
|
||||
{
|
||||
START_HOOK(WORLD_EVENT_ON_SHUTDOWN_INIT);
|
||||
Push(code);
|
||||
Push(mask);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnShutdownCancel()
|
||||
{
|
||||
START_HOOK(WORLD_EVENT_ON_SHUTDOWN_CANCEL);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnWorldUpdate(uint32 diff)
|
||||
{
|
||||
{
|
||||
LOCK_ELUNA;
|
||||
if (ShouldReload())
|
||||
_ReloadEluna();
|
||||
}
|
||||
|
||||
eventMgr->globalProcessor->Update(diff);
|
||||
httpManager.HandleHttpResponses();
|
||||
queryProcessor.ProcessReadyCallbacks();
|
||||
|
||||
START_HOOK(WORLD_EVENT_ON_UPDATE);
|
||||
Push(diff);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnStartup()
|
||||
{
|
||||
START_HOOK(WORLD_EVENT_ON_STARTUP);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnShutdown()
|
||||
{
|
||||
START_HOOK(WORLD_EVENT_ON_SHUTDOWN);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
/* Map */
|
||||
void Eluna::OnCreate(Map* map)
|
||||
{
|
||||
START_HOOK(MAP_EVENT_ON_CREATE);
|
||||
Push(map);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnDestroy(Map* map)
|
||||
{
|
||||
START_HOOK(MAP_EVENT_ON_DESTROY);
|
||||
Push(map);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnPlayerEnter(Map* map, Player* player)
|
||||
{
|
||||
START_HOOK(MAP_EVENT_ON_PLAYER_ENTER);
|
||||
Push(map);
|
||||
Push(player);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnPlayerLeave(Map* map, Player* player)
|
||||
{
|
||||
START_HOOK(MAP_EVENT_ON_PLAYER_LEAVE);
|
||||
Push(map);
|
||||
Push(player);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnUpdate(Map* map, uint32 diff)
|
||||
{
|
||||
START_HOOK(MAP_EVENT_ON_UPDATE);
|
||||
// enable this for multithread
|
||||
// eventMgr->globalProcessor->Update(diff);
|
||||
Push(map);
|
||||
Push(diff);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnRemove(GameObject* gameobject)
|
||||
{
|
||||
START_HOOK(WORLD_EVENT_ON_DELETE_GAMEOBJECT);
|
||||
Push(gameobject);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnRemove(Creature* creature)
|
||||
{
|
||||
START_HOOK(WORLD_EVENT_ON_DELETE_CREATURE);
|
||||
Push(creature);
|
||||
CallAllFunctions(ServerEventBindings, key);
|
||||
}
|
||||
66
src/LuaEngine/hooks/VehicleHooks.cpp
Normal file
66
src/LuaEngine/hooks/VehicleHooks.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
|
||||
* This program is free software licensed under GPL version 3
|
||||
* Please see the included DOCS/LICENSE.md for more information
|
||||
*/
|
||||
|
||||
#include "Hooks.h"
|
||||
#include "HookHelpers.h"
|
||||
#include "LuaEngine.h"
|
||||
#include "BindingMap.h"
|
||||
#include "ElunaTemplate.h"
|
||||
|
||||
#ifndef CLASSIC
|
||||
#ifndef TBC
|
||||
|
||||
using namespace Hooks;
|
||||
|
||||
#define START_HOOK(EVENT) \
|
||||
if (!IsEnabled())\
|
||||
return;\
|
||||
auto key = EventKey<VehicleEvents>(EVENT);\
|
||||
if (!VehicleEventBindings->HasBindingsFor(key))\
|
||||
return;\
|
||||
LOCK_ELUNA
|
||||
|
||||
void Eluna::OnInstall(Vehicle* vehicle)
|
||||
{
|
||||
START_HOOK(VEHICLE_EVENT_ON_INSTALL);
|
||||
Push(vehicle);
|
||||
CallAllFunctions(VehicleEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnUninstall(Vehicle* vehicle)
|
||||
{
|
||||
START_HOOK(VEHICLE_EVENT_ON_UNINSTALL);
|
||||
Push(vehicle);
|
||||
CallAllFunctions(VehicleEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnInstallAccessory(Vehicle* vehicle, Creature* accessory)
|
||||
{
|
||||
START_HOOK(VEHICLE_EVENT_ON_INSTALL_ACCESSORY);
|
||||
Push(vehicle);
|
||||
Push(accessory);
|
||||
CallAllFunctions(VehicleEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnAddPassenger(Vehicle* vehicle, Unit* passenger, int8 seatId)
|
||||
{
|
||||
START_HOOK(VEHICLE_EVENT_ON_ADD_PASSENGER);
|
||||
Push(vehicle);
|
||||
Push(passenger);
|
||||
Push(seatId);
|
||||
CallAllFunctions(VehicleEventBindings, key);
|
||||
}
|
||||
|
||||
void Eluna::OnRemovePassenger(Vehicle* vehicle, Unit* passenger)
|
||||
{
|
||||
START_HOOK(VEHICLE_EVENT_ON_REMOVE_PASSENGER);
|
||||
Push(vehicle);
|
||||
Push(passenger);
|
||||
CallAllFunctions(VehicleEventBindings, key);
|
||||
}
|
||||
|
||||
#endif // CLASSIC
|
||||
#endif // TBC
|
||||
Reference in New Issue
Block a user