PluMGMK wrote: Wed Aug 16, 2017 8:02 pm
I posted a video in another topic yesterday about a glitch I discovered many years ago in Rayman 2. Probably best to leave it here too for posterity!
https://youtu.be/6PuSjy66sno
So, in Menhir Hills part 2, it's possible to turn the shell around, but doing so apparently earns you a punishment worse than a Try Again: Rayman disappears and his health starts draining, and doesn't seem to stop at zero!
I think I saw another video fairly recently about how a new Rayman+shell entity is created at the entrance of each room on that ride, and the old one is deleted. So I guess what happened here is that I activated the "delete" trigger again, but not the corresponding "create" one. The game was left with no player entity and didn't know what to do. I think something similar, but weirder, happens after 10:30 in
this video of Carrot's.
So, five years later, I decided to look into this a bit more, and it seems I was pretty wide of the mark!

The real reason involves the way the engine organizes level geometry, and how the Walking Shell handles being the Main Actor while Rayman is riding it.
First, the bit about level geometry: as you may or may not know, maps in Rayman 2 (and all OpenSpace games) are organized into Sectors. When you're in a particular Sector, then all entities ("Persos") in that Sector are active, and all geometry in it can be drawn if it's in the camera's field of view. But of course, that's not enough. What about when you can see into the next Sector? You need to be able to see the geometry and Persos in there too!
So, each Sector has two lists of other Sectors, which are called the Activity and Graphic Sector lists. So let's say we have three Sectors: A, B and C. Then Sector B has A and C as Graphic Sectors, and just C as an Activity Sectors. Then when you're in Sector B: All geometry in any of the three Sectors can be drawn, but only Persos in Sectors B and C will be active, so the ones in A will be deactivated (so the game doesn't need to spend computing resources running their code).
It turns out that this is exactly the situation on the path that Rayman rides the shell along. Each sector has both the previous and next ones as Graphic Sectors, but only the next one as an Activity Sector. You can see this in
Raymap (at least the full version in Unity, not sure about the online version…) – more technically, Sector A = "Sector @ Rodeo_40|0x00052B10", Sector B = "Sector @ Rodeo_40|0x00055908", Sector C = "Sector @ Rodeo_40|0x0005EBA8". The devs did this optimization because they assumed it was impossible for Rayman to turn around and go back to the previous Sector.
Then there's the matter of the Walking Shell itself. Its initial state is as an enemy, standing still and waiting for Rayman to come near so it can start chasing him. It doesn't have any hitpoints in this state (since it doesn't have a lifebar) and, of course, does not respond to player input or anything like that. When Rayman starts riding it though, it becomes the Main Actor, assumes his hitpoints, and starts responding to player input. (It also deactivates the Perso that normally represents Rayman himself, but carries it around with it to make sure that he dismounts in the right place when the time comes.) However, there are a few flags that are normally set on Rayman's object, which do not get set on the Shell object, even when it is the Main Actor.
So, putting all this together, what happens when the Shell (with Rayman on it) moves from Sector B
back to Sector A? Well, since Sector A wasn't an Activity Sector, all the Persos in it need to be reactivated. The engine iterates over all the Persos that it finds in Sector A, and runs some code to activate them and reset them to their initial state. The problem is that the Shell
just moved into Sector A – so it is one of those Persos that gets reset! Because it doesn't have certain flags set (I'm not sure which ones exactly

), the engine doesn't care that it's the Main Actor and proceeds to reinitialize the Shell, with the following consequences:

It gets teleported back to its initial position at the start of the map!

Because it's in its initial state (waiting to chase Rayman) it is no longer aware that it is supposed to be carrying the deactivated Rayman Perso, so it stays down at the end of the corridor – I
think that's why the camera doesn't follow the Shell back to the beginning of the map…

Seemingly on N64 (according to what R4Y_ANC3L said five years ago), this deactivated Perso is then allowed to use Look Mode, and doing so resets Rayman's shadow to being active. But on PC, this doesn't happen – attempting to use Look Mode just causes the "camera operation not allowed" icon to flash on the screen…

The Shell's hitpoints are restored to their initial value of zero – since it is still technically the Main Actor, this is why the lifebar drains to zero (despite my sensationalized video title, it doesn't actually go negative!).
Using
GDB, I was able to set some breakpoints and jump over the "reactivation" function for the Shell itself, thus allowing me to ride the Shell back up the corridor to the beginning of the map. There are probably some hex edits that could be done to make that happen every time instead of needing to attach a debugger…
Anyway, I'm really glad to have finally solved that mystery! I hope you found it interesting!
