Describe the problem
In situations where an MG is firing and the ammo box it's firing from empties mid-fire, the MG will continue trying to fire forever and one will see damage floaties forever. This is easy to replicate in vanilla by changing the ammo box for MGs to have 3 ammo in them and start a skirmish with a mech that has at least one MG. When you go to fire you will see this. It is possible to get in this state in the base game if you have multiple ammo boxes and MGs such that they are pulling ammo to create amounts in the ammo boxes not divisible by the number of shots (5).
The reason this happens is there is an out of bound exception in BurstBallisticEffect.Update in two places which causes update to never mark the firing as complete.
It was more severe in modded games because of changes to number of shots and the addition of other items like half-ammo boxes, which made the likelihood of running out of ammo higher and the likelihood of firing after all ammo was consumed higher.
Provide an example of the code where the problem occurs
There's no guarantee in either case that hitLocations will have the index being used because hitLocations is computed way before/outside Update and stops adding new hit locations when ammo is gone.
Provide an example of your proposed solution
I wrote a mod that patches the problem using IL, but the fix is pretty easy and you can see it in the comments in this file.
To save clicking, the first conditional needs to change to something like:
The important new part is this.hitIndex < this.hitInfo.hitLocations.Length.
The second thing that changes is the loop condition in the for loop:
for (int index = 0;
index < this.hitInfo.hitLocations.Length && index < this.weapon.ShotsWhenFired;
++index)
The important part there is index < this.hitInfo.hitLocations.Length.
Provide a link to a commit in the private repo for this issue
Didn't make one because of the mod.
Leave any additional comments here
This fix has been used in at least the mod RogueTech for about a week to solve the issue of MGs and other BurstBallisticEffect-based weapons soft locking.
Describe the problem In situations where an MG is firing and the ammo box it's firing from empties mid-fire, the MG will continue trying to fire forever and one will see damage floaties forever. This is easy to replicate in vanilla by changing the ammo box for MGs to have 3 ammo in them and start a skirmish with a mech that has at least one MG. When you go to fire you will see this. It is possible to get in this state in the base game if you have multiple ammo boxes and MGs such that they are pulling ammo to create amounts in the ammo boxes not divisible by the number of shots (5).
The reason this happens is there is an out of bound exception in
BurstBallisticEffect.Update
in two places which causes update to never mark the firing as complete.It was more severe in modded games because of changes to number of shots and the addition of other items like half-ammo boxes, which made the likelihood of running out of ammo higher and the likelihood of firing after all ammo was consumed higher.
Provide an example of the code where the problem occurs
Two places: 1 and 2
There's no guarantee in either case that
hitLocations
will have the index being used becausehitLocations
is computed way before/outsideUpdate
and stops adding new hit locations when ammo is gone.Provide an example of your proposed solution
I wrote a mod that patches the problem using IL, but the fix is pretty easy and you can see it in the comments in this file.
To save clicking, the first conditional needs to change to something like:
The important new part is
this.hitIndex < this.hitInfo.hitLocations.Length
.The second thing that changes is the loop condition in the for loop:
The important part there is
index < this.hitInfo.hitLocations.Length
.Provide a link to a commit in the private repo for this issue
Didn't make one because of the mod.
Leave any additional comments here
This fix has been used in at least the mod RogueTech for about a week to solve the issue of MGs and other
BurstBallisticEffect
-based weapons soft locking.