diff options
-rw-r--r-- | berry_fix/payload/include/global.fieldmap.h | 17 | ||||
-rw-r--r-- | src/event_object_movement.c | 11 | ||||
-rw-r--r-- | src/fieldmap.c | 24 | ||||
-rw-r--r-- | src/pokeball.c | 5 | ||||
-rw-r--r-- | src/pokedex.c | 8 | ||||
-rw-r--r-- | src/pokemon_animation.c | 1 | ||||
-rw-r--r-- | src/pokemon_storage_system.c | 7 | ||||
-rw-r--r-- | tools/gbafix/gbafix.c | 8 |
8 files changed, 60 insertions, 21 deletions
diff --git a/berry_fix/payload/include/global.fieldmap.h b/berry_fix/payload/include/global.fieldmap.h index f876e5a56..d5ab0812e 100644 --- a/berry_fix/payload/include/global.fieldmap.h +++ b/berry_fix/payload/include/global.fieldmap.h @@ -79,23 +79,16 @@ struct CoordEvent struct BgEvent { - /*0x00*/u16 x; - /*0x02*/u16 y; - /*0x04*/u8 elevation; - /*0x05*/u8 kind; - /*0x08*/union { // carried over from diego's FR/LG work, seems to be the same struct - // in gen 3, "kind" (0x3 in BgEvent struct) determines the method to read the union. + u16 x, y; + u8 elevation; + u8 kind; // The "kind" field determines how to access bgUnion union below. + union { u8 *script; - - // hidden item type struct { u16 item; - u16 hiddenItemId; // flag offset to determine flag lookup + u16 hiddenItemId; } hiddenItem; - - // secret base type u32 secretBaseId; - } bgUnion; }; diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 1d06ddc84..12ef4acdc 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -2275,7 +2275,18 @@ u8 CameraObjectGetFollowedObjectId(void) void CameraObjectReset2(void) { + // UB: Possible null dereference +#ifdef UBFIX + struct Sprite *cameraObject; + + cameraObject = FindCameraObject(); + if (cameraObject != NULL) + { + cameraObject->data[1] = 2; + } +#else FindCameraObject()->data[1] = 2; +#endif // UBFIX } u8 CopySprite(struct Sprite *sprite, s16 x, s16 y, u8 subpriority) diff --git a/src/fieldmap.c b/src/fieldmap.c index 49337ebbe..296c4edf2 100644 --- a/src/fieldmap.c +++ b/src/fieldmap.c @@ -797,15 +797,33 @@ bool8 CameraMove(int x, int y) struct MapConnection *sub_8088950(u8 direction, int x, int y) { int count; - struct MapConnection *connection; int i; - count = gMapHeader.connections->count; - connection = gMapHeader.connections->connections; + struct MapConnection *connection; + const struct MapConnections *connections = gMapHeader.connections; + // UB: Multiple possible null dereferences +#ifdef UBFIX + if (connections != NULL) + { + count = connections->count; + connection = connections->connections; + if (connection != NULL) + { + for (i = 0; i < count; i++, connection++) + { + if (connection->direction == direction && sub_80889A8(direction, x, y, connection) == TRUE) + return connection; + } + } + } +#else + count = connections->count; + connection = connections->connections; for (i = 0; i < count; i++, connection++) { if (connection->direction == direction && sub_80889A8(direction, x, y, connection) == TRUE) return connection; } +#endif return NULL; } diff --git a/src/pokeball.c b/src/pokeball.c index 92081a296..916c86287 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -1133,6 +1133,11 @@ static void sub_80767D4(struct Sprite *sprite) AnimateBallOpenParticlesForPokeball(sprite->pos1.x, sprite->pos1.y - 5, sprite->oam.priority, r6); sprite->data[1] = LaunchBallFadeMonTaskForPokeball(1, r8, r5); sprite->callback = sub_807687C; +#ifdef BUGFIX + // FIX: If this is used on a sprite that has previously had an affine animation, it will not + // play the shrink anim properly due to being paused. Works together with the fix to `sub_817F77C`. + gSprites[r7].affineAnimPaused = FALSE; +#endif // BUGFIX StartSpriteAffineAnim(&gSprites[r7], 2); AnimateSprite(&gSprites[r7]); gSprites[r7].data[1] = 0; diff --git a/src/pokedex.c b/src/pokedex.c index 516cef6a7..691abd649 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -3037,7 +3037,15 @@ static void SpriteCB_PokedexListMonSprite(struct Sprite *sprite) u32 var; sprite->pos2.y = gSineTable[(u8)sprite->data[5]] * 76 / 256; + // UB: possible division by zero +#ifdef UBFIX + if (gSineTable[sprite->data[5] + 64] != 0) + var = 0x10000 / gSineTable[sprite->data[5] + 64]; + else + var = 0xFFFF; +#else var = 0x10000 / gSineTable[sprite->data[5] + 64]; +#endif //UBFIX if (var > 0xFFFF) var = 0xFFFF; SetOamMatrix(sprite->data[1] + 1, 0x100, 0, 0, var); diff --git a/src/pokemon_animation.c b/src/pokemon_animation.c index 58c174263..c4077aff4 100644 --- a/src/pokemon_animation.c +++ b/src/pokemon_animation.c @@ -1046,7 +1046,6 @@ static void sub_817F77C(struct Sprite *sprite) { // FIX: Reset these back to normal after they were changed so Poké Ball catch/release // animations without a screen transition in between don't break - sprite->affineAnimPaused = FALSE; sprite->affineAnims = gUnknown_082FF694; } #endif // BUGFIX diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index db8f3d2bb..4be1cf729 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -8408,8 +8408,13 @@ static void sub_80D08CC(void) for (j = sMoveMonsPtr->minRow; j < rowCount; j++) { struct BoxPokemon *boxMon = GetBoxedMonPtr(boxId, boxPosition); - + // UB: possible null dereference +#ifdef UBFIX + if (boxMon != NULL) + sMoveMonsPtr->boxMons[monArrayId] = *boxMon; +#else sMoveMonsPtr->boxMons[monArrayId] = *boxMon; +#endif monArrayId++; boxPosition++; } diff --git a/tools/gbafix/gbafix.c b/tools/gbafix/gbafix.c index 598e43aa0..d62a9c661 100644 --- a/tools/gbafix/gbafix.c +++ b/tools/gbafix/gbafix.c @@ -28,14 +28,14 @@ // gbafix.c //--------------------------------------------------------------------------------- /* - Gameboy Advance ROM fixer (by Dark Fader / BlackThunder / WinterMute / Diegoisawesome) + Gameboy Advance ROM fixer (by Dark Fader / BlackThunder / WinterMute / Sierraffinity) Validates header of GBA roms. History ------- v1.07 - added support for ELF input, (PikalaxALT) - v1.06 - added output silencing, (Diegoisawesome) - v1.05 - added debug offset argument, (Diegoisawesome) + v1.06 - added output silencing, (Sierraffinity) + v1.05 - added debug offset argument, (Sierraffinity) v1.04 - converted to plain C, (WinterMute) v1.03 - header.fixed, header.device_type v1.02 - redefined the options (rgbfix style), checksum=0 @@ -146,7 +146,7 @@ int main(int argc, char *argv[]) // show syntax if (argc <= 1) { - printf("GBA ROM fixer v"VER" by Dark Fader / BlackThunder / WinterMute / Diegoisawesome \n"); + printf("GBA ROM fixer v"VER" by Dark Fader / BlackThunder / WinterMute / Sierraffinity \n"); printf("Syntax: gbafix <rom.gba> [-p] [-t[title]] [-c<game_code>] [-m<maker_code>] [-r<version>] [-d<debug>] [--silent]\n"); printf("\n"); printf("parameters:\n"); |