From 106a89eace1cb4de5f7b45683d14c484c4cfdd90 Mon Sep 17 00:00:00 2001 From: hjk321 <37224753+hjk321@users.noreply.github.com> Date: Sat, 27 Apr 2019 16:41:37 -0600 Subject: [PATCH 1/5] Document magic number from atk04_critcalc --- src/battle_script_commands.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 7e783bef5..f7eed0760 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1276,8 +1276,8 @@ static void atk04_critcalc(void) + 2 * (holdEffect == HOLD_EFFECT_LUCKY_PUNCH && gBattleMons[gBattlerAttacker].species == SPECIES_CHANSEY) + 2 * (holdEffect == HOLD_EFFECT_STICK && gBattleMons[gBattlerAttacker].species == SPECIES_FARFETCHD); - if (critChance > 4) - critChance = 4; + if (critChance > ARRAY_COUNT(sCriticalHitChance) - 1 ) + critChance = ARRAY_COUNT(sCriticalHitChance) - 1; if ((gBattleMons[gBattlerTarget].ability != ABILITY_BATTLE_ARMOR && gBattleMons[gBattlerTarget].ability != ABILITY_SHELL_ARMOR) && !(gStatuses3[gBattlerAttacker] & STATUS3_CANT_SCORE_A_CRIT) From 438c5432aa2c14cb54402071aa8b8cc3557decf5 Mon Sep 17 00:00:00 2001 From: hjk321 <37224753+hjk321@users.noreply.github.com> Date: Sat, 27 Apr 2019 16:45:32 -0600 Subject: [PATCH 2/5] Document MON_DATA_10 --- include/pokemon.h | 2 +- src/evolution_scene.c | 2 +- src/pokemon.c | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/pokemon.h b/include/pokemon.h index 26d715d89..c5fea6df7 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -14,7 +14,7 @@ #define MON_DATA_OT_NAME 7 #define MON_DATA_MARKINGS 8 #define MON_DATA_CHECKSUM 9 -#define MON_DATA_10 10 +#define MON_DATA_ENCRYPT_SEPARATOR 10 #define MON_DATA_SPECIES 11 #define MON_DATA_HELD_ITEM 12 #define MON_DATA_MOVE1 13 diff --git a/src/evolution_scene.c b/src/evolution_scene.c index 1e120bc90..96ca2ed1c 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -556,7 +556,7 @@ static void CreateShedinja(u16 preEvoSpecies, struct Pokemon* mon) SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_NICKNAME, (gSpeciesNames[gEvolutionTable[preEvoSpecies][1].targetSpecies])); SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_HELD_ITEM, (&data)); SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_MARKINGS, (&data)); - SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_10, (&data)); + SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_ENCRYPT_SEPARATOR, (&data)); for (i = MON_DATA_COOL_RIBBON; i < MON_DATA_COOL_RIBBON + 5; i++) SetMonData(&gPlayerParty[gPlayerPartyCount], i, (&data)); diff --git a/src/pokemon.c b/src/pokemon.c index fc9a0843f..4479fa448 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -3642,7 +3642,8 @@ u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data) struct PokemonSubstruct2 *substruct2 = NULL; struct PokemonSubstruct3 *substruct3 = NULL; - if (field > MON_DATA_10) + // Any field greater than MON_DATA_ENCRYPT_SEPARATOR is encrypted and must be treated as such + if (field > MON_DATA_ENCRYPT_SEPARATOR) { substruct0 = &(GetSubstruct(boxMon, boxMon->personality, 0)->type0); substruct1 = &(GetSubstruct(boxMon, boxMon->personality, 1)->type1); @@ -3736,7 +3737,7 @@ u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data) case MON_DATA_CHECKSUM: retVal = boxMon->checksum; break; - case MON_DATA_10: + case MON_DATA_ENCRYPT_SEPARATOR: retVal = boxMon->unknown; break; case MON_DATA_SPECIES: @@ -3977,7 +3978,7 @@ u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data) break; } - if (field > MON_DATA_10) + if (field > MON_DATA_ENCRYPT_SEPARATOR) EncryptBoxMon(boxMon); return retVal; @@ -4040,7 +4041,7 @@ void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg) struct PokemonSubstruct2 *substruct2 = NULL; struct PokemonSubstruct3 *substruct3 = NULL; - if (field > MON_DATA_10) + if (field > MON_DATA_ENCRYPT_SEPARATOR) { substruct0 = &(GetSubstruct(boxMon, boxMon->personality, 0)->type0); substruct1 = &(GetSubstruct(boxMon, boxMon->personality, 1)->type1); @@ -4099,7 +4100,7 @@ void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg) case MON_DATA_CHECKSUM: SET16(boxMon->checksum); break; - case MON_DATA_10: + case MON_DATA_ENCRYPT_SEPARATOR: SET16(boxMon->unknown); break; case MON_DATA_SPECIES: @@ -4295,7 +4296,7 @@ void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg) break; } - if (field > MON_DATA_10) + if (field > MON_DATA_ENCRYPT_SEPARATOR) { boxMon->checksum = CalculateBoxMonChecksum(boxMon); EncryptBoxMon(boxMon); From ee4049d93edfeb24a315c40e3d6849278cdb33e5 Mon Sep 17 00:00:00 2001 From: hjk321 <37224753+hjk321@users.noreply.github.com> Date: Thu, 2 May 2019 22:26:11 -0500 Subject: [PATCH 3/5] Fix indentation Error --- src/battle_script_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index f7eed0760..d2496881e 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1277,7 +1277,7 @@ static void atk04_critcalc(void) + 2 * (holdEffect == HOLD_EFFECT_STICK && gBattleMons[gBattlerAttacker].species == SPECIES_FARFETCHD); if (critChance > ARRAY_COUNT(sCriticalHitChance) - 1 ) - critChance = ARRAY_COUNT(sCriticalHitChance) - 1; + critChance = ARRAY_COUNT(sCriticalHitChance) - 1; if ((gBattleMons[gBattlerTarget].ability != ABILITY_BATTLE_ARMOR && gBattleMons[gBattlerTarget].ability != ABILITY_SHELL_ARMOR) && !(gStatuses3[gBattlerAttacker] & STATUS3_CANT_SCORE_A_CRIT) From 26114d45793c14602e7c9f565461bddac1d3fc40 Mon Sep 17 00:00:00 2001 From: hjk321 <37224753+hjk321@users.noreply.github.com> Date: Fri, 3 May 2019 07:56:44 -0500 Subject: [PATCH 4/5] Update comparison --- src/battle_script_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index d2496881e..51b658250 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1276,7 +1276,7 @@ static void atk04_critcalc(void) + 2 * (holdEffect == HOLD_EFFECT_LUCKY_PUNCH && gBattleMons[gBattlerAttacker].species == SPECIES_CHANSEY) + 2 * (holdEffect == HOLD_EFFECT_STICK && gBattleMons[gBattlerAttacker].species == SPECIES_FARFETCHD); - if (critChance > ARRAY_COUNT(sCriticalHitChance) - 1 ) + if (critChance >= ARRAY_COUNT(sCriticalHitChance)) critChance = ARRAY_COUNT(sCriticalHitChance) - 1; if ((gBattleMons[gBattlerTarget].ability != ABILITY_BATTLE_ARMOR && gBattleMons[gBattlerTarget].ability != ABILITY_SHELL_ARMOR) From fe59902b8a0608eafb746222e8e6800cad2fca8b Mon Sep 17 00:00:00 2001 From: huderlem Date: Fri, 3 May 2019 18:17:45 -0500 Subject: [PATCH 5/5] Fix indentation --- src/battle_script_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 51b658250..837fb5bac 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1277,7 +1277,7 @@ static void atk04_critcalc(void) + 2 * (holdEffect == HOLD_EFFECT_STICK && gBattleMons[gBattlerAttacker].species == SPECIES_FARFETCHD); if (critChance >= ARRAY_COUNT(sCriticalHitChance)) - critChance = ARRAY_COUNT(sCriticalHitChance) - 1; + critChance = ARRAY_COUNT(sCriticalHitChance) - 1; if ((gBattleMons[gBattlerTarget].ability != ABILITY_BATTLE_ARMOR && gBattleMons[gBattlerTarget].ability != ABILITY_SHELL_ARMOR) && !(gStatuses3[gBattlerAttacker] & STATUS3_CANT_SCORE_A_CRIT)