Luck manipulation (Generation III): Difference between revisions

From Glitch City Wiki
Jump to navigation Jump to search
Content added Content deleted
>Sherkel
No edit summary
m (Text replacement - "{| {| align=top style="background: grey; -moz-border-radius: 0.5em; border: 5px solid #000000; color: grey"" to "{|")
 
(2 intermediate revisions by 2 users not shown)
Line 9: Line 9:
Emerald
Emerald
- same sections, explain IDs
- same sections, explain IDs
FireRed & LeafGreen (just say no)
FireRed & LeafGreen
- look at Google Doc
- see Emerald, but...
Ruby & Sapphire (live battery) (just say no)
Ruby & Sapphire (live battery)
- see dead battery, but...
- see dead battery, but...
LCG values, memory locations
Memory locations
Colo/XD? -->
Emulator tips? (probably off-topic) -->


== 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 [[wikipedia:linear congruential generator|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.
The current seed is calculated by multiplying the previous one by $41C64E6D, adding $6073, and then taking the result modulo $100000000. This happens once per frame outside of battle, and twice per frame when in battle. {{clarify}}


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.
Emerald's initial seed is always 0. When the internal battery has run dry in Ruby and Sapphire, the initial seed is always $5A0. Thus, in these games, a Pokémon with a desired IV spread or PID (which determines shininess) can be obtained by setting a timer when the game is reset and encountering the Pokémon within a 1 frame window. However, complications may arise with Method H encounters. {{clarify}} <!-- I forget the details of the inconsistent H methods... -->


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.
When playing Ruby or Sapphire 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.


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.
In Emerald, the [[Battle Video exploit]] can be used to set the RNG seed to any given value once it rolls around the first time, eliminating wait times up to 828 days long. <!-- 2^32 / (60 * 3600 * 24) -->

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 <ref>[https://www.reddit.com/r/pokemonrng/comments/6zwzvp/emerald_h2_h4_question/]</ref>
* 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.<ref>https://github.com/pret/pokeruby/blob/d63e99c418de98005eac31ba3e6c1abdd6e3ecaf/src/main.c#L189</ref>

=== 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. <!-- 2^32 / (60 * 3600 * 24) -->

== Memory locations ==


{|
{|
{| align=top style="background: grey; -moz-border-radius: 0.5em; border: 5px solid #000000; color: grey"
|-
|-
|
|
{| class="wikitable sortable"
{| border=1 width="100%" align=left class="sortable" style="background:#f0f0f0; border:1px solid #000000; border-collapse:collapse;"
|-style="background: silver;"
! Game !! Region !! Seed address
! Game !! Region !! Seed address
|-
|-

Latest revision as of 21:15, 31 December 2020

This article is incomplete. Please feel free to add any missing information about the subject. It is missing: a ton of stuff.


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 [1]
  • 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.[2]

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

Game Region Seed address
Ruby/Sapphire USA 0x03004818
Ruby/Sapphire PAL 0x03004828
Ruby/Sapphire JPN 0x03004748
FireRed/LeafGreen USA 0x03005000
FireRed/LeafGreen PAL 0x03004F50
FireRed/LeafGreen JPN 0x03005040
Emerald USA 0x03005D80
Emerald PAL 0x03005D80
Emerald JPN 0x03005AE0


Attribution

  1. Kaphotics, Bond697, and OmegaDonut from Project Pokémon [clarification needed]
  2. The New Order of Breeding
  3. Smogon University
  4. Hozu from Smogon for the anecdote about Box
This article or section is a stub. You can help Glitch City Wiki by expanding it.