Merge pull request #1437 from ExpoSeed/bugfixes
Various BUGFIXes and UBFIXes
This commit is contained in:
commit
9e690c07ed
10 changed files with 48 additions and 9 deletions
|
@ -1877,9 +1877,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;
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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++)
|
||||
|
|
|
@ -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]++;
|
||||
}
|
||||
|
|
|
@ -548,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)
|
||||
{
|
||||
|
|
|
@ -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[] =
|
||||
|
|
|
@ -417,6 +417,9 @@ static u8 ReadData()
|
|||
u8 i;
|
||||
u8 temp;
|
||||
u8 value;
|
||||
#ifdef UBFIX
|
||||
value = 0;
|
||||
#endif
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
|
@ -428,7 +431,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); // UB: value is uninitialized on first iteration
|
||||
}
|
||||
|
||||
return value;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue