From fd3f80e86017b7a6d8942d00bcd596c54a0e1ccc Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Tue, 28 Mar 2023 17:04:18 +0300 Subject: [PATCH] Fix game hang on invalid shooter animation config --- client/battle/BattleAnimationClasses.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/battle/BattleAnimationClasses.cpp b/client/battle/BattleAnimationClasses.cpp index 30f1eb2b7..96ffffbd4 100644 --- a/client/battle/BattleAnimationClasses.cpp +++ b/client/battle/BattleAnimationClasses.cpp @@ -756,7 +756,15 @@ void ShootingAnimation::createProjectile(const Point & from, const Point & dest) uint32_t ShootingAnimation::getAttackClimaxFrame() const { const CCreature *shooterInfo = getCreature(); - return shooterInfo->animation.attackClimaxFrame; + + uint32_t maxFrames = stackAnimation(attackingStack)->framesInGroup(getGroup()); + uint32_t climaxFrame = shooterInfo->animation.attackClimaxFrame; + uint32_t selectedFrame = vstd::clamp(shooterInfo->animation.attackClimaxFrame, 1, maxFrames); + + if (climaxFrame != selectedFrame) + logGlobal->warn("Shooter %s has ranged attack climax frame set to %d, but only %d available!", shooterInfo->getNamePluralTranslated(), climaxFrame, maxFrames); + + return selectedFrame - 1; // H3 counts frames from 1 } ECreatureAnimType ShootingAnimation::getUpwardsGroup() const