Page 1 of 1

0.11.4 - EnemyMotor potential out of range exception

Posted: Sun Jun 20, 2021 3:43 am
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).

Re: 0.11.4 - EnemyMotor potential out of range exception

Posted: Tue Jun 22, 2021 3:07 am
by Interkarma
Thank you for detailed report. I'll move this to bug reports for investigation.

Re: 0.11.4 - EnemyMotor potential out of range exception

Posted: Sun Jun 27, 2021 7:13 pm
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"