Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Remove CCharEntity::pushPacket(raw packet) #6713

Merged
merged 12 commits into from
Jan 15, 2025
Merged
8 changes: 4 additions & 4 deletions modules/custom/cpp/ah_announcement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AHAnnouncementModule : public CPPModule

auto originalHandler = PacketParser[0x04E];

auto newHandler = [this, originalHandler](map_session_data_t* const PSession, CCharEntity* const PChar, CBasicPacket& data) -> void
auto newHandler = [originalHandler](map_session_data_t* const PSession, CCharEntity* const PChar, CBasicPacket& data) -> void
{
TracyZoneScoped;

Expand All @@ -72,7 +72,7 @@ class AHAnnouncementModule : public CPPModule

if (PChar->getStorage(LOC_INVENTORY)->GetFreeSlotsCount() == 0)
{
PChar->pushPacket(new CAuctionHousePacket(action, 0xE5, 0, 0, 0, 0));
PChar->pushPacket<CAuctionHousePacket>(action, 0xE5, 0, 0, 0, 0);
}
else
{
Expand All @@ -85,7 +85,7 @@ class AHAnnouncementModule : public CPPModule
{
if (PChar->getStorage(LocID)->SearchItem(itemid) != ERROR_SLOTID)
{
PChar->pushPacket(new CAuctionHousePacket(action, 0xE5, 0, 0, 0, 0));
PChar->pushPacket<CAuctionHousePacket>(action, 0xE5, 0, 0, 0, 0);
return;
}
}
Expand Down Expand Up @@ -179,7 +179,7 @@ class AHAnnouncementModule : public CPPModule
name[0] = std::toupper(name[0]);

// Send message to seller!
message::send(sellerId, new CChatMessagePacket(PChar, MESSAGE_SYSTEM_3,
message::send(sellerId, std::make_unique<CChatMessagePacket>(PChar, MESSAGE_SYSTEM_3,
fmt::format("Your '{}' has sold to {} for {} gil!", name, PChar->name, price).c_str(), ""));
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/custom/cpp/ah_pagination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AHPaginationModule : public CPPModule

auto originalHandler = PacketParser[0x04E];

auto newHandler = [this, ITEMS_PER_PAGE, TOTAL_PAGES, originalHandler](map_session_data_t* const PSession, CCharEntity* const PChar, CBasicPacket& data) -> void
auto newHandler = [ITEMS_PER_PAGE, TOTAL_PAGES, originalHandler](map_session_data_t* const PSession, CCharEntity* const PChar, CBasicPacket& data) -> void
{
TracyZoneScoped;

Expand Down
10 changes: 5 additions & 5 deletions modules/renamer/cpp/renamer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../src/map/packet_guard.h"
#include "../src/map/utils/moduleutils.h"
#include "../src/map/zone.h"
#include "map/packet_guard.h"
#include "map/utils/moduleutils.h"
#include "map/zone.h"

extern uint8 PacketSize[512];
extern std::function<void(map_session_data_t* const, CCharEntity* const, CBasicPacket&)> PacketParser[512];
Expand All @@ -15,14 +15,14 @@ class RenamerModule : public CPPModule
return;
}

auto* customPacket = new CBasicPacket();
auto customPacket = std::unique_ptr<CBasicPacket>();
customPacket->setType(0x1FF);
customPacket->setSize(0x100);
for (std::size_t i = 0; i < data.size(); ++i)
{
customPacket->ref<uint8>(0x04 + i) = data[i];
}
PChar->pushPacket(customPacket);
PChar->pushPacket(std::move(customPacket));
}

void OnInit() override
Expand Down
2 changes: 1 addition & 1 deletion src/map/ability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ namespace ability
{
// TODO: Add message field to table

memset(PAbilityList, 0, sizeof(PAbilityList));
std::memset(PAbilityList, 0, sizeof(PAbilityList));

const char* Query = "SELECT "
"abilityId,"
Expand Down
2 changes: 1 addition & 1 deletion src/map/ability.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#include "common/mmo.h"
#include "packets/action.h"

#include "status_effect.h"
#include "entities/battleentity.h"
#include "status_effect.h"

enum ADDTYPE
{
Expand Down
7 changes: 7 additions & 0 deletions src/map/ai/helpers/gambits_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ namespace gambits
G_SELECT select;
uint32 select_arg = 0;

Action_t(G_REACTION reaction, G_SELECT select, uint32 select_arg)
: reaction(reaction)
, select(select)
, select_arg(select_arg)
{
}

bool parseInput(std::string const& key, uint32 value)
{
if (key.compare("reaction") == 0)
Expand Down
10 changes: 5 additions & 5 deletions src/map/ai/states/ability_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ CAbilityState::CAbilityState(CBattleEntity* PEntity, uint16 targid, uint16 abili

if (!PTarget || m_errorMsg)
{
throw CStateInitException(std::move(m_errorMsg));
throw CStateInitException(m_errorMsg->copy());
}
SetTarget(PTarget->targid);
m_PAbility = std::make_unique<CAbility>(*PAbility);
Expand All @@ -65,7 +65,7 @@ CAbilityState::CAbilityState(CBattleEntity* PEntity, uint16 targid, uint16 abili
actionTarget.animation = 121;
actionTarget.messageID = 326;
actionTarget.param = PAbility->getID();
PEntity->loc.zone->PushPacket(PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
PEntity->loc.zone->PushPacket(PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));
m_PEntity->PAI->EventHandler.triggerListener("ABILITY_START", CLuaBaseEntity(m_PEntity), CLuaAbility(PAbility));

// face toward target
Expand Down Expand Up @@ -127,7 +127,7 @@ bool CAbilityState::Update(time_point tick)
action_t action;
m_PEntity->OnAbility(*this, action);
m_PEntity->PAI->EventHandler.triggerListener("ABILITY_USE", CLuaBaseEntity(m_PEntity), CLuaBaseEntity(GetTarget()), CLuaAbility(m_PAbility.get()), CLuaAction(&action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));
if (auto* target = GetTarget())
{
target->PAI->EventHandler.triggerListener("ABILITY_TAKE", CLuaBaseEntity(target), CLuaBaseEntity(m_PEntity), CLuaAbility(m_PAbility.get()), CLuaAction(&action));
Expand All @@ -149,7 +149,7 @@ bool CAbilityState::Update(time_point tick)
actionTarget.animation = 0x1FC;
actionTarget.reaction = REACTION::MISS;

m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));
}
Complete();
}
Expand Down Expand Up @@ -282,7 +282,7 @@ bool CAbilityState::CanUseAbility()
actionTarget.param = 0; // Observed as 639 on retail, but I'm not sure that it actually does anything.
actionTarget.messageID = tooFarAway ? MSGBASIC_TOO_FAR_AWAY_RED : 0;

m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));
}
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/map/ai/states/attack_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ CAttackState::CAttackState(CBattleEntity* PEntity, uint16 targid)
if (!GetTarget() || m_errorMsg)
{
PEntity->SetBattleTargetID(0);
throw CStateInitException(std::move(m_errorMsg));
throw CStateInitException(m_errorMsg->copy());
}
if (PEntity->PAI->PathFind)
{
Expand Down Expand Up @@ -68,7 +68,7 @@ bool CAttackState::Update(time_point tick)
// CMobEntity::OnAttack(...) can generate it's own action with a mobmod, and that leaves this action.actionType = 0, which is never valid. Skip sending the packet.
if (action.actiontype != ACTION_NONE)
{
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/map/ai/states/despawn_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CDespawnState::CDespawnState(CBaseEntity* _PEntity, bool instantDespawn)
{
if (!instantDespawn && (_PEntity->status != STATUS_TYPE::DISAPPEAR && !(static_cast<CMobEntity*>(_PEntity)->m_Behavior & BEHAVIOR_NO_DESPAWN)))
{
_PEntity->loc.zone->PushPacket(_PEntity, CHAR_INRANGE, new CEntityAnimationPacket(_PEntity, _PEntity, CEntityAnimationPacket::Fade_Out));
_PEntity->loc.zone->PushPacket(_PEntity, CHAR_INRANGE, std::make_unique<CEntityAnimationPacket>(_PEntity, _PEntity, CEntityAnimationPacket::Fade_Out));
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/map/ai/states/item_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ CItemState::CItemState(CCharEntity* PEntity, uint16 targid, uint8 loc, uint8 slo

if (!PTarget || m_errorMsg)
{
throw CStateInitException(std::move(m_errorMsg));
throw CStateInitException(m_errorMsg->copy());
}

auto [error, param, value] = luautils::OnItemCheck(PTarget, m_PItem, ITEMCHECK::NONE, m_PEntity);
Expand Down Expand Up @@ -126,7 +126,7 @@ CItemState::CItemState(CCharEntity* PEntity, uint16 targid, uint8 loc, uint8 slo
actionTarget.knockback = 0;

m_PEntity->PAI->EventHandler.triggerListener("ITEM_START", CLuaBaseEntity(PTarget), CLuaItem(m_PItem), CLuaAction(&action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));

m_PItem->setSubType(ITEM_LOCKED);

Expand Down Expand Up @@ -182,7 +182,7 @@ bool CItemState::Update(time_point tick)
FinishItem(action);
}
m_PEntity->PAI->EventHandler.triggerListener("ITEM_USE", CLuaBaseEntity(m_PEntity), CLuaItem(m_PItem), CLuaAction(&action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));
Complete();
}
else if (IsCompleted() && tick > GetEntryTime() + m_castTime + m_animationTime)
Expand Down Expand Up @@ -294,7 +294,7 @@ void CItemState::InterruptItem(action_t& action)
actionTarget.messageID = 0;
actionTarget.knockback = 0;

m_PEntity->pushPacket(m_errorMsg.release());
m_PEntity->pushPacket(m_errorMsg->copy());
}
}

Expand Down
28 changes: 14 additions & 14 deletions src/map/ai/states/magic_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ CMagicState::CMagicState(CBattleEntity* PEntity, uint16 targid, SpellID spellid,
auto* PTarget = m_PEntity->IsValidTarget(m_targid, m_PSpell->getValidTarget(), m_errorMsg);
if (!PTarget || m_errorMsg)
{
throw CStateInitException(std::move(m_errorMsg));
throw CStateInitException(m_errorMsg->copy());
}

if (!CanCastSpell(PTarget, false))
{
throw CStateInitException(std::move(m_errorMsg));
throw CStateInitException(m_errorMsg->copy());
}

auto errorMsg = luautils::OnMagicCastingCheck(m_PEntity, PTarget, GetSpell());
Expand Down Expand Up @@ -94,7 +94,7 @@ CMagicState::CMagicState(CBattleEntity* PEntity, uint16 targid, SpellID spellid,
// TODO: weaponskill lua object
m_PEntity->PAI->EventHandler.triggerListener("MAGIC_START", CLuaBaseEntity(m_PEntity), CLuaSpell(m_PSpell.get()), CLuaAction(&action));

m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));
}

bool CMagicState::Update(time_point tick)
Expand All @@ -110,7 +110,7 @@ bool CMagicState::Update(time_point tick)
(HasMoved() && (m_PEntity->objtype != TYPE_PET || static_cast<CPetEntity*>(m_PEntity)->getPetType() != PET_TYPE::AUTOMATON)))
{
m_PEntity->OnCastInterrupted(*this, action, msg, false);
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));

Complete();
return false;
Expand All @@ -121,7 +121,7 @@ bool CMagicState::Update(time_point tick)
if (PChar->m_Locked)
{
m_PEntity->OnCastInterrupted(*this, action, msg, true);
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));

Complete();
return false;
Expand All @@ -133,7 +133,7 @@ bool CMagicState::Update(time_point tick)
{
m_PEntity->OnCastInterrupted(*this, action, MSGBASIC_TRUST_NO_CAST_TRUST, true);
action.recast = 2; // seems hardcoded to 2
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));

Complete();
return false;
Expand All @@ -153,7 +153,7 @@ bool CMagicState::Update(time_point tick)
if (PChar->m_Locked)
{
m_PEntity->OnCastInterrupted(*this, action, msg, true);
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));

Complete();
return false;
Expand All @@ -164,7 +164,7 @@ bool CMagicState::Update(time_point tick)
if (PTarget->PAI->IsUntargetable())
{
m_PEntity->OnCastInterrupted(*this, action, msg, true);
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));

Complete();
return false;
Expand All @@ -176,7 +176,7 @@ bool CMagicState::Update(time_point tick)
m_PEntity->setActionInterrupted(interruptedAction, PTarget, MSGBASIC_IS_PARALYZED_2, static_cast<uint16>(m_PSpell->getID()));
interruptedAction.recast = 2; // seems hardcoded to 2
interruptedAction.actionid = static_cast<uint16>(m_PSpell->getID());
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(interruptedAction));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(interruptedAction));

// Yes, you're seeing this correctly.
// A paralyze/interrupt proc on *spells* actually sends two actions. One that contains the para/intimidate message
Expand All @@ -194,7 +194,7 @@ bool CMagicState::Update(time_point tick)
actionTarget.messageID = 0;
actionTarget.animation = 0;
actionTarget.param = 0; // sometimes 1?
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));

Complete();
return false;
Expand All @@ -205,7 +205,7 @@ bool CMagicState::Update(time_point tick)
m_PEntity->setActionInterrupted(interruptedAction, PTarget, MSGBASIC_IS_INTIMIDATED, static_cast<uint16>(m_PSpell->getID()));
interruptedAction.recast = 2; // seems hardcoded to 2
interruptedAction.actionid = static_cast<uint16>(m_PSpell->getID());
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(interruptedAction));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(interruptedAction));

// See comment in above block for paralyze
action.id = m_PEntity->id;
Expand All @@ -220,7 +220,7 @@ bool CMagicState::Update(time_point tick)
actionTarget.messageID = 0;
actionTarget.animation = 0;
actionTarget.param = 0; // sometimes 1?
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));

Complete();
return false;
Expand All @@ -237,7 +237,7 @@ bool CMagicState::Update(time_point tick)
PTarget->PAI->EventHandler.triggerListener("MAGIC_TAKE", CLuaBaseEntity(PTarget), CLuaBaseEntity(m_PEntity), CLuaSpell(m_PSpell.get()), CLuaAction(&action));
}

m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));

Complete();
}
Expand All @@ -260,7 +260,7 @@ void CMagicState::Cleanup(time_point tick)
{
action_t action;
m_PEntity->OnCastInterrupted(*this, action, MSGBASIC_IS_INTERRUPTED, false);
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/map/ai/states/mobskill_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CMobSkillState::CMobSkillState(CBattleEntity* PEntity, uint16 targid, uint16 wsi

if (!PTarget || m_errorMsg)
{
throw CStateInitException(std::move(m_errorMsg));
throw CStateInitException(m_errorMsg->copy());
}

m_PSkill = std::make_unique<CMobSkill>(*skill);
Expand All @@ -72,7 +72,7 @@ CMobSkillState::CMobSkillState(CBattleEntity* PEntity, uint16 targid, uint16 wsi
actionTarget.animation = 0;
actionTarget.param = m_PSkill->getID();
actionTarget.messageID = 43;
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));

// face toward target // TODO : add force param to turnTowardsTarget on certain TP moves like Petro Eyes
battleutils::turnTowardsTarget(m_PEntity, PTarget);
Expand Down Expand Up @@ -126,7 +126,7 @@ bool CMobSkillState::Update(time_point tick)
{
action_t action;
m_PEntity->OnMobSkillFinished(*this, action);
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));
auto delay = std::chrono::milliseconds(m_PSkill->getAnimationTime());
m_finishTime = tick + delay;
Complete();
Expand Down Expand Up @@ -173,7 +173,7 @@ void CMobSkillState::Cleanup(time_point tick)
actionTarget.animation = 0x1FC; // Not perfectly accurate, this animation ID can change from time to time for unknown reasons.
actionTarget.reaction = REACTION::HIT;

m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, std::make_unique<CActionPacket>(action));

// On retail testing, mobs lose 33% of their TP at 2900 or higher TP
// But lose 25% at < 2900 TP.
Expand Down
Loading
Loading