Slips in the mission script interpreter
Each mission is a script of 16-byte command slots that the map scene runs (see mission scripts). The interpreter has a few mistakes. The original scripts were written around them or never touch them, so none is known to show up in normal play. They matter to anyone writing new missions.
- Where
- main.dol, map script interpreter (map_script_step)
- Bugs in the interpreter
- Several, listed below
- Hit by the shipped missions
- Not known to cause a visible problemUnconfirmed
The mistakes
| Command | What goes wrong |
|---|---|
| 22, dialogue | Reads its “kind” uninitialised when argument byte 5 is neither 0 nor 1. |
| 41, an enemy squad appears | Writes 0xBB (the “no monster” id) back into the loaded script where a monster byte was 0xFF. Running the same command a second time in one mission would then treat the empty slot as holding a monster and write its three skill slots through a null pointer. No shipped script is known to run one twice. (The command is two slots long, so moving the script position on by two is correct.) |
| 54, a unit near a point | Keeps scanning after a hit. With no “taken” target it steps the script position once per matching unit and still runs the “not taken” target afterwards, so each unit in range skips one of the commands that follow. S07.lsc command 43 has neither target: while Kaiba’s unit is in its range, command 44, a test of a point far away, is skipped. |
| 61, a monster in a marshal’s team | With no “taken” target it ignores its test and always runs “not taken”; when the test holds and there is no “not taken” target, it skips the first command of the “taken” block. The two scripts that use it (S12.lsc, y09.lsc) start that block with a marker, which is harmless to skip. With both targets set it calls both. |
| 13 and 14, fades | Divide 128 by the fade’s length in frames; a length of 0 divides by zero. The console does not crash; with a quotient of 0, the value the Dolphin emulator gives, the fade never advances and the script waits on it for ever. |
| calls | A condition’s target is a call, kept on a stack of four. A fifth nested call writes its return address into the script’s flag bytes 0 and 1. |
By design, the interpreter keeps running commands within a frame until one of them waits. A jump to itself, or any loop without a waiting command, freezes the game. Inserting raw bytes into a script without fixing its jump targets is the usual way to cause one.
Evidence
All of these come from the decompiled interpreter, whose code matches the original machine code exactly, and the uses were found by decoding all 56 shipped mission scripts. No shipped script has a fade of 0 frames.