1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-23 05:39:42 +00:00

Merge pull request #2819 from elsid/fix_ub

Fix UB in NpcAnimation::mNpcType initialization
This commit is contained in:
Alexei Dobrohotov 2020-05-01 21:49:04 +03:00 committed by GitHub
commit 7ba8176862
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View file

@ -266,16 +266,22 @@ void HeadAnimationTime::setBlinkStop(float value)
// ---------------------------------------------------- // ----------------------------------------------------
NpcAnimation::NpcType NpcAnimation::getNpcType() NpcAnimation::NpcType NpcAnimation::getNpcType() const
{ {
const MWWorld::Class &cls = mPtr.getClass(); const MWWorld::Class &cls = mPtr.getClass();
// Dead vampires should typically stay vampires. // Dead vampires should typically stay vampires.
if (mNpcType == Type_Vampire && cls.getNpcStats(mPtr).isDead() && !cls.getNpcStats(mPtr).isWerewolf()) if (mNpcType == Type_Vampire && cls.getNpcStats(mPtr).isDead() && !cls.getNpcStats(mPtr).isWerewolf())
return mNpcType; return mNpcType;
return getNpcType(mPtr);
}
NpcAnimation::NpcType NpcAnimation::getNpcType(const MWWorld::Ptr& ptr)
{
const MWWorld::Class &cls = ptr.getClass();
NpcAnimation::NpcType curType = Type_Normal; NpcAnimation::NpcType curType = Type_Normal;
if (cls.getCreatureStats(mPtr).getMagicEffects().get(ESM::MagicEffect::Vampirism).getMagnitude() > 0) if (cls.getCreatureStats(ptr).getMagicEffects().get(ESM::MagicEffect::Vampirism).getMagnitude() > 0)
curType = Type_Vampire; curType = Type_Vampire;
if (cls.getNpcStats(mPtr).isWerewolf()) if (cls.getNpcStats(ptr).isWerewolf())
curType = Type_Werewolf; curType = Type_Werewolf;
return curType; return curType;
@ -326,7 +332,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, osg::ref_ptr<osg::Group> par
mViewMode(viewMode), mViewMode(viewMode),
mShowWeapons(false), mShowWeapons(false),
mShowCarriedLeft(true), mShowCarriedLeft(true),
mNpcType(getNpcType()), mNpcType(getNpcType(ptr)),
mFirstPersonFieldOfView(firstPersonFieldOfView), mFirstPersonFieldOfView(firstPersonFieldOfView),
mSoundsDisabled(disableSounds), mSoundsDisabled(disableSounds),
mAccurateAiming(false), mAccurateAiming(false),

View file

@ -74,7 +74,7 @@ private:
void updateNpcBase(); void updateNpcBase();
NpcType getNpcType(); NpcType getNpcType() const;
PartHolderPtr insertBoundedPart(const std::string &model, const std::string &bonename, PartHolderPtr insertBoundedPart(const std::string &model, const std::string &bonename,
const std::string &bonefilter, bool enchantedGlow, osg::Vec4f* glowColor=nullptr); const std::string &bonefilter, bool enchantedGlow, osg::Vec4f* glowColor=nullptr);
@ -94,6 +94,7 @@ private:
static bool isFirstPersonPart(const ESM::BodyPart* bodypart); static bool isFirstPersonPart(const ESM::BodyPart* bodypart);
static bool isFemalePart(const ESM::BodyPart* bodypart); static bool isFemalePart(const ESM::BodyPart* bodypart);
static NpcType getNpcType(const MWWorld::Ptr& ptr);
protected: protected:
virtual void addControllers(); virtual void addControllers();