From add58fb00d73495655243c4cf13b730bbc1b3242 Mon Sep 17 00:00:00 2001 From: Eldred Habert Date: Sun, 3 Mar 2019 17:27:35 +0100 Subject: [PATCH 1/5] Fix "100% secondary effect" fix, add compatibility The original fix was bugged (example: erroneous `pop hl` if `.failed` was jumped to). Replaced with a less invasive fix, keeping all side effects from the original function; it's less intuitive, but more performant - and the tricky bit has been commented. Also the new fix is more friendly to the compatibility patch I also added, by request of ShinyDragonHunter. --- docs/bugs_and_glitches.md | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/docs/bugs_and_glitches.md b/docs/bugs_and_glitches.md index f58d2a06b..020090329 100644 --- a/docs/bugs_and_glitches.md +++ b/docs/bugs_and_glitches.md @@ -175,24 +175,38 @@ This bug existed for all battles in Gold and Silver, and was only fixed for sing ```diff - ; BUG: 1/256 chance to fail even for a 100% effect chance, - ; since carry is not set if BattleRandom == [hl] == 255 +- call BattleRandom + ld a, [hl] -+ cp 100 percent -+ jr z, .ok - call BattleRandom ++ 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 cp [hl] -- pop hl -- ret c -+ jr c, .ok + pop hl + ret c .failed ld a, 1 ld [wEffectFailed], a and a -+.ok -+ pop hl ret ``` +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: + +```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 + 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 +``` + ## Belly Drum sharply boosts Attack even with under 50% HP *Fixing this bug will break compatibility with standard Pokémon Crystal for link battles.* From c170810ad4952e3add1b1453db7436c5a8c16cce Mon Sep 17 00:00:00 2001 From: Eldred Habert Date: Sun, 3 Mar 2019 18:10:03 +0100 Subject: [PATCH 2/5] Correct indentation Add spaces before unchanged lines --- docs/bugs_and_glitches.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/bugs_and_glitches.md b/docs/bugs_and_glitches.md index 020090329..72a333757 100644 --- a/docs/bugs_and_glitches.md +++ b/docs/bugs_and_glitches.md @@ -182,8 +182,8 @@ This bug existed for all battles in Gold and Silver, and was only fixed for sing + ; Thus chance will be subtracted from 0, guaranteeing a carry + call c, BattleRandom cp [hl] - pop hl - ret c + pop hl + ret c .failed ld a, 1 @@ -199,12 +199,12 @@ If you wish to keep compatibility with standard Pokémon Crystal, you can disabl + cp LINK_COLOSSEUM + scf ; Force RNG to be called + jr z, .nofix ; Don't apply fix in link battles, for compatibility - 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 + 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 ``` ## Belly Drum sharply boosts Attack even with under 50% HP From ce7e955d10ce86109a458dca23845bf5e64c6db0 Mon Sep 17 00:00:00 2001 From: Eldred Habert Date: Sun, 3 Mar 2019 18:36:42 +0100 Subject: [PATCH 3/5] Correct Metal Powder fix The cap would be applied when it shouldn't - if the high byte was below `HIGH(MAX_STAT_VALUE)` (and thus the value below the cap) but the low byte above `LOW(MAX_STAT_VALUE)` --- docs/bugs_and_glitches.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/bugs_and_glitches.md b/docs/bugs_and_glitches.md index 72a333757..baa0a52de 100644 --- a/docs/bugs_and_glitches.md +++ b/docs/bugs_and_glitches.md @@ -126,6 +126,7 @@ Some fixes are mentioned as breaking compatibility with link battles. This can b + ld a, HIGH(MAX_STAT_VALUE) + cp b + jr c, .cap ++ ret nz + ld a, LOW(MAX_STAT_VALUE) + cp c + ret nc From 64d8a2b8fea10b4f5811f2a6f17b268e0a2959e9 Mon Sep 17 00:00:00 2001 From: Eldred Habert Date: Sun, 3 Mar 2019 18:48:24 +0100 Subject: [PATCH 4/5] Correct Thick Club overflow fix Would, similarly as previous commit, cap incorrectly. --- docs/bugs_and_glitches.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/bugs_and_glitches.md b/docs/bugs_and_glitches.md index baa0a52de..769c07601 100644 --- a/docs/bugs_and_glitches.md +++ b/docs/bugs_and_glitches.md @@ -89,6 +89,7 @@ Some fixes are mentioned as breaking compatibility with link battles. This can b + ld a, HIGH(MAX_STAT_VALUE) + cp h + jr c, .cap ++ ret nz + ld a, LOW(MAX_STAT_VALUE) + cp l + ret nc From 6b8abd1af12669a706db6377e5b38f78e5051c80 Mon Sep 17 00:00:00 2001 From: Eldred Habert Date: Sun, 3 Mar 2019 20:35:29 +0100 Subject: [PATCH 5/5] Correct compatibility claims --- docs/bugs_and_glitches.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/bugs_and_glitches.md b/docs/bugs_and_glitches.md index 769c07601..e59530db4 100644 --- a/docs/bugs_and_glitches.md +++ b/docs/bugs_and_glitches.md @@ -168,7 +168,7 @@ This bug existed for all battles in Gold and Silver, and was only fixed for sing ## Moves with a 100% secondary effect chance will not trigger it in 1/256 uses -*Fixing this bug will break compatibility with standard Pokémon Crystal for link battles.* +*Fixing this bug **may** break compatibility with standard Pokémon Crystal for link battles.* ([Video](https://www.youtube.com/watch?v=mHkyO5T5wZU&t=206)) @@ -194,7 +194,7 @@ This bug existed for all battles in Gold and Silver, and was only fixed for sing ret ``` -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: +**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: ```diff + ld a, [wLinkMode]