RBA is very simple.
Basically, your button inventory is represented by the following sequence, where each value is a single byte big.
B Button, C-Left, C-Down, C-Right, C-Left Slot, C-Down Slot, C-Right Slot
The purpose the slot values serve is they point back into your inventory to show what item you've selected, and in the case of bottle items, what bottle you have equipped (as they are otherwise identical). So if you have a bottle on C-Right, and it's contents are updated, the code that handles bottle items would update the C-Right item, then look into the relevant slot (which is 3 bytes over), and update the inventory of that slot.
With RBA, when you duplicate a bottle on B there is no equivalent B inventory slot value stored, so it reads the C-Right button item as an offset into your inventory, writing the value of the bottle item into some place in memory after the start of where the inventory is stored. And since there are only 24 inventory slots vs 55 possible C-Right items, RBA can overwrite more than just the memory slots used to hold items.
It then becomes a matter of knowing the internal values used to represent the different items, and knowing what address stores what data, and how.
As for Ganondoor (and really wrong warping in general), you are confused on an important (and quite difficult to explain) aspect of the trick. When you touch the blue warp normally (no tricks) when you are to receive the Kokiri Emerald, the blue warp will store two important values into a temporary spot, which the game will then copy over once the game engine is ready to load a new area. They are the following:
- The first is what I call a Base Entrance Index. It's a two byte index value used to determine what entrance to place you at next.
- The second is what I call the Cutscene Entrance Offset. It's a two byte value that does a multitude of things. It modifies where the Base Entrance Index places, you and it causes a specific type of cutscene (one which requires different set of assets) to load and play depending on the cutscene number it represents. Values FFF0 - FFFF? represent cutscenes 0 through 15; 0000 represents no cutscene... usually.
You can't quite understand how these two values work together without understanding how the entrance table works. The entrance table is just a table which stores an area to load, and what position to be placed at. The messy part to this is that for each logical entrance (the entrance to the Deku Tree for example), there are at least
four different records into the entrance table, one for every combination of day/night and child/adult. Then, if an area has a certain type of cutscene which requires different assets to be loaded, the first logical entrance will also have one extra entrance for every cutscene it has.
This is where our two values come in. The Base Entrance Index is an index value to the first record in the entrance table for a logical entrance (which is the Child Day record). If the Cutscene Entrance Offset is defined, the game will take the logical entrance, and add 4 + the number of the cutscene the Cutscene Entrance Offset represents. Otherwise it uses time/age to determine the entrance record that is chosen.
Back to our Blue Warp, when you touch it when you are to get the Kokiri Emerald, it sets a Base Entrance Index of 00EE (the first entrance record to the first logical entrance into Kokiri Forest), and a Cutscene Entrance Offset of FFF1 (cutscene 1) into the proper temporary values, causing the entrance record at index 00EE + 4 + 1 = 00F3 to be read, which is still Kokiri Forest. Since the Cutscene Entrance Offset isn't 0000, and the Kokiri Forest properly defines cutscene 1, when Kokiri Forest loads it will play the cutscene.
When you perform a perfect Ganondoor, you overwrite the 00EE set by the blue warp with the Base Entrance Index for the door outside Gohma's Room (0252), but still have a Cutscene Entrance Offset of FFF1. 0252 + 4 + 1 = 257 which ends up being an entrance into the inside of Ganon's Tower Collapse, rather than the Deku Tree.
There is still another element to this though.
Within the main header of a scene file (scene is a common romhacking term for the file which makes up a large area like Kokiri Forest or Link's House), there can exist a command (known as the 0x18 command) which defines a table for alternate versions of a scene. These are often known as alternate scene setups (scene setups for short), or alternate headers.
It works like this... Some areas in the game (like Kakariko Village, Lots of Pots, Kokiri Forest) can change depending on your age, the time of day, a combination of both, or by a game event. Rather than hard coding this into an actor, a different scene setup is used instead.
After the playable scene setups. there may also be setups for cutscenes, setups which the Cutscene Entrance Offset is designed to load. Within the headers for these cutscene setups is yet another command, the 0x17 command, which serves to set the cutscene pointer to point at the proper cutscene.
Because of the 0x18 command, there are three possible scenarios that can occur when wrong warping.
Let's go back to the normal Blue Warp. With 00EE as a base entrance index and FFF1 for a cutscene, the game will find entrance 00F3 for Kokiri Forest. Inside the main header for Kokiri Forest is the 0x18 command that defines the table of alternate scene setups. Cutscene 1 is defined, so the scene setup for Cutscene 1 is loaded and the cutscene plays.
Now a new area, Zora's Fountain. With 010E as a base entrance index and FFF3 for a cutscene, the game will find entrance 0115, which is still Zoras Fountain. However, the alternate scene setups table does not define a setup for cutscene 3 (and actually it will read past the table), so the game will crash.
And back to Ganondoor. With 0252 as a base entrance index, and FFF1 for a cutscene, the game will find entrance 0257 for Inside Ganon's Tower Collapse. However, the 0x18 command is
not defined, so the game doesn't attempt to load an alternate scene setup, and doesn't crash because of it. Since the main header is still used, the cutscene pointer isn't updated.
HOWEVER, because the Cutscene Entrance Offset is set, the game
still attempts to play a cutscene. Since Ganondoor doesn't update the cutscene pointer, and because the cutscene pointer isn't properly nulled, it ends up attempting to play what's left of the last cutscene.
This is why your last cutscene is so important. If your last cutscene is the Deku Tree Intro, the entire cutscene will be overwritten by the file for Inside Ganon's Tower, causing garbage data to be read, resulting in no cutscene. If your last cutscene is the Title Screen cutscene (which is stored in Hyrule Field), the size of the Hyrule Field file will be so great that the cutscene won't be overwritten by Inside Ganon's Tower Collapse, and you'll end up softlocking because the title screen cutscene will place you well out of bounds.
Last edited 03 Jul 2013, 02:44 by mzxrules.