Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ElunaConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class ElunaConfig
const uint32& GetConfig(ElunaConfigUInt32Values index) const { return _configUInt32Values[index]; }

bool IsElunaEnabled() { return GetConfig(CONFIG_ELUNA_ENABLED); }
bool IsElunaCompatibilityMode() { return false; }
bool UnsafeMethodsEnabled() { return GetConfig(CONFIG_ELUNA_ENABLE_UNSAFE); }
bool DeprecatedMethodsEnabled() { return GetConfig(CONFIG_ELUNA_ENABLE_DEPRECATED); }
bool IsReloadCommandEnabled() { return GetConfig(CONFIG_ELUNA_ENABLE_RELOAD_COMMAND); }
Expand Down
2 changes: 1 addition & 1 deletion ElunaEventMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ ElunaEventProcessor* EventMgr::GetGlobalProcessor(GlobalEventSpace space)

uint64 EventMgr::CreateObjectProcessor(WorldObject* obj)
{
#if !ELUNA_CMANGOS && !ELUNA_VMANGOS
#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
uint64 id = obj->GetGUID().GetRawValue();
#else
uint64 id = obj->GetObjectGuid().GetRawValue();
Expand Down
1 change: 0 additions & 1 deletion ElunaIncludes.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include "ScriptMgr.h"
#include "Spell.h"
#include "SpellAuras.h"
#include "SpellAuraEffects.h"
#include "SpellMgr.h"
#include "TemporarySummon.h"
#include "WorldPacket.h"
Expand Down
13 changes: 12 additions & 1 deletion ElunaSpellWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ElunaProcInfo::ElunaProcInfo(Unit* actor, Unit* actionTarget, uint32 typeMask,
{
}

#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
ElunaProcInfo::ElunaProcInfo(ProcEventInfo& procInfo, Map* map)
: _actor(procInfo.GetActor()), _actionTarget(procInfo.GetActionTarget()), _typeMask(procInfo.GetTypeMask()), _spellTypeMask(procInfo.GetSpellTypeMask()), _spellPhaseMask(procInfo.GetSpellPhaseMask())
, _hitMask(procInfo.GetHitMask()), _spell(const_cast<Spell*>(procInfo.GetProcSpell())), _spellInfo(procInfo.GetSpellInfo()), _schoolMask(procInfo.GetSchoolMask()), _damage(0)
Expand Down Expand Up @@ -58,13 +59,16 @@ ElunaProcInfo::ElunaProcInfo(ProcEventInfo& procInfo, Map* map)
}
}
}
#endif

SpellInfo const* ElunaProcInfo::GetSpellInfo() const
{
if (_spellInfo)
return _spellInfo;
#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
if (_spell)
return _spell->GetSpellInfo();
#endif
return nullptr;
}

Expand All @@ -81,6 +85,7 @@ void ElunaProcInfo::SetHeal(uint32 heal)
_effectiveHeal = heal;
}

#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
void ElunaProcInfo::ApplyToProcEventInfo(ProcEventInfo& procInfo) const
{
if (DamageInfo* damageInfo = procInfo.GetDamageInfo())
Expand Down Expand Up @@ -122,9 +127,15 @@ void ElunaProcInfo::ApplyToProcEventInfo(ProcEventInfo& procInfo) const
}
}
}
#endif

ElunaSpellInfo::ElunaSpellInfo(uint32 spellId) : _spellInfo(sSpellMgr->GetSpellInfo(spellId))
ElunaSpellInfo::ElunaSpellInfo(uint32 spellId) : _spellInfo(nullptr)
{
#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
_spellInfo = sSpellMgr->GetSpellInfo(spellId);
#else
_spellInfo = sSpellStore.LookupEntry(spellId);
#endif
#ifdef ELUNA_TRINITY
if (_spellInfo)
m_scriptRef = Trinity::unique_trackable_ptr<ElunaSpellInfo>(this, NoopAuraDeleter());
Expand Down
13 changes: 12 additions & 1 deletion ElunaSpellWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@
class Unit;
class Spell;
class Map;
class SpellInfo;
#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
class ProcEventInfo;
class DamageInfo;
class HealInfo;
#endif
#ifdef ELUNA_TRINITY
enum SpellSchoolMask : uint32;
#else
enum SpellSchoolMask;
#endif
enum DamageEffectType : uint8;
enum WeaponAttackType : uint8;

#if !defined(ELUNA_TRINITY) && !defined(ELUNA_AZEROTHCORE)
// For non-Trinity/AzerothCore builds, ensure SpellEntry/SpellInfo is declared
struct SpellEntry;
typedef SpellEntry SpellInfo;
#endif
#ifdef ELUNA_TRINITY
namespace Trinity
{
Expand Down Expand Up @@ -67,7 +74,9 @@ class ElunaProcInfo
uint32 spellTypeMask, uint32 spellPhaseMask, uint32 hitMask,
Spell* spell, SpellInfo const* spellInfo, SpellSchoolMask schoolMask, Map* map);

#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
explicit ElunaProcInfo(ProcEventInfo& procInfo, Map* map);
#endif
~ElunaProcInfo()
{
#ifdef TRACKABLE_PTR_NAMESPACE
Expand Down Expand Up @@ -115,7 +124,9 @@ class ElunaProcInfo
#ifdef ELUNA_TRINITY
Trinity::unique_weak_ptr<ElunaProcInfo> GetWeakPtr() const { return m_scriptRef; }
#endif
#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
void ApplyToProcEventInfo(ProcEventInfo& procInfo) const;
#endif
};

class ElunaSpellInfo
Expand Down
9 changes: 9 additions & 0 deletions LuaEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include <mutex>
#include <memory>
#include <array>
#include "ElunaSpellWrapper.h"

extern "C"
Expand Down Expand Up @@ -640,6 +641,7 @@ class ELUNA_GAME_API Eluna

/* Spell */
void OnSpellCast(Spell* pSpell, bool skipCheck);
#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
bool OnAuraApplication(Aura* aura, AuraEffect const* auraEff, Unit* target, uint8 mode, bool apply);
void OnAuraDispel(Aura* aura, DispelInfo* dispelInfo);
bool OnPeriodicTick(Aura* aura, AuraEffect const* auraEff, Unit* target);
Expand All @@ -648,20 +650,27 @@ class ELUNA_GAME_API Eluna
void OnCalcPeriodic(Aura* aura, AuraEffect const* auraEff, bool& isPeriodic, int32& amplitude);
bool OnAuraCanProc(Aura* aura, ProcEventInfo& procInfo);
bool OnAuraProc(Aura* aura, ProcEventInfo& procInfo);
#endif
uint32 OnCheckCast(Spell* pSpell);
void OnBeforeCast(Spell* pSpell);
void OnAfterCast(Spell* pSpell);
void OnObjectAreaTargetSelect(Spell* pSpell, uint8 effIndex, std::list<WorldObject*>& targets);
void OnObjectTargetSelect(Spell* pSpell, uint8 effIndex, WorldObject*& target);
#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
void OnDestinationTargetSelect(Spell* pSpell, uint8 effIndex, SpellDestination& target);
#endif
bool OnEffectLaunch(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault);
bool OnEffectLaunchTarget(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault);
bool OnEffectHit(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault);
bool OnEffectHitTarget(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault);
void OnBeforeSpellHit(Spell* pSpell, uint8 missInfo);
void OnSpellHit(Spell* pSpell);
void OnAfterSpellHit(Spell* pSpell);
#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
void OnEffectCalcAbsorb(Spell* pSpell, DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount);
#else
void OnEffectCalcAbsorb(Spell* pSpell, void const* damageInfo, uint32& resistAmount, int32& absorbAmount);
#endif
};
template<> Unit* Eluna::CHECKOBJ<Unit>(int narg, bool error);
template<> Object* Eluna::CHECKOBJ<Object>(int narg, bool error);
Expand Down
79 changes: 78 additions & 1 deletion hooks/SpellHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

using namespace Hooks;

#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
#define START_HOOK(EVENT, SPELL) \
auto binding = GetBinding<EntryKey<SpellEvents>>(REGTYPE_SPELL);\
auto key = EntryKey<SpellEvents>(EVENT, SPELL->GetSpellInfo()->Id);\
Expand All @@ -32,7 +33,16 @@ void Eluna::OnSpellCast(Spell* pSpell, bool skipCheck)
HookPush(skipCheck);
CallAllFunctions(binding, key);
}
#else
void Eluna::OnSpellCast(Spell* pSpell, bool skipCheck)
{
// MaNGOS - no spell hook support
}
#endif

#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE

#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
bool Eluna::OnAuraApplication(Aura* aura, AuraEffect const* auraEff, Unit* target, uint8 mode, bool apply)
{
START_HOOK_WITH_RETVAL(SPELL_EVENT_ON_AURA_APPLICATION, aura, false);
Expand Down Expand Up @@ -134,14 +144,20 @@ bool Eluna::OnAuraProc(Aura* aura, ProcEventInfo& procInfo)
luaProcInfo.ApplyToProcEventInfo(procInfo);
return defaultPrevented;
}
#endif

uint32 Eluna::OnCheckCast(Spell* pSpell)
{
#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
START_HOOK_WITH_RETVAL(SPELL_EVENT_ON_CHECK_CAST, pSpell, SPELL_CAST_OK);
HookPush(pSpell);
return static_cast<uint32>(CallAllFunctionsInt(binding, key, int32(SPELL_CAST_OK)));
#else
return SPELL_CAST_OK;
#endif
}

#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
void Eluna::OnBeforeCast(Spell* pSpell)
{
START_HOOK(SPELL_EVENT_ON_BEFORE_CAST, pSpell);
Expand Down Expand Up @@ -175,6 +191,7 @@ void Eluna::OnObjectTargetSelect(Spell* pSpell, uint8 effIndex, WorldObject*& ta

void Eluna::OnDestinationTargetSelect(Spell* pSpell, uint8 effIndex, SpellDestination& target)
{
#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
START_HOOK(SPELL_EVENT_ON_DEST_TARGET, pSpell);
HookPush(pSpell);
HookPush(effIndex);
Expand Down Expand Up @@ -207,8 +224,10 @@ void Eluna::OnDestinationTargetSelect(Spell* pSpell, uint8 effIndex, SpellDestin
target._position.m_positionY = posY;
target._position.m_positionZ = posZ;
target._position.SetOrientation(orientation);
#endif
}

#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
bool Eluna::OnEffectLaunch(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault)
{
START_HOOK_WITH_RETVAL(SPELL_EVENT_ON_EFFECT_LAUNCH, pSpell, preventDefault);
Expand Down Expand Up @@ -269,7 +288,61 @@ void Eluna::OnAfterSpellHit(Spell* pSpell)
HookPush(pSpell);
CallAllFunctions(binding, key);
}

#else
void Eluna::OnBeforeCast(Spell* pSpell) {}
void Eluna::OnAfterCast(Spell* pSpell) {}
void Eluna::OnObjectAreaTargetSelect(Spell* pSpell, uint8 effIndex, std::list<WorldObject*>& targets) {}
void Eluna::OnObjectTargetSelect(Spell* pSpell, uint8 effIndex, WorldObject*& target) {}
bool Eluna::OnEffectLaunch(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault) { return preventDefault; }
bool Eluna::OnEffectLaunchTarget(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault) { return preventDefault; }
bool Eluna::OnEffectHit(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault) { return preventDefault; }
bool Eluna::OnEffectHitTarget(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault) { return preventDefault; }
void Eluna::OnBeforeSpellHit(Spell* pSpell, uint8 missInfo) {}
void Eluna::OnSpellHit(Spell* pSpell) {}
void Eluna::OnAfterSpellHit(Spell* pSpell) {}
#endif

#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
void Eluna::OnEffectCalcAbsorb(Spell* pSpell, DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount)
{
START_HOOK(SPELL_EVENT_ON_EFFECT_CALC_ABSORB, pSpell);
HookPush(pSpell);
HookPush(damageInfo.GetAttacker());
HookPush(damageInfo.GetVictim());
HookPush(damageInfo.GetDamage());
HookPush(damageInfo.GetAbsorb());
HookPush(damageInfo.GetResist());
HookPush(damageInfo.GetBlock());
HookPush(static_cast<uint32>(damageInfo.GetSchoolMask()));
HookPush(static_cast<uint32>(damageInfo.GetDamageType()));
HookPush(static_cast<uint32>(damageInfo.GetAttackType()));
HookPush(damageInfo.GetHitMask());
HookPush(resistAmount);
int resistIndex = lua_gettop(L);
HookPush(absorbAmount);
int absorbIndex = lua_gettop(L);
CallAllFunctionsMultiReturn(
binding,
key,
std::tie(resistAmount, absorbAmount),
std::array<int, 2>{ resistIndex, absorbIndex }
);
}
#else
void Eluna::OnEffectCalcAbsorb(Spell* pSpell, void const* damageInfo, uint32& resistAmount, int32& absorbAmount) {}
#endif

void Eluna::OnObjectTargetSelect(Spell* pSpell, uint8 effIndex, WorldObject*& target) {}
bool Eluna::OnEffectLaunch(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault) { return preventDefault; }
bool Eluna::OnEffectLaunchTarget(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault) { return preventDefault; }
bool Eluna::OnEffectHit(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault) { return preventDefault; }
bool Eluna::OnEffectHitTarget(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault) { return preventDefault; }
void Eluna::OnBeforeSpellHit(Spell* pSpell, uint8 missInfo) {}
void Eluna::OnSpellHit(Spell* pSpell) {}
void Eluna::OnAfterSpellHit(Spell* pSpell) {}
#endif

#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE
void Eluna::OnEffectCalcAbsorb(Spell* pSpell, DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount)
{
START_HOOK(SPELL_EVENT_ON_EFFECT_CALC_ABSORB, pSpell);
Expand All @@ -295,3 +368,7 @@ void Eluna::OnEffectCalcAbsorb(Spell* pSpell, DamageInfo const& damageInfo, uint
std::array<int, 2>{ resistIndex, absorbIndex }
);
}
#else
void Eluna::OnEffectCalcAbsorb(Spell* pSpell, void const* damageInfo, uint32& resistAmount, int32& absorbAmount) {}
#endif
#endif
42 changes: 26 additions & 16 deletions methods/Mangos/WorldObjectMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -768,16 +768,28 @@ namespace LuaWorldObject
int functionRef = luaL_ref(E->L, LUA_REGISTRYINDEX);
if (functionRef != LUA_REFNIL && functionRef != LUA_NOREF)
{
ElunaEventProcessor* proc = obj->GetElunaEvents(E->GetBoundMapId());
if (!proc)
// For MaNGOS, we need to get the event manager from Eluna
// Objects don't have direct event processor access
if (E && E->eventMgr)
{
uint64 procId = E->eventMgr->CreateObjectProcessor(obj);
ElunaEventProcessor* proc = E->eventMgr->GetObjectProcessor(procId);
if (proc)
{
proc->AddEvent(functionRef, min, max, repeats);
E->Push(functionRef);
}
else
{
luaL_unref(E->L, LUA_REGISTRYINDEX, functionRef);
E->Push();
}
}
else
{
luaL_unref(E->L, LUA_REGISTRYINDEX, functionRef);
E->Push();
return 1;
}

proc->AddEvent(functionRef, min, max, repeats);
E->Push(functionRef);
}
return 1;
}
Expand All @@ -790,12 +802,11 @@ namespace LuaWorldObject
int RemoveEventById(Eluna* E, WorldObject* obj)
{
int eventId = E->CHECKVAL<int>(2);

ElunaEventProcessor* proc = obj->GetElunaEvents(E->GetBoundMapId());
if (!proc)
return 0;

proc->SetState(eventId, LUAEVENT_STATE_ABORT);
if (E && E->eventMgr)
{
E->eventMgr->SetEventState(eventId, LUAEVENT_STATE_ABORT);
}
return 0;
}

Expand All @@ -805,11 +816,10 @@ namespace LuaWorldObject
*/
int RemoveEvents(Eluna* E, WorldObject* obj)
{
ElunaEventProcessor* proc = obj->GetElunaEvents(E->GetBoundMapId());
if (!proc)
return 0;

proc->SetStates(LUAEVENT_STATE_ABORT);
if (E && E->eventMgr)
{
E->eventMgr->SetAllEventStates(LUAEVENT_STATE_ABORT);
}
return 0;
}

Expand Down
Loading