0.11.4 - EnemyMotor potential out of range exception

Moderators will move topics here from Help & Support once an issue has been confirmed and enough information provided to reproduce.
Post Reply
User avatar
Posts: 63
Joined: Wed Apr 14, 2021 1:58 am
Location: Southeast US

0.11.4 - EnemyMotor potential out of range exception

Post by DunnyOfPenwick »

Was testing a mod earlier and came across a bug related to attacking allies. (index out of bounds)

--EnemyMotor.cs lines 184,185

Code: Select all

	int id = (entityBehaviour.Entity as EnemyEntity).MobileEnemy.ID;
	entityBehaviour.Entity.Team = EnemyBasics.Enemies[id].Team;
When player attacking an ally that is an enemy-class type, the ID doesn't correspond with the array index.
MobileEnemy.ID skips from 42 to 128 for enemy class types.
Should work fine for monster types.

Possible fix is to use the GameObjectHelper.EnemyDict Dictionary

Code: Select all

	entityBehaviour.Entity.Team = GameObjectHelper.EnemyDict[id].Team;
Another possible fix is to call EnemyBasics.GetEnemy() (slower).

User avatar
Posts: 6578
Joined: Sun Mar 22, 2015 1:51 am

Re: 0.11.4 - EnemyMotor potential out of range exception

Post by Interkarma »

Thank you for detailed report. I'll move this to bug reports for investigation.

User avatar
Kab the Bird Ranger
Posts: 74
Joined: Tue Feb 23, 2021 12:30 am

Re: 0.11.4 - EnemyMotor potential out of range exception

Post by Kab the Bird Ranger »

I've also seen this issue when investigating a possible solution for allowing mods to add new enemy types (viewtopic.php?f=23&t=4915). Going through the GameObjectHelper enemy dictionary would work best for eventual custom enemy types.

Since this code only runs for player allies, I assume the only repro is to attack clones created by the Skull of Corruption, when the nearest enemy is an EnemyClass type.

On that subject, the only other case of indexing EnemyBasics.Enemies is in SoulBound.cs, line 64

Code: Select all

SecondaryDisplayName = TextManager.Instance.GetLocalizedEnemyName(EnemyBasics.Enemies[i].ID)
This one is not an issue for unmodded DFU, because "i" only goes from 0 to 42. However, the access to EnemyBasics.Enemies is not needed, since "EnemyBasics.Enemies.ID" is equal to to "i"

Post Reply