Leftovers found by reading the code
A matching decompilation has to reproduce the original code exactly, so it cannot tidy up. Shapes in the machine code that look pointless have to be explained by the source that produced them, and some can only be explained by code the developers left behind. Almost none of them change what a player sees; they show how the source looked.
- Where
- main.dol game code, HSD and the effect modules
- Found in the original code
- Yes, all kept in the decompiled source
- Visible in play
- The lightning jitter that a division by zero can cause; no other visible effect is knownUnconfirmed
A test that was removed, but not completely
The function that works out a monster’s stats handles its terrain traits in a switch. Two of its cases contain jumps that lead nowhere different: one case is a lone jump, the other a test whose two outcomes go to the same place. The compiler only leaves those shapes when the source had a test there whose result no longer mattered, so the original read something like:
case 5: if (terrain == 5) continue; break;
case 6: if (terrain == 5 || terrain == 6) continue; break;
Neither outcome of those tests does anything different, so whatever they once decided is gone; only the tests are left. Only one value, the first 5 in the second line, can actually be read off the code; the compiler threw the rest away, so the other values are a reconstruction.
A loop with nothing in it
The entry functions of modules z257 (the special attack of Swordstalker, Beast of Gilfer and Mystical Beast Serket) and z269 (Twin-Headed Thunder Dragon’s special attack and the card Power of Nature) contain a loop over their targets with an empty body. The compiler kept the loop: the code counts through the targets and does nothing with them, so the source must have read for (i = 0; i < count; i++) {}. The map’s unit-selection panel ends with the same kind of loop over the selected units (at 0x8001062C, unrolled eight times).
Variables set and never used
157 effect modules start their entry function with three initialised local variables, a green colour and two vectors, that no code reads. The compiler writes no code for them but still stores their starting values with the module’s constants, which is how they were found (the effect modules as a family). The same happens in module b117, which works out the average of three of the attacking monster’s points as its starting point and then overwrites it with one of them.
Reading before anything is written
Some functions read a variable that nothing has set, and use whatever the memory happens to hold:
- HAL’s library builds the colour constants for the graphics hardware in a local table it never clears, so some calls carry leftover stack data in colour channels the hardware does not use.
- One effect library draw adds an angle offset that nothing sets; it takes whatever is in a processor register at the time.
- The map’s information panel reads a page number that is not set in some of its phases; whether that ever shows on screen is not known.
Writing past the end
- Two effect library functions (
fx_loops_step,fx_twists_step) declare an array of three corner points and fill four. The fourth corner lands on a matrix next to it in memory that is no longer needed, so nothing breaks. - The game calls the SDK’s stick-clamping function on a single controller record, but the function always works through four, so it reads and rewrites the stick values of up to three records past it. No effect of this has been seen on the console; that it is harmless there is an inference.
- Module
b105’s start fills 64 rows of a 16-row table (slips in the attack effects).
Dividing by zero
The GameCube’s processor does not stop on a division by zero. It returns 0 (or -1 for a negative number), and the remainder then equals the number being divided. Several places in the game can divide by zero and simply carry on with that result; the clearest case is the lightning effects (lightning that divides by zero).
Evidence
Each item was found while rewriting the function in C and confirmed by building it: the C only produces the original instructions when it has these shapes. The removed test, the empty loops and the unused variables are the plainest source forms found that give the code and data on the disc.