summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/bugs_and_glitches.md2066
-rw-r--r--docs/design_flaws.md142
-rw-r--r--docs/move_effect_commands.md8
3 files changed, 1088 insertions, 1128 deletions
diff --git a/docs/bugs_and_glitches.md b/docs/bugs_and_glitches.md
index 786c51ab3..33df631b2 100644
--- a/docs/bugs_and_glitches.md
+++ b/docs/bugs_and_glitches.md
@@ -2,11 +2,19 @@
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.
+Fixes are written in the `diff` format. If you're familiar with git, this should look farmiliar:
+```diff
+ this is some code
+-delete red - lines
++add green + lines
+```
+
## Contents
-- [Thick Club and Light Ball can decrease damage done with boosted (Special) Attack](#thick-club-and-light-ball-can-decrease-damage-done-with-boosted-special-attack)
+- [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)
- [Belly Drum sharply boosts Attack even with under 50% HP](#belly-drum-sharply-boosts-attack-even-with-under-50-hp)
- [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)
@@ -15,7 +23,8 @@ These are known bugs and glitches in the original Pokémon Crystal game: code th
- [A Pokémon that fainted from Pursuit will have its old status condition when revived](#a-pokémon-that-fainted-from-pursuit-will-have-its-old-status-condition-when-revived)
- [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)
-- [Beat Up may fail to raise substitute](#beat-up-may-fail-to-raise-substitute)
+- [Beat Up works incorrectly with only one Pokémon in the party](#beat-up-works-incorrectly-with-only-one-pokémon-in-the-party)
+- [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)
- ["Smart" AI encourages Mean Look if its own Pokémon is badly poisoned](#smart-ai-encourages-mean-look-if-its-own-pokémon-is-badly-poisoned)
@@ -55,43 +64,33 @@ These are known bugs and glitches in the original Pokémon Crystal game: code th
- [`LoadSpriteGFX` does not limit the capacity of `UsedSprites`](#loadspritegfx-does-not-limit-the-capacity-of-usedsprites)
- [`ChooseWildEncounter` doesn't really validate the wild Pokémon species](#choosewildencounter-doesnt-really-validate-the-wild-pokémon-species)
- [`TryObjectEvent` arbitrary code execution](#tryobjectevent-arbitrary-code-execution)
-- [`CheckBugContestContestantFlag` can read beyond its data table](#checkbugcontestcontestantflag-can-read-beyond-its-data-table)
- [`ClearWRAM` only clears WRAM bank 1](#clearwram-only-clears-wram-bank-1)
-## Thick Club and Light Ball can decrease damage done with boosted (Special) Attack
+## Thick Club and Light Ball can make (Special) Attack wrap around above 1024
*Fixing this bug will break compatibility with standard Pokémon Crystal for link battles.*
([Video](https://www.youtube.com/watch?v=rGqu3d3pdok&t=450))
-This is a bug with `SpeciesItemBoost` in [engine/battle/effect_commands.asm](/engine/battle/effect_commands.asm):
-
-```asm
-; Double the stat
- sla l
- rl h
- ret
-```
-
-**Fix:**
-
-```asm
-; Double the stat
- sla l
- rl h
-
- ld a, HIGH(MAX_STAT_VALUE)
- cp h
- jr c, .cap
- ld a, LOW(MAX_STAT_VALUE)
- cp l
- ret nc
-
-.cap
- ld h, HIGH(MAX_STAT_VALUE)
- ld l, LOW(MAX_STAT_VALUE)
- ret
+**Fix:** Edit `SpeciesItemBoost` in [engine/battle/effect_commands.asm](/engine/battle/effect_commands.asm)
+
+```diff
+ ; Double the stat
+ sla l
+ rl h
++
++ ld a, HIGH(MAX_STAT_VALUE)
++ cp h
++ jr c, .cap
++ ld a, LOW(MAX_STAT_VALUE)
++ cp l
++ ret nc
++
++.cap
++ ld h, HIGH(MAX_STAT_VALUE)
++ ld l, LOW(MAX_STAT_VALUE)
+ ret
```
@@ -101,57 +100,65 @@ This is a bug with `SpeciesItemBoost` in [engine/battle/effect_commands.asm](/en
([Video](https://www.youtube.com/watch?v=rGqu3d3pdok&t=450))
-This is a bug with `DittoMetalPowder` in [engine/battle/effect_commands.asm](/engine/battle/effect_commands.asm):
+**Fix:** Edit `DittoMetalPowder` in [engine/battle/effect_commands.asm](/engine/battle/effect_commands.asm):
+
+```diff
+ 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 a, HIGH(MAX_STAT_VALUE)
++ cp b
++ jr c, .cap
++ ld a, LOW(MAX_STAT_VALUE)
++ cp c
++ ret nc
++
++.cap
++ ld b, HIGH(MAX_STAT_VALUE)
++ ld c, LOW(MAX_STAT_VALUE)
+ ret
+```
-```asm
- 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
- ret
-```
+## Reflect and Light Screen can make (Special) Defense wrap around above 1024
-**Fix:**
+*Fixing this bug will break compatibility with standard Pokémon Crystal for link battles.*
-```asm
- ld a, c
- srl a
- add c
- ld c, a
- ret nc
+This bug existed for all battles in Gold and Silver, and was only fixed for single-player battles in Crystal to preserve link compatibility.
- srl b
- ld a, b
- and a
- jr nz, .done
- inc b
-.done
- scf
- rr c
-
- ld a, HIGH(MAX_STAT_VALUE)
- cp b
- jr c, .cap
- ld a, LOW(MAX_STAT_VALUE)
- cp c
- ret nc
-
-.cap
- ld b, HIGH(MAX_STAT_VALUE)
- ld c, LOW(MAX_STAT_VALUE)
- ret
+**Fix:** Edit `TruncateHL_BC` in [engine/battle/effect_commands.asm](/engine/battle/effect_commands.asm)
+
+```diff
+ .finish
+- 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.)
+
## Belly Drum sharply boosts Attack even with under 50% HP
@@ -159,37 +166,27 @@ This is a bug with `DittoMetalPowder` in [engine/battle/effect_commands.asm](/en
([Video](https://www.youtube.com/watch?v=zuCLMikWo4Y))
-This is a bug with `BattleCommand_BellyDrum` in [engine/battle/move_effects/belly_drum.asm](/engine/battle/move_effects/belly_drum.asm):
-
-```asm
-BattleCommand_BellyDrum:
-; bellydrum
-; This command is buggy because it raises the user's attack
-; before checking that it has enough HP to use the move.
-; Swap the order of these two blocks to fix.
- call BattleCommand_AttackUp2
- ld a, [wAttackMissed]
- and a
- jr nz, .failed
-
- callfar GetHalfMaxHP
- callfar CheckUserHasEnoughHP
- jr nc, .failed
-```
-
-**Fix:**
-
-```asm
-BattleCommand_BellyDrum:
-; bellydrum
- callfar GetHalfMaxHP
- callfar CheckUserHasEnoughHP
- jr nc, .failed
-
- call BattleCommand_AttackUp2
- ld a, [wAttackMissed]
- and a
- jr nz, .failed
+**Fix:** Edit `BattleCommand_BellyDrum` in [engine/battle/move_effects/belly_drum.asm](/engine/battle/move_effects/belly_drum.asm):
+
+```diff
+ BattleCommand_BellyDrum:
+ ; bellydrum
+-; This command is buggy because it raises the user's attack
+-; before checking that it has enough HP to use the move.
+-; Swap the order of these two blocks to fix.
+- call BattleCommand_AttackUp2
+- ld a, [wAttackMissed]
+- and a
+- jr nz, .failed
+-
+ callfar GetHalfMaxHP
+ callfar CheckUserHasEnoughHP
+ jr nc, .failed
++
++ call BattleCommand_AttackUp2
++ ld a, [wAttackMissed]
++ and a
++ jr nz, .failed
```
@@ -210,35 +207,33 @@ BattleCommand_BellyDrum:
This bug affects Acid, Iron Tail, and Rock Smash.
-This is a bug with `DefenseDownHit` in [data/moves/effects.asm](/data/moves/effects.asm):
-
-```asm
-DefenseDownHit:
- checkobedience
- usedmovetext
- doturn
- critical
- damagestats
- damagecalc
- stab
- damagevariation
- checkhit
- effectchance
- hittarget
- failuretext
- checkfaint
- criticaltext
- supereffectivetext
- checkdestinybond
- buildopponentrage
- effectchance ; bug: duplicate effectchance shouldn't be here
- defensedown
- statdownmessage
- endmove
+**Fix:** Edit `DefenseDownHit` in [data/moves/effects.asm](/data/moves/effects.asm):
+
+```diff
+ DefenseDownHit:
+ checkobedience
+ usedmovetext
+ doturn
+ critical
+ damagestats
+ damagecalc
+ stab
+ damagevariation
+ checkhit
+ effectchance
+ hittarget
+ failuretext
+ checkfaint
+ criticaltext
+ supereffectivetext
+ checkfaint
+ buildopponentrage
+- effectchance ; bug: duplicate effectchance shouldn't be here
+ defensedown
+ statdownmessage
+ endmove
```
-**Fix:** Delete the second `effectchance`.
-
## Counter and Mirror Coat still work if the opponent uses an item
@@ -246,7 +241,26 @@ DefenseDownHit:
([Video](https://www.youtube.com/watch?v=uRYyzKRatFk))
-*To do:* Identify specific code causing this bug and fix it.
+**Fix:** Edit `BattleCommand_Counter` in [engine/battle/move_effects/counter.asm](/engine/battle/move_effects/counter.asm) and `BattleCommand_MirrorCoat` in [engine/battle/move_effects/mirror_coat.asm](/engine/battle/move_effects/mirror_coat.asm):
+
+```diff
+- ; BUG: Move should fail with all non-damaging battle actions
+ ld hl, wCurDamage
+ ld a, [hli]
+ or [hl]
+- ret z
++ jp z, .failed
+```
+
+Add this to the end of each file:
+
+```diff
++.failed
++ ld a, 1
++ ld [wEffectFailed], a
++ and a
++ ret
+```
## A Disabled but PP Up–enhanced move may not trigger Struggle
@@ -255,25 +269,24 @@ DefenseDownHit:
([Video](https://www.youtube.com/watch?v=1v9x4SgMggs))
-This is a bug with `CheckPlayerHasUsableMoves` in [engine/battle/core.asm](/engine/battle/core.asm):
-
-```asm
-.done
- ; Bug: this will result in a move with PP Up confusing the game.
- and a ; should be "and PP_MASK"
- ret nz
-
-.force_struggle
- ld hl, BattleText_MonHasNoMovesLeft
- call StdBattleTextBox
- ld c, 60
- call DelayFrames
- xor a
- ret
+**Fix:** Edit `CheckPlayerHasUsableMoves` in [engine/battle/core.asm](/engine/battle/core.asm):
+
+```diff
+ .done
+- ; Bug: this will result in a move with PP Up confusing the game.
+- and a ; should be "and PP_MASK"
++ and PP_MASK
+ ret nz
+
+ .force_struggle
+ ld hl, BattleText_MonHasNoMovesLeft
+ call StdBattleTextBox
+ ld c, 60
+ call DelayFrames
+ xor a
+ ret
```
-**Fix:** Change `and a` to `and PP_MASK`.
-
## A Pokémon that fainted from Pursuit will have its old status condition when revived
@@ -290,19 +303,18 @@ This is a bug with `CheckPlayerHasUsableMoves` in [engine/battle/core.asm](/engi
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.
-This is a bug with `CheckHiddenOpponent` in [engine/battle/effect_commands.asm](/engine/battle/effect_commands.asm):
+**Fix:** Edit `CheckHiddenOpponent` in [engine/battle/effect_commands.asm](/engine/battle/effect_commands.asm):
-```asm
-CheckHiddenOpponent:
-; BUG: This routine should account for Lock-On and Mind Reader.
- ld a, BATTLE_VARS_SUBSTATUS3_OPP
- call GetBattleVar
- and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND
- ret
+```diff
+ CheckHiddenOpponent:
+-; BUG: This routine is completely redundant and introduces a bug, since BattleCommand_CheckHit does these checks properly.
+- ld a, BATTLE_VARS_SUBSTATUS3_OPP
+- call GetBattleVar
+- and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND
++ xor a
+ ret
```
-*To do:* Fix this bug.
-
## Beat Up can desynchronize link battles
@@ -310,110 +322,110 @@ CheckHiddenOpponent:
([Video](https://www.youtube.com/watch?v=202-iAsrIa8))
-This is a bug with `BattleCommand_BeatUp` in [engine/battle/move_effects/beat_up.asm](/engine/battle/move_effects/beat_up.asm):
-
-```asm
-.got_mon
- ld a, [wd002]
- ld hl, wPartyMonNicknames
- call GetNick
- ld a, MON_HP
- call GetBeatupMonLocation
- ld a, [hli]
- or [hl]
- jp z, .beatup_fail ; fainted
- ld a, [wd002]
- ld c, a
- ld a, [wCurBattleMon]
- ; BUG: this can desynchronize link battles
- ; Change "cp [hl]" to "cp c" to fix
- cp [hl]
- ld hl, wBattleMonStatus
- jr z, .active_mon
- ld a, MON_STATUS
- call GetBeatupMonLocation
-.active_mon
- ld a, [hl]
- and a
- jp nz, .beatup_fail
+**Fix:** Edit `BattleCommand_BeatUp` in [engine/battle/move_effects/beat_up.asm](/engine/battle/move_effects/beat_up.asm):
+
+```diff
+ .got_mon
+ ld a, [wd002]
+ ld hl, wPartyMonNicknames
+ call GetNick
+ ld a, MON_HP
+ call GetBeatupMonLocation
+ ld a, [hli]
+ or [hl]
+ jp z, .beatup_fail ; fainted
+ ld a, [wd002]
+ ld c, a
+ ld a, [wCurBattleMon]
+- ; BUG: this can desynchronize link battles
+- ; Change "cp [hl]" to "cp c" to fix
+- cp [hl]
++ cp c
+ ld hl, wBattleMonStatus
+ jr z, .active_mon
+ ld a, MON_STATUS
+ call GetBeatupMonLocation
+ .active_mon
+ ld a, [hl]
+ and a
+ jp nz, .beatup_fail
```
-**Fix:** Change `cp [hl]` to `cp c`.
+## Beat Up works incorrectly with only one Pokémon in the party
-## Beat Up may fail to raise substitute
+*Fixing this bug may break compatibility with standard Pokémon Crystal for link battles.*
-*Fixing this bug will break compatibility with standard Pokémon Crystal for link battles.*
-(Only the fixes denoted with "breaking" will actually break compatibility, the others just affect what's shown on the screen with the patched game)
+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.
-This is a bug in `BattleCommand_EndLoop` in [engine/battle/effect_commands.asm](/engine/battle/effect_commands.asm) that prevents the rest of the move's effect from being executed if the player or enemy only has one mon in their party while using Beat Up.
+**Fix:** Edit `BattleCommand_EndLoop` in [engine/battle/effect_commands.asm](/engine/battle/effect_commands.asm):
-It prevents the substitute from being raised and the King's Rock from working.
-
-```asm
-.only_one_beatup
- ld a, BATTLE_VARS_SUBSTATUS3
- call GetBattleVarAddr
- res SUBSTATUS_IN_LOOP, [hl]
- call BattleCommand_BeatUpFailText
- jp EndMoveEffect
+```diff
+ .only_one_beatup
+ ld a, BATTLE_VARS_SUBSTATUS3
+ call GetBattleVarAddr
+ res SUBSTATUS_IN_LOOP, [hl]
+- call BattleCommand_BeatUpFailText
+- jp EndMoveEffect
++ ret
```
-**Fix (breaking):** Replace the last two lines with `ret`.
-**Fix (cosmetics):** Call `BattleCommand_RaiseSub` before the `jp`.
-
-There's a similar oversight in `BattleCommand_FailureText` in [engine/battle/effect_commands.asm](/engine/battle/effect_commands.asm) that will prevent the substitute from being raised if Beat Up is protected against.
+**Cosmetic fix:** This fix does not break compatibility, but it only affects what's shown on the screen for the patched game.
-```asm
- cp EFFECT_MULTI_HIT
- jr z, .multihit
- cp EFFECT_DOUBLE_HIT
- jr z, .multihit
- cp EFFECT_POISON_MULTI_HIT
- jr z, .multihit
- jp EndMoveEffect
-
-.multihit
- call BattleCommand_RaiseSub
- jp EndMoveEffect
+```diff
+ .only_one_beatup
+ ld a, BATTLE_VARS_SUBSTATUS3
+ call GetBattleVarAddr
+ res SUBSTATUS_IN_LOOP, [hl]
+ call BattleCommand_BeatUpFailText
++ call BattleCommand_RaiseSub
+ jp EndMoveEffect
```
-**Fix:** Check for `EFFECT_BEAT_UP` as well.
+## Beat Up may fail to raise Substitute
-## Beat Up may trigger King's Rock even if it failed
+This bug prevents Substitute from being raised if Beat Up was blocked by Protect or Detect.
-*Fixing this bug will break compatibility with standard Pokémon Crystal for link battles.*
+**Fix:** Edit `BattleCommand_FailureText` in [engine/battle/effect_commands.asm](/engine/battle/effect_commands.asm).
-This is a bug in how `wAttackMissed` is never set by BeatUp, even when none of the 'mon have been able to attack (due to being fainted or having a status effect), the King's Rock may activate.
+```diff
+ cp EFFECT_MULTI_HIT
+ jr z, .multihit
+ cp EFFECT_DOUBLE_HIT
+ jr z, .multihit
+ cp EFFECT_POISON_MULTI_HIT
+ jr z, .multihit
++ cp EFFECT_BEAT_UP
++ jr z, .multihit
+ jp EndMoveEffect
-This bug can be fixed in a plethora of ways, but the most straight-forward would be in `BattleCommand_BeatUpFailText` in [engine/battle/move_effects/beat_up.asm](/engine/battle/move_effects/beat_up.asm), as that's always ran before the king's rock effect.
+ .multihit
+ call BattleCommand_RaiseSub
+ jp EndMoveEffect
+```
-```asm
-BattleCommand_BeatUpFailText:
-; beatupfailtext
- ld a, [wBeatUpHitAtLeastOnce]
- and a
- ret nz
+## Beat Up may trigger King's Rock even if it failed
- jp PrintButItFailed
-```
+*Fixing this bug will break compatibility with standard Pokémon Crystal for link battles.*
-**Fix:**
+This bug is caused because Beat Up never sets `wAttackMissed`, even when no Pokémon was able to attack (due to being fainted or having a status condition).
-```asm
-BattleCommand_BeatUpFailText:
-; beatupfailtext
+**Fix:** Edit `BattleCommand_BeatUpFailText` in [engine/battle/move_effects/beat_up.asm](/engine/battle/move_effects/beat_up.asm):
- ld a, [wBeatUpHitAtLeastOnce]
- and a
- ret nz
+```diff
+ BattleCommand_BeatUpFailText:
+ ; beatupfailtext
- inc a
- ld [wAttackMissed], a
+ ld a, [wBeatUpHitAtLeastOnce]
+ and a
+ ret nz
++
++ inc a
++ ld [wAttackMissed], a
- jp PrintButItFailed
+ jp PrintButItFailed
```
@@ -425,40 +437,27 @@ BattleCommand_BeatUpFailText:
This bug existed for all battles in Gold and Silver, and was only fixed for single-player battles in Crystal to preserve link compatibility.
-This is a bug with `BattleCommand_Present` in [engine/battle/move_effects/present.asm](/engine/battle/move_effects/present.asm):
-
-```asm
-BattleCommand_Present:
-; present
-
- ld a, [wLinkMode]
- cp LINK_COLOSSEUM
- jr z, .colosseum_skippush
- push bc
- push de
-.colosseum_skippush
-
- call BattleCommand_Stab
-
- ld a, [wLinkMode]
- cp LINK_COLOSSEUM
- jr z, .colosseum_skippop
- pop de
- pop bc
-.colosseum_skippop
-```
-
-**Fix:**
+**Fix:** Edit `BattleCommand_Present` in [engine/battle/move_effects/present.asm](/engine/battle/move_effects/present.asm):
-```asm
-BattleCommand_Present:
-; present
+```diff
+ BattleCommand_Present:
+ ; present
- push bc
- push de
+- ld a, [wLinkMode]
+- cp LINK_COLOSSEUM
+- jr z, .colosseum_skippush
+ push bc
+ push de
+-.colosseum_skippush
+-
call BattleCommand_Stab
- pop de
- pop bc
+-
+- ld a, [wLinkMode]
+- cp LINK_COLOSSEUM
+- jr z, .colosseum_skippop
+ pop de
+ pop bc
+-.colosseum_skippop
```
@@ -466,22 +465,22 @@ BattleCommand_Present:
([Video](https://www.youtube.com/watch?v=cygMO-zHTls))
-This is a bug with `AI_Smart_MeanLook` in [engine/battle/ai/scoring.asm](/engine/battle/ai/scoring.asm):
+**Fix:** Edit `AI_Smart_MeanLook` in [engine/battle/ai/scoring.asm](/engine/battle/ai/scoring.asm):
-```asm
-; 80% chance to greatly encourage this move if the enemy is badly poisoned (buggy).
-; Should check wPlayerSubStatus5 instead.
- ld a, [wEnemySubStatus5]
- bit SUBSTATUS_TOXIC, a
- jr nz, .asm_38e26
+```diff
+-; 80% chance to greatly encourage this move if the enemy is badly poisoned (buggy).
+-; Should check wPlayerSubStatus5 instead.
+- ld a, [wEnemySubStatus5]
++; 80% chance to greatly encourage this move if the player is badly poisoned
++ ld a, [wPlayerSubStatus5]
+ bit SUBSTATUS_TOXIC, a
+ jr nz, .asm_38e26
```
-**Fix:** Change `wEnemySubStatus5` to `wPlayerSubStatus5`.
-
## AI makes a false assumption about `CheckTypeMatchup`
-In [engine/battle/effect_commands.asm](/engine/battle/effect_commands.asm):
+In [engine/battle/effect_commands.asm](/engine/battle/effect_commands.asm).
```asm
BattleCheckTypeMatchup:
@@ -512,83 +511,81 @@ CheckTypeMatchup:
([Video](https://www.youtube.com/watch?v=rGqu3d3pdok&t=322))
-This is a bug with `AI_HealStatus` in [engine/battle/ai/items.asm](/engine/battle/ai/items.asm):
-
-```asm
-AI_HealStatus:
- ld a, [wCurOTMon]
- ld hl, wOTPartyMon1Status
- ld bc, PARTYMON_STRUCT_LENGTH
- call AddNTimes
- xor a
- ld [hl], a
- ld [wEnemyMonStatus], a
- ; Bug: this should reset SUBSTATUS_NIGHTMARE too
- ; Uncomment the lines below to fix
- ; ld hl, wEnemySubStatus1
- ; res SUBSTATUS_NIGHTMARE, [hl]
- ld hl, wEnemySubStatus5
- res SUBSTATUS_TOXIC, [hl]
- ret
+**Fix:** Edit `AI_HealStatus` in [engine/battle/ai/items.asm](/engine/battle/ai/items.asm):
+
+```diff
+ AI_HealStatus:
+ ld a, [wCurOTMon]
+ ld hl, wOTPartyMon1Status
+ ld bc, PARTYMON_STRUCT_LENGTH
+ call AddNTimes
+ xor a
+ ld [hl], a
+ ld [wEnemyMonStatus], a
+- ; Bug: this should reset SUBSTATUS_NIGHTMARE too
+- ; Uncomment the lines below to fix
+- ; ld hl, wEnemySubStatus1
+- ; res SUBSTATUS_NIGHTMARE, [hl]
++ ld hl, wEnemySubStatus1
++ res SUBSTATUS_NIGHTMARE, [hl]
+ ld hl, wEnemySubStatus5
+ res SUBSTATUS_TOXIC, [hl]
+ ret
```
-**Fix:** Uncomment `ld hl, wEnemySubStatus1` and `res SUBSTATUS_NIGHTMARE, [hl]`.
-
## HP bar animation is slow for high HP
([Video](https://www.youtube.com/watch?v=SE-BfsFgZVM))
-This is a bug with `LongAnim_UpdateVariables` in [engine/battle/anim_hp_bar.asm](/engine/battle/anim_hp_bar.asm):
-
-```asm
- ; This routine is buggy. The result from ComputeHPBarPixels is stored
- ; in e. However, the pop de opcode deletes this result before it is even
- ; used. The game then proceeds as though it never deleted that output.
- ; To fix, uncomment the line below.
- call ComputeHPBarPixels
- ; ld a, e
- pop bc
- pop de
- pop hl
- ld a, e ; Comment or delete this line to fix the above bug.
- ld hl, wCurHPBarPixels
- cp [hl]
- jr z, .loop
- ld [hl], a
- and a
- ret
+**Fix:** Edit `LongAnim_UpdateVariables` in [engine/battle/anim_hp_bar.asm](/engine/battle/anim_hp_bar.asm):
+
+```diff
+- ; This routine is buggy. The result from ComputeHPBarPixels is stored
+- ; in e. However, the pop de opcode deletes this result before it is even
+- ; used. The game then proceeds as though it never deleted that output.
+- ; To fix, uncomment the line below.
+ call ComputeHPBarPixels
+- ; ld a, e
++ ld a, e
+ pop bc
+ pop de
+ pop hl
+- ld a, e ; Comment or delete this line to fix the above bug.
+ ld hl, wCurHPBarPixels
+ cp [hl]
+ jr z, .loop
+ ld [hl], a
+ and a
+ ret
```
-**Fix:** Move `ld a, e` to right after `call ComputeHPBarPixels`.
-
## HP bar animation off-by-one error for low HP
([Video](https://www.youtube.com/watch?v=9KyNVIZxJvI))
-This is a bug with `ShortHPBar_CalcPixelFrame` in [engine/battle/anim_hp_bar.asm](/engine/battle/anim_hp_bar.asm):
-
-```asm
- ld b, 0
-; This routine is buggy. If [wCurHPAnimMaxHP] * [wCurHPBarPixels] is
-; divisible by HP_BAR_LENGTH_PX, the loop runs one extra time.
-; To fix, uncomment the line below.
-.loop
- 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
+**Fix:** Edit `ShortHPBar_CalcPixelFrame` in [engine/battle/anim_hp_bar.asm](/engine/battle/anim_hp_bar.asm):
+
+```diff
+ ld b, 0
+-; This routine is buggy. If [wCurHPAnimMaxHP] * [wCurHPBarPixels] is
+-; divisible by HP_BAR_LENGTH_PX, the loop runs one extra time.
+-; To fix, uncomment the line below.
+ .loop
+ ld a, l
+ sub HP_BAR_LENGTH_PX
+ ld l, a
+ ld a, h
+ sbc $0
+ ld h, a
+- ; jr z, .done
++ jr z, .done
+ jr c, .done
+ inc b
+ jr .loop
```
-**Fix:** Uncomment `jr z, .done`.
-
## Experience underflow for level 1 Pokémon with Medium-Slow growth rate
@@ -596,45 +593,31 @@ This is a bug with `ShortHPBar_CalcPixelFrame` in [engine/battle/anim_hp_bar.asm
This can bring Pokémon straight from level 1 to 100 by gaining just a few experience points.
-This is a bug with `CalcExpAtLevel` in [engine/pokemon/experience.asm](/engine/pokemon/experience.asm):
-
-```asm
-CalcExpAtLevel:
-; (a/b)*n**3 + c*n**2 + d*n - e
- ld a, [wBaseGrowthRate]
- add a
- add a
- ld c, a
- ld b, 0
- ld hl, GrowthRates
- add hl, bc
-```
-
-**Fix:**
-
-```asm
-CalcExpAtLevel:
-; (a/b)*n**3 + c*n**2 + d*n - e
- ld a, d
- cp 1
- jr nz, .UseExpFormula
-; Pokémon have 0 experience at level 1
- xor a
- ld hl, hProduct
- ld [hli], a
- ld [hli], a
- ld [hli], a
- ld [hl], a
- ret
-
-.UseExpFormula
- ld a, [wBaseGrowthRate]
- add a
- add a
- ld c, a
- ld b, 0
- ld hl, GrowthRates
- add hl, bc
+**Fix:** Edit `CalcExpAtLevel` in [engine/pokemon/experience.asm](/engine/pokemon/experience.asm):
+
+```diff
+ CalcExpAtLevel:
+ ; (a/b)*n**3 + c*n**2 + d*n - e
++ ld a, d
++ cp 1
++ jr nz, .UseExpFormula
++; Pokémon have 0 experience at level 1
++ xor a
++ ld hl, hProduct
++ ld [hli], a
++ ld [hli], a
++ ld [hli], a
++ ld [hl], a
++ ret
++
+ +.UseExpFormula
+ ld a, [wBaseGrowthRate]
+ add a
+ add a
+ ld c, a
+ ld b, 0
+ ld hl, GrowthRates
+ add hl, bc
```
@@ -642,151 +625,128 @@ CalcExpAtLevel:
([Video](https://www.youtube.com/watch?v=o54VjpAEoO8))
-This is a bug with `Text_ABoostedStringBuffer2ExpPoints` and `Text_StringBuffer2ExpPoints` in [data/text/common_2.asm](/data/text/common_2.asm):
-
-```asm
-Text_ABoostedStringBuffer2ExpPoints::
- text_start
- line "a boosted"
- cont "@"
- deciram wStringBuffer2, 2, 4
- text " EXP. Points!"
- prompt
-
-Text_StringBuffer2ExpPoints::
- text_start
- line "@"
- deciram wStringBuffer2, 2, 4
- text " EXP. Points!"
- prompt
+**Fix:** Edit `Text_ABoostedStringBuffer2ExpPoints` and `Text_StringBuffer2ExpPoints` in [data/text/common_2.asm](/data/text/common_2.asm):
+
+```diff
+ Text_ABoostedStringBuffer2ExpPoints::
+ text_start
+ line "a boosted"
+ cont "@"
+- deciram wStringBuffer2, 2, 4
++ deciram wStringBuffer2, 2, 5
+ text " EXP. Points!"
+ prompt
+
+ Text_StringBuffer2ExpPoints::
+ text_start
+ line "@"
+- deciram wStringBuffer2, 2, 4
++ deciram wStringBuffer2, 2, 5
+ text " EXP. Points!"
+ prompt
```
-**Fix:** Change both `deciram wStringBuffer2, 2, 4` to `deciram wStringBuffer2, 2, 5`.
-
## BRN/PSN/PAR do not affect catch rate
-This is a bug with `PokeBallEffect` in [engine/items/item_effects.asm](/engine/items/item_effects.asm):
-
-```asm
-; This routine is buggy. It was intended that SLP and FRZ provide a higher
-; catch rate than BRN/PSN/PAR, which in turn provide a higher catch rate than
-; no status effect at all. But instead, it makes BRN/PSN/PAR provide no
-; benefit.
-; Uncomment the line below to fix this.
- ld b, a
- ld a, [wEnemyMonStatus]
- and 1 << FRZ | SLP
- ld c, 10
- jr nz, .addstatus
- ; ld a, [wEnemyMonStatus]
- 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
+**Fix:** Edit `PokeBallEffect` in [engine/items/item_effects.asm](/engine/items/item_effects.asm):
+
+```diff
+-; This routine is buggy. It was intended that SLP and FRZ provide a higher
+-; catch rate than BRN/PSN/PAR, which in turn provide a higher catch rate than
+-; no status effect at all. But instead, it makes BRN/PSN/PAR provide no
+-; benefit.
+-; Uncomment the line below to fix this.
+ ld b, a
+ ld a, [wEnemyMonStatus]
+ and 1 << FRZ | SLP
+ ld c, 10
+ jr nz, .addstatus
+- ; ld a, [wEnemyMonStatus]
++ ld a, [wEnemyMonStatus]
+ 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
```
-**Fix:** Uncomment `ld a, [wEnemyMonStatus]`.
-
## Moon Ball does not boost catch rate
-This is a bug with `MoonBallMultiplier` in [items/item_effects.asm](/items/item_effects.asm):
-
-```asm
-MoonBallMultiplier:
-; This function is buggy.
-; Intent: multiply catch rate by 4 if mon evolves with moon stone
-; Reality: no boost
-
-...
-
-; Moon Stone's constant from Pokémon Red is used.
-; No Pokémon evolve with Burn Heal,
-; so Moon Balls always have a catch rate of 1×.
- push bc
- ld a, BANK("Evolutions and Attacks")
- call GetFarByte
- cp MOON_STONE_RED ; BURN_HEAL
- pop bc
- ret nz
+**Fix:** Edit `MoonBallMultiplier` in [items/item_effects.asm](/items/item_effects.asm):
+
+```diff
+-; Moon Stone's constant from Pokémon Red is used.
+-; No Pokémon evolve with Burn Heal,
+-; so Moon Balls always have a catch rate of 1×.
+ push bc
+ ld a, BANK("Evolutions and Attacks")
+ call GetFarByte
+- cp MOON_STONE_RED ; BURN_HEAL
++ cp MOON_STONE
+ pop bc
+ ret nz
```
-**Fix:** Change `MOON_STONE_RED` to `MOON_STONE`.
-
## Love Ball boosts catch rate for the wrong gender
-This is a bug with `LoveBallMultiplier` in [items/item_effects.asm](/items/item_effects.asm):
+**Fix:** Edit `LoveBallMultiplier` in [items/item_effects.asm](/items/item_effects.asm):
-```asm
-LoveBallMultiplier:
-; This function is buggy.
-; Intent: multiply catch rate by 8 if mons are of same species, different sex
-; Reality: multiply catch rate by 8 if mons are of same species, same sex
-
-...
+```diff
+ .wildmale
- ld a, d
- pop de
- cp d
- pop bc
- ret nz ; for the intended effect, this should be "ret z"
+ ld a, d
+ pop de
+ cp d
+ pop bc
+- ret nz ; for the intended effect, this should be "ret z"
++ ret z
```
-**Fix:** Change `ret nz` to `ret z`.
-
## Fast Ball only boosts catch rate for three Pokémon
-This is a bug with `FastBallMultiplier` in [items/item_effects.asm](/items/item_effects.asm):
-
-```asm
-FastBallMultiplier:
-; This function is buggy.
-; Intent: multiply catch rate by 4 if enemy mon is in one of the three
-; FleeMons tables.
-; Reality: multiply catch rate by 4 if enemy mon is one of the first three in
-; the first FleeMons table.
-
-...
-
- inc hl
- cp -1
- jr z, .next
- cp c
- jr nz, .next ; for the intended effect, this should be "jr nz, .loop"
- sla b
- jr c, .max
+**Fix:** Edit `FastBallMultiplier` in [items/item_effects.asm](/items/item_effects.asm):
+
+```diff
+ .loop
+ ld a, BANK(FleeMons)
+ call GetFarByte
+
+ inc hl
+ cp -1
+ jr z, .next
+ cp c
+- jr nz, .next ; for the intended effect, this should be "jr nz, .loop"
++ jr nz, .loop
+ sla b
+ jr c, .max
```
-**Fix:** Change `jr nz, .next` to `jr nz, .loop`.
-
## Dragon Scale, not Dragon Fang, boosts Dragon-type moves
*Fixing this bug will break compatibility with standard Pokémon Crystal for link battles.*
-This is a bug with `ItemAttributes` in [data/items/attributes.asm](/data/items/attributes.asm):
+**Fix:** Edit `ItemAttributes` in [data/items/attributes.asm](/data/items/attributes.asm):
-```asm
-; DRAGON_FANG
- item_attribute 100, 0, 0, CANT_SELECT, ITEM, ITEMMENU_NOUSE, ITEMMENU_NOUSE
-
-...
-
-; DRAGON_SCALE
- item_attribute 2100, HELD_DRAGON_BOOST, 10, CANT_SELECT, ITEM, ITEMMENU_NOUSE, ITEMMENU_NOUSE
+```diff
+ ; DRAGON_FANG
+- item_attribute 100, HELD_NONE, 0, CANT_SELECT, ITEM, ITEMMENU_NOUSE, ITEMMENU_NOUSE
++ item_attribute 100, HELD_DRAGON_BOOST, 0, 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, 10, CANT_SELECT, ITEM, ITEMMENU_NOUSE, ITEMMENU_NOUSE
```
-**Fix:** Move `HELD_DRAGON_BOOST` to the `DRAGON_FANG` attributes and `0` to `DRAGON_SCALE`.
-
## Daisy's grooming doesn't always increase happiness
@@ -827,273 +787,344 @@ CopyPokemonName_Buffer1_Buffer3:
jp CopyBytes
```
-In [data/events/happiness_probabilities.asm](/data/events/happiness_probabilities.asm):
+**Fix:** Edit [data/events/happiness_probabilities.asm](/data/events/happiness_probabilities.asm):
-```asm
-HappinessData_DaisysGrooming:
- db $ff, 2, HAPPINESS_GROOMING ; 99.6% chance
-```
-
-**Fix:**
-
-```asm
-HappinessData_DaisysGrooming:
- db $80, 2, HAPPINESS_GROOMING ; 50% chance
- db $ff, 2, HAPPINESS_GROOMING ; 50% chance
+```diff
+ HappinessData_DaisysGrooming:
+- db $ff, 2, HAPPINESS_GROOMING ; 99.6% chance
++ db $80, 2, HAPPINESS_GROOMING ; 50% chance
++ db $ff, 2, HAPPINESS_GROOMING ; 50% chance
```
## Magikarp in Lake of Rage are shorter, not longer
-This is a bug with `LoadEnemyMon.CheckMagikarpArea` in [engine/battle/core.asm](/engine/battle/core.asm):
-
-```asm
-.CheckMagikarpArea:
-; The "jr z" checks are supposed to be "jr nz".
-
-; Instead, all maps in GROUP_LAKE_OF_RAGE (Mahogany area)
-; and Routes 20 and 44 are treated as Lake of Rage.
-
-; This also means Lake of Rage Magikarp can be smaller than ones
-; caught elsewhere rather than the other way around.
-
-; Intended behavior enforces a minimum size at Lake of Rage.
-; The real behavior prevents a minimum size in the Lake of Rage area.
-
-; Moreover, due to the check not being translated to feet+inches, all Magikarp
-; smaller than 4'0" may be caught by the filter, a lot more than intended.
- ld a, [wMapGroup]
- cp GROUP_LAKE_OF_RAGE
- jr z, .Happiness
- ld a, [wMapNumber]
- cp MAP_LAKE_OF_RAGE
- jr z, .Happiness
+**Fix:** Edit `LoadEnemyMon.CheckMagikarpArea` in [engine/battle/core.asm](/engine/battle/core.asm):
+
+```diff
+ .CheckMagikarpArea:
+-; The "jr z" checks are supposed to be "jr nz".
+-
+-; Instead, all maps in GROUP_LAKE_OF_RAGE (Mahogany area)
+-; and Routes 20 and 44 are treated as Lake of Rage.
+-
+-; This also means Lake of Rage Magikarp can be smaller than ones
+-; caught elsewhere rather than the other way around.
+-
+-; Intended behavior enforces a minimum size at Lake of Rage.
+-; The real behavior prevents a minimum size in the Lake of Rage area.
+-
+-; Moreover, due to the check not being translated to feet+inches, all Magikarp
+-; smaller than 4'0" may be caught by the filter, a lot more than intended.
+ 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
```
-**Fix:** Change both `jr z, .Happiness` to `jr nz, .Happiness`.
-
## Magikarp length limits have a unit conversion error
-This is a bug with `LoadEnemyMon.CheckMagikarpArea` in [engine/battle/core.asm](/engine/battle/core.asm):
-
-```asm
-; Get Magikarp's length
- ld de, wEnemyMonDVs
- ld bc, wPlayerID
- callfar CalcMagikarpLength
-
-; No reason to keep going if length > 1536 mm (i.e. if HIGH(length) > 6 feet)
- ld a, [wMagikarpLength]
- cp HIGH(1536) ; should be "cp 5", since 1536 mm = 5'0", but HIGH(1536) = 6
- 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) >= 3 inches)
- ld a, [wMagikarpLength + 1]
- cp LOW(1616) ; should be "cp 3", since 1616 mm = 5'3", but LOW(1616) = 80
- 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) >= 2 inches)
- ld a, [wMagikarpLength + 1]
- cp LOW(1600) ; should be "cp 2", since 1600 mm = 5'2", but LOW(1600) = 64
- jr nc, .GenerateDVs
+**Fix:** Edit `LoadEnemyMon.CheckMagikarpArea` in [engine/battle/core.asm](/engine/battle/core.asm):
+
+```diff
+ ; Get Magikarp's length
+ ld de, wEnemyMonDVs
+ ld bc, wPlayerID
+ callfar CalcMagikarpLength
+
+ ; No reason to keep going if length > 1536 mm (i.e. if HIGH(length) > 6 feet)
+ ld a, [wMagikarpLength]
+- cp HIGH(1536) ; should be "cp 5", since 1536 mm = 5'0", but HIGH(1536) = 6
++ 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) >= 3 inches)
+ ld a, [wMagikarpLength + 1]
+- cp LOW(1616) ; should be "cp 3", since 1616 mm = 5'3", but LOW(1616) = 80
++ cp 3
+ 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) >= 2 inches)
+ ld a, [wMagikarpLength + 1]
+- cp LOW(1600) ; should be "cp 2", since 1600 mm = 5'2", but LOW(1600) = 64
++ cp 2
+ jr nc, .GenerateDVs
```
-**Fix:** Change the three `cp` instructions to use their commented values.
-
## Magikarp lengths can be miscalculated
-This is a bug with `CalcMagikarpLength.BCLessThanDE` in [engine/events/magikarp.asm](/engine/events/magikarp.asm):
-
-```asm
-.BCLessThanDE:
-; Intention: Return bc < de.
-; Reality: Return b < d.
- ld a, b
- cp d
- ret c
- ret nc ; whoops
- ld a, c
- cp e
- ret
+**Fix:** Edit `CalcMagikarpLength.BCLessThanDE` in [engine/events/magikarp.asm](/engine/events/magikarp.asm):
+
+```diff
+ .BCLessThanDE:
+-; Intention: Return bc < de.
+-; Reality: Return b < d.
+ ld a, b
+ cp d
+ ret c
+- ret nc ; whoops
+ ld a, c
+ cp e
+ ret
```
-**Fix:** Delete `ret nc`.
-
## Battle transitions fail to account for the enemy's level
([Video](https://www.youtube.com/watch?v=eij_1060SMc))
-This is a bug with `StartTrainerBattle_DetermineWhichAnimation` in [engine/battle/battle_transition.asm](/engine/battle/battle_transition.asm):
+There are three things wrong here:
-```asm
-StartTrainerBattle_DetermineWhichAnimation:
-; The screen flashes a different number of times depending on the level of
-; your lead Pokemon relative to the opponent's.
-; BUG: wBattleMonLevel and wEnemyMonLevel are not set at this point, so whatever
-; values happen to be there will determine the animation.
+- `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
+
+**Fix:**
+
+First, edit [engine/battle/battle_transition.asm](/engine/battle/battle_transition.asm):
+
+```diff
+ StartTrainerBattle_DetermineWhichAnimation:
+ ; The screen flashes a different number of times depending on the level of
+ ; your lead Pokemon relative to the opponent's.
+-; BUG: wBattleMonLevel and wEnemyMonLevel are not set at this point, so whatever
+-; values happen to be there will determine the animation.
++ 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
++ ld de, MON_LEVEL - MON_HP
++ add hl, de
ld de, 0
- ld a, [wBattleMonLevel]
- add 3
- ld hl, wEnemyMonLevel
- 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
+- ld a, [wBattleMonLevel]
++ ld a, [hl]
+ add 3
+- ld hl, wEnemyMonLevel
++ ld hl, wCurPartyLevel
+ 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
+
+ .StartingPoints:
+ ; entries correspond to TRANS_* constants
+ db BATTLETRANSITION_CAVE
+ db BATTLETRANSITION_CAVE_STRONGER
+ db BATTLETRANSITION_NO_CAVE
+ db BATTLETRANSITION_NO_CAVE_STRONGER
+```
-.StartingPoints:
-; entries correspond to TRANS_* constants
- db BATTLETRANSITION_CAVE
- db BATTLETRANSITION_CAVE_STRONGER
- db BATTLETRANSITION_NO_CAVE
- db BATTLETRANSITION_NO_CAVE_STRONGER
+Then edit [engine/battle/start_battle.asm](/engine/battle/start_battle.asm):
+
+```diff
+ FindFirstAliveMonAndStartBattle:
+ xor a
+ ld [hMapAnims], a
+ call DelayFrame
+- ld b, 6
+- 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
+ predef DoBattleTransition
```
-*To do:* Fix this bug.
+Finally, edit [engine/battle/read_trainer_party.asm](/engine/battle/read_trainer_party.asm):
+
+```diff
+ 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
++.loop1
++ ld a, [hli]
++ cp $ff
++ jr nz, .loop1
++ jr .skip_trainer
++.got_trainer
++
++.skip_name
++ ld a, [hli]
++ cp "@"
++ jr nz, .skip_name
++
++ inc hl
++ ld a, [hl]
++ ld [wCurPartyLevel], a
++ ret
+```
## A "HOF Master!" title for 200-Time Famers is defined but inaccessible
([Video](https://www.youtube.com/watch?v=iHkWubvxmSg))
-This is a bug with `_HallOfFamePC.DisplayMonAndStrings` in [engine/events/halloffame.asm](/engine/events/halloffame.asm):
-
-```asm
- ld a, [wHallOfFameTempWinCount]
- cp HOF_MASTER_COUNT + 1 ; should be HOF_MASTER_COUNT
- jr c, .print_num_hof
- ld de, .HOFMaster
- hlcoord 1, 2
- call PlaceString
- hlcoord 13, 2
- jr .finish
+**Fix:** Edit `_HallOfFamePC.DisplayMonAndStrings` in [engine/events/halloffame.asm](/engine/events/halloffame.asm):
+
+```diff
+ ld a, [wHallOfFameTempWinCount]
+- cp HOF_MASTER_COUNT + 1 ; should be HOF_MASTER_COUNT
++ cp HOF_MASTER_COUNT
+ jr c, .print_num_hof
+ ld de, .HOFMaster
+ hlcoord 1, 2
+ call PlaceString
+ hlcoord 13, 2
+ jr .finish
```
-**Fix:** Change `HOF_MASTER_COUNT + 1` to `HOF_MASTER_COUNT`.
-
## Slot machine payout sound effects cut each other off
([Video](https://www.youtube.com/watch?v=ojq3xqfRF6I))
-This is a bug with `Slots_PayoutAnim` in [engine/games/slot_machine.asm](/engine/games/slot_machine.asm):
-
-```asm
-.okay
- ld [hl], e
- dec hl
- ld [hl], d
- ld a, [wSlotsDelay]
- and $7
- ret z ; ret nz would be more appropriate
- ld de, SFX_GET_COIN_FROM_SLOTS
- call PlaySFX
- ret
+**Fix:** Edit `Slots_PayoutAnim` in [engine/games/slot_machine.asm](/engine/games/slot_machine.asm):
+
+```diff
+ .okay
+ ld [hl], e
+ dec hl
+ ld [hl], d
+ ld a, [wSlotsDelay]
+ and $7
+- ret z ; ret nz would be more appropriate
++ ret nz
+ ld de, SFX_GET_COIN_FROM_SLOTS
+ call PlaySFX
+ ret
```
-**Fix:** Change `ret z` to `ret nz`.
-
## Team Rocket battle music is not used for Executives or Scientists
-This is a bug with `PlayBattleMusic` in [engine/battle/start_battle.asm](/engine/battle/start_battle.asm):
-
-```asm
- ; They should have included EXECUTIVEM, EXECUTIVEF, and SCIENTIST too...
- ld de, MUSIC_ROCKET_BATTLE
- cp GRUNTM
- jr z, .done
- cp GRUNTF
- jr z, .done
-```
-
-**Fix:**
-
-```asm
- ld de, MUSIC_ROCKET_BATTLE
- cp GRUNTM
- jr z, .done
- cp GRUNTF
- jr z, .done
- cp EXECUTIVEM
- jr z, .done
- cp EXECUTIVEF
- jr z, .done
- cp SCIENTIST
- jr z, .done
+**Fix:** Edit `PlayBattleMusic` in [engine/battle/start_battle.asm](/engine/battle/start_battle.asm):
+
+```diff
+ ld de, MUSIC_ROCKET_BATTLE
+ cp GRUNTM
+ jr z, .done
+ cp GRUNTF
+ jr z, .done
++ cp EXECUTIVEM
++ jr z, .done
++ cp EXECUTIVEF
++ jr z, .done
++ cp SCIENTIST
++ jr z, .done
```
## No bump noise if standing on tile `$3E`
-This is a bug with `DoPlayerMovement.CheckWarp` in [engine/overworld/player_movement.asm](/engine/overworld/player_movement.asm):
-
-```asm
-; Bug: Since no case is made for STANDING here, it will check
-; [.edgewarps + $ff]. This resolves to $3e at $8035a.
-; This causes wd041 to be nonzero when standing on tile $3e,
-; making bumps silent.
-
- ld a, [wWalkingDirection]
- ; cp STANDING
- ; jr z, .not_warp
- ld e, a
- ld d, 0
- ld hl, .EdgeWarps
- add hl, de
- ld a, [wPlayerStandingTile]
- cp [hl]
- jr nz, .not_warp
-
- ld a, 1
- ld [wd041], a
- ld a, [wWalkingDirection]
- ; This is in the wrong place.
- cp STANDING
- jr z, .not_warp
-```
-
-**Fix:**
-
-```asm
- ld a, [wWalkingDirection]
- cp STANDING
- jr z, .not_warp
- ld e, a
- ld d, 0
- ld hl, .EdgeWarps
- add hl, de
- ld a, [wPlayerStandingTile]
- cp [hl]
- jr nz, .not_warp
-
- ld a, 1
- ld [wd041], a
- ld a, [wWalkingDirection]
+**Fix:** Edit `DoPlayerMovement.CheckWarp` in [engine/overworld/player_movement.asm](/engine/overworld/player_movement.asm):
+
+```diff
+ .CheckWarp:
+-; Bug: Since no case is made for STANDING here, it will check
+-; [.edgewarps + $ff]. This resolves to $3e at $8035a.
+-; This causes wd041 to be nonzero when standing on tile $3e,
+-; making bumps silent.
+-
+ ld a, [wWalkingDirection]
+- ; cp STANDING
+- ; jr z, .not_warp
++ cp STANDING
++ jr z, .not_warp
+ ld e, a
+ ld d, 0
+ ld hl, .EdgeWarps
+ add hl, de
+ ld a, [wPlayerStandingTile]
+ cp [hl]
+ jr nz, .not_warp
+
+ ld a, 1
+ ld [wd041], a
+ ld a, [wWalkingDirection]
+- ; This is in the wrong place.
+- cp STANDING
+- jr z, .not_warp
```
@@ -1101,26 +1132,21 @@ This is a bug with `DoPlayerMovement.CheckWarp` in [engine/overworld/player_move
([Video](https://www.youtube.com/watch?v=z305e4sIO24))
-The exact cause is unknown, but a workaround exists for `DexEntryScreen_MenuActionJumptable.Cry` in [engine/pokedex/pokedex.asm](/engine/pokedex/pokedex.asm):
-
-```asm
-.Cry:
- call Pokedex_GetSelectedMon
- ld a, [wd265]
- call GetCryIndex
- ld e, c
- ld d, b
- call PlayCry
- ret
-```
-
-**Workaround:**
-
-```asm
-.Cry:
- ld a, [wCurPartySpecies]
- call PlayMonCry
- ret
+The exact cause of this bug is unknown.
+
+**Workaround:** Edit `DexEntryScreen_MenuActionJumptable.Cry` in [engine/pokedex/pokedex.asm](/engine/pokedex/pokedex.asm):
+
+```diff
+ .Cry:
+- call Pokedex_GetSelectedMon
+- ld a, [wTempSpecies]
+- call GetCryIndex
+- ld e, c
+- ld d, b
+- call PlayCry
++ ld a, [wCurPartySpecies]
++ call PlayMonCry
+ ret
```
@@ -1150,29 +1176,28 @@ This is a mistake with the left-hand warp carpet corner tiles in [gfx/tilesets/p
This bug prevents you from using blocksets with more than 128 blocks.
-In [home/map.asm](/home/map.asm):
-
-```asm
- ; Set hl to the address of the current metatile data ([wTilesetBlocksAddress] + (a) tiles).
- ; This is buggy; it wraps around past 128 blocks.
- ; To fix, uncomment the line below.
- add a ; Comment or delete this line to fix the above bug.
- 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
+**Fix:** Edit `LoadMetatiles` in [home/map.asm](/home/map.asm):
+
+```diff
+ ; Set hl to the address of the current metatile data ([wTilesetBlocksAddress] + (a) tiles).
+- ; This is buggy; it wraps around past 128 blocks.
+- ; To fix, uncomment the line below.
+- add a ; Comment or delete this line to fix the above bug.
+ ld l, a
+ ld h, 0
+- ; add hl, hl
++ 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
```
-**Fix:** Delete `add a` and uncomment `add hl, hl`.
-
## Surfing directly across a map connection does not load the new map
@@ -1185,17 +1210,16 @@ In [home/map.asm](/home/map.asm):
This bug is why the Lapras in [maps/UnionCaveB2F.asm](/maps/UnionCaveB2F.asm), which uses `SPRITEMOVEDATA_SWIM_WANDER`, is not restricted by its `1, 1` movement radius.
-This is a bug with `CanObjectMoveInDirection` in [engine/overworld/npc_movement.asm](/engine/overworld/npc_movement.asm):
+**Fix:** Edit `CanObjectMoveInDirection` in [engine/overworld/npc_movement.asm](/engine/overworld/npc_movement.asm):
-```asm
- ld hl, OBJECT_FLAGS1
- add hl, bc
- bit NOCLIP_TILES_F, [hl] ; lost, uncomment next line to fix
- ; jr nz, .noclip_tiles
+```diff
+ ld hl, OBJECT_FLAGS1
+ add hl, bc
+ bit NOCLIP_TILES_F, [hl] ; lost, uncomment next line to fix
+- ; jr nz, .noclip_tiles
++ jr nz, .noclip_tiles
```
-**Fix:** Uncomment `jr nz, .noclip_tiles`.
-
## `CheckOwnMon` only checks the first five letters of OT names
@@ -1203,102 +1227,74 @@ This is a bug with `CanObjectMoveInDirection` in [engine/overworld/npc_movement.
This bug can allow you to talk to Eusine in Celadon City and encounter Ho-Oh with only traded legendary beasts.
-In [engine/pokemon/search.asm](/engine/pokemon/search.asm):
-
-```asm
-; check OT
-; This only checks five characters, which is fine for the Japanese version,
-; but in the English version the player name is 7 characters, so this is wrong.
-
- ld hl, wPlayerName
-
-rept NAME_LENGTH_JAPANESE + -2 ; should be PLAYER_NAME_LENGTH + -2
- 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
+**Fix:** Edit `CheckOwnMon` in [engine/pokemon/search.asm](/engine/pokemon/search.asm):
+
+```diff
+ ; check OT
+-; This only checks five characters, which is fine for the Japanese version,
+-; but in the English version the player name is 7 characters, so this is wrong.
+
+ ld hl, wPlayerName
+
+-rept NAME_LENGTH_JAPANESE + -2 ; should be PLAYER_NAME_LENGTH + -2
++rept PLAYER_NAME_LENGTH + -2
+ 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
```
-**Fix:** Change `rept NAME_LENGTH_JAPANESE + -2` to `rept PLAYER_NAME_LENGTH + -2`.
-
## Catching a Transformed Pokémon always catches a Ditto
This bug can affect Mew or Pokémon other than Ditto that used Transform via Mirror Move or Sketch.
-This is a bug with `PokeBallEffect` in [engine/items/item_effects.asm](/engine/items/item_effects.asm):
-
-```asm
- ld hl, wEnemySubStatus5
- ld a, [hl]
- push af
- set SUBSTATUS_TRANSFORMED, [hl]
-
-; This code is buggy. Any wild Pokémon that has Transformed will be
-; caught as a Ditto, even if it was something else like Mew.
-; To fix, do not set [wTempEnemyMonSpecies] to DITTO.
- bit SUBSTATUS_TRANSFORMED, a
- jr nz, .ditto
- jr .not_ditto
-
-.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]
- ld [hl], a
-
-.load_data
- ld a, [wTempEnemyMonSpecies]
- ld [wCurPartySpecies], a
- ld a, [wEnemyMonLevel]
- ld [wCurPartyLevel], a
- farcall LoadEnemyMon
-
- pop af
- ld [wEnemySubStatus5], a
-```
-
-**Fix:**
-
-```asm
- ld hl, wEnemySubStatus5
- ld a, [hl]
- push af
- set SUBSTATUS_TRANSFORMED, [hl]
-
- bit SUBSTATUS_TRANSFORMED, a
- jr nz, .load_data
-
- ld hl, wEnemyBackupDVs
- ld a, [wEnemyMonDVs]
- ld [hli], a
- ld a, [wEnemyMonDVs + 1]
- ld [hl], a
-
-.load_data
- ld a, [wTempEnemyMonSpecies]
- ld [wCurPartySpecies], a
- ld a, [wEnemyMonLevel]
- ld [wCurPartyLevel], a
- farcall LoadEnemyMon
-
- pop af
- ld [wEnemySubStatus5], a
+**Fix:** Edit `PokeBallEffect` in [engine/items/item_effects.asm](/engine/items/item_effects.asm):
+
+```diff
+ ld hl, wEnemySubStatus5
+ ld a, [hl]
+ push af
+ set SUBSTATUS_TRANSFORMED, [hl]
+
+-; This code is buggy. Any wild Pokémon that has Transformed will be
+-; caught as a Ditto, even if it was something else like Mew.
+-; To fix, do not set [wTempEnemyMonSpecies] to DITTO.
+ bit SUBSTATUS_TRANSFORMED, a
+- jr nz, .ditto
+- jr .not_ditto
++ jr nz, .load_data
+
+-.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]
+ ld [hl], a
+
+ .load_data
+ ld a, [wTempEnemyMonSpecies]
+ ld [wCurPartySpecies], a
+ ld a, [wEnemyMonLevel]
+ ld [wCurPartyLevel], a
+ farcall LoadEnemyMon
+
+ pop af
+ ld [wEnemySubStatus5], a
```
@@ -1306,109 +1302,87 @@ This is a bug with `PokeBallEffect` in [engine/items/item_effects.asm](/engine/i
([Video](https://www.youtube.com/watch?v=v1ErZdLCIyU))
-This is a bug with `PokeBallEffect` in [engine/items/item_effects.asm](/engine/items/item_effects.asm):
-
-```asm
-.room_in_party
- xor a
- ld [wWildMon], a
- ld a, [wCurItem]
- cp PARK_BALL
- call nz, ReturnToBattle_UseBall
-```
-
-**Fix:**
-
-```asm
-.room_in_party
- xor a
- ld [wWildMon], a
- ld a, [wBattleType]
- cp BATTLETYPE_CONTEST
- call nz, ReturnToBattle_UseBall
+**Fix:** Edit `PokeBallEffect` in [engine/items/item_effects.asm](/engine/items/item_effects.asm):
+
+```diff
+ .room_in_party
+ xor a
+ ld [wWildMon], a
+- ld a, [wCurItem]
+- cp PARK_BALL
++ ld a, [wBattleType]
++ cp BATTLETYPE_CONTEST
+ call nz, ReturnToBattle_UseBall
```
## `HELD_CATCH_CHANCE` has no effect
-This is a bug with `PokeBallEffect` in [engine/items/item_effects.asm](/engine/items/item_effects.asm):
-
-```asm
- ; BUG: farcall overwrites a, and GetItemHeldEffect takes b anyway.
- ; This is probably the reason the HELD_CATCH_CHANCE effect is never used.
- ; Uncomment the line below to fix.
- 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
+**Fix:** Edit `PokeBallEffect` in [engine/items/item_effects.asm](/engine/items/item_effects.asm):
+
+```diff
+- ; BUG: farcall overwrites a, and GetItemHeldEffect takes b anyway.
+- ; This is probably the reason the HELD_CATCH_CHANCE effect is never used.
+- ; Uncomment the line below to fix.
+ ld d, a
+ push de
+ ld a, [wBattleMonItem]
+- ; ld b, a
++ 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
```
-**Fix:** Uncomment `ld b, a`.
-
## Only the first three evolution entries can have Stone compatibility reported correctly
-This is a bug with `PlacePartyMonEvoStoneCompatibility.DetermineCompatibility` in [engine/pokemon/party_menu.asm](/engine/pokemon/party_menu.asm):
-
-```asm
-.DetermineCompatibility:
- 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
- call FarCopyBytes
+**Workaround:** Edit `PlacePartyMonEvoStoneCompatibility.DetermineCompatibility` in [engine/pokemon/party_menu.asm](/engine/pokemon/party_menu.asm):
+
+```diff
+ .DetermineCompatibility:
+ 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
++ ld bc, wStringBuffer2 - wStringBuffer1
+ call FarCopyBytes
```
-**Fix:** Change `ld bc, 10` to `ld bc, wStringBuffer2 - wStringBuffer1` to support up to six Stone entries.
+This supports up to six entries.
## `EVOLVE_STAT` can break Stone compatibility reporting
-This is a bug with `PlacePartyMonEvoStoneCompatibility.DetermineCompatibility` in [engine/pokemon/party_menu.asm](/engine/pokemon/party_menu.asm):
-
-```asm
-.loop2
- ld a, [hli]
- and a
- jr z, .nope
- inc hl
- inc hl
- cp EVOLVE_ITEM
- jr nz, .loop2
-```
-
-**Fix:**
-
-```asm
-.loop2
- 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
+**Fix:** Edit `PlacePartyMonEvoStoneCompatibility.DetermineCompatibility` in [engine/pokemon/party_menu.asm](/engine/pokemon/party_menu.asm):
+
+```diff
+ .loop2
+ 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
```
@@ -1454,157 +1428,107 @@ ScriptCall:
## `LoadSpriteGFX` does not limit the capacity of `UsedSprites`
-In [engine/overworld/overworld.asm](/engine/overworld/overworld.asm):
-
-```asm
-LoadSpriteGFX:
-; Bug: b is not preserved, so it's useless as a next count.
-; Uncomment the lines below to fix.
-
- 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:
- ; push bc
- call GetSprite
- ; pop bc
- ld a, l
- ret
+**Fix:** Edit `LoadSpriteGFX` in [engine/overworld/overworld.asm](/engine/overworld/overworld.asm):
+
+```diff
+ LoadSpriteGFX:
+-; Bug: b is not preserved, so it's useless as a next count.
+-; Uncomment the lines below to fix.
+-
+ 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:
+- ; push bc
++ push bc
+ call GetSprite
+- ; pop bc
++ pop bc
+ ld a, l
+ ret
```
-**Fix:** Uncomment `push bc` and `pop bc`.
-
## `ChooseWildEncounter` doesn't really validate the wild Pokémon species
-In [engine/overworld/wildmons.asm](/engine/overworld/wildmons.asm):
+**Fix:** Edit `ChooseWildEncounter` in [engine/overworld/wildmons.asm](/engine/overworld/wildmons.asm):
-```asm
-ChooseWildEncounter:
-...
- ld a, b
- ld [wCurPartyLevel], a
- ld b, [hl]
- ; ld a, b
- call ValidateTempWildMonSpecies
- jr c, .nowildbattle
-
- ld a, b ; This is in the wrong place.
- cp UNOWN
- jr nz, .done
-
-...
+```diff
+ .ok
+ ld a, b
+ ld [wCurPartyLevel], a
+ ld b, [hl]
+- ; ld a, b
++ ld a, b
+ call ValidateTempWildMonSpecies
+ jr c, .nowildbattle
-ValidateTempWildMonSpecies:
-; Due to a development oversight, this function is called with the wild Pokemon's level, not its species, in a.
+ cp UNOWN
+ jr nz, .done
```
-**Fix:**
-
-```asm
- ld a, b
- ld [wCurPartyLevel], a
- ld b, [hl]
- ld a, b
- call ValidateTempWildMonSpecies
- jr c, .nowildbattle
-
- cp UNOWN
- jr nz, .done
-```
## `TryObjectEvent` arbitrary code execution
-In [engine/overworld/events.asm](/engine/overworld/events.asm):
-
-```asm
-; Bug: If IsInArray returns nc, data at bc will be executed as code.
- push bc
- ld de, 3
- ld hl, .pointers
- call IsInArray
- jr nc, .nope_bugged
- pop bc
-
- inc hl
- ld a, [hli]
- ld h, [hl]
- ld l, a
- jp hl
-
-.nope_bugged
- ; pop bc
- xor a
- ret
-```
-
-**Fix:** Uncomment `pop bc`.
-
-
-## `CheckBugContestContestantFlag` can read beyond its data table
-
-In [engine/events/bug_contest/contest_2.asm](/engine/events/bug_contest/contest_2.asm):
-
-```asm
-CheckBugContestContestantFlag:
-; Checks the flag of the Bug Catching Contestant whose index is loaded in a.
-
-; Bug: If a >= NUM_BUG_CONTESTANTS when this is called,
-; it will read beyond the table.
-
- ld hl, BugCatchingContestantEventFlagTable
- ld e, a
- ld d, 0
- add hl, de
- add hl, de
- ld e, [hl]
- inc hl
- ld d, [hl]
- ld b, CHECK_FLAG
- call EventFlagAction
- ret
-
-INCLUDE "data/events/bug_contest_flags.asm"
+**Fix:** Edit `TryObjectEvent` in [engine/overworld/events.asm](/engine/overworld/events.asm):
+
+```diff
+-; Bug: If IsInArray returns nc, data at bc will be executed as code.
+ push bc
+ ld de, 3
+ ld hl, .pointers
+ call IsInArray
+ jr nc, .nope_bugged
+ pop bc
+
+ inc hl
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp hl
+
+ .nope_bugged
+- ; pop bc
++ pop bc
+ xor a
+ ret
```
-However, `a < NUM_BUG_CONTESTANTS` should always be true, so in practice this is not a problem.
-
## `ClearWRAM` only clears WRAM bank 1
-In [home/init.asm](/home/init.asm):
-
-```asm
-ClearWRAM::
-; Wipe swappable WRAM banks (1-7)
-; Assumes CGB or AGB
-
- ld a, 1
-.bank_loop
- push af
- ld [rSVBK], a
- xor a
- ld hl, WRAM1_Begin
- ld bc, WRAM1_End - WRAM1_Begin
- call ByteFill
- pop af
- inc a
- cp 8
- jr nc, .bank_loop ; Should be jr c
- ret
+**Fix:** Edit `ClearWRAM` in [home/init.asm](/home/init.asm):
+
+```diff
+ ClearWRAM::
+ ; Wipe swappable WRAM banks (1-7)
+ ; Assumes CGB or AGB
+
+ ld a, 1
+ .bank_loop
+ push af
+ ld [rSVBK], a
+ xor a
+ ld hl, WRAM1_Begin
+ ld bc, WRAM1_End - WRAM1_Begin
+ call ByteFill
+ pop af
+ inc a
+ cp 8
+- jr nc, .bank_loop ; Should be jr c
++ jr c, .bank_loop
+ ret
```
-
-**Fix:** Change `jr nc, .bank_loop` to `jr c, .bank_loop`.
diff --git a/docs/design_flaws.md b/docs/design_flaws.md
index 4b24a0cc3..80c34dfdb 100644
--- a/docs/design_flaws.md
+++ b/docs/design_flaws.md
@@ -152,41 +152,44 @@ Don't enforce `org $4000` in pokecrystal.link.
Modify `GetFrontpicPointer`:
-```asm
- ld a, [wCurPartySpecies]
- cp UNOWN
- jr z, .unown
- ld a, [wCurPartySpecies]
- ld hl, PokemonPicPointers
- ld d, BANK(PokemonPicPointers)
- jr .ok
-
-.unown
- ld a, [wUnownLetter]
- ld hl, UnownPicPointers
- ld d, BANK(UnownPicPointers)
-
-.ok
- dec a
- ld bc, 6
- call AddNTimes
+```diff
+ ld a, [wCurPartySpecies]
+ cp UNOWN
+ jr z, .unown
+ ld a, [wCurPartySpecies]
++ ld hl, PokemonPicPointers
+ ld d, BANK(PokemonPicPointers)
+ jr .ok
+
+ .unown
+ ld a, [wUnownLetter]
++ ld hl, UnownPicPointers
+ ld d, BANK(UnownPicPointers)
+
+ .ok
+- ld hl, PokemonPicPointers ; UnownPicPointers
+ dec a
+ ld bc, 6
+ call AddNTimes
```
And `GetMonBackpic`:
-```asm
- ld a, b
- ld hl, PokemonPicPointers
- ld d, BANK(PokemonPicPointers)
- cp UNOWN
- jr nz, .ok
- ld a, c
- ld hl, UnownPicPointers
- ld d, BANK(UnownPicPointers)
-.ok
- dec a
- ld bc, 6
- call AddNTimes
+```diff
+- ; These are assumed to be at the same address in their respective banks.
+- ld hl, PokemonPicPointers ; UnownPicPointers
+ ld a, b
++ ld hl, PokemonPicPointers
+ ld d, BANK(PokemonPicPointers)
+ cp UNOWN
+ jr nz, .ok
+ ld a, c
++ ld hl, UnownPicPointers
+ ld d, BANK(UnownPicPointers)
+ .ok
+ dec a
+ ld bc, 6
+ call AddNTimes
```
@@ -268,12 +271,26 @@ INCBIN "gfx/footprints/wartortle.1bpp"
Modify `Pokedex_LoadAnyFootprint`:
-```asm
- ld e, l
- ld d, h
- ld hl, vTiles2 tile $62
- lb bc, BANK(Footprints), 4
- call Request1bpp
+```diff
+- push hl
+ ld e, l
+ ld d, h
+ ld hl, vTiles2 tile $62
+- lb bc, BANK(Footprints), 2
++ lb bc, BANK(Footprints), 4
+ call Request1bpp
+- pop hl
+-
+- ; Whoever was editing footprints forgot to fix their
+- ; tile editor. Now each bottom half is 8 tiles off.
+- ld de, 8 tiles
+- add hl, de
+-
+- ld e, l
+- ld d, h
+- ld hl, vTiles2 tile $64
+- lb bc, BANK(Footprints), 2
+- call Request1bpp
```
@@ -341,22 +358,41 @@ Move `ITEM_C3` and `ITEM_DC` above all the TMs in every table of item data.
Modify engine/items/items.asm:
-```asm
-GetTMHMNumber::
-; Return the number of a TM/HM by item id c.
- ld a, c
- sub TM01
- inc a
- ld c, a
- ret
-
-GetNumberedTMHM:
-; Return the item id of a TM/HM by number c.
- ld a, c
- add TM01
- dec a
- ld c, a
- ret
+```diff
+ GetTMHMNumber::
+ ; Return the number of a TM/HM by item id c.
+ ld a, c
+-; Skip any dummy items.
+- cp ITEM_C3 ; TM04-05
+- jr c, .done
+- cp ITEM_DC ; TM28-29
+- jr c, .skip
+- dec a
+-.skip
+- dec a
+-.done
+ sub TM01
+ inc a
+ ld c, a
+ ret
+
+ GetNumberedTMHM:
+ ; Return the item id of a TM/HM by number c.
+ ld a, c
+-; Skip any gaps.
+- cp ITEM_C3 - (TM01 - 1)
+- jr c, .done
+- cp ITEM_DC - (TM01 - 1) - 1
+- jr c, .skip_one
+-.skip_two
+- inc a
+-.skip_one
+- inc a
+-.done
+ add TM01
+ dec a
+ ld c, a
+ ret
```
diff --git a/docs/move_effect_commands.md b/docs/move_effect_commands.md
index a7a779123..acb9eca8e 100644
--- a/docs/move_effect_commands.md
+++ b/docs/move_effect_commands.md
@@ -29,13 +29,13 @@ Defined in [macros/scripts/battle_commands.asm](/macros/scripts/battle_commands.
## `$0D`: `failuretext`
-## `$0E`: `checkfaint`
+## `$0E`: `applydamage`
## `$0F`: `criticaltext`
## `$10`: `supereffectivetext`
-## `$11`: `checkdestinybond`
+## `$11`: `checkfaint`
## `$12`: `buildopponentrage`
@@ -331,13 +331,13 @@ Defined in [macros/scripts/battle_commands.asm](/macros/scripts/battle_commands.
## `$A4`: `allstatsup`
-## `$A5`: `effect0xa5`
+## `$A5`: `bidefailtext`
## `$A6`: `raisesubnoanim`
## `$A7`: `lowersubnoanim`
-## `$A8`: `effect0xa8`
+## `$A8`: `beatupfailtext`
## `$A9`: `clearmissdamage`