diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 46c9d5e16fca97..6c05393d2e8fe9 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -59,7 +59,8 @@ function(ConfigureElunaModule moduleName) target_compile_options(game-interface INTERFACE -DAZEROTHCORE - -DWOTLK) + -DWOTLK + -DMOD_ELUNA) endfunction() # Set the MODULES_${SOURCE_MODULE} variables from the diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index fe37ea46c92f95..c3a690a99d397e 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -52,6 +52,11 @@ #include "World.h" #include "WorldPacket.h" +#if defined(MOD_ELUNA) +#include "LuaEngine.h" +#include "ElunaConfig.h" +#endif + /// @todo: this import is not necessary for compilation and marked as unused by the IDE // however, for some reasons removing it would cause a damn linking issue // there is probably some underlying problem with imports which should properly addressed @@ -3231,3 +3236,13 @@ void WorldObject::RemoveAllowedLooter(ObjectGuid guid) { _allowedLooters.erase(guid); } + +#if defined(MOD_ELUNA) +Eluna* WorldObject::GetEluna() const +{ + if (const Map * map = FindMap()) + return map->GetEluna(); + + return nullptr; +} +#endif \ No newline at end of file diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index 043a34d6d6b0fd..6c4ffd75f88d03 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -40,6 +40,9 @@ #include "UpdateFields.h" class ElunaEventProcessor; +#if defined(MOD_ELUNA) +class Eluna; +#endif enum TempSummonType { @@ -630,6 +633,10 @@ class WorldObject : public Object, public WorldLocation std::string GetDebugInfo() const override; +#if defined(MOD_ELUNA) + Eluna* GetEluna() const; +#endif + // Event handler ElunaEventProcessor* elunaEvents; EventProcessor m_Events; diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 0f8ba75f747067..4fdf044791c8f7 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -44,6 +44,12 @@ #include "VMapMgr2.h" #include "Weather.h" +#if defined(MOD_ELUNA) +#include "LuaEngine.h" +#include "ElunaConfig.h" +#include "ElunaLoader.h" +#endif + union u_map_magic { char asChar[4]; @@ -64,6 +70,11 @@ ZoneDynamicInfo::ZoneDynamicInfo() : MusicId(0), WeatherId(WEATHER_STATE_FINE), Map::~Map() { +#if defined(MOD_ELUNA) + delete eluna; + eluna = nullptr; +#endif + // UnloadAll must be called before deleting the map sScriptMgr->OnDestroyMap(this); @@ -242,6 +253,16 @@ Map::Map(uint32 id, uint32 InstanceId, uint8 SpawnMode, Map* _parent) : _transportsUpdateIter(_transports.end()), i_scriptLock(false), _defaultLight(GetDefaultMapLight(id)) { m_parentMap = (_parent ? _parent : this); + + // lua state begins uninitialized +#if defined(MOD_ELUNA) + eluna = nullptr; + + if (sElunaConfig->IsElunaEnabled() && !sElunaConfig->IsElunaCompatibilityMode() && sElunaConfig->ShouldMapLoadEluna(id)) + if (!IsParentMap() || (IsParentMap() && !Instanceable())) + eluna = new Eluna(this); +#endif + for (unsigned int idx = 0; idx < MAX_NUMBER_OF_GRIDS; ++idx) { for (unsigned int j = 0; j < MAX_NUMBER_OF_GRIDS; ++j) @@ -2655,6 +2676,16 @@ void Map::AddObjectToRemoveList(WorldObject* obj) { ASSERT(obj->GetMapId() == GetId() && obj->GetInstanceId() == GetInstanceId()); +#if defined(MOD_ELUNA) + if (Eluna* E = GetEluna()) + { + if (Creature* creature = obj->ToCreature()) + E->OnRemove(creature); + else if (GameObject* gameobject = obj->ToGameObject()) + E->OnRemove(gameobject); + } +#endif + obj->CleanupsBeforeDelete(false); // remove or simplify at least cross referenced links i_objectsToRemove.insert(obj); @@ -4088,3 +4119,13 @@ std::string InstanceMap::GetDebugInfo() const << "ScriptId: " << GetScriptId() << " ScriptName: " << GetScriptName(); return sstr.str(); } + +#if defined(MOD_ELUNA) +Eluna *Map::GetEluna() const +{ + if (sElunaConfig->IsElunaCompatibilityMode()) + return sWorld->GetEluna(); + + return eluna; +} +#endif diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index e753d841f0278e..659dccedfc2431 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -38,6 +38,10 @@ #include #include +#if defined(MOD_ELUNA) +class Eluna; +#endif + class Unit; class WorldPacket; class InstanceScript; @@ -380,6 +384,7 @@ class Map : public GridRefMgr static bool ExistVMap(uint32 mapid, int gx, int gy); [[nodiscard]] Map const* GetParent() const { return m_parentMap; } + bool IsParentMap() const { return GetParent() == this; } // pussywizard: movemaps, mmaps [[nodiscard]] std::shared_mutex& GetMMapLock() const { return *(const_cast(&MMapLock)); } @@ -656,6 +661,10 @@ class Map : public GridRefMgr virtual std::string GetDebugInfo() const; +#if defined(MOD_ELUNA) + Eluna* GetEluna() const; +#endif + private: void LoadMapAndVMap(int gx, int gy); void LoadVMap(int gx, int gy); @@ -802,6 +811,10 @@ class Map : public GridRefMgr std::unordered_set _corpseBones; std::unordered_set _updateObjects; + +#if defined(MOD_ELUNA) + Eluna* eluna; +#endif }; enum InstanceResetMethod diff --git a/src/server/game/World/IWorld.h b/src/server/game/World/IWorld.h index 8e6d353353bd45..fb9d3959f2054b 100644 --- a/src/server/game/World/IWorld.h +++ b/src/server/game/World/IWorld.h @@ -25,6 +25,10 @@ #include "SharedDefines.h" #include +#if defined(MOD_ELUNA) +class Eluna; +#endif + class WorldPacket; class WorldSession; class Player; @@ -612,6 +616,11 @@ class IWorld virtual void SetRealmName(std::string name) = 0; virtual void RemoveOldCorpses() = 0; virtual void DoForAllOnlinePlayers(std::function exec) = 0; + +#if defined(MOD_ELUNA) + Eluna* GetEluna() const { return eluna; } + Eluna* eluna; +#endif }; #endif //AZEROTHCORE_IWORLD_H diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index e891444b90f7d5..e46d744ed1de41 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -415,11 +415,11 @@ void World::LoadConfigSettings(bool reload) LOG_ERROR("server.loading", "World settings reload fail: can't read settings."); return; } - - sLog->LoadFromConfig(); - sMetric->LoadFromConfigs(); } + sLog->LoadFromConfig(); + sMetric->LoadFromConfigs(); + // Set realm id and enable db logging sLog->SetRealmId(realm.Id.Realm); diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h index 75f3bbdac8ef92..c5f52ffb44abad 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -33,6 +33,10 @@ #include #include +#if defined(MOD_ELUNA) +class Eluna; +#endif + class Object; class WorldPacket; class WorldSocket; @@ -344,6 +348,11 @@ class World: public IWorld void DoForAllOnlinePlayers(std::function exec) override; +#if defined(MOD_ELUNA) + Eluna* GetEluna() const { return eluna; } + Eluna* eluna; +#endif + protected: void _UpdateGameTime(); // callback for UpdateRealmCharacters