I was going through my notes the other day when something caught my attention that I'd meant to expand on a little more. It's not really anything useable at the moment, but hey, I figure someone should be able to get something out of it.
First off, some class declarations
You may have seen these classes before if you've ever taken the time to look inside any stage module. For the sake of the analysis, I used the Wifi Waiting Room stage(
st_otrain.rel) - I will refer to it whenever necessary.
For now we'll look at stClassInfoImpl<55, stOnlineTrainning>, a derived class of the stClassInfo class. (
you could argue that it's actually an implementation of the abstract interface stClassInfo, but let's not complicate the terminology) This is a lightweight class that Brawl uses whenever it needs to generate the Wifi Waiting Room stage for you to fight on. (
Incidentally, the Results Screen stage's stClassInfo is always loaded into memory, so it can be loaded at any time)
The method in question that loads the stage is stClassInfoImpl<55, stOnlinetrainning>.Method[1]. I won't go into details, but it does 3 main things:
1. Allocate a block of memory on the StageInstance heap the size of the stOnlineTrainning class.
2. Call the stMelee constructor. (
the base class of the stOnlineTrainning class)
3. Construct the remaining parts unique to the stOnlineTrainning class.
After the constructor returns, the address of the stOnlineTrainning class gets stored at 80B8A428. (
Somewhere inside module 1B) When the match actually starts, stOnlineTrainning gets accessed from 80B8A428 and it's initializer gets called.
For all instances of the Stage class, method[23] is the initalizer. This is the function that is responsible for loading up all the assets from STGONLINETRAINING.pac. It is also responsible for creating any other instances that exist on the stage as separate objects. (
The blocks from Mushroomy Kingdom, say)
And unfortunately, that's really as far as I got with this. I might venture a guess as to say that the method at 80015DDC is responsible for loading specific archives out of the .pac with r4 being the type and r5 being the FileIndex, but the rest of it is uncharted territory.
In case that all went by a little bit too fast for you, I whipped up a quick diagram for you to reference at your leisure.
(
The diagram says that Method[22] is the Stage initializer - ignore that, it's really Method[23])
Just a few more miscellaneous notes:
As mentioned above, the current existing stage instance can be accessed at any time from the pointer at 80B8A428.
All methods in a class that don't reference assembly inside it's own module are methods that have not been overridden from it's base class.
Method[127] is the main loop of the stage. It is constantly called and is used for things like the Sandbag in WWR or rebuilding the mansion in Luigi's Mansion.
Just as there are constructors and initializers, there are also destructors and finalizers. stClassInfo.Method[0] is used for removing the stClassInfo from memory and Stage.Method[22] is the destructor for the actual stage
The memory allocation function can be found at 8000C8B8, it may be a good idea to see what else calls it if you wish to find out where other classes get constructed. (
8000C8C8 is the memory free function if anyone was wondering) Also, here's a list of the types of memory heaps.
That's all for now folks. I'll hang around for a little while to see if this can be taken anywhere, but I'll be riding backseat for the most part.