Skip to content

Commit e216838

Browse files
sogladevShauren
andauthored
fix(Core/Vehicle): fix crash when using MC on a player riding a vehicle (azerothcore#24551)
Co-authored-by: Shauren <shauren.trinity@gmail.com>
1 parent 0df7baa commit e216838

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/server/game/Entities/Unit/Unit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18618,7 +18618,7 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type, AuraApplication const* au
1861818618
ASSERT(type != CHARM_TYPE_POSSESS || charmer->IsPlayer());
1861918619
if (type == CHARM_TYPE_VEHICLE && !IsVehicle()) // pussywizard
1862018620
throw 1;
18621-
ASSERT((type == CHARM_TYPE_VEHICLE) == IsVehicle());
18621+
ASSERT((type == CHARM_TYPE_VEHICLE) == (GetVehicleKit() && GetVehicleKit()->IsControllableVehicle()));
1862218622

1862318623
LOG_DEBUG("entities.unit", "SetCharmedBy: charmer {} ({}), charmed {} ({}), type {}.",
1862418624
charmer->GetEntry(), charmer->GetGUID().ToString(), GetEntry(), GetGUID().ToString(), uint32(type));

src/server/game/Entities/Vehicle/Vehicle.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "TemporarySummon.h"
2727
#include "Unit.h"
2828
#include "Util.h"
29+
#include <algorithm>
2930

3031
Vehicle::Vehicle(Unit* unit, VehicleEntry const* vehInfo, uint32 creatureEntry) :
3132
_me(unit), _vehicleInfo(vehInfo), _usableSeatNum(0), _creatureEntry(creatureEntry), _status(STATUS_NONE)
@@ -562,6 +563,11 @@ bool Vehicle::IsVehicleInUse()
562563
return false;
563564
}
564565

566+
bool Vehicle::IsControllableVehicle() const
567+
{
568+
return std::ranges::any_of(Seats, [](auto const& seat) { return seat.second.SeatInfo->CanControl(); });
569+
}
570+
565571
void Vehicle::TeleportVehicle(float x, float y, float z, float ang)
566572
{
567573
_me->GetMap()->LoadGrid(x, y);

src/server/game/Entities/Vehicle/Vehicle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Vehicle : public TransportBase
5151
void RemoveAllPassengers();
5252
void Dismiss();
5353
bool IsVehicleInUse();
54+
[[nodiscard]] bool IsControllableVehicle() const;
5455
void TeleportVehicle(float x, float y, float z, float ang);
5556

5657
SeatMap Seats;

0 commit comments

Comments
 (0)