feat(LuaEngine/Packed GUIDs) Add support for writing packed GUIDs and reading packed GUID size (#295)

This commit is contained in:
mostlynick3
2025-08-21 14:04:04 +02:00
committed by GitHub
parent ce7ee6c0f8
commit a63ef3fe8c
3 changed files with 29 additions and 0 deletions

View File

@@ -113,6 +113,7 @@ luaL_Reg GlobalMethods[] =
{ "GetGUIDLow", &LuaGlobalFunctions::GetGUIDLow },
{ "GetGUIDType", &LuaGlobalFunctions::GetGUIDType },
{ "GetGUIDEntry", &LuaGlobalFunctions::GetGUIDEntry },
{ "GetPackedGUIDSize", &LuaGlobalFunctions::GetPackedGUIDSize },
{ "GetAreaName", &LuaGlobalFunctions::GetAreaName },
{ "GetOwnerHalaa", &LuaGlobalFunctions::GetOwnerHalaa },
{ "bit_not", &LuaGlobalFunctions::bit_not },
@@ -1204,6 +1205,7 @@ ElunaRegister<WorldPacket> PacketMethods[] =
{ "WriteLong", &LuaPacket::WriteLong },
{ "WriteULong", &LuaPacket::WriteULong },
{ "WriteGUID", &LuaPacket::WriteGUID },
{ "WritePackedGUID", &LuaPacket::WritePackedGUID },
{ "WriteString", &LuaPacket::WriteString },
{ "WriteFloat", &LuaPacket::WriteFloat },
{ "WriteDouble", &LuaPacket::WriteDouble },

View File

@@ -468,6 +468,20 @@ namespace LuaGlobalFunctions
return 1;
}
/**
* Returns the byte size in bytes (2-9) of the ObjectGuid when packed.
*
* @param ObjectGuid guid : the ObjectGuid to get packed size for
* @return number size
*/
int GetPackedGUIDSize(lua_State* L)
{
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
PackedGuid packedGuid(guid);
Eluna::Push(L, static_cast<int>(packedGuid.size()));
return 1;
}
/**
* Returns the area or zone's name.
*

View File

@@ -212,6 +212,19 @@ namespace LuaPacket
return 0;
}
/**
* Writes an ObjectGuid as packed GUID format to the [WorldPacket].
*
* @param ObjectGuid value : the ObjectGuid to be packed to the [WorldPacket]
*/
int WritePackedGUID(lua_State* L, WorldPacket* packet)
{
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 2);
PackedGuid packedGuid(guid);
(*packet) << packedGuid;
return 0;
}
/**
* Writes a string to the [WorldPacket].
*