Glitch City Laboratories Archives

Glitch City Laboratories closed on 1 September 2020 (announcement). This is an archived copy of an article from Glitch City Laboratories wiki.

A live version of this article is available at the Glitch City Wiki here.

You can join Glitch City Research Institute to ask questions or discuss current developments.

You may also download the archive of the wiki in .tar.gz or .xml.gz formats.

Luck manipulation (Generation III)

This article is incomplete. Please feel free to add any missing information about the subject. It is missing: Index number.






Introduction

The RNG for all of the handheld games in Generation III is based upon a single 32-bit value, either changing it or running it through a formula every frame. This will be referred to as the seed.

Every frame, the seed is iterated through a linear congruential generator. The multiplier is $41C64E6D, and the increment is $6073. Outside of battle, this iteration happens once; however, when in battle, it happens roughly twice per frame. Curiously, it does not iterate at all in Battle Frontier battles, except during calculations for damage and opponent move selection.

With this knowledge, one can obtain any desired Pokémon simply by timing inputs, provided they know their initial seed. While the RNG controls countless events ranging from NPC movement to critical hits, this is its only common use, as desirable RNG outcomes in battle need to be routed frame-by-frame.

Manipulating the RNG provides access to any possible PID without the need of a game-altering device. The PID of any given Pokémon both contains its nature and determines whether or not it is shiny if obtained on a save file with a specific ID and secret ID.

To determine whether a Pokémon is shiny, the xor of the upper and lower 16 bits of the PID are compared to the xor of the player's ID and secret ID. If the difference is less than 7 (including 0), this leads to 8 out of every 65536 random combinations being shiny, or 1 out of every 8192.

While both the PID and IVs are calculated using the RNG seed in a wild encounter, the two aren't intrinsically connected further than that. (For instance, after an IV spread of all 31s (FFFFFFFF) is generated, the seed will be FFFFFFFF two frames later.) A bred Pokémon can legally have any combination of IVs and PID, even ones not within the 4294967296 usual possibilities.

Methods

In short, how much the calculation is altered by other factors.{clarify}

... in Generation III ...
  • Method 1 (Stationary encounters and gifts)
  • Method H-2
  • Method H-4 https://www.reddit.com/r/pokemonrng/comments/6zwzvp/emerald_h2_h4_question/
  • Method 4
  • Method 2

    Notes for each game



    Ruby and Sapphire

    When the internal battery is dead, the initial seed in these games is always $5A0. This makes the process for manipulating it identical to Emerald in this case.

    When playing one of these through the emulator in Pokémon Box, Rayquaza's stats are generated by Method 4 as opposed to Method 1. This presumably applies to other stationary encounters as well.

    When the internal battery is alive, the seed is determined by the UID of the time stored in the internal clock.{clarify} It takes roughly two days after the battery has been disconnected or run dry for the real time clock to stop working, but the value it's stuck at has no bearing on initial seeding.https://github.com/pret/pokeruby/blob/d63e99c418de98005eac31ba3e6c1abdd6e3ecaf/src/main.c#L189

    FireRed and LeafGreen

    The game is seeded by the AGB's Timer0, defined in hardware and thus theoretically unpredictable without 16.7 MHz precision. However, timing A presses very specifically can make the results correlate surprisingly well.

    Emerald

    Emerald's initial seed is always 0. This makes calculating the time to any given wild or bred IV spread straightforward, as the player can simply let the LCG run idly for however many frames are required. While the possibility of only one initial seed would restrict many possibilities due to wait time on intended hardward, the Battle Video exploit can be used to set it to any given value once it rolls around the first time, eliminating wait times up to 828 days long.

    Memory locations



    {|
    GameRegionSeed address
    Ruby/SapphireUSA0x03004818
    Ruby/SapphirePAL0x03004828
    Ruby/SapphireJPN0x03004748
    FireRed/LeafGreenUSA0x03005000
    FireRed/LeafGreenPAL0x03004F50
    FireRed/LeafGreenJPN0x03005040
    EmeraldUSA0x03005D80
    EmeraldPAL0x03005D80
    EmeraldJPN0x03005AE0


    Attribution

  • Kaphotics, Bond697, and OmegaDonut from Project Pokémon [clarification needed]
  • The New Order of Breeding
  • Smogon University
  • Hozu from Smogon for the anecdote about Box

    This article or section is a stub. You can help wiki by [ expanding it].

    Categories