Single Status Update
I think I figured it out.
There's only one muzzle flash state field for each weapon, but some weapons have two flashes. Like, not one animation made of two frames, but two separate flashes, each one being called based on a certain condition.
The second one's default position in the state table is muzzle flash state + 1. It worked with the plasma gun's attack codepointer, even though I gave it to an entirely different weapon located pretty far from the original plasma gun states.
Not so simple with the chaingun attack. With the plasma attack, the muzzle flash is determined randomly each shot - it's either muzzle flash state or muzzle flash state + 1. The chaingun works like that:
The attack codepointer was called from the attack state = muzzle flash state for the flash
The attack codepointer was called from the attack state + 1 = muzzle flash state + 1 for the flash
And so on. I haven't looked at the code for a long time, so I thought that the attack state is being read from the weapon's properties, which would make sense. Nuh-uh. It's always 52. So the farther the actual attack states were from the state 52, the more ludicrous were the places the engine tried to find a muzzle flash in. Including going over the table's end and crashing the game.
Here's to even more unpleasantness when I test the fix for the first time.