Skip to content

Commit

Permalink
TC Retail Changes
Browse files Browse the repository at this point in the history
It compiles and runs!
  • Loading branch information
Niam5 committed Jul 14, 2024
1 parent 3b85a67 commit 59e2196
Show file tree
Hide file tree
Showing 32 changed files with 575 additions and 281 deletions.
4 changes: 4 additions & 0 deletions ElunaCreatureAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ struct ElunaCreatureAI : CreatureAI
if (!me->GetEluna()->UpdateAI(me, diff))
{
#if defined TRINITY || AZEROTHCORE || VMANGOS
#ifdef RETAIL
if (!me->HasUnitFlag(UNIT_FLAG_IMMUNE_TO_NPC))
#else
if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC))
#endif
ScriptedAI::UpdateAI(diff);
#elif defined CMANGOS
if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC))
Expand Down
6 changes: 4 additions & 2 deletions ElunaIncludes.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#include "CellImpl.h"
#include "Chat.h"
#include "Channel.h"
#ifndef RETAIL
#include "DBCStores.h"
#if defined CATA && defined TRINITY
#endif
#if (defined CATA || defined RETAIL) && defined TRINITY
#include "DB2Stores.h"
#endif
#include "GameEventMgr.h"
Expand Down Expand Up @@ -141,7 +143,7 @@
#endif
#endif

#if (defined(TRINITY) && defined(CATA))
#if (defined CATA || defined RETAIL) && defined TRINITY
typedef OpcodeServer OpcodesList;

#elif !defined CLASSIC
Expand Down
8 changes: 8 additions & 0 deletions ElunaInstanceAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,18 @@ class ElunaInstanceAI : public InstanceData
* These are responsible for serializing/deserializing the instance's
* data table to/from the core.
*/
#if defined(TRINITY) && defined(RETAIL)
void Load(const char* data);
#else
void Load(const char* data) override;
#endif
#if defined TRINITY || AZEROTHCORE
// Simply calls Save, since the functions are a bit different in name and data types on different cores
#if defined(TRINITY) && defined(RETAIL)
std::string GetSaveData()
#else
std::string GetSaveData() override
#endif
{
return Save();
}
Expand Down
12 changes: 8 additions & 4 deletions ElunaUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
#include "Object.h"
#include "Unit.h"
#include "GameObject.h"
#ifdef RETAIL
#include "DB2Stores.h"
#else
#include "DBCStores.h"
#endif
#else
#include "World/World.h"
#include "Entities/Object.h"
Expand Down Expand Up @@ -101,12 +105,12 @@ bool ElunaUtil::WorldObjectInRangeCheck::operator()(WorldObject* u)
{
if (i_obj_fact)
{
#if ((defined TRINITY || AZEROTHCORE || CMANGOS || VMANGOS) && !defined CATA)
if ((i_obj_fact->IsHostileTo(*target->GetFactionTemplateEntry())) != (i_hostile == 1))
return false;
#elif defined CATA && defined TRINITY
#if ((defined CATA || RETAIL) && defined TRINITY)
if ((i_obj_fact->IsHostileTo(target->GetFactionTemplateEntry())) != (i_hostile == 1))
return false;
#elif ((defined TRINITY || AZEROTHCORE || CMANGOS || VMANGOS) && !defined CATA)
if ((i_obj_fact->IsHostileTo(*target->GetFactionTemplateEntry())) != (i_hostile == 1))
return false;
#elif defined CATA && defined CMANGOS
if ((i_obj_fact->IsHostileTo(*target->GetFactionTemplateEntry())) != (i_hostile == 1))
return false;
Expand Down
10 changes: 5 additions & 5 deletions ElunaUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@
typedef QueryResult ElunaQuery;
#define GET_GUID GetGUID
#define HIGHGUID_PLAYER HighGuid::Player
#define HIGHGUID_UNIT HighGuid::Unit
#define HIGHGUID_UNIT HighGuid::Creature
#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_CONTAINER HighGuid::Container
#define HIGHGUID_DYNAMICOBJECT HighGuid::DynamicObject
#define HIGHGUID_CORPSE HighGuid::Corpse
#define HIGHGUID_MO_TRANSPORT HighGuid::Mo_Transport
#define HIGHGUID_MO_TRANSPORT HighGuid::Transport
#define HIGHGUID_INSTANCE HighGuid::Instance
#define HIGHGUID_GROUP HighGuid::Group
//#define HIGHGUID_GROUP HighGuid::Group
#endif

#ifdef TRINITY
#ifdef WOTLK
#if defined WOTLK || defined RETAIL
#include "fmt/printf.h"
#define ELUNA_LOG_TC_FMT(TC_LOG_MACRO, ...) \
try { \
Expand Down
28 changes: 15 additions & 13 deletions LuaEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ElunaUtility.h"
#include "ElunaCreatureAI.h"
#include "ElunaInstanceAI.h"
#include <sstream>

extern "C"
{
Expand Down Expand Up @@ -72,9 +73,8 @@ ItemEventBindings(NULL),
ItemGossipBindings(NULL),
PlayerGossipBindings(NULL),
MapEventBindings(NULL),
InstanceEventBindings(NULL),

CreatureUniqueBindings(NULL)
InstanceEventBindings(NULL)
//CreatureUniqueBindings(NULL)
{
OpenLua();
eventMgr = new EventMgr(this);
Expand Down Expand Up @@ -193,7 +193,7 @@ void Eluna::CreateBindStores()
MapEventBindings = new BindingMap< EntryKey<Hooks::InstanceEvents> >(L);
InstanceEventBindings = new BindingMap< EntryKey<Hooks::InstanceEvents> >(L);

CreatureUniqueBindings = new BindingMap< UniqueObjectKey<Hooks::CreatureEvents> >(L);
//CreatureUniqueBindings = new BindingMap< UniqueObjectKey<Hooks::CreatureEvents> >(L);
}

void Eluna::DestroyBindStores()
Expand All @@ -217,7 +217,7 @@ void Eluna::DestroyBindStores()
delete MapEventBindings;
delete InstanceEventBindings;

delete CreatureUniqueBindings;
//delete CreatureUniqueBindings;

ServerEventBindings = NULL;
PlayerEventBindings = NULL;
Expand All @@ -238,7 +238,7 @@ void Eluna::DestroyBindStores()
MapEventBindings = NULL;
InstanceEventBindings = NULL;

CreatureUniqueBindings = NULL;
//CreatureUniqueBindings = NULL;
}

void Eluna::RunScripts()
Expand Down Expand Up @@ -786,20 +786,20 @@ int Eluna::Register(uint8 regtype, uint32 entry, ObjectGuid guid, uint32 instanc
case Hooks::REGTYPE_PACKET:
if (event_id < Hooks::PACKET_EVENT_COUNT)
{
if (entry >= NUM_MSG_TYPES)
/*if (entry >= NUM_MSG_TYPES)
{
luaL_unref(L, LUA_REGISTRYINDEX, functionRef);
luaL_error(L, "Couldn't find a creature with (ID: %d)!", entry);
return 0; // Stack: (empty)
}
}*/

auto key = EntryKey<Hooks::PacketEvents>((Hooks::PacketEvents)event_id, entry);
bindingID = PacketEventBindings->Insert(key, functionRef, shots);
createCancelCallback(this, bindingID, PacketEventBindings);
return 1; // Stack: callback
}
break;

#ifndef RETAIL
case Hooks::REGTYPE_CREATURE:
if (event_id < Hooks::CREATURE_EVENT_COUNT)
{
Expand Down Expand Up @@ -832,6 +832,7 @@ int Eluna::Register(uint8 regtype, uint32 entry, ObjectGuid guid, uint32 instanc
return 1; // Stack: callback
}
break;
#endif

case Hooks::REGTYPE_CREATURE_GOSSIP:
if (event_id < Hooks::GOSSIP_EVENT_COUNT)
Expand Down Expand Up @@ -958,21 +959,21 @@ 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 " << guid.ToHexString() << ", instance " << instanceId;
luaL_error(L, "Unknown event type (%s)", oss.str().c_str());
return 0;
}

void Eluna::UpdateEluna(uint32 diff)
{
if (reload)
#ifdef TRINITY
#if defined TRINITY && defined WOTLK
if(!GetQueryProcessor().HasPendingCallbacks())
#endif
_ReloadEluna();

eventMgr->globalProcessor->Update(diff);
#ifdef TRINITY
#if defined TRINITY && defined WOTLK
GetQueryProcessor().ProcessReadyCallbacks();
#endif
}
Expand Down Expand Up @@ -1022,7 +1023,7 @@ int Eluna::CallOneFunction(int number_of_functions, int number_of_arguments, int

return functions_top + 1; // Return the location of the first result (if any exist).
}

#ifndef RETAIL
CreatureAI* Eluna::GetAI(Creature* creature)
{
for (int i = 1; i < Hooks::CREATURE_EVENT_COUNT; ++i)
Expand All @@ -1039,6 +1040,7 @@ CreatureAI* Eluna::GetAI(Creature* creature)

return NULL;
}
#endif

InstanceData* Eluna::GetInstanceData(Map* map)
{
Expand Down
25 changes: 17 additions & 8 deletions LuaEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class ELUNA_GAME_API Eluna
BindingMap< EntryKey<Hooks::InstanceEvents> >* MapEventBindings;
BindingMap< EntryKey<Hooks::InstanceEvents> >* InstanceEventBindings;

BindingMap< UniqueObjectKey<Hooks::CreatureEvents> >* CreatureUniqueBindings;
//BindingMap< UniqueObjectKey<Hooks::CreatureEvents> >* CreatureUniqueBindings;

static int StackTrace(lua_State* _L);
static void Report(lua_State* _L);
Expand Down Expand Up @@ -410,7 +410,11 @@ class ELUNA_GAME_API Eluna
void OnResurrect(Player* pPlayer);
void OnQuestAbandon(Player* pPlayer, uint32 questId);
void OnQuestStatusChanged(Player* pPlayer, uint32 questId, uint8 status);
#ifdef RETAIL
void OnLearnTalents(Player* pPlayer, uint32 talentId, uint32 spellid);
#else
void OnLearnTalents(Player* pPlayer, uint32 talentId, uint32 talentRank, uint32 spellid);
#endif
void OnSkillChange(Player* pPlayer, uint32 skillId, uint32 skillValue);
void OnLearnSpell(Player* pPlayer, uint32 spellid);
InventoryResult OnCanUseItem(const Player* pPlayer, uint32 itemEntry);
Expand Down Expand Up @@ -506,7 +510,7 @@ class ELUNA_GAME_API Eluna
void OnFreeTalentPointsChanged(Player* pPlayer, uint32 newPoints);
void OnTalentsReset(Player* pPlayer, bool noCost);
void OnMoneyChanged(Player* pPlayer, int32& amount);
#ifdef CATA
#if defined CATA || defined RETAIL
void OnMoneyChanged(Player* pPlayer, int64& amount);
#endif
void OnGiveXP(Player* pPlayer, uint32& amount, Unit* pVictim);
Expand Down Expand Up @@ -552,24 +556,29 @@ class ELUNA_GAME_API Eluna
void OnChange(Weather* weather, uint32 zone, WeatherState state, float grade);

/* Auction House */
void OnAdd(AuctionHouseObject* ah, AuctionEntry* entry);
void OnRemove(AuctionHouseObject* ah, AuctionEntry* entry);
void OnSuccessful(AuctionHouseObject* ah, AuctionEntry* entry);
void OnExpire(AuctionHouseObject* ah, AuctionEntry* entry);
//void OnAdd(AuctionHouseObject* ah, AuctionEntry* entry);
//void OnAdd(AuctionHouseObject* ah, AuctionPosting* entry);
//void OnRemove(AuctionHouseObject* ah, AuctionEntry* entry);
//void OnSuccessful(AuctionHouseObject* ah, AuctionEntry* entry);
//void OnExpire(AuctionHouseObject* ah, AuctionEntry* entry);

/* Guild */
void OnAddMember(Guild* guild, Player* player, uint32 plRank);
#ifdef RETAIL
void OnRemoveMember(Guild* guild, ObjectGuid guid, bool isDisbanding);
#else
void OnRemoveMember(Guild* guild, Player* player, bool isDisbanding);
#endif
void OnMOTDChanged(Guild* guild, const std::string& newMotd);
void OnInfoChanged(Guild* guild, const std::string& newInfo);
void OnCreate(Guild* guild, Player* leader, const std::string& name);
void OnDisband(Guild* guild);
void OnMemberWitdrawMoney(Guild* guild, Player* player, uint32& amount, bool isRepair);
#ifdef CATA
#if defined CATA || defined RETAIL
void OnMemberWitdrawMoney(Guild* guild, Player* player, uint64& amount, bool isRepair);
#endif
void OnMemberDepositMoney(Guild* guild, Player* player, uint32& amount);
#ifdef CATA
#if defined CATA || defined RETAIL
void OnMemberDepositMoney(Guild* guild, Player* player, uint64& amount);
#endif
void OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId, bool isDestBank, uint8 destContainer, uint8 destSlotId);
Expand Down
1 change: 1 addition & 0 deletions LuaFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void RegisterFunctions(Eluna* E)
ElunaTemplate<Player>::SetMethods(E, LuaUnit::UnitMethods);
ElunaTemplate<Player>::SetMethods(E, LuaPlayer::PlayerMethods);


ElunaTemplate<Creature>::Register(E, "Creature");
ElunaTemplate<Creature>::SetMethods(E, LuaObject::ObjectMethods);
ElunaTemplate<Creature>::SetMethods(E, LuaWorldObject::WorldObjectMethods);
Expand Down
3 changes: 2 additions & 1 deletion hooks/CreatureHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "ElunaTemplate.h"

using namespace Hooks;

#ifndef RETAIL
#define START_HOOK(EVENT, CREATURE) \
auto entry_key = EntryKey<CreatureEvents>(EVENT, CREATURE->GetEntry());\
auto unique_key = UniqueObjectKey<CreatureEvents>(EVENT, CREATURE->GET_GUID(), CREATURE->GetInstanceId());\
Expand Down Expand Up @@ -325,3 +325,4 @@ bool Eluna::OwnerAttacked(Creature* me, Unit* target)
}

#endif // TRINITY
#endif
8 changes: 4 additions & 4 deletions hooks/GossipHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ bool Eluna::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender,
auto original_menu = *pPlayer->GetPlayerMenu();
pPlayer->GetPlayerMenu()->ClearMenus();
#else
auto original_menu = *pPlayer->PlayerTalkClass;
auto original_menu = pPlayer->PlayerTalkClass->GetGossipMenu().GetMenuId();
pPlayer->PlayerTalkClass->ClearMenus();
#endif
HookPush(pPlayer);
Expand All @@ -154,7 +154,7 @@ bool Eluna::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender,
#if defined CMANGOS && !defined(CATA)
*pPlayer->GetPlayerMenu() = original_menu;
#else
*pPlayer->PlayerTalkClass = original_menu;
pPlayer->PlayerTalkClass->GetGossipMenu().SetMenuId(original_menu);
#endif
}
return preventDefault;
Expand All @@ -167,7 +167,7 @@ bool Eluna::OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 send
auto original_menu = *pPlayer->GetPlayerMenu();
pPlayer->GetPlayerMenu()->ClearMenus();
#else
auto original_menu = *pPlayer->PlayerTalkClass;
auto original_menu = pPlayer->PlayerTalkClass->GetGossipMenu().GetMenuId();
pPlayer->PlayerTalkClass->ClearMenus();
#endif
HookPush(pPlayer);
Expand All @@ -180,7 +180,7 @@ bool Eluna::OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 send
#if defined CMANGOS &&!defined(CATA)
*pPlayer->GetPlayerMenu() = original_menu;
#else
*pPlayer->PlayerTalkClass = original_menu;
pPlayer->PlayerTalkClass->GetGossipMenu().SetMenuId(original_menu);
#endif
}
return preventDefault;
Expand Down
15 changes: 13 additions & 2 deletions hooks/GuildHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ void Eluna::OnAddMember(Guild* guild, Player* player, uint32 plRank)
CallAllFunctions(GuildEventBindings, key);
}

#ifdef RETAIL
void Eluna::OnRemoveMember(Guild* guild, ObjectGuid guid, bool isDisbanding)
{
START_HOOK(GUILD_EVENT_ON_REMOVE_MEMBER);
HookPush(guild);
HookPush(guid);
HookPush(isDisbanding);
CallAllFunctions(GuildEventBindings, key);
}
#else
void Eluna::OnRemoveMember(Guild* guild, Player* player, bool isDisbanding)
{
START_HOOK(GUILD_EVENT_ON_REMOVE_MEMBER);
Expand All @@ -34,6 +44,7 @@ void Eluna::OnRemoveMember(Guild* guild, Player* player, bool isDisbanding)
HookPush(isDisbanding);
CallAllFunctions(GuildEventBindings, key);
}
#endif

void Eluna::OnMOTDChanged(Guild* guild, const std::string& newMotd)
{
Expand Down Expand Up @@ -94,7 +105,7 @@ void Eluna::OnMemberWitdrawMoney(Guild* guild, Player* player, uint32& amount, b
CleanUpStack(4);
}

#ifdef CATA
#if defined CATA || defined RETAIL
void Eluna::OnMemberWitdrawMoney(Guild* guild, Player* player, uint64& amount, bool isRepair)
{
START_HOOK(GUILD_EVENT_ON_MONEY_WITHDRAW);
Expand Down Expand Up @@ -149,7 +160,7 @@ void Eluna::OnMemberDepositMoney(Guild* guild, Player* player, uint32& amount)
CleanUpStack(3);
}

#ifdef CATA
#if defined CATA || defined RETAIL
void Eluna::OnMemberDepositMoney(Guild* guild, Player* player, uint64& amount)
{
START_HOOK(GUILD_EVENT_ON_MONEY_DEPOSIT);
Expand Down
Loading

0 comments on commit 59e2196

Please sign in to comment.