[Client] Rework MechanicsHelper::getTarget() to avoid crashes

0.6.3
David Cernat 7 years ago
parent 7f0549fc4f
commit 509882b5f6

@ -97,31 +97,33 @@ MWWorld::Ptr MechanicsHelper::getPlayerPtr(const Target& target)
mwmp::Target MechanicsHelper::getTarget(const MWWorld::Ptr& ptr)
{
mwmp::Target target;
clearTarget(target);
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())
{
target.isPlayer = true;
target.guid = mwmp::Main::get().getLocalPlayer()->guid;
}
else if (mwmp::PlayerList::isDedicatedPlayer(ptr))
if (ptr != nullptr)
{
target.isPlayer = true;
target.guid = mwmp::PlayerList::getPlayer(ptr)->guid;
}
else
{
MWWorld::CellRef *ptrRef = &ptr.getCellRef();
if (ptrRef)
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())
{
target.isPlayer = false;
target.refId = ptrRef->getRefId();
target.refNumIndex = ptrRef->getRefNum().mIndex;
target.mpNum = ptrRef->getMpNum();
target.name = ptr.getClass().getName(ptr);
target.isPlayer = true;
target.guid = mwmp::Main::get().getLocalPlayer()->guid;
}
else if (mwmp::PlayerList::isDedicatedPlayer(ptr))
{
target.isPlayer = true;
target.guid = mwmp::PlayerList::getPlayer(ptr)->guid;
}
else
clearTarget(target);
{
MWWorld::CellRef *ptrRef = &ptr.getCellRef();
if (ptrRef)
{
target.isPlayer = false;
target.refId = ptrRef->getRefId();
target.refNumIndex = ptrRef->getRefNum().mIndex;
target.mpNum = ptrRef->getMpNum();
target.name = ptr.getClass().getName(ptr);
}
}
}
return target;

Loading…
Cancel
Save