shithub: pokecrystal

Download patch

ref: 96bcf72d96cf59e3e1f5aaefb9b62b5e9b154e18
parent: 771d2efd6569036531d69cf79d9b5aa163341cfc
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Sat Feb 16 08:31:23 EST 2019

Document the BattleAnimCmd_ClearObjs bug

--- a/docs/bugs_and_glitches.md
+++ b/docs/bugs_and_glitches.md
@@ -68,6 +68,7 @@
 - [`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)
 - [`ClearWRAM` only clears WRAM bank 1](#clearwram-only-clears-wram-bank-1)
+- [`BattleAnimCmd_ClearObjs` only clears the first 6⅔ objects](#battleanimcmd_clearobjs-only-clears-the-first-6⅔-objects)
 
 
 ## Thick Club and Light Ball can make (Special) Attack wrap around above 1024
@@ -1583,5 +1584,24 @@
  	cp 8
 -	jr nc, .bank_loop ; Should be jr c
 +	jr c, .bank_loop
+ 	ret
+```
+
+
+## `BattleAnimCmd_ClearObjs` only clears the first 6⅔ objects
+
+**Fix:** Edit `BattleAnimCmd_ClearObjs` in [engine/battle_anims/anim_commands.asm](/engine/battle_anims/anim_commands.asm):
+
+```diff
+ BattleAnimCmd_ClearObjs:
+-; BUG: This function only clears the first 6⅔ objects
+ 	ld hl, wActiveAnimObjects
+-	ld a, $a0 ; should be NUM_ANIM_OBJECTS * BATTLEANIMSTRUCT_LENGTH
+-	ld a, NUM_ANIM_OBJECTS * BATTLEANIMSTRUCT_LENGTH
+ .loop
+ 	ld [hl], 0
+ 	inc hl
+ 	dec a
+ 	jr nz, .loop
  	ret
 ```
--- a/engine/battle_anims/anim_commands.asm
+++ b/engine/battle_anims/anim_commands.asm
@@ -644,11 +644,9 @@
 	ret
 
 BattleAnimCmd_ClearObjs:
-; BUG: This function only clears the first 6+(2/3) objects
-
+; BUG: This function only clears the first 6⅔ objects
 	ld hl, wActiveAnimObjects
-	ld a, $a0
-	; ld a, wActiveAnimObjectsEnd - wActiveAnimObjects
+	ld a, $a0 ; should be NUM_ANIM_OBJECTS * BATTLEANIMSTRUCT_LENGTH
 .loop
 	ld [hl], 0
 	inc hl