Skip to content

Commit

Permalink
Improve compatibility with TrinityCore master branch (ElunaLuaEngine#486
Browse files Browse the repository at this point in the history
)

* Remove ObjectGuid::GetRawValue uses from Eluna for TrinityCore
* Slightly improve compatibility with TrinityCore master branch
* Fixed ElunaQuery:GetRow() to push correct variable types
  • Loading branch information
Shauren authored Jul 14, 2024
1 parent f4a1203 commit fa4cebd
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 42 deletions.
2 changes: 1 addition & 1 deletion BindingMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,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.GetRawValue());
return hash_helper::hash(k.event_id, k.instance_id, k.guid);
}
};
}
Expand Down
8 changes: 7 additions & 1 deletion LuaEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,13 @@ int Eluna::Register(uint8 regtype, uint32 entry, ObjectGuid guid, uint32 instanc
}
luaL_unref(L, LUA_REGISTRYINDEX, functionRef);
std::ostringstream oss;
oss << "regtype " << static_cast<uint32>(regtype) << ", event " << event_id << ", entry " << entry << ", guid " << guid.GetRawValue() << ", instance " << instanceId;
oss << "regtype " << static_cast<uint32>(regtype) << ", event " << event_id << ", entry " << entry << ", guid " <<
#ifdef TRINITY
guid.ToHexString()
#else
guid.GetRawValue()
#endif
<< ", instance " << instanceId;
luaL_error(L, "Unknown event type (%s)", oss.str().c_str());
return 0;
}
Expand Down
34 changes: 26 additions & 8 deletions methods/TrinityCore/ElunaQueryMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,26 +281,44 @@ namespace LuaQuery

for (uint32 i = 0; i < col; ++i)
{
E->Push(RESULT->GetFieldName(i));
QueryResultFieldMetadata const& fieldMetadata = RESULT->GetFieldMetadata(i);

const char* str = row[i].GetCString();
if (row[i].IsNull() || !str)
E->Push(fieldMetadata.Alias);

if (row[i].IsNull())
E->Push();
else
{
// MYSQL_TYPE_LONGLONG Interpreted as string for lua
switch (row[i].GetType())
switch (fieldMetadata.Type)
{
case DatabaseFieldTypes::UInt8:
case DatabaseFieldTypes::UInt16:
case DatabaseFieldTypes::UInt32:
E->Push(row[i].GetUInt32());
break;
case DatabaseFieldTypes::Int8:
case DatabaseFieldTypes::Int16:
case DatabaseFieldTypes::Int32:
E->Push(row[i].GetInt32());
break;
case DatabaseFieldTypes::UInt64:
E->Push(row[i].GetUInt64());
break;
case DatabaseFieldTypes::Int64:
E->Push(row[i].GetInt64());
break;
case DatabaseFieldTypes::Float:
case DatabaseFieldTypes::Double:
E->Push(strtod(str, NULL));
case DatabaseFieldTypes::Decimal:
E->Push(row[i].GetDouble());
break;
case DatabaseFieldTypes::Date:
case DatabaseFieldTypes::Time:
case DatabaseFieldTypes::Binary:
E->Push(row[i].GetCString());
break;
default:
E->Push(str);
E->Push();
break;
}
}
Expand All @@ -310,7 +328,7 @@ namespace LuaQuery
lua_settop(E->L, tbl);
return 1;
}

ElunaRegister<ElunaQuery> QueryMethods[] =
{
// Getters
Expand Down
52 changes: 20 additions & 32 deletions methods/TrinityCore/PlayerMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#define PLAYERMETHODS_H

#include "LuaValue.h"
#include "NPCPackets.h"
#include "PartyPackets.h"
#include <boost/callable_traits/args.hpp>

/***
* Inherits all methods from: [Object], [WorldObject], [Unit]
Expand Down Expand Up @@ -1914,7 +1917,9 @@ namespace LuaPlayer
*/
int SetCoinage(Eluna* E, Player* player)
{
uint32 amt = E->CHECKVAL<uint32>(2);
using MoneyType = std::tuple_element_t<1, boost::callable_traits::args_t<decltype(&Player::SetMoney)>>;

MoneyType amt = E->CHECKVAL<MoneyType>(2);
player->SetMoney(amt);
return 0;
}
Expand Down Expand Up @@ -2136,16 +2141,7 @@ namespace LuaPlayer
{
Unit* unit = E->CHECKOBJ<Unit>(2);

AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit->GetFaction());
if (!ahEntry)
return 0;

WorldPacket data(MSG_AUCTION_HELLO, 12);
data << unit->GET_GUID();
data << uint32(ahEntry->ID);
data << uint8(1);

player->GetSession()->SendPacket(&data);
player->GetSession()->SendAuctionHello(unit->GET_GUID(), unit);
return 0;
}

Expand Down Expand Up @@ -3328,7 +3324,9 @@ namespace LuaPlayer
*/
int ModifyMoney(Eluna* E, Player* player)
{
int32 amt = E->CHECKVAL<int32>(2);
using MoneyType = std::tuple_element_t<1, boost::callable_traits::args_t<decltype(&Player::ModifyMoney)>>;

MoneyType amt = E->CHECKVAL<MoneyType>(2);

player->ModifyMoney(amt);
return 1;
Expand Down Expand Up @@ -3504,15 +3502,14 @@ namespace LuaPlayer
uint32 data = E->CHECKVAL<uint32>(6);
std::string iconText = E->CHECKVAL<std::string>(7);

WorldPacket packet(SMSG_GOSSIP_POI, 4 + 4 + 4 + 4 + 4 + 10);
packet << flags;
packet << x;
packet << y;
packet << icon;
packet << data;
packet << iconText;
WorldPackets::NPC::GossipPOI packet;
packet.Name = iconText;
packet.Flags = flags;
packet.Pos.Pos.Relocate(x, y);
packet.Icon = icon;
packet.Importance = data;

player->GetSession()->SendPacket(&packet);
player->SendDirectMessage(packet.Write());
return 0;
}

Expand Down Expand Up @@ -3623,18 +3620,9 @@ namespace LuaPlayer

if (success)
{
#ifdef CATA
WorldPacket data(SMSG_PARTY_INVITE, 10); // guess size
#else
WorldPacket data(SMSG_GROUP_INVITE, 10); // guess size
#endif
data << uint8(1); // invited/already in group flag
data << player->GetName(); // max len 48
data << uint32(0); // unk
data << uint8(0); // count
data << uint32(0); // unk

invited->GetSession()->SendPacket(&data);
WorldPackets::Party::PartyInvite partyInvite;
partyInvite.Initialize(player, 0, true);
invited->SendDirectMessage(partyInvite.Write());
}

E->Push(success);
Expand Down

0 comments on commit fa4cebd

Please sign in to comment.