summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/apprentice.c27
-rw-r--r--src/battle_ai_script_commands.c29
-rw-r--r--src/battle_anim_dark.c10
-rwxr-xr-xsrc/battle_anim_effects_2.c16
-rw-r--r--src/battle_anim_mons.c2
-rw-r--r--src/battle_anim_sound_tasks.c8
-rwxr-xr-xsrc/battle_anim_throw.c2
-rw-r--r--src/battle_dome.c65
-rw-r--r--src/battle_factory.c2
-rw-r--r--src/battle_factory_screen.c5
-rw-r--r--src/battle_gfx_sfx_util.c6
-rw-r--r--src/battle_interface.c25
-rw-r--r--src/battle_main.c11
-rw-r--r--src/battle_message.c8
-rw-r--r--src/battle_pyramid.c6
-rw-r--r--src/battle_script_commands.c26
-rw-r--r--src/battle_transition.c27
-rw-r--r--src/bike.c29
-rw-r--r--src/contest.c29
-rw-r--r--src/contest_util.c2
-rw-r--r--src/daycare.c2
-rw-r--r--src/egg_hatch.c3
-rw-r--r--src/evolution_scene.c12
-rw-r--r--src/item.c18
-rwxr-xr-xsrc/item_use.c2
-rw-r--r--src/m4a.c15
-rw-r--r--src/main_menu.c19
-rw-r--r--src/mystery_gift.c24
-rw-r--r--src/overworld.c6
-rw-r--r--src/player_pc.c11
-rw-r--r--src/pokemon.c1
-rw-r--r--src/pokemon_animation.c15
-rw-r--r--src/pokemon_size_record.c2
-rw-r--r--src/pokemon_storage_system.c7
-rw-r--r--src/pokemon_summary_screen.c20
-rw-r--r--src/region_map.c2
-rw-r--r--src/rotating_gate.c3
-rw-r--r--src/roulette.c38
-rw-r--r--src/siirtc.c29
-rw-r--r--src/strings.c6
-rw-r--r--src/union_room.c7
-rwxr-xr-xsrc/union_room_chat.c2
-rw-r--r--src/wild_encounter.c4
43 files changed, 326 insertions, 257 deletions
diff --git a/src/apprentice.c b/src/apprentice.c
index f93a3e30b..00157dc1a 100644
--- a/src/apprentice.c
+++ b/src/apprentice.c
@@ -30,7 +30,7 @@
#include "constants/trainers.h"
#include "constants/moves.h"
-/* Summary of Apprentice, because (as of writing at least) its not very well documented online
+/* Summary of Apprentice, because (as of writing at least) it's not very well documented online
*
* ## Basic info
* In the Battle Tower lobby there is an NPC which asks to be taught by the player
@@ -1107,17 +1107,24 @@ static void TrySetApprenticeHeldItem(void)
if (PLAYER_APPRENTICE.questionsAnswered < NUM_WHICH_MON_QUESTIONS)
return;
+
+ count = 0;
+ for (j = 0; j < APPRENTICE_MAX_QUESTIONS; j++)
+ {
+ if (PLAYER_APPRENTICE.questions[j].questionId == QUESTION_ID_WIN_SPEECH)
+ break;
+ count++;
+ }
- for (count = 0, j = 0; j < APPRENTICE_MAX_QUESTIONS && PLAYER_APPRENTICE.questions[j].questionId != QUESTION_ID_WIN_SPEECH; count++, j++)
- ;
-
- // Make sure the item hasnt already been suggested in previous questions
- for (i = 0; i < count && i < CURRENT_QUESTION_NUM; i++)
+ // Make sure the item hasn't already been suggested in previous questions
+ for (i = 0; i < count; i++)
{
- do {} while(0);
- if (PLAYER_APPRENTICE.questions[i].questionId == QUESTION_ID_WHAT_ITEM
- && PLAYER_APPRENTICE.questions[i].suggestedChange
- && PLAYER_APPRENTICE.questions[i].data == gSpecialVar_0x8005)
+ if (i >= CURRENT_QUESTION_NUM)
+ break;
+ if (PLAYER_APPRENTICE.questions[i].questionId != QUESTION_ID_WHAT_ITEM ||
+ PLAYER_APPRENTICE.questions[i].suggestedChange == 0)
+ continue;
+ if (PLAYER_APPRENTICE.questions[i].data == gSpecialVar_0x8005)
{
PLAYER_APPRENTICE.questions[CURRENT_QUESTION_NUM].suggestedChange = FALSE;
PLAYER_APPRENTICE.questions[CURRENT_QUESTION_NUM].data = gSpecialVar_0x8005;
diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c
index 9fdd4d0c3..b72875036 100644
--- a/src/battle_ai_script_commands.c
+++ b/src/battle_ai_script_commands.c
@@ -1761,7 +1761,11 @@ static void Cmd_if_cant_faint(void)
gBattleMoveDamage = gBattleMoveDamage * AI_THINKING_STRUCT->simulatedRNG[AI_THINKING_STRUCT->movesetIndex] / 100;
- // This macro is missing the damage 0 = 1 assumption.
+#ifdef BUGFIX
+ // Moves always do at least 1 damage.
+ if (gBattleMoveDamage == 0)
+ gBattleMoveDamage = 1;
+#endif
if (gBattleMons[gBattlerTarget].hp > gBattleMoveDamage)
gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 1);
@@ -1877,9 +1881,14 @@ static void Cmd_if_has_move_with_effect(void)
case AI_TARGET_PARTNER:
for (i = 0; i < MAX_MON_MOVES; i++)
{
- // UB: checks sBattler_AI instead of gBattlerTarget.
+ // BUG: checks sBattler_AI instead of gBattlerTarget.
+ #ifndef BUGFIX
if (gBattleMons[sBattler_AI].moves[i] != 0 && gBattleMoves[BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i]].effect == gAIScriptPtr[2])
break;
+ #else
+ if (gBattleMons[gBattlerTarget].moves[i] != 0 && gBattleMoves[BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i]].effect == gAIScriptPtr[2])
+ break;
+ #endif
}
if (i == MAX_MON_MOVES)
gAIScriptPtr += 7;
@@ -2014,18 +2023,24 @@ static void Cmd_if_holds_item(void)
{
u8 battlerId = BattleAI_GetWantedBattler(gAIScriptPtr[1]);
u16 item;
- u8 var1, var2;
+ u8 itemLo, itemHi;
if ((battlerId & BIT_SIDE) == (sBattler_AI & BIT_SIDE))
item = gBattleMons[battlerId].item;
else
item = BATTLE_HISTORY->itemEffects[battlerId];
- // UB: doesn't properly read an unaligned u16
- var2 = gAIScriptPtr[2];
- var1 = gAIScriptPtr[3];
+ itemHi = gAIScriptPtr[2];
+ itemLo = gAIScriptPtr[3];
- if ((var1 | var2) == item)
+#ifdef BUGFIX
+ // This bug doesn't affect the vanilla game because this script command
+ // is only used to check ITEM_PERSIM_BERRY, whose high byte happens to
+ // be 0.
+ if (((itemHi << 8) | itemLo) == item)
+#else
+ if ((itemLo | itemHi) == item)
+#endif
gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4);
else
gAIScriptPtr += 8;
diff --git a/src/battle_anim_dark.c b/src/battle_anim_dark.c
index c2bfe269b..8000a648c 100644
--- a/src/battle_anim_dark.c
+++ b/src/battle_anim_dark.c
@@ -870,7 +870,7 @@ void AnimTask_MetallicShine(u8 taskId)
paletteNum = 16 + gSprites[spriteId].oam.paletteNum;
if (gBattleAnimArgs[1] == 0)
- SetGreyscaleOrOriginalPalette(paletteNum, FALSE);
+ SetGrayscaleOrOriginalPalette(paletteNum, FALSE);
else
BlendPalette(paletteNum * 16, 16, 11, gBattleAnimArgs[2]);
@@ -900,7 +900,7 @@ static void AnimTask_MetallicShine_Step(u8 taskId)
spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER);
paletteNum = 16 + gSprites[spriteId].oam.paletteNum;
if (gTasks[taskId].data[1] == 0)
- SetGreyscaleOrOriginalPalette(paletteNum, TRUE);
+ SetGrayscaleOrOriginalPalette(paletteNum, TRUE);
DestroySprite(&gSprites[gTasks[taskId].data[0]]);
GetBattleAnimBg1Data(&animBg);
@@ -925,10 +925,10 @@ static void AnimTask_MetallicShine_Step(u8 taskId)
}
}
-// Changes battler's palette to either greyscale or original.
+// Changes battler's palette to either grayscale or original.
// arg0: which battler
// arg1: FALSE grayscale, TRUE original
-void AnimTask_SetGreyscaleOrOriginalPal(u8 taskId)
+void AnimTask_SetGrayscaleOrOriginalPal(u8 taskId)
{
u8 spriteId;
u8 battler;
@@ -974,7 +974,7 @@ void AnimTask_SetGreyscaleOrOriginalPal(u8 taskId)
}
if (spriteId != SPRITE_NONE)
- SetGreyscaleOrOriginalPalette(gSprites[spriteId].oam.paletteNum + 16, gBattleAnimArgs[1]);
+ SetGrayscaleOrOriginalPalette(gSprites[spriteId].oam.paletteNum + 16, gBattleAnimArgs[1]);
DestroyAnimVisualTask(taskId);
}
diff --git a/src/battle_anim_effects_2.c b/src/battle_anim_effects_2.c
index 5dd584386..0ac5d384b 100755
--- a/src/battle_anim_effects_2.c
+++ b/src/battle_anim_effects_2.c
@@ -89,7 +89,7 @@ static void AnimPerishSongMusicNote_Step1(struct Sprite *);
static void AnimPerishSongMusicNote_Step2(struct Sprite *);
static void AnimGuardRing(struct Sprite *);
static void AnimTask_Withdraw_Step(u8);
-static void AnimTask_GrowAndGreyscale_Step(u8);
+static void AnimTask_GrowAndGrayscale_Step(u8);
static void AnimTask_Minimize_Step(u8);
static void CreateMinimizeSprite(struct Task *, u8);
static void ClonedMinizeSprite_Step(struct Sprite *);
@@ -1996,26 +1996,26 @@ static void AnimGuillotinePincer_Step3(struct Sprite *sprite)
DestroyAnimSprite(sprite);
}
-// Scales up the target mon sprite, and sets the palette to greyscale.
+// Scales up the target mon sprite, and sets the palette to grayscale.
// Used in MOVE_DISABLE.
// No args.
-void AnimTask_GrowAndGreyscale(u8 taskId)
+void AnimTask_GrowAndGrayscale(u8 taskId)
{
u8 spriteId = GetAnimBattlerSpriteId(ANIM_TARGET);
PrepareBattlerSpriteForRotScale(spriteId, ST_OAM_OBJ_BLEND);
SetSpriteRotScale(spriteId, 0xD0, 0xD0, 0);
- SetGreyscaleOrOriginalPalette(gSprites[spriteId].oam.paletteNum + 16, FALSE);
+ SetGrayscaleOrOriginalPalette(gSprites[spriteId].oam.paletteNum + 16, FALSE);
gTasks[taskId].data[0] = 80;
- gTasks[taskId].func = AnimTask_GrowAndGreyscale_Step;
+ gTasks[taskId].func = AnimTask_GrowAndGrayscale_Step;
}
-static void AnimTask_GrowAndGreyscale_Step(u8 taskId)
+static void AnimTask_GrowAndGrayscale_Step(u8 taskId)
{
if (--gTasks[taskId].data[0] == -1)
{
u8 spriteId = GetAnimBattlerSpriteId(ANIM_TARGET);
ResetSpriteRotScale(spriteId);
- SetGreyscaleOrOriginalPalette(gSprites[spriteId].oam.paletteNum + 16, TRUE);
+ SetGrayscaleOrOriginalPalette(gSprites[spriteId].oam.paletteNum + 16, TRUE);
DestroyAnimVisualTask(taskId);
}
}
@@ -3710,7 +3710,7 @@ static void AnimPerishSongMusicNote2(struct Sprite *sprite)
}
if (++sprite->data[0] == sprite->data[1])
- SetGreyscaleOrOriginalPalette(sprite->oam.paletteNum + 16, 0);
+ SetGrayscaleOrOriginalPalette(sprite->oam.paletteNum + 16, 0);
if (sprite->data[0] == sprite->data[1] + 80)
DestroyAnimSprite(sprite);
diff --git a/src/battle_anim_mons.c b/src/battle_anim_mons.c
index 2082512ff..cf5ae6eb2 100644
--- a/src/battle_anim_mons.c
+++ b/src/battle_anim_mons.c
@@ -1310,7 +1310,7 @@ u16 ArcTan2Neg(s16 a, s16 b)
return -var;
}
-void SetGreyscaleOrOriginalPalette(u16 paletteNum, bool8 restoreOriginalColor)
+void SetGrayscaleOrOriginalPalette(u16 paletteNum, bool8 restoreOriginalColor)
{
int i;
struct PlttData *originalColor;
diff --git a/src/battle_anim_sound_tasks.c b/src/battle_anim_sound_tasks.c
index 8fc93c3aa..39d6729e8 100644
--- a/src/battle_anim_sound_tasks.c
+++ b/src/battle_anim_sound_tasks.c
@@ -135,8 +135,10 @@ void SoundTask_PlayCryHighPitch(u8 taskId)
{
if (gBattleAnimArgs[0] == ANIM_ATTACKER)
species = gContestResources->moveAnim->species;
+ #ifndef UBFIX
else
- DestroyAnimVisualTask(taskId); // UB: function should return upon destroying task.
+ DestroyAnimVisualTask(taskId); // UB: task gets destroyed twice.
+ #endif
}
else
{
@@ -179,8 +181,10 @@ void SoundTask_PlayDoubleCry(u8 taskId)
{
if (gBattleAnimArgs[0] == ANIM_ATTACKER)
species = gContestResources->moveAnim->species;
+ #ifndef UBFIX
else
- DestroyAnimVisualTask(taskId); // UB: function should return upon destroying task.
+ DestroyAnimVisualTask(taskId); // UB: task gets destroyed twice.
+ #endif
}
else
{
diff --git a/src/battle_anim_throw.c b/src/battle_anim_throw.c
index 83768b476..4064e250c 100755
--- a/src/battle_anim_throw.c
+++ b/src/battle_anim_throw.c
@@ -1420,7 +1420,7 @@ static void MakeCaptureStars(struct Sprite *sprite)
LoadBallParticleGfx(BALL_MASTER);
for (i = 0; i < ARRAY_COUNT(sCaptureStars); i++)
{
- u8 spriteId = CreateSprite(&sBallParticleSpriteTemplates[4], sprite->pos1.x, sprite->pos1.y, subpriority);
+ u8 spriteId = CreateSprite(&sBallParticleSpriteTemplates[BALL_MASTER], sprite->pos1.x, sprite->pos1.y, subpriority);
if (spriteId != MAX_SPRITES)
{
gSprites[spriteId].sDuration = 24;
diff --git a/src/battle_dome.c b/src/battle_dome.c
index a5cf168ef..ea1e5abba 100644
--- a/src/battle_dome.c
+++ b/src/battle_dome.c
@@ -1211,8 +1211,8 @@ static const u8 gUnknown_0860D1A0[DOME_TOURNAMENT_TRAINERS_COUNT / 2][DOME_ROUND
static const u8 gUnknown_0860D1C0[DOME_TOURNAMENT_TRAINERS_COUNT] = {0, 15, 8, 7, 3, 12, 11, 4, 1, 14, 9, 6, 2, 13, 10, 5};
-// Each tourney trainer has a text describing their potential to win, depending on their seed ranking for the current tourney
-// Dome Ace Tucker has their own separate potential text
+// The first line of text on a trainers info card. It describes their potential to win, based on their seed in the tournament tree.
+// Dome Ace Tucker has their own separate potential text.
static const u8 *const sBattleDomePotentialTexts[DOME_TOURNAMENT_TRAINERS_COUNT + 1] =
{
BattleDome_Text_Potential1, // Highest potential
@@ -1234,7 +1234,7 @@ static const u8 *const sBattleDomePotentialTexts[DOME_TOURNAMENT_TRAINERS_COUNT
BattleDome_Text_PotentialDomeAceTucker,
};
-// The first line of text on a trainers info card that gives information about their battle style (dependent on their party's moves)
+// The second line of text on a trainers info card. It gives information about their battle style (dependent on their party's moves).
static const u8 *const sBattleDomeOpponentStyleTexts[NUM_BATTLE_STYLES] =
{
[DOME_BATTLE_STYLE_RISKY] = BattleDome_Text_StyleRiskDisaster,
@@ -1271,7 +1271,7 @@ static const u8 *const sBattleDomeOpponentStyleTexts[NUM_BATTLE_STYLES] =
[DOME_BATTLE_STYLE_UNUSED4] = BattleDome_Text_StyleSampleMessage4,
};
-// The second line of text on a trainers info card that gives information about their party's stat spread
+// The third line of text on a trainers info card. It that gives information about their party's stat spread (based on their Pokémon's effort values and Nature).
static const u8 *const sBattleDomeOpponentStatsTexts[] =
{
BattleDome_Text_EmphasizesHPAndAtk, // DOME_TEXT_TWO_GOOD_STATS and DOME_TEXT_HP start here
@@ -2766,13 +2766,22 @@ static int GetTypeEffectivenessPoints(int move, int targetSpecies, int arg2)
}
if (TYPE_EFFECT_ATK_TYPE(i) == moveType)
{
- // BUG: TYPE_x2 is not necessary and makes the condition always false if the ability is wonder guard.
+ // BUG: the value of TYPE_x2 does not exist in gTypeEffectiveness, so if defAbility is ABILITY_WONDER_GUARD, the conditional always fails
+ #ifndef BUGFIX
if (TYPE_EFFECT_DEF_TYPE(i) == defType1)
if ((defAbility == ABILITY_WONDER_GUARD && TYPE_EFFECT_MULTIPLIER(i) == TYPE_x2) || defAbility != ABILITY_WONDER_GUARD)
typePower = (typePower * TYPE_EFFECT_MULTIPLIER(i)) / 10;
if (TYPE_EFFECT_DEF_TYPE(i) == defType2 && defType1 != defType2)
if ((defAbility == ABILITY_WONDER_GUARD && TYPE_EFFECT_MULTIPLIER(i) == TYPE_x2) || defAbility != ABILITY_WONDER_GUARD)
typePower = (typePower * TYPE_EFFECT_MULTIPLIER(i)) / 10;
+ #else
+ if (TYPE_EFFECT_DEF_TYPE(i) == defType1)
+ if ((defAbility == ABILITY_WONDER_GUARD && TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_SUPER_EFFECTIVE) || defAbility != ABILITY_WONDER_GUARD)
+ typePower = (typePower * TYPE_EFFECT_MULTIPLIER(i)) / 10;
+ if (TYPE_EFFECT_DEF_TYPE(i) == defType2 && defType1 != defType2)
+ if ((defAbility == ABILITY_WONDER_GUARD && TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_SUPER_EFFECTIVE) || defAbility != ABILITY_WONDER_GUARD)
+ typePower = (typePower * TYPE_EFFECT_MULTIPLIER(i)) / 10;
+ #endif
}
i += 3;
}
@@ -5211,40 +5220,38 @@ static u16 GetWinningMove(int winnerTournamentId, int loserTournamentId, u8 roun
}
j = bestId;
- goto LABEL;
- while (j != 0)
+ do
{
- for (j = 0, k = 0; k < MAX_MON_MOVES * FRONTIER_PARTY_SIZE; k++)
+ for (i = 0; i < roundId - 1; i++)
{
- if (bestScore < moveScores[k])
- {
- j = k;
- bestScore = moveScores[k];
- }
- else if (bestScore == moveScores[k] && moveIds[j] < moveIds[k])
- {
- j = k;
- }
+ if (gSaveBlock2Ptr->frontier.domeWinningMoves[sub_81953E8(winnerTournamentId, i)] == moveIds[j])
+ break;
}
- if (i == roundId - 1)
- break;
- LABEL:
+ if (i != roundId - 1)
{
- for (i = 0; i < roundId - 1; i++)
- {
- if (gSaveBlock2Ptr->frontier.domeWinningMoves[sub_81953E8(winnerTournamentId, i)] == moveIds[j])
- break;
- }
- if (i == roundId - 1)
- break;
-
moveScores[j] = 0;
bestScore = 0;
j = 0;
for (k = 0; k < MAX_MON_MOVES * FRONTIER_PARTY_SIZE; k++)
j += moveScores[k];
+ if (j == 0)
+ break;
+ j = 0;
+ for (k = 0; k < MAX_MON_MOVES * FRONTIER_PARTY_SIZE; k++)
+ {
+ if (bestScore < moveScores[k])
+ {
+ j = k;
+ bestScore = moveScores[k];
+ }
+ else if (bestScore == moveScores[k] && moveIds[j] < moveIds[k]) // Yes, these conditions are redundant
+ {
+ j = k;
+ bestScore = moveScores[k];
+ }
+ }
}
- }
+ } while (i != roundId - 1);
if (moveScores[j] == 0)
j = bestId;
diff --git a/src/battle_factory.c b/src/battle_factory.c
index 72772929a..e0bfdfdd0 100644
--- a/src/battle_factory.c
+++ b/src/battle_factory.c
@@ -38,7 +38,7 @@ static void GenerateInitialRentalMons(void);
static void GetOpponentMostCommonMonType(void);
static void GetOpponentBattleStyle(void);
static void RestorePlayerPartyHeldItems(void);
-static u16 GetFactoryMonId(u8 lvlMode, u8 challengeNum, bool8 arg2);
+static u16 GetFactoryMonId(u8 lvlMode, u8 challengeNum, bool8 useBetterRange);
static u8 GetMoveBattleStyle(u16 move);
// Number of moves needed on the team to be considered using a certain battle style
diff --git a/src/battle_factory_screen.c b/src/battle_factory_screen.c
index 680c6e81c..db810e965 100644
--- a/src/battle_factory_screen.c
+++ b/src/battle_factory_screen.c
@@ -4221,12 +4221,17 @@ static void Task_OpenMonPic(u8 taskId)
return;
break;
default:
+ #ifndef UBFIX
DestroyTask(taskId);
+ #endif
// UB: Should not use the task after it has been deleted.
if (gTasks[taskId].tIsSwapScreen == TRUE)
Swap_CreateMonSprite();
else
Select_CreateMonSprite();
+ #ifdef UBFIX
+ DestroyTask(taskId);
+ #endif
return;
}
task->tState++;
diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c
index ba0cab814..88e69665e 100644
--- a/src/battle_gfx_sfx_util.c
+++ b/src/battle_gfx_sfx_util.c
@@ -40,7 +40,7 @@ extern const struct SpriteTemplate gSpriteTemplate_EnemyShadow;
static u8 GetBattlePalaceMoveGroup(u16 move);
static u16 GetBattlePalaceTarget(void);
static void SpriteCB_TrainerSlideVertical(struct Sprite *sprite);
-static bool8 ShouldAnimBeDoneRegardlessOfSubsitute(u8 animId);
+static bool8 ShouldAnimBeDoneRegardlessOfSubstitute(u8 animId);
static void Task_ClearBitWhenBattleTableAnimDone(u8 taskId);
static void Task_ClearBitWhenSpecialAnimDone(u8 taskId);
static void ClearSpritesBattlerHealthboxAnimData(void);
@@ -444,7 +444,7 @@ bool8 TryHandleLaunchBattleTableAnimation(u8 activeBattler, u8 atkBattler, u8 de
return TRUE;
}
if (gBattleSpritesDataPtr->battlerData[activeBattler].behindSubstitute
- && !ShouldAnimBeDoneRegardlessOfSubsitute(tableId))
+ && !ShouldAnimBeDoneRegardlessOfSubstitute(tableId))
{
return TRUE;
}
@@ -480,7 +480,7 @@ static void Task_ClearBitWhenBattleTableAnimDone(u8 taskId)
#undef tBattlerId
-static bool8 ShouldAnimBeDoneRegardlessOfSubsitute(u8 animId)
+static bool8 ShouldAnimBeDoneRegardlessOfSubstitute(u8 animId)
{
switch (animId)
{
diff --git a/src/battle_interface.c b/src/battle_interface.c
index 5518fd21b..50eb5373a 100644
--- a/src/battle_interface.c
+++ b/src/battle_interface.c
@@ -159,7 +159,7 @@ enum
// strings
extern const u8 gText_Slash[];
-extern const u8 gText_HighlightDarkGrey[];
+extern const u8 gText_HighlightDarkGray[];
extern const u8 gText_DynColor2[];
extern const u8 gText_DynColor2Male[];
extern const u8 gText_DynColor1Female[];
@@ -1099,21 +1099,14 @@ static void UpdateLvlInHealthbox(u8 healthboxSpriteId, u8 lvl)
u32 windowId, spriteTileNum;
u8 *windowTileData;
u8 text[16];
- u32 xPos, var1;
- void *objVram;
-
- text[0] = 0xF9;
- text[1] = 5;
+ u32 xPos;
+ u8 *objVram;
+
+ text[0] = CHAR_EXTRA_SYMBOL;
+ text[1] = CHAR_LV_2;
- xPos = (u32) ConvertIntToDecimalStringN(text + 2, lvl, STR_CONV_MODE_LEFT_ALIGN, 3);
- // Alright, that part was unmatchable. It's basically doing:
- // xPos = 5 * (3 - (u32)(&text[2]));
- xPos--;
- xPos--;
- xPos -= ((u32)(text));
- var1 = (3 - xPos);
- xPos = 4 * var1;
- xPos += var1;
+ objVram = ConvertIntToDecimalStringN(text + 2, lvl, STR_CONV_MODE_LEFT_ALIGN, 3);
+ xPos = 5 * (3 - (objVram - (text + 2)));
windowTileData = AddTextPrinterAndCreateWindowOnHealthbox(text, xPos, 3, 2, &windowId);
spriteTileNum = gSprites[healthboxSpriteId].oam.tileNum * TILE_SIZE_4BPP;
@@ -1902,7 +1895,7 @@ static void UpdateNickInHealthbox(u8 healthboxSpriteId, struct Pokemon *mon)
u16 species;
u8 gender;
- StringCopy(gDisplayedStringBattle, gText_HighlightDarkGrey);
+ StringCopy(gDisplayedStringBattle, gText_HighlightDarkGray);
GetMonData(mon, MON_DATA_NICKNAME, nickname);
StringGetEnd10(nickname);
ptr = StringAppend(gDisplayedStringBattle, nickname);
diff --git a/src/battle_main.c b/src/battle_main.c
index c74de896e..977bcbd9c 100644
--- a/src/battle_main.c
+++ b/src/battle_main.c
@@ -1961,10 +1961,10 @@ static u8 CreateNPCTrainerParty(struct Pokemon *party, u16 trainerNum, bool8 fir
if (gTrainers[trainerNum].doubleBattle == TRUE)
personalityValue = 0x80;
- else if (gTrainers[trainerNum].encounterMusic_gender & 0x80)
- personalityValue = 0x78;
+ else if (gTrainers[trainerNum].encounterMusic_gender & F_TRAINER_FEMALE)
+ personalityValue = 0x78; // Use personality more likely to result in a female Pokémon
else
- personalityValue = 0x88;
+ personalityValue = 0x88; // Use personality more likely to result in a male Pokémon
for (j = 0; gTrainers[trainerNum].trainerName[j] != EOS; j++)
nameHash += gTrainers[trainerNum].trainerName[j];
@@ -5148,7 +5148,12 @@ static void ReturnFromBattleToOverworld(void)
if (gBattleTypeFlags & BATTLE_TYPE_ROAMER)
{
UpdateRoamerHPStatus(&gEnemyParty[0]);
+
+#ifndef BUGFIX
if ((gBattleOutcome & B_OUTCOME_WON) || gBattleOutcome == B_OUTCOME_CAUGHT)
+#else
+ if ((gBattleOutcome == B_OUTCOME_WON) || gBattleOutcome == B_OUTCOME_CAUGHT) // Bug: When Roar is used by roamer, gBattleOutcome is B_OUTCOME_PLAYER_TELEPORTED (5).
+#endif // & with B_OUTCOME_WON (1) will return TRUE and deactivates the roamer.
SetRoamerInactive();
}
diff --git a/src/battle_message.c b/src/battle_message.c
index 2e752dcca..ae30a2a62 100644
--- a/src/battle_message.c
+++ b/src/battle_message.c
@@ -383,7 +383,7 @@ static const u8 sText_ThrewPokeblockAtPkmn[] = _("{B_PLAYER_NAME} threw a {POKEB
static const u8 sText_OutOfSafariBalls[] = _("{PLAY_SE SE_DING_DONG}ANNOUNCER: You're out of\nSAFARI BALLS! Game over!\p");
static const u8 sText_OpponentMon1Appeared[] = _("{B_OPPONENT_MON1_NAME} appeared!\p");
static const u8 sText_WildPkmnAppeared[] = _("Wild {B_OPPONENT_MON1_NAME} appeared!\p");
-static const u8 sText_WildPkmnAppeared2[] = _("Wild {B_OPPONENT_MON1_NAME} appeared!\p");
+static const u8 sText_LegendaryPkmnAppeared[] = _("Wild {B_OPPONENT_MON1_NAME} appeared!\p");
static const u8 sText_WildPkmnAppearedPause[] = _("Wild {B_OPPONENT_MON1_NAME} appeared!{PAUSE 127}");
static const u8 sText_TwoWildPkmnAppeared[] = _("Wild {B_OPPONENT_MON1_NAME} and\n{B_OPPONENT_MON2_NAME} appeared!\p");
static const u8 sText_Trainer1WantsToBattle[] = _("{B_TRAINER1_CLASS} {B_TRAINER1_NAME}\nwould like to battle!\p");
@@ -1067,7 +1067,7 @@ const u16 gTransformUsedStringIds[] =
[B_MSG_TRANSFORM_FAILED] = STRINGID_BUTITFAILED
};
-const u16 gSubsituteUsedStringIds[] =
+const u16 gSubstituteUsedStringIds[] =
{
[B_MSG_SET_SUBSTITUTE] = STRINGID_PKMNMADESUBSTITUTE,
[B_MSG_SUBSTITUTE_FAILED] = STRINGID_TOOWEAKFORSUBSTITUTE
@@ -1328,7 +1328,7 @@ static const u8 sText_SpaceIs[] = _(" is");
static const u8 sText_ApostropheS[] = _("'s");
// For displaying names of invalid moves
-static const u8 sATypeMove_Table[][NUMBER_OF_MON_TYPES - 1] =
+static const u8 sATypeMove_Table[NUMBER_OF_MON_TYPES][17] =
{
[TYPE_NORMAL] = _("a NORMAL move"),
[TYPE_FIGHTING] = _("a FIGHTING move"),
@@ -2125,7 +2125,7 @@ void BufferStringBattle(u16 stringID)
else
{
if (gBattleTypeFlags & BATTLE_TYPE_LEGENDARY)
- stringPtr = sText_WildPkmnAppeared2;
+ stringPtr = sText_LegendaryPkmnAppeared;
else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) // interesting, looks like they had something planned for wild double battles
stringPtr = sText_TwoWildPkmnAppeared;
else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL)
diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c
index a41a80bbb..50efeecb4 100644
--- a/src/battle_pyramid.c
+++ b/src/battle_pyramid.c
@@ -1399,8 +1399,12 @@ void GenerateBattlePyramidWildMon(void)
for (i = 0; i < MAX_MON_MOVES; i++)
SetMonMoveSlot(&gEnemyParty[0], wildMons[id].moves[i], i);
- // BUG: Reading outside the array as lvl was used for mon level instead of frontier lvl mode.
+ // UB: Reading outside the array as lvl was used for mon level instead of frontier lvl mode.
+ #ifndef UBFIX
if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvl] >= 140)
+ #else
+ if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[gSaveBlock2Ptr->frontier.lvlMode] >= 140)
+ #endif
{
id = (Random() % 17) + 15;
for (i = 0; i < NUM_STATS; i++)
diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c
index 0492caeb5..d927ffb76 100644
--- a/src/battle_script_commands.c
+++ b/src/battle_script_commands.c
@@ -3269,7 +3269,7 @@ static void Cmd_getexp(void)
if (viaExpShare) // at least one mon is getting exp via exp share
{
- *exp = calculatedExp / 2 / viaSentIn;
+ *exp = SAFE_DIV(calculatedExp / 2, viaSentIn);
if (*exp == 0)
*exp = 1;
@@ -3279,7 +3279,7 @@ static void Cmd_getexp(void)
}
else
{
- *exp = calculatedExp / viaSentIn;
+ *exp = SAFE_DIV(calculatedExp, viaSentIn);
if (*exp == 0)
*exp = 1;
gExpShareExp = 0;
@@ -3357,7 +3357,7 @@ static void Cmd_getexp(void)
// get exp getter battlerId
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
{
- if (!(gBattlerPartyIndexes[2] != gBattleStruct->expGetterMonId) && !(gAbsentBattlerFlags & gBitTable[2]))
+ if (gBattlerPartyIndexes[2] == gBattleStruct->expGetterMonId && !(gAbsentBattlerFlags & gBitTable[2]))
gBattleStruct->expGetterBattlerId = 2;
else
{
@@ -3431,14 +3431,13 @@ static void Cmd_getexp(void)
gBattleMons[0].maxHP = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_MAX_HP);
gBattleMons[0].attack = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_ATK);
gBattleMons[0].defense = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_DEF);
- // Why is this duplicated?
+ // Speed is duplicated, likely due to a copy-paste error.
gBattleMons[0].speed = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPEED);
gBattleMons[0].speed = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPEED);
-
gBattleMons[0].spAttack = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPATK);
gBattleMons[0].spDefense = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPDEF);
}
- // What is else if?
+
if (gBattlerPartyIndexes[2] == gBattleStruct->expGetterMonId && gBattleMons[2].hp && (gBattleTypeFlags & BATTLE_TYPE_DOUBLE))
{
gBattleMons[2].level = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_LEVEL);
@@ -3446,10 +3445,13 @@ static void Cmd_getexp(void)
gBattleMons[2].maxHP = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_MAX_HP);
gBattleMons[2].attack = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_ATK);
gBattleMons[2].defense = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_DEF);
- // Duplicated again, but this time there's no Sp Defense
gBattleMons[2].speed = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPEED);
+ // Speed is duplicated again, but Special Defense is missing.
+#ifdef BUGFIX
+ gBattleMons[2].spDefense = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPDEF);
+#else
gBattleMons[2].speed = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPEED);
-
+#endif
gBattleMons[2].spAttack = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPATK);
}
gBattleScripting.getexpState = 5;
@@ -6168,7 +6170,13 @@ static void Cmd_recordlastability(void)
{
gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]);
RecordAbilityBattle(gActiveBattler, gLastUsedAbility);
- gBattlescriptCurrInstr += 1; // UB: Should be + 2, one byte for command and one byte for battlerId argument.
+
+#ifdef BUGFIX
+ // This command occupies two bytes (one for the command id, and one for the battler id parameter).
+ gBattlescriptCurrInstr += 2;
+#else
+ gBattlescriptCurrInstr += 1;
+#endif
}
void BufferMoveToLearnIntoBattleTextBuff2(void)
diff --git a/src/battle_transition.c b/src/battle_transition.c
index 1b484f7c5..461c45e7d 100644
--- a/src/battle_transition.c
+++ b/src/battle_transition.c
@@ -1323,6 +1323,12 @@ static bool8 Phase2_BigPokeball_Func1(struct Task *task)
return FALSE;
}
+#define SOME_VRAM_STORE(ptr, posY, posX, toStore) \
+{ \
+ u32 index = (posY) * 32 + posX; \
+ ptr[index] = toStore; \
+}
+
static bool8 Phase2_BigPokeball_Func2(struct Task *task)
{
s16 i, j;
@@ -1335,7 +1341,7 @@ static bool8 Phase2_BigPokeball_Func2(struct Task *task)
{
for (j = 0; j < 30; j++, BigPokeballMap++)
{
- tilemap[i * 32 + j] = *BigPokeballMap | 0xF000;
+ SOME_VRAM_STORE(tilemap, i, j, *BigPokeballMap | 0xF000);
}
}
sub_8149F98(gScanlineEffectRegBuffers[0], 0, task->tData4, 132, task->tData5, 160);
@@ -1675,12 +1681,6 @@ bool8 FldEff_Pokeball(void)
return FALSE;
}
-#define SOME_VRAM_STORE(ptr, posY, posX, toStore) \
-{ \
- u32 index = (posY) * 32 + posX; \
- ptr[index] = toStore; \
-}
-
static void sub_814713C(struct Sprite *sprite)
{
s16 arr0[ARRAY_COUNT(sUnknown_085C8B96)];
@@ -2142,7 +2142,7 @@ static bool8 Phase2_Mugshot_Func2(struct Task *task)
{
for (j = 0; j < 32; j++, mugshotsMap++)
{
- tilemap[i * 32 + j] = *mugshotsMap | 0xF000;
+ SOME_VRAM_STORE(tilemap, i, j, *mugshotsMap | 0xF000);
}
}
@@ -2960,17 +2960,15 @@ static bool8 Phase2_RectangularSpiral_Func2(struct Task *task)
if (sub_8149048(gUnknown_085C8D38[j / 2], &sRectangularSpiralTransition[j]))
{
- u32 one;
done = FALSE;
var = sRectangularSpiralTransition[j].field_2;
- one = 1;
- if ((j & 1) == one)
+ if ((j % 2) == 1)
var = 0x27D - var;
var2 = var % 32;
- var3 = var / 32 * 32;
+ var3 = var / 32;
- tilemap[var3 + var2] = 0xF002;
+ SOME_VRAM_STORE(tilemap, var3, var2, 0xF002);
}
}
}
@@ -4328,7 +4326,10 @@ static bool8 Phase2_FrontierSquaresScroll_Func5(struct Task *task)
BlendPalettes(PALETTES_ALL, 0x10, 0);
DestroyTask(FindTaskIdByFunc(task->func));
+
+#ifndef UBFIX
task->tState++; // UB: changing value of a destroyed task
+#endif
return FALSE;
}
diff --git a/src/bike.c b/src/bike.c
index bbcda989c..e97a5e04e 100644
--- a/src/bike.c
+++ b/src/bike.c
@@ -614,27 +614,24 @@ static void AcroBikeTransition_WheelieHoppingMoving(u8 direction)
return;
}
collision = GetBikeCollision(direction);
- // TODO: Try to get rid of this goto
- if (collision == 0 || collision == COLLISION_WHEELIE_HOP)
+ if (collision && collision != COLLISION_WHEELIE_HOP)
{
- goto derp;
- }
- else if (collision == COLLISION_LEDGE_JUMP)
- {
- PlayerLedgeHoppingWheelie(direction);
- }
- else if (collision < COLLISION_STOP_SURFING || collision > COLLISION_ROTATING_GATE)
- {
- if (collision < COLLISION_VERTICAL_RAIL)
+ if (collision == COLLISION_LEDGE_JUMP)
{
- AcroBikeTransition_WheelieHoppingStanding(direction);
+ PlayerLedgeHoppingWheelie(direction);
+ return;
}
- else
+ if (collision >= COLLISION_STOP_SURFING && collision <= COLLISION_ROTATING_GATE)
+ {
+ return;
+ }
+ if (collision < COLLISION_VERTICAL_RAIL)
{
- derp:
- PlayerMovingHoppingWheelie(direction);
+ AcroBikeTransition_WheelieHoppingStanding(direction);
+ return;
}
}
+ PlayerMovingHoppingWheelie(direction);
}
static void AcroBikeTransition_SideJump(u8 direction)
@@ -1056,7 +1053,7 @@ void Bike_HandleBumpySlopeJump(void)
bool32 IsRunningDisallowed(u8 metatile)
{
- if (!(gMapHeader.flags & MAP_ALLOW_RUNNING) || IsRunningDisallowedByMetatile(metatile) == TRUE)
+ if (!gMapHeader.allowRunning || IsRunningDisallowedByMetatile(metatile) == TRUE)
return TRUE;
else
return FALSE;
diff --git a/src/contest.c b/src/contest.c
index dbbd6ef63..84d00d8ee 100644
--- a/src/contest.c
+++ b/src/contest.c
@@ -258,6 +258,11 @@ enum {
#define TAG_BLINK_EFFECT_CONTESTANT2 0x80EA
#define TAG_BLINK_EFFECT_CONTESTANT3 0x80EB
+#define TILE_FILLED_APPEAL_HEART 0x5012
+#define TILE_FILLED_JAM_HEART 0x5014
+#define TILE_EMPTY_APPEAL_HEART 0x5035
+#define TILE_EMPTY_JAM_HEART 0x5036
+
enum {
SLIDER_HEART_ANIM_NORMAL,
SLIDER_HEART_ANIM_DISAPPEAR,
@@ -1526,7 +1531,7 @@ static void Task_ShowMoveSelectScreen(u8 taskId)
&& eContestantStatus[gContestPlayerMonIndex].hasJudgesAttention)
{
// Highlight the text because it's a combo move
- moveNameBuffer = StringCopy(moveName, gText_ColorLightShadowDarkGrey);
+ moveNameBuffer = StringCopy(moveName, gText_ColorLightShadowDarkGray);
}
else if (move != MOVE_NONE
&& eContestantStatus[gContestPlayerMonIndex].prevMove == move
@@ -3203,27 +3208,25 @@ static void PrintContestMoveDescription(u16 a)
ContestBG_FillBoxWithIncrementingTile(0, categoryTile, 0x0b, 0x1f, 0x05, 0x01, 0x11, 0x01);
ContestBG_FillBoxWithIncrementingTile(0, categoryTile + 0x10, 0x0b, 0x20, 0x05, 0x01, 0x11, 0x01);
+ // Appeal hearts
if (gContestEffects[gContestMoves[a].effect].appeal == 0xFF)
numHearts = 0;
else
numHearts = gContestEffects[gContestMoves[a].effect].appeal / 10;
- if (numHearts > 8)
- numHearts = 8;
- // Filled-in hearts
- ContestBG_FillBoxWithTile(0, 0x5035, 0x15, 0x1f, 0x08, 0x01, 0x11);
- // Empty hearts
- ContestBG_FillBoxWithTile(0, 0x5012, 0x15, 0x1f, numHearts, 0x01, 0x11);
+ if (numHearts > MAX_CONTEST_MOVE_HEARTS)
+ numHearts = MAX_CONTEST_MOVE_HEARTS;
+ ContestBG_FillBoxWithTile(0, TILE_EMPTY_APPEAL_HEART, 0x15, 0x1f, MAX_CONTEST_MOVE_HEARTS, 0x01, 0x11);
+ ContestBG_FillBoxWithTile(0, TILE_FILLED_APPEAL_HEART, 0x15, 0x1f, numHearts, 0x01, 0x11);
+ // Jam hearts
if (gContestEffects[gContestMoves[a].effect].jam == 0xFF)
numHearts = 0;
else
numHearts = gContestEffects[gContestMoves[a].effect].jam / 10;
- if (numHearts > 8)
- numHearts = 8;
- // Filled-in hearts
- ContestBG_FillBoxWithTile(0, 0x5036, 0x15, 0x20, 0x08, 0x01, 0x11);
- // Empty hearts
- ContestBG_FillBoxWithTile(0, 0x5014, 0x15, 0x20, numHearts, 0x01, 0x11);
+ if (numHearts > MAX_CONTEST_MOVE_HEARTS)
+ numHearts = MAX_CONTEST_MOVE_HEARTS;
+ ContestBG_FillBoxWithTile(0, TILE_EMPTY_JAM_HEART, 0x15, 0x20, MAX_CONTEST_MOVE_HEARTS, 0x01, 0x11);
+ ContestBG_FillBoxWithTile(0, TILE_FILLED_JAM_HEART, 0x15, 0x20, numHearts, 0x01, 0x11);
FillWindowPixelBuffer(WIN_MOVE_DESCRIPTION, PIXEL_FILL(0));
Contest_PrintTextToBg0WindowStd(WIN_MOVE_DESCRIPTION, gContestEffectDescriptionPointers[gContestMoves[a].effect]);
diff --git a/src/contest_util.c b/src/contest_util.c
index decbded2c..88ab4a7d2 100644
--- a/src/contest_util.c
+++ b/src/contest_util.c
@@ -497,7 +497,7 @@ static void LoadContestMonName(u8 monIndex)
struct ContestPokemon *mon = &gContestMons[monIndex];
u8 *str = gDisplayedStringBattle;
if (monIndex == gContestPlayerMonIndex)
- str = StringCopy(gDisplayedStringBattle, gText_ColorDarkGrey);
+ str = StringCopy(gDisplayedStringBattle, gText_ColorDarkGray);
StringCopy(str, mon->nickname);
AddContestTextPrinter(monIndex, gDisplayedStringBattle, 0);
diff --git a/src/daycare.c b/src/daycare.c
index 34b864981..4199bfda6 100644
--- a/src/daycare.c
+++ b/src/daycare.c
@@ -23,6 +23,8 @@
#include "constants/moves.h"
#include "constants/region_map_sections.h"
+extern const struct Evolution gEvolutionTable[][EVOS_PER_MON];
+
// this file's functions
static void ClearDaycareMonMail(struct DaycareMail *mail);
static void SetInitialEggData(struct Pokemon *mon, u16 species, struct DayCare *daycare);
diff --git a/src/egg_hatch.c b/src/egg_hatch.c
index 7a3019f56..576e5c0d9 100644
--- a/src/egg_hatch.c
+++ b/src/egg_hatch.c
@@ -584,6 +584,9 @@ static void Task_EggHatchPlayBGM(u8 taskID)
PlayBGM(MUS_EVOLUTION);
DestroyTask(taskID);
// UB: task is destroyed, yet the value is incremented
+ #ifdef UBFIX
+ return;
+ #endif
}
gTasks[taskID].data[0]++;
}
diff --git a/src/evolution_scene.c b/src/evolution_scene.c
index 39e917161..08f816f4f 100644
--- a/src/evolution_scene.c
+++ b/src/evolution_scene.c
@@ -34,6 +34,8 @@
#include "constants/rgb.h"
#include "constants/items.h"
+extern struct Evolution gEvolutionTable[][EVOS_PER_MON];
+
struct EvoInfo
{
u8 preEvoSpriteId;
@@ -550,8 +552,6 @@ static void CreateShedinja(u16 preEvoSpecies, struct Pokemon* mon)
{
s32 i;
struct Pokemon* shedinja = &gPlayerParty[gPlayerPartyCount];
- const struct Evolution *evos;
- const struct Evolution *evos2;
CopyMon(&gPlayerParty[gPlayerPartyCount], mon, sizeof(struct Pokemon));
SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_SPECIES, &gEvolutionTable[preEvoSpecies][1].targetSpecies);
@@ -572,12 +572,8 @@ static void CreateShedinja(u16 preEvoSpecies, struct Pokemon* mon)
CalculateMonStats(&gPlayerParty[gPlayerPartyCount]);
CalculatePlayerPartyCount();
- // can't match it otherwise, ehh
- evos2 = gEvolutionTable[0];
- evos = evos2 + EVOS_PER_MON * preEvoSpecies;
-
- GetSetPokedexFlag(SpeciesToNationalPokedexNum(evos[1].targetSpecies), FLAG_SET_SEEN);
- GetSetPokedexFlag(SpeciesToNationalPokedexNum(evos[1].targetSpecies), FLAG_SET_CAUGHT);
+ GetSetPokedexFlag(SpeciesToNationalPokedexNum(gEvolutionTable[preEvoSpecies][1].targetSpecies), FLAG_SET_SEEN);
+ GetSetPokedexFlag(SpeciesToNationalPokedexNum(gEvolutionTable[preEvoSpecies][1].targetSpecies), FLAG_SET_CAUGHT);
if (GetMonData(shedinja, MON_DATA_SPECIES) == SPECIES_SHEDINJA
&& GetMonData(shedinja, MON_DATA_LANGUAGE) == LANGUAGE_JAPANESE
diff --git a/src/item.c b/src/item.c
index cc9a09ee0..156034262 100644
--- a/src/item.c
+++ b/src/item.c
@@ -280,10 +280,6 @@ bool8 AddBagItem(u16 itemId, u16 count)
{
// successfully added to already existing item's count
SetBagItemQuantity(&newItems[i].quantity, ownedCount + count);
-
- // goto SUCCESS_ADD_ITEM;
- // is equivalent but won't match
-
memcpy(itemPocket->itemSlots, newItems, itemPocket->capacity * sizeof(struct ItemSlot));
Free(newItems);
return TRUE;
@@ -303,7 +299,7 @@ bool8 AddBagItem(u16 itemId, u16 count)
// don't create another instance of the item if it's at max slot capacity and count is equal to 0
if (count == 0)
{
- goto SUCCESS_ADD_ITEM;
+ break;
}
}
}
@@ -334,7 +330,8 @@ bool8 AddBagItem(u16 itemId, u16 count)
{
// created a new slot and added quantity
SetBagItemQuantity(&newItems[i].quantity, count);
- goto SUCCESS_ADD_ITEM;
+ count = 0;
+ break;
}
}
}
@@ -345,11 +342,9 @@ bool8 AddBagItem(u16 itemId, u16 count)
return FALSE;
}
}
-
- SUCCESS_ADD_ITEM:
- memcpy(itemPocket->itemSlots, newItems, itemPocket->capacity * sizeof(struct ItemSlot));
- Free(newItems);
- return TRUE;
+ memcpy(itemPocket->itemSlots, newItems, itemPocket->capacity * sizeof(struct ItemSlot));
+ Free(newItems);
+ return TRUE;
}
}
@@ -553,7 +548,6 @@ bool8 AddPCItem(u16 itemId, u16 count)
void RemovePCItem(u8 index, u16 count)
{
- // UB: should use GetPCItemQuantity and SetPCItemQuantity functions
gSaveBlock1Ptr->pcItems[index].quantity -= count;
if (gSaveBlock1Ptr->pcItems[index].quantity == 0)
{
diff --git a/src/item_use.c b/src/item_use.c
index 19f50549e..c9087e929 100755
--- a/src/item_use.c
+++ b/src/item_use.c
@@ -910,7 +910,7 @@ static void ItemUseOnFieldCB_EscapeRope(u8 taskId)
bool8 CanUseDigOrEscapeRopeOnCurMap(void)
{
- if (gMapHeader.flags & MAP_ALLOW_ESCAPING)
+ if (gMapHeader.allowEscaping)
return TRUE;
else
return FALSE;
diff --git a/src/m4a.c b/src/m4a.c
index 3bb440f65..105312a40 100644
--- a/src/m4a.c
+++ b/src/m4a.c
@@ -1525,6 +1525,10 @@ void ply_xwave(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track
{
u32 wav;
+#ifdef UBFIX
+ wav = 0;
+#endif
+
READ_XCMD_BYTE(wav, 0) // UB: uninitialized variable
READ_XCMD_BYTE(wav, 1)
READ_XCMD_BYTE(wav, 2)
@@ -1592,6 +1596,10 @@ void ply_xcmd_0C(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *tra
{
u32 unk;
+#ifdef UBFIX
+ unk = 0;
+#endif
+
READ_XCMD_BYTE(unk, 0) // UB: uninitialized variable
READ_XCMD_BYTE(unk, 1)
@@ -1611,6 +1619,7 @@ void ply_xcmd_0C(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *tra
void ply_xcmd_0D(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track)
{
u32 unk;
+
#ifdef UBFIX
unk = 0;
#endif
@@ -1703,14 +1712,14 @@ void SetPokemonCryProgress(u32 val)
gPokemonCrySong.unkCmd0DParam = val;
}
-int IsPokemonCryPlaying(struct MusicPlayerInfo *mplayInfo)
+bool32 IsPokemonCryPlaying(struct MusicPlayerInfo *mplayInfo)
{
struct MusicPlayerTrack *track = mplayInfo->tracks;
if (track->chan && track->chan->track == track)
- return 1;
+ return TRUE;
else
- return 0;
+ return FALSE;
}
void SetPokemonCryChorus(s8 val)
diff --git a/src/main_menu.c b/src/main_menu.c
index 38859b860..38e7648d0 100644
--- a/src/main_menu.c
+++ b/src/main_menu.c
@@ -1387,11 +1387,9 @@ static void Task_NewGameBirchSpeechSub_WaitForLotad(u8 taskId)
switch (tState)
{
case 0:
- if (sprite->callback == SpriteCallbackDummy)
- {
- sprite->oam.affineMode = ST_OAM_AFFINE_OFF;
- goto incrementStateAndTimer;
- }
+ if (sprite->callback != SpriteCallbackDummy)
+ return;
+ sprite->oam.affineMode = ST_OAM_AFFINE_OFF;
break;
case 1:
if (gTasks[sBirchSpeechMainTaskId].tTimer >= 96)
@@ -1400,14 +1398,11 @@ static void Task_NewGameBirchSpeechSub_WaitForLotad(u8 taskId)
if (gTasks[sBirchSpeechMainTaskId].tTimer < 0x4000)
gTasks[sBirchSpeechMainTaskId].tTimer++;
}
- break;
- incrementStateAndTimer:
- default:
- tState++;
- if (gTasks[sBirchSpeechMainTaskId].tTimer < 0x4000)
- gTasks[sBirchSpeechMainTaskId].tTimer++;
- break;
+ return;
}
+ tState++;
+ if (gTasks[sBirchSpeechMainTaskId].tTimer < 0x4000)
+ gTasks[sBirchSpeechMainTaskId].tTimer++;
}
#undef tState
diff --git a/src/mystery_gift.c b/src/mystery_gift.c
index 1e00a5788..afbe50e4d 100644
--- a/src/mystery_gift.c
+++ b/src/mystery_gift.c
@@ -558,14 +558,12 @@ bool32 MG_PrintTextOnWindow1AndWaitButton(u8 *textState, const u8 *str)
{
case 0:
AddTextPrinterToWindow1(str);
- goto inc;
+ (*textState)++;
+ break;
case 1:
DrawDownArrow(1, 0xD0, 0x14, 1, FALSE, &sDownArrowCounterAndYCoordIdx[0], &sDownArrowCounterAndYCoordIdx[1]);
if (({JOY_NEW(A_BUTTON | B_BUTTON);}))
- {
- inc:
(*textState)++;
- }
break;
case 2:
DrawDownArrow(1, 0xD0, 0x14, 1, TRUE, &sDownArrowCounterAndYCoordIdx[0], &sDownArrowCounterAndYCoordIdx[1]);
@@ -574,7 +572,7 @@ bool32 MG_PrintTextOnWindow1AndWaitButton(u8 *textState, const u8 *str)
return TRUE;
case 0xFF:
*textState = 2;
- break;
+ return FALSE;
}
return FALSE;
}
@@ -809,8 +807,6 @@ static bool32 ValidateCardOrNews(bool32 cardOrNews)
static bool32 HandleLoadWonderCardOrNews(u8 * state, bool32 cardOrNews)
{
- s32 v0;
-
switch (*state)
{
case 0:
@@ -827,20 +823,18 @@ static bool32 HandleLoadWonderCardOrNews(u8 * state, bool32 cardOrNews)
case 1:
if (cardOrNews == 0)
{
- v0 = FadeToWonderCardMenu();
- check:
- if (v0 != 0)
+ if (!FadeToWonderCardMenu())
{
- goto done;
+ return FALSE;
}
- break;
}
else
{
- v0 = FadeToWonderNewsMenu();
- goto check;
+ if (!FadeToWonderNewsMenu())
+ {
+ return FALSE;
+ }
}
- done:
*state = 0;
return TRUE;
}
diff --git a/src/overworld.c b/src/overworld.c
index 600333a47..979ebb74c 100644
--- a/src/overworld.c
+++ b/src/overworld.c
@@ -962,7 +962,7 @@ static u16 GetCenterScreenMetatileBehavior(void)
bool32 Overworld_IsBikingAllowed(void)
{
- if (!(gMapHeader.flags & MAP_ALLOW_CYCLING))
+ if (!gMapHeader.allowCycling)
return FALSE;
else
return TRUE;
@@ -1687,7 +1687,7 @@ void CB2_ReturnToFieldFadeFromBlack(void)
static void FieldCB_FadeTryShowMapPopup(void)
{
- if (SHOW_MAP_NAME_ENABLED && SecretBaseMapPopupEnabled() == TRUE)
+ if (gMapHeader.showMapName == TRUE && SecretBaseMapPopupEnabled() == TRUE)
ShowMapNamePopup();
FieldCB_WarpExitFadeFromBlack();
}
@@ -1933,7 +1933,7 @@ static bool32 LoadMapInStepsLocal(u8 *state, bool32 a2)
(*state)++;
break;
case 11:
- if (SHOW_MAP_NAME_ENABLED && SecretBaseMapPopupEnabled() == TRUE)
+ if (gMapHeader.showMapName == TRUE && SecretBaseMapPopupEnabled() == TRUE)
ShowMapNamePopup();
(*state)++;
break;
diff --git a/src/player_pc.c b/src/player_pc.c
index e5c3c5a18..a040ba5b6 100644
--- a/src/player_pc.c
+++ b/src/player_pc.c
@@ -1245,7 +1245,6 @@ static void ItemStorage_DoItemSwap(u8 taskId, bool8 a)
{
s16 *data;
u16 b;
- u8 c;
data = gTasks[taskId].data;
b = (playerPCItemPageInfo.itemsAbove + playerPCItemPageInfo.cursorPos);
@@ -1253,21 +1252,17 @@ static void ItemStorage_DoItemSwap(u8 taskId, bool8 a)
DestroyListMenuTask(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos));
if (!a)
{
- c = gUnknown_0203BCC4->unk666;
- if (c != b)
+ if (gUnknown_0203BCC4->unk666 != b)
{
- if (c != b - 1)
+ if (gUnknown_0203BCC4->unk666 != b - 1)
{
- MoveItemSlotInList(gSaveBlock1Ptr->pcItems, c, b);
+ MoveItemSlotInList(gSaveBlock1Ptr->pcItems, gUnknown_0203BCC4->unk666, b);
ItemStorage_RefreshListMenu();
}
}
- else
- goto LABEL_SKIP_CURSOR_DECREMENT;
}
if (gUnknown_0203BCC4->unk666 < b)
playerPCItemPageInfo.cursorPos--;
- LABEL_SKIP_CURSOR_DECREMENT:
SetSwapLineSpritesInvisibility(gUnknown_0203BCC4->spriteIds, 7, TRUE);
gUnknown_0203BCC4->unk666 = 0xFF;
data[5] = ListMenuInit(&gMultiuseListMenuTemplate, playerPCItemPageInfo.itemsAbove, playerPCItemPageInfo.cursorPos);
diff --git a/src/pokemon.c b/src/pokemon.c
index b4eb6f01a..28b402216 100644
--- a/src/pokemon.c
+++ b/src/pokemon.c
@@ -1642,6 +1642,7 @@ static const u8 sMonFrontAnimIdsTable[] =
[SPECIES_LUGIA - 1] = ANIM_GROW_IN_STAGES,
[SPECIES_HO_OH - 1] = ANIM_GROW_VIBRATE,
[SPECIES_CELEBI - 1] = ANIM_RISING_WOBBLE,
+ [SPECIES_TREECKO - 1] = ANIM_V_SQUISH_AND_BOUNCE,
[SPECIES_GROVYLE - 1] = ANIM_V_STRETCH,
[SPECIES_SCEPTILE - 1] = ANIM_V_SHAKE,
[SPECIES_TORCHIC - 1] = ANIM_H_STRETCH,
diff --git a/src/pokemon_animation.c b/src/pokemon_animation.c
index 14a17437c..500916b0e 100644
--- a/src/pokemon_animation.c
+++ b/src/pokemon_animation.c
@@ -2604,9 +2604,9 @@ static void RotateUpSlamDown_0(struct Sprite *sprite)
{
TryFlipX(sprite);
sprite->data[7]--;
- sprite->pos2.x = Cos(sprite->data[7], sprite->data[6]) + sprite->data[6];
+ sprite->pos2.x = sprite->data[6] + Cos(sprite->data[7], sprite->data[6]);
- sprite->pos2.y = -(Sin(sprite->data[7], sprite->data[6] += 0)); // dummy += 0 is needed to match
+ sprite->pos2.y = -(Sin(sprite->data[7], sprite->data[6]));
HandleSetAffineData(sprite, 256, 256, (sprite->data[7] - 128) << 8);
if (sprite->data[7] <= 120)
@@ -2634,9 +2634,9 @@ static void RotateUpSlamDown_2(struct Sprite *sprite)
{
TryFlipX(sprite);
sprite->data[7] += 2;
- sprite->pos2.x = Cos(sprite->data[7], sprite->data[6]) + sprite->data[6];
+ sprite->pos2.x = sprite->data[6] + Cos(sprite->data[7], sprite->data[6]);
- sprite->pos2.y = -(Sin(sprite->data[7], sprite->data[6] += 0)); // dummy += 0 is needed to match
+ sprite->pos2.y = -(Sin(sprite->data[7], sprite->data[6]));
HandleSetAffineData(sprite, 256, 256, (sprite->data[7] - 128) << 8);
if (sprite->data[7] >= 128)
@@ -4066,16 +4066,15 @@ static void VerticalShakeLowTwice(struct Sprite *sprite)
u8 var8 = sprite->data[2];
u8 var9 = sprite->data[6];
u8 var5 = sVerticalShakeData[sprite->data[5]][0];
- u8 var2 = var5;
if (var5 != (u8)-1)
var5 = sprite->data[7];
- else
- var5 = (u8)-1; // needed to match
var6 = sVerticalShakeData[sprite->data[5]][1];
var7 = 0;
- if (var2 != (u8)-2)
+ if (sVerticalShakeData[sprite->data[5]][0] != (u8)-2)
var7 = (var6 - var9) * var5 / var6;
+ else
+ var7 = 0;
if (var5 == (u8)-1)
{
diff --git a/src/pokemon_size_record.c b/src/pokemon_size_record.c
index 4beb9c83f..7c88e5bf1 100644
--- a/src/pokemon_size_record.c
+++ b/src/pokemon_size_record.c
@@ -97,7 +97,7 @@ static void FormatMonSizeRecord(u8 *string, u32 size)
{
#ifdef UNITS_IMPERIAL
//Convert size from centimeters to inches
- size = (double)(size * 10) / (CM_PER_INCH * 10);
+ size = (f64)(size * 10) / (CM_PER_INCH * 10);
#endif
string = ConvertIntToDecimalStringN(string, size / 10, STR_CONV_MODE_LEFT_ALIGN, 8);
diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c
index e5720d914..c82caf0b0 100644
--- a/src/pokemon_storage_system.c
+++ b/src/pokemon_storage_system.c
@@ -5437,15 +5437,16 @@ static bool32 WaitForWallpaperGfxLoad(void)
static void DrawWallpaper(const void *tilemap, s8 direction, u8 offset)
{
- s16 var = (offset * 2) + 3;
+ s16 var = offset * 256;
+ s16 var2 = (offset * 2) + 3;
s16 x = ((sStorage->bg2_X / 8 + 10) + (direction * 24)) & 0x3F;
- CopyRectToBgTilemapBufferRect(2, tilemap, 0, 0, 0x14, 0x12, x, 2, 0x14, 0x12, 0x11, offset << 8, var);
+ CopyRectToBgTilemapBufferRect(2, tilemap, 0, 0, 0x14, 0x12, x, 2, 0x14, 0x12, 0x11, var, var2);
if (direction == 0)
return;
if (direction > 0)
- x *= 1, x += 0x14; // x * 1 is needed to match, but can be safely removed as it makes no functional difference
+ x += 0x14;
else
x -= 4;
diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c
index 8f16321b2..31505b7c9 100644
--- a/src/pokemon_summary_screen.c
+++ b/src/pokemon_summary_screen.c
@@ -119,6 +119,11 @@ enum
SPRITE_ARR_ID_COUNT = SPRITE_ARR_ID_MOVE_SELECTOR2 + MOVE_SELECTOR_SPRITES_COUNT
};
+#define TILE_EMPTY_APPEAL_HEART 0x1039
+#define TILE_FILLED_APPEAL_HEART 0x103A
+#define TILE_FILLED_JAM_HEART 0x103C
+#define TILE_EMPTY_JAM_HEART 0x103D
+
static EWRAM_DATA struct PokemonSummaryScreenData
{
/*0x00*/ union {
@@ -2645,29 +2650,30 @@ static void DrawContestMoveHearts(u16 move)
if (move != MOVE_NONE)
{
+ // Draw appeal hearts
u8 effectValue = gContestEffects[gContestMoves[move].effect].appeal;
if (effectValue != 0xFF)
effectValue /= 10;
- for (i = 0; i < 8; i++)
+ for (i = 0; i < MAX_CONTEST_MOVE_HEARTS; i++)
{
if (effectValue != 0xFF && i < effectValue)
- tilemap[(i / 4 * 32) + (i & 3) + 0x1E6] = 0x103A;
+ tilemap[(i / 4 * 32) + (i & 3) + 0x1E6] = TILE_FILLED_APPEAL_HEART;
else
- tilemap[(i / 4 * 32) + (i & 3) + 0x1E6] = 0x1039;
+ tilemap[(i / 4 * 32) + (i & 3) + 0x1E6] = TILE_EMPTY_APPEAL_HEART;
}
+ // Draw jam hearts
effectValue = gContestEffects[gContestMoves[move].effect].jam;
-
if (effectValue != 0xFF)
effectValue /= 10;
- for (i = 0; i < 8; i++)
+ for (i = 0; i < MAX_CONTEST_MOVE_HEARTS; i++)
{
if (effectValue != 0xFF && i < effectValue)
- tilemap[(i / 4 * 32) + (i & 3) + 0x226] = 0x103C;
+ tilemap[(i / 4 * 32) + (i & 3) + 0x226] = TILE_FILLED_JAM_HEART;
else
- tilemap[(i / 4 * 32) + (i & 3) + 0x226] = 0x103D;
+ tilemap[(i / 4 * 32) + (i & 3) + 0x226] = TILE_EMPTY_JAM_HEART;
}
}
}
diff --git a/src/region_map.c b/src/region_map.c
index bec51ebf0..27e035199 100644
--- a/src/region_map.c
+++ b/src/region_map.c
@@ -1007,7 +1007,7 @@ static void InitMapBasedOnPlayerLocation(void)
break;
case MAP_TYPE_UNDERGROUND:
case MAP_TYPE_UNKNOWN:
- if (gMapHeader.flags & MAP_ALLOW_ESCAPING)
+ if (gMapHeader.allowEscaping)
{
mapHeader = Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->escapeWarp.mapGroup, gSaveBlock1Ptr->escapeWarp.mapNum);
gRegionMap->mapSecId = mapHeader->regionMapSectionId;
diff --git a/src/rotating_gate.c b/src/rotating_gate.c
index 22a0b0bdf..36c23c2a5 100644
--- a/src/rotating_gate.c
+++ b/src/rotating_gate.c
@@ -670,7 +670,8 @@ static void RotatingGate_RotateInDirection(u8 gateId, u32 rotationDirection)
}
else
{
- orientation = ++orientation % GATE_ORIENTATION_MAX;
+ orientation++;
+ orientation = orientation % GATE_ORIENTATION_MAX;
}
RotatingGate_SetGateOrientation(gateId, orientation);
}
diff --git a/src/roulette.c b/src/roulette.c
index cf27fdf9b..adde16199 100644
--- a/src/roulette.c
+++ b/src/roulette.c
@@ -275,7 +275,7 @@ struct RouletteTable
struct Taillow taillow;
u16 ballSpeed;
u16 baseTravelDist;
- float var1C;
+ f32 var1C;
};
struct GridSelection
@@ -340,13 +340,13 @@ static EWRAM_DATA struct Roulette
s16 ballTravelDistFast;
u16 ballTravelDistMed;
u16 ballTravelDistSlow;
- float ballAngle;
- float ballAngleSpeed;
- float ballAngleAccel;
- float ballDistToCenter;
- float ballFallSpeed;
- float ballFallAccel;
- float varA0;
+ f32 ballAngle;
+ f32 ballAngleSpeed;
+ f32 ballAngleAccel;
+ f32 ballDistToCenter;
+ f32 ballFallSpeed;
+ f32 ballFallAccel;
+ f32 varA0;
u8 playTaskId;
u8 spinTaskId;
u8 filler_1[2];
@@ -2896,7 +2896,9 @@ static const union AnimCmd sAnim_CreditDigit[] =
ANIMCMD_FRAME(18, 0), // 9
// BUG: Animation not terminated properly
// Doesn't matter in practice, the frames are set directly and not looped
- //ANIMCMD_END
+#ifdef BUGFIX
+ ANIMCMD_END
+#endif
};
static const union AnimCmd *const sAnims_CreditDigit[] =
@@ -3948,7 +3950,7 @@ static s16 UpdateBallRelativeWheelAngle(struct Sprite *sprite)
static u8 UpdateSlotBelowBall(struct Sprite *sprite)
{
- sRoulette->hitSlot = UpdateBallRelativeWheelAngle(sprite) / (float) DEGREES_PER_SLOT;
+ sRoulette->hitSlot = UpdateBallRelativeWheelAngle(sprite) / (f32)DEGREES_PER_SLOT;
return sRoulette->hitSlot;
}
@@ -4050,7 +4052,7 @@ static void SpriteCB_UnstickBall_ShroomishBallFall(struct Sprite *sprite)
static void SpriteCB_UnstickBall_Shroomish(struct Sprite *sprite)
{
- float slotOffset, ballFallDist, ballFallSpeed;
+ f32 slotOffset, ballFallDist, ballFallSpeed;
UpdateBallPos(sprite);
switch (sprite->sBallAngle)
@@ -4233,7 +4235,7 @@ static void SpriteCB_RollBall_TryLand(struct Sprite *sprite)
}
else // fall left
{
- float temp;
+ f32 temp;
sRoulette->ballAngleSpeed = (temp = sRouletteTables[sRoulette->tableId].var1C) * 2.0f;
slotId = (sRoulette->hitSlot + NUM_ROULETTE_SLOTS - 1) % NUM_ROULETTE_SLOTS;
sRoulette->stuckHitSlot = sRoulette->hitSlot;
@@ -4279,7 +4281,7 @@ static void SpriteCB_RollBall_Slow(struct Sprite *sprite)
{
// Reached slot to land in
sRoulette->ballAngleAccel = 0.0f;
- sRoulette->ballAngleSpeed -= (float)(sRouletteTables[sRoulette->tableId].wheelSpeed)
+ sRoulette->ballAngleSpeed -= (f32)(sRouletteTables[sRoulette->tableId].wheelSpeed)
/ (sRouletteTables[sRoulette->tableId].wheelDelay + 1);
sprite->sState = 4;
sprite->callback = SpriteCB_RollBall_TryLand;
@@ -4304,8 +4306,8 @@ static void SpriteCB_RollBall_Medium(struct Sprite *sprite)
if (sRoulette->ballDistToCenter > 40.0f)
return;
- sRoulette->ballFallSpeed = -(4.0f / (float)(sRoulette->ballTravelDistSlow));
- sRoulette->ballAngleAccel = -(sRoulette->ballAngleSpeed / (float)(sRoulette->ballTravelDistSlow));
+ sRoulette->ballFallSpeed = -(4.0f / (f32)(sRoulette->ballTravelDistSlow));
+ sRoulette->ballAngleAccel = -(sRoulette->ballAngleSpeed / (f32)(sRoulette->ballTravelDistSlow));
sprite->animNum = 2;
sprite->animBeginning = TRUE;
sprite->animEnded = FALSE;
@@ -4320,8 +4322,8 @@ static void SpriteCB_RollBall_Fast(struct Sprite *sprite)
return;
m4aSongNumStartOrChange(SE_ROULETTE_BALL2);
- sRoulette->ballFallSpeed = -(20.0f / (float)(sRoulette->ballTravelDistMed));
- sRoulette->ballAngleAccel = ((1.0f - sRoulette->ballAngleSpeed) / (float)(sRoulette->ballTravelDistMed));
+ sRoulette->ballFallSpeed = -(20.0f / (f32)(sRoulette->ballTravelDistMed));
+ sRoulette->ballAngleAccel = ((1.0f - sRoulette->ballAngleSpeed) / (f32)(sRoulette->ballTravelDistMed));
sprite->animNum = 1;
sprite->animBeginning = TRUE;
sprite->animEnded = FALSE;
@@ -4558,7 +4560,7 @@ static void SpriteCB_ShroomishShakeScreen(struct Sprite *sprite)
static void SpriteCB_ShroomishFall(struct Sprite *sprite)
{
- float timer;
+ f32 timer;
sprite->data[1]++;
timer = sprite->data[1];
sprite->pos2.y = timer * 0.039f * timer;
diff --git a/src/siirtc.c b/src/siirtc.c
index 5c153a841..5f4fc0a23 100644
--- a/src/siirtc.c
+++ b/src/siirtc.c
@@ -71,6 +71,7 @@ static bool8 sLocked;
static int WriteCommand(u8 value);
static int WriteData(u8 value);
static u8 ReadData();
+
static void EnableGpioPortRead();
static void DisableGpioPortRead();
@@ -98,8 +99,12 @@ u8 SiiRtcProbe(void)
errorCode = 0;
+#ifdef BUGFIX
+ if (!(rtc.status & SIIRTCINFO_24HOUR) || (rtc.status & SIIRTCINFO_POWER))
+#else
if ((rtc.status & (SIIRTCINFO_POWER | SIIRTCINFO_24HOUR)) == SIIRTCINFO_POWER
|| (rtc.status & (SIIRTCINFO_POWER | SIIRTCINFO_24HOUR)) == 0)
+#endif
{
// The RTC is in 12-hour mode. Reset it and switch to 24-hour mode.
@@ -131,7 +136,7 @@ u8 SiiRtcProbe(void)
bool8 SiiRtcReset(void)
{
- u8 result;
+ bool8 result;
struct SiiRtcInfo rtc;
if (sLocked == TRUE)
@@ -392,7 +397,11 @@ static int WriteCommand(u8 value)
GPIO_PORT_DATA = (temp << 1) | SCK_HI | CS_HI;
}
- // control reaches end of non-void function
+ // Nothing uses the returned value from this function,
+ // so the undefined behavior is harmless in the vanilla game.
+#ifdef UBFIX
+ return 0;
+#endif
}
static int WriteData(u8 value)
@@ -409,7 +418,11 @@ static int WriteData(u8 value)
GPIO_PORT_DATA = (temp << 1) | SCK_HI | CS_HI;
}
- // control reaches end of non-void function
+ // Nothing uses the returned value from this function,
+ // so the undefined behavior is harmless in the vanilla game.
+#ifdef UBFIX
+ return 0;
+#endif
}
static u8 ReadData()
@@ -418,6 +431,10 @@ static u8 ReadData()
u8 temp;
u8 value;
+#ifdef UBFIX
+ value = 0;
+#endif
+
for (i = 0; i < 8; i++)
{
GPIO_PORT_DATA = CS_HI;
@@ -428,7 +445,7 @@ static u8 ReadData()
GPIO_PORT_DATA = SCK_HI | CS_HI;
temp = ((GPIO_PORT_DATA & SIO_HI) >> 1);
- value = (value >> 1) | (temp << 7); // UB: accessing uninitialized var
+ value = (value >> 1) | (temp << 7);
}
return value;
@@ -436,10 +453,10 @@ static u8 ReadData()
static void EnableGpioPortRead()
{
- GPIO_PORT_READ_ENABLE = 1;
+ GPIO_PORT_READ_ENABLE = TRUE;
}
static void DisableGpioPortRead()
{
- GPIO_PORT_READ_ENABLE = 0;
+ GPIO_PORT_READ_ENABLE = FALSE;
}
diff --git a/src/strings.c b/src/strings.c
index 18cf31fb7..4987e32d2 100644
--- a/src/strings.c
+++ b/src/strings.c
@@ -1229,7 +1229,7 @@ ALIGNED(4) const u8 gText_Facility[] = _("{STR_VAR_1}");
const u8 gText_Give[] = _("Give");
const u8 gText_NoNeed[] = _("No need");
-const u8 gText_ColorLightShadowDarkGrey[] = _("{COLOR LIGHT_GRAY}{SHADOW DARK_GRAY}");
+const u8 gText_ColorLightShadowDarkGray[] = _("{COLOR LIGHT_GRAY}{SHADOW DARK_GRAY}");
const u8 gText_ColorBlue[] = _("{COLOR BLUE}");
const u8 gText_ColorTransparent[] = _("{HIGHLIGHT TRANSPARENT}{COLOR TRANSPARENT}");
const u8 gText_CDot[] = _("C.");
@@ -1239,9 +1239,9 @@ const u8 gText_PreliminaryResults[] = _("The preliminary results!");
const u8 gText_Round2Results[] = _("Round 2 results!");
const u8 gText_ContestantsMonWon[] = _("{STR_VAR_1}'s {STR_VAR_2} won!");
const u8 gText_CommunicationStandby[] = _("Communication standby…");
-const u8 gText_ColorDarkGrey[] = _("{COLOR DARK_GRAY}");
+const u8 gText_ColorDarkGray[] = _("{COLOR DARK_GRAY}");
const u8 gText_ColorDynamic6WhiteDynamic5[] = _("{COLOR_HIGHLIGHT_SHADOW DYNAMIC_COLOR6 WHITE DYNAMIC_COLOR5}"); // Unused
-const u8 gText_HighlightDarkGrey[] = _("{HIGHLIGHT DARK_GRAY}");
+const u8 gText_HighlightDarkGray[] = _("{HIGHLIGHT DARK_GRAY}");
const u8 gText_EmptySpace2[] = _(" "); // Unused
const u8 gText_DynColor2Male[] = _("{COLOR DYNAMIC_COLOR2}♂");
const u8 gText_DynColor1Female[] = _("{COLOR DYNAMIC_COLOR1}♀");
diff --git a/src/union_room.c b/src/union_room.c
index 06d3321c3..395650f28 100644
--- a/src/union_room.c
+++ b/src/union_room.c
@@ -319,8 +319,13 @@ static void StringExpandPlaceholders_AwaitingCommFromAnother(u8 *dst, u8 caseId)
case ACTIVITY_CONTEST_CUTE:
case ACTIVITY_CONTEST_SMART:
case ACTIVITY_CONTEST_TOUGH:
- // UB: argument *dst isn't used, instead it always prints to gStringVar4
+ // BUG: argument *dst isn't used, instead it always prints to gStringVar4
+ // not an issue in practice since Gamefreak never used any other arguments here besides gStringVar4
+ #ifndef BUGFIX
StringExpandPlaceholders(gStringVar4, sText_AwaitingCommunication);
+ #else
+ StringExpandPlaceholders(dst, sText_AwaitingCommunication);
+ #endif
break;
}
}
diff --git a/src/union_room_chat.c b/src/union_room_chat.c
index fb875bbb4..8e9f78280 100755
--- a/src/union_room_chat.c
+++ b/src/union_room_chat.c
@@ -2984,7 +2984,7 @@ static void HideKeyboardSwapMenu(void)
static void PrintChatMessage(u16 row, u8 *str, u8 colorIdx)
{
- // colorIdx: 0 = grey, 1 = red, 2 = green, 3 = blue
+ // colorIdx: 0 = gray, 1 = red, 2 = green, 3 = blue
u8 color[3];
color[0] = TEXT_COLOR_WHITE;
color[1] = colorIdx * 2 + 2;
diff --git a/src/wild_encounter.c b/src/wild_encounter.c
index 767fbe4e7..8bcb17605 100644
--- a/src/wild_encounter.c
+++ b/src/wild_encounter.c
@@ -162,7 +162,7 @@ static u8 ChooseWildMonIndex_Land(void)
return 8;
else if (rand >= ENCOUNTER_CHANCE_LAND_MONS_SLOT_8 && rand < ENCOUNTER_CHANCE_LAND_MONS_SLOT_9)
return 9;
- else if (rand == ENCOUNTER_CHANCE_LAND_MONS_SLOT_9)
+ else if (rand >= ENCOUNTER_CHANCE_LAND_MONS_SLOT_9 && rand < ENCOUNTER_CHANCE_LAND_MONS_SLOT_10)
return 10;
else
return 11;
@@ -215,7 +215,7 @@ static u8 ChooseWildMonIndex_Fishing(u8 rod)
wildMonIndex = 7;
if (rand >= ENCOUNTER_CHANCE_FISHING_MONS_SUPER_ROD_SLOT_7 && rand < ENCOUNTER_CHANCE_FISHING_MONS_SUPER_ROD_SLOT_8)
wildMonIndex = 8;
- if (rand == ENCOUNTER_CHANCE_FISHING_MONS_SUPER_ROD_SLOT_8)
+ if (rand >= ENCOUNTER_CHANCE_FISHING_MONS_SUPER_ROD_SLOT_8 && rand < ENCOUNTER_CHANCE_FISHING_MONS_SUPER_ROD_SLOT_9)
wildMonIndex = 9;
break;
}