Skip to content

Instantly share code, notes, and snippets.

@QbeRoot
Created December 12, 2021 18:36
Show Gist options
  • Select an option

  • Save QbeRoot/5c62ac9211680cd7706e70c9189b658f to your computer and use it in GitHub Desktop.

Select an option

Save QbeRoot/5c62ac9211680cd7706e70c9189b658f to your computer and use it in GitHub Desktop.
Source code for the Super Mario Sunshine position/angle/speed display Gecko code (build with https://github.com/BitPatty/Super-Mario-Sunshine-C-Kit)
#include <stdio.h>
#include "sms.h"
static J2DTextBox tb;
static int loaded = 0;
void OnSetup(MarDirector* director) {
JUTRect r;
MarDirector_SetupObjects(director);
JUTRect_Set(&r, 10, -40, 800, 512);
// textbox creation copies the string to a newly-allocated buffer, only its length is important here
// use the format string so the code only needs a single string literal
J2DTextBox_Create(&tb, 0, &r, GameFont,
"X Pos %.0f\nY Pos %.0f\nZ Pos %.0f\nAngle %hu\nH Spd %.2f\nV Spd %.2f ", 2, 0);
loaded = 1;
}
int OnUpdate(MarDirector* director) {
int (*GameUpdate)(MarDirector* director) = GetObjectFunction(director, Director_GameUpdate);
if (loaded) {
void *mario = *gpMarioOriginal;
snprintf(J2DTextBox_GetStringPtr(&tb), 128, "X Pos %.0f\nY Pos %.0f\nZ Pos %.0f\nAngle %hu\nH Spd %.2f\nV Spd %.2f ",
*(float *) (mario + 0x10),
*(float *) (mario + 0x14),
*(float *) (mario + 0x18),
*(uint16_t *) (mario + 0x96),
*(float *) (mario + 0xB0),
*(float *) (mario + 0xA8));
}
return GameUpdate(director);
}
void OnDraw2D(J2DOrthoGraph* graphics) {
J2DGrafContext_Setup2D((J2DGrafContext*) graphics);
J2DScreen_Draw((J2DScreen*) &tb, 0, 0, (J2DGrafContext*) graphics, 0x81);
}
// requires a separate asm code to reset `loaded` between areas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment