Structures
Aside from few highly optimized paired-single algorithms, Mario Kart Wii and the first-party Wii EAD libraries were written in C and C++ and compiled to PowerPC Assembly. This article presents several highly-used structures and classes reconstructed to C and C++ structures.
Primitive Sizes
The following table presents the size of primitive elements as they are in Mario Kart Wii. This is the equivalent of sizeof(...).
Shorthand | Type | Size in bytes. |
---|---|---|
s32, u32 | (unsigned) int, long int | 4 |
s16, u16 | (unsigned) short int | 2 |
u8, s8 | (unsigned) char | 1 |
- | bool | 1 |
- | enum | 4 |
u64, s64 | (unsigned) long long int | 8 |
f32 | float | 4 |
f64 | double | 8 |
Alignment
All members are aligned to multiples of their size. For example, an int is four bytes and therefore must be aligned to a multiple of four bytes. Consider the following:
struct Example { short FieldA; int FieldB; };
FieldA will be placed at +00 and end at +02. However, FieldB will not end at +02 as it is not a multiple of four. The compiler will instead place two bytes of implicit padding between FieldA and FieldB. Structures presented in this article will omit implicit padding.
Structures
Multithreading
Thread
The Thread class defines an implementation of a thread that game threads must inherit. Wrapping an OSThread, Thread is the successor to JSYSTEM's JKRThread.
Offset | Return Type | Description |
---|---|---|
0x08 | - | Virtual destructor. |
0x0C | int | Function to run the thread. |
0x10 | void | Called on entering the thread. |
0x14 | void | Called on exiting the thread. |
0x3C | End of this structure |
Offset | Type | Description |
---|---|---|
0x00 | - | Virtual Table |
0x04 | Heap* | Heap to use for thread-specific allocations. It's used immediately in the constructor to allocate the stack and optionally OSThread on heap. |
0x08 | OSThread* | The OS thread this object wraps. |
0x0C | OSMessageQueue | The message queue of this thread. |
0x2C | OSMessage* | The message buffer. |
0x30 | u32 | The number of messages in the buffer. |
0x34 | void* | The base (beginning) of the stack. |
0x38 | u32 | Size of the stack. |
0x3C | Heap* | When not NULL, it will override the heap used for allocations. (Note: Does not escape the global heap restriction if enabled.) |
0x3C | End of this structure |
System
RKSystem
The following structures describe the Mario Kart Wii specific system class. The system class in actuality has a complex class hierarchy, however for readability, has been condensed into one structure. The incredibly specific descriptions of members are based on decompilation of the game, not speculation.
The system instance is located in BSS at PAL 802A4080. Two main pointers to this class are located at PAL 80386F60 (parent main class instance pointer used only by system classes) and PAL 80385FC8 (RK SystemManager System instance pointer used by game code). The SystemManager getter for the System is at PAL 80008E84.
Offset | Return Type | Description |
---|---|---|
0x08 | Video* | Returns a pointer to the video wrapper. |
0x0C | Heap* | Returns a pointer to the system heap. |
0x10 | Display* | Returns a pointer to the display wrapper. |
0x14 | XfbManager* | Returns a pointer to the external framebuffer manager. |
0x18 | PerformanceView* | Returns a pointer to the debug bar. Mario Kart Wii's debug bar inherits Thread before PerformanceView, so sizeof(Thread) is added when returning. |
0x1C | SceneManager* | Returns a pointer to the system scene manager. |
0x20 | AudioManager* | Returns a pointer to the system audio manager. |
0x24 | void | Called before every frame. Nullsub. |
0x28 | void | Called at the end of every frame. Nullsub. |
0x2C | void | Called in initialization functions. Nullsub. |
0x30 | void | Initializes the system memory. |
0x34 | void | The main game loop! |
0x38 | void | Initializes the system. |
0x3C | End of this structure |
Offset | Type | Description |
---|---|---|
0x00 | - | Virtual Table |
0x04 | void* | Lower boundary of MEM1 arena. |
0x08 | void* | Upper boundary of MEM1 arena (start of FST). |
0x0C | void* | Lower boundary of MEM2 arena. |
0x10 | void* | Upper boundary of MEM2 arena. |
0x14 | u32 | Memory size, as set in the boot info. |
0x18 | Heap* | Pointer to the MEM1 root expanded heap. Encompasses all of the MEM1 arena. Name pointer set to "EGGRootMEM1". |
0x1C | Heap* | Pointer to the MEM2 root expanded heap. Encompasses all of the MEM2 arena. Name pointer set to "EGGRootMEM2". |
0x20 | Heap* | Pointer to the Debug root expanded heap. Size is either 0x3B50000 when enabled or 0 when empty. Only created if Mem2ArenaSize >= 0x4000000, as debug units have an additional 64MB of MEM2 memory (ending at 7FFFFFF; retail ends at 3FFFFFF). Several stripped debug tasks use this. Name pointer set to "EGGRootDebug". |
0x24 | Heap* | Pointer to the System expanded heap. The system heap is a child of the root MEM1 heap. Name pointer set to "EGGSystem". |
0x28 | Thread* | Pointer to the thread that initialized the system. |
0x2C | void* | Set to the cached base (0x80000000). |
0x30 | void* | Set to the MEM1 arena low. |
0x34 | u32 | Determines the size of the system heap to create. |
0x38 | u32 | Determines the GXFifo buffer size. |
0x3C | GXRenderModeObj* | Render mode used when configuring the video wrapper. |
0x40 | ExpandedAudioManager* | The system audio manager. |
0x44 | Video* | The system video wrapper. |
0x48 | XfbManager* | The system external framebuffer manager. Holds two XFBs. |
0x4C | AsyncDisplay* | The system asynchronous display wrapper. |
0x50 | ProcessMeter* | The system debug bar. |
0x54 | SceneManager* | The system scene manager. |
0x58 | void* | KPAD working memory. |
0x5C | u32 | Unknown. |
0x60 | Heap* | Heap to use when linking StaticR.rel. |
0x64 | ExpHeap* | Another system heap. Overrided system heap getter returns this heap in the RK system rather than the heap returned by the debug main class system heap getter. |
0x68 | u8[4] | Misc |
0x70 | void* | Unknown |
0x3C | End of this structure |