Skip to content

Commit

Permalink
Merge pull request #357 from UltraNix/ObjectGuidAzerothCore
Browse files Browse the repository at this point in the history
Implemented ObjectGuid support for AzerothCore.
  • Loading branch information
Rochet2 committed Apr 26, 2021
2 parents ca5f1bb + c438332 commit 2962d4f
Show file tree
Hide file tree
Showing 19 changed files with 206 additions and 181 deletions.
6 changes: 3 additions & 3 deletions BindingMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ template <typename T>
struct UniqueObjectKey
{
T event_id;
uint64 guid;
ObjectGuid guid;
uint32 instance_id;

UniqueObjectKey(T event_id, uint64 guid, uint32 instance_id) :
UniqueObjectKey(T event_id, ObjectGuid guid, uint32 instance_id) :
event_id(event_id),
guid(guid),
instance_id(instance_id)
Expand Down Expand Up @@ -367,7 +367,7 @@ namespace std

hash_helper::result_type operator()(argument_type const& k) const
{
return hash_helper::hash(k.event_id, k.instance_id, k.guid);
return hash_helper::hash(k.event_id, k.instance_id, k.guid.GetRawValue());
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion CorpseMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace LuaCorpse
/**
* Returns the GUID of the [Player] that left the [Corpse] behind.
*
* @return uint64 ownerGUID
* @return ObjectGuid ownerGUID
*/
int GetOwnerGUID(lua_State* L, Corpse* corpse)
{
Expand Down
2 changes: 1 addition & 1 deletion CreatureMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList();
*/
int GetDBTableGUIDLow(lua_State* L, Creature* creature)
{
#if defined(TRINITY)
#if defined(TRINITY) || defined(AZEROTHCORE)
Eluna::Push(L, creature->GetSpawnId());
#else
// on mangos based this is same as lowguid
Expand Down
22 changes: 18 additions & 4 deletions ElunaUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,24 @@ typedef QueryResult ElunaQuery;
#define HIGHGUID_GROUP HighGuid::Group
#elif AZEROTHCORE
typedef QueryResult ElunaQuery;
#define ELUNA_LOG_INFO(...) sLog->outString(__VA_ARGS__);
#define ELUNA_LOG_ERROR(...) sLog->outError(__VA_ARGS__);
#define ELUNA_LOG_DEBUG(...) sLog->outDebug(LOG_FILTER_NONE,__VA_ARGS__);
#define ELUNA_LOG_INFO(...) LOG_INFO("eluna", __VA_ARGS__);
#define ELUNA_LOG_ERROR(...) LOG_ERROR("eluna", __VA_ARGS__);
#define ELUNA_LOG_DEBUG(...) LOG_DEBUG("eluna", __VA_ARGS__);
#define GET_GUID GetGUID

#define HIGHGUID_PLAYER HighGuid::Player
#define HIGHGUID_UNIT HighGuid::Unit
#define HIGHGUID_ITEM HighGuid::Item
#define HIGHGUID_GAMEOBJECT HighGuid::GameObject
#define HIGHGUID_PET HighGuid::Pet
#define HIGHGUID_TRANSPORT HighGuid::Transport
#define HIGHGUID_VEHICLE HighGuid::Vehicle
#define HIGHGUID_CONTAINER HighGuid::Container
#define HIGHGUID_DYNAMICOBJECT HighGuid::DynamicObject
#define HIGHGUID_CORPSE HighGuid::Corpse
#define HIGHGUID_MO_TRANSPORT HighGuid::Mo_Transport
#define HIGHGUID_INSTANCE HighGuid::Instance
#define HIGHGUID_GROUP HighGuid::Group
#else
typedef QueryNamedResult ElunaQuery;
#define ASSERT MANGOS_ASSERT
Expand All @@ -63,7 +77,7 @@ typedef QueryNamedResult ElunaQuery;
#define GetTemplate GetProto
#endif

#if defined(TRINITY) || defined(MANGOS)
#if defined(TRINITY) || defined(AZEROTHCORE) || defined(MANGOS)
#ifndef MAKE_NEW_GUID
#define MAKE_NEW_GUID(l, e, h) ObjectGuid(h, e, l)
#endif
Expand Down
4 changes: 1 addition & 3 deletions GameObjectMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,8 @@ namespace LuaGameObject
*/
int GetDBTableGUIDLow(lua_State* L, GameObject* go)
{
#ifdef TRINITY
#if defined(TRINITY) || defined(AZEROTHCORE)
Eluna::Push(L, go->GetSpawnId());
#elif AZEROTHCORE
Eluna::Push(L, go->GetDBTableGUIDLow());
#else
// on mangos based this is same as lowguid
Eluna::Push(L, go->GetGUIDLow());
Expand Down
69 changes: 31 additions & 38 deletions GlobalMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ namespace LuaGlobalFunctions
/**
* Finds and Returns [Player] by guid if found
*
* @param uint64 guid : guid of the [Player], you can get it with [Object:GetGUID]
* @param ObjectGuid guid : guid of the [Player], you can get it with [Object:GetGUID]
* @return [Player] player
*/
int GetPlayerByGUID(lua_State* L)
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
Eluna::Push(L, eObjectAccessor()FindPlayer(ObjectGuid(guid)));
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
Eluna::Push(L, eObjectAccessor()FindPlayer(guid));
return 1;
}

Expand Down Expand Up @@ -261,14 +261,14 @@ namespace LuaGlobalFunctions
/**
* Returns [Guild] by the leader's GUID
*
* @param uint64 guid : the guid of a [Guild] leader
* @param ObjectGuid guid : the guid of a [Guild] leader
* @return [Guild] guild, or `nil` if it doesn't exist
*/
int GetGuildByLeaderGUID(lua_State* L)
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);

Eluna::Push(L, eGuildMgr->GetGuildByLeader(ObjectGuid(guid)));
Eluna::Push(L, eGuildMgr->GetGuildByLeader(guid));
return 1;
}

Expand All @@ -291,7 +291,7 @@ namespace LuaGlobalFunctions
* [Player] and [Creature] for example can have the same low GUID but not GUID.
*
* @param uint32 lowguid : low GUID of the [Player]
* @return uint64 guid
* @return ObjectGuid guid
*/
int GetPlayerGUID(lua_State* L)
{
Expand All @@ -307,7 +307,7 @@ namespace LuaGlobalFunctions
* [Player] and [Item] for example can have the same low GUID but not GUID.
*
* @param uint32 lowguid : low GUID of the [Item]
* @return uint64 guid
* @return ObjectGuid guid
*/
int GetItemGUID(lua_State* L)
{
Expand All @@ -325,7 +325,7 @@ namespace LuaGlobalFunctions
*
* @param uint32 lowguid : low GUID of the [GameObject]
* @param uint32 entry : entry ID of the [GameObject]
* @return uint64 guid
* @return ObjectGuid guid
*/
int GetObjectGUID(lua_State* L)
{
Expand All @@ -344,7 +344,7 @@ namespace LuaGlobalFunctions
*
* @param uint32 lowguid : low GUID of the [Creature]
* @param uint32 entry : entry ID of the [Creature]
* @return uint64 guid
* @return ObjectGuid guid
*/
int GetUnitGUID(lua_State* L)
{
Expand All @@ -370,14 +370,14 @@ namespace LuaGlobalFunctions
* For example creatures in instances use the same low GUID assigned for that spawn in the database.
* This is why to identify a creature you have to know the instanceId and low GUID. See [Map:GetIntstanceId]
*
* @param uint64 guid : GUID of an [Object]
* @param ObjectGuid guid : GUID of an [Object]
* @return uint32 lowguid : low GUID of the [Object]
*/
int GetGUIDLow(lua_State* L)
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);

Eluna::Push(L, GUID_LOPART(guid));
Eluna::Push(L, guid.GetCounter());
return 1;
}

Expand Down Expand Up @@ -435,13 +435,13 @@ namespace LuaGlobalFunctions
*
* GUID consist of entry ID, low GUID, and type ID.
*
* @param uint64 guid : GUID of an [Object]
* @param ObjectGuid guid : GUID of an [Object]
* @return int32 typeId : type ID of the [Object]
*/
int GetGUIDType(lua_State* L)
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
Eluna::Push(L, static_cast<int>(GUID_HIPART(guid)));
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
Eluna::Push(L, static_cast<int>(guid.GetHigh()));
return 1;
}

Expand All @@ -450,13 +450,13 @@ namespace LuaGlobalFunctions
*
* GUID consist of entry ID, low GUID, and type ID.
*
* @param uint64 guid : GUID of an [Creature] or [GameObject]
* @param ObjectGuid guid : GUID of an [Creature] or [GameObject]
* @return uint32 entry : entry ID, or `0` if `guid` is not a [Creature] or [GameObject]
*/
int GetGUIDEntry(lua_State* L)
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
Eluna::Push(L, GUID_ENPART(guid));
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
Eluna::Push(L, guid.GetEntry());
return 1;
}

Expand Down Expand Up @@ -537,7 +537,7 @@ namespace LuaGlobalFunctions
lua_pushvalue(L, 3);
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef >= 0)
return Eluna::GetEluna(L)->Register(L, regtype, id, 0, 0, ev, functionRef, shots);
return Eluna::GetEluna(L)->Register(L, regtype, id, ObjectGuid(), 0, ev, functionRef, shots);
else
luaL_argerror(L, 3, "unable to make a ref to function");
return 0;
Expand All @@ -552,15 +552,15 @@ namespace LuaGlobalFunctions
lua_pushvalue(L, 2);
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef >= 0)
return Eluna::GetEluna(L)->Register(L, regtype, 0, 0, 0, ev, functionRef, shots);
return Eluna::GetEluna(L)->Register(L, regtype, 0, ObjectGuid(), 0, ev, functionRef, shots);
else
luaL_argerror(L, 2, "unable to make a ref to function");
return 0;
}

static int RegisterUniqueHelper(lua_State* L, int regtype)
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
uint32 instanceId = Eluna::CHECKVAL<uint32>(L, 2);
uint32 ev = Eluna::CHECKVAL<uint32>(L, 3);
luaL_checktype(L, 4, LUA_TFUNCTION);
Expand Down Expand Up @@ -1149,7 +1149,7 @@ namespace LuaGlobalFunctions
* @proto cancel = (guid, instance_id, event, function)
* @proto cancel = (guid, instance_id, event, function, shots)
*
* @param uint64 guid : the GUID of a single [Creature]
* @param ObjectGuid guid : the GUID of a single [Creature]
* @param uint32 instance_id : the instance ID of a single [Creature]
* @param uint32 event : refer to CreatureEvents above
* @param function function : function that will be called when the event occurs
Expand Down Expand Up @@ -1708,7 +1708,7 @@ namespace LuaGlobalFunctions
#ifndef AZEROTHCORE
if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, phase, entry, pos))
#else
if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, phase, entry, 0, x, y, z, o))
if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, phase, entry, 0, x, y, z, o))
#endif
{
delete creature;
Expand All @@ -1718,11 +1718,8 @@ namespace LuaGlobalFunctions

creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase);

#ifndef AZEROTHCORE
uint32 db_guid = creature->GetSpawnId();
#else
uint32 db_guid = creature->GetDBTableGUIDLow();
#endif

// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells()
// current "creature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
creature->CleanupsBeforeDelete();
Expand All @@ -1731,7 +1728,7 @@ namespace LuaGlobalFunctions
#ifndef AZEROTHCORE
if (!creature->LoadFromDB(db_guid, map, true, true))
#else
if (!creature->LoadFromDB(db_guid, map))
if (!creature->LoadFromDB(db_guid, map, true))
#endif
{
delete creature;
Expand Down Expand Up @@ -1783,7 +1780,7 @@ namespace LuaGlobalFunctions
QuaternionData rot = QuaternionData::fromEulerAnglesZYX(o, 0.f, 0.f);
if (!object->Create(guidLow, objectInfo->entry, map, phase, Position(x, y, z, o), rot, 0, GO_STATE_READY))
#else
uint32 guidLow = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);
uint32 guidLow = map->GenerateLowGuid<HighGuid::GameObject>();
if (!object->Create(guidLow, entry, map, phase, x, y, z, o, G3D::Quat(0.0f, 0.0f, 0.0f, 0.0f), 100, GO_STATE_READY))
#endif
{
Expand All @@ -1799,11 +1796,7 @@ namespace LuaGlobalFunctions
{
// fill the gameobject data and save to the db
object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase);
#ifndef AZEROTHCORE
guidLow = object->GetSpawnId();
#else
guidLow = object->GetDBTableGUIDLow();
#endif

// delete the old object and do a clean load from DB with a fresh new GameObject instance.
// this is required to avoid weird behavior and memory leaks
Expand Down Expand Up @@ -2157,7 +2150,7 @@ namespace LuaGlobalFunctions
item->SaveToDB();
#endif
draft.AddItem(item);
#if defined TRINITY
#if defined TRINITY || AZEROTHCORE
Eluna::Push(L, item->GetGUID().GetCounter());
#else
Eluna::Push(L, item->GetGUIDLow());
Expand Down Expand Up @@ -2768,7 +2761,7 @@ namespace LuaGlobalFunctions
*
* @proto (entry)
* @proto (entry, event_type)
* @param uint64 guid : the GUID of a single [Creature] whose handlers will be cleared
* @param ObjectGuid guid : the GUID of a single [Creature] whose handlers will be cleared
* @param uint32 instance_id : the instance ID of a single [Creature] whose handlers will be cleared
* @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterCreatureEvent]
*/
Expand All @@ -2778,7 +2771,7 @@ namespace LuaGlobalFunctions

if (lua_isnoneornil(L, 3))
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
uint32 instanceId = Eluna::CHECKVAL<uint32>(L, 2);

Eluna* E = Eluna::GetEluna(L);
Expand All @@ -2787,7 +2780,7 @@ namespace LuaGlobalFunctions
}
else
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
uint32 instanceId = Eluna::CHECKVAL<uint32>(L, 2);
uint32 event_type = Eluna::CHECKVAL<uint32>(L, 3);
Eluna::GetEluna(L)->CreatureUniqueBindings->Clear(Key((Hooks::CreatureEvents)event_type, guid, instanceId));
Expand Down
10 changes: 5 additions & 5 deletions GroupHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ using namespace Hooks;
return;\
LOCK_ELUNA

void Eluna::OnAddMember(Group* group, uint64 guid)
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, uint64 guid)
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, uint64 guid, uint8 method)
void Eluna::OnRemoveMember(Group* group, ObjectGuid guid, uint8 method)
{
START_HOOK(GROUP_EVENT_ON_MEMBER_REMOVE);
Push(group);
Expand All @@ -45,7 +45,7 @@ void Eluna::OnRemoveMember(Group* group, uint64 guid, uint8 method)
CallAllFunctions(GroupEventBindings, key);
}

void Eluna::OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeaderGuid)
void Eluna::OnChangeLeader(Group* group, ObjectGuid newLeaderGuid, ObjectGuid oldLeaderGuid)
{
START_HOOK(GROUP_EVENT_ON_LEADER_CHANGE);
Push(group);
Expand All @@ -61,7 +61,7 @@ void Eluna::OnDisband(Group* group)
CallAllFunctions(GroupEventBindings, key);
}

void Eluna::OnCreate(Group* group, uint64 leaderGuid, GroupType groupType)
void Eluna::OnCreate(Group* group, ObjectGuid leaderGuid, GroupType groupType)
{
START_HOOK(GROUP_EVENT_ON_CREATE);
Push(group);
Expand Down
Loading

0 comments on commit 2962d4f

Please sign in to comment.