Dodongo's Cavern blue warp crash fix (#622)

* Doodong's Cavern blue warp crash fix

* >= not >

* Don't waste a line of space
This commit is contained in:
Sirius902 2022-07-10 06:30:19 -07:00 committed by GitHub
parent d1a2f98524
commit 89e07f8dbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -89,6 +89,7 @@ typedef struct {
/* 0x20 */ CamData* cameraDataList; /* 0x20 */ CamData* cameraDataList;
/* 0x24 */ u16 numWaterBoxes; /* 0x24 */ u16 numWaterBoxes;
/* 0x28 */ WaterBox* waterBoxes; /* 0x28 */ WaterBox* waterBoxes;
size_t cameraDataListLen; // OTRTODO: Added to allow for bounds checking the cameraDataList.
} CollisionHeader; // original name: BGDataInfo } CollisionHeader; // original name: BGDataInfo
typedef struct { typedef struct {

View File

@ -158,6 +158,7 @@ bool func_80098674(GlobalContext* globalCtx, Ship::SceneCommand* cmd)
} }
colHeader->cameraDataList = (CamData*)malloc(sizeof(CamData) * colRes->camData->entries.size()); colHeader->cameraDataList = (CamData*)malloc(sizeof(CamData) * colRes->camData->entries.size());
colHeader->cameraDataListLen = colRes->camData->entries.size();
for (int i = 0; i < colRes->camData->entries.size(); i++) for (int i = 0; i < colRes->camData->entries.size(); i++)
{ {

View File

@ -383,6 +383,19 @@ void Gameplay_Init(GameState* thisx) {
Camera_InitPlayerSettings(&globalCtx->mainCamera, player); Camera_InitPlayerSettings(&globalCtx->mainCamera, player);
Camera_ChangeMode(&globalCtx->mainCamera, CAM_MODE_NORMAL); Camera_ChangeMode(&globalCtx->mainCamera, CAM_MODE_NORMAL);
// OTRTODO: Bounds check cameraDataList to guard against scenes spawning the player with
// an out of bounds background camera index. This requires adding an extra field to the
// CollisionHeader struct to save the length of cameraDataList.
// Fixes Dodongo's Cavern blue warp crash.
{
CollisionHeader* colHeader = BgCheck_GetCollisionHeader(&globalCtx->colCtx, BGCHECK_SCENE);
// If the player's start cam is out of bounds, set it to 0xFF so it isn't used.
if (colHeader != NULL && ((player->actor.params & 0xFF) >= colHeader->cameraDataListLen)) {
player->actor.params |= 0xFF;
}
}
playerStartCamId = player->actor.params & 0xFF; playerStartCamId = player->actor.params & 0xFF;
if (playerStartCamId != 0xFF) { if (playerStartCamId != 0xFF) {
osSyncPrintf("player has start camera ID (" VT_FGCOL(BLUE) "%d" VT_RST ")\n", playerStartCamId); osSyncPrintf("player has start camera ID (" VT_FGCOL(BLUE) "%d" VT_RST ")\n", playerStartCamId);