Fire Boomerang Super Jump
In SOTN, almost everything you see onscreen is an Entity. Every enemy is an Entity. Every projectile is an Entity. Every elevator is an Entity, and even some backgrounds are Entities (for example, any background with parallax). Alucard is also an Entity. The game contains 256 "slots" for entities, numbered 0 to 255. Alucard is always in slot 0. Generally (but not always), different ranges of Entities are reserved for different things. Entities 224 through 255 are often graphical decoration entities (like puffs of smoke) rather than things like projectiles.
Every frame of the game, there is a loop that runs. It goes through every entity, and runs an "Updater Function" on the entity. For enemies, this might decide whether they attack. For projectiles, it will run physics to continue their velocity in the direction of travel. The pushable box in Alchemy Lab has logic in its Updater Function that says "If the player is touching my left side, move me to the right".
Alucard is one of the most complex Entities in the game. Alucard can be in many "modes". These include, but are not limited to:
- Standing
- Walking
- Crouching
- Falling
- Jumping
- In bat form
- Untransforming from bat
- In wolf form
- High-Jumping
- Grabbed by boss (Akmodan, Darkwing bat)
- Teleporting during Hellfire
- And many more
Depending on which of these "modes" Alucard is in, he will use different Updater Functions. When you transform into Wolf, he starts running a function we call "PlayerStepMorphWolf". A quick reminder: 99% of the function names that we use are created by the people making the decomp. We study what the code does, and based on that information, we give the functions a name. Konami has different names for these functions, but the process of compiling the game removes the names. So we have to come up with our own names that try to be descriptive.
The wolf form is itself quite complex. When Alucard is in the Wolf form, a few things happen: 1. Set the player's palette to the Wolf palette. 2. Check if the player is untransforming from Wolf. If so, cancel everything else in this sequence! 3. Check what "sub-mode" Alucard is in. For the Wolf mode, we have not fully documented these yet, but you can imagine they are similar to Alucard's modes - jumping, swimming, wolf-charge, whatever. Based on the sub-mode, we run yet another Updater.
When you first go into wolf-mode, your sub-mode is set to 0. We call a function called "WolfStepS_0".
WolfStepS_0 initializes wolf mode. The first thing it does is check if you are transitioning from Mist mode. If you are not, then the game turns Alucard a brighter, less saturated color, prior to the wavy transformation animation. If you look closely you can see this as a white flash over Alucard. After that, the game swaps out Alucard's graphics for the wolf sprite, sets velocity to zero, and sets the sub-mode to #8. This represents the wolf being idle.
(by the way: The thing I'm calling 'mode' here is called 'step' in the code, and 'sub-mode' is called 'step_s', but those are a misnomer - 'step' makes it sound like step 4 comes before step 5, but that's not how it works. Step values jump around arbitrarily, so I find "mode" more descriptive).
Remember, the Entity Updater functions run every single frame. So when we transition into Wolf mode, we will have Alucard Mode = Wolf, and Sub-Mode = 0. We'll run that initialization routine, and then set the Sub-Mode to 8. On the next frame, the routine for Sub-Mode 8 will run. So Alucard only spends a single frame in Sub-Mode 0 before it gets updated to Sub-Mode 8.
You will recall that the first thing that happens in Sub-Mode 0 is that we check if you were Mist, and if not, apply a white flash-over effect. That effect is key here. And to understand its importance, we have to understand Entity Factories. Now we're really getting into the weeds of SOTN internals.
There are many situations where an entity will spawn other entities. For example, think of the basic Skeleton enemy, who chucks bones at you. When he decides to chuck a bone, the Skeleton entity needs to create a "Thrown Bone" entity, at the location of his hand, and then set that bone to have some initial velocity. Or, think of any time you kill an enemy and little spots of fire come from him. Each of those little fires is a new entity, spawned at the location of the "Parent" entity.
When it is necessary to create new entities, one of the ways this is done is through the use of Entity Factories. An Entity Factory is a special type of invisible entity which has the sole purpose of creating other entities. Entity Factories are complex and have a lot of different ways they can be controlled. An entity factory can be configured to produce an arbitrary number of "child" entities, with a configurable number of frames of delay to each next one, and more. The entity factory system itself is pretty complicated and is not fully understood yet. An Entity Factory uses a "Blueprint" to tell it what to create. A blueprint might say "Spawn 5 flames, each of them 4 frames after each other, at the location of the player".
When an entity wants to create an Entity Factory, it calls a function called "CreateEntFactoryFromEntity". That says "Create an entity factory, at my location. It should use blueprint #17". This creates the factory, which reads the blueprint, and then creates those entities.
When you call CreateEntFactoryFromEntity, it needs to create that entity factory. To do that, it needs a vacant slot. Recall that the slots are numbered 0 to 255. The game has it hard-coded that CreateEntFactoryFromEntity will search for an available slot from slots 8 to 15 (inclusive). This means there are 8 slots available for whatever factories might need to appear on screen. So it says "Is slot 8 vacant? If so, place our new factory into slot 8. Otherwise, try slot 9." and so on, up to 15. If it tries slot 15, and there is STILL no slot available, then it will say "Darn, no slots available. Can not create factory. Sorry". The factory will not be created, and whoever asked for the factory will have to live with that. Often, when a requested factory can not be created, the game just ignores it.
Return again to that wolf initializer function, which causes the shimmering transformation effect (if Alucard is not in mist form). The way this works is through a call to CreateEntFactoryFromEntity. But crucially, this is set up so that it says "Create the factory. If unable, then we're going to abort this Alucard updating cycle".
It turns out that the Fire Boomerang creates an unusually high number of factories. Watch it as it flies - it creates "shadow trails" of itself behind it, as well as spawning little flames in the air behind it. Throwing a single fire boomerang creates dozens of factories which are created, do their thing, and are destroyed, in the time it takes the Fire Boomerang to travel.
If enough Fire Boomerangs are flying at the same time, it is possible for all 8 Factory slots (from 8 to 15) to be filled with active Factories which are spawning those graphical elements. If you then transition into Wolf, there will be no factory available to create the transformation effect. The Wolf Form's logic says if that factory can not be created, we abort updating. Recall that Sub-Mode 0 is only supposed to last for a single frame before transitioning into Sub-Mode 8. But if we abort the update process, then we do not do the rest of the logic. We do not transition to Sub-Mode 8, and we do not swap out Alucard's graphics for the Wolf graphics. We also do not update physics, so Alucard continues with whatever velocity he has. Every frame, he keeps running Wolf Sub-Mode 0, and every frame, it fails to create a factory because no slots are available. Once a Fire Boomerang goes off-screen, the factory spamming calms down, and a slot becomes available again for the transformation effect's factory. Then the factory is created, Alucard switches into Sub-Mode 8, and everything proceeds as usual.
The following Lua script works in PCSX-Redux to show you the status of Entity slots 8-15 so you can see how they fill up while the fire boomerangs are on screen.
local ffi = require("ffi")
local g_Entities = 0x800733D8;
local entLen = 0xBC
function DrawImguiFrame()
if imgui.safe and imgui.safe.Begin then
imgui.safe.Begin("Memory Monitor", true, function()
local memPtr = PCSX.getMemPtr()
if memPtr ~= nil then
local mem8 = ffi.cast("uint8_t*", memPtr)
imgui.TextUnformatted("Entity Monitor (Indices 8 to 15)")
imgui.TextUnformatted("----------------------------------------")
imgui.TextUnformatted(string.format("%-7s | %-10s | %-5s", "Slot", "Address", "Val"))
imgui.TextUnformatted("----------------------------------------")
for i = 8, 15 do
local address = g_Entities + (i * entLen) + 0x26 -- offset 0x26 is entity ID --
local offset = bit.band(address, 0x1FFFFF)
local entId = mem8[offset]
imgui.TextUnformatted(string.format("[%2d] | 0x%08X | 0x%02X", i, address, entId))
end
else
imgui.TextUnformatted("Error: Memory pointer is nil.")
end
end)
end
end
Additionally, I ran a script to track the flight of a Fire Boomerang on-screen. It prints out which entity requested a factory, which blueprint it wanted to use, a parameter that tells if it's an "original" entity, and the time offset since it was thrown. I got the following results from one particular throw:
Creating factory:0,1103E,86,0 Creating factory:17,103A,00,1 Creating factory:17,106E,00,1 Creating factory:17,106E,00,2 Creating factory:17,103A,00,3 Creating factory:17,106E,00,3 Creating factory:26,B0004,00,3 Creating factory:17,106E,00,4 Creating factory:17,103A,00,5 Creating factory:17,106E,00,5 Creating factory:28,B0004,00,5 Creating factory:17,106E,00,6 Creating factory:17,103A,00,7 Creating factory:17,106E,00,7 Creating factory:30,B0004,00,7 Creating factory:17,106E,00,8 Creating factory:17,103A,00,9 Creating factory:17,106E,00,9 Creating factory:17,106E,00,10 Creating factory:17,103A,00,11 Creating factory:17,106E,00,11 Creating factory:17,106E,00,12 Creating factory:17,103A,00,13 Creating factory:17,106E,00,13 Creating factory:17,106E,00,14 Creating factory:17,103A,00,15 Creating factory:17,106E,00,15 Creating factory:17,106E,00,16 Creating factory:17,103A,00,17 Creating factory:17,106E,00,17 Creating factory:17,106E,00,18 Creating factory:25,B0004,00,18 Creating factory:17,103A,00,19 Creating factory:17,106E,00,19 Creating factory:17,106E,00,20 Creating factory:27,B0004,00,20 Creating factory:17,103A,00,21 Creating factory:17,106E,00,21 Creating factory:17,106E,00,22 Creating factory:29,B0004,00,22 Creating factory:17,103A,00,23 Creating factory:17,106E,00,23 Creating factory:17,106E,00,24 Creating factory:31,B0004,00,24 Creating factory:17,103A,00,25 Creating factory:17,106E,00,25 Creating factory:17,106E,00,26 Creating factory:17,103A,00,27 Creating factory:17,106E,00,27 Creating factory:17,106E,00,28 Creating factory:17,103A,00,29 Creating factory:17,106E,00,29 Creating factory:17,106E,00,30 Creating factory:17,103A,00,31 Creating factory:17,106E,00,31 Creating factory:17,106E,00,32 Creating factory:17,103A,00,33 Creating factory:17,106E,00,33 Creating factory:17,106E,00,34 Creating factory:17,103A,00,35 Creating factory:17,106E,00,35 Creating factory:26,B0004,00,35 Creating factory:17,106E,00,36 Creating factory:17,103A,00,37 Creating factory:17,106E,00,37 Creating factory:28,B0004,00,37 Creating factory:17,106E,00,38 Creating factory:17,103A,00,39 Creating factory:17,106E,00,39 Creating factory:30,B0004,00,39 Creating factory:17,106E,00,40 Creating factory:17,103A,00,41 Creating factory:17,106E,00,41 Creating factory:17,106E,00,42 Creating factory:17,103A,00,43 Creating factory:17,106E,00,43 Creating factory:17,106E,00,44 Creating factory:17,103A,00,45 Creating factory:17,106E,00,45 Creating factory:17,106E,00,46 Creating factory:17,103A,00,47 Creating factory:17,106E,00,47 Creating factory:17,106E,00,48 Creating factory:17,103A,00,49 Creating factory:17,106E,00,49 Creating factory:17,106E,00,50 Creating factory:25,B0004,00,50 Creating factory:17,103A,00,51 Creating factory:17,106E,00,51 Creating factory:17,106E,00,52 Creating factory:27,B0004,00,52 Creating factory:17,103A,00,53 Creating factory:17,106E,00,53 Creating factory:17,106E,00,54 Creating factory:29,B0004,00,54 Creating factory:17,103A,00,55 Creating factory:17,106E,00,55 Creating factory:17,106E,00,56 Creating factory:31,B0004,00,56 Creating factory:17,103A,00,57 Creating factory:17,106E,00,57 Creating factory:17,106E,00,58 Creating factory:17,103A,00,59 Creating factory:17,106E,00,59 Creating factory:17,106E,00,60 Creating factory:17,103A,00,61 Creating factory:17,106E,00,61 Creating factory:17,106E,00,62 Creating factory:17,103A,00,63 Creating factory:17,106E,00,63 Creating factory:17,106E,00,64 Creating factory:17,103A,00,65 Creating factory:17,106E,00,65 Creating factory:17,106E,00,66 Creating factory:17,103A,00,67 Creating factory:17,106E,00,67 Creating factory:26,B0004,00,67 Creating factory:17,106E,00,68 Creating factory:17,103A,00,69 Creating factory:17,106E,00,69 Creating factory:28,B0004,00,69 Creating factory:17,106E,00,70 Creating factory:17,103A,00,71 Creating factory:17,106E,00,71 Creating factory:30,B0004,00,71
Now we can study this a bit. The first call is originating from entity 0, the factory blueprint is 1103E, and the last parameter is 86. 86 is the weapon ID for the fire boomerang. All other calls will have a 0 in that slot. And because this is the start of the process, the time elapsed is 0 frames. On the next frame, frame 1, the fire boomerang (which has been placed in slot 17) creates factories with blueprints 103A and 106E. 103A creates the trailing boomerang which fades over time. 106E creates a fire which fades out over 8 frames. But that fire itself then creates blueprint B0004, which I believe tells the factory to create the single red flame pixels we see around the fire boomerang. We see that on every single frame, the fire boomerang creates at least 2 factories, and sometimes (indirectly) a third. Once factories have run their course, they are cleaned up, so these usually do not occupy too many slots. But if you have 6 on screen, that's going to occupy all the slots as they try to create all their entities. The factory slots fill up and there is no room for another factory for the Wolf transformation to use.
There is a distinct possibility that there are other ways to fill up the set of factories. Other weapons, or using spells, who knows. Ultimately, all that matters for the Wolf super jump is that all of those factory slots are occupied which prevents the transformation effect from happening. There is nothing particularly special about the Fire Boomerangs, except that they are obnoxious with creating tons of factories for their graphics and that makes it easy to fill up all 8 slots.
One final note: The PSP appears to lack the line that says "If factory creation fails, abort wolf sub-mode 0". Therefore PSP will always run through 0 to completion, and will always transition to 8 within a single frame, making it not susceptible to the glitch.
As with anything, more study of this is merited. But this begins to explain the cause of the glitch, and opens doors to potentially being able to use it in other situations, perhaps without the Fire Boomerang. Having the Lua readout available should make it easier to glitch-hunt for other places this may happen.
Please reach out to Bismurphy for any questions or other ideas related to this writeup.
None of this would be possible without the massive efforts by all the folks who have contributed to sotn-decomp. The code would not have been possible to study in this depth without the understanding we have gained. As I mentioned above, all the function names are created by us based on studying the code. There are still many, many functions that have not properly been studied, so if you are interested in helping to make more study like this possible, consider joining the project and contributing useful names for things. Even if you don't know assembly, just being able to trace code and figure out what its purpose was can be a big help.