From c5aa91741b4ba674e0eec574b33a6fb78b349b7a Mon Sep 17 00:00:00 2001 From: PokeCodec Date: Sun, 19 Jul 2020 15:57:20 -0400 Subject: [PATCH 01/17] Change signedness and add casts to avoid implicit conversion warnings --- src/agb_flash.c | 28 +++++++++++++-------------- src/battle_anim_bug.c | 38 +++++++++++++------------------------ src/battle_anim_effects_1.c | 2 +- src/berry.c | 2 +- src/berry_blender.c | 10 +++++----- src/easy_chat.c | 18 +++++++++--------- src/event_object_movement.c | 6 +++--- src/field_effect.c | 2 +- src/hall_of_fame.c | 4 ++-- src/item_use.c | 2 +- src/list_menu.c | 10 +++++----- src/mirage_tower.c | 7 +++---- src/overworld.c | 2 +- src/party_menu.c | 8 ++++---- src/player_pc.c | 14 +++++++------- src/pokedex.c | 6 +++--- src/roulette.c | 32 +++++++++++++++---------------- src/scrcmd.c | 4 ++-- src/secret_base.c | 8 ++++---- src/slot_machine.c | 2 +- src/start_menu.c | 2 +- src/trainer_see.c | 4 ++-- 22 files changed, 99 insertions(+), 112 deletions(-) diff --git a/src/agb_flash.c b/src/agb_flash.c index 1ad9e47ecb..0045219c41 100644 --- a/src/agb_flash.c +++ b/src/agb_flash.c @@ -41,7 +41,7 @@ u16 ReadFlashId(void) u8 (*readFlash1)(u8 *); SetReadFlash1(readFlash1Buffer); - readFlash1 = (u8 (*)(u8 *))((s32)readFlash1Buffer + 1); + readFlash1 = (u8 (*)(u8 *))((uintptr_t)readFlash1Buffer + 1); // Enter ID mode. FLASH_WRITE(0x5555, 0xAA); @@ -113,12 +113,12 @@ void SetReadFlash1(u16 *dest) u16 *src; u16 i; - PollFlashStatus = (u8 (*)(u8 *))((s32)dest + 1); + PollFlashStatus = (u8 (*)(u8 *))((uintptr_t)dest + 1); src = (u16 *)ReadFlash1; - src = (u16 *)((s32)src ^ 1); + src = (u16 *)((uintptr_t)src ^ 1); - i = ((s32)SetReadFlash1 - (s32)ReadFlash1) >> 1; + i = ((uintptr_t)SetReadFlash1 - (uintptr_t)ReadFlash1) >> 1; while (i != 0) { @@ -154,10 +154,10 @@ void ReadFlash(u16 sectorNum, u32 offset, u8 *dest, u32 size) } funcSrc = (u16 *)ReadFlash_Core; - funcSrc = (u16 *)((s32)funcSrc ^ 1); + funcSrc = (u16 *)((uintptr_t)funcSrc ^ 1); funcDest = readFlash_Core_Buffer; - i = ((s32)ReadFlash - (s32)ReadFlash_Core) >> 1; + i = ((uintptr_t)ReadFlash - (uintptr_t)ReadFlash_Core) >> 1; while (i != 0) { @@ -165,7 +165,7 @@ void ReadFlash(u16 sectorNum, u32 offset, u8 *dest, u32 size) i--; } - readFlash_Core = (void (*)(vu8 *, u8 *, u32))((s32)readFlash_Core_Buffer + 1); + readFlash_Core = (void (*)(vu8 *, u8 *, u32))((uintptr_t)readFlash_Core_Buffer + 1); src = FLASH_BASE + (sectorNum << gFlash->sector.shift) + offset; @@ -202,10 +202,10 @@ u32 VerifyFlashSector(u16 sectorNum, u8 *src) } funcSrc = (u16 *)VerifyFlashSector_Core; - funcSrc = (u16 *)((s32)funcSrc ^ 1); + funcSrc = (u16 *)((uintptr_t)funcSrc ^ 1); funcDest = verifyFlashSector_Core_Buffer; - i = ((s32)VerifyFlashSector - (s32)VerifyFlashSector_Core) >> 1; + i = (u16)(((uintptr_t)VerifyFlashSector - (uintptr_t)VerifyFlashSector_Core) >> 1); while (i != 0) { @@ -213,7 +213,7 @@ u32 VerifyFlashSector(u16 sectorNum, u8 *src) i--; } - verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((s32)verifyFlashSector_Core_Buffer + 1); + verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((uintptr_t)verifyFlashSector_Core_Buffer + 1); tgt = FLASH_BASE + (sectorNum << gFlash->sector.shift); size = gFlash->sector.size; @@ -239,10 +239,10 @@ u32 VerifyFlashSectorNBytes(u16 sectorNum, u8 *src, u32 n) REG_WAITCNT = (REG_WAITCNT & ~WAITCNT_SRAM_MASK) | WAITCNT_SRAM_8; funcSrc = (u16 *)VerifyFlashSector_Core; - funcSrc = (u16 *)((s32)funcSrc ^ 1); + funcSrc = (u16 *)((uintptr_t)funcSrc ^ 1); funcDest = verifyFlashSector_Core_Buffer; - i = ((s32)VerifyFlashSector - (s32)VerifyFlashSector_Core) >> 1; + i = (u16)(((uintptr_t)VerifyFlashSector - (uintptr_t)VerifyFlashSector_Core) >> 1); while (i != 0) { @@ -250,7 +250,7 @@ u32 VerifyFlashSectorNBytes(u16 sectorNum, u8 *src, u32 n) i--; } - verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((s32)verifyFlashSector_Core_Buffer + 1); + verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((uintptr_t)verifyFlashSector_Core_Buffer + 1); tgt = FLASH_BASE + (sectorNum << gFlash->sector.shift); @@ -293,4 +293,4 @@ u32 ProgramFlashSectorAndVerifyNBytes(u16 sectorNum, u8 *src, u32 n) } return result; -} +} \ No newline at end of file diff --git a/src/battle_anim_bug.c b/src/battle_anim_bug.c index ea3df80986..5e8a8b2a76 100644 --- a/src/battle_anim_bug.c +++ b/src/battle_anim_bug.c @@ -372,14 +372,11 @@ static void AnimTranslateStinger(struct Sprite *sprite) { gBattleAnimArgs[2] = -gBattleAnimArgs[2]; } - else + else if (GetBattlerSide(gBattleAnimAttacker)) { - if (GetBattlerSide(gBattleAnimAttacker)) - { - gBattleAnimArgs[2] = -gBattleAnimArgs[2]; - gBattleAnimArgs[1] = -gBattleAnimArgs[1]; - gBattleAnimArgs[3] = -gBattleAnimArgs[3]; - } + gBattleAnimArgs[2] = -gBattleAnimArgs[2]; + gBattleAnimArgs[1] = -gBattleAnimArgs[1]; + gBattleAnimArgs[3] = -gBattleAnimArgs[3]; } if (!IsContest() && GetBattlerSide(gBattleAnimAttacker) == GetBattlerSide(gBattleAnimTarget)) @@ -387,13 +384,8 @@ static void AnimTranslateStinger(struct Sprite *sprite) if (GetBattlerPosition(gBattleAnimTarget) == B_POSITION_PLAYER_LEFT || GetBattlerPosition(gBattleAnimTarget) == B_POSITION_OPPONENT_LEFT) { - s16 temp1, temp2; - - temp1 = gBattleAnimArgs[2]; - gBattleAnimArgs[2] = -temp1; - - temp2 = gBattleAnimArgs[0]; - gBattleAnimArgs[0] = -temp2; + gBattleAnimArgs[2] *= -1; + gBattleAnimArgs[0] *= -1; } } @@ -448,28 +440,24 @@ static void AnimMissileArc_Step(struct Sprite *sprite) else { s16 tempData[8]; - u16 *data = sprite->data; - u16 x1 = sprite->pos1.x; - s16 x2 = sprite->pos2.x; - u16 y1 = sprite->pos1.y; - s16 y2 = sprite->pos2.y; + s16 xpos, ypos; int i; for (i = 0; i < 8; i++) - tempData[i] = data[i]; + tempData[i] = sprite->data[i]; - x2 += x1; - y2 += y1; + xpos = sprite->pos1.x + sprite->pos2.x; + ypos = sprite->pos1.y + sprite->pos2.y; if (!TranslateAnimHorizontalArc(sprite)) { - u16 rotation = ArcTan2Neg(sprite->pos1.x + sprite->pos2.x - x2, - sprite->pos1.y + sprite->pos2.y - y2); + u16 rotation = ArcTan2Neg(sprite->pos1.x + sprite->pos2.x - xpos, //Isn't this zero lol + sprite->pos1.y + sprite->pos2.y - ypos); rotation += 0xC000; TrySetSpriteRotScale(sprite, FALSE, 0x100, 0x100, rotation); for (i = 0; i < 8; i++) - data[i] = tempData[i]; + sprite->data[i] = tempData[i]; } } } diff --git a/src/battle_anim_effects_1.c b/src/battle_anim_effects_1.c index 516c58e557..9acb4b83ab 100644 --- a/src/battle_anim_effects_1.c +++ b/src/battle_anim_effects_1.c @@ -4445,7 +4445,7 @@ static void AnimBowMon_Step1_Callback(struct Sprite* sprite) { sprite->data[3] = gBattlerSpriteIds[gBattleAnimAttacker]; PrepareBattlerSpriteForRotScale(sprite->data[3], ST_OAM_OBJ_NORMAL); - sprite->data[4] = (sprite->data[6] = GetBattlerSide(gBattleAnimAttacker)) ? 0x300 : 0xFFFFFD00; + sprite->data[4] = (sprite->data[6] = GetBattlerSide(gBattleAnimAttacker)) ? 0x300 : (s16)0xFFFFFD00; sprite->data[5] = 0; } diff --git a/src/berry.c b/src/berry.c index 98264f37b8..d70e8c3537 100644 --- a/src/berry.c +++ b/src/berry.c @@ -1331,7 +1331,7 @@ void ResetBerryTreeSparkleFlags(void) s16 bottom; int i; - GetCameraCoords(&cam_left, &cam_top); + GetCameraCoords((u16*)&cam_left, (u16*)&cam_top); left = cam_left; top = cam_top + 3; right = cam_left + 14; diff --git a/src/berry_blender.c b/src/berry_blender.c index a2a96c0892..de3cc62759 100644 --- a/src/berry_blender.c +++ b/src/berry_blender.c @@ -116,8 +116,8 @@ struct BerryBlenderData u16 field_116; u16 field_118; u16 field_11A; - u16 bg_X; - u16 bg_Y; + s16 bg_X; + s16 bg_Y; u8 field_120[3]; u8 field_123; u16 scores[BLENDER_MAX_PLAYERS][BLENDER_SCORES_NO]; @@ -3166,13 +3166,13 @@ static void sub_80832E8(s16* a0) static void sub_808330C(void) { - sub_80832E8(&sBerryBlenderData->bg_X); - sub_80832E8(&sBerryBlenderData->bg_Y); + sub_80832E8((s16 *)&sBerryBlenderData->bg_X); + sub_80832E8((s16 *)&sBerryBlenderData->bg_Y); } static void sub_8083334(s16* a0, u16 a1) { - s32 var; + u8 var; if (a1 < 10) var = 16; diff --git a/src/easy_chat.c b/src/easy_chat.c index 44a7b90c14..c839c0070d 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -2537,7 +2537,7 @@ u8 sub_811BBBC(void) return sEasyChatScreen->unk_0c; } -void sub_811BBC8(u8 *arg0, u8 *arg1) +static void sub_811BBC8(s8 *arg0, s8 *arg1) { *arg0 = sEasyChatScreen->unk_10; *arg1 = sEasyChatScreen->unk_11; @@ -4529,18 +4529,18 @@ static void sub_811E30C(void) x = var0 * 13; x = x * 8 + 28; y = var1 * 16 + 96; - sub_811E34C(x, y); + sub_811E34C((u8)x, (u8)y); } static void sub_811E34C(u8 x, u8 y) { - if (sUnknown_0203A11C->unk2E4) - { - sUnknown_0203A11C->unk2E4->pos1.x = x; - sUnknown_0203A11C->unk2E4->pos1.y = y; - sUnknown_0203A11C->unk2E4->pos2.x = 0; - sUnknown_0203A11C->unk2E4->data[0] = 0; - } + if (!sUnknown_0203A11C->unk2E4) + return; + + sUnknown_0203A11C->unk2E4->pos1.x = (s16)x; + sUnknown_0203A11C->unk2E4->pos1.y = (s16)y; + sUnknown_0203A11C->unk2E4->pos2.x = 0; + sUnknown_0203A11C->unk2E4->data[0] = 0; } static void sub_811E380(void) diff --git a/src/event_object_movement.c b/src/event_object_movement.c index ad839e0067..c3fef8c0de 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -8950,7 +8950,7 @@ void CreateLevitateMovementTask(struct ObjectEvent *objectEvent) u8 taskId = CreateTask(ApplyLevitateMovement, 0xFF); struct Task *task = &gTasks[taskId]; - StoreWordInTwoHalfwords(&task->data[0], (u32)objectEvent); + StoreWordInTwoHalfwords((u16 *)&task->data[0], (u32)objectEvent); objectEvent->warpArrowSpriteId = taskId; task->data[3] = 0xFFFF; } @@ -8961,7 +8961,7 @@ static void ApplyLevitateMovement(u8 taskId) struct Sprite *sprite; struct Task *task = &gTasks[taskId]; - LoadWordFromTwoHalfwords(&task->data[0], (u32 *)&objectEvent); // load the map object pointer. + LoadWordFromTwoHalfwords((u16 *)&task->data[0], (u32 *)&objectEvent); // load the map object pointer. sprite = &gSprites[objectEvent->spriteId]; if(!(task->data[2] & 0x3)) @@ -8978,7 +8978,7 @@ void DestroyExtraMovementTask(u8 taskId) struct ObjectEvent *objectEvent; struct Task *task = &gTasks[taskId]; - LoadWordFromTwoHalfwords(&task->data[0], (u32 *)&objectEvent); // unused objectEvent + LoadWordFromTwoHalfwords((u16 *)&task->data[0], (u32 *)&objectEvent); // unused objectEvent DestroyTask(taskId); } diff --git a/src/field_effect.c b/src/field_effect.c index 07579f55d5..bc1e6f134d 100644 --- a/src/field_effect.c +++ b/src/field_effect.c @@ -2501,7 +2501,7 @@ static void sub_80B8584(struct Task *task) { task->data[11] = REG_WININ; task->data[12] = REG_WINOUT; - StoreWordInTwoHalfwords(&task->data[13], (u32)gMain.vblankCallback); + StoreWordInTwoHalfwords((u16 *)&task->data[13], (u32)gMain.vblankCallback); task->data[1] = 0xf0f1; task->data[2] = 0x5051; task->data[3] = 0x3f; diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index bf9850deca..8e47c1e3ae 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -612,7 +612,7 @@ static void Task_Hof_PrintMonInfoAfterAnimating(u8 taskId) static void Task_Hof_TryDisplayAnotherMon(u8 taskId) { - u16 currPokeID = gTasks[taskId].tDisplayedMonId; + u16 currPokeID = (u16)gTasks[taskId].tDisplayedMonId; struct HallofFameMon* currMon = &sHofMonPtr->mon[currPokeID]; if (gTasks[taskId].tFrameCount != 0) @@ -1483,7 +1483,7 @@ static void UpdateDomeConfetti(struct ConfettiUtil *util) static void Task_DoDomeConfetti(u8 taskId) { u32 id = 0; - u16 *data = gTasks[taskId].data; + u16 *data = (u16 *)gTasks[taskId].data; switch (tState) { diff --git a/src/item_use.c b/src/item_use.c index 0aae441c8b..fa3f130810 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -721,7 +721,7 @@ static void ItemUseOnFieldCB_WailmerPailBerry(u8 taskId) static bool8 TryToWaterSudowoodo(void) { - u16 x, y; + s16 x, y; u8 z; u8 objId; GetXYCoordsOneStepInFrontOfPlayer(&x, &y); diff --git a/src/list_menu.c b/src/list_menu.c index ddcad0fe9c..ebf02bab65 100644 --- a/src/list_menu.c +++ b/src/list_menu.c @@ -1257,17 +1257,17 @@ void ListMenuSetUpRedOutlineCursorSpriteOamTable(u16 rowWidth, u16 rowHeight, st s32 i, j, id = 0; subsprites[id] = sSubsprite_RedOutline1; - subsprites[id].x = 136; - subsprites[id].y = 136; + subsprites[id].x = -120; + subsprites[id].y = -120; id++; subsprites[id] = sSubsprite_RedOutline2; subsprites[id].x = rowWidth + 128; - subsprites[id].y = 136; + subsprites[id].y = -120; id++; subsprites[id] = sSubsprite_RedOutline7; - subsprites[id].x = 136; + subsprites[id].x = -120; subsprites[id].y = rowHeight + 128; id++; @@ -1297,7 +1297,7 @@ void ListMenuSetUpRedOutlineCursorSpriteOamTable(u16 rowWidth, u16 rowHeight, st for (j = 8; j < rowHeight - 8; j += 8) { subsprites[id] = sSubsprite_RedOutline4; - subsprites[id].x = 136; + subsprites[id].x = -120; subsprites[id].y = j - 120; id++; diff --git a/src/mirage_tower.c b/src/mirage_tower.c index e2f5cefb78..bdddbdbe64 100644 --- a/src/mirage_tower.c +++ b/src/mirage_tower.c @@ -168,7 +168,7 @@ const struct PulseBlendSettings gMirageTowerPulseBlendSettings = { .numColors = 15, .delay = 5, .numFadeCycles = -1, - .maxBlendCoeff = 11, + .maxBlendCoeff = -5, .fadeType = 1, .restorePaletteOnUnload = FALSE, .unk7_7 = 1, @@ -412,10 +412,9 @@ void DoMirageTowerCeilingCrumble(void) static void WaitCeilingCrumble(u8 taskId) { - u16 *data = gTasks[taskId].data; - data[1]++; + u16 *data = (u16 *)gTasks[taskId].data; // Either wait 1000 frames, or until all 16 crumble sprites and the one screen-shake task are completed. - if (data[1] == 1000 || data[0] == 17) + if (++data[1] == 1000 || data[0] == 17) gTasks[taskId].func = FinishCeilingCrumbleTask; } diff --git a/src/overworld.c b/src/overworld.c index ea0d633bcf..6b8fd232e6 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -3212,7 +3212,7 @@ static void SpriteCB_LinkPlayer(struct Sprite *sprite) SetObjectSubpriorityByZCoord(objEvent->previousElevation, sprite, 1); sprite->oam.priority = ZCoordToPriority(objEvent->previousElevation); - if (!linkPlayerObjEvent->movementMode != MOVEMENT_MODE_FREE) + if (linkPlayerObjEvent->movementMode == MOVEMENT_MODE_FREE) StartSpriteAnim(sprite, GetFaceDirectionAnimNum(objEvent->range.as_byte)); else StartSpriteAnimIfDifferent(sprite, GetMoveDirectionAnimNum(objEvent->range.as_byte)); diff --git a/src/party_menu.c b/src/party_menu.c index d5bc6dfb63..6a38d90989 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -1862,7 +1862,7 @@ u8 GetMonAilment(struct Pokemon *mon) static void SetPartyMonsAllowedInMinigame(void) { - u16 *ptr; + s16 *ptr; if (gPartyMenu.menuType == PARTY_MENU_TYPE_MINIGAME) { @@ -4951,9 +4951,9 @@ static void Task_DisplayLevelUpStatsPg2(u8 taskId) static void DisplayLevelUpStatsPg1(u8 taskId) { - s16 *arrayPtr = sPartyMenuInternal->data; + u16 *arrayPtr = (u16*)sPartyMenuInternal->data; - arrayPtr[12] = CreateLevelUpStatsWindow(); + arrayPtr[12] = (u16)CreateLevelUpStatsWindow(); DrawLevelUpWindowPg1(arrayPtr[12], arrayPtr, &arrayPtr[6], TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY, TEXT_COLOR_LIGHT_GREY); CopyWindowToVram(arrayPtr[12], 2); ScheduleBgCopyTilemapToVram(2); @@ -4961,7 +4961,7 @@ static void DisplayLevelUpStatsPg1(u8 taskId) static void DisplayLevelUpStatsPg2(u8 taskId) { - s16 *arrayPtr = sPartyMenuInternal->data; + u16 *arrayPtr = (u16 *)sPartyMenuInternal->data; DrawLevelUpWindowPg2(arrayPtr[12], &arrayPtr[6], TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY, TEXT_COLOR_LIGHT_GREY); CopyWindowToVram(arrayPtr[12], 2); diff --git a/src/player_pc.c b/src/player_pc.c index fc0bd9f4c8..2010d84f85 100644 --- a/src/player_pc.c +++ b/src/player_pc.c @@ -327,7 +327,7 @@ void PlayerPC(void) static void InitPlayerPCMenu(u8 taskId) { - u16 *data; + s16 *data; struct WindowTemplate windowTemplate; data = gTasks[taskId].data; @@ -346,7 +346,7 @@ static void InitPlayerPCMenu(u8 taskId) static void PlayerPCProcessMenuInput(u8 taskId) { - u16 *data; + s16 *data; s8 inputOptionId; data = gTasks[taskId].data; @@ -435,7 +435,7 @@ static void PlayerPC_TurnOff(u8 taskId) static void InitItemStorageMenu(u8 taskId, u8 var) { - u16 *data; + s16 *data; struct WindowTemplate windowTemplate; data = gTasks[taskId].data; @@ -548,7 +548,7 @@ static void ItemStorage_Toss(u8 taskId) static void ItemStorage_WithdrawToss_Helper(u8 taskId, bool8 toss) { - u16 *data = gTasks[taskId].data; + s16 *data = gTasks[taskId].data; data[3] = toss; sub_816B4DC(taskId); @@ -581,9 +581,9 @@ static void ItemStorage_SetItemAndMailCount(u8 taskId) static void sub_816B4DC(u8 taskId) { - u16 *data = gTasks[taskId].data; + u16 *data = (u16 *)gTasks[taskId].data; - ClearStdWindowAndFrameToTransparent(data[4], FALSE); + ClearStdWindowAndFrameToTransparent((u8)data[4], FALSE); ClearWindowTilemap(data[4]); RemoveWindow(data[4]); ScheduleBgCopyTilemapToVram(0); @@ -1380,7 +1380,7 @@ static void ItemStorage_DoItemToss(u8 taskId) data = gTasks[taskId].data; b = (playerPCItemPageInfo.cursorPos + playerPCItemPageInfo.itemsAbove); - if (!ItemId_GetImportance(gSaveBlock1Ptr->pcItems[b].itemId)) + if (ItemId_GetImportance(gSaveBlock1Ptr->pcItems[b].itemId) == 0) { CopyItemName(gSaveBlock1Ptr->pcItems[b].itemId, gStringVar1); ConvertIntToDecimalStringN(gStringVar2, data[2], STR_CONV_MODE_LEFT_ALIGN, 3); diff --git a/src/pokedex.c b/src/pokedex.c index 0541f3f2e6..777cc52cd6 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -5117,9 +5117,9 @@ static void Task_SelectSearchMenuItem(u8 taskId) u16 *scrollOffset; DrawOrEraseSearchParameterBox(FALSE); - menuItem = gTasks[taskId].tMenuItem; - cursorPos = &gTasks[taskId].data[sSearchOptions[menuItem].taskDataCursorPos]; - scrollOffset = &gTasks[taskId].data[sSearchOptions[menuItem].taskDataScrollOffset]; + menuItem = (u16)gTasks[taskId].tMenuItem; + cursorPos = (u16*)&gTasks[taskId].data[sSearchOptions[menuItem].taskDataCursorPos]; + scrollOffset = (u16*)&gTasks[taskId].data[sSearchOptions[menuItem].taskDataScrollOffset]; gTasks[taskId].tCursorPos = *cursorPos; gTasks[taskId].tScrollOffset = *scrollOffset; PrintSearchParameterText(taskId); diff --git a/src/roulette.c b/src/roulette.c index 58e120cb50..f55736a969 100644 --- a/src/roulette.c +++ b/src/roulette.c @@ -633,7 +633,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -643,7 +643,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -653,7 +653,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -663,7 +663,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -673,7 +673,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -683,7 +683,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -693,7 +693,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -703,7 +703,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -713,7 +713,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -723,7 +723,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -733,7 +733,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -743,7 +743,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -753,7 +753,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 10, .var06 = 0xFF, .var07_0 = 14, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, }; @@ -767,7 +767,7 @@ static const struct UnkStruct1 gUnknown_085B63F0[] = .var05 = 30, .var06 = 0xFF, .var07_0 = 14, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -777,7 +777,7 @@ static const struct UnkStruct1 gUnknown_085B63F0[] = .var05 = 30, .var06 = 0xFF, .var07_0 = 14, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -787,7 +787,7 @@ static const struct UnkStruct1 gUnknown_085B63F0[] = .var05 = 30, .var06 = 0xFF, .var07_0 = 14, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 } }; diff --git a/src/scrcmd.c b/src/scrcmd.c index 4a7f4ea735..2a6abf17e1 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -788,8 +788,8 @@ bool8 ScrCmd_warphole(struct ScriptContext *ctx) { u8 mapGroup = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx); - u16 x; - u16 y; + s16 x; + s16 y; PlayerGetDestCoords(&x, &y); if (mapGroup == 0xFF && mapNum == 0xFF) diff --git a/src/secret_base.c b/src/secret_base.c index 83626710fc..35ac31d4a7 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -964,7 +964,7 @@ static void HandleRegistryMenuInput(u8 taskId) data = gTasks[taskId].data; input = ListMenu_ProcessInput(data[5]); - ListMenuGetScrollAndRow(data[5], &data[2], &data[1]); + ListMenuGetScrollAndRow((u8)data[5], (u16 *)&data[2], (u16 *)&data[1]); switch (input) { case LIST_NOTHING_CHOSEN: @@ -1045,10 +1045,10 @@ void DeleteRegistry_Yes_Callback(u8 taskId) { s16 *data = gTasks[taskId].data; ClearDialogWindowAndFrame(0, 0); - DestroyListMenuTask(data[5], &data[2], &data[1]); + DestroyListMenuTask((u8)data[5], (u16 *)&data[2], (u16 *)&data[1]); gSaveBlock1Ptr->secretBases[data[4]].registryStatus = 0; BuildRegistryMenuItems(taskId); - sub_812225C(&data[2], &data[1], data[3], data[0]); + sub_812225C((u16 *)&data[2], (u16 *)&data[1], (u16)data[3], (u16)data[0]); FinalizeRegistryMenu(taskId); gTasks[taskId].func = HandleRegistryMenuInput; } @@ -1062,7 +1062,7 @@ static void DeleteRegistry_No(u8 taskId) { s16 *data = gTasks[taskId].data; ClearDialogWindowAndFrame(0, 0); - DestroyListMenuTask(data[5], &data[2], &data[1]); + DestroyListMenuTask((u8)data[5], (u16 *)&data[2], (u16 *)&data[1]); FinalizeRegistryMenu(taskId); gTasks[taskId].func = HandleRegistryMenuInput; } diff --git a/src/slot_machine.c b/src/slot_machine.c index d1cb05b180..6557e8cf49 100644 --- a/src/slot_machine.c +++ b/src/slot_machine.c @@ -775,7 +775,7 @@ static void PlaySlotMachine_Internal(u8 slotMachineIndex, MainCallback cb) { struct Task *task = &gTasks[CreateTask(SlotMachineDummyTask, 0xFF)]; task->data[0] = slotMachineIndex; - StoreWordInTwoHalfwords(task->data + 1, (intptr_t)cb); + StoreWordInTwoHalfwords((u16 *)(task->data + 1), (intptr_t)cb); } diff --git a/src/start_menu.c b/src/start_menu.c index 88ad364c7b..68a3161855 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -463,7 +463,7 @@ static bool32 InitStartMenuStep(void) sInitStartMenuData[0]++; break; case 4: - if (PrintStartMenuActions(&sInitStartMenuData[1], 2)) + if (PrintStartMenuActions((s8 *)&sInitStartMenuData[1], 2)) sInitStartMenuData[0]++; break; case 5: diff --git a/src/trainer_see.c b/src/trainer_see.c index 68a16e208b..93daab421d 100644 --- a/src/trainer_see.c +++ b/src/trainer_see.c @@ -603,7 +603,7 @@ static void sub_80B44C8(u8 taskId) struct ObjectEvent *objEvent; // another objEvent loaded into by loadword? - LoadWordFromTwoHalfwords(&task->data[1], (u32 *)&objEvent); + LoadWordFromTwoHalfwords((u16*)&task->data[1], (u32 *)&objEvent); if (!task->data[7]) { ObjectEventClearHeldMovement(objEvent); @@ -624,7 +624,7 @@ static void sub_80B44C8(u8 taskId) void sub_80B4578(struct ObjectEvent *var) { - StoreWordInTwoHalfwords(&gTasks[CreateTask(sub_80B44C8, 0)].data[1], (u32)var); + StoreWordInTwoHalfwords((u16 *)&gTasks[CreateTask(sub_80B44C8, 0)].data[1], (u32)var); } void EndTrainerApproach(void) From f007165c538376fa8357727783ede54884c982e1 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 27 Jul 2020 12:27:35 +0200 Subject: [PATCH 02/17] Fix undefined behaviour in protect animation gPlttBufferFaded[sprite->data[2] + ++i] = gPlttBufferFaded[sprite->data[2] + i + 1] The above does NOT make it certain that i gets incremented before reading from the right side. Changed it, so the function always increments i first, then reads from pal buffer. --- src/battle_anim_effects_1.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/battle_anim_effects_1.c b/src/battle_anim_effects_1.c index 516c58e557..f93b2a5c48 100644 --- a/src/battle_anim_effects_1.c +++ b/src/battle_anim_effects_1.c @@ -3967,21 +3967,21 @@ static void AnimProtect(struct Sprite* sprite) static void AnimProtect_Step(struct Sprite *sprite) { - int a; - int i; + int i, id, savedPal; sprite->data[5] += 96; sprite->pos2.x = -(sprite->data[5] >> 8); if (++sprite->data[1] > 1) { sprite->data[1] = 0; - a = gPlttBufferFaded[sprite->data[2] + 1]; + savedPal = gPlttBufferFaded[sprite->data[2] + 1]; i = 0; - do + while (i < 6) { - gPlttBufferFaded[sprite->data[2] + ++i] = gPlttBufferFaded[sprite->data[2] + i + 1]; - } while (i < 6); + id = sprite->data[2] + ++i; + gPlttBufferFaded[id] = gPlttBufferFaded[id + 1]; + } - gPlttBufferFaded[sprite->data[2] + 7] = a; + gPlttBufferFaded[sprite->data[2] + 7] = savedPal; } if (sprite->data[7] > 6 && sprite->data[0] >0 && ++sprite->data[6] > 1) From ddd012f3edf7cd1a3df518492faa8de15833874c Mon Sep 17 00:00:00 2001 From: PokeCodec Date: Mon, 27 Jul 2020 12:47:08 -0400 Subject: [PATCH 03/17] holding back on casts --- src/agb_flash.c | 2 +- src/battle_anim_effects_1.c | 2 +- src/hall_of_fame.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/agb_flash.c b/src/agb_flash.c index 0045219c41..eeccf11164 100644 --- a/src/agb_flash.c +++ b/src/agb_flash.c @@ -242,7 +242,7 @@ u32 VerifyFlashSectorNBytes(u16 sectorNum, u8 *src, u32 n) funcSrc = (u16 *)((uintptr_t)funcSrc ^ 1); funcDest = verifyFlashSector_Core_Buffer; - i = (u16)(((uintptr_t)VerifyFlashSector - (uintptr_t)VerifyFlashSector_Core) >> 1); + i = ((uintptr_t)VerifyFlashSector - (uintptr_t)VerifyFlashSector_Core) >> 1; while (i != 0) { diff --git a/src/battle_anim_effects_1.c b/src/battle_anim_effects_1.c index 9acb4b83ab..516c58e557 100644 --- a/src/battle_anim_effects_1.c +++ b/src/battle_anim_effects_1.c @@ -4445,7 +4445,7 @@ static void AnimBowMon_Step1_Callback(struct Sprite* sprite) { sprite->data[3] = gBattlerSpriteIds[gBattleAnimAttacker]; PrepareBattlerSpriteForRotScale(sprite->data[3], ST_OAM_OBJ_NORMAL); - sprite->data[4] = (sprite->data[6] = GetBattlerSide(gBattleAnimAttacker)) ? 0x300 : (s16)0xFFFFFD00; + sprite->data[4] = (sprite->data[6] = GetBattlerSide(gBattleAnimAttacker)) ? 0x300 : 0xFFFFFD00; sprite->data[5] = 0; } diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index 8e47c1e3ae..bf9850deca 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -612,7 +612,7 @@ static void Task_Hof_PrintMonInfoAfterAnimating(u8 taskId) static void Task_Hof_TryDisplayAnotherMon(u8 taskId) { - u16 currPokeID = (u16)gTasks[taskId].tDisplayedMonId; + u16 currPokeID = gTasks[taskId].tDisplayedMonId; struct HallofFameMon* currMon = &sHofMonPtr->mon[currPokeID]; if (gTasks[taskId].tFrameCount != 0) @@ -1483,7 +1483,7 @@ static void UpdateDomeConfetti(struct ConfettiUtil *util) static void Task_DoDomeConfetti(u8 taskId) { u32 id = 0; - u16 *data = (u16 *)gTasks[taskId].data; + u16 *data = gTasks[taskId].data; switch (tState) { From 1c55734e44a2006571a0f04805bea38852207965 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 19 Jul 2020 14:12:38 -0400 Subject: [PATCH 04/17] Document faraway island --- data/maps/FarawayIsland_Interior/scripts.inc | 52 ++--- data/specials.inc | 4 +- include/faraway_island.h | 2 +- src/event_object_movement.c | 2 +- src/faraway_island.c | 191 ++++++++++--------- 5 files changed, 136 insertions(+), 115 deletions(-) diff --git a/data/maps/FarawayIsland_Interior/scripts.inc b/data/maps/FarawayIsland_Interior/scripts.inc index cad875b654..2a06ffdfaf 100644 --- a/data/maps/FarawayIsland_Interior/scripts.inc +++ b/data/maps/FarawayIsland_Interior/scripts.inc @@ -8,24 +8,24 @@ FarawayIsland_Interior_MapScripts:: @ 8267CFA .byte 0 FarawayIsland_Interior_OnReturnToField: @ 8267D0F - call_if_set FLAG_SYS_CTRL_OBJ_DELETE, FarawayIsland_Interior_EventScript_267D19 + call_if_set FLAG_SYS_CTRL_OBJ_DELETE, FarawayIsland_Interior_EventScript_TrySetMewAboveGrass end -FarawayIsland_Interior_EventScript_267D19:: @ 8267D19 +FarawayIsland_Interior_EventScript_TrySetMewAboveGrass:: @ 8267D19 specialvar VAR_RESULT, GetBattleOutcome compare VAR_RESULT, B_OUTCOME_WON - goto_if_eq FarawayIsland_Interior_EventScript_267D4B + goto_if_eq FarawayIsland_Interior_EventScript_SetMewAboveGrass compare VAR_RESULT, B_OUTCOME_RAN - goto_if_eq FarawayIsland_Interior_EventScript_267D4B + goto_if_eq FarawayIsland_Interior_EventScript_SetMewAboveGrass compare VAR_RESULT, B_OUTCOME_PLAYER_TELEPORTED - goto_if_eq FarawayIsland_Interior_EventScript_267D4B + goto_if_eq FarawayIsland_Interior_EventScript_SetMewAboveGrass compare VAR_RESULT, B_OUTCOME_MON_TELEPORTED - goto_if_eq FarawayIsland_Interior_EventScript_267D4B + goto_if_eq FarawayIsland_Interior_EventScript_SetMewAboveGrass return -FarawayIsland_Interior_EventScript_267D4B:: @ 8267D4B +FarawayIsland_Interior_EventScript_SetMewAboveGrass:: @ 8267D4B setvar VAR_0x8004, 1 - special sub_81D4A90 + special SetMewAboveGrass return FarawayIsland_Interior_OnResume: @ 8267D54 @@ -81,7 +81,7 @@ FarawayIsland_Interior_Movement_MewAppear: @ 8267DD4 set_visible step_end -FarawayIsland_Interior_Movement_MewHideDown: @ 8267DD6 +FarawayIsland_Interior_Movement_MewFloatUpNorth: @ 8267DD6 lock_facing_direction walk_fast_up walk_fast_up @@ -90,7 +90,7 @@ FarawayIsland_Interior_Movement_MewHideDown: @ 8267DD6 walk_in_place_down step_end -FarawayIsland_Interior_Movement_MewHideUp: @ 8267DDD +FarawayIsland_Interior_Movement_MewFloatUpSouth: @ 8267DDD lock_facing_direction walk_fast_up walk_fast_up @@ -99,7 +99,7 @@ FarawayIsland_Interior_Movement_MewHideUp: @ 8267DDD walk_in_place_up step_end -FarawayIsland_Interior_Movement_MewHideRight: @ 8267DE4 +FarawayIsland_Interior_Movement_MewFloatUpWest: @ 8267DE4 lock_facing_direction walk_fast_up walk_fast_up @@ -108,7 +108,7 @@ FarawayIsland_Interior_Movement_MewHideRight: @ 8267DE4 walk_in_place_right step_end -FarawayIsland_Interior_Movement_MewHideLeft: @ 8267DEB +FarawayIsland_Interior_Movement_MewFloatUpEast: @ 8267DEB lock_facing_direction walk_fast_up walk_fast_up @@ -123,19 +123,19 @@ FarawayIsland_Interior_EventScript_Mew:: @ 8267DF2 applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewAppear waitmovement 0 setvar VAR_0x8004, 0 - special sub_81D4A90 + special SetMewAboveGrass message FarawayIsland_Interior_Text_Mew waitse playmoncry SPECIES_MEW, 2 compare VAR_FACING, DIR_NORTH - call_if_eq FarawayIsland_Interior_EventScript_MewHideDown + call_if_eq FarawayIsland_Interior_EventScript_FoundMewNorth compare VAR_FACING, DIR_SOUTH - call_if_eq FarawayIsland_Interior_EventScript_MewHideUp + call_if_eq FarawayIsland_Interior_EventScript_FoundMewSouth compare VAR_FACING, DIR_WEST - call_if_eq FarawayIsland_Interior_EventScript_MewHideRight + call_if_eq FarawayIsland_Interior_EventScript_FoundMewWest compare VAR_FACING, DIR_EAST - call_if_eq FarawayIsland_Interior_EventScript_MewHideLeft - special sub_81D4BEC + call_if_eq FarawayIsland_Interior_EventScript_FoundMewEast + special DestroyMewEmergingGrassSprite delay 40 waitmoncry setvar VAR_0x8004, SPECIES_MEW @@ -170,23 +170,23 @@ FarawayIsland_Interior_EventScript_PlayerOrMewRan:: @ 8267EA4 goto Common_EventScript_LegendaryFlewAway end -FarawayIsland_Interior_EventScript_MewHideDown:: @ 8267EAF - applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewHideDown +FarawayIsland_Interior_EventScript_FoundMewNorth:: @ 8267EAF + applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewFloatUpNorth waitmovement 0 return -FarawayIsland_Interior_EventScript_MewHideUp:: @ 8267EBA - applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewHideUp +FarawayIsland_Interior_EventScript_FoundMewSouth:: @ 8267EBA + applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewFloatUpSouth waitmovement 0 return -FarawayIsland_Interior_EventScript_MewHideRight:: @ 8267EC5 - applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewHideRight +FarawayIsland_Interior_EventScript_FoundMewWest:: @ 8267EC5 + applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewFloatUpWest waitmovement 0 return -FarawayIsland_Interior_EventScript_MewHideLeft:: @ 8267ED0 - applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewHideLeft +FarawayIsland_Interior_EventScript_FoundMewEast:: @ 8267ED0 + applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewFloatUpEast waitmovement 0 return diff --git a/data/specials.inc b/data/specials.inc index 0f78f981f5..d7d1897d87 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -511,14 +511,14 @@ gSpecials:: @ 81DBA64 def_special ScriptMenu_CreateLilycoveSSTidalMultichoice def_special GetLilycoveSSTidalSelection def_special TurnOnTVScreen - def_special sub_81D4A90 + def_special SetMewAboveGrass def_special ShouldDistributeEonTicket def_special LinkRetireStatusWithBattleTowerPartner def_special sub_813B534 def_special CallTrainerHillFunction def_special Script_DoRayquazaScene @ Listed twice def_special LoopWingFlapSE - def_special sub_81D4BEC + def_special DestroyMewEmergingGrassSprite def_special ShowBerryCrushRankings def_special TryBufferWaldaPhrase def_special DoWaldaNamingScreen diff --git a/include/faraway_island.h b/include/faraway_island.h index 084b5a2779..a5243c6a70 100755 --- a/include/faraway_island.h +++ b/include/faraway_island.h @@ -2,7 +2,7 @@ #define GUARD_FARAWAY_ISLAND_H u32 GetMewMoveDirection(void); -bool8 sub_81D4A58(struct ObjectEvent*); +bool8 ShouldMewShakeGrass(struct ObjectEvent*); void UpdateFarawayIslandStepCounter(void); bool8 ObjectEventIsFarawayIslandMew(struct ObjectEvent *); bool8 IsMewPlayingHideAndSeek(void); diff --git a/src/event_object_movement.c b/src/event_object_movement.c index c3fef8c0de..76331c2b14 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -8124,7 +8124,7 @@ static void DoFlaggedGroundEffects(struct ObjectEvent *objEvent, struct Sprite * { u8 i; - if (ObjectEventIsFarawayIslandMew(objEvent) == TRUE && !sub_81D4A58(objEvent)) + if (ObjectEventIsFarawayIslandMew(objEvent) == TRUE && !ShouldMewShakeGrass(objEvent)) return; for (i = 0; i < ARRAY_COUNT(sGroundEffectFuncs); i++, flags >>= 1) diff --git a/src/faraway_island.c b/src/faraway_island.c index 06e47cd216..57d31057f0 100755 --- a/src/faraway_island.c +++ b/src/faraway_island.c @@ -9,15 +9,15 @@ #include "constants/maps.h" #include "constants/metatile_behaviors.h" -static u8 sub_81D4890(u8); -static bool8 sub_81D4C14(struct ObjectEvent*, u8); -static u8 sub_81D4C9C(struct ObjectEvent*, u8); -static u8 sub_81D4C58(struct ObjectEvent*, u8); -static u8 sub_81D4CE0(struct ObjectEvent*, u8); -static u8 sub_81D4D24(u8); -static bool8 CanMewWalkToCoords(s16, s16); +static u8 GetValidMewMoveDirection(u8); +static bool8 ShouldMewMoveNorth(struct ObjectEvent*, u8); +static bool8 ShouldMewMoveSouth(struct ObjectEvent*, u8); +static bool8 ShouldMewMoveEast(struct ObjectEvent*, u8); +static bool8 ShouldMewMoveWest(struct ObjectEvent*, u8); +static u8 GetRandomMewDirectionCandidate(u8); +static bool8 CanMewMoveToCoords(s16, s16); -static EWRAM_DATA u8 sUnknown_0203CF50 = 0; +static EWRAM_DATA u8 sGrassSpriteId = 0; static s16 sPlayerToMewDeltaX; static s16 sPlayerToMewDeltaY; @@ -28,10 +28,10 @@ extern const struct SpriteTemplate *const gFieldEffectObjectTemplatePointers[]; static const s16 sFarawayIslandRockCoords[4][2] = { - {21, 16}, - {25, 16}, - {16, 17}, - {20, 20}, + {14 + 7, 9 + 7}, + {18 + 7, 9 + 7}, + { 9 + 7, 10 + 7}, + {13 + 7, 13 + 7}, }; static u8 GetMewObjectEventId(void) @@ -41,10 +41,12 @@ static u8 GetMewObjectEventId(void) return objectEventId; } +// When the player enters Faraway Island interior it begins a "hide and seek" minigame where Mew disappears into the grass +// This function returns the direction Mew will take a step, and is run every time the player takes a step u32 GetMewMoveDirection(void) { u8 i; - int skip; + int mewSafeFromTrap; struct ObjectEvent *mew = &gObjectEvents[GetMewObjectEventId()]; sPlayerToMewDeltaX = gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.x - mew->currentCoords.x; @@ -52,43 +54,47 @@ u32 GetMewMoveDirection(void) for (i = 0; i < ARRAY_COUNT(sMewDirectionCandidates); i++) sMewDirectionCandidates[i] = DIR_NONE; + // Player hasn't moved (just facing new direction), don't move if (gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.x == gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.x && gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.y == gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.y) { return DIR_NONE; } + // Mew is invisible except for every 8th step if (VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % 8 == 0) - mew->invisible = 0; + mew->invisible = FALSE; else - mew->invisible = 1; + mew->invisible = TRUE; + // Mew will stay in place for 1 step after its visible if (VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % 9 == 0) return DIR_NONE; + // Below loop is for Mew to try to avoid getting trapped between the player and a rock for (i = 0; i < ARRAY_COUNT(sFarawayIslandRockCoords); i++) { if (gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.x == sFarawayIslandRockCoords[i][0]) { - skip = 0; + mewSafeFromTrap = FALSE; if (gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.y < sFarawayIslandRockCoords[i][1]) { if (mew->currentCoords.y <= sFarawayIslandRockCoords[i][1]) - skip = 1; + mewSafeFromTrap = TRUE; } else { if (mew->currentCoords.y >= sFarawayIslandRockCoords[i][1]) - skip = 1; + mewSafeFromTrap = TRUE; } - if (!skip) + if (!mewSafeFromTrap) { if (sPlayerToMewDeltaX > 0) { if (mew->currentCoords.x + 1 == gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.x) { - if (CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) return DIR_EAST; } } @@ -96,7 +102,7 @@ u32 GetMewMoveDirection(void) { if (mew->currentCoords.x - 1 == gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.x) { - if (CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) return DIR_WEST; } } @@ -105,12 +111,12 @@ u32 GetMewMoveDirection(void) { if (sPlayerToMewDeltaY > 0) { - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) return DIR_NORTH; } else { - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) return DIR_SOUTH; } } @@ -119,25 +125,25 @@ u32 GetMewMoveDirection(void) if (gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.y == sFarawayIslandRockCoords[i][1]) { - skip = 0; + mewSafeFromTrap = FALSE; if (gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.x < sFarawayIslandRockCoords[i][0]) { if (mew->currentCoords.x <= sFarawayIslandRockCoords[i][0]) - skip = 1; + mewSafeFromTrap = TRUE; } else { if (mew->currentCoords.x >= sFarawayIslandRockCoords[i][0]) - skip = 1; + mewSafeFromTrap = TRUE; } - if (!skip) + if (!mewSafeFromTrap) { if (sPlayerToMewDeltaY > 0) { if (mew->currentCoords.y + 1 == gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.y) { - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) return DIR_SOUTH; } } @@ -145,7 +151,7 @@ u32 GetMewMoveDirection(void) { if (mew->currentCoords.y - 1 == gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.y) { - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) return DIR_NORTH; } } @@ -154,12 +160,12 @@ u32 GetMewMoveDirection(void) { if (sPlayerToMewDeltaX > 0) { - if (CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) return DIR_WEST; } else { - if (CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) return DIR_EAST; } } @@ -167,92 +173,101 @@ u32 GetMewMoveDirection(void) } } - if (sub_81D4C14(mew, 0)) + // Check if Mew can move in any direction without getting closer to the player + // If so load into sMewDirectionCandidates + // If Mew can move in two of the checked directions, choose one randomly + if (ShouldMewMoveNorth(mew, 0)) { - if (sub_81D4C58(mew, 1)) - return sub_81D4D24(2); - else if (sub_81D4CE0(mew, 1)) - return sub_81D4D24(2); + if (ShouldMewMoveEast(mew, 1)) + return GetRandomMewDirectionCandidate(2); + else if (ShouldMewMoveWest(mew, 1)) + return GetRandomMewDirectionCandidate(2); else return DIR_NORTH; } - if (sub_81D4C9C(mew, 0)) + if (ShouldMewMoveSouth(mew, 0)) { - if (sub_81D4C58(mew, 1)) - return sub_81D4D24(2); - else if (sub_81D4CE0(mew, 1)) - return sub_81D4D24(2); + if (ShouldMewMoveEast(mew, 1)) + return GetRandomMewDirectionCandidate(2); + else if (ShouldMewMoveWest(mew, 1)) + return GetRandomMewDirectionCandidate(2); else return DIR_SOUTH; } - if (sub_81D4C58(mew, 0)) + if (ShouldMewMoveEast(mew, 0)) { - if (sub_81D4C14(mew, 1)) - return sub_81D4D24(2); - else if (sub_81D4C9C(mew, 1)) - return sub_81D4D24(2); + if (ShouldMewMoveNorth(mew, 1)) + return GetRandomMewDirectionCandidate(2); + else if (ShouldMewMoveSouth(mew, 1)) + return GetRandomMewDirectionCandidate(2); else return DIR_EAST; } - if (sub_81D4CE0(mew, 0)) + if (ShouldMewMoveWest(mew, 0)) { - if (sub_81D4C14(mew, 1)) - return sub_81D4D24(2); - else if (sub_81D4C9C(mew, 1)) - return sub_81D4D24(2); + if (ShouldMewMoveNorth(mew, 1)) + return GetRandomMewDirectionCandidate(2); + else if (ShouldMewMoveSouth(mew, 1)) + return GetRandomMewDirectionCandidate(2); else return DIR_WEST; } + // If this point is reached, Mew cannot move without getting closer to the player + + // Avoid player on same Y, try move North/South if (sPlayerToMewDeltaY == 0) { if (gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.y > mew->currentCoords.y) { - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) return DIR_NORTH; } if (gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.y < mew->currentCoords.y) { - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) return DIR_SOUTH; } - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) return DIR_NORTH; - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) return DIR_SOUTH; } + // Avoid player on same X, try move West/East if (sPlayerToMewDeltaX == 0) { if (gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.x > mew->currentCoords.x) { - if (CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) return DIR_WEST; } if (gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.x < mew->currentCoords.x) { - if (CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) return DIR_EAST; } - if (CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) return DIR_EAST; - if (CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) return DIR_WEST; } - return sub_81D4890(DIR_NONE); + // Can't avoid player on axis, move any valid direction + return GetValidMewMoveDirection(DIR_NONE); } -static bool8 CanMewWalkToCoords(s16 x, s16 y) +// Mew can move to any Tall/Long Grass metatile the player isn't currently on +static bool8 CanMewMoveToCoords(s16 x, s16 y) { if (gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.x == x && gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.y == y) @@ -263,7 +278,8 @@ static bool8 CanMewWalkToCoords(s16 x, s16 y) return MetatileBehavior_IsPokeGrass(MapGridGetMetatileBehaviorAt(x, y)); } -static u8 sub_81D4890(u8 ignoredDir) +// Last ditch effort to move, clear move candidates and try all directions again +static u8 GetValidMewMoveDirection(u8 ignoredDir) { u8 i; u8 count = 0; @@ -272,25 +288,25 @@ static u8 sub_81D4890(u8 ignoredDir) for (i = 0; i < ARRAY_COUNT(sMewDirectionCandidates); i++) sMewDirectionCandidates[i] = DIR_NONE; - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1) == TRUE && ignoredDir != DIR_NORTH) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y - 1) == TRUE && ignoredDir != DIR_NORTH) { sMewDirectionCandidates[count] = DIR_NORTH; count++; } - if (CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y) == TRUE && ignoredDir != DIR_EAST) + if (CanMewMoveToCoords(mew->currentCoords.x + 1, mew->currentCoords.y) == TRUE && ignoredDir != DIR_EAST) { sMewDirectionCandidates[count] = DIR_EAST; count++; } - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1) == TRUE && ignoredDir != DIR_SOUTH) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y + 1) == TRUE && ignoredDir != DIR_SOUTH) { sMewDirectionCandidates[count] = DIR_SOUTH; count++; } - if (CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y) == TRUE && ignoredDir != DIR_WEST) + if (CanMewMoveToCoords(mew->currentCoords.x - 1, mew->currentCoords.y) == TRUE && ignoredDir != DIR_WEST) { sMewDirectionCandidates[count] = DIR_WEST; count++; @@ -340,7 +356,9 @@ bool8 IsMewPlayingHideAndSeek(void) return FALSE; } -bool8 sub_81D4A58(struct ObjectEvent *objectEvent) +// Every 4th step Mew will shake the grass it steps into +// Otherwise its movement leaves grass undisturbed +bool8 ShouldMewShakeGrass(struct ObjectEvent *objectEvent) { if (VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) != 0xFFFF && VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % 4 == 0) @@ -349,22 +367,25 @@ bool8 sub_81D4A58(struct ObjectEvent *objectEvent) return FALSE; } -void sub_81D4A90(void) +void SetMewAboveGrass(void) { s16 x; s16 y; u8 spriteId; struct ObjectEvent *mew = &gObjectEvents[GetMewObjectEventId()]; - mew->invisible = 0; + mew->invisible = FALSE; if (gSpecialVar_0x8004 == 1) { + // For after battle where Mew should still be present (e.g. if ran from battle) mew->fixedPriority = 1; gSprites[mew->spriteId].subspriteMode = SUBSPRITES_IGNORE_PRIORITY; gSprites[mew->spriteId].subpriority = 1; } else { + // Mew emerging from grass when found + // Also do field effect for grass shaking as it emerges VarSet(VAR_FARAWAY_ISLAND_STEP_COUNTER, 0xFFFF); mew->fixedPriority = 1; gSprites[mew->spriteId].subspriteMode = SUBSPRITES_IGNORE_PRIORITY; @@ -377,10 +398,10 @@ void sub_81D4A90(void) x = mew->currentCoords.x; y = mew->currentCoords.y; SetSpritePosToOffsetMapCoords(&x, &y, 8, 8); - sUnknown_0203CF50 = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[15], x, y, gSprites[mew->spriteId].subpriority - 1); - if (sUnknown_0203CF50 != MAX_SPRITES) + sGrassSpriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[15], x, y, gSprites[mew->spriteId].subpriority - 1); + if (sGrassSpriteId != MAX_SPRITES) { - struct Sprite *sprite = &gSprites[sUnknown_0203CF50]; + struct Sprite *sprite = &gSprites[sGrassSpriteId]; sprite->coordOffsetEnabled = 1; sprite->oam.priority = 2; sprite->callback = SpriteCallbackDummy; @@ -388,15 +409,15 @@ void sub_81D4A90(void) } } -void sub_81D4BEC(void) +void DestroyMewEmergingGrassSprite(void) { - if (sUnknown_0203CF50 != MAX_SPRITES) - DestroySprite(&gSprites[sUnknown_0203CF50]); + if (sGrassSpriteId != MAX_SPRITES) + DestroySprite(&gSprites[sGrassSpriteId]); } -static bool8 sub_81D4C14(struct ObjectEvent *mew, u8 index) +static bool8 ShouldMewMoveNorth(struct ObjectEvent *mew, u8 index) { - if (sPlayerToMewDeltaY > 0 && CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) + if (sPlayerToMewDeltaY > 0 && CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) { sMewDirectionCandidates[index] = DIR_NORTH; return TRUE; @@ -405,9 +426,9 @@ static bool8 sub_81D4C14(struct ObjectEvent *mew, u8 index) return FALSE; } -static u8 sub_81D4C58(struct ObjectEvent *mew, u8 index) +static bool8 ShouldMewMoveEast(struct ObjectEvent *mew, u8 index) { - if (sPlayerToMewDeltaX < 0 && CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) + if (sPlayerToMewDeltaX < 0 && CanMewMoveToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) { sMewDirectionCandidates[index] = DIR_EAST; return TRUE; @@ -416,9 +437,9 @@ static u8 sub_81D4C58(struct ObjectEvent *mew, u8 index) return FALSE; } -static u8 sub_81D4C9C(struct ObjectEvent *mew, u8 index) +static bool8 ShouldMewMoveSouth(struct ObjectEvent *mew, u8 index) { - if (sPlayerToMewDeltaY < 0 && CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) + if (sPlayerToMewDeltaY < 0 && CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) { sMewDirectionCandidates[index] = DIR_SOUTH; return TRUE; @@ -427,9 +448,9 @@ static u8 sub_81D4C9C(struct ObjectEvent *mew, u8 index) return FALSE; } -static u8 sub_81D4CE0(struct ObjectEvent *mew, u8 index) +static bool8 ShouldMewMoveWest(struct ObjectEvent *mew, u8 index) { - if (sPlayerToMewDeltaX > 0 && CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) + if (sPlayerToMewDeltaX > 0 && CanMewMoveToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) { sMewDirectionCandidates[index] = DIR_WEST; return TRUE; @@ -438,7 +459,7 @@ static u8 sub_81D4CE0(struct ObjectEvent *mew, u8 index) return FALSE; } -static u8 sub_81D4D24(u8 mod) +static u8 GetRandomMewDirectionCandidate(u8 numDirections) { - return sMewDirectionCandidates[VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % mod]; + return sMewDirectionCandidates[VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % numDirections]; } From ad3de420af4f5daf617103352f5139e17e7b636a Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 21 Jul 2020 17:21:01 -0400 Subject: [PATCH 05/17] Sync flags with pokeruby --- data/maps/LavaridgeTown_HerbShop/scripts.inc | 4 +-- include/constants/flags.h | 34 +++++++------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/data/maps/LavaridgeTown_HerbShop/scripts.inc b/data/maps/LavaridgeTown_HerbShop/scripts.inc index c08d37609c..d98d6ef49f 100644 --- a/data/maps/LavaridgeTown_HerbShop/scripts.inc +++ b/data/maps/LavaridgeTown_HerbShop/scripts.inc @@ -28,12 +28,12 @@ LavaridgeTown_HerbShop_EventScript_ExpertM:: @ 81FE4FC LavaridgeTown_HerbShop_EventScript_OldMan:: @ 81FE505 lock faceplayer - goto_if_set FLFLAG_RECEIVED_CHARCOAL, LavaridgeTown_HerbShop_EventScript_ExplainCharcoal + goto_if_set FLAG_RECEIVED_CHARCOAL, LavaridgeTown_HerbShop_EventScript_ExplainCharcoal msgbox LavaridgeTown_HerbShop_Text_YouveComeToLookAtHerbalMedicine, MSGBOX_DEFAULT giveitem ITEM_CHARCOAL compare VAR_RESULT, FALSE goto_if_eq Common_EventScript_ShowBagIsFull - setflag FLFLAG_RECEIVED_CHARCOAL + setflag FLAG_RECEIVED_CHARCOAL release end diff --git a/include/constants/flags.h b/include/constants/flags.h index e1a88283a5..485dd3058c 100644 --- a/include/constants/flags.h +++ b/include/constants/flags.h @@ -275,7 +275,7 @@ #define FLAG_RECEIVED_DURIN_BERRY 0xFB #define FLAG_RECEIVED_BELUE_BERRY 0xFC #define FLAG_ENABLE_RIVAL_MATCH_CALL 0xFD -#define FLFLAG_RECEIVED_CHARCOAL 0xFE +#define FLAG_RECEIVED_CHARCOAL 0xFE #define FLAG_LATIOS_OR_LATIAS_ROAMING 0xFF #define FLAG_RECEIVED_REPEAT_BALL 0x100 #define FLAG_RECEIVED_OLD_ROD 0x101 @@ -1077,9 +1077,7 @@ #define FLAG_ITEM_ROUTE_120_NUGGET 0x406 #define FLAG_ITEM_ROUTE_120_FULL_HEAL 0x407 #define FLAG_ITEM_ROUTE_123_CALCIUM 0x408 - -#define FLAG_UNUSED_0x409 0x409 // Unused Flag - +#define FLAG_ITEM_ROUTE_123_RARE_CANDY 0x409 // Unused Flag, leftover from R/S. In Emerald this is a hidden item and uses a different flag #define FLAG_ITEM_ROUTE_127_ZINC 0x40A #define FLAG_ITEM_ROUTE_127_CARBOS 0x40B #define FLAG_ITEM_ROUTE_132_RARE_CANDY 0x40C @@ -1171,37 +1169,27 @@ #define FLAG_ITEM_NEW_MAUVILLE_FULL_HEAL 0x462 #define FLAG_ITEM_NEW_MAUVILLE_PARALYZE_HEAL 0x463 #define FLAG_ITEM_AQUA_HIDEOUT_B1F_MASTER_BALL 0x464 - -#define FLAG_UNUSED_0x465 0x465 // Unused Flag -#define FLAG_UNUSED_0x466 0x466 // Unused Flag -#define FLAG_UNUSED_0x467 0x467 // Unused Flag +#define FLAG_ITEM_OLD_MAGMA_HIDEOUT_B1F_MASTER_BALL 0x465 // Unused Flag, leftover from the Ruby Magma hideout +#define FLAG_ITEM_OLD_MAGMA_HIDEOUT_B1F_MAX_ELIXIR 0x466 // Unused Flag, leftover from the Ruby Magma hideout +#define FLAG_ITEM_OLD_MAGMA_HIDEOUT_B2F_NEST_BALL 0x467 // Unused Flag, leftover from the Ruby Magma hideout #define FLAG_UNUSED_0x468 0x468 // Unused Flag - #define FLAG_ITEM_MT_PYRE_2F_ULTRA_BALL 0x469 #define FLAG_ITEM_MT_PYRE_4F_SEA_INCENSE 0x46A #define FLAG_ITEM_SAFARI_ZONE_SOUTH_WEST_MAX_REVIVE 0x46B #define FLAG_ITEM_AQUA_HIDEOUT_B1F_NUGGET 0x46C - -#define FLAG_UNUSED_0x46D 0x46D // Unused Flag - +#define FLAG_ITEM_MOSSDEEP_STEVENS_HOUSE_HM08 0x46D // Unused Flag, leftover from R/S. HM08 is given to the player directly in Emerald #define FLAG_ITEM_ROUTE_119_NUGGET 0x46E #define FLAG_ITEM_ROUTE_104_POTION 0x46F - #define FLAG_UNUSED_0x470 0x470 // Unused Flag - #define FLAG_ITEM_ROUTE_103_PP_UP 0x471 - #define FLAG_UNUSED_0x472 0x472 // Unused Flag - #define FLAG_ITEM_ROUTE_108_STAR_PIECE 0x473 #define FLAG_ITEM_ROUTE_109_POTION 0x474 #define FLAG_ITEM_ROUTE_110_ELIXIR 0x475 #define FLAG_ITEM_ROUTE_111_ELIXIR 0x476 #define FLAG_ITEM_ROUTE_113_HYPER_POTION 0x477 #define FLAG_ITEM_ROUTE_115_HEAL_POWDER 0x478 - #define FLAG_UNUSED_0x479 0x479 // Unused Flag - #define FLAG_ITEM_ROUTE_116_POTION 0x47A #define FLAG_ITEM_ROUTE_119_ELIXIR_2 0x47B #define FLAG_ITEM_ROUTE_120_REVIVE 0x47C @@ -1356,7 +1344,7 @@ #define FLAG_SYS_POKEMON_GET (SYSTEM_FLAGS + 0x0) // FLAG_0x860 #define FLAG_SYS_POKEDEX_GET (SYSTEM_FLAGS + 0x1) #define FLAG_SYS_POKENAV_GET (SYSTEM_FLAGS + 0x2) -#define FLAG_UNUSED_0x863 (SYSTEM_FLAGS + 0x3) +#define FLAG_UNUSED_0x863 (SYSTEM_FLAGS + 0x3) // Unused Flag #define FLAG_SYS_GAME_CLEAR (SYSTEM_FLAGS + 0x4) #define FLAG_SYS_CHAT_USED (SYSTEM_FLAGS + 0x5) #define FLAG_SYS_HIPSTER_MEET (SYSTEM_FLAGS + 0x6) @@ -1373,7 +1361,7 @@ #define NUM_BADGES (1 + FLAG_BADGE08_GET - FLAG_BADGE01_GET) // Towns and Cities -#define FLAG_VISITED_LITTLEROOT_TOWN (SYSTEM_FLAGS + 0xF) +#define FLAG_VISITED_LITTLEROOT_TOWN (SYSTEM_FLAGS + 0xF) #define FLAG_VISITED_OLDALE_TOWN (SYSTEM_FLAGS + 0x10) #define FLAG_VISITED_DEWFORD_TOWN (SYSTEM_FLAGS + 0x11) #define FLAG_VISITED_LAVARIDGE_TOWN (SYSTEM_FLAGS + 0x12) @@ -1418,9 +1406,9 @@ #define FLAG_SYS_MIX_RECORD (SYSTEM_FLAGS + 0x34) #define FLAG_SYS_CLOCK_SET (SYSTEM_FLAGS + 0x35) #define FLAG_SYS_NATIONAL_DEX (SYSTEM_FLAGS + 0x36) -#define FLAG_SYS_UNUSED_CAVE_SHIP (SYSTEM_FLAGS + 0x37) // Unused Flag? -#define FLAG_SYS_UNUSED_CAVE_WONDER (SYSTEM_FLAGS + 0x38) // Unused Flag? -#define FLAG_SYS_UNUSED_CAVE_BATTLE (SYSTEM_FLAGS + 0x39) // Unused Flag? +#define FLAG_SYS_CAVE_SHIP (SYSTEM_FLAGS + 0x37) // Unused Flag, leftover from R/S debug, presumably used by Emerald's debug too +#define FLAG_SYS_CAVE_WONDER (SYSTEM_FLAGS + 0x38) // Unused Flag, same as above +#define FLAG_SYS_CAVE_BATTLE (SYSTEM_FLAGS + 0x39) // Unused Flag, same as above #define FLAG_SYS_SHOAL_TIDE (SYSTEM_FLAGS + 0x3A) #define FLAG_SYS_RIBBON_GET (SYSTEM_FLAGS + 0x3B) From 11178a49db67304bb82287e4c93ef4a36cf5edca Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 27 Jul 2020 12:27:35 +0200 Subject: [PATCH 06/17] Fix undefined behaviour in protect animation gPlttBufferFaded[sprite->data[2] + ++i] = gPlttBufferFaded[sprite->data[2] + i + 1] The above does NOT make it certain that i gets incremented before reading from the right side. Changed it, so the function always increments i first, then reads from pal buffer. --- src/battle_anim_effects_1.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/battle_anim_effects_1.c b/src/battle_anim_effects_1.c index 516c58e557..f4769145d4 100644 --- a/src/battle_anim_effects_1.c +++ b/src/battle_anim_effects_1.c @@ -3967,24 +3967,25 @@ static void AnimProtect(struct Sprite* sprite) static void AnimProtect_Step(struct Sprite *sprite) { - int a; - int i; + int i, savedPal; sprite->data[5] += 96; sprite->pos2.x = -(sprite->data[5] >> 8); if (++sprite->data[1] > 1) { + int id; sprite->data[1] = 0; - a = gPlttBufferFaded[sprite->data[2] + 1]; + savedPal = gPlttBufferFaded[sprite->data[2] + 1]; i = 0; do { - gPlttBufferFaded[sprite->data[2] + ++i] = gPlttBufferFaded[sprite->data[2] + i + 1]; + id = sprite->data[2] + ++i; + gPlttBufferFaded[id] = gPlttBufferFaded[id + 1]; } while (i < 6); - gPlttBufferFaded[sprite->data[2] + 7] = a; + gPlttBufferFaded[sprite->data[2] + 7] = savedPal; } - if (sprite->data[7] > 6 && sprite->data[0] >0 && ++sprite->data[6] > 1) + if (sprite->data[7] > 6 && sprite->data[0] > 0 && ++sprite->data[6] > 1) { sprite->data[6] = 0; sprite->data[7] -= 1; From 5f6e7e2279711f9aab5fe861a76b20732551eebb Mon Sep 17 00:00:00 2001 From: PokeCodec <67983839+PokeCodec@users.noreply.github.com> Date: Mon, 27 Jul 2020 14:59:37 -0400 Subject: [PATCH 07/17] Update secret_base.c --- src/secret_base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/secret_base.c b/src/secret_base.c index 35ac31d4a7..3f69e0419e 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -964,7 +964,7 @@ static void HandleRegistryMenuInput(u8 taskId) data = gTasks[taskId].data; input = ListMenu_ProcessInput(data[5]); - ListMenuGetScrollAndRow((u8)data[5], (u16 *)&data[2], (u16 *)&data[1]); + ListMenuGetScrollAndRow(data[5], (u16 *)&data[2], (u16 *)&data[1]); switch (input) { case LIST_NOTHING_CHOSEN: From 71dc5edf2e590c85b5874f82dde3b418e5769450 Mon Sep 17 00:00:00 2001 From: ExpoSeed <> Date: Mon, 27 Jul 2020 17:10:42 -0500 Subject: [PATCH 08/17] Document some battle_util.c --- include/battle_util.h | 4 ++-- src/battle_script_commands.c | 2 +- src/battle_util.c | 8 ++++---- src/pokemon.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/battle_util.h b/include/battle_util.h index b77fa10ad6..e145a5e9ca 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -52,8 +52,8 @@ void CancelMultiTurnMoves(u8 battlerId); bool8 WasUnableToUseMove(u8 battlerId); void PrepareStringBattle(u16 stringId, u8 battlerId); void ResetSentPokesToOpponentValue(void); -void sub_803F9EC(u8 battlerId); -void sub_803FA70(u8 battlerId); +void OpponentSwitchInResetSentPokesToOpponent(u8 battlerId); +void UpdateSentPokesToOpponentValue(u8 battlerId); void BattleScriptPush(const u8* bsPtr); void BattleScriptPushCursor(void); void BattleScriptPop(void); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 4e0e087b60..994d356258 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5471,7 +5471,7 @@ static void Cmd_switchineffects(void) s32 i; gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]); - sub_803FA70(gActiveBattler); + UpdateSentPokesToOpponentValue(gActiveBattler); gHitMarker &= ~(HITMARKER_FAINTED(gActiveBattler)); gSpecialStatuses[gActiveBattler].flag40 = 0; diff --git a/src/battle_util.c b/src/battle_util.c index 9cc2252b68..a579f7edd6 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -259,7 +259,7 @@ void ResetSentPokesToOpponentValue(void) gSentPokesToOpponent[(i & BIT_FLANK) >> 1] = bits; } -void sub_803F9EC(u8 battler) +void OpponentSwitchInResetSentPokesToOpponent(u8 battler) { s32 i = 0; u32 bits = 0; @@ -279,11 +279,11 @@ void sub_803F9EC(u8 battler) } } -void sub_803FA70(u8 battler) +void UpdateSentPokesToOpponentValue(u8 battler) { if (GetBattlerSide(battler) == B_SIDE_OPPONENT) { - sub_803F9EC(battler); + OpponentSwitchInResetSentPokesToOpponent(battler); } else { @@ -1250,7 +1250,7 @@ bool8 HandleFaintedMonActions(void) gBattleStruct->faintedActionsState = 3; break; case 2: - sub_803F9EC(gBattlerFainted); + OpponentSwitchInResetSentPokesToOpponent(gBattlerFainted); if (++gBattleStruct->faintedActionsBattlerId == gBattlersCount) gBattleStruct->faintedActionsState = 3; else diff --git a/src/pokemon.c b/src/pokemon.c index 80e93c5685..b26f2f412a 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -4628,7 +4628,7 @@ void CopyPlayerPartyMonToBattleData(u8 battlerId, u8 partyIndex) gBattleMons[battlerId].statStages[i] = 6; gBattleMons[battlerId].status2 = 0; - sub_803FA70(battlerId); + UpdateSentPokesToOpponentValue(battlerId); ClearTemporarySpeciesSpriteData(battlerId, FALSE); } From fb6f859eddd63cd59e8fabd53e47ca9080c63f3e Mon Sep 17 00:00:00 2001 From: PokeCodec Date: Mon, 27 Jul 2020 19:17:34 -0400 Subject: [PATCH 09/17] semicolon --- src/AgbRfu_LinkManager.c | 2 +- src/battle_anim_psychic.c | 2 +- src/battle_anim_utility_funcs.c | 2 +- src/digit_obj_util.c | 2 +- src/mirage_tower.c | 2 +- src/save_failed_screen.c | 2 +- tools/gbagfx/gfx.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/AgbRfu_LinkManager.c b/src/AgbRfu_LinkManager.c index e4127ee090..f6ebcc7265 100644 --- a/src/AgbRfu_LinkManager.c +++ b/src/AgbRfu_LinkManager.c @@ -918,7 +918,7 @@ static void rfu_LMAN_REQ_callback(u16 reqCommandId, u16 reqResult) { lman.reserveDisconnectSlot_flag = 0; lman.acceptCount = 0; - lman.acceptSlot_flag = 0;; + lman.acceptSlot_flag = 0; lman.parent_child = MODE_NEUTRAL; rfu_LMAN_managerChangeAgbClockMaster(); if (reqCommandId == ID_STOP_MODE_REQ) diff --git a/src/battle_anim_psychic.c b/src/battle_anim_psychic.c index 7918698fc0..25340f9c6a 100644 --- a/src/battle_anim_psychic.c +++ b/src/battle_anim_psychic.c @@ -1101,7 +1101,7 @@ static void AnimTask_TransparentCloneGrowAndShrink_Step(u8 taskId) break; case 1: task->data[1] -= 4; - task->data[2] = 256 - (gSineTable[task->data[1]] >> 1);; + task->data[2] = 256 - (gSineTable[task->data[1]] >> 1); SetSpriteRotScale(task->data[15], task->data[2], task->data[2], 0); SetBattlerSpriteYOffsetFromOtherYScale(task->data[15], task->data[13]); if (task->data[1] == 0) diff --git a/src/battle_anim_utility_funcs.c b/src/battle_anim_utility_funcs.c index dcef7d4830..bca669cc26 100644 --- a/src/battle_anim_utility_funcs.c +++ b/src/battle_anim_utility_funcs.c @@ -569,7 +569,7 @@ static void sub_81172EC(u8 taskId) if (gTasks[taskId].data[12] == 0) { sub_80A477C(0); - gTasks[taskId].data[15]++;; + gTasks[taskId].data[15]++; } } break; diff --git a/src/digit_obj_util.c b/src/digit_obj_util.c index fe5d49e69d..f887dafb95 100644 --- a/src/digit_obj_util.c +++ b/src/digit_obj_util.c @@ -33,7 +33,7 @@ struct DigitPrinterAlloc }; // this file's functions -static u8 GetFirstOamId(u8 oamCount);; +static u8 GetFirstOamId(u8 oamCount); static void CopyWorkToOam(struct DigitPrinter *objWork); static void DrawNumObjsLeadingZeros(struct DigitPrinter *objWork, s32 num, bool32 sign); static void DrawNumObjsMinusInFront(struct DigitPrinter *objWork, s32 num, bool32 sign); diff --git a/src/mirage_tower.c b/src/mirage_tower.c index bdddbdbe64..3f3dc1ef85 100644 --- a/src/mirage_tower.c +++ b/src/mirage_tower.c @@ -690,7 +690,7 @@ static void DoFossilFallAndSink(u8 taskId) if (gSprites[sUnknown_0203CF0C->spriteId].callback != SpriteCallbackDummy) return; DestroySprite(&gSprites[sUnknown_0203CF0C->spriteId]); - FREE_AND_SET_NULL(sUnknown_0203CF0C->unkC);; + FREE_AND_SET_NULL(sUnknown_0203CF0C->unkC); FREE_AND_SET_NULL(sUnknown_0203CF0C->frameImage); FREE_AND_SET_NULL(sUnknown_0203CF0C->frameImageTiles); FREE_AND_SET_NULL(sUnknown_0203CF0C); diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index a2a2acc8d6..7c824e82dd 100644 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -349,7 +349,7 @@ static void VBlankCB_UpdateClockGraphics(void) gMain.oamBuffer[0] = sClockOamData; gMain.oamBuffer[0].x = 112; - gMain.oamBuffer[0].y = (CLOCK_WIN_TOP + 1) * 8;; + gMain.oamBuffer[0].y = (CLOCK_WIN_TOP + 1) * 8; if (gSaveFailedClockInfo[CLOCK_RUNNING] != FALSE) { diff --git a/tools/gbagfx/gfx.c b/tools/gbagfx/gfx.c index 8d959465f7..4e85953fdc 100644 --- a/tools/gbagfx/gfx.c +++ b/tools/gbagfx/gfx.c @@ -282,7 +282,7 @@ static void HflipTile(unsigned char * tile, int bitDepth) for (i = 0; i < 8; i++) { SWAP_NYBBLES(&tile[4 * i + 0], &tile[4 * i + 3]); - SWAP_NYBBLES(&tile[4 * i + 1], &tile[4 * i + 2]);; + SWAP_NYBBLES(&tile[4 * i + 1], &tile[4 * i + 2]); } break; case 8: From b401e2eb86dba8a48c12fec75c2201de7fb1ec63 Mon Sep 17 00:00:00 2001 From: ExpoSeed <> Date: Mon, 27 Jul 2020 21:22:16 -0500 Subject: [PATCH 10/17] Fix naming style of function --- include/battle_util.h | 2 +- src/battle_util.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/battle_util.h b/include/battle_util.h index e145a5e9ca..157ba8eb6d 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -52,7 +52,7 @@ void CancelMultiTurnMoves(u8 battlerId); bool8 WasUnableToUseMove(u8 battlerId); void PrepareStringBattle(u16 stringId, u8 battlerId); void ResetSentPokesToOpponentValue(void); -void OpponentSwitchInResetSentPokesToOpponent(u8 battlerId); +void OpponentSwitchInResetSentPokesToOpponentValue(u8 battlerId); void UpdateSentPokesToOpponentValue(u8 battlerId); void BattleScriptPush(const u8* bsPtr); void BattleScriptPushCursor(void); diff --git a/src/battle_util.c b/src/battle_util.c index a579f7edd6..89fe95fbc4 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -259,7 +259,7 @@ void ResetSentPokesToOpponentValue(void) gSentPokesToOpponent[(i & BIT_FLANK) >> 1] = bits; } -void OpponentSwitchInResetSentPokesToOpponent(u8 battler) +void OpponentSwitchInResetSentPokesToOpponentValue(u8 battler) { s32 i = 0; u32 bits = 0; @@ -283,7 +283,7 @@ void UpdateSentPokesToOpponentValue(u8 battler) { if (GetBattlerSide(battler) == B_SIDE_OPPONENT) { - OpponentSwitchInResetSentPokesToOpponent(battler); + OpponentSwitchInResetSentPokesToOpponentValue(battler); } else { @@ -1250,7 +1250,7 @@ bool8 HandleFaintedMonActions(void) gBattleStruct->faintedActionsState = 3; break; case 2: - OpponentSwitchInResetSentPokesToOpponent(gBattlerFainted); + OpponentSwitchInResetSentPokesToOpponentValue(gBattlerFainted); if (++gBattleStruct->faintedActionsBattlerId == gBattlersCount) gBattleStruct->faintedActionsState = 3; else From ebcb982e16a0fd6b22185d159234495c44a15874 Mon Sep 17 00:00:00 2001 From: PokeCodec Date: Sun, 19 Jul 2020 15:57:20 -0400 Subject: [PATCH 11/17] Change signedness and add casts to avoid implicit conversion warnings --- src/agb_flash.c | 28 +++++++++++++-------------- src/battle_anim_bug.c | 38 +++++++++++++------------------------ src/battle_anim_effects_1.c | 2 +- src/berry.c | 2 +- src/berry_blender.c | 10 +++++----- src/easy_chat.c | 18 +++++++++--------- src/event_object_movement.c | 6 +++--- src/field_effect.c | 2 +- src/hall_of_fame.c | 4 ++-- src/item_use.c | 2 +- src/list_menu.c | 10 +++++----- src/mirage_tower.c | 7 +++---- src/overworld.c | 2 +- src/party_menu.c | 8 ++++---- src/player_pc.c | 14 +++++++------- src/pokedex.c | 6 +++--- src/roulette.c | 32 +++++++++++++++---------------- src/scrcmd.c | 4 ++-- src/secret_base.c | 8 ++++---- src/slot_machine.c | 2 +- src/start_menu.c | 2 +- src/trainer_see.c | 4 ++-- 22 files changed, 99 insertions(+), 112 deletions(-) diff --git a/src/agb_flash.c b/src/agb_flash.c index 1ad9e47ecb..0045219c41 100644 --- a/src/agb_flash.c +++ b/src/agb_flash.c @@ -41,7 +41,7 @@ u16 ReadFlashId(void) u8 (*readFlash1)(u8 *); SetReadFlash1(readFlash1Buffer); - readFlash1 = (u8 (*)(u8 *))((s32)readFlash1Buffer + 1); + readFlash1 = (u8 (*)(u8 *))((uintptr_t)readFlash1Buffer + 1); // Enter ID mode. FLASH_WRITE(0x5555, 0xAA); @@ -113,12 +113,12 @@ void SetReadFlash1(u16 *dest) u16 *src; u16 i; - PollFlashStatus = (u8 (*)(u8 *))((s32)dest + 1); + PollFlashStatus = (u8 (*)(u8 *))((uintptr_t)dest + 1); src = (u16 *)ReadFlash1; - src = (u16 *)((s32)src ^ 1); + src = (u16 *)((uintptr_t)src ^ 1); - i = ((s32)SetReadFlash1 - (s32)ReadFlash1) >> 1; + i = ((uintptr_t)SetReadFlash1 - (uintptr_t)ReadFlash1) >> 1; while (i != 0) { @@ -154,10 +154,10 @@ void ReadFlash(u16 sectorNum, u32 offset, u8 *dest, u32 size) } funcSrc = (u16 *)ReadFlash_Core; - funcSrc = (u16 *)((s32)funcSrc ^ 1); + funcSrc = (u16 *)((uintptr_t)funcSrc ^ 1); funcDest = readFlash_Core_Buffer; - i = ((s32)ReadFlash - (s32)ReadFlash_Core) >> 1; + i = ((uintptr_t)ReadFlash - (uintptr_t)ReadFlash_Core) >> 1; while (i != 0) { @@ -165,7 +165,7 @@ void ReadFlash(u16 sectorNum, u32 offset, u8 *dest, u32 size) i--; } - readFlash_Core = (void (*)(vu8 *, u8 *, u32))((s32)readFlash_Core_Buffer + 1); + readFlash_Core = (void (*)(vu8 *, u8 *, u32))((uintptr_t)readFlash_Core_Buffer + 1); src = FLASH_BASE + (sectorNum << gFlash->sector.shift) + offset; @@ -202,10 +202,10 @@ u32 VerifyFlashSector(u16 sectorNum, u8 *src) } funcSrc = (u16 *)VerifyFlashSector_Core; - funcSrc = (u16 *)((s32)funcSrc ^ 1); + funcSrc = (u16 *)((uintptr_t)funcSrc ^ 1); funcDest = verifyFlashSector_Core_Buffer; - i = ((s32)VerifyFlashSector - (s32)VerifyFlashSector_Core) >> 1; + i = (u16)(((uintptr_t)VerifyFlashSector - (uintptr_t)VerifyFlashSector_Core) >> 1); while (i != 0) { @@ -213,7 +213,7 @@ u32 VerifyFlashSector(u16 sectorNum, u8 *src) i--; } - verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((s32)verifyFlashSector_Core_Buffer + 1); + verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((uintptr_t)verifyFlashSector_Core_Buffer + 1); tgt = FLASH_BASE + (sectorNum << gFlash->sector.shift); size = gFlash->sector.size; @@ -239,10 +239,10 @@ u32 VerifyFlashSectorNBytes(u16 sectorNum, u8 *src, u32 n) REG_WAITCNT = (REG_WAITCNT & ~WAITCNT_SRAM_MASK) | WAITCNT_SRAM_8; funcSrc = (u16 *)VerifyFlashSector_Core; - funcSrc = (u16 *)((s32)funcSrc ^ 1); + funcSrc = (u16 *)((uintptr_t)funcSrc ^ 1); funcDest = verifyFlashSector_Core_Buffer; - i = ((s32)VerifyFlashSector - (s32)VerifyFlashSector_Core) >> 1; + i = (u16)(((uintptr_t)VerifyFlashSector - (uintptr_t)VerifyFlashSector_Core) >> 1); while (i != 0) { @@ -250,7 +250,7 @@ u32 VerifyFlashSectorNBytes(u16 sectorNum, u8 *src, u32 n) i--; } - verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((s32)verifyFlashSector_Core_Buffer + 1); + verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((uintptr_t)verifyFlashSector_Core_Buffer + 1); tgt = FLASH_BASE + (sectorNum << gFlash->sector.shift); @@ -293,4 +293,4 @@ u32 ProgramFlashSectorAndVerifyNBytes(u16 sectorNum, u8 *src, u32 n) } return result; -} +} \ No newline at end of file diff --git a/src/battle_anim_bug.c b/src/battle_anim_bug.c index ea3df80986..5e8a8b2a76 100644 --- a/src/battle_anim_bug.c +++ b/src/battle_anim_bug.c @@ -372,14 +372,11 @@ static void AnimTranslateStinger(struct Sprite *sprite) { gBattleAnimArgs[2] = -gBattleAnimArgs[2]; } - else + else if (GetBattlerSide(gBattleAnimAttacker)) { - if (GetBattlerSide(gBattleAnimAttacker)) - { - gBattleAnimArgs[2] = -gBattleAnimArgs[2]; - gBattleAnimArgs[1] = -gBattleAnimArgs[1]; - gBattleAnimArgs[3] = -gBattleAnimArgs[3]; - } + gBattleAnimArgs[2] = -gBattleAnimArgs[2]; + gBattleAnimArgs[1] = -gBattleAnimArgs[1]; + gBattleAnimArgs[3] = -gBattleAnimArgs[3]; } if (!IsContest() && GetBattlerSide(gBattleAnimAttacker) == GetBattlerSide(gBattleAnimTarget)) @@ -387,13 +384,8 @@ static void AnimTranslateStinger(struct Sprite *sprite) if (GetBattlerPosition(gBattleAnimTarget) == B_POSITION_PLAYER_LEFT || GetBattlerPosition(gBattleAnimTarget) == B_POSITION_OPPONENT_LEFT) { - s16 temp1, temp2; - - temp1 = gBattleAnimArgs[2]; - gBattleAnimArgs[2] = -temp1; - - temp2 = gBattleAnimArgs[0]; - gBattleAnimArgs[0] = -temp2; + gBattleAnimArgs[2] *= -1; + gBattleAnimArgs[0] *= -1; } } @@ -448,28 +440,24 @@ static void AnimMissileArc_Step(struct Sprite *sprite) else { s16 tempData[8]; - u16 *data = sprite->data; - u16 x1 = sprite->pos1.x; - s16 x2 = sprite->pos2.x; - u16 y1 = sprite->pos1.y; - s16 y2 = sprite->pos2.y; + s16 xpos, ypos; int i; for (i = 0; i < 8; i++) - tempData[i] = data[i]; + tempData[i] = sprite->data[i]; - x2 += x1; - y2 += y1; + xpos = sprite->pos1.x + sprite->pos2.x; + ypos = sprite->pos1.y + sprite->pos2.y; if (!TranslateAnimHorizontalArc(sprite)) { - u16 rotation = ArcTan2Neg(sprite->pos1.x + sprite->pos2.x - x2, - sprite->pos1.y + sprite->pos2.y - y2); + u16 rotation = ArcTan2Neg(sprite->pos1.x + sprite->pos2.x - xpos, //Isn't this zero lol + sprite->pos1.y + sprite->pos2.y - ypos); rotation += 0xC000; TrySetSpriteRotScale(sprite, FALSE, 0x100, 0x100, rotation); for (i = 0; i < 8; i++) - data[i] = tempData[i]; + sprite->data[i] = tempData[i]; } } } diff --git a/src/battle_anim_effects_1.c b/src/battle_anim_effects_1.c index f93b2a5c48..e9930eeef0 100644 --- a/src/battle_anim_effects_1.c +++ b/src/battle_anim_effects_1.c @@ -4445,7 +4445,7 @@ static void AnimBowMon_Step1_Callback(struct Sprite* sprite) { sprite->data[3] = gBattlerSpriteIds[gBattleAnimAttacker]; PrepareBattlerSpriteForRotScale(sprite->data[3], ST_OAM_OBJ_NORMAL); - sprite->data[4] = (sprite->data[6] = GetBattlerSide(gBattleAnimAttacker)) ? 0x300 : 0xFFFFFD00; + sprite->data[4] = (sprite->data[6] = GetBattlerSide(gBattleAnimAttacker)) ? 0x300 : (s16)0xFFFFFD00; sprite->data[5] = 0; } diff --git a/src/berry.c b/src/berry.c index 98264f37b8..d70e8c3537 100644 --- a/src/berry.c +++ b/src/berry.c @@ -1331,7 +1331,7 @@ void ResetBerryTreeSparkleFlags(void) s16 bottom; int i; - GetCameraCoords(&cam_left, &cam_top); + GetCameraCoords((u16*)&cam_left, (u16*)&cam_top); left = cam_left; top = cam_top + 3; right = cam_left + 14; diff --git a/src/berry_blender.c b/src/berry_blender.c index a2a96c0892..de3cc62759 100644 --- a/src/berry_blender.c +++ b/src/berry_blender.c @@ -116,8 +116,8 @@ struct BerryBlenderData u16 field_116; u16 field_118; u16 field_11A; - u16 bg_X; - u16 bg_Y; + s16 bg_X; + s16 bg_Y; u8 field_120[3]; u8 field_123; u16 scores[BLENDER_MAX_PLAYERS][BLENDER_SCORES_NO]; @@ -3166,13 +3166,13 @@ static void sub_80832E8(s16* a0) static void sub_808330C(void) { - sub_80832E8(&sBerryBlenderData->bg_X); - sub_80832E8(&sBerryBlenderData->bg_Y); + sub_80832E8((s16 *)&sBerryBlenderData->bg_X); + sub_80832E8((s16 *)&sBerryBlenderData->bg_Y); } static void sub_8083334(s16* a0, u16 a1) { - s32 var; + u8 var; if (a1 < 10) var = 16; diff --git a/src/easy_chat.c b/src/easy_chat.c index 44a7b90c14..c839c0070d 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -2537,7 +2537,7 @@ u8 sub_811BBBC(void) return sEasyChatScreen->unk_0c; } -void sub_811BBC8(u8 *arg0, u8 *arg1) +static void sub_811BBC8(s8 *arg0, s8 *arg1) { *arg0 = sEasyChatScreen->unk_10; *arg1 = sEasyChatScreen->unk_11; @@ -4529,18 +4529,18 @@ static void sub_811E30C(void) x = var0 * 13; x = x * 8 + 28; y = var1 * 16 + 96; - sub_811E34C(x, y); + sub_811E34C((u8)x, (u8)y); } static void sub_811E34C(u8 x, u8 y) { - if (sUnknown_0203A11C->unk2E4) - { - sUnknown_0203A11C->unk2E4->pos1.x = x; - sUnknown_0203A11C->unk2E4->pos1.y = y; - sUnknown_0203A11C->unk2E4->pos2.x = 0; - sUnknown_0203A11C->unk2E4->data[0] = 0; - } + if (!sUnknown_0203A11C->unk2E4) + return; + + sUnknown_0203A11C->unk2E4->pos1.x = (s16)x; + sUnknown_0203A11C->unk2E4->pos1.y = (s16)y; + sUnknown_0203A11C->unk2E4->pos2.x = 0; + sUnknown_0203A11C->unk2E4->data[0] = 0; } static void sub_811E380(void) diff --git a/src/event_object_movement.c b/src/event_object_movement.c index de55362407..76331c2b14 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -8950,7 +8950,7 @@ void CreateLevitateMovementTask(struct ObjectEvent *objectEvent) u8 taskId = CreateTask(ApplyLevitateMovement, 0xFF); struct Task *task = &gTasks[taskId]; - StoreWordInTwoHalfwords(&task->data[0], (u32)objectEvent); + StoreWordInTwoHalfwords((u16 *)&task->data[0], (u32)objectEvent); objectEvent->warpArrowSpriteId = taskId; task->data[3] = 0xFFFF; } @@ -8961,7 +8961,7 @@ static void ApplyLevitateMovement(u8 taskId) struct Sprite *sprite; struct Task *task = &gTasks[taskId]; - LoadWordFromTwoHalfwords(&task->data[0], (u32 *)&objectEvent); // load the map object pointer. + LoadWordFromTwoHalfwords((u16 *)&task->data[0], (u32 *)&objectEvent); // load the map object pointer. sprite = &gSprites[objectEvent->spriteId]; if(!(task->data[2] & 0x3)) @@ -8978,7 +8978,7 @@ void DestroyExtraMovementTask(u8 taskId) struct ObjectEvent *objectEvent; struct Task *task = &gTasks[taskId]; - LoadWordFromTwoHalfwords(&task->data[0], (u32 *)&objectEvent); // unused objectEvent + LoadWordFromTwoHalfwords((u16 *)&task->data[0], (u32 *)&objectEvent); // unused objectEvent DestroyTask(taskId); } diff --git a/src/field_effect.c b/src/field_effect.c index 07579f55d5..bc1e6f134d 100644 --- a/src/field_effect.c +++ b/src/field_effect.c @@ -2501,7 +2501,7 @@ static void sub_80B8584(struct Task *task) { task->data[11] = REG_WININ; task->data[12] = REG_WINOUT; - StoreWordInTwoHalfwords(&task->data[13], (u32)gMain.vblankCallback); + StoreWordInTwoHalfwords((u16 *)&task->data[13], (u32)gMain.vblankCallback); task->data[1] = 0xf0f1; task->data[2] = 0x5051; task->data[3] = 0x3f; diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index bf9850deca..8e47c1e3ae 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -612,7 +612,7 @@ static void Task_Hof_PrintMonInfoAfterAnimating(u8 taskId) static void Task_Hof_TryDisplayAnotherMon(u8 taskId) { - u16 currPokeID = gTasks[taskId].tDisplayedMonId; + u16 currPokeID = (u16)gTasks[taskId].tDisplayedMonId; struct HallofFameMon* currMon = &sHofMonPtr->mon[currPokeID]; if (gTasks[taskId].tFrameCount != 0) @@ -1483,7 +1483,7 @@ static void UpdateDomeConfetti(struct ConfettiUtil *util) static void Task_DoDomeConfetti(u8 taskId) { u32 id = 0; - u16 *data = gTasks[taskId].data; + u16 *data = (u16 *)gTasks[taskId].data; switch (tState) { diff --git a/src/item_use.c b/src/item_use.c index 0aae441c8b..fa3f130810 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -721,7 +721,7 @@ static void ItemUseOnFieldCB_WailmerPailBerry(u8 taskId) static bool8 TryToWaterSudowoodo(void) { - u16 x, y; + s16 x, y; u8 z; u8 objId; GetXYCoordsOneStepInFrontOfPlayer(&x, &y); diff --git a/src/list_menu.c b/src/list_menu.c index ddcad0fe9c..ebf02bab65 100644 --- a/src/list_menu.c +++ b/src/list_menu.c @@ -1257,17 +1257,17 @@ void ListMenuSetUpRedOutlineCursorSpriteOamTable(u16 rowWidth, u16 rowHeight, st s32 i, j, id = 0; subsprites[id] = sSubsprite_RedOutline1; - subsprites[id].x = 136; - subsprites[id].y = 136; + subsprites[id].x = -120; + subsprites[id].y = -120; id++; subsprites[id] = sSubsprite_RedOutline2; subsprites[id].x = rowWidth + 128; - subsprites[id].y = 136; + subsprites[id].y = -120; id++; subsprites[id] = sSubsprite_RedOutline7; - subsprites[id].x = 136; + subsprites[id].x = -120; subsprites[id].y = rowHeight + 128; id++; @@ -1297,7 +1297,7 @@ void ListMenuSetUpRedOutlineCursorSpriteOamTable(u16 rowWidth, u16 rowHeight, st for (j = 8; j < rowHeight - 8; j += 8) { subsprites[id] = sSubsprite_RedOutline4; - subsprites[id].x = 136; + subsprites[id].x = -120; subsprites[id].y = j - 120; id++; diff --git a/src/mirage_tower.c b/src/mirage_tower.c index e2f5cefb78..bdddbdbe64 100644 --- a/src/mirage_tower.c +++ b/src/mirage_tower.c @@ -168,7 +168,7 @@ const struct PulseBlendSettings gMirageTowerPulseBlendSettings = { .numColors = 15, .delay = 5, .numFadeCycles = -1, - .maxBlendCoeff = 11, + .maxBlendCoeff = -5, .fadeType = 1, .restorePaletteOnUnload = FALSE, .unk7_7 = 1, @@ -412,10 +412,9 @@ void DoMirageTowerCeilingCrumble(void) static void WaitCeilingCrumble(u8 taskId) { - u16 *data = gTasks[taskId].data; - data[1]++; + u16 *data = (u16 *)gTasks[taskId].data; // Either wait 1000 frames, or until all 16 crumble sprites and the one screen-shake task are completed. - if (data[1] == 1000 || data[0] == 17) + if (++data[1] == 1000 || data[0] == 17) gTasks[taskId].func = FinishCeilingCrumbleTask; } diff --git a/src/overworld.c b/src/overworld.c index ea0d633bcf..6b8fd232e6 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -3212,7 +3212,7 @@ static void SpriteCB_LinkPlayer(struct Sprite *sprite) SetObjectSubpriorityByZCoord(objEvent->previousElevation, sprite, 1); sprite->oam.priority = ZCoordToPriority(objEvent->previousElevation); - if (!linkPlayerObjEvent->movementMode != MOVEMENT_MODE_FREE) + if (linkPlayerObjEvent->movementMode == MOVEMENT_MODE_FREE) StartSpriteAnim(sprite, GetFaceDirectionAnimNum(objEvent->range.as_byte)); else StartSpriteAnimIfDifferent(sprite, GetMoveDirectionAnimNum(objEvent->range.as_byte)); diff --git a/src/party_menu.c b/src/party_menu.c index d5bc6dfb63..6a38d90989 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -1862,7 +1862,7 @@ u8 GetMonAilment(struct Pokemon *mon) static void SetPartyMonsAllowedInMinigame(void) { - u16 *ptr; + s16 *ptr; if (gPartyMenu.menuType == PARTY_MENU_TYPE_MINIGAME) { @@ -4951,9 +4951,9 @@ static void Task_DisplayLevelUpStatsPg2(u8 taskId) static void DisplayLevelUpStatsPg1(u8 taskId) { - s16 *arrayPtr = sPartyMenuInternal->data; + u16 *arrayPtr = (u16*)sPartyMenuInternal->data; - arrayPtr[12] = CreateLevelUpStatsWindow(); + arrayPtr[12] = (u16)CreateLevelUpStatsWindow(); DrawLevelUpWindowPg1(arrayPtr[12], arrayPtr, &arrayPtr[6], TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY, TEXT_COLOR_LIGHT_GREY); CopyWindowToVram(arrayPtr[12], 2); ScheduleBgCopyTilemapToVram(2); @@ -4961,7 +4961,7 @@ static void DisplayLevelUpStatsPg1(u8 taskId) static void DisplayLevelUpStatsPg2(u8 taskId) { - s16 *arrayPtr = sPartyMenuInternal->data; + u16 *arrayPtr = (u16 *)sPartyMenuInternal->data; DrawLevelUpWindowPg2(arrayPtr[12], &arrayPtr[6], TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY, TEXT_COLOR_LIGHT_GREY); CopyWindowToVram(arrayPtr[12], 2); diff --git a/src/player_pc.c b/src/player_pc.c index fc0bd9f4c8..2010d84f85 100644 --- a/src/player_pc.c +++ b/src/player_pc.c @@ -327,7 +327,7 @@ void PlayerPC(void) static void InitPlayerPCMenu(u8 taskId) { - u16 *data; + s16 *data; struct WindowTemplate windowTemplate; data = gTasks[taskId].data; @@ -346,7 +346,7 @@ static void InitPlayerPCMenu(u8 taskId) static void PlayerPCProcessMenuInput(u8 taskId) { - u16 *data; + s16 *data; s8 inputOptionId; data = gTasks[taskId].data; @@ -435,7 +435,7 @@ static void PlayerPC_TurnOff(u8 taskId) static void InitItemStorageMenu(u8 taskId, u8 var) { - u16 *data; + s16 *data; struct WindowTemplate windowTemplate; data = gTasks[taskId].data; @@ -548,7 +548,7 @@ static void ItemStorage_Toss(u8 taskId) static void ItemStorage_WithdrawToss_Helper(u8 taskId, bool8 toss) { - u16 *data = gTasks[taskId].data; + s16 *data = gTasks[taskId].data; data[3] = toss; sub_816B4DC(taskId); @@ -581,9 +581,9 @@ static void ItemStorage_SetItemAndMailCount(u8 taskId) static void sub_816B4DC(u8 taskId) { - u16 *data = gTasks[taskId].data; + u16 *data = (u16 *)gTasks[taskId].data; - ClearStdWindowAndFrameToTransparent(data[4], FALSE); + ClearStdWindowAndFrameToTransparent((u8)data[4], FALSE); ClearWindowTilemap(data[4]); RemoveWindow(data[4]); ScheduleBgCopyTilemapToVram(0); @@ -1380,7 +1380,7 @@ static void ItemStorage_DoItemToss(u8 taskId) data = gTasks[taskId].data; b = (playerPCItemPageInfo.cursorPos + playerPCItemPageInfo.itemsAbove); - if (!ItemId_GetImportance(gSaveBlock1Ptr->pcItems[b].itemId)) + if (ItemId_GetImportance(gSaveBlock1Ptr->pcItems[b].itemId) == 0) { CopyItemName(gSaveBlock1Ptr->pcItems[b].itemId, gStringVar1); ConvertIntToDecimalStringN(gStringVar2, data[2], STR_CONV_MODE_LEFT_ALIGN, 3); diff --git a/src/pokedex.c b/src/pokedex.c index 0541f3f2e6..777cc52cd6 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -5117,9 +5117,9 @@ static void Task_SelectSearchMenuItem(u8 taskId) u16 *scrollOffset; DrawOrEraseSearchParameterBox(FALSE); - menuItem = gTasks[taskId].tMenuItem; - cursorPos = &gTasks[taskId].data[sSearchOptions[menuItem].taskDataCursorPos]; - scrollOffset = &gTasks[taskId].data[sSearchOptions[menuItem].taskDataScrollOffset]; + menuItem = (u16)gTasks[taskId].tMenuItem; + cursorPos = (u16*)&gTasks[taskId].data[sSearchOptions[menuItem].taskDataCursorPos]; + scrollOffset = (u16*)&gTasks[taskId].data[sSearchOptions[menuItem].taskDataScrollOffset]; gTasks[taskId].tCursorPos = *cursorPos; gTasks[taskId].tScrollOffset = *scrollOffset; PrintSearchParameterText(taskId); diff --git a/src/roulette.c b/src/roulette.c index 58e120cb50..f55736a969 100644 --- a/src/roulette.c +++ b/src/roulette.c @@ -633,7 +633,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -643,7 +643,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -653,7 +653,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -663,7 +663,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -673,7 +673,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -683,7 +683,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -693,7 +693,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -703,7 +703,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -713,7 +713,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -723,7 +723,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -733,7 +733,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -743,7 +743,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 1, .var06 = 0xFF, .var07_0 = 8, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -753,7 +753,7 @@ static const struct UnkStruct1 gUnknown_085B6388[] = .var05 = 10, .var06 = 0xFF, .var07_0 = 14, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, }; @@ -767,7 +767,7 @@ static const struct UnkStruct1 gUnknown_085B63F0[] = .var05 = 30, .var06 = 0xFF, .var07_0 = 14, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -777,7 +777,7 @@ static const struct UnkStruct1 gUnknown_085B63F0[] = .var05 = 30, .var06 = 0xFF, .var07_0 = 14, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 }, { @@ -787,7 +787,7 @@ static const struct UnkStruct1 gUnknown_085B63F0[] = .var05 = 30, .var06 = 0xFF, .var07_0 = 14, - .var07_5 = 2, + .var07_5 = -2, .var07_7 = 0 } }; diff --git a/src/scrcmd.c b/src/scrcmd.c index 4a7f4ea735..2a6abf17e1 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -788,8 +788,8 @@ bool8 ScrCmd_warphole(struct ScriptContext *ctx) { u8 mapGroup = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx); - u16 x; - u16 y; + s16 x; + s16 y; PlayerGetDestCoords(&x, &y); if (mapGroup == 0xFF && mapNum == 0xFF) diff --git a/src/secret_base.c b/src/secret_base.c index 83626710fc..35ac31d4a7 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -964,7 +964,7 @@ static void HandleRegistryMenuInput(u8 taskId) data = gTasks[taskId].data; input = ListMenu_ProcessInput(data[5]); - ListMenuGetScrollAndRow(data[5], &data[2], &data[1]); + ListMenuGetScrollAndRow((u8)data[5], (u16 *)&data[2], (u16 *)&data[1]); switch (input) { case LIST_NOTHING_CHOSEN: @@ -1045,10 +1045,10 @@ void DeleteRegistry_Yes_Callback(u8 taskId) { s16 *data = gTasks[taskId].data; ClearDialogWindowAndFrame(0, 0); - DestroyListMenuTask(data[5], &data[2], &data[1]); + DestroyListMenuTask((u8)data[5], (u16 *)&data[2], (u16 *)&data[1]); gSaveBlock1Ptr->secretBases[data[4]].registryStatus = 0; BuildRegistryMenuItems(taskId); - sub_812225C(&data[2], &data[1], data[3], data[0]); + sub_812225C((u16 *)&data[2], (u16 *)&data[1], (u16)data[3], (u16)data[0]); FinalizeRegistryMenu(taskId); gTasks[taskId].func = HandleRegistryMenuInput; } @@ -1062,7 +1062,7 @@ static void DeleteRegistry_No(u8 taskId) { s16 *data = gTasks[taskId].data; ClearDialogWindowAndFrame(0, 0); - DestroyListMenuTask(data[5], &data[2], &data[1]); + DestroyListMenuTask((u8)data[5], (u16 *)&data[2], (u16 *)&data[1]); FinalizeRegistryMenu(taskId); gTasks[taskId].func = HandleRegistryMenuInput; } diff --git a/src/slot_machine.c b/src/slot_machine.c index d1cb05b180..6557e8cf49 100644 --- a/src/slot_machine.c +++ b/src/slot_machine.c @@ -775,7 +775,7 @@ static void PlaySlotMachine_Internal(u8 slotMachineIndex, MainCallback cb) { struct Task *task = &gTasks[CreateTask(SlotMachineDummyTask, 0xFF)]; task->data[0] = slotMachineIndex; - StoreWordInTwoHalfwords(task->data + 1, (intptr_t)cb); + StoreWordInTwoHalfwords((u16 *)(task->data + 1), (intptr_t)cb); } diff --git a/src/start_menu.c b/src/start_menu.c index 88ad364c7b..68a3161855 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -463,7 +463,7 @@ static bool32 InitStartMenuStep(void) sInitStartMenuData[0]++; break; case 4: - if (PrintStartMenuActions(&sInitStartMenuData[1], 2)) + if (PrintStartMenuActions((s8 *)&sInitStartMenuData[1], 2)) sInitStartMenuData[0]++; break; case 5: diff --git a/src/trainer_see.c b/src/trainer_see.c index 68a16e208b..93daab421d 100644 --- a/src/trainer_see.c +++ b/src/trainer_see.c @@ -603,7 +603,7 @@ static void sub_80B44C8(u8 taskId) struct ObjectEvent *objEvent; // another objEvent loaded into by loadword? - LoadWordFromTwoHalfwords(&task->data[1], (u32 *)&objEvent); + LoadWordFromTwoHalfwords((u16*)&task->data[1], (u32 *)&objEvent); if (!task->data[7]) { ObjectEventClearHeldMovement(objEvent); @@ -624,7 +624,7 @@ static void sub_80B44C8(u8 taskId) void sub_80B4578(struct ObjectEvent *var) { - StoreWordInTwoHalfwords(&gTasks[CreateTask(sub_80B44C8, 0)].data[1], (u32)var); + StoreWordInTwoHalfwords((u16 *)&gTasks[CreateTask(sub_80B44C8, 0)].data[1], (u32)var); } void EndTrainerApproach(void) From c722b7755808e0ee34b84087f3a31a28bf685cad Mon Sep 17 00:00:00 2001 From: PokeCodec Date: Mon, 27 Jul 2020 12:47:08 -0400 Subject: [PATCH 12/17] holding back on casts --- src/agb_flash.c | 2 +- src/battle_anim_effects_1.c | 2 +- src/hall_of_fame.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/agb_flash.c b/src/agb_flash.c index 0045219c41..eeccf11164 100644 --- a/src/agb_flash.c +++ b/src/agb_flash.c @@ -242,7 +242,7 @@ u32 VerifyFlashSectorNBytes(u16 sectorNum, u8 *src, u32 n) funcSrc = (u16 *)((uintptr_t)funcSrc ^ 1); funcDest = verifyFlashSector_Core_Buffer; - i = (u16)(((uintptr_t)VerifyFlashSector - (uintptr_t)VerifyFlashSector_Core) >> 1); + i = ((uintptr_t)VerifyFlashSector - (uintptr_t)VerifyFlashSector_Core) >> 1; while (i != 0) { diff --git a/src/battle_anim_effects_1.c b/src/battle_anim_effects_1.c index e9930eeef0..f93b2a5c48 100644 --- a/src/battle_anim_effects_1.c +++ b/src/battle_anim_effects_1.c @@ -4445,7 +4445,7 @@ static void AnimBowMon_Step1_Callback(struct Sprite* sprite) { sprite->data[3] = gBattlerSpriteIds[gBattleAnimAttacker]; PrepareBattlerSpriteForRotScale(sprite->data[3], ST_OAM_OBJ_NORMAL); - sprite->data[4] = (sprite->data[6] = GetBattlerSide(gBattleAnimAttacker)) ? 0x300 : (s16)0xFFFFFD00; + sprite->data[4] = (sprite->data[6] = GetBattlerSide(gBattleAnimAttacker)) ? 0x300 : 0xFFFFFD00; sprite->data[5] = 0; } diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index 8e47c1e3ae..bf9850deca 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -612,7 +612,7 @@ static void Task_Hof_PrintMonInfoAfterAnimating(u8 taskId) static void Task_Hof_TryDisplayAnotherMon(u8 taskId) { - u16 currPokeID = (u16)gTasks[taskId].tDisplayedMonId; + u16 currPokeID = gTasks[taskId].tDisplayedMonId; struct HallofFameMon* currMon = &sHofMonPtr->mon[currPokeID]; if (gTasks[taskId].tFrameCount != 0) @@ -1483,7 +1483,7 @@ static void UpdateDomeConfetti(struct ConfettiUtil *util) static void Task_DoDomeConfetti(u8 taskId) { u32 id = 0; - u16 *data = (u16 *)gTasks[taskId].data; + u16 *data = gTasks[taskId].data; switch (tState) { From 462e3bc0cb63c92fcebb397252454d7912594c24 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 21 Jul 2020 17:21:01 -0400 Subject: [PATCH 13/17] Sync flags with pokeruby From 37957b2d15833db0c7949387ce7136a11265cd9b Mon Sep 17 00:00:00 2001 From: PokeCodec Date: Mon, 27 Jul 2020 19:17:34 -0400 Subject: [PATCH 14/17] semicolon --- src/AgbRfu_LinkManager.c | 2 +- src/battle_anim_psychic.c | 2 +- src/battle_anim_utility_funcs.c | 2 +- src/digit_obj_util.c | 2 +- src/mirage_tower.c | 2 +- src/save_failed_screen.c | 2 +- tools/gbagfx/gfx.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/AgbRfu_LinkManager.c b/src/AgbRfu_LinkManager.c index e4127ee090..f6ebcc7265 100644 --- a/src/AgbRfu_LinkManager.c +++ b/src/AgbRfu_LinkManager.c @@ -918,7 +918,7 @@ static void rfu_LMAN_REQ_callback(u16 reqCommandId, u16 reqResult) { lman.reserveDisconnectSlot_flag = 0; lman.acceptCount = 0; - lman.acceptSlot_flag = 0;; + lman.acceptSlot_flag = 0; lman.parent_child = MODE_NEUTRAL; rfu_LMAN_managerChangeAgbClockMaster(); if (reqCommandId == ID_STOP_MODE_REQ) diff --git a/src/battle_anim_psychic.c b/src/battle_anim_psychic.c index 7918698fc0..25340f9c6a 100644 --- a/src/battle_anim_psychic.c +++ b/src/battle_anim_psychic.c @@ -1101,7 +1101,7 @@ static void AnimTask_TransparentCloneGrowAndShrink_Step(u8 taskId) break; case 1: task->data[1] -= 4; - task->data[2] = 256 - (gSineTable[task->data[1]] >> 1);; + task->data[2] = 256 - (gSineTable[task->data[1]] >> 1); SetSpriteRotScale(task->data[15], task->data[2], task->data[2], 0); SetBattlerSpriteYOffsetFromOtherYScale(task->data[15], task->data[13]); if (task->data[1] == 0) diff --git a/src/battle_anim_utility_funcs.c b/src/battle_anim_utility_funcs.c index dcef7d4830..bca669cc26 100644 --- a/src/battle_anim_utility_funcs.c +++ b/src/battle_anim_utility_funcs.c @@ -569,7 +569,7 @@ static void sub_81172EC(u8 taskId) if (gTasks[taskId].data[12] == 0) { sub_80A477C(0); - gTasks[taskId].data[15]++;; + gTasks[taskId].data[15]++; } } break; diff --git a/src/digit_obj_util.c b/src/digit_obj_util.c index fe5d49e69d..f887dafb95 100644 --- a/src/digit_obj_util.c +++ b/src/digit_obj_util.c @@ -33,7 +33,7 @@ struct DigitPrinterAlloc }; // this file's functions -static u8 GetFirstOamId(u8 oamCount);; +static u8 GetFirstOamId(u8 oamCount); static void CopyWorkToOam(struct DigitPrinter *objWork); static void DrawNumObjsLeadingZeros(struct DigitPrinter *objWork, s32 num, bool32 sign); static void DrawNumObjsMinusInFront(struct DigitPrinter *objWork, s32 num, bool32 sign); diff --git a/src/mirage_tower.c b/src/mirage_tower.c index bdddbdbe64..3f3dc1ef85 100644 --- a/src/mirage_tower.c +++ b/src/mirage_tower.c @@ -690,7 +690,7 @@ static void DoFossilFallAndSink(u8 taskId) if (gSprites[sUnknown_0203CF0C->spriteId].callback != SpriteCallbackDummy) return; DestroySprite(&gSprites[sUnknown_0203CF0C->spriteId]); - FREE_AND_SET_NULL(sUnknown_0203CF0C->unkC);; + FREE_AND_SET_NULL(sUnknown_0203CF0C->unkC); FREE_AND_SET_NULL(sUnknown_0203CF0C->frameImage); FREE_AND_SET_NULL(sUnknown_0203CF0C->frameImageTiles); FREE_AND_SET_NULL(sUnknown_0203CF0C); diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index a2a2acc8d6..7c824e82dd 100644 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -349,7 +349,7 @@ static void VBlankCB_UpdateClockGraphics(void) gMain.oamBuffer[0] = sClockOamData; gMain.oamBuffer[0].x = 112; - gMain.oamBuffer[0].y = (CLOCK_WIN_TOP + 1) * 8;; + gMain.oamBuffer[0].y = (CLOCK_WIN_TOP + 1) * 8; if (gSaveFailedClockInfo[CLOCK_RUNNING] != FALSE) { diff --git a/tools/gbagfx/gfx.c b/tools/gbagfx/gfx.c index 8d959465f7..4e85953fdc 100644 --- a/tools/gbagfx/gfx.c +++ b/tools/gbagfx/gfx.c @@ -282,7 +282,7 @@ static void HflipTile(unsigned char * tile, int bitDepth) for (i = 0; i < 8; i++) { SWAP_NYBBLES(&tile[4 * i + 0], &tile[4 * i + 3]); - SWAP_NYBBLES(&tile[4 * i + 1], &tile[4 * i + 2]);; + SWAP_NYBBLES(&tile[4 * i + 1], &tile[4 * i + 2]); } break; case 8: From 7b6607d9e38702f41fda057cc13148b8f0bbcc0a Mon Sep 17 00:00:00 2001 From: PokeCodec <67983839+PokeCodec@users.noreply.github.com> Date: Mon, 27 Jul 2020 14:59:37 -0400 Subject: [PATCH 15/17] Update secret_base.c --- src/secret_base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/secret_base.c b/src/secret_base.c index 35ac31d4a7..3f69e0419e 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -964,7 +964,7 @@ static void HandleRegistryMenuInput(u8 taskId) data = gTasks[taskId].data; input = ListMenu_ProcessInput(data[5]); - ListMenuGetScrollAndRow((u8)data[5], (u16 *)&data[2], (u16 *)&data[1]); + ListMenuGetScrollAndRow(data[5], (u16 *)&data[2], (u16 *)&data[1]); switch (input) { case LIST_NOTHING_CHOSEN: From 044d968513f28566fab1db3ceff1b52162b8387a Mon Sep 17 00:00:00 2001 From: PokeCodec Date: Tue, 28 Jul 2020 14:38:38 -0400 Subject: [PATCH 16/17] Match --- src/event_object_movement.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 76331c2b14..4b275a9702 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1205,8 +1205,7 @@ static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template, { struct ObjectEvent *objectEvent; u8 objectEventId; - s16 x; - s16 y; + s16 x, y; if (GetAvailableObjectEventId(template->localId, mapNum, mapGroup, &objectEventId)) return OBJECT_EVENTS_COUNT; @@ -1220,7 +1219,6 @@ static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template, objectEvent->movementType = template->movementType; objectEvent->localId = template->localId; objectEvent->mapNum = mapNum; - objectEvent++; objectEvent--; objectEvent->mapGroup = mapGroup; objectEvent->initialCoords.x = x; objectEvent->initialCoords.y = y; @@ -1237,9 +1235,6 @@ static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template, objectEvent->previousMovementDirection = gInitialMovementTypeFacingDirections[template->movementType]; SetObjectEventDirection(objectEvent, objectEvent->previousMovementDirection); SetObjectEventDynamicGraphicsId(objectEvent); -#ifndef NONMATCHING - asm("":::"r5", "r6"); -#endif if (gRangedMovementTypes[objectEvent->movementType]) { if (objectEvent->range.as_nybbles.x == 0) From 93be3a08ce53fd3364fdb055e86269aa32e7fc4f Mon Sep 17 00:00:00 2001 From: PokeCodec Date: Tue, 28 Jul 2020 15:31:08 -0400 Subject: [PATCH 17/17] Match --- src/event_object_movement.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 4b275a9702..af34829695 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1205,7 +1205,8 @@ static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template, { struct ObjectEvent *objectEvent; u8 objectEventId; - s16 x, y; + s16 x; + s16 y; if (GetAvailableObjectEventId(template->localId, mapNum, mapGroup, &objectEventId)) return OBJECT_EVENTS_COUNT; @@ -1231,6 +1232,7 @@ static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template, objectEvent->range.as_nybbles.x = template->movementRangeX; objectEvent->range.as_nybbles.y = template->movementRangeY; objectEvent->trainerType = template->trainerType; + objectEvent->mapNum = mapNum; //redundant, but needed to match objectEvent->trainerRange_berryTreeId = template->trainerRange_berryTreeId; objectEvent->previousMovementDirection = gInitialMovementTypeFacingDirections[template->movementType]; SetObjectEventDirection(objectEvent, objectEvent->previousMovementDirection);