Focus Energy glitch: Difference between revisions

From Glitch City Wiki
Jump to navigation Jump to search
Content added Content deleted
>Krys3000
No edit summary
>Bbbbbbbbba
(Stadium fact check, code formatting)
Line 7: Line 7:
In Generation I, due to a bug, Focus Energy will always effectively quarter the player's chances of getting a critical hit.
In Generation I, due to a bug, Focus Energy will always effectively quarter the player's chances of getting a critical hit.


This glitch was fixed in [[bp:Pokémon Stadium|Pokémon Stadium]], where Focus Energy quadruples the critical hit rate instead.{{fact}}
This glitch was fixed in [[bp:Pokémon Stadium|Pokémon Stadium]], where [[bp:Critical hit#In Pokémon Stadium|a different critical hit rate formula]] is used instead, and Focus Energy indeed increases the critical hit rate.


==Analysis==
==Analysis==
The relevant block of code for Focus Energy's effect is this, beginning at offset 3E055 in Pokémon Red and Blue (view 0F:6055 in a debugger). Thanks Wack0 for walking through this.
The relevant block of code for Focus Energy's effect is this, beginning at offset 3E055 in Pokémon Red and Blue (view 0F:6055 in a debugger). Thanks Wack0 for walking through this.


bit 2, a ; test for focus energy<br/>
bit 2, a ; test for focus energy
jr nz, .focusEnergyUsed (6061)<br>
jr nz, .focusEnergyUsed
sla b ; b=b*2<br>
sla b ; b=b*2
jr nc, .noFocusEnergyUsed ; if b was below 128, skip...<br>
jr nc, .noFocusEnergyUsed ; if b was below 128, skip...
ld b, $ff ; a cap at 255/256<br>
ld b, $ff ; a cap at 255/256
jr .noFocusEnergyUsed<br>
jr .noFocusEnergyUsed
.focusEnergyUsed<br>
.focusEnergyUsed
srl b ; whoops! b=b/2, and if you look, the jump to here is before the b=b*2, so b is effectively 1/4 of what it should be<br>
srl b ; whoops! b=b/2, and if you look, the jump to here is before the b=b*2, so b is effectively 1/4 of what it should be
.noFocusEnergyUsed ; no cap at 255/256 for focus energy. I wonder if, if done properly, this would have caused bugs related to integer wraparound..<br>
.noFocusEnergyUsed ; no cap at 255/256 for focus energy. I wonder if, if done properly, this would have caused bugs related to integer wraparound...
; ... (check for high critical hit move here)<br>
; ... (check for high critical hit move here)


The relative jump to '.focusEnergyUsed' that happens when Focus Energy is used makes the game skip a 'sla b' (double b), and then a 'srl b' (half b) at '.focusEnergyUsed' halves the value in register 'b'.
The relative jump to '.focusEnergyUsed' that happens when Focus Energy is used makes the game skip a 'sla b' (double b), and then a 'srl b' (half b) at '.focusEnergyUsed' halves the value in register 'b'.

Revision as of 01:15, 5 September 2019

Miscellaneous glitches of Pokémon Red and Blue and Pokémon Yellow

Amazing Man (Red and Blue only) | Cable Club escape glitch | Celadon looping map trick | Champion Blue music muting glitch | Coastal Flooding | Confusion and Substitute glitch | Cooltrainer move | Cycling based glitch maps | Escape sprite handling glitch | Evolve without an evolutionary stone (Red and Blue only) | Evolving Raichu (Red and Blue only) | Expanded item pack | Expanded Pokédex | Focus Energy glitch | Get stuck in a wall | Ghost Bicycle glitch | Glitch encounter system | Glitch City RAM Manipulation | Infinite Blaine Door | Introduction Nidorino glitch (Red and Blue only) | Invisible PCs (Red and Blue only) | Invisible tree glitch | Item stack duplication glitch | Mute the music in the Pokémon League | Partial trapping move link battle glitch | Pokémon Tower Pokédex glitch | PP underflow glitches | Recovery move glitch | Rival's effect | See a Ghost without a Silph Scope | Selfdestruct and Substitute glitch | Silph Co. PC Glitch | Slot machine glitch | Stand on a tree | Statue behavior glitch (Red and Blue only) | Super effective move AI flaw (Red and Blue only) | Super Glitch | Surf down glitch | Swift miss glitch | Transform assumption glitch | Transform Empty Move Glitch | Trick Zone | Vending machine purchase glitch | Walk around with only fainted Pokémon (Red and Blue only) | Walking lag glitch | Walk on water through Surf | Walking Pikachu happiness glitch (Yellow only) | Wild appeared! | ZZAZZ Glitch

(view, talk, edit)
PRAMA Initiative a également une page sur Focus Energy glitch.

The Focus Energy glitch is a glitch in Pokémon Red, Blue and Yellow.

Focus Energy is a move that, ever since Generation II, increased the user's critical hit rate.

In Generation I, due to a bug, Focus Energy will always effectively quarter the player's chances of getting a critical hit.

This glitch was fixed in Pokémon Stadium, where a different critical hit rate formula is used instead, and Focus Energy indeed increases the critical hit rate.

Analysis

The relevant block of code for Focus Energy's effect is this, beginning at offset 3E055 in Pokémon Red and Blue (view 0F:6055 in a debugger). Thanks Wack0 for walking through this.

    bit 2, a                  ; test for focus energy
    jr nz, .focusEnergyUsed
    sla b                     ; b=b*2
    jr nc, .noFocusEnergyUsed ; if b was below 128, skip...
    ld b, $ff                 ; a cap at 255/256
    jr .noFocusEnergyUsed
.focusEnergyUsed
    srl b                     ; whoops! b=b/2, and if you look, the jump to here is before the b=b*2, so b is effectively 1/4 of what it should be
.noFocusEnergyUsed            ; no cap at 255/256 for focus energy. I wonder if, if done properly, this would have caused bugs related to integer wraparound...
                              ; ... (check for high critical hit move here)

The relative jump to '.focusEnergyUsed' that happens when Focus Energy is used makes the game skip a 'sla b' (double b), and then a 'srl b' (half b) at '.focusEnergyUsed' halves the value in register 'b'.

If Focus Energy is not used, the value in 'b' is doubled and if it was used, the value in 'b' is halved. 2.0/0.5=4.0, meaning critical hits land four times less likely.