diff --git a/ElunaConfig.h b/ElunaConfig.h index 87acc3820e..72242311cd 100644 --- a/ElunaConfig.h +++ b/ElunaConfig.h @@ -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); } diff --git a/ElunaEventMgr.cpp b/ElunaEventMgr.cpp index 2dd0c5fcc3..80e92e42ee 100644 --- a/ElunaEventMgr.cpp +++ b/ElunaEventMgr.cpp @@ -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(); diff --git a/ElunaIncludes.h b/ElunaIncludes.h index 3d4a82dbff..c5a2c88bd8 100644 --- a/ElunaIncludes.h +++ b/ElunaIncludes.h @@ -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" diff --git a/ElunaSpellWrapper.cpp b/ElunaSpellWrapper.cpp index 828cf882b7..a865cd4d61 100644 --- a/ElunaSpellWrapper.cpp +++ b/ElunaSpellWrapper.cpp @@ -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(procInfo.GetProcSpell())), _spellInfo(procInfo.GetSpellInfo()), _schoolMask(procInfo.GetSchoolMask()), _damage(0) @@ -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; } @@ -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()) @@ -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(this, NoopAuraDeleter()); diff --git a/ElunaSpellWrapper.h b/ElunaSpellWrapper.h index dcb3be662f..2e648772f3 100644 --- a/ElunaSpellWrapper.h +++ b/ElunaSpellWrapper.h @@ -9,10 +9,11 @@ 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 @@ -20,6 +21,12 @@ 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 { @@ -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 @@ -115,7 +124,9 @@ class ElunaProcInfo #ifdef ELUNA_TRINITY Trinity::unique_weak_ptr GetWeakPtr() const { return m_scriptRef; } #endif +#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE void ApplyToProcEventInfo(ProcEventInfo& procInfo) const; +#endif }; class ElunaSpellInfo diff --git a/LuaEngine.h b/LuaEngine.h index e5abf85619..585549a335 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -36,6 +36,7 @@ #include #include +#include #include "ElunaSpellWrapper.h" extern "C" @@ -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); @@ -648,12 +650,15 @@ 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& 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); @@ -661,7 +666,11 @@ class ELUNA_GAME_API Eluna 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(int narg, bool error); template<> Object* Eluna::CHECKOBJ(int narg, bool error); diff --git a/hooks/SpellHooks.cpp b/hooks/SpellHooks.cpp index 08399067c8..3a25b72a46 100644 --- a/hooks/SpellHooks.cpp +++ b/hooks/SpellHooks.cpp @@ -13,6 +13,7 @@ using namespace Hooks; +#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE #define START_HOOK(EVENT, SPELL) \ auto binding = GetBinding>(REGTYPE_SPELL);\ auto key = EntryKey(EVENT, SPELL->GetSpellInfo()->Id);\ @@ -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); @@ -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(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); @@ -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); @@ -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); @@ -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& 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(damageInfo.GetSchoolMask())); + HookPush(static_cast(damageInfo.GetDamageType())); + HookPush(static_cast(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{ 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); @@ -295,3 +368,7 @@ void Eluna::OnEffectCalcAbsorb(Spell* pSpell, DamageInfo const& damageInfo, uint std::array{ resistIndex, absorbIndex } ); } +#else +void Eluna::OnEffectCalcAbsorb(Spell* pSpell, void const* damageInfo, uint32& resistAmount, int32& absorbAmount) {} +#endif +#endif \ No newline at end of file diff --git a/methods/Mangos/WorldObjectMethods.h b/methods/Mangos/WorldObjectMethods.h index 675812bc21..8ee8762c19 100644 --- a/methods/Mangos/WorldObjectMethods.h +++ b/methods/Mangos/WorldObjectMethods.h @@ -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; } @@ -790,12 +802,11 @@ namespace LuaWorldObject int RemoveEventById(Eluna* E, WorldObject* obj) { int eventId = E->CHECKVAL(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; } @@ -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; } diff --git a/methods/Methods.cpp b/methods/Methods.cpp index ba096513fe..6d54cb66fd 100644 --- a/methods/Methods.cpp +++ b/methods/Methods.cpp @@ -23,12 +23,14 @@ #include "GameObjectMethods.h" #include "ElunaQueryMethods.h" #include "AuraMethods.h" +#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE #include "AuraEffectMethods.h" #include "ElunaProcInfoMethods.h" +#include "SpellInfoMethods.h" +#endif #include "ItemMethods.h" #include "WorldPacketMethods.h" #include "SpellMethods.h" -#include "SpellInfoMethods.h" #include "QuestMethods.h" #include "MapMethods.h" #include "CorpseMethods.h" @@ -93,6 +95,7 @@ void RegisterMethods(Eluna* E) ElunaTemplate::Register(E, "Aura"); ElunaTemplate::SetMethods(E, LuaAura::AuraMethods); +#if defined ELUNA_TRINITY || defined ELUNA_AZEROTHCORE ElunaTemplate::Register(E, "AuraEffect"); ElunaTemplate::SetMethods(E, LuaAuraEffects::AuraEffectMethods); @@ -101,6 +104,7 @@ void RegisterMethods(Eluna* E) ElunaTemplate::Register(E, "ElunaSpellInfo"); ElunaTemplate::SetMethods(E, LuaSpellInfo::SpellInfoMethods); +#endif ElunaTemplate::Register(E, "Spell"); ElunaTemplate::SetMethods(E, LuaSpell::SpellMethods);