2017-12-12 17:50:34 -08:00
# Bugs and Glitches
2017-12-12 17:15:07 -08:00
2017-12-28 08:50:02 -08:00
These are known bugs and glitches in the original Pokémon Crystal game: code that clearly does not work as intended, or that only works in limited circumstances but has the possibility to fail or crash.
2018-12-30 22:03:38 -08:00
Fixes are written in the `diff` format. If you've used Git before, this should look familiar:
2018-07-27 02:25:29 -07:00
```diff
this is some code
-delete red - lines
+add green + lines
```
2020-08-29 10:27:44 -07:00
Fixes in the [multi-player battle engine ](#multi-player-battle-engine ) category will break compatibility with standard Pokémon Gold/Silver/Crystal for link battles, unless otherwise noted. This can be avoided by writing more complicated fixes that only apply if the value at `[wLinkMode]` is not `LINK_COLOSSEUM` . That's how Crystal itself fixed two bugs in Gold and Silver regarding the moves [Reflect and Light Screen ](#reflect-and-light-screen-can-make-special-defense-wrap-around-above-1024 ) and [Present ](#present-damage-is-incorrect-in-link-battles ).
2019-02-17 10:18:38 -08:00
2017-12-12 17:15:07 -08:00
2017-12-12 21:28:48 -08:00
## Contents
2020-08-29 10:27:44 -07:00
- [Multi-player battle engine ](#multi-player-battle-engine )
2022-07-21 16:48:28 -07:00
- [Perish Song and Spikes can leave a Pokémon with 0 HP and not faint ](#perish-song-and-spikes-can-leave-a-pok%C3%A9mon-with-0-hp-and-not-faint )
2020-08-29 10:27:44 -07:00
- [Thick Club and Light Ball can make (Special) Attack wrap around above 1024 ](#thick-club-and-light-ball-can-make-special-attack-wrap-around-above-1024 )
- [Metal Powder can increase damage taken with boosted (Special) Defense ](#metal-powder-can-increase-damage-taken-with-boosted-special-defense )
- [Reflect and Light Screen can make (Special) Defense wrap around above 1024 ](#reflect-and-light-screen-can-make-special-defense-wrap-around-above-1024 )
- [Moves with a 100% secondary effect chance will not trigger it in 1/256 uses ](#moves-with-a-100-secondary-effect-chance-will-not-trigger-it-in-1256-uses )
- [Belly Drum sharply boosts Attack even with under 50% HP ](#belly-drum-sharply-boosts-attack-even-with-under-50-hp )
2022-07-21 16:48:28 -07:00
- [Berserk Gene's confusion lasts for 256 turns or the previous Pokémon's confusion count ](#berserk-genes-confusion-lasts-for-256-turns-or-the-previous-pok%C3%A9mons-confusion-count )
2020-08-29 10:27:44 -07:00
- [Confusion damage is affected by type-boosting items and Explosion/Self-Destruct doubling ](#confusion-damage-is-affected-by-type-boosting-items-and-explosionself-destruct-doubling )
- [Moves that lower Defense can do so after breaking a Substitute ](#moves-that-lower-defense-can-do-so-after-breaking-a-substitute )
- [Counter and Mirror Coat still work if the opponent uses an item ](#counter-and-mirror-coat-still-work-if-the-opponent-uses-an-item )
- [A Disabled but PP Up– enhanced move may not trigger Struggle ](#a-disabled-but-pp-upenhanced-move-may-not-trigger-struggle )
2022-07-21 16:48:28 -07:00
- [A Pokémon that fainted from Pursuit will have its old status condition when revived ](#a-pok%C3%A9mon-that-fainted-from-pursuit-will-have-its-old-status-condition-when-revived )
2020-08-29 10:27:44 -07:00
- [Lock-On and Mind Reader don't always bypass Fly and Dig ](#lock-on-and-mind-reader-dont-always-bypass-fly-and-dig )
- [Beat Up can desynchronize link battles ](#beat-up-can-desynchronize-link-battles )
2022-07-21 16:48:28 -07:00
- [Beat Up works incorrectly with only one Pokémon in the party ](#beat-up-works-incorrectly-with-only-one-pok%C3%A9mon-in-the-party )
2020-08-29 10:27:44 -07:00
- [Beat Up may fail to raise Substitute ](#beat-up-may-fail-to-raise-substitute )
- [Beat Up may trigger King's Rock even if it failed ](#beat-up-may-trigger-kings-rock-even-if-it-failed )
- [Present damage is incorrect in link battles ](#present-damage-is-incorrect-in-link-battles )
2022-01-24 17:48:21 -08:00
- [Return and Frustration deal no damage when the user's happiness is low or high, respectively ](#return-and-frustration-deal-no-damage-when-the-users-happiness-is-low-or-high-respectively )
2020-08-29 10:27:44 -07:00
- [Dragon Scale, not Dragon Fang, boosts Dragon-type moves ](#dragon-scale-not-dragon-fang-boosts-dragon-type-moves )
2022-07-21 16:48:28 -07:00
- [Switching out or switching against a Pokémon with max HP below 4 freezes the game ](#switching-out-or-switching-against-a-pok%C3%A9mon-with-max-HP-below-4-freezes-the-game )
2022-01-10 18:32:41 -08:00
- [Moves that do damage and increase your stats do not increase stats after a KO ](#moves-that-do-damage-and-increase-your-stats-do-not-increase-stats-after-a-ko )
2020-08-29 10:27:44 -07:00
- [HP bar animation is slow for high HP ](#hp-bar-animation-is-slow-for-high-hp )
- [HP bar animation off-by-one error for low HP ](#hp-bar-animation-off-by-one-error-for-low-hp )
- [Single-player battle engine ](#single-player-battle-engine )
2022-07-21 16:48:28 -07:00
- [A Transformed Pokémon can use Sketch and learn otherwise unobtainable moves ](#a-transformed-pok%C3%A9mon-can-use-sketch-and-learn-otherwise-unobtainable-moves )
- [Catching a Transformed Pokémon always catches a Ditto ](#catching-a-transformed-pok%C3%A9mon-always-catches-a-ditto )
- [Experience underflow for level 1 Pokémon with Medium-Slow growth rate ](#experience-underflow-for-level-1-pok%C3%A9mon-with-medium-slow-growth-rate )
- [The Dude's catching tutorial may crash if his Poké Ball can't be used ](#the-dudes-catching-tutorial-may-crash-if-his-pok%C3%A9-ball-cant-be-used )
2020-08-29 10:27:44 -07:00
- [BRN/PSN/PAR do not affect catch rate ](#brnpsnpar-do-not-affect-catch-rate )
- [Moon Ball does not boost catch rate ](#moon-ball-does-not-boost-catch-rate )
- [Love Ball boosts catch rate for the wrong gender ](#love-ball-boosts-catch-rate-for-the-wrong-gender )
2022-07-21 16:48:28 -07:00
- [Fast Ball only boosts catch rate for three Pokémon ](#fast-ball-only-boosts-catch-rate-for-three-pok%C3%A9mon )
- [Heavy Ball uses wrong weight value for three Pokémon ](#heavy-ball-uses-wrong-weight-value-for-three-pok%C3%A9mon )
2022-12-01 13:54:01 -08:00
- [PRZ and BRN stat reductions don't apply to switched Pokémon ](#prz-and-brn-stat-reductions-dont-apply-to-switched-pok%C3%A9mon )
2020-08-29 10:27:44 -07:00
- [Glacier Badge may not boost Special Defense depending on the value of Special Attack ](#glacier-badge-may-not-boost-special-defense-depending-on-the-value-of-special-attack )
2022-07-21 16:48:28 -07:00
- ["Smart" AI encourages Mean Look if its own Pokémon is badly poisoned ](#smart-ai-encourages-mean-look-if-its-own-pok%C3%A9mon-is-badly-poisoned )
2020-12-07 10:13:03 -08:00
- ["Smart" AI discourages Conversion2 after the first turn ](#smart-ai-discourages-conversion2-after-the-first-turn )
2021-09-05 09:40:32 -07:00
- ["Smart" AI does not encourage Solar Beam, Flame Wheel, or Moonlight during Sunny Day ](#smart-ai-does-not-encourage-solar-beam-flame-wheel-or-moonlight-during-sunny-day )
2021-03-03 14:17:57 -08:00
- [AI does not discourage Future Sight when it's already been used ](#ai-does-not-discourage-future-sight-when-its-already-been-used )
2020-08-29 10:27:44 -07:00
- [AI makes a false assumption about `CheckTypeMatchup` ](#ai-makes-a-false-assumption-about-checktypematchup )
- [AI use of Full Heal or Full Restore does not cure Nightmare status ](#ai-use-of-full-heal-or-full-restore-does-not-cure-nightmare-status )
- [AI use of Full Heal does not cure confusion status ](#ai-use-of-full-heal-does-not-cure-confusion-status )
2023-07-26 17:50:16 -07:00
- [AI might use its base reward value as an item ](#ai-might-use-its-base-reward-value-as-an-item )
2022-07-21 16:48:28 -07:00
- [Wild Pokémon can always Teleport regardless of level difference ](#wild-pok%C3%A9mon-can-always-teleport-regardless-of-level-difference )
2021-09-05 09:40:32 -07:00
- [`RIVAL2` has lower DVs than `RIVAL1` ](#rival2-has-lower-dvs-than-rival1 )
2020-08-29 10:27:44 -07:00
- [`HELD_CATCH_CHANCE` has no effect ](#held_catch_chance-has-no-effect )
- [Credits sequence changes move selection menu behavior ](#credits-sequence-changes-move-selection-menu-behavior )
2022-03-20 17:43:10 -07:00
- [Game engine ](#game-engine )
2020-08-29 10:27:44 -07:00
- [`LoadMetatiles` wraps around past 128 blocks ](#loadmetatiles-wraps-around-past-128-blocks )
- [Surfing directly across a map connection does not load the new map ](#surfing-directly-across-a-map-connection-does-not-load-the-new-map )
- [Swimming NPCs aren't limited by their movement radius ](#swimming-npcs-arent-limited-by-their-movement-radius )
2022-08-31 16:13:10 -07:00
- [You can fish on top of NPCs ](#you-can-fish-on-top-of-npcs )
2022-07-21 16:48:28 -07:00
- [Pokémon deposited in the Day-Care might lose experience ](#pok%C3%A9mon-deposited-in-the-day-care-might-lose-experience )
2020-08-29 10:27:44 -07:00
- [Graphics ](#graphics )
- [In-battle “`…`” ellipsis is too high ](#in-battle--ellipsis-is-too-high )
- [Two tiles in the `port` tileset are drawn incorrectly ](#two-tiles-in-the-port-tileset-are-drawn-incorrectly )
2021-09-05 09:40:32 -07:00
- [The Ruins of Alph research center's roof color at night looks wrong ](#the-ruins-of-alph-research-centers-roof-color-at-night-looks-wrong )
2021-12-31 08:53:54 -08:00
- [A hatching Unown egg would not show the right letter ](#a-hatching-unown-egg-would-not-show-the-right-letter )
2020-08-29 10:27:44 -07:00
- [Using a Park Ball in non-Contest battles has a corrupt animation ](#using-a-park-ball-in-non-contest-battles-has-a-corrupt-animation )
- [Battle transitions fail to account for the enemy's level ](#battle-transitions-fail-to-account-for-the-enemys-level )
- [Some trainer NPCs have inconsistent overworld sprites ](#some-trainer-npcs-have-inconsistent-overworld-sprites )
- [Audio ](#audio )
- [Slot machine payout sound effects cut each other off ](#slot-machine-payout-sound-effects-cut-each-other-off )
- [Team Rocket battle music is not used for Executives or Scientists ](#team-rocket-battle-music-is-not-used-for-executives-or-scientists )
- [No bump noise if standing on tile `$3E` ](#no-bump-noise-if-standing-on-tile-3e )
2022-07-21 16:48:28 -07:00
- [Playing Entei's Pokédex cry can distort Raikou's and Suicune's ](#playing-enteis-pok%C3%A9dex-cry-can-distort-raikous-and-suicunes )
2020-08-29 10:27:44 -07:00
- [Text ](#text )
- [Five-digit experience gain is printed incorrectly ](#five-digit-experience-gain-is-printed-incorrectly )
- [Only the first three evolution entries can have Stone compatibility reported correctly ](#only-the-first-three-evolution-entries-can-have-stone-compatibility-reported-correctly )
- [`EVOLVE_STAT` can break Stone compatibility reporting ](#evolve_stat-can-break-stone-compatibility-reporting )
- [A "HOF Master!" title for 200-Time Famers is defined but inaccessible ](#a-hof-master-title-for-200-time-famers-is-defined-but-inaccessible )
- [Scripted events ](#scripted-events )
- [Clair can give TM24 Dragonbreath twice ](#clair-can-give-tm24-dragonbreath-twice )
- [Daisy's grooming doesn't always increase happiness ](#daisys-grooming-doesnt-always-increase-happiness )
- [Magikarp in Lake of Rage are shorter, not longer ](#magikarp-in-lake-of-rage-are-shorter-not-longer )
- [Magikarp length limits have a unit conversion error ](#magikarp-length-limits-have-a-unit-conversion-error )
- [Magikarp lengths can be miscalculated ](#magikarp-lengths-can-be-miscalculated )
- [`CheckOwnMon` only checks the first five letters of OT names ](#checkownmon-only-checks-the-first-five-letters-of-ot-names )
- [`CheckOwnMonAnywhere` does not check the Day-Care ](#checkownmonanywhere-does-not-check-the-day-care )
2020-12-07 10:32:08 -08:00
- [The unused `phonecall` script command may crash ](#the-unused-phonecall-script-command-may-crash )
2020-08-29 10:27:44 -07:00
- [Internal engine routines ](#internal-engine-routines )
- [Saves corrupted by mid-save shutoff are not handled ](#saves-corrupted-by-mid-save-shutoff-are-not-handled )
- [`ScriptCall` can overflow `wScriptStack` and crash ](#scriptcall-can-overflow-wscriptstack-and-crash )
- [`LoadSpriteGFX` does not limit the capacity of `UsedSprites` ](#loadspritegfx-does-not-limit-the-capacity-of-usedsprites )
2022-07-21 16:48:28 -07:00
- [`ChooseWildEncounter` doesn't really validate the wild Pokémon species ](#choosewildencounter-doesnt-really-validate-the-wild-pok%C3%A9mon-species )
2020-08-29 10:27:44 -07:00
- [`TryObjectEvent` arbitrary code execution ](#tryobjectevent-arbitrary-code-execution )
- [`ReadObjectEvents` overflows into `wObjectMasks` ](#readobjectevents-overflows-into-wobjectmasks )
- [`ClearWRAM` only clears WRAM bank 1 ](#clearwram-only-clears-wram-bank-1 )
2021-12-31 08:53:54 -08:00
- [`BattleAnimCmd_ClearObjs` only clears the first 6⅔ objects ](#battleanimcmd_clearobjs-only-clears-the-first-6-objects )
2022-08-11 21:28:35 -07:00
- [Options menu fails to clear joypad state on initialization ](#options-menu-fails-to-clear-joypad-state-on-initialization )
2020-08-29 10:27:44 -07:00
## Multi-player battle engine
### Perish Song and Spikes can leave a Pokémon with 0 HP and not faint
2020-01-04 13:52:08 -08:00
2020-01-04 14:08:25 -08:00
([Video](https://www.youtube.com/watch?v=1IiPWw5fMf8& t=85))
2020-01-04 13:52:08 -08:00
2020-01-04 14:08:25 -08:00
**Fix:** Edit `CheckFaint_PlayerThenEnemy` and `CheckFaint_EnemyThenPlayer` in [engine/battle/core.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/core.asm ):
2020-01-04 13:52:08 -08:00
```diff
jp HandleEncore
2020-01-04 14:08:25 -08:00
2020-01-04 13:52:08 -08:00
+HasAnyoneFainted:
+ call HasPlayerFainted
2020-01-27 04:27:48 -08:00
+ jp nz, HasEnemyFainted
2020-01-04 13:52:08 -08:00
+ ret
+
2020-01-04 14:08:25 -08:00
CheckFaint_PlayerThenEnemy:
2022-07-09 14:12:02 -07:00
-; BUG: Perish Song and Spikes can leave a Pokemon with 0 HP and not faint (see docs/bugs_and_glitches.md)
2020-01-04 13:52:08 -08:00
+.faint_loop
+ call .Function
+ ret c
+ call HasAnyoneFainted
+ ret nz
+ jr .faint_loop
+
+.Function:
call HasPlayerFainted
jr nz, .PlayerNotFainted
call HandlePlayerMonFaint
2020-01-04 14:08:25 -08:00
...
2020-01-04 13:52:08 -08:00
```
```diff
2020-01-04 14:08:25 -08:00
CheckFaint_EnemyThenPlayer:
2022-07-09 14:12:02 -07:00
-; BUG: Perish Song and Spikes can leave a Pokemon with 0 HP and not faint (see docs/bugs_and_glitches.md)
2020-01-04 13:52:08 -08:00
+.faint_loop
+ call .Function
+ ret c
+ call HasAnyoneFainted
+ ret nz
+ jr .faint_loop
+
+.Function:
call HasEnemyFainted
jr nz, .EnemyNotFainted
call HandleEnemyMonFaint
2020-01-04 14:08:25 -08:00
...
2020-01-04 13:52:08 -08:00
```
2020-08-29 10:27:44 -07:00
### Thick Club and Light Ball can make (Special) Attack wrap around above 1024
2017-12-28 09:58:18 -08:00
2017-12-12 19:58:20 -08:00
([Video](https://www.youtube.com/watch?v=rGqu3d3pdok& t=450))
2022-07-09 14:12:02 -07:00
**Fix:** Edit `SpeciesItemBoost` in [engine/battle/effect_commands.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/effect_commands.asm ):
2017-12-12 19:58:20 -08:00
2018-06-09 15:35:50 -07:00
```diff
2018-07-27 10:11:30 -07:00
; Double the stat
2022-07-09 14:12:02 -07:00
-; BUG: Thick Club and Light Ball can make (Special) Attack wrap around above 1024 (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
sla l
rl h
2018-06-09 15:35:50 -07:00
+
+ ld a, HIGH(MAX_STAT_VALUE)
+ cp h
+ jr c, .cap
2019-03-03 09:48:24 -08:00
+ ret nz
2018-06-09 15:35:50 -07:00
+ ld a, LOW(MAX_STAT_VALUE)
+ cp l
+ ret nc
+
+.cap
2019-01-19 16:11:38 -08:00
+ ld hl, MAX_STAT_VALUE
2018-07-27 10:11:30 -07:00
ret
2017-12-12 19:58:20 -08:00
```
2020-08-29 10:27:44 -07:00
### Metal Powder can increase damage taken with boosted (Special) Defense
2017-12-28 09:58:18 -08:00
2017-12-12 19:58:20 -08:00
([Video](https://www.youtube.com/watch?v=rGqu3d3pdok& t=450))
2022-03-14 19:53:38 -07:00
**Fix:** Edit [engine/battle/effect_commands.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/effect_commands.asm ):
2017-12-12 19:58:20 -08:00
2018-06-09 15:35:50 -07:00
```diff
2022-03-14 19:53:38 -07:00
DittoMetalPowder:
...
2022-07-09 14:12:02 -07:00
-; BUG: Metal Powder can increase damage taken with boosted (Special) Defense (see docs/bugs_and_glitches.md)
2022-03-14 19:53:38 -07:00
- ld a, c
- srl a
- add c
- ld c, a
- ret nc
-
- srl b
- ld a, b
- and a
- jr nz, .done
- inc b
-.done
- scf
- rr c
+ ld h, b
+ ld l, c
+ srl b
+ rr c
+ add hl, bc
+ ld b, h
+ ld c, l
2018-06-09 15:35:50 -07:00
+
+ ld a, HIGH(MAX_STAT_VALUE)
+ cp b
+ jr c, .cap
2019-03-03 09:36:42 -08:00
+ ret nz
2018-06-09 15:35:50 -07:00
+ ld a, LOW(MAX_STAT_VALUE)
+ cp c
+ ret nc
+
+.cap
2019-01-19 16:11:38 -08:00
+ ld bc, MAX_STAT_VALUE
2018-07-27 10:11:30 -07:00
ret
2017-12-12 19:58:20 -08:00
```
2022-03-14 19:53:38 -07:00
```diff
PlayerAttackDamage:
...
.done
+ push hl
+ call DittoMetalPowder
+ pop hl
call TruncateHL_BC
ld a, [wBattleMonLevel]
ld e, a
- call DittoMetalPowder
ld a, 1
and a
ret
```
```diff
EnemyAttackDamage:
...
.done
+ push hl
+ call DittoMetalPowder
+ pop hl
call TruncateHL_BC
ld a, [wBattleMonLevel]
ld e, a
- call DittoMetalPowder
ld a, 1
and a
ret
```
2017-12-12 19:58:20 -08:00
2020-08-29 10:27:44 -07:00
### Reflect and Light Screen can make (Special) Defense wrap around above 1024
2018-07-27 15:45:33 -07:00
This bug existed for all battles in Gold and Silver, and was only fixed for single-player battles in Crystal to preserve link compatibility.
2022-06-21 05:09:28 -07:00
**Fix:** Edit `TruncateHL_BC` in [engine/battle/effect_commands.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/effect_commands.asm ):
2018-07-27 15:45:33 -07:00
```diff
.finish
2022-07-09 14:12:02 -07:00
-; BUG: Reflect and Light Screen can make (Special) Defense wrap around above 1024 (see docs/bugs_and_glitches.md)
2018-07-27 15:45:33 -07:00
- ld a, [wLinkMode]
- cp LINK_COLOSSEUM
- jr z, .done
; If we go back to the loop point,
; it's the same as doing this exact
; same check twice.
ld a, h
or b
jr nz, .loop
-.done
ld b, l
ret
```
(This fix also affects Thick Club, Light Ball, and Metal Powder, as described above, but their specific fixes in the above bugs allow more accurate damage calculations.)
2020-08-29 10:27:44 -07:00
### Moves with a 100% secondary effect chance will not trigger it in 1/256 uses
2019-01-05 17:29:45 -08:00
([Video](https://www.youtube.com/watch?v=mHkyO5T5wZU& t=206))
2019-03-10 20:00:01 -07:00
**Fix:** Edit `BattleCommand_EffectChance` in [engine/battle/effect_commands.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/effect_commands.asm ):
2019-01-05 17:29:45 -08:00
```diff
2022-07-09 14:12:02 -07:00
.got_move_chance
-; BUG: Moves with a 100% secondary effect chance will not trigger it in 1/256 uses (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
- call BattleRandom
2019-01-05 17:29:45 -08:00
+ ld a, [hl]
2019-03-03 08:27:35 -08:00
+ sub 100 percent
+ ; If chance was 100%, RNG won't be called (carry not set)
+ ; Thus chance will be subtracted from 0, guaranteeing a carry
+ call c, BattleRandom
2019-01-05 17:29:45 -08:00
cp [hl]
2019-03-03 09:10:03 -08:00
pop hl
ret c
2019-01-05 17:29:45 -08:00
.failed
ld a, 1
ld [wEffectFailed], a
and a
ret
```
2019-03-03 11:35:29 -08:00
**Compatibility preservation:** If you wish to keep compatibility with standard Pokémon Crystal, you can disable the fix during link battles by also applying the following edit in the same place:
2019-03-03 08:27:35 -08:00
```diff
+ ld a, [wLinkMode]
+ cp LINK_COLOSSEUM
+ scf ; Force RNG to be called
+ jr z, .nofix ; Don't apply fix in link battles, for compatibility
2019-03-03 09:10:03 -08:00
ld a, [hl]
sub 100 percent
; If chance was 100%, RNG won't be called (carry not set)
; Thus chance will be subtracted from 0, guaranteeing a carry
+.nofix
call c, BattleRandom
2019-03-03 08:27:35 -08:00
```
2020-08-29 10:27:44 -07:00
### Belly Drum sharply boosts Attack even with under 50% HP
2017-12-28 09:58:18 -08:00
2017-12-12 17:15:07 -08:00
([Video](https://www.youtube.com/watch?v=zuCLMikWo4Y))
2019-03-10 20:00:01 -07:00
**Fix:** Edit `BattleCommand_BellyDrum` in [engine/battle/move_effects/belly_drum.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/move_effects/belly_drum.asm ):
2017-12-12 17:15:07 -08:00
2018-07-26 14:24:58 -07:00
```diff
2018-07-27 10:11:30 -07:00
BattleCommand_BellyDrum:
2022-07-09 14:12:02 -07:00
-; BUG: Belly Drum sharply boosts Attack even with under 50% HP (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
- call BattleCommand_AttackUp2
- ld a, [wAttackMissed]
- and a
- jr nz, .failed
2018-07-26 14:24:58 -07:00
-
2018-07-27 10:11:30 -07:00
callfar GetHalfMaxHP
callfar CheckUserHasEnoughHP
jr nc, .failed
+
2018-11-25 14:15:33 -08:00
+ push bc
2018-07-27 10:11:30 -07:00
+ call BattleCommand_AttackUp2
2018-11-25 14:15:33 -08:00
+ pop bc
2018-07-27 10:11:30 -07:00
+ ld a, [wAttackMissed]
+ and a
+ jr nz, .failed
2017-12-12 17:15:07 -08:00
```
2020-08-29 10:27:44 -07:00
### Berserk Gene's confusion lasts for 256 turns or the previous Pokémon's confusion count
2020-01-04 14:08:25 -08:00
([Video](https://youtube.com/watch?v=Pru3mohq20A))
**Fix:** Edit `HandleBerserkGene` in [engine/battle/core.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/core.asm ):
```diff
HandleBerserkGene:
...
2022-07-09 14:12:02 -07:00
-; BUG: Berserk Gene's confusion lasts for 256 turns or the previous Pokémon's confusion count (see docs/bugs_and_glitches.md)
2020-01-04 14:08:25 -08:00
ld a, BATTLE_VARS_SUBSTATUS3
call GetBattleVarAddr
push af
set SUBSTATUS_CONFUSED, [hl]
2020-04-18 14:31:51 -07:00
+ ldh a, [hBattleTurn]
2020-01-04 14:08:25 -08:00
+ and a
+ ld hl, wPlayerConfuseCount
2021-11-30 09:57:04 -08:00
+ jr z, .set_confuse_count
+ ld hl, wEnemyConfuseCount
2020-01-04 14:08:25 -08:00
+.set_confuse_count
+ call BattleRandom
+ and %11
2020-04-18 14:31:51 -07:00
+ add 2
2020-01-04 14:08:25 -08:00
+ ld [hl], a
ld a, BATTLE_VARS_MOVE_ANIM
call GetBattleVarAddr
...
```
2020-08-29 10:27:44 -07:00
This makes the Berserk Gene use the regular confusion duration (2– 5 turns).
2020-01-04 14:08:25 -08:00
2020-08-29 10:27:44 -07:00
### Confusion damage is affected by type-boosting items and Explosion/Self-Destruct doubling
2017-12-28 09:58:18 -08:00
2017-12-28 09:49:32 -08:00
([Video](https://twitter.com/crystal_rby/status/874626362287562752))
2019-03-03 16:55:28 -08:00
**Fix:**
2020-01-04 14:08:25 -08:00
First, edit [wram.asm ](https://github.com/pret/pokecrystal/blob/master/wram.asm ):
2019-03-03 12:49:52 -08:00
```diff
2020-06-20 20:03:40 -07:00
wTurnEnded:: db
2020-01-04 14:08:25 -08:00
- ds 1
2020-06-20 20:03:40 -07:00
+wIsConfusionDamage:: db
2020-01-04 14:08:25 -08:00
2020-06-20 20:03:40 -07:00
wPlayerStats::
2019-03-03 12:49:52 -08:00
```
2019-03-10 20:00:01 -07:00
Then edit four routines in [engine/battle/effect_commands.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/effect_commands.asm ):
2019-03-03 12:49:52 -08:00
```diff
2019-03-03 16:55:28 -08:00
HitSelfInConfusion:
...
call TruncateHL_BC
ld d, 40
2019-03-03 12:49:52 -08:00
pop af
ld e, a
2019-03-03 16:55:28 -08:00
+ ld a, TRUE
2020-01-04 14:08:25 -08:00
+ ld [wIsConfusionDamage], a
2019-03-03 12:49:52 -08:00
ret
```
```diff
2019-03-03 16:55:28 -08:00
BattleCommand_DamageCalc:
2022-07-09 14:12:02 -07:00
; Return a damage value for move power d, player level e, enemy defense c and player attack b.
-; BUG: Confusion damage is affected by type-boosting items and Explosion/Self-Destruct doubling (see docs/bugs_and_glitches.md)
2019-03-03 16:55:28 -08:00
...
2019-03-03 12:49:52 -08:00
.skip_zero_damage_check
+ xor a ; Not confusion damage
2020-01-04 14:08:25 -08:00
+ ld [wIsConfusionDamage], a
2019-03-03 16:55:28 -08:00
+ ; fallthrough
2019-03-03 12:49:52 -08:00
+
+ConfusionDamageCalc:
; Minimum defense value is 1.
ld a, c
and a
jr nz, .not_dividing_by_zero
ld c, 1
.not_dividing_by_zero
2019-03-03 16:55:28 -08:00
...
2019-03-03 12:49:52 -08:00
; Item boosts
2019-03-03 16:55:28 -08:00
+
+; Item boosts don't apply to confusion damage
2020-01-04 14:08:25 -08:00
+ ld a, [wIsConfusionDamage]
2019-03-03 12:49:52 -08:00
+ and a
2019-03-03 16:55:28 -08:00
+ jr nz, .DoneItem
+
2019-03-03 12:49:52 -08:00
call GetUserItem
2019-03-03 16:55:28 -08:00
...
```
2019-03-03 12:49:52 -08:00
```diff
2019-03-03 16:55:28 -08:00
CheckEnemyTurn:
...
2019-03-03 12:49:52 -08:00
ld hl, HurtItselfText
2019-04-08 05:15:10 -07:00
call StdBattleTextbox
2019-03-03 16:55:28 -08:00
2019-03-10 20:40:21 -07:00
call HitSelfInConfusion
2019-03-03 12:49:52 -08:00
- call BattleCommand_DamageCalc
+ call ConfusionDamageCalc
call BattleCommand_LowerSub
2019-03-03 16:55:28 -08:00
...
2019-03-03 12:49:52 -08:00
```
```diff
2019-03-03 16:55:28 -08:00
HitConfusion:
ld hl, HurtItselfText
2019-04-08 05:15:10 -07:00
call StdBattleTextbox
2019-03-03 16:55:28 -08:00
xor a
ld [wCriticalHit], a
2019-03-03 12:49:52 -08:00
call HitSelfInConfusion
- call BattleCommand_DamageCalc
+ call ConfusionDamageCalc
call BattleCommand_LowerSub
```
2017-12-28 09:49:32 -08:00
2020-08-29 10:27:44 -07:00
### Moves that lower Defense can do so after breaking a Substitute
2017-12-28 09:58:18 -08:00
2017-12-14 13:28:16 -08:00
([Video](https://www.youtube.com/watch?v=OGwKPRJLaaI))
This bug affects Acid, Iron Tail, and Rock Smash.
2019-03-10 20:00:01 -07:00
**Fix:** Edit `DefenseDownHit` in [data/moves/effects.asm ](https://github.com/pret/pokecrystal/blob/master/data/moves/effects.asm ):
2017-12-14 13:28:16 -08:00
2018-07-27 10:11:30 -07:00
```diff
DefenseDownHit:
checkobedience
usedmovetext
doturn
critical
damagestats
damagecalc
stab
damagevariation
checkhit
effectchance
hittarget
failuretext
checkfaint
criticaltext
supereffectivetext
2018-08-19 03:17:54 -07:00
checkfaint
2018-07-27 10:11:30 -07:00
buildopponentrage
2022-07-09 14:12:02 -07:00
-; BUG: Moves that lower Defense can do so after breaking a Substitute (see docs/bugs_and_glitches.md)
- effectchance
2018-07-27 10:11:30 -07:00
defensedown
statdownmessage
endmove
2017-12-14 13:28:16 -08:00
```
2020-08-29 10:27:44 -07:00
### Counter and Mirror Coat still work if the opponent uses an item
2017-12-28 09:58:18 -08:00
2017-12-14 13:28:16 -08:00
([Video](https://www.youtube.com/watch?v=uRYyzKRatFk))
2019-03-10 20:00:01 -07:00
**Fix:** Edit `BattleCommand_Counter` in [engine/battle/move_effects/counter.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/move_effects/counter.asm ) and `BattleCommand_MirrorCoat` in [engine/battle/move_effects/mirror_coat.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/move_effects/mirror_coat.asm ):
2018-07-20 17:39:53 -07:00
```diff
2022-07-09 14:12:02 -07:00
-; BUG: Counter and Mirror Coat still work if the opponent uses an item (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
ld hl, wCurDamage
ld a, [hli]
or [hl]
2018-07-20 17:39:53 -07:00
- ret z
2019-01-27 11:00:21 -08:00
+ jr z, .failed
2018-07-20 17:39:53 -07:00
```
Add this to the end of each file:
```diff
+.failed
+ ld a, 1
+ ld [wEffectFailed], a
+ and a
+ ret
```
2017-12-14 13:28:16 -08:00
2020-08-29 10:27:44 -07:00
### A Disabled but PP Up– enhanced move may not trigger Struggle
2017-12-28 09:58:18 -08:00
2017-12-14 13:28:16 -08:00
([Video](https://www.youtube.com/watch?v=1v9x4SgMggs))
2019-03-10 20:00:01 -07:00
**Fix:** Edit `CheckPlayerHasUsableMoves` in [engine/battle/core.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/core.asm ):
2018-07-26 14:24:58 -07:00
```diff
2018-07-27 10:11:30 -07:00
.done
2022-07-09 14:12:02 -07:00
-; BUG: A Disabled but PP Up– enhanced move may not trigger Struggle (see docs/bugs_and_glitches.md)
- and a
2018-07-26 14:24:58 -07:00
+ and PP_MASK
2018-07-27 10:11:30 -07:00
ret nz
.force_struggle
ld hl, BattleText_MonHasNoMovesLeft
2019-04-08 05:15:10 -07:00
call StdBattleTextbox
2018-07-27 10:11:30 -07:00
ld c, 60
call DelayFrames
xor a
ret
2017-12-14 13:28:16 -08:00
```
2020-08-29 10:27:44 -07:00
### A Pokémon that fainted from Pursuit will have its old status condition when revived
2017-12-28 09:58:18 -08:00
2017-12-14 13:28:16 -08:00
([Video](https://www.youtube.com/watch?v=tiRvw-Nb2ME))
2022-07-09 14:12:02 -07:00
**Fix:** Edit `PursuitSwitch` in [engine/battle/core.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/core.asm ):
2019-03-03 15:01:55 -08:00
```diff
2022-07-09 14:12:02 -07:00
-; BUG: A Pokémon that fainted from Pursuit will have its old status condition when revived (see docs/bugs_and_glitches.md)
2019-03-03 15:01:55 -08:00
ld a, $f0
ld [wCryTracks], a
ld a, [wBattleMonSpecies]
call PlayStereoCry
2019-03-03 15:21:30 -08:00
+ ld a, [wCurBattleMon]
+ push af
2019-03-03 15:01:55 -08:00
ld a, [wLastPlayerMon]
2019-03-03 15:21:30 -08:00
+ ld [wCurBattleMon], a
+ call UpdateFaintedPlayerMon
+ pop af
+ ld [wCurBattleMon], a
- ld c, a
- ld hl, wBattleParticipantsNotFainted
- ld b, RESET_FLAG
- predef SmallFarFlagAction
2019-03-03 15:01:55 -08:00
call PlayerMonFaintedAnimation
ld hl, BattleText_MonFainted
jr .done_fainted
```
2017-12-14 13:28:16 -08:00
2020-08-29 10:27:44 -07:00
### Lock-On and Mind Reader don't always bypass Fly and Dig
2017-12-28 09:58:18 -08:00
2017-12-14 18:45:35 -08:00
This bug affects Attract, Curse, Foresight, Mean Look, Mimic, Nightmare, Spider Web, Transform, and stat-lowering effects of moves like String Shot or Bubble during the semi-invulnerable turn of Fly or Dig.
2019-03-10 20:00:01 -07:00
**Fix:** Edit `CheckHiddenOpponent` in [engine/battle/effect_commands.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/effect_commands.asm ):
2018-07-27 10:11:30 -07:00
2018-07-26 14:24:58 -07:00
```diff
2018-07-28 21:27:13 -07:00
CheckHiddenOpponent:
2022-07-09 14:12:02 -07:00
-; BUG: Lock-On and Mind Reader don't always bypass Fly and Dig (see docs/bugs_and_glitches.md)
2023-04-06 09:05:59 -07:00
+ ld a, BATTLE_VARS_SUBSTATUS5_OPP
+ call GetBattleVar
+ cpl
+ and 1 < < SUBSTATUS_LOCK_ON
+ ret z
+
ld a, BATTLE_VARS_SUBSTATUS3_OPP
call GetBattleVar
and 1 < < SUBSTATUS_FLYING | 1 < < SUBSTATUS_UNDERGROUND
2018-07-27 14:53:26 -07:00
ret
2018-07-27 10:11:30 -07:00
```
2018-07-26 14:24:58 -07:00
2017-12-14 18:45:35 -08:00
2020-08-29 10:27:44 -07:00
### Beat Up can desynchronize link battles
2017-12-28 09:58:18 -08:00
2017-12-14 13:28:16 -08:00
([Video](https://www.youtube.com/watch?v=202-iAsrIa8))
2019-03-10 20:00:01 -07:00
**Fix:** Edit `BattleCommand_BeatUp` in [engine/battle/move_effects/beat_up.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/move_effects/beat_up.asm ):
2018-07-26 14:24:58 -07:00
```diff
2018-07-27 10:11:30 -07:00
.got_mon
2022-07-09 14:12:02 -07:00
-; BUG: Beat Up can desynchronize link battles (see docs/bugs_and_glitches.md)
2020-10-29 11:45:40 -07:00
ld a, [wCurBeatUpPartyMon]
2018-07-27 10:11:30 -07:00
ld hl, wPartyMonNicknames
2021-03-17 13:16:02 -07:00
call GetNickname
2018-07-27 10:11:30 -07:00
ld a, MON_HP
call GetBeatupMonLocation
ld a, [hli]
or [hl]
jp z, .beatup_fail ; fainted
2020-10-29 11:45:40 -07:00
ld a, [wCurBeatUpPartyMon]
2018-07-27 10:11:30 -07:00
ld c, a
ld a, [wCurBattleMon]
2018-07-26 14:24:58 -07:00
- cp [hl]
+ cp c
2018-07-27 10:11:30 -07:00
ld hl, wBattleMonStatus
jr z, .active_mon
ld a, MON_STATUS
call GetBeatupMonLocation
.active_mon
ld a, [hl]
and a
jp nz, .beatup_fail
2017-12-14 13:28:16 -08:00
```
2020-08-29 10:27:44 -07:00
### Beat Up works incorrectly with only one Pokémon in the party
2018-04-03 04:15:18 -07:00
2018-07-27 14:53:26 -07:00
This bug prevents the rest of Beat Up's effect from being executed if the player or enemy only has one Pokémon in their party while using it. It prevents Substitute from being raised and King's Rock from working.
2018-07-26 14:24:58 -07:00
2019-03-10 20:00:01 -07:00
**Fix:** Edit `BattleCommand_EndLoop` in [engine/battle/effect_commands.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/effect_commands.asm ):
2018-07-26 14:24:58 -07:00
```diff
2018-07-27 10:11:30 -07:00
.only_one_beatup
2022-07-09 14:12:02 -07:00
-; BUG: Beat Up works incorrectly with only one Pokémon in the party (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
ld a, BATTLE_VARS_SUBSTATUS3
call GetBattleVarAddr
res SUBSTATUS_IN_LOOP, [hl]
2018-07-26 14:24:58 -07:00
- call BattleCommand_BeatUpFailText
- jp EndMoveEffect
+ ret
```
2018-07-27 10:11:30 -07:00
**Cosmetic fix:** This fix does not break compatibility, but it only affects what's shown on the screen for the patched game.
2018-07-26 14:24:58 -07:00
```diff
2018-07-27 10:11:30 -07:00
.only_one_beatup
2022-07-09 14:12:02 -07:00
; BUG: Beat Up works incorrectly with only one Pokemon in the party (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
ld a, BATTLE_VARS_SUBSTATUS3
call GetBattleVarAddr
res SUBSTATUS_IN_LOOP, [hl]
call BattleCommand_BeatUpFailText
2018-07-26 14:24:58 -07:00
+ call BattleCommand_RaiseSub
2018-07-27 10:11:30 -07:00
jp EndMoveEffect
2018-04-03 04:15:18 -07:00
```
2018-07-27 14:53:26 -07:00
2020-08-29 10:27:44 -07:00
### Beat Up may fail to raise Substitute
2022-07-09 14:12:02 -07:00
*Fixing this cosmetic bug will* **not** *break link battle compatibility.*
2018-07-27 14:53:26 -07:00
This bug prevents Substitute from being raised if Beat Up was blocked by Protect or Detect.
2019-03-10 20:00:01 -07:00
**Fix:** Edit `BattleCommand_FailureText` in [engine/battle/effect_commands.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/effect_commands.asm ).
2018-04-03 04:15:18 -07:00
2018-07-27 10:11:30 -07:00
```diff
2022-07-09 14:12:02 -07:00
-; BUG: Beat Up may fail to raise Substitute (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
cp EFFECT_MULTI_HIT
jr z, .multihit
cp EFFECT_DOUBLE_HIT
jr z, .multihit
cp EFFECT_POISON_MULTI_HIT
jr z, .multihit
2018-07-26 14:24:58 -07:00
+ cp EFFECT_BEAT_UP
+ jr z, .multihit
2018-07-27 10:11:30 -07:00
jp EndMoveEffect
2018-04-03 04:15:18 -07:00
2018-07-27 10:11:30 -07:00
.multihit
call BattleCommand_RaiseSub
jp EndMoveEffect
2018-04-03 04:15:18 -07:00
```
2020-08-29 10:27:44 -07:00
### Beat Up may trigger King's Rock even if it failed
2018-04-03 04:15:18 -07:00
2019-03-10 20:00:01 -07:00
**Fix:** Edit `BattleCommand_BeatUpFailText` in [engine/battle/move_effects/beat_up.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/move_effects/beat_up.asm ):
2018-04-03 04:15:18 -07:00
2018-06-09 15:35:50 -07:00
```diff
2018-07-27 10:11:30 -07:00
BattleCommand_BeatUpFailText:
2022-07-09 14:12:02 -07:00
-; BUG: Beat Up may trigger King's Rock even if it failed (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
ld a, [wBeatUpHitAtLeastOnce]
and a
ret nz
2018-06-09 15:35:50 -07:00
+
+ inc a
+ ld [wAttackMissed], a
2018-04-03 04:15:18 -07:00
2018-07-27 10:11:30 -07:00
jp PrintButItFailed
2018-04-03 04:15:18 -07:00
```
2020-08-29 10:27:44 -07:00
### Present damage is incorrect in link battles
2017-12-28 09:58:18 -08:00
2017-12-14 13:28:16 -08:00
([Video](https://www.youtube.com/watch?v=XJaQoKtrEuw))
This bug existed for all battles in Gold and Silver, and was only fixed for single-player battles in Crystal to preserve link compatibility.
2019-03-10 20:00:01 -07:00
**Fix:** Edit `BattleCommand_Present` in [engine/battle/move_effects/present.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/move_effects/present.asm ):
2017-12-14 13:28:16 -08:00
2018-07-26 14:24:58 -07:00
```diff
2018-07-27 10:11:30 -07:00
BattleCommand_Present:
2022-07-09 14:12:02 -07:00
-; BUG: Present damage is incorrect in link battles (see docs/bugs_and_glitches.md)
2018-07-26 14:24:58 -07:00
- ld a, [wLinkMode]
- cp LINK_COLOSSEUM
- jr z, .colosseum_skippush
2018-07-27 10:11:30 -07:00
push bc
push de
2018-07-26 14:24:58 -07:00
-.colosseum_skippush
-
2021-12-31 08:53:54 -08:00
call BattleCommand_Stab
2018-07-26 14:24:58 -07:00
-
- ld a, [wLinkMode]
- cp LINK_COLOSSEUM
- jr z, .colosseum_skippop
2018-07-27 10:11:30 -07:00
pop de
pop bc
2018-07-26 14:24:58 -07:00
-.colosseum_skippop
2017-12-14 13:28:16 -08:00
```
2022-01-24 18:57:55 -08:00
### Return and Frustration deal no damage when the user's happiness is low or high, respectively
2022-01-24 17:48:21 -08:00
This happens because the user's happiness (or 255 − happiness for Frustration) is multiplied by 10 and divided by 25, which rounds down to zero when the happiness is 0– 2 (or 253– 255 for Frustration).
**Fix:**
Edit [engine/battle/move_effects/return.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/move_effects/return.asm ):
```diff
BattleCommand_HappinessPower:
2022-07-09 14:12:02 -07:00
-; BUG: Return and Frustration deal no damage when the user's happiness is low or high, respectively (see docs/bugs_and_glitches.md)
2022-01-24 17:48:21 -08:00
...
call Multiply
ld a, 25
ldh [hDivisor], a
ld b, 4
call Divide
ldh a, [hQuotient + 3]
+ and a
+ jr nz, .done
+ inc a
+.done
ld d, a
pop bc
ret
```
And edit [engine/battle/move_effects/frustration.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/move_effects/frustration.asm ):
```diff
BattleCommand_FrustrationPower:
2022-07-09 14:12:02 -07:00
-; BUG: Return and Frustration deal no damage when the user's happiness is low or high, respectively (see docs/bugs_and_glitches.md)
2022-01-24 17:48:21 -08:00
...
call Multiply
ld a, 25
ldh [hDivisor], a
ld b, 4
call Divide
ldh a, [hQuotient + 3]
+ and a
+ jr nz, .done
+ inc a
+.done
ld d, a
pop bc
ret
```
2020-08-29 10:27:44 -07:00
### Dragon Scale, not Dragon Fang, boosts Dragon-type moves
**Fix:** Edit `ItemAttributes` in [data/items/attributes.asm ](https://github.com/pret/pokecrystal/blob/master/data/items/attributes.asm ):
```diff
2022-07-09 14:12:02 -07:00
-; BUG: Dragon Scale, not Dragon Fang, boosts Dragon-type moves (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
; DRAGON_FANG
- item_attribute 100, HELD_NONE, 0, CANT_SELECT, ITEM, ITEMMENU_NOUSE, ITEMMENU_NOUSE
+ item_attribute 100, HELD_DRAGON_BOOST, 10, CANT_SELECT, ITEM, ITEMMENU_NOUSE, ITEMMENU_NOUSE
...
; DRAGON_SCALE
- item_attribute 2100, HELD_DRAGON_BOOST, 10, CANT_SELECT, ITEM, ITEMMENU_NOUSE, ITEMMENU_NOUSE
+ item_attribute 2100, HELD_NONE, 0, CANT_SELECT, ITEM, ITEMMENU_NOUSE, ITEMMENU_NOUSE
```
2022-01-10 18:32:41 -08:00
### Switching out or switching against a Pokémon with max HP below 4 freezes the game
This happens because switching involves calculating a percentage of maximum enemy HP. Directly calculating *HP* × 100 / *max HP* would require a two-byte denominator, so instead the game calculates *HP* × 25 / (*max HP* / 4), since even a maximum HP of 999 divided by 4 is 249, which fits in one byte. However, if the maximum HP is below 4 this will divide by 0, which enters an infinite loop in `_Divide` .
**Fix:** First, edit `SendOutMonText` in [engine/battle/core.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/core.asm ):
```diff
2022-07-09 14:12:02 -07:00
-; BUG: Switching out or switching against a Pokémon with max HP below 4 freezes the game (see docs/bugs_and_glitches.md)
2022-01-10 18:32:41 -08:00
; compute enemy health remaining as a percentage
xor a
ldh [hMultiplicand + 0], a
ld hl, wEnemyMonHP
ld a, [hli]
ld [wEnemyHPAtTimeOfPlayerSwitch], a
ldh [hMultiplicand + 1], a
ld a, [hl]
ld [wEnemyHPAtTimeOfPlayerSwitch + 1], a
ldh [hMultiplicand + 2], a
- ld a, 25
- ldh [hMultiplier], a
- call Multiply
ld hl, wEnemyMonMaxHP
ld a, [hli]
ld b, [hl]
- srl a
- rr b
- srl a
- rr b
+ ld c, 100
+ and a
+ jr z, .shift_done
+.shift
+ rra
+ rr b
+ srl c
+ and a
+ jr nz, .shift
+.shift_done
+ ld a, c
+ ldh [hMultiplier], a
+ call Multiply
ld a, b
ld b, 4
ldh [hDivisor], a
call Divide
```
Then edit `WithdrawMonText` in the same file:
```diff
; compute enemy health lost as a percentage
ld hl, wEnemyMonHP + 1
ld de, wEnemyHPAtTimeOfPlayerSwitch + 1
ld b, [hl]
dec hl
ld a, [de]
sub b
ldh [hMultiplicand + 2], a
dec de
ld b, [hl]
ld a, [de]
sbc b
ldh [hMultiplicand + 1], a
- ld a, 25
- ldh [hMultiplier], a
- call Multiply
ld hl, wEnemyMonMaxHP
ld a, [hli]
ld b, [hl]
- srl a
- rr b
- srl a
- rr b
+ ld c, 100
+ and a
+ jr z, .shift_done
+.shift
+ rra
+ rr b
+ srl c
+ and a
+ jr nz, .shift
+.shift_done
+ ld a, c
+ ldh [hMultiplier], a
+ call Multiply
ld a, b
ld b, 4
ldh [hDivisor], a
call Divide
```
This changes both calculations to *HP* × (100 / *N* ) / (*max HP* / *N* ) for the smallest necessary *N* , which will be at least 1, so it avoids dividing by zero and is also more accurate.
### Moves that do damage and increase your stats do not increase stats after a KO
`BattleCommand_CheckFaint` "ends the move effect if the opponent faints", and these moves attempt to raise the user's stats *after* `checkfaint` . Note that fixing this can lead to stats being increased at the end of battle, but will not have any negative effects.
**Fix:** Edit [data/moves/effects.asm ](https://github.com/pret/pokecrystal/blob/master/data/moves/effects.asm ):
```diff
DefenseUpHit:
...
criticaltext
supereffectivetext
2022-07-09 14:12:02 -07:00
-; BUG: Moves that do damage and increase your stats do not increase stats after a KO (see docs/bugs_and_glitches.md)
2022-01-10 18:32:41 -08:00
+ defenseup
+ statupmessage
checkfaint
buildopponentrage
- defenseup
- statupmessage
endmove
AttackUpHit:
...
criticaltext
supereffectivetext
+ attackup
+ statupmessage
checkfaint
buildopponentrage
- attackup
- statupmessage
endmove
AllUpHit:
...
criticaltext
supereffectivetext
+ allstatsup
checkfaint
buildopponentrage
- allstatsup
endmove
```
2020-08-29 10:27:44 -07:00
### HP bar animation is slow for high HP
2022-07-09 14:12:02 -07:00
*Fixing this cosmetic bug will* **not** *break link battle compatibility.*
2020-08-29 10:27:44 -07:00
([Video](https://www.youtube.com/watch?v=SE-BfsFgZVM))
**Fix:** Edit `LongAnim_UpdateVariables` in [engine/battle/anim_hp_bar.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/anim_hp_bar.asm ):
```diff
2022-07-09 14:12:02 -07:00
-; BUG: HP bar animation is slow for high HP (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
call ComputeHPBarPixels
+ ld a, e
pop bc
pop de
pop hl
2022-07-09 14:12:02 -07:00
- ld a, e
2020-08-29 10:27:44 -07:00
ld hl, wCurHPBarPixels
cp [hl]
jr z, .loop
ld [hl], a
and a
ret
```
### HP bar animation off-by-one error for low HP
2022-07-09 14:12:02 -07:00
*Fixing this cosmetic bug will* **not** *break link battle compatibility.*
2020-08-29 10:27:44 -07:00
([Video](https://www.youtube.com/watch?v=9KyNVIZxJvI))
**Fix:** Edit `ShortHPBar_CalcPixelFrame` in [engine/battle/anim_hp_bar.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/anim_hp_bar.asm ):
```diff
ld b, 0
.loop
2022-07-09 14:12:02 -07:00
-; BUG: HP bar animation off-by-one error for low HP (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
ld a, l
sub HP_BAR_LENGTH_PX
ld l, a
ld a, h
sbc $0
ld h, a
+ jr z, .done
jr c, .done
inc b
jr .loop
```
2020-12-18 06:25:49 -08:00
2020-08-29 10:27:44 -07:00
## Single-player battle engine
### A Transformed Pokémon can use Sketch and learn otherwise unobtainable moves
2020-01-04 14:08:25 -08:00
([Video](https://www.youtube.com/watch?v=AFiBxAOkCGI))
**Fix:** Edit `BattleCommand_Sketch` in [engine/battle/move_effects/sketch.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/move_effects/sketch.asm ):
```diff
-; If the opponent is transformed, fail.
2022-07-09 14:12:02 -07:00
-; BUG: A Transformed Pokémon can use Sketch and learn otherwise unobtainable moves (see docs/bugs_and_glitches.md)
2020-01-04 14:08:25 -08:00
+; If the user is transformed, fail.
- ld a, BATTLE_VARS_SUBSTATUS5_OPP
+ ld a, BATTLE_VARS_SUBSTATUS5
call GetBattleVarAddr
bit SUBSTATUS_TRANSFORMED, [hl]
jp nz, .fail
```
2020-08-29 10:27:44 -07:00
### Catching a Transformed Pokémon always catches a Ditto
2017-12-14 13:28:16 -08:00
2020-08-29 10:27:44 -07:00
**Fix:** Edit `PokeBallEffect` in [engine/items/item_effects.asm ](https://github.com/pret/pokecrystal/blob/master/engine/items/item_effects.asm ):
2018-07-26 14:24:58 -07:00
```diff
2020-08-29 10:27:44 -07:00
ld hl, wEnemySubStatus5
ld a, [hl]
push af
set SUBSTATUS_TRANSFORMED, [hl]
2017-12-14 13:28:16 -08:00
2022-07-09 14:12:02 -07:00
-; BUG: Catching a Transformed Pokémon always catches a Ditto (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
bit SUBSTATUS_TRANSFORMED, a
- jr nz, .ditto
- jr .not_ditto
+ jr nz, .load_data
2017-12-14 18:45:35 -08:00
2020-08-29 10:27:44 -07:00
-.ditto
- ld a, DITTO
- ld [wTempEnemyMonSpecies], a
- jr .load_data
-
-.not_ditto
- set SUBSTATUS_TRANSFORMED, [hl]
ld hl, wEnemyBackupDVs
ld a, [wEnemyMonDVs]
ld [hli], a
ld a, [wEnemyMonDVs + 1]
2018-07-27 10:11:30 -07:00
ld [hl], a
2017-12-12 17:15:07 -08:00
2020-08-29 10:27:44 -07:00
.load_data
ld a, [wTempEnemyMonSpecies]
ld [wCurPartySpecies], a
ld a, [wEnemyMonLevel]
ld [wCurPartyLevel], a
farcall LoadEnemyMon
2017-12-12 17:15:07 -08:00
2020-08-29 10:27:44 -07:00
pop af
ld [wEnemySubStatus5], a
2017-12-12 19:58:20 -08:00
```
2020-08-29 10:27:44 -07:00
### Experience underflow for level 1 Pokémon with Medium-Slow growth rate
2017-12-12 17:15:07 -08:00
([Video](https://www.youtube.com/watch?v=SXH8u0plHrE))
2019-03-10 20:00:01 -07:00
**Fix:** Edit `CalcExpAtLevel` in [engine/pokemon/experience.asm ](https://github.com/pret/pokecrystal/blob/master/engine/pokemon/experience.asm ):
2017-12-12 17:15:07 -08:00
2018-06-09 15:35:50 -07:00
```diff
2018-07-27 10:11:30 -07:00
CalcExpAtLevel:
; (a/b)*n**3 + c*n**2 + d*n - e
2022-07-09 14:12:02 -07:00
-; BUG: Experience underflow for level 1 Pokémon with Medium-Slow growth rate (see docs/bugs_and_glitches.md)
2018-06-09 15:35:50 -07:00
+ ld a, d
2020-09-27 09:31:59 -07:00
+ dec a
2018-06-09 15:35:50 -07:00
+ jr nz, .UseExpFormula
+; Pokémon have 0 experience at level 1
+ ld hl, hProduct
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ld [hl], a
+ ret
+
2019-01-07 16:36:56 -08:00
+.UseExpFormula
2018-07-27 10:11:30 -07:00
ld a, [wBaseGrowthRate]
add a
add a
ld c, a
ld b, 0
ld hl, GrowthRates
add hl, bc
2017-12-12 17:15:07 -08:00
```
2020-08-29 10:27:44 -07:00
### The Dude's catching tutorial may crash if his Poké Ball can't be used
2017-12-12 17:15:07 -08:00
2020-08-29 10:27:44 -07:00
([Video](https://www.youtube.com/watch?v=A8zaTOkjKS4& t=407))
2017-12-12 17:15:07 -08:00
2020-08-29 10:27:44 -07:00
This can occur if your party and current PC box are both full when you start the tutorial.
**Fix:** Edit `PokeBallEffect` in [engine/items/item_effects.asm ](https://github.com/pret/pokecrystal/blob/master/engine/items/item_effects.asm ):
2018-07-26 14:24:58 -07:00
```diff
2022-07-09 14:12:02 -07:00
PokeBallEffect:
-; BUG: The Dude's catching tutorial may crash if his Poké Ball can't be used (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
ld a, [wBattleMode]
dec a
jp nz, UseBallInTrainerBattle
2017-12-12 17:15:07 -08:00
2020-08-29 10:27:44 -07:00
+ ld a, [wBattleType]
+ cp BATTLETYPE_TUTORIAL
+ jr z, .room_in_party
+
ld a, [wPartyCount]
cp PARTY_LENGTH
jr nz, .room_in_party
ld a, BANK(sBoxCount)
call OpenSRAM
ld a, [sBoxCount]
cp MONS_PER_BOX
call CloseSRAM
jp z, Ball_BoxIsFullMessage
2017-12-12 17:15:07 -08:00
```
2017-12-12 19:58:20 -08:00
2020-08-29 10:27:44 -07:00
### BRN/PSN/PAR do not affect catch rate
2017-12-12 17:15:07 -08:00
2019-03-10 20:00:01 -07:00
**Fix:** Edit `PokeBallEffect` in [engine/items/item_effects.asm ](https://github.com/pret/pokecrystal/blob/master/engine/items/item_effects.asm ):
2018-07-26 14:24:58 -07:00
```diff
2022-07-09 14:12:02 -07:00
.statuscheck
-; BUG: BRN/PSN/PAR do not affect catch rate (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
ld b, a
ld a, [wEnemyMonStatus]
2022-06-17 19:25:56 -07:00
and 1 < < FRZ | SLP_MASK
2018-07-27 10:11:30 -07:00
ld c, 10
jr nz, .addstatus
2018-07-26 14:24:58 -07:00
+ ld a, [wEnemyMonStatus]
2018-07-27 10:11:30 -07:00
and a
ld c, 5
jr nz, .addstatus
ld c, 0
.addstatus
ld a, b
add c
jr nc, .max_1
ld a, $ff
.max_1
2017-12-12 17:15:07 -08:00
```
2020-08-29 10:27:44 -07:00
### Moon Ball does not boost catch rate
2017-12-12 17:15:07 -08:00
2020-08-29 10:27:44 -07:00
**Fix:** Edit `MoonBallMultiplier` in [engine/items/item_effects.asm ](https://github.com/pret/pokecrystal/blob/master/engine/items/item_effects.asm ):
2017-12-12 17:15:07 -08:00
2018-07-26 14:24:58 -07:00
```diff
2022-07-09 14:12:02 -07:00
-; BUG: Moon Ball does not boost catch rate (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
push bc
ld a, BANK("Evolutions and Attacks")
call GetFarByte
2018-07-26 14:24:58 -07:00
- cp MOON_STONE_RED ; BURN_HEAL
+ cp MOON_STONE
2018-07-27 10:11:30 -07:00
pop bc
ret nz
2017-12-12 17:15:07 -08:00
```
2020-08-29 10:27:44 -07:00
### Love Ball boosts catch rate for the wrong gender
2017-12-12 17:15:07 -08:00
2020-08-29 10:27:44 -07:00
**Fix:** Edit `LoveBallMultiplier` in [engine/items/item_effects.asm ](https://github.com/pret/pokecrystal/blob/master/engine/items/item_effects.asm ):
2018-07-26 14:24:58 -07:00
```diff
2022-07-09 14:12:02 -07:00
.got_wild_gender
2017-12-12 17:15:07 -08:00
2022-07-09 14:12:02 -07:00
-; BUG: Love Ball boosts catch rate for the wrong gender (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
ld a, d
pop de
cp d
pop bc
2022-07-09 14:12:02 -07:00
- ret nz
2018-07-26 14:24:58 -07:00
+ ret z
2017-12-12 17:15:07 -08:00
```
2020-08-29 10:27:44 -07:00
### Fast Ball only boosts catch rate for three Pokémon
2017-12-12 17:15:07 -08:00
2020-08-29 10:27:44 -07:00
**Fix:** Edit `FastBallMultiplier` in [engine/items/item_effects.asm ](https://github.com/pret/pokecrystal/blob/master/engine/items/item_effects.asm ):
2018-07-26 14:24:58 -07:00
```diff
2018-07-27 10:11:30 -07:00
.loop
2022-07-09 14:12:02 -07:00
-; BUG: Fast Ball only boosts catch rate for three Pokémon (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
ld a, BANK(FleeMons)
call GetFarByte
inc hl
cp -1
jr z, .next
cp c
2022-07-09 14:12:02 -07:00
- jr nz, .next
2018-07-26 14:24:58 -07:00
+ jr nz, .loop
2018-07-27 10:11:30 -07:00
sla b
jr c, .max
2017-12-12 17:15:07 -08:00
```
2020-09-27 09:39:27 -07:00
### Heavy Ball uses wrong weight value for three Pokémon
2022-07-09 14:12:02 -07:00
`HeavyBall_GetDexEntryBank` gets the wrong bank for Kadabra (64), Tauros (128), and Sunflora (192).
2022-02-22 14:11:33 -08:00
**Fix:** Edit `HeavyBall_GetDexEntryBank` in [engine/items/item_effects.asm ](https://github.com/pret/pokecrystal/blob/master/engine/items/item_effects.asm ):
2020-09-27 09:39:27 -07:00
```diff
2022-02-22 14:11:33 -08:00
HeavyBall_GetDexEntryBank:
2022-07-09 14:12:02 -07:00
-; BUG: Heavy Ball uses wrong weight value for three Pokemon (see docs/bugs_and_glitches.md)
2020-09-27 09:39:27 -07:00
push hl
push de
ld a, [wEnemyMonSpecies]
+ dec a
rlca
rlca
maskbits NUM_DEX_ENTRY_BANKS
ld hl, .PokedexEntryBanks
ld d, 0
ld e, a
add hl, de
ld a, [hl]
pop de
pop hl
ret
.PokedexEntryBanks:
db BANK("Pokedex Entries 001-064")
db BANK("Pokedex Entries 065-128")
db BANK("Pokedex Entries 129-192")
db BANK("Pokedex Entries 193-251")
```
2022-12-01 13:54:01 -08:00
### PRZ and BRN stat reductions don't apply to switched Pokémon
This does not affect link battles or Battle Tower battles because those jump from `LoadEnemyMon` to `InitEnemyMon` , which already calls `ApplyStatusEffectOnEnemyStats` .
**Fix:** Edit `LoadEnemyMon` in [engine/battle/core.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/core.asm ):
```diff
ld hl, wEnemyMonStats
ld de, wEnemyStats
ld bc, NUM_EXP_STATS * 2
call CopyBytes
-; BUG: PRZ and BRN stat reductions don't apply to switched Pokémon (see docs/bugs_and_glitches.md)
+ call ApplyStatusEffectOnEnemyStats
ret
```
2020-08-29 10:27:44 -07:00
### Glacier Badge may not boost Special Defense depending on the value of Special Attack
2017-12-12 17:15:07 -08:00
2022-07-09 14:12:02 -07:00
Pryce's dialog ("That BADGE will raise the SPECIAL stats of POKéMON.") implies that Glacier Badge is intended to boost both Special Attack and Special Defense, but the Special Defense boost will not happen unless the unboosted Special Attack stat is 206– 432, or 661 or above.
2017-12-28 09:58:18 -08:00
2020-08-29 10:27:44 -07:00
**Fix:** Edit `BadgeStatBoosts.CheckBadge` in [engine/battle/core.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/core.asm ):
2018-07-26 14:24:58 -07:00
```diff
2020-08-29 10:27:44 -07:00
.CheckBadge:
2022-07-09 14:12:02 -07:00
-; BUG: Glacier Badge may not boost Special Defense depending on the value of Special Attack (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
ld a, b
srl b
+ push af
call c, BoostStat
+ pop af
inc hl
inc hl
; Check every other badge.
srl b
dec c
jr nz, .CheckBadge
srl a
call c, BoostStat
ret
2017-12-12 17:15:07 -08:00
```
2020-08-29 10:27:44 -07:00
### "Smart" AI encourages Mean Look if its own Pokémon is badly poisoned
2019-01-19 16:11:38 -08:00
2020-08-29 10:27:44 -07:00
([Video](https://www.youtube.com/watch?v=cygMO-zHTls))
2019-01-19 16:11:38 -08:00
2020-08-29 10:27:44 -07:00
**Fix:** Edit `AI_Smart_MeanLook` in [engine/battle/ai/scoring.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/ai/scoring.asm ):
2019-01-19 16:27:45 -08:00
```diff
2022-07-09 14:12:02 -07:00
; 80% chance to greatly encourage this move if the enemy is badly poisoned.
-; BUG: "Smart" AI encourages Mean Look if its own Pokémon is badly poisoned (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
- ld a, [wEnemySubStatus5]
+ ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TOXIC, a
jr nz, .asm_38e26
2019-01-19 16:27:45 -08:00
```
2019-01-19 16:11:38 -08:00
2020-12-07 10:13:03 -08:00
### "Smart" AI discourages Conversion2 after the first turn
**Fix:** Edit `AI_Smart_Conversion2` in [engine/battle/ai/scoring.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/ai/scoring.asm ):
```diff
AI_Smart_Conversion2:
2022-07-09 14:12:02 -07:00
-; BUG: "Smart" AI discourages Conversion2 after the first turn (see docs/bugs_and_glitches.md)
2020-12-07 10:13:03 -08:00
ld a, [wLastPlayerMove]
and a
2022-07-09 14:12:02 -07:00
- jr nz, .discourage
2020-12-07 10:13:03 -08:00
+ jr z, .discourage
```
2021-12-31 08:53:54 -08:00
### "Smart" AI does not encourage Solar Beam, Flame Wheel, or Moonlight during Sunny Day
2021-09-05 09:40:32 -07:00
**Fix:** Edit `SunnyDayMoves` in [data/battle/ai/sunny_day_moves.asm ](https://github.com/pret/pokecrystal/blob/master/data/battle/ai/sunny_day_moves.asm ):
```diff
2022-07-09 14:12:02 -07:00
SunnyDayMoves:
-; BUG: "Smart" AI does not encourage Solar Beam, Flame Wheel, or Moonlight during Sunny Day (see docs/bugs_and_glitches.md)
2021-09-05 09:40:32 -07:00
db FIRE_PUNCH
db EMBER
db FLAMETHROWER
+ db SOLARBEAM
db FIRE_SPIN
db FIRE_BLAST
+ db FLAME_WHEEL
db SACRED_FIRE
db MORNING_SUN
db SYNTHESIS
+ db MOONLIGHT
db -1 ; end
```
2021-03-03 14:17:57 -08:00
### AI does not discourage Future Sight when it's already been used
**Fix:** Edit `AI_Redundant` in [engine/battle/ai/redundant.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/ai/redundant.asm ):
```diff
.FutureSight:
2022-07-09 14:12:02 -07:00
-; BUG: AI does not discourage Future Sight when it's already been used (see docs/bugs_and_glitches.md)
2021-03-03 14:17:57 -08:00
- ld a, [wEnemyScreens]
- bit 5, a
+ ld a, [wEnemyFutureSightCount]
+ and a
ret
```
2020-08-29 10:27:44 -07:00
### AI makes a false assumption about `CheckTypeMatchup`
2017-12-12 17:15:07 -08:00
2020-08-29 10:27:44 -07:00
**Fix:** Edit `BattleCheckTypeMatchup` in [engine/battle/effect_commands.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/effect_commands.asm ):
2017-12-12 17:15:07 -08:00
2020-08-29 10:27:44 -07:00
```diff
BattleCheckTypeMatchup:
ld hl, wEnemyMonType1
ldh a, [hBattleTurn]
and a
- jr z, CheckTypeMatchup
+ jr z, .get_type
ld hl, wBattleMonType1
+.get_type
+ ld a, BATTLE_VARS_MOVE_TYPE
+ call GetBattleVar ; preserves hl, de, and bc
2022-07-09 14:12:02 -07:00
; fallthrough
2020-08-29 10:27:44 -07:00
CheckTypeMatchup:
2022-07-09 14:12:02 -07:00
-; BUG: AI makes a false assumption about CheckTypeMatchup (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
push hl
push de
push bc
- ld a, BATTLE_VARS_MOVE_TYPE
- call GetBattleVar
ld d, a
...
```
2017-12-12 17:15:07 -08:00
2020-08-29 10:27:44 -07:00
### AI use of Full Heal or Full Restore does not cure Nightmare status
2017-12-12 17:15:07 -08:00
2020-08-29 10:27:44 -07:00
([Video](https://www.youtube.com/watch?v=rGqu3d3pdok& t=322))
2017-12-12 17:15:07 -08:00
2020-08-29 10:27:44 -07:00
**Fix:** Edit `AI_HealStatus` in [engine/battle/ai/items.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/ai/items.asm ):
```diff
AI_HealStatus:
2022-07-09 14:12:02 -07:00
-; BUG: AI use of Full Heal or Full Restore does not cure Nightmare status (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
ld a, [wCurOTMon]
ld hl, wOTPartyMon1Status
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
xor a
ld [hl], a
ld [wEnemyMonStatus], a
+ ld hl, wEnemySubStatus1
+ res SUBSTATUS_NIGHTMARE, [hl]
2022-07-09 14:12:02 -07:00
ld hl, wEnemySubStatus5
res SUBSTATUS_TOXIC, [hl]
ret
2017-12-12 17:15:07 -08:00
```
2020-08-29 10:27:44 -07:00
### AI use of Full Heal does not cure confusion status
2022-03-12 22:46:04 -08:00
**Fix:** Edit `EnemyUsedFullRestore` , and `AI_HealStatus` in [engine/battle/ai/items.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/ai/items.asm ):
2017-12-12 17:15:07 -08:00
2018-06-09 15:35:50 -07:00
```diff
2020-08-29 10:27:44 -07:00
EnemyUsedFullRestore:
2022-07-09 14:12:02 -07:00
-; BUG: AI use of Full Heal does not cure confusion status (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
call AI_HealStatus
ld a, FULL_RESTORE
ld [wCurEnemyItem], a
- ld hl, wEnemySubStatus3
- res SUBSTATUS_CONFUSED, [hl]
2022-03-12 22:46:04 -08:00
- xor a
- ld [wEnemyConfuseCount], a
2022-07-09 14:12:02 -07:00
; fallthrough
2020-08-29 10:27:44 -07:00
```
```diff
AI_HealStatus:
2022-07-09 14:12:02 -07:00
; BUG: AI use of Full Heal or Full Restore does not cure Nightmare status (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
ld a, [wCurOTMon]
ld hl, wOTPartyMon1Status
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
xor a
ld [hl], a
ld [wEnemyMonStatus], a
2022-03-12 22:46:04 -08:00
+ ld [wEnemyConfuseCount], a
2020-08-29 10:27:44 -07:00
+ ld hl, wEnemySubStatus3
+ res SUBSTATUS_CONFUSED, [hl]
ld hl, wEnemySubStatus5
res SUBSTATUS_TOXIC, [hl]
ret
2017-12-12 17:15:07 -08:00
```
2023-07-26 17:50:16 -07:00
### AI might use its base reward value as an item
In the `AI_TryItem` routine, an item pointer is set to `wEnemyTrainerItem1` and then increments to `wEnemyTrainerItem2` to see if either of the AI's items are in the `AI_Items` list. However, if the AI has used its first item (or its first one is `ITEM_NONE` ) and hasn't used its second item, the item pointer can increment from `wEnemyTrainerItem2` to `wEnemyTrainerBaseReward` . If the value at this address then matches an item in the `AI_Items` list, the AI could mistakenly use it.
**Fix:** Edit `AI_TryItem` in [engine/battle/ai/items.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/ai/items.asm ):
```diff
AI_TryItem:
...
ld a, [wTrainerClass]
dec a
ld hl, TrainerClassAttributes + TRNATTR_AI_ITEM_SWITCH
ld bc, NUM_TRAINER_ATTRIBUTES
call AddNTimes
ld b, h
ld c, l
ld hl, AI_Items
-; BUG: AI might use its base reward value as an item (see docs/bugs_and_glitches.md)
- ld de, wEnemyTrainerItem1
.loop
+ ld de, wEnemyTrainerItem1
ld a, [hl]
and a
inc a
ret z
```
2017-12-12 17:15:07 -08:00
2020-08-29 10:27:44 -07:00
### Wild Pokémon can always Teleport regardless of level difference
2017-12-12 19:58:20 -08:00
2020-08-29 10:27:44 -07:00
**Fix:** Edit `BattleCommand_Teleport` in [engine/battle/move_effects/teleport.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/move_effects/teleport.asm ):
2017-12-12 19:58:20 -08:00
2018-07-26 14:24:58 -07:00
```diff
2020-08-29 10:27:44 -07:00
.loop_enemy
2022-07-09 14:12:02 -07:00
-; BUG: Wild Pokémon can always Teleport regardless of level difference (see docs/bugs_and_glitches.md)
+; If a random number >= player level / 4, Teleport will succeed
2020-08-29 10:27:44 -07:00
call BattleRandom
cp c
jr nc, .loop_enemy
2021-06-20 07:56:11 -07:00
; b = player level / 4
2020-08-29 10:27:44 -07:00
srl b
srl b
2021-06-20 07:56:11 -07:00
cp b
2020-08-29 10:27:44 -07:00
- jr nc, .run_away
+ jr c, .failed
2017-12-12 19:58:20 -08:00
```
2021-09-05 09:40:32 -07:00
### `RIVAL2` has lower DVs than `RIVAL1`
`RIVAL1` is battled throughout the game. `RIVAL2` is battled at Indigo Plateau, and would not be expected to have worse DVs.
**Fix:** Edit `TrainerClassDVs` in [data/trainers/dvs.asm ](https://github.com/pret/pokecrystal/blob/master/data/trainers/dvs.asm ):
```diff
dn 13, 13, 13, 13 ; RIVAL1
...
2022-07-09 14:12:02 -07:00
-; BUG: RIVAL2 has lower DVs than RIVAL1 (see docs/bugs_and_glitches.md)
2021-09-05 09:40:32 -07:00
- dn 9, 8, 8, 8 ; RIVAL2
+ dn 13, 13, 13, 13 ; RIVAL2
```
2020-08-29 10:27:44 -07:00
### `HELD_CATCH_CHANCE` has no effect
2017-12-28 10:17:43 -08:00
2020-08-29 10:27:44 -07:00
**Fix:** Edit `PokeBallEffect` in [engine/items/item_effects.asm ](https://github.com/pret/pokecrystal/blob/master/engine/items/item_effects.asm ):
2018-07-26 14:24:58 -07:00
```diff
2022-07-09 14:12:02 -07:00
-; BUG: HELD_CATCH_CHANCE has no effect (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
ld d, a
push de
ld a, [wBattleMonItem]
+ ld b, a
farcall GetItemHeldEffect
ld a, b
cp HELD_CATCH_CHANCE
pop de
ld a, d
jr nz, .max_2
add c
jr nc, .max_2
ld a, $ff
.max_2
```
2017-12-28 10:17:43 -08:00
2018-07-27 10:11:30 -07:00
2020-08-29 10:27:44 -07:00
### Credits sequence changes move selection menu behavior
2018-07-27 10:11:30 -07:00
2020-08-29 10:27:44 -07:00
([Video](https://www.youtube.com/watch?v=vjFUo6Jr4po& t=438))
2017-12-28 10:17:43 -08:00
2020-08-29 10:27:44 -07:00
To select a move in battle, you have to press and release the Up or Down buttons. However, after playing the credits sequence, holding down either button will continuously scroll through the moves.
**Fix:** Edit `Credits` in [engine/movie/credits.asm ](https://github.com/pret/pokecrystal/blob/master/engine/movie/credits.asm ):
2019-02-17 10:18:38 -08:00
2020-08-29 10:27:44 -07:00
```diff
2022-07-09 14:12:02 -07:00
-; BUG: Credits sequence changes move selection menu behavior (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
ldh a, [hVBlank]
push af
ld a, $5
ldh [hVBlank], a
+ ldh a, [hInMenu]
+ push af
2022-07-09 14:12:02 -07:00
ld a, TRUE
2020-08-29 10:27:44 -07:00
ldh [hInMenu], a
2017-12-28 10:17:43 -08:00
2020-08-29 10:27:44 -07:00
...
2017-12-14 22:01:57 -08:00
2020-08-29 10:27:44 -07:00
ldh [hLCDCPointer], a
ldh [hBGMapAddress], a
+ pop af
+ ldh [hInMenu], a
pop af
ldh [hVBlank], a
pop af
ldh [rSVBK], a
```
The `[hInMenu]` value determines this button behavior. However, the battle moves menu doesn't actually set `[hInMenu]` to anything, so either behavior *may* have been intentional. The default 0 prevents continuous scrolling; a value of 1 allows it. (The Japanese release sets it to 0.)
**Optional fix:** To explicitly set a `[hInMenu]` for the moves menu, edit `BattleTurn` in [engine/battle/core.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/core.asm ):
2018-07-26 14:24:58 -07:00
```diff
2020-08-29 10:27:44 -07:00
BattleTurn:
+ ldh a, [hInMenu]
+ push af
+ ld a, 1 ; or "xor a" for the value 0
+ ldh [hInMenu], a
+
.loop
...
jp .loop
.quit
+ pop af
+ ldh [hInMenu], a
2018-07-27 10:11:30 -07:00
ret
2017-12-14 22:01:57 -08:00
```
2022-03-20 17:43:10 -07:00
## Game engine
2020-08-29 10:27:44 -07:00
### `LoadMetatiles` wraps around past 128 blocks
This bug prevents you from using blocksets with more than 128 blocks.
**Fix:** Edit `LoadMetatiles` in [home/map.asm ](https://github.com/pret/pokecrystal/blob/master/home/map.asm ):
```diff
; Set hl to the address of the current metatile data ([wTilesetBlocksAddress] + (a) tiles).
2022-07-09 14:12:02 -07:00
-; BUG: LoadMetatiles wraps around past 128 blocks (see docs/bugs_and_glitches.md)
- add a
2020-08-29 10:27:44 -07:00
ld l, a
ld h, 0
+ add hl, hl
add hl, hl
add hl, hl
add hl, hl
ld a, [wTilesetBlocksAddress]
add l
ld l, a
ld a, [wTilesetBlocksAddress + 1]
adc h
ld h, a
```
### Surfing directly across a map connection does not load the new map
([Video](https://www.youtube.com/watch?v=XFOWvMNG-zw))
**Fix:**
First, edit `UsedSurfScript` in [engine/events/overworld.asm ](https://github.com/pret/pokecrystal/blob/master/engine/events/overworld.asm ):
```diff
UsedSurfScript:
2022-07-09 14:12:02 -07:00
-; BUG: Surfing directly across a map connection does not load the new map (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
writetext UsedSurfText ; "used SURF!"
waitbutton
closetext
callasm .empty_fn ; empty function
2020-11-03 19:52:50 -08:00
readmem wSurfingPlayerState
2020-08-29 10:27:44 -07:00
writevar VAR_MOVEMENT
special UpdatePlayerSprite
special PlayMapMusic
-; step into the water (slow_step DIR, step_end)
special SurfStartStep
- applymovement PLAYER, wMovementBuffer
end
```
Then edit `SurfStartStep` in [engine/overworld/player_object.asm ](https://github.com/pret/pokecrystal/blob/master/engine/overworld/player_object.asm ):
```diff
SurfStartStep:
- call InitMovementBuffer
- call .GetMovementData
- call AppendToMovementBuffer
- ld a, movement_step_end
- call AppendToMovementBuffer
- ret
-
-.GetMovementData:
ld a, [wPlayerDirection]
srl a
srl a
maskbits NUM_DIRECTIONS
ld e, a
ld d, 0
ld hl, .movement_data
add hl, de
- ld a, [hl]
- ret
+ add hl, de
+ add hl, de
+ ld a, BANK(.movement_data)
+ jp StartAutoInput
.movement_data
- slow_step DOWN
- slow_step UP
- slow_step LEFT
- slow_step RIGHT
+ db D_DOWN, 0, -1
+ db D_UP, 0, -1
+ db D_LEFT, 0, -1
+ db D_RIGHT, 0, -1
```
2020-09-27 09:46:42 -07:00
This fix will make the player enter the water at a normal walking speed, not with a slow step.
2020-08-29 10:27:44 -07:00
### Swimming NPCs aren't limited by their movement radius
This bug is why the Lapras in [maps/UnionCaveB2F.asm ](https://github.com/pret/pokecrystal/blob/master/maps/UnionCaveB2F.asm ), which uses `SPRITEMOVEDATA_SWIM_WANDER` , is not restricted by its `1, 1` movement radius.
**Fix:** Edit `CanObjectMoveInDirection` in [engine/overworld/npc_movement.asm ](https://github.com/pret/pokecrystal/blob/master/engine/overworld/npc_movement.asm ):
```diff
2022-07-09 14:12:02 -07:00
-; BUG: Swimming NPCs aren't limited by their movement radius (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
ld hl, OBJECT_FLAGS1
add hl, bc
2022-07-09 14:12:02 -07:00
bit NOCLIP_TILES_F, [hl]
2020-08-29 10:27:44 -07:00
+ jr nz, .noclip_tiles
```
2022-08-31 16:13:10 -07:00
### You can fish on top of NPCs
2022-08-30 14:06:12 -07:00
**Fix**: Edit [engine/events/overworld.asm ](https://github.com/pret/pokecrystal/blob/master/engine/events/overworld.asm ):
2022-08-30 22:43:12 -07:00
```diff
FishFunction:
...
.TryFish:
2022-08-31 16:14:20 -07:00
-; BUG: You can fish on top of NPCs (see docs/bugs_and_glitches.md)
2022-08-30 22:43:12 -07:00
ld a, [wPlayerState]
cp PLAYER_SURF
jr z, .fail
cp PLAYER_SURF_PIKA
jr z, .fail
call GetFacingTileCoord
call GetTileCollision
cp WATER_TILE
2022-08-31 16:13:10 -07:00
- jr z, .facingwater
+ jr nz, .fail
+ farcall CheckFacingObject
+ jr nc, .facingwater
.fail
ld a, $3
ret
2022-08-30 22:43:12 -07:00
```
2022-08-30 14:06:12 -07:00
2022-03-20 17:43:10 -07:00
### Pokémon deposited in the Day-Care might lose experience
2022-07-09 14:12:02 -07:00
When a Pokémon is withdrawn from the Day-Care, its Exp. Points are reset to the minimum required for its level. This means that if it hasn't gained any levels, it may lose experience.
2022-03-20 17:43:10 -07:00
2022-08-30 14:06:12 -07:00
**Fix:** Edit `RetrieveBreedmon` in [engine/pokemon/move_mon.asm ](https://github.com/pret/pokecrystal/blob/master/engine/pokemon/move_mon.asm ):
2022-03-20 17:43:10 -07:00
```diff
RetrieveBreedmon:
...
2022-07-09 14:12:02 -07:00
-; BUG: Pokémon deposited in the Day-Care might lose experience (see docs/bugs_and_glitches.md)
2022-03-20 17:43:10 -07:00
ld a, [wPartyCount]
dec a
ld [wCurPartyMon], a
farcall HealPartyMon
- ld a, [wCurPartyLevel]
- ld d, a
+ ld d, MAX_LEVEL
callfar CalcExpAtLevel
pop bc
- ld hl, MON_EXP
+ ld hl, MON_EXP + 2
add hl, bc
ldh a, [hMultiplicand]
- ld [hli], a
+ ld b, a
ldh a, [hMultiplicand + 1]
- ld [hli], a
+ ld c, a
ldh a, [hMultiplicand + 2]
+ ld d, a
+ ld a, [hld]
+ sub d
+ ld a, [hld]
+ sbc c
+ ld a, [hl]
+ sbc b
+ jr c, .not_max_exp
+ ld a, b
+ ld [hli], a
+ ld a, c
+ ld [hli], a
+ ld a, d
ld [hl], a
+.not_max_exp
and a
ret
```
2020-08-29 10:27:44 -07:00
## Graphics
### In-battle “`…`” ellipsis is too high
This is a mistake with the “`…`” tile in [gfx/battle/hp_exp_bar_border.png ](https://github.com/pret/pokecrystal/blob/master/gfx/battle/hp_exp_bar_border.png ):
![image ](https://raw.githubusercontent.com/pret/pokecrystal/master/gfx/battle/hp_exp_bar_border.png )
**Fix:** Lower the ellipsis by two pixels:
![image ](https://raw.githubusercontent.com/pret/pokecrystal/master/docs/images/hp_exp_bar_border.png )
### Two tiles in the `port` tileset are drawn incorrectly
This is a mistake with the left-hand warp carpet corner tiles in [gfx/tilesets/port.png ](https://github.com/pret/pokecrystal/blob/master/gfx/tilesets/port.png ):
![image ](https://raw.githubusercontent.com/pret/pokecrystal/master/gfx/tilesets/port.png )
**Fix:** Adjust them to match the right-hand corner tiles:
![image ](https://raw.githubusercontent.com/pret/pokecrystal/master/docs/images/port.png )
2022-08-08 12:28:36 -07:00
### The Ruins of Alph research center's roof color at night looks wrong
2021-09-05 09:40:32 -07:00
The dungeons' map group mostly has indoor maps that don't need roof colors, but [maps/RuinsOfAlphOutside.blk ](https://github.com/pret/pokecrystal/blob/master/maps/RuinsOfAlphOutside.blk ) is an exception. It appears to have poorly-chosen roof colors: the morning/day colors are the same default gray as the unused group 0, and the night colors combine the light default gray and the dark red of Cinnabar's night roofs.
![image ](https://raw.githubusercontent.com/pret/pokecrystal/master/docs/images/ruins_of_alph_outside.png )
**Fix:** Edit [gfx/tilesets/roofs.pal ](https://github.com/pret/pokecrystal/blob/master/gfx/tilesets/roofs.pal ) to use the same red colors as Cinnabar (which are not actually seen in-game):
```diff
2021-09-05 09:52:01 -07:00
; group 3 (dungeons)
2021-09-05 09:40:32 -07:00
- RGB 21,21,21, 11,11,11 ; morn/day
- RGB 21,21,21, 17,08,07 ; nite
+ RGB 31,10,00, 18,06,00 ; morn/day
+ RGB 18,05,09, 17,08,07 ; nite
```
![image ](https://raw.githubusercontent.com/pret/pokecrystal/master/docs/images/ruins_of_alph_outside_cinnabar.png )
2021-12-31 08:53:54 -08:00
### A hatching Unown egg would not show the right letter
**Fix:** Edit both functions in [engine/pokemon/breeding.asm ](https://github.com/pret/pokecrystal/blob/master/engine/pokemon/breeding.asm ):
```diff
GetEggFrontpic:
2022-07-09 14:12:02 -07:00
-; BUG: A hatching Unown egg would not show the right letter (see docs/bugs_and_glitches.md)
2021-12-31 08:53:54 -08:00
push de
ld [wCurPartySpecies], a
ld [wCurSpecies], a
call GetBaseData
- ld hl, wBattleMonDVs
+ ld a, MON_DVS
+ call GetPartyParamLocation
predef GetUnownLetter
pop de
predef_jump GetMonFrontpic
GetHatchlingFrontpic:
push de
ld [wCurPartySpecies], a
ld [wCurSpecies], a
call GetBaseData
- ld hl, wBattleMonDVs
+ ld a, MON_DVS
+ call GetPartyParamLocation
predef GetUnownLetter
pop de
predef_jump GetAnimatedFrontpic
```
2020-08-29 10:27:44 -07:00
### Using a Park Ball in non-Contest battles has a corrupt animation
([Video](https://www.youtube.com/watch?v=v1ErZdLCIyU))
**Fix:** Edit `PokeBallEffect` in [engine/items/item_effects.asm ](https://github.com/pret/pokecrystal/blob/master/engine/items/item_effects.asm ):
```diff
.room_in_party
2022-07-09 14:12:02 -07:00
-; BUG: Using a Park Ball in non-Contest battles has a corrupt animation (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
xor a
ld [wWildMon], a
- ld a, [wCurItem]
- cp PARK_BALL
+ ld a, [wBattleType]
+ cp BATTLETYPE_CONTEST
call nz, ReturnToBattle_UseBall
```
### Battle transitions fail to account for the enemy's level
2017-12-12 19:58:20 -08:00
([Video](https://www.youtube.com/watch?v=eij_1060SMc))
2018-07-28 21:27:13 -07:00
There are three things wrong here:
2017-12-12 19:58:20 -08:00
2018-07-28 21:27:13 -07:00
- `wEnemyMonLevel` isn't initialized yet
- `wBattleMonLevel` gets overwritten after it's initialized by `FindFirstAliveMonAndStartBattle`
- `wBattleMonLevel` isn't initialized until much later when the battle is with a trainer
2018-06-26 13:32:44 -07:00
2018-07-28 21:27:13 -07:00
**Fix:**
2018-06-26 13:32:44 -07:00
2019-03-10 20:00:01 -07:00
First, edit [engine/battle/battle_transition.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/battle_transition.asm ):
2018-06-26 13:32:44 -07:00
```diff
2018-07-28 21:27:13 -07:00
StartTrainerBattle_DetermineWhichAnimation:
; The screen flashes a different number of times depending on the level of
; your lead Pokemon relative to the opponent's.
2022-07-09 14:12:02 -07:00
-; BUG: Battle transitions fail to account for enemy's level (see docs/bugs_and_glitches.md)
2018-06-26 13:32:44 -07:00
+ ld a, [wOtherTrainerClass]
+ and a
+ jr z, .wild
+ farcall SetTrainerBattleLevel
+
+.wild
+ ld b, PARTY_LENGTH
+ ld hl, wPartyMon1HP
+ ld de, PARTYMON_STRUCT_LENGTH - 1
+
+.loop
+ ld a, [hli]
+ or [hl]
+ jr nz, .okay
+ add hl, de
+ dec b
+ jr nz, .loop
+
+.okay
2019-01-27 11:00:21 -08:00
+ ld de, MON_LEVEL - MON_HP - 1
2018-06-26 13:32:44 -07:00
+ add hl, de
2021-12-31 08:53:54 -08:00
ld de, 0
2018-06-26 13:32:44 -07:00
- ld a, [wBattleMonLevel]
+ ld a, [hl]
2018-07-28 21:27:13 -07:00
add 3
2018-06-26 13:32:44 -07:00
- ld hl, wEnemyMonLevel
+ ld hl, wCurPartyLevel
2018-07-28 21:27:13 -07:00
cp [hl]
jr nc, .not_stronger
set TRANS_STRONGER_F, e
.not_stronger
ld a, [wEnvironment]
cp CAVE
jr z, .cave
cp ENVIRONMENT_5
jr z, .cave
cp DUNGEON
jr z, .cave
set TRANS_NO_CAVE_F, e
.cave
ld hl, .StartingPoints
add hl, de
ld a, [hl]
ld [wJumptableIndex], a
ret
2017-12-12 19:58:20 -08:00
2018-07-28 21:27:13 -07:00
.StartingPoints:
; entries correspond to TRANS_* constants
db BATTLETRANSITION_CAVE
db BATTLETRANSITION_CAVE_STRONGER
db BATTLETRANSITION_NO_CAVE
db BATTLETRANSITION_NO_CAVE_STRONGER
2017-12-12 19:58:20 -08:00
```
2019-03-10 20:00:01 -07:00
Then edit [engine/battle/start_battle.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/start_battle.asm ):
2018-06-26 13:32:44 -07:00
```diff
2018-07-28 21:27:13 -07:00
FindFirstAliveMonAndStartBattle:
xor a
2018-08-25 11:28:22 -07:00
ldh [hMapAnims], a
2018-07-28 21:27:13 -07:00
call DelayFrame
2019-03-12 19:55:40 -07:00
- ld b, PARTY_LENGTH
2018-06-26 13:32:44 -07:00
- ld hl, wPartyMon1HP
- ld de, PARTYMON_STRUCT_LENGTH - 1
-
-.loop
- ld a, [hli]
- or [hl]
- jr nz, .okay
- add hl, de
- dec b
- jr nz, .loop
-
-.okay
- ld de, MON_LEVEL - MON_HP
- add hl, de
- ld a, [hl]
- ld [wBattleMonLevel], a
2018-07-28 21:27:13 -07:00
predef DoBattleTransition
2018-06-26 13:32:44 -07:00
```
2019-03-10 20:00:01 -07:00
Finally, edit [engine/battle/read_trainer_party.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/read_trainer_party.asm ):
2018-06-26 13:32:44 -07:00
2018-08-23 07:07:05 -07:00
```diff
2018-07-28 21:27:13 -07:00
INCLUDE "data/trainers/parties.asm"
+
+SetTrainerBattleLevel:
+ ld a, 255
+ ld [wCurPartyLevel], a
+
+ ld a, [wInBattleTowerBattle]
+ bit 0, a
+ ret nz
+
+ ld a, [wLinkMode]
+ and a
+ ret nz
+
+ ld a, [wOtherTrainerClass]
+ dec a
+ ld c, a
+ ld b, 0
+ ld hl, TrainerGroups
+ add hl, bc
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+
+ ld a, [wOtherTrainerID]
+ ld b, a
+.skip_trainer
+ dec b
+ jr z, .got_trainer
2019-01-27 11:00:21 -08:00
+.skip_party
2018-07-28 21:27:13 -07:00
+ ld a, [hli]
+ cp $ff
2019-01-27 11:00:21 -08:00
+ jr nz, .skip_party
2018-07-28 21:27:13 -07:00
+ jr .skip_trainer
+.got_trainer
+
+.skip_name
+ ld a, [hli]
+ cp "@"
+ jr nz, .skip_name
+
+ inc hl
+ ld a, [hl]
+ ld [wCurPartyLevel], a
+ ret
2018-06-26 13:32:44 -07:00
```
2017-12-12 19:58:20 -08:00
2020-08-29 10:27:44 -07:00
### Some trainer NPCs have inconsistent overworld sprites
2018-02-26 08:51:16 -08:00
2020-08-29 10:27:44 -07:00
*Some of these may have been intentional behavior; use your own judgment for whether to fix them.*
2018-02-26 08:51:16 -08:00
2020-08-29 10:27:44 -07:00
Most trainer classes always use the same sprite and color for their overworld NPCs. There are some exceptions:
- [maps/FastShipCabins_SE_SSE_CaptainsCabin.asm ](https://github.com/pret/pokecrystal/blob/master/maps/FastShipCabins_SE_SSE_CaptainsCabin.asm ): `TrainerPsychicRodney` should use `SPRITE_YOUNGSTER` , not `SPRITE_SUPER_NERD`
- [maps/LakeOfRage.asm ](https://github.com/pret/pokecrystal/blob/master/maps/LakeOfRage.asm ): `TrainerFisherAndre` and `TrainerFisherRaymond` should use `PAL_NPC_GREEN` , not `PAL_NPC_BLUE`
- [maps/Route13.asm ](https://github.com/pret/pokecrystal/blob/master/maps/Route13.asm ): `TrainerHikerKenny` should use `PAL_NPC_BROWN` , not `PAL_NPC_RED`
- [maps/Route44.asm ](https://github.com/pret/pokecrystal/blob/master/maps/Route44.asm ): `TrainerBirdKeeperVance1` should use `PAL_NPC_BLUE` , not `PAL_NPC_GREEN`
- [maps/Route44.asm ](https://github.com/pret/pokecrystal/blob/master/maps/Route44.asm ): `TrainerPokemaniacZach` should use `PAL_NPC_BLUE` , not `PAL_NPC_GREEN`
- [maps/UnionCaveB2F.asm ](https://github.com/pret/pokecrystal/blob/master/maps/UnionCaveB2F.asm ): `TrainerCooltrainermNick` should use `SPRITE_COOLTRAINER_M` , not `SPRITE_ROCKER`
- [maps/FuchsiaPokecenter1F.asm ](https://github.com/pret/pokecrystal/blob/master/maps/FuchsiaPokecenter1F.asm ): `FuchsiaPokecenter1FNurseScript` should use `PAL_NPC_RED` , not `PAL_NPC_GREEN`
Most of the NPCs in [maps/NationalParkBugContest.asm ](https://github.com/pret/pokecrystal/blob/master/maps/NationalParkBugContest.asm ) and [maps/Route36NationalParkGate.asm ](https://github.com/pret/pokecrystal/blob/master/maps/Route36NationalParkGate.asm ) are also inconsistent with their trainers from other maps:
- `BugCatchingContestant1AScript` and `BugCatchingContestant1BScript` : `BUG_CATCHER DON` from [maps/Route30.asm ](https://github.com/pret/pokecrystal/blob/master/maps/Route30.asm ) should use `SPRITE_BUG_CATCHER` and `PAL_NPC_BROWN` , not `SPRITE_YOUNGSTER` and `PAL_NPC_RED`
- `BugCatchingContestant2AScript` and `BugCatchingContestant2BScript` : `BUG_CATCHER ED` from [maps/Route2.asm ](https://github.com/pret/pokecrystal/blob/master/maps/Route2.asm ) should use `SPRITE_BUG_CATCHER` and `PAL_NPC_BROWN` , not `SPRITE_YOUNGSTER` and `PAL_NPC_GREEN`
- `BugCatchingContestant3AScript` and `BugCatchingContestant3BScript` : `COOLTRAINERM NICK` from [maps/UnionCaveB2F.asm ](https://github.com/pret/pokecrystal/blob/master/maps/UnionCaveB2F.asm ) should use `SPRITE_COOLTRAINER_M` and `PAL_NPC_RED` , not `SPRITE_ROCKER` and `PAL_NPC_BLUE`
- `BugCatchingContestant4AScript` and `BugCatchingContestant4BScript` : `POKEFANM WILLIAM` from [maps/NationalPark.asm ](https://github.com/pret/pokecrystal/blob/master/maps/NationalPark.asm ) should use `PAL_NPC_RED` , not `PAL_NPC_BROWN`
- `BugCatchingContestant5AScript` and `BugCatchingContestant5BScript` : `BUG_CATCHER BENNY` from [maps/AzaleaGym.asm ](https://github.com/pret/pokecrystal/blob/master/maps/AzaleaGym.asm ) should use `SPRITE_BUG_CATCHER` and `PAL_NPC_BROWN` , not `SPRITE_YOUNGSTER` and `PAL_NPC_RED`
- `BugCatchingContestant7AScript` and `BugCatchingContestant7BScript` : `PICNICKER CINDY` from [maps/FuchsiaGym.asm ](https://github.com/pret/pokecrystal/blob/master/maps/FuchsiaGym.asm ) should use `PAL_NPC_GREEN` , not `PAL_NPC_BLUE`
- `BugCatchingContestant8AScript` and `BugCatchingContestant8BScript` : `BUG_CATCHER JOSH` from [maps/AzaleaGym.asm ](https://github.com/pret/pokecrystal/blob/master/maps/AzaleaGym.asm ) should use `SPRITE_BUG_CATCHER` and `PAL_NPC_BROWN` , not `SPRITE_YOUNGSTER` and `PAL_NPC_RED`
- `BugCatchingContestant9AScript` and `BugCatchingContestant9BScript` : `YOUNGSTER SAMUEL` from [maps/Route34.asm ](https://github.com/pret/pokecrystal/blob/master/maps/Route34.asm ) should use `PAL_NPC_BLUE` , not `PAL_NPC_GREEN`
(Note that [maps/Route8.asm ](https://github.com/pret/pokecrystal/blob/master/maps/Route8.asm ) has three `BIKER` s, `DWAYNE` , `HARRIS` , and `ZEKE` , that use `PAL_NPC_RED` , `PAL_NPC_GREEN` , and `PAL_NPC_BLUE` instead of `PAL_NPC_BROWN` ; this is intentional since they're the "Kanto Pokémon Federation".)
(The use of `SPRITE_ROCKER` instead of `SPRITE_COOLTRAINER_M` for `COOLTRAINERM NICK` may also be an intentional reference to the player's brother from the [Space World '97 beta ](https://github.com/pret/pokegold-spaceworld ).)
2018-07-26 14:24:58 -07:00
2018-02-26 08:51:16 -08:00
2020-08-29 10:27:44 -07:00
## Audio
2018-02-26 08:51:16 -08:00
2020-08-29 10:27:44 -07:00
### Slot machine payout sound effects cut each other off
2017-12-14 18:45:35 -08:00
([Video](https://www.youtube.com/watch?v=ojq3xqfRF6I))
2019-11-23 17:56:22 -08:00
**Fix:** Edit `SlotsAction_PayoutAnim` in [engine/games/slot_machine.asm ](https://github.com/pret/pokecrystal/blob/master/engine/games/slot_machine.asm ):
2018-07-26 14:24:58 -07:00
```diff
2018-07-27 10:11:30 -07:00
.okay
2022-07-09 14:12:02 -07:00
-; BUG: Slot machine payout sound effects cut each other off (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
ld [hl], e
dec hl
ld [hl], d
ld a, [wSlotsDelay]
and $7
2022-07-09 14:12:02 -07:00
- ret z
2018-07-26 14:24:58 -07:00
+ ret nz
2023-09-02 09:23:25 -07:00
ld de, SFX_GET_CHIP_FROM_SLOTS
2018-07-27 10:11:30 -07:00
call PlaySFX
ret
2017-12-14 18:45:35 -08:00
```
2020-08-29 10:27:44 -07:00
### Team Rocket battle music is not used for Executives or Scientists
2017-12-14 21:05:53 -08:00
2019-03-10 20:00:01 -07:00
**Fix:** Edit `PlayBattleMusic` in [engine/battle/start_battle.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/start_battle.asm ):
2017-12-14 21:05:53 -08:00
2018-06-09 15:35:50 -07:00
```diff
2022-07-09 14:12:02 -07:00
-; BUG: Team Rocket battle music is not used for Executives or Scientists (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
ld de, MUSIC_ROCKET_BATTLE
cp GRUNTM
jr z, .done
cp GRUNTF
jr z, .done
2020-08-29 10:27:44 -07:00
+ cp EXECUTIVEM
+ jr z, .done
+ cp EXECUTIVEF
+ jr z, .done
+ cp SCIENTIST
+ jr z, .done
```
2020-08-28 11:29:53 -07:00
2020-08-29 10:27:44 -07:00
### No bump noise if standing on tile `$3E`
2017-12-12 17:15:07 -08:00
2022-07-09 14:12:02 -07:00
If `[wWalkingDirection]` is `STANDING` (`$FF`), this will check `[.EdgeWarps + $ff]` , which happens to be `$3E` .
2019-03-10 20:00:01 -07:00
**Fix:** Edit `DoPlayerMovement.CheckWarp` in [engine/overworld/player_movement.asm ](https://github.com/pret/pokecrystal/blob/master/engine/overworld/player_movement.asm ):
2017-12-12 17:15:07 -08:00
2018-06-09 15:35:50 -07:00
```diff
2018-07-27 10:11:30 -07:00
.CheckWarp:
2022-07-09 14:12:02 -07:00
-; BUG: No bump noise if standing on tile $3E (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
ld a, [wWalkingDirection]
2018-06-09 15:35:50 -07:00
+ cp STANDING
+ jr z, .not_warp
2018-07-27 10:11:30 -07:00
ld e, a
ld d, 0
ld hl, .EdgeWarps
add hl, de
2022-09-12 06:15:44 -07:00
ld a, [wPlayerTile]
2018-07-27 10:11:30 -07:00
cp [hl]
jr nz, .not_warp
2019-04-08 15:50:10 -07:00
ld a, TRUE
ld [wWalkingIntoEdgeWarp], a
2018-07-27 10:11:30 -07:00
ld a, [wWalkingDirection]
2018-06-09 15:35:50 -07:00
- cp STANDING
- jr z, .not_warp
2017-12-12 17:15:07 -08:00
```
2020-08-29 10:27:44 -07:00
### Playing Entei's Pokédex cry can distort Raikou's and Suicune's
2017-12-13 13:46:31 -08:00
([Video](https://www.youtube.com/watch?v=z305e4sIO24))
2018-07-27 10:11:30 -07:00
The exact cause of this bug is unknown.
2017-12-13 13:46:31 -08:00
2019-03-10 20:00:01 -07:00
**Workaround:** Edit `DexEntryScreen_MenuActionJumptable.Cry` in [engine/pokedex/pokedex.asm ](https://github.com/pret/pokecrystal/blob/master/engine/pokedex/pokedex.asm ):
2017-12-13 13:46:31 -08:00
2018-07-26 14:24:58 -07:00
```diff
2018-07-27 10:11:30 -07:00
.Cry:
2022-07-09 14:12:02 -07:00
-; BUG: Playing Entei's Pokédex cry can distort Raikou's and Suicune's (see docs/bugs_and_glitches.md)
2018-07-26 14:24:58 -07:00
- call Pokedex_GetSelectedMon
2018-07-28 21:27:13 -07:00
- ld a, [wTempSpecies]
2018-07-26 14:24:58 -07:00
- call GetCryIndex
- ld e, c
- ld d, b
- call PlayCry
+ ld a, [wCurPartySpecies]
+ call PlayMonCry
2018-07-27 10:11:30 -07:00
ret
2017-12-13 13:46:31 -08:00
```
2020-08-29 10:27:44 -07:00
## Text
2017-12-22 14:52:34 -08:00
2020-08-29 10:27:44 -07:00
### Five-digit experience gain is printed incorrectly
2017-12-22 14:52:34 -08:00
2020-08-29 10:27:44 -07:00
([Video](https://www.youtube.com/watch?v=o54VjpAEoO8))
2017-12-22 14:52:34 -08:00
2020-08-29 10:27:44 -07:00
**Fix:** Edit `_BoostedExpPointsText` and `_ExpPointsText` in [data/text/common_2.asm ](https://github.com/pret/pokecrystal/blob/master/data/text/common_2.asm ):
2017-12-22 14:52:34 -08:00
2020-08-29 10:27:44 -07:00
```diff
_BoostedExpPointsText::
2022-07-09 14:12:02 -07:00
-; BUG: Five-digit experience gain is printed incorrectly (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
text_start
line "a boosted"
cont "@"
- text_decimal wStringBuffer2, 2, 4
+ text_decimal wStringBuffer2, 2, 5
text " EXP. Points!"
prompt
2017-12-22 14:52:34 -08:00
2020-08-29 10:27:44 -07:00
_ExpPointsText::
2022-07-09 14:12:02 -07:00
-; BUG: Five-digit experience gain is printed incorrectly (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
text_start
line "@"
- text_decimal wStringBuffer2, 2, 4
+ text_decimal wStringBuffer2, 2, 5
text " EXP. Points!"
prompt
```
2020-08-28 18:38:46 -07:00
2019-06-08 15:05:32 -07:00
2020-08-29 10:27:44 -07:00
### Only the first three evolution entries can have Stone compatibility reported correctly
2019-06-08 15:05:32 -07:00
2020-08-29 10:27:44 -07:00
**Workaround:** Edit `PlacePartyMonEvoStoneCompatibility.DetermineCompatibility` in [engine/pokemon/party_menu.asm ](https://github.com/pret/pokecrystal/blob/master/engine/pokemon/party_menu.asm ):
2019-06-08 15:05:32 -07:00
```diff
2020-08-29 10:27:44 -07:00
.DetermineCompatibility:
2022-07-09 14:12:02 -07:00
-; BUG: Only the first three evolution entries can have Stone compatibility reported correctly (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
ld de, wStringBuffer1
ld a, BANK(EvosAttacksPointers)
ld bc, 2
call FarCopyBytes
ld hl, wStringBuffer1
ld a, [hli]
ld h, [hl]
ld l, a
ld de, wStringBuffer1
ld a, BANK("Evolutions and Attacks")
- ld bc, 10
2020-11-24 17:11:17 -08:00
+ ld bc, STRING_BUFFER_LENGTH
2020-08-29 10:27:44 -07:00
call FarCopyBytes
```
2019-06-08 15:05:32 -07:00
2020-08-29 10:27:44 -07:00
This supports up to six entries.
2019-06-08 15:05:32 -07:00
2020-08-29 10:27:44 -07:00
### `EVOLVE_STAT` can break Stone compatibility reporting
2019-06-08 15:05:32 -07:00
2020-08-29 10:27:44 -07:00
**Fix:** Edit `PlacePartyMonEvoStoneCompatibility.DetermineCompatibility` in [engine/pokemon/party_menu.asm ](https://github.com/pret/pokecrystal/blob/master/engine/pokemon/party_menu.asm ):
2019-06-09 16:52:46 -07:00
```diff
2020-08-29 10:27:44 -07:00
.loop2
2022-07-09 14:12:02 -07:00
-; BUG: EVOLVE_STAT can break Stone compatibility reporting (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
ld a, [hli]
and a
jr z, .nope
+ cp EVOLVE_STAT
+ jr nz, .not_four_bytes
+ inc hl
+.not_four_bytes
inc hl
inc hl
cp EVOLVE_ITEM
jr nz, .loop2
```
2019-06-09 16:52:46 -07:00
2020-08-29 10:27:44 -07:00
### A "HOF Master!" title for 200-Time Famers is defined but inaccessible
2020-01-04 14:08:25 -08:00
2020-08-29 10:27:44 -07:00
([Video](https://www.youtube.com/watch?v=iHkWubvxmSg))
**Fix:** Edit `_HallOfFamePC.DisplayMonAndStrings` in [engine/events/halloffame.asm ](https://github.com/pret/pokecrystal/blob/master/engine/events/halloffame.asm ):
```diff
2022-07-09 14:12:02 -07:00
-; BUG: A "HOF Master!" title for 200-Time Famers is defined but inaccessible (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
ld a, [wHallOfFameTempWinCount]
2022-07-09 14:12:02 -07:00
- cp HOF_MASTER_COUNT + 1
2020-08-29 10:27:44 -07:00
+ cp HOF_MASTER_COUNT
jr c, .print_num_hof
ld de, .HOFMaster
hlcoord 1, 2
call PlaceString
hlcoord 13, 2
jr .finish
2019-06-09 16:52:46 -07:00
```
2020-08-29 10:27:44 -07:00
## Scripted events
2017-12-22 14:59:50 -08:00
2020-08-29 10:27:44 -07:00
### Clair can give TM24 Dragonbreath twice
2017-12-22 14:59:50 -08:00
2020-08-29 10:27:44 -07:00
([Video](https://www.youtube.com/watch?v=8BvBjqxmyOk))
2017-12-22 14:59:50 -08:00
2022-07-09 14:12:02 -07:00
**Fix:**
Edit `DragonsDen1F_MapScripts` in [maps/DragonsDen1F.asm ](https://github.com/pret/pokecrystal/blob/master/maps/DragonsDen1F.asm ):
2017-12-22 14:59:50 -08:00
2020-08-29 10:27:44 -07:00
```diff
2021-09-05 09:52:01 -07:00
def_callbacks
2020-08-29 10:27:44 -07:00
+ callback MAPCALLBACK_NEWMAP, .UnsetClairScene
+
+.UnsetClairScene:
2022-07-29 14:43:10 -07:00
+ setmapscene DRAGONS_DEN_B1F, SCENE_DRAGONSDENB1F_NOOP
2021-09-05 09:52:01 -07:00
+ endcallback
2020-08-29 10:27:44 -07:00
```
2017-12-22 14:59:50 -08:00
2022-07-09 14:12:02 -07:00
And edit [maps/DragonsDenB1F.asm ](https://github.com/pret/pokecrystal/blob/master/maps/DragonsDenB1F.asm ):
```diff
DragonsDenB1F_ClairScene:
-; BUG: Clair can give TM24 Dragonbreath twice (see docs/bugs_and_glitches.md)
```
2017-12-13 13:46:31 -08:00
2020-08-29 10:27:44 -07:00
### Daisy's grooming doesn't always increase happiness
2017-12-12 20:05:30 -08:00
2022-07-09 14:12:02 -07:00
Subtracting `$FF` from `$FF` fails to set the carry flag, which results in a 0.4% chance that Daisy's grooming will not affect your Pokémon's happiness.
2020-08-29 10:27:44 -07:00
This is a bug with `HaircutOrGrooming` in [engine/events/haircut.asm ](https://github.com/pret/pokecrystal/blob/master/engine/events/haircut.asm ):
2018-07-26 14:24:58 -07:00
2020-08-29 10:27:44 -07:00
```asm
.loop
sub [hl]
jr c, .ok
inc hl
inc hl
inc hl
jr .loop
2017-12-12 20:05:30 -08:00
2020-08-29 10:27:44 -07:00
.ok
inc hl
ld a, [hli]
ld [wScriptVar], a
ld c, [hl]
call ChangeHappiness
ret
2017-12-12 20:05:30 -08:00
2020-08-29 10:27:44 -07:00
...
2017-12-12 19:58:20 -08:00
2020-08-29 10:27:44 -07:00
INCLUDE "data/events/happiness_probabilities.asm"
2017-12-12 19:58:20 -08:00
2020-08-29 10:27:44 -07:00
CopyPokemonName_Buffer1_Buffer3:
ld hl, wStringBuffer1
ld de, wStringBuffer3
ld bc, MON_NAME_LENGTH
jp CopyBytes
```
2019-02-16 12:45:55 -08:00
2020-08-29 10:27:44 -07:00
**Fix:** Edit [data/events/happiness_probabilities.asm ](https://github.com/pret/pokecrystal/blob/master/data/events/happiness_probabilities.asm ):
2019-02-16 12:45:55 -08:00
```diff
2020-08-29 10:27:44 -07:00
HappinessData_DaisysGrooming:
2022-07-09 14:12:02 -07:00
-; BUG: Daisy's grooming doesn't always increase happiness (see docs/bugs_and_glitches.md)
2021-10-28 14:02:13 -07:00
- db -1, 2, HAPPINESS_GROOMING ; 99.6% chance
+ db 50 percent, 2, HAPPINESS_GROOMING ; 50% chance
+ db -1, 2, HAPPINESS_GROOMING ; 50% chance
2020-08-29 10:27:44 -07:00
```
2020-01-04 14:08:25 -08:00
2020-08-29 10:27:44 -07:00
### Magikarp in Lake of Rage are shorter, not longer
2020-01-04 14:08:25 -08:00
2022-07-09 14:12:02 -07:00
`cp HIGH(1024)` should be `cp 3` , since 1024 mm = 3'4", but `HIGH(1024)` = 4.
2020-08-29 10:27:44 -07:00
**Fix:** Edit `LoadEnemyMon.CheckMagikarpArea` in [engine/battle/core.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/core.asm ):
```diff
.CheckMagikarpArea:
2022-07-09 14:12:02 -07:00
-; BUG: Magikarp in Lake of Rage are shorter, not longer (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
ld a, [wMapGroup]
cp GROUP_LAKE_OF_RAGE
- jr z, .Happiness
+ jr nz, .Happiness
ld a, [wMapNumber]
cp MAP_LAKE_OF_RAGE
- jr z, .Happiness
+ jr nz, .Happiness
2022-07-09 14:12:02 -07:00
; 40% chance of not flooring
call Random
cp 39 percent + 1
jr c, .Happiness
; Try again if length < 1024 mm ( i . e . if HIGH ( length ) < 3 feet )
ld a, [wMagikarpLength]
- cp HIGH(1024)
+ cp 3
jr c, .GenerateDVs ; try again
2019-02-16 12:45:55 -08:00
```
2020-08-29 10:27:44 -07:00
### Magikarp length limits have a unit conversion error
2022-07-09 14:12:02 -07:00
- `cp HIGH(1536)` should be `cp 5` , since 1536 mm = 5'0", but `HIGH(1536)` = 6.
- `cp LOW(1616)` should be `cp 4` , since 1616 mm = 5'4", but `LOW(1616)` = 80.
- `cp LOW(1600)` should be `cp 3` , since 1600 mm = 5'3", but `LOW(1600)` = 64.
2020-08-29 10:27:44 -07:00
**Fix:** Edit `LoadEnemyMon.CheckMagikarpArea` in [engine/battle/core.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle/core.asm ):
2019-02-16 12:45:55 -08:00
```diff
2020-08-29 10:27:44 -07:00
; Get Magikarp's length
2022-07-09 14:12:02 -07:00
-; BUG: Magikarp length limits have a unit conversion error (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
ld de, wEnemyMonDVs
ld bc, wPlayerID
callfar CalcMagikarpLength
2019-02-16 12:45:55 -08:00
2020-08-29 10:27:44 -07:00
; No reason to keep going if length > 1536 mm (i.e. if HIGH(length) > 6 feet)
ld a, [wMagikarpLength]
2022-07-09 14:12:02 -07:00
- cp HIGH(1536)
2020-08-29 10:27:44 -07:00
+ cp 5
jr nz, .CheckMagikarpArea
; 5% chance of skipping both size checks
call Random
cp 5 percent
jr c, .CheckMagikarpArea
; Try again if length >= 1616 mm (i.e. if LOW(length) >= 4 inches)
ld a, [wMagikarpLength + 1]
2022-07-09 14:12:02 -07:00
- cp LOW(1616)
2020-08-29 10:27:44 -07:00
+ cp 4
jr nc, .GenerateDVs
; 20% chance of skipping this check
call Random
cp 20 percent - 1
jr c, .CheckMagikarpArea
; Try again if length >= 1600 mm (i.e. if LOW(length) >= 3 inches)
ld a, [wMagikarpLength + 1]
2022-07-09 14:12:02 -07:00
- cp LOW(1600)
2020-08-29 10:27:44 -07:00
+ cp 3
jr nc, .GenerateDVs
2019-02-16 12:45:55 -08:00
```
2017-12-12 19:58:20 -08:00
2020-08-29 10:27:44 -07:00
**Better fix:** Rewrite the whole system to use millimeters instead of feet and inches, since they have better precision (1 in = 25.4 mm); and only convert from metric to imperial units for display purposes (or don't, of course).
2017-12-12 19:58:20 -08:00
2017-12-21 08:43:41 -08:00
2020-08-29 10:27:44 -07:00
### Magikarp lengths can be miscalculated
2017-12-21 08:43:41 -08:00
2020-08-29 10:27:44 -07:00
**Fix:** Edit `CalcMagikarpLength.BCLessThanDE` in [engine/events/magikarp.asm ](https://github.com/pret/pokecrystal/blob/master/engine/events/magikarp.asm ):
2018-07-26 14:24:58 -07:00
```diff
2020-08-29 10:27:44 -07:00
.BCLessThanDE:
2022-07-09 14:12:02 -07:00
-; BUG: Magikarp lengths can be miscalculated (see docs/bugs_and_glitches.md)
2020-08-29 10:27:44 -07:00
ld a, b
cp d
ret c
2022-07-09 14:12:02 -07:00
- ret nc
2020-08-29 10:27:44 -07:00
ld a, c
cp e
ret
2017-12-21 08:43:41 -08:00
```
2020-08-29 10:27:44 -07:00
### `CheckOwnMon` only checks the first five letters of OT names
2017-12-12 17:15:07 -08:00
([Video](https://www.youtube.com/watch?v=GVTTmReM4nQ))
This bug can allow you to talk to Eusine in Celadon City and encounter Ho-Oh with only traded legendary beasts.
2022-06-17 20:27:53 -07:00
**Fix:** Edit `CheckOwnMon` in [engine/pokemon/search_owned.asm ](https://github.com/pret/pokecrystal/blob/master/engine/pokemon/search_owned.asm ):
2018-07-26 14:24:58 -07:00
```diff
2022-07-09 14:12:02 -07:00
; check OT
2017-12-12 17:15:07 -08:00
2018-07-27 10:11:30 -07:00
ld hl, wPlayerName
2017-12-12 17:15:07 -08:00
2022-07-09 14:12:02 -07:00
-; BUG: CheckOwnMon only checks the first five letters of OT names (see docs/bugs_and_glitches.md)
-rept NAME_LENGTH_JAPANESE - 2
2020-03-21 11:01:05 -07:00
+rept PLAYER_NAME_LENGTH - 2
2018-07-27 10:11:30 -07:00
ld a, [de]
cp [hl]
jr nz, .notfound
cp "@"
jr z, .found ; reached end of string
inc hl
inc de
endr
ld a, [de]
cp [hl]
jr z, .found
2017-12-12 17:15:07 -08:00
```
2020-08-29 10:27:44 -07:00
### `CheckOwnMonAnywhere` does not check the Day-Care
2020-08-28 11:29:53 -07:00
2020-08-28 18:38:46 -07:00
*This may have been intentional behavior; use your own judgment for whether to fix it.*
2020-08-28 11:29:53 -07:00
This bug can prevent you from talking to Eusine in Celadon City or encountering Ho-Oh when a caught legendary beast is in the Day-Care.
2022-06-17 20:27:53 -07:00
**Fix:** Edit `CheckOwnMonAnywhere` in [engine/pokemon/search_owned.asm ](https://github.com/pret/pokecrystal/blob/master/engine/pokemon/search_owned.asm ):
2020-08-28 11:29:53 -07:00
```diff
2022-07-09 14:12:02 -07:00
-; BUG: CheckOwnMon does not check the Day-Care (see docs/bugs_and_glitches.md)
2020-08-28 11:29:53 -07:00
+ ld hl, wBreedMon1Species
+ ld bc, wBreedMon1OT
+ call CheckOwnMon
+ ret c ; found!
+
+ ld hl, wBreedMon2Species
+ ld bc, wBreedMon2OT
+ call CheckOwnMon
+ ret c ; found!
2022-08-31 14:56:00 -07:00
+
ld d, a
ld e, 0
ld hl, wPartyMon1Species
ld bc, wPartyMonOTs
2020-08-28 11:29:53 -07:00
```
2020-12-07 10:32:08 -08:00
### The unused `phonecall` script command may crash
The `phonecall` script command calls the `PhoneCall` routine, which calls the `BrokenPlaceFarString` routine; this switches banks without being in bank 0, so it would start running arbitrary data as code.
**Fix:** Edit `PhoneCall.CallerTextboxWithName` in [engine/phone/phone.asm ](https://github.com/pret/pokecrystal/blob/master/engine/phone/phone.asm ):
```diff
2022-07-09 14:12:02 -07:00
-; BUG: The unused phonecall script command may crash (see docs/bugs_and_glitches.md)
2020-12-07 10:32:08 -08:00
- ld a, [wPhoneScriptBank]
- ld b, a
ld a, [wPhoneCaller]
ld e, a
ld a, [wPhoneCaller + 1]
ld d, a
- call BrokenPlaceFarString
+ ld a, [wPhoneScriptBank]
+ call PlaceFarString
ret
```
2022-07-09 14:12:02 -07:00
You can also delete the now-unused `BrokenPlaceFarString` routine in the same file.
2020-12-07 10:32:08 -08:00
2020-08-29 10:27:44 -07:00
## Internal engine routines
2018-07-27 10:11:30 -07:00
2017-12-13 13:46:31 -08:00
2020-08-29 10:27:44 -07:00
### Saves corrupted by mid-save shutoff are not handled
2017-12-13 13:46:31 -08:00
2020-08-29 10:27:44 -07:00
([Video 1](https://www.youtube.com/watch?v=ukqtK0l6bu0), [Video 2 ](https://www.youtube.com/watch?v=c2zHd1BPtvc ))
2020-01-21 16:19:27 -08:00
2022-07-09 14:12:02 -07:00
This allows Pokémon to be duplicated, among other effects. It does not have a simple and accurate fix. A fix would involve redesigning parts of the save system for Pokémon boxes.
2018-02-26 10:41:48 -08:00
2020-08-29 10:27:44 -07:00
### `ScriptCall` can overflow `wScriptStack` and crash
2017-12-12 17:15:07 -08:00
2019-03-10 20:00:01 -07:00
**Fix:** Edit `ScriptCall` in [engine/overworld/scripting.asm ](https://github.com/pret/pokecrystal/blob/master/engine/overworld/scripting.asm ):
2017-12-12 17:15:07 -08:00
2019-01-07 15:28:16 -08:00
```diff
ScriptCall:
2022-07-09 14:12:02 -07:00
-; BUG: ScriptCall can overflow wScriptStack and crash (see docs/bugs_and_glitches.md)
2019-01-07 15:28:16 -08:00
-
+ ld hl, wScriptStackSize
+ ld a, [hl]
+ cp 5
+ ret nc
push de
- ld hl, wScriptStackSize
- ld e, [hl]
inc [hl]
+ ld e, a
ld d, 0
ld hl, wScriptStack
add hl, de
add hl, de
add hl, de
pop de
ld a, [wScriptBank]
ld [hli], a
ld a, [wScriptPos]
ld [hli], a
ld a, [wScriptPos + 1]
ld [hl], a
ld a, b
ld [wScriptBank], a
ld a, e
ld [wScriptPos], a
ld a, d
ld [wScriptPos + 1], a
ret
2017-12-12 17:15:07 -08:00
```
2020-08-29 10:27:44 -07:00
### `LoadSpriteGFX` does not limit the capacity of `UsedSprites`
2017-12-12 17:15:07 -08:00
2019-03-10 20:00:01 -07:00
**Fix:** Edit `LoadSpriteGFX` in [engine/overworld/overworld.asm ](https://github.com/pret/pokecrystal/blob/master/engine/overworld/overworld.asm ):
2018-07-26 14:24:58 -07:00
```diff
2018-07-27 10:11:30 -07:00
LoadSpriteGFX:
2022-07-09 14:12:02 -07:00
-; BUG: LoadSpriteGFX does not limit the capacity of UsedSprites (see docs/bugs_and_glitches.md)
2018-07-26 14:24:58 -07:00
-
2018-07-27 10:11:30 -07:00
ld hl, wUsedSprites
ld b, SPRITE_GFX_LIST_CAPACITY
.loop
ld a, [hli]
and a
jr z, .done
push hl
call .LoadSprite
pop hl
ld [hli], a
dec b
jr nz, .loop
.done
ret
.LoadSprite:
2018-07-26 14:24:58 -07:00
+ push bc
2018-07-27 10:11:30 -07:00
call GetSprite
2018-07-26 14:24:58 -07:00
+ pop bc
2018-07-27 10:11:30 -07:00
ld a, l
ret
2017-12-12 17:15:07 -08:00
```
2020-08-29 10:27:44 -07:00
### `ChooseWildEncounter` doesn't really validate the wild Pokémon species
2017-12-12 17:15:07 -08:00
2019-03-10 20:00:01 -07:00
**Fix:** Edit `ChooseWildEncounter` in [engine/overworld/wildmons.asm ](https://github.com/pret/pokecrystal/blob/master/engine/overworld/wildmons.asm ):
2017-12-12 17:15:07 -08:00
2018-06-09 15:35:50 -07:00
```diff
2018-07-27 10:11:30 -07:00
.ok
2022-07-09 14:12:02 -07:00
-; BUG: ChooseWildEncounter doesn't really validate the wild Pokemon species (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
ld a, b
ld [wCurPartyLevel], a
ld b, [hl]
2018-06-09 15:35:50 -07:00
+ ld a, b
2018-07-27 10:11:30 -07:00
call ValidateTempWildMonSpecies
jr c, .nowildbattle
2017-12-12 17:15:07 -08:00
2022-07-09 14:12:02 -07:00
- ld a, b
2018-07-27 10:11:30 -07:00
cp UNOWN
jr nz, .done
2017-12-12 17:15:07 -08:00
```
2018-07-26 14:24:58 -07:00
2020-08-29 10:27:44 -07:00
### `TryObjectEvent` arbitrary code execution
2017-12-12 17:15:07 -08:00
2022-07-09 14:12:02 -07:00
If `IsInArray` returns `nc` , data at `bc` will be executed as code.
2019-03-10 20:00:01 -07:00
**Fix:** Edit `TryObjectEvent` in [engine/overworld/events.asm ](https://github.com/pret/pokecrystal/blob/master/engine/overworld/events.asm ):
2018-07-26 14:24:58 -07:00
```diff
2022-07-09 14:12:02 -07:00
-; BUG: TryObjectEvent arbitrary code execution (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
push bc
ld de, 3
2022-07-09 14:12:02 -07:00
ld hl, ObjectEventTypeArray
2018-07-27 10:11:30 -07:00
call IsInArray
2020-08-29 10:27:44 -07:00
- jr nc, .nope
2018-07-27 10:11:30 -07:00
pop bc
2020-01-04 13:52:08 -08:00
+ jr nc, .nope
2018-07-27 10:11:30 -07:00
inc hl
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
2019-04-23 16:07:41 -07:00
.nope
2018-07-27 10:11:30 -07:00
xor a
ret
2017-12-12 17:15:07 -08:00
```
2020-08-29 10:27:44 -07:00
### `ReadObjectEvents` overflows into `wObjectMasks`
2020-04-18 14:31:51 -07:00
**Fix:** Edit `ReadObjectEvents` in [home/map.asm ](https://github.com/pret/pokecrystal/blob/master/home/map.asm ):
```diff
-; get NUM_OBJECTS - [wCurMapObjectEventCount]
+; get NUM_OBJECTS - [wCurMapObjectEventCount] - 1
2022-07-09 14:12:02 -07:00
-; BUG: ReadObjectEvents overflows into wObjectMasks (see docs/bugs_and_glitches.md)
2020-04-18 14:31:51 -07:00
ld a, [wCurMapObjectEventCount]
ld c, a
2022-07-09 14:12:02 -07:00
- ld a, NUM_OBJECTS
2020-04-18 14:31:51 -07:00
+ ld a, NUM_OBJECTS - 1
sub c
jr z, .skip
+ jr c, .skip
2020-09-27 09:39:27 -07:00
2020-04-18 14:31:51 -07:00
; could have done "inc hl" instead
ld bc, 1
add hl, bc
ld bc, MAPOBJECT_LENGTH
.loop
ld [hl], 0
inc hl
ld [hl], -1
dec hl
add hl, bc
dec a
jr nz, .loop
```
2020-08-29 10:27:44 -07:00
### `ClearWRAM` only clears WRAM bank 1
2017-12-12 17:15:07 -08:00
2019-03-10 20:00:01 -07:00
**Fix:** Edit `ClearWRAM` in [home/init.asm ](https://github.com/pret/pokecrystal/blob/master/home/init.asm ):
2018-07-26 14:24:58 -07:00
```diff
2018-07-27 10:11:30 -07:00
ClearWRAM::
; Wipe swappable WRAM banks (1-7)
; Assumes CGB or AGB
2022-07-09 14:12:02 -07:00
-; BUG: ClearWRAM only clears WRAM bank 1 (see docs/bugs_and_glitches.md)
2018-07-27 10:11:30 -07:00
ld a, 1
.bank_loop
push af
2018-08-25 11:28:22 -07:00
ldh [rSVBK], a
2018-07-27 10:11:30 -07:00
xor a
ld hl, WRAM1_Begin
ld bc, WRAM1_End - WRAM1_Begin
call ByteFill
pop af
inc a
cp 8
2022-07-09 14:12:02 -07:00
- jr nc, .bank_loop
2018-07-26 14:24:58 -07:00
+ jr c, .bank_loop
2018-07-27 10:11:30 -07:00
ret
2017-12-12 17:15:07 -08:00
```
2019-02-16 10:31:23 -08:00
2020-08-29 10:27:44 -07:00
### `BattleAnimCmd_ClearObjs` only clears the first 6⅔ objects
2019-02-16 10:31:23 -08:00
2019-03-10 20:00:01 -07:00
**Fix:** Edit `BattleAnimCmd_ClearObjs` in [engine/battle_anims/anim_commands.asm ](https://github.com/pret/pokecrystal/blob/master/engine/battle_anims/anim_commands.asm ):
2019-02-16 10:31:23 -08:00
```diff
BattleAnimCmd_ClearObjs:
2022-07-09 14:12:02 -07:00
-; BUG: BattleAnimCmd only clears the first 6⅔ objects (see docs/bugs_and_glitches.md)
2019-02-16 10:31:23 -08:00
ld hl, wActiveAnimObjects
2022-07-09 14:12:02 -07:00
- ld a, $a0
2019-02-16 11:11:33 -08:00
+ ld a, NUM_ANIM_OBJECTS * BATTLEANIMSTRUCT_LENGTH
2019-02-16 10:31:23 -08:00
.loop
ld [hl], 0
inc hl
dec a
jr nz, .loop
ret
```
2022-08-11 21:28:35 -07:00
### Options menu fails to clear joypad state on initialization
([Video](https://www.youtube.com/watch?v=uhDSIkXkl3g))
This bug allows all the options to be updated at once if the left or right buttons are pressed on the same frame that the options menu is opened.
**Fix:** Edit `_Option` in [engine/menus/options_menu.asm ](https://github.com/pret/pokecrystal/blob/master/engine/menus/options_menu.asm ):
```diff
_Option:
-; BUG: Options menu fails to clear joypad state on initialization (see docs/bugs_and_glitches.md)
+ call ClearJoypad
ld hl, hInMenu
ld a, [hl]
push af
```