Skip to content

Commit

Permalink
Core: All pushPacket methods now take unique_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
zach2good committed Jan 14, 2025
1 parent eb7f7ad commit 88d412e
Show file tree
Hide file tree
Showing 47 changed files with 166 additions and 183 deletions.
2 changes: 1 addition & 1 deletion modules/custom/cpp/ah_announcement.cpp
Original file line number Diff line number Diff line change
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
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.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
8 changes: 4 additions & 4 deletions src/map/ai/states/ability_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/map/ai/states/attack_state.cpp
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions src/map/ai/states/item_state.cpp
Original file line number Diff line number Diff line change
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
24 changes: 12 additions & 12 deletions src/map/ai/states/magic_state.cpp
Original file line number Diff line number Diff line change
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
6 changes: 3 additions & 3 deletions src/map/ai/states/mobskill_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions src/map/ai/states/petskill_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ CPetSkillState::CPetSkillState(CPetEntity* PEntity, uint16 targid, uint16 wsid)
actionTarget.animation = 0;
actionTarget.param = m_PSkill->getID();
actionTarget.messageID = 326; // Seems hardcoded? TODO: Verify on more pet actions. Tested on Wyvern and SMN BPs.
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE, std::make_unique<CActionPacket>(action));
}
m_PEntity->PAI->EventHandler.triggerListener("WEAPONSKILL_STATE_ENTER", CLuaBaseEntity(m_PEntity), m_PSkill->getID());
SpendCost();
Expand All @@ -97,7 +97,7 @@ bool CPetSkillState::Update(time_point tick)
{
action_t action;
m_PEntity->OnPetSkillFinished(*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 @@ -144,6 +144,6 @@ void CPetSkillState::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, new CActionPacket(action));
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE, std::make_unique<CActionPacket>(action));
}
}
6 changes: 3 additions & 3 deletions src/map/ai/states/range_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ CRangeState::CRangeState(CBattleEntity* PEntity, uint16 targid)

m_PEntity->PAI->EventHandler.triggerListener("RANGE_START", CLuaBaseEntity(m_PEntity), 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));
}

void CRangeState::SpendCost()
Expand Down Expand Up @@ -128,15 +128,15 @@ bool CRangeState::Update(time_point tick)
}
// reset aim time so interrupted players only have to wait the correct 2.7s until next shot
m_aimTime = std::chrono::seconds(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));
m_PEntity->PAI->EventHandler.triggerListener("RANGE_STATE_EXIT", CLuaBaseEntity(m_PEntity), nullptr, CLuaAction(&action));
}
else
{
m_errorMsg.reset();

m_PEntity->OnRangedAttack(*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));
m_PEntity->PAI->EventHandler.triggerListener("RANGE_STATE_EXIT", CLuaBaseEntity(m_PEntity), CLuaBaseEntity(PTarget), CLuaAction(&action));
}

Expand Down
6 changes: 3 additions & 3 deletions src/map/ai/states/weaponskill_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ CWeaponSkillState::CWeaponSkillState(CBattleEntity* PEntity, uint16 targid, uint
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));
}

CWeaponSkill* CWeaponSkillState::GetSkill()
Expand Down Expand Up @@ -118,7 +118,7 @@ bool CWeaponSkillState::Update(time_point tick)
SpendCost();

m_PEntity->OnWeaponSkillFinished(*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));

// Reset Restraint bonus and trackers on weaponskill use
if (m_PEntity->StatusEffectContainer->HasStatusEffect(EFFECT_RESTRAINT))
Expand Down Expand Up @@ -169,7 +169,7 @@ bool CWeaponSkillState::Update(time_point tick)
actionTarget.messageID = 0;
actionTarget.reaction = REACTION::ABILITY | 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));
}

auto delay = m_PSkill->getAnimationTime(); // TODO: Is delay time a fixed number if the weaponskill is used out of range?
Expand Down
2 changes: 1 addition & 1 deletion src/map/battlefield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ bool CBattlefield::RemoveEntity(CBaseEntity* PEntity, uint8 leavecode)
PMob->PEnmityContainer->Clear();
}
}
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));
}

PEntity->PBattlefield = nullptr;
Expand Down
Loading

0 comments on commit 88d412e

Please sign in to comment.