Browse Source

Avoid overflow of tickCounterOfCurrentFrame (#4893)

* When MFLAG_ALLOW_SPECIAL is set, don't call processAnimation (avoid overflow of tickCounterOfCurrentFrame)
pull/4881/merge
obligaron 4 years ago committed by GitHub
parent
commit
3c571bf64b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      Source/engine/animationinfo.cpp
  2. 2
      Source/engine/animationinfo.h
  3. 3
      Source/loadsave.cpp
  4. 6
      Source/monster.cpp

4
Source/engine/animationinfo.cpp

@ -185,11 +185,9 @@ void AnimationInfo::changeAnimationData(OptionalCelSprite celSprite, int8_t numb
this->celSprite = celSprite;
}
void AnimationInfo::processAnimation(bool reverseAnimation /*= false*/, bool dontProgressAnimation /*= false*/)
void AnimationInfo::processAnimation(bool reverseAnimation /*= false*/)
{
tickCounterOfCurrentFrame++;
if (dontProgressAnimation)
return;
ticksSinceSequenceStarted_++;
if (tickCounterOfCurrentFrame >= ticksPerFrame) {
tickCounterOfCurrentFrame = 0;

2
Source/engine/animationinfo.h

@ -97,7 +97,7 @@ public:
* @param reverseAnimation Play the animation backwards (for example is used for "unseen" monster fading)
* @param dontProgressAnimation Increase tickCounterOfCurrentFrame but don't change currentFrame
*/
void processAnimation(bool reverseAnimation = false, bool dontProgressAnimation = false);
void processAnimation(bool reverseAnimation = false);
private:
/**

3
Source/loadsave.cpp

@ -593,7 +593,8 @@ void LoadMonster(LoadHelper *file, Monster &monster)
file->Skip(4); // Skip pointer _mAnimData
monster.AnimInfo = {};
monster.AnimInfo.ticksPerFrame = file->NextLENarrow<int32_t, int8_t>();
monster.AnimInfo.tickCounterOfCurrentFrame = file->NextLENarrow<int32_t, int8_t>();
// Ensure that we can increase the tickCounterOfCurrentFrame at least once without overflow (needed for backwards compatibility for sitting gargoyles)
monster.AnimInfo.tickCounterOfCurrentFrame = file->NextLENarrow<int32_t, int8_t>(1) - 1;
monster.AnimInfo.numberOfFrames = file->NextLENarrow<int32_t, int8_t>();
monster.AnimInfo.currentFrame = file->NextLENarrow<int32_t, int8_t>(-1);
file->Skip(4); // Skip _meflag

6
Source/monster.cpp

@ -1464,7 +1464,7 @@ bool MonsterRangedSpecialAttack(int monsterId)
assert(monsterId >= 0 && monsterId < MaxMonsters);
auto &monster = Monsters[monsterId];
if (monster.AnimInfo.currentFrame == monster.data().mAFNum2 - 1 && monster.AnimInfo.tickCounterOfCurrentFrame == 0) {
if (monster.AnimInfo.currentFrame == monster.data().mAFNum2 - 1 && monster.AnimInfo.tickCounterOfCurrentFrame == 0 && (monster._mAi != AI_MEGA || monster._mVar2 == 0)) {
if (AddMissile(
monster.position.tile,
monster.enemyPosition,
@ -4282,8 +4282,8 @@ void ProcessMonsters()
GroupUnity(monster);
}
} while (raflag);
if (monster._mmode != MonsterMode::Petrified) {
monster.AnimInfo.processAnimation((monster._mFlags & MFLAG_LOCK_ANIMATION) != 0, (monster._mFlags & MFLAG_ALLOW_SPECIAL) != 0);
if (monster._mmode != MonsterMode::Petrified && (monster._mFlags & MFLAG_ALLOW_SPECIAL) == 0) {
monster.AnimInfo.processAnimation((monster._mFlags & MFLAG_LOCK_ANIMATION) != 0);
}
}

Loading…
Cancel
Save