Crystal_
Pokemon G/S - Make any Pokemon shiny: Coin Case arbitrary code execution
updated
Part 2 (21-40): youtube.com/watch?v=iSKzAZdxONw
These are for Pokemon Red or Pokemon Silver, as indicated. To use them, you'd need the BGB emulator, the corresponding Pokemon game ROM, and the ROM of the game they are for.
If you think the technical stuff will bore you, feel free to skip to around 15:50.
Save file for Pokemon Silver (just go downstairs) - http://www.mediafire.com/file/bjaor2o27g48ke7
Links referenced in the video below.
Programming Snake into Pokémon Crystal: sites.google.com/site/crystalglitchystuff/articles/snake
Pokemon Gold/Silver - Generic Coin Case ACE setup for almost any purpose: youtube.com/watch?v=PsIb3OZaYAs
Thanks to gifvex, who made me notice that the PP-incrementing function fails to account for being transformed. Indeed, this function used by Mirror Move and Metronome is the cause of this bug.
Consider this video a part 2 to youtube.com/watch?v=MtSm7sBnCw0
In the pokecrystal disassembly, the error is located at github.com/pret/pokecrystal/blob/d0d61cb/battle/effect_commands.asm#L3194
The highlighted instruction should've been 'cp c' instead of 'cp [hl]'.
Credit to luckytyphlosion for originally finding this glitch and making me aware of it.
Don't be scared about the length of the video. It's only so long because it contains plenty of details, examples, and some useful troubleshooting. It also begins with an introduction that you can skip by going right to 2:15. The length of this video is actually about the same amount of time that it would take to you to set everything up, if not more.
Any information not covered in the video that is found important or relevant will go here:
- At 9:58, the bolded text should have been "make Quagsire hold one of the TM09, replacing its current TM02".
- The pinned comment contains various useful box name codes compatible with this setup (thanks to user Timothy Gerritsen), so does this document (thanks to user Matt, also in the comments): pastebin.com/y3SJ4ZqV
------------------------------
Use the following spreadsheet for additional help -
docs.google.com/spreadsheets/d/1Wu2v3gnqzdj1QF2thz6xGKJaObVwPkpg0VR6HCJJYp0
It contains the following information:
- "IDs" sheet: Internal numbers (IDs) of Pokemon, moves, and items.
- "Addresses" sheet: Location and meaning of relevant memory addresses, including additional information on how to use them for the most requested purposes. I will be adding more useful memory addresses in the future.
- "Hex2Text" sheet: Table to convert each pair of digits to its respective pair of text symbols.
You will know how and why to use this spreadsheet after watching the video.
Online hex to box name conversion tool, thanks to youtube.com/user/NineNineNineFour: http://people.emich.edu/elewis23/gs%20ace/index.html
------------------------------
If you need additional help, feel free to leave a comment explaining what your problem is or what to want to achieve, as well as what you have tried already (and failed), if anything. I'd appreciate if you made a little effort first though!
------------------------------
For arbitrary code execution in the spanish, italian, french, and german versions of Pokemon Gold and Silver - youtube.com/watch?v=b2tVVeZ7Th4
------------------------------
Assembly code for those interested - pastebin.com/TQdYyM4P
Any relevant information not covered in the video that is found important or relevant will go here.
------------------------------
Various resources and examples for Step 8.
For step 8.1) - Use the following resources to find out the location of relevant memory addresses:
datacrystal.romhacking.net/wiki/Pok%C3%A9mon_Gold_and_Silver:RAM_map
- github.com/PikalaxALT/pokegold/blob/master/wram.asm
The first one is more user-friendly but the second one (from the disassembly) has far more information. If you have trouble locating an address in one, resort to the other one.
For step 8.2) - If you want a specific Pokemon, item, or move, you will need to know its hexadecimal number. Use the information from the first, sixth, seventh, and eight columns of the table found here: http://glitchcity.info/biglist.htm. For example, Celebi is FB, Aeroblast is B1, and Rare Candy is 20.
For step 8.3) - Conversion tables from hexadecimal to box name codes (language-dependant):
- Italian and spanish: pastebin.com/bAra9Wy7
- German: pastebin.com/yW9MeaKe
- French: pastebin.com/8VvWLHqA
If you need further assistance with step 8 - Usage examples:
- Party count (github.com/PikalaxALT/pokegold/blob/master/wram.asm#L3638): Address DA22
- Party Pokemon #3 species (datacrystal.romhacking.net/wiki/Pok%C3%A9mon_Gold_and_Silver:RAM_map#Pokemon_3_Settings): Address DA8A
- To make party Pokemon #3 shiny: Write FA to DA9F and AA to DAA0
- Item 6 quantity (datacrystal.romhacking.net/wiki/Pok%C3%A9mon_Gold_and_Silver:RAM_map#Game_Settings): Address D5C3
- Money (github.com/PikalaxALT/pokegold/blob/master/wram.asm#L2919): Addresses D573 to D575 (only set D573 to 0E for near maximum money)
------------------------------
Techncal explanation -
When a Pokemon is withdrawn to the 30th slot of the party, it corrupts addresses between DF9A and DFB9. More specifically, when the Pokemon's data is being copied from SRAM to those WRAM addresses, the stack pointer is at DFB3, and the 3rd and 4th PP slots of the Pokemon are copied to DFB3 and DFB4, respectively. Returning from the memory copy routine will bring the game to whatever stack pointer was spelled out by those two PP fields.
Of course, after doing this, the stack is absolutely destroyed and there are no realistic hope of restoring it to anything playable. The suggested alternative is to edit the SRAM to give ourselves one of the TMs into the items pocket of the bag, some of which execute code from WRAM. Modifying data in SRAM this way also requires to update the checksum at AD69-AD6A by the difference.
The suggested item to obtain this way is TM17, which, when used from outside the TM/HM pocket, makes the game jump to DA47, the middle of the first party Pokemon data. By having two party Pokemon with some specific qualities, we can conveniently redirect the execution to the buffer where box names are stored.
------------------------------
Special thanks to ISSOtm for his help with the development and testing of the method, to luckytyphlosion and gifvex for help with the TM17 setups, and to the GCL Discord for help and support.
------------------------------
Please, do not ask for help with Coin Case arbitrary code execution in english Gold and Silver. I will be working on adapting the "memory editor" setup for Coin Case ACE in those version, and there should be a video about it within the next 2 or 3 weeks. Most of the complexity involved in the method of ACE shown in this video won't be a problem in the Coin Case approach for the english versions. Meanwhile, there are already many videos about Coin Case ACE (not necessarily made by me) that you can check out.
Update: Here is the Coin Case video - youtube.com/watch?v=PsIb3OZaYAs
Code: pastebin.com/P19vZ3EP
The save file was made for the sole purpose of being reliable enough to make this video. In order to save a few bytes to fit all the displayed text within the party Pokemon data, it assumes that the second game enters the trade with a party of six Pokemon. Also, there's a ~2% chance that the checksum will overflow and there won't be any effect.
More information on ACE via bad clones: forums.glitchcity.info/index.php?topic=7706.msg203310#msg203310
Pong source code: http://pastebin.com/LTmnYhTx
Save file for Pokemon Red (ready to start link battle, do not move or open the Pokemon menu): http://www.mediafire.com/file/vaxujj3t3ple6du/Pokemon+Red.sav
Starting item list (with usual 8F party setup):
Bicycle (recommended)
8F
X Accuracy, x97
Burn Heal, x126
Parlyz Heal, x15
HP UP, x15
Ice Heal, x15
Potion, x134
TM34, x20
TM15, x46
Leaf Stone, x52
Great Ball, x201
TM16, x46
TM17, x46
TM18, x46
TM34, x181
TM10, x73
Copy data + cartswap code:
ld bc, 0176
ld hl, D8B5
ld de, D17C
call 00B5
di
ld b, 20
ld c, b
ld d, b
dec c
jr nz, $fd
dec b
jr nz, $fa
dec d
jr nz, $f7
ei
ret
Code and raw bytes - http://pastebin.com/raw/jcRmZM28
Instead, Mew must have an IDNo. of 22796 and a OT (original trainer) of GF (short for Game Freak), in order to be considered legitimate. Luckily, we can still use arbitrary code execution exploits in Pokemon Red/Blue to give Mew the required information. Arbitrary code execution in these games can be achieved with the glitch item 8F. In addition, we can also abuse 8F to give any Pokemon a certain combination of DVs that would make it shiny once transferred.
Item lists (includes assembly code):
Encounter Mew with 8F: http://pastebin.com/MJd9rA8y
Mew method #1: http://pastebin.com/BA4mK4PK
Mew method #2: http://pastebin.com/z836UeVA
One shiny Pokemon: http://pastebin.com/QaNpSYCc
All shiny Pokemon: http://pastebin.com/z6ZVN76z
Arbitrary code execution in Red/Blue using the "8F" item: http://forums.glitchcity.info/index.php?topic=6638.0
Credit to TheZZAZZGlitch for the method to obtain 8F and for the original code to get any item with 8F, credit to Pidgevil2010 for the bootstrap party setup, and credit to SciresM for the Pokemon Bank discoveries (Mew requirements and shiny DVs). Hopefully I got all of them right.
Introduction - 00:00
Getting 8F - 00:32 (*1)
Getting over 99 units of the same item stack - 04:18
Bootstrapping - 07:30
Obtaining any item - 08:52
Pokebank-compatible Mew method #1: Changing player's IDNo and name - 09:47
Capturing Mew - 12:38
Pokebank-compatible Mew method #2: Changing Mew's IDNo and OT - 15:19
Turning one Pokemon into Pokebank-shiny - 17:37
Turning all box Pokemon into Pokebank-shiny - 19:01
(*1): I forgot to mention in this section of the video that you must be in the exact spot where I am (edge between Celadon City and Route 8, just above the fourth tree from the right). This is completely necessary.
(*2): At 16:25 (just before the third 8F use), I forgot to add that TM18/TM50 must be replaced with TM21. It's reflected in the screen, but not mentioned in the side text, so be careful with that. If you use TM18 or TM50 wrongly instead, simply nothing will happen.
I don't own a 3DS, so I can't test the results achieved by the different methods explained in the video on console or in the Pokemon Bank. However, it's been confirmed by different people that they work as expected:
reddit.com/r/pokemon/comments/5q6zyq/step_by_step_guide_on_how_to_obtain_a
reddit.com/r/pokemon/comments/5q4meg/how_to_trick_pokebank_into_thinking_your_gen_1
CAREFUL: When using the Mew method #1, make sure not to save the game between the fourth and fifth 8F use if your name is just one character long. You can still save after the third and last use. However, saving and turning off the game after the fourth use would corrupt your save file due to having an unterminated name. Again, this is only relevant for method #1 if your name is 1 character long.
IMPORTANT: It's been confirmed that the Pokemon bank will NOT accept Mews below level 5, regardless of ID/OT. If you take the path of capturing Mew through 8F, either do it in a route with over level 5 Pokemon, or make sure to level it up to at least level 5.
KEEP IN MIND: When you perform dangerous glitches like 8F and everything that takes obtaining it, there's always a risk. A crash would very rarely destroy your save file but it's a possibility. It's actually much more likely to happen in RBY than in GSC because the former games do not backup save data and spend a lot of time with SRAM opened. Still, a save file corruption will only occur after a crash if another SRAM bank is loaded, which may occur if the game randomly executes code that does it. I can't assure you that your save is 100% safe, only that if you don't make any mistake anywhere save will not be corrupted. But granted, everybody can make mistakes.
PAY SPECIAL ATTENTION: Some people got their save file corrupted due to making a mistake somewhere. The VC Pokemon Red/Blue is more prone to erase your save file upon crashing due to the way it handles invalid opcodes and stops. Consequently, it's actually quite probable that a crash will result in your save becoming corrupted. Most of the reports of corrupted saves where a consequence of an error in the party setup rather than in the item lists, so make sure to pay special attention that your party is exactly like the one shown in the video everytime you use 8F, with the right Pokemon in the right order and with 233 current HP in your Pidgey.
FAQ: pastebin.com/BRNC6r8m
The soruce code can be found here:
github.com/pret/pokecrystal/blob/master/engine/slot_machine.asm
Pseudo-code (includes inconsequential stuff regarding delays and reel speeds, and it's also a bit dirty; you should probably just watch the video) - sites.google.com/site/crystalglitchystuff/research/gsc-slot-machine
In other news, if you remember my previous video where I programmed the Snake game into Pokemon Crystal, I put up a detailed article explaining how it was done around two weeks ago now. It's available here - sites.google.com/site/crystalglitchystuff/articles/snake
The first part of the video is the demonstration, followed by a brief explanation of the whole process (begins at 5:04). As stated in the video, I was going to work on a more detailed document that was going to be available here once finished, and... it's already available here! - sites.google.com/site/crystalglitchystuff/articles/snake
Since that article covers the explanation in much greater detail than the second part of the video, you are encouraged to give it a read if you're interested! If you're looking for a lighter explanation without getting into the nitty-gritty of the process and the assembly routines though, you're also welcome to watch the second part of this video instead!
Some of you may identify some of the effects presented in the video as the 0 Error glitch or the Walking Lag glitch.
PC items are used to spell out the payload code in the demonstration. This isn't ideal, however, since using the names of the PC boxes is far more efficient if we're capable of spelling out our code with them.
If you want to see something far more interesting being done by abusing this glitch (and others), you should watch this - youtube.com/watch?v=g2mCyh7Y2xM
Video by Werster of a TAS using this ACE exploit - youtube.com/watch?v=Gj7m4vh18c8
Relevant GCL thread - forums.glitchcity.info/index.php?topic=7706.0
- Safari Zone entrance glitch
- Oak's Laboratory corruption glitch
- Minimize / Substitute picture glitch
More Pokemon glitches explained in depth! - youtube.com/playlist?list=PLLvtRtlPBbbjjWxBAli42LZMQqla0_9wI
Compilation of Red/Blue glitches - sites.google.com/site/crystalglitchystuff/research/compilation-of-red-blue-eu-errors
Source of TPP video - youtube.com/watch?v=8Fj-ZztP_0s
The Pokemon Crystal Randofuser is already available for download. You can read more about the features of this randomizer and download it by following either of these links:
github.com/xCrystal/crystal-randofuser#pokemon-crystal-randofuser
pokecommunity.com/showthread.php?p=9492070
0:00 - Introduction
0:53 - Move misses and fails
2:36 - Mirror Coat, Bind, Sleep (status condition)
4:34 - Spikes, Bide, Dig, Sleep Talk
6:20 - Confusion (statud condition), Poison (status condition)
7:42 - Fire Spin, Rollout, Sand Swirl, Leech Seed
10:06 - Rage Powder, Encore
11:22 - Burn (status condition), Mean Look, Roar, Rage
13:29 - Double battles
17:40 - Some out-of-battle features
There are a bunch of other move effects or status conditions already implemented that have not been shown in the video (you know, I can't fit everything).
Older video with more content about double battles: youtube.com/watch?v=IsTgdBcAmyY
Even older video, pretty outdated but got more attention than the second: youtube.com/watch?v=M6VZepedbko
My Twitter: twitter.com/crystal_rby
Something that I forgot to mention in the video in relation to double battles is that their logic has experienced a relevant update. Now the replacement of fainted Pokemon does not occur mid-turn, instead waiting until all the active Pokemon have attacked during the current turn. In more familiar terms, if I'm not mistaken, double battles used to work like they do in Gen 3, and now they work like they do in Gen 4 and newer games. I took this decision not because I wanted to match the functionality of the newest generations, but because after some thinking I came to the conclusion that this new logic is better design-wise, at least to me. In addition, Pokemon switches executed by the player now wait until the regular turn, instead of occurring immediatelty after submitted during the move/action selection period.
Edit: A logic bug regarding the accuracy of Fire Spin and moves with a similar effect has been fixed. As field targeting moves (i.e. like Spikes), they do not check accuracy. Their power has been adjusted following this (also Pokemon that are flying or underground won't be damaged that turn).
For some unknown reason, during the execution of the "Defense down by 1 stage" secondary move effect, the command responsible for testing the secondary effect odds (command effect_chance) is executed twice, one of them occurring after the execution of the command responsible for applying the damage on the target (command hit_target). The result of the second effect_chance command overwrites the result of the first, and as the damage has already been applied at this point, it's possible that a Substitute has been taken down in the process. If so, the game won't be aware that a Substitute had been up before the use of this attack, and proceed to give the move a chance to trigger its secondary effect.
This error does not apply to any other effect of damaging moves, because, in the rest, there is only a single effect_chance command that comes prior to the hit_target command. Therefore, the game notices the Substitute still being up and disables the chance to trigger the secondary effect.
The "Defense down by 1 stage" move effect is used by Acid, Iron Tail, and Rock Smash. In the video, I also showed the 100% secondary effect chance move DynamicPunch to prove that this bug doesn't apply to other moves.
Related code below.
Phone engine - github.com/pret/pokecrystal/blob/master/engine/phone.asm
Time and delays - github.com/pret/pokecrystal/blob/master/engine/time.asm
Mom purchases - github.com/pret/pokecrystal/blob/master/event/mom_phone.asm
Phone scripts - github.com/pret/pokecrystal/blob/master/engine/phone_scripts.asm
Counter glitches and link battle desynchronization - youtube.com/watch?v=ftTalHMjPRY
More GSC battling glitches:
Counter / Mirror Coat - youtube.com/watch?v=uRYyzKRatFk
Reflect / Light Screen - youtube.com/watch?v=yveIVI5oGO8
Disable - youtube.com/watch?v=1v9x4SgMggs
HP bar - youtube.com/watch?v=SE-BfsFgZVM
Magikarp length histogram (mm): http://pastebin.com/8QXxrj2s
Magikarp length histogram (ft): http://pastebin.com/pt7rENpk
Magikarp length raw samples (mm): http://pastebin.com/PyJsYeca
Magikarp length raw samples (ft): http://pastebin.com/F9gAxpsH
Related code in the pokecrystal disassembly:
github.com/pret/pokecrystal/blob/master/battle/magikarp_length.asm
github.com/pret/pokecrystal/blob/master/battle/core.asm#L6405-L6465
Did you like this video? You can find similar videos on game mechanics and curiosities in this playlist: youtube.com/watch?v=YbDCXJ0xH2g&list=PLLvtRtlPBbbjmvD13s_zUAhsOAE-DECg6
Pokemon Speedruns - Pokémon Red/Blue Wild DVs: http://wiki.pokemonspeedruns.com/index.php?title=Pok%C3%A9mon_Red/Blue_Wild_DVs
The complete list of DV combinations for all existing encounter rates can be found here: http://www.smogon.com/forums/threads/15-15-15-15-dvs-are-impossible-in-most-cases.3573219/page-2#post-6915001
When a Pokemon has no PP left on its moves, or when the Pokemon's only move with PP left is disabled, the Pokemon is then expected to use Struggle automatically. However, in the event where the attacking Pokemon is affected by the Disable status condition, the game will always fail to recognize moves boosted by one or more PP Ups as having no PP left.
Both the remaining PP and number of PP Ups that have been used on a move are stored in the same byte, with the lower six bits representing the amount of PP left (0-63), and the higher two bits indicating how many PP Ups have been used on the move (0-3). If no move is disabled, the game will correctly mask out the higher two bits in order to compute whether any move has PP left.
However, if one of the moves is disabled, the two higher bits aren't ignored and thus any move boosted by PP Ups will always be interpreted to have PP left. If all three non-disabled moves have 0 PP, yet one or more of them has been boosted by PP Ups, the game erroneously believes that the Pokemon has available moves and won't trigger the use of Struggle. If we are in a trainer battle with no other usable Pokemon and no PP-restoring items such as Ether (or in a link battle where no items can be used), we'll have no other option than to turn off the game.
This glitch is also present in Pokemon Red, Blue, and Yellow
You can check out and download Pokemon Pyrite here: http://www.pokecommunity.com/showthread.php?t=350926
Related code (R/B/Y):
github.com/pret/pokered/blob/2b2c6fe/engine/mon_party_sprites.asm#L84-89
github.com/pret/pokered/blob/7e12ca56/engine/battle/common_text.asm#L97-138
github.com/pret/pokered/blob/7e12ca56/engine/battle/common_text.asm#L171-220
Related code (G/S/C):
github.com/pret/pokecrystal/blob/7aef5984/engine/mon_icons.asm#L188-218
github.com/pret/pokecrystal/blob/7aef59841/battle/core.asm#L8036-8084
github.com/pret/pokecrystal/blob/7aef59841/battle/core.asm#L8122-8172
For reference of the HP bar color:
The HP bar is 48 pixels long in both generations. The amount of pixels left in the HP bar approximately represents the current (HP / max HP) ratio of the Pokemon. In Gen 1, the HP bar turns yellow when it has 26 or less pixels, while in Gen 2, it will turn yellow at 23 pixels or less. In both generations the HP bar turns red at 9 or less pixels.
This setup allows writting any given value into any given memory address by specifying it in the charactes that make Box 9's name. The name's first four characters will determine the address to hack (2 bytes), while the last two will determine the value to be written on it (1 byte).
PC item list for the coin case as a memory editor setup: http://pastebin.com/in4MS7zW
Hexadecimal numbers represented by each character pair in the box name: http://pastebin.com/4ZDpQXGe
For more information follow the link of the video listed above.
For the party Pokemon, a Quagsire knowing Sleep Talk as its first move, and holding a Protein, is required in the fourth position. Additionally, a low level untrained Pokemon is required in the third position (e.g. a Pidgey or Ratatta from route 29). The coin case glitch is not guaranteed to work with every single Pokemon, but these conditions (low level and untrained) will give the best results. It's possible that the game will crash/reset regardless, and if that's the case it's a matter of trying with another Pokemon.
The coin case glitch only works in the english versions of Pokemon Gold and Sliver. It won't work in Pokemon Crystal or in any other localization of G/S. The coin case glitch will also not work in the VBA emulator due to an emulation bug.
For detailed information about the Coin Case glitch and how to perform it: http://forums.glitchcity.info/index.php/topic,6716.0.html
If you're still unsure about something feel free to ask it in the comments!
****************************************************************************************************************************************
Thanks everyone for your support in regards to the 101 Pokemon Red & Blue bugs series! Following al your opinions, these are the decisions I've made: twitter.com/crystal_rby/status/737214499581796352
Slot machines in GSC! - youtube.com/watch?v=ojq3xqfRF6I
Source code:
github.com/pret/pokered/blob/6057f285a/scripts/celadongamecorner.asm
github.com/pret/pokered/blob/3fd678769/engine/game_corner_slots.asm
github.com/pret/pokered/blob/3fd678769/engine/slot_machine.asm
github.com/pret/pokered/blob/6057f285a/constants/misc_constants.asm#L97
github.com/pret/pokered/blob/6057f285a/data/slot_machine_wheels.asm
Did you like this video? You can find similar videos on game mechanics and curiosities in this playlist: youtube.com/watch?v=YbDCXJ0xH2g&list=PLLvtRtlPBbbjmvD13s_zUAhsOAE-DECg6
Battle transitions in R/B/Y! - youtube.com/watch?v=YbDCXJ0xH2g
I thought I'd let you guys know that I haven't abandoned the hack, and I've been making slow progress since then. I've been focusing on the battle engine, refining some things sine I uploaded that video, and for the most part I've implemented a bunch of move effects that I thought could be some of the hardest to implement, so I thought working on those first will be a much better idea in terms of escalability. Keep in mind that I'm rewriting nearly everything, so the moves that one expects to be already functional in the original game and being worked on as much as the others, and will not necessarily work exactly as they originally did, given that this is also allowing me to redesign some things here and there about how they work the way I like it.
Considering that the majority of move effects aren't implemented yet (even though a lot of them are straightforward and/or reused by a lot of moves), as well as the majority of status handlers, all the held item effects, and plenty of things that will need refining, I'd say I'm around halfway through calling the battling logic done. The move choices and move data has already been mostly designed, (except for some minor stuff that is subject to change) so it's just about porting it to the game when it's time. After that, my idea is to move on to the battle animation engine, AI engine, and other miscelaneous stuff more connected to battling than the overworld that is way too much to list here. Then I'd ideally move on into everything overworld engine to try to set everything up as good as I can in order to start redesigning the storyline and all that kind of gameplay in the better possible way. Obviously much faster said than done!
I've been also working on a bunch of other feautures not directly related to battling, that include experience gain mechanics, moveset and evolution engine, trainer and wild Pokemon engine, and some new PC features. All in all, I don't wan't to reveal too many details because I'd rather the majority of the things come more as a surprise when the hack is hopefully released (in a long, very long time). My goal with this was just to show that the hack's not been abandoned, but at the same time, I want to only reveal as little information as possible so that if this is ever finished and released, it is as unpredictable as possible which I do really believe will make it far more exciting! This has been one of my goals since the beginning and that's the reason I'm working on it privately for the most part.
Anyway, since what probably stands out more from this hack as of now is the double battle functionality, I thought I'd just stick to that in the video and use it to show the overall functionality of the majority of the move effects that I have implemented. These effects I'm showing are functional in regular battles just like I'm showing them in a double battle, but I just thought the latter will be more exciting! Note that double battles are intended to be only a small part of the game, and the vast majority of battles are intended to be regular ones. Anyway, I'm not sure how many questions if any may pop up regarding the inner workings of certaing moves (or anything else), but keep in mind that there are details that I may not be too comfortable revealing for the reasons that I stated before. That's not no say that I don't want anyone to ask questions or to give me feedback (not at all!), but I'd just wanted to let you all know about it.
Before you watch the video I'd also like to ask to you please ignore broken or unfitting animations, absurd movesets, non-existant AI, and odd damage rolls or stat distributions. As I've said, these are things that I haven't gotten into yet and I've only taken care of the essential regarding these things in order to make the battles playable.
By the way, also remember that this is based off the Pokemon Red Color hack dissasembly, so sometimes it may look more like a generation 2 hack!
That's all, but while we're at it I'm also going to leave the link to the Pokemon Pyrite thread in Pokecommunity for no particular reason! :) (in case you don't know this is a Pokemon Crystal hack that I've made)
http://www.pokecommunity.com/showthread.php?t=350926
This video is part of an april fools joke that was posted in Smogon. Check out the reactions of several RBY players in Smogon (http://www.smogon.com/forums/threads/past-gens-research-thread.3506992/page-5#post-6738691) (http://www.smogon.com/forums/threads/bide-and-double-hit-attacks.3568816) and Pokemon Perfect (http://www.pokemonperfect.com/forums/index.php?threads/new-discovery-rby-bide-glitch-april-fools.3796)
****************************************************************
The number of hits of a multi-hit move and the least significant byte of the Bide stored damage share the memory address. This shouldn't be a problem since there's no way you interrupt Bide in order to use a multi-hit move, meaning that there should be no collisions, but...
The default value (when a battle starts) of this address is 2. This is to reflect that double strike moves (namely Double Kick, Bonemerang, and Twineedle) always hit twice. Moves like Pin Missile on the other hand, hit 2 to 5 times, so RNG is needed to decide how many times they will hit. Whenever a move like Pin Missilie is used, a random number is generated, and this address is updated with the number of times the move will hit.
Moves like Double Kick, however, doesn't update this address at all. Instead they assume it will always contains 2. They use a different move effect handler, and the way it's structured a workaround would be needed to make the game load 2 into that address without breaking the two-hit loop (in the sense that that on every hit the address has to be decremented, and the way it is programmed, if 2 was loaded into it after every hit, we'd be stuck in an infinite loop).
Anyway, when the battle starts, whenever a move like Pin Missile or Double Kick ends (even if not all hits were necessary to KO the target), and when Bide successfully unleashes energy, 2 is loaded into this address. But if the Bide sequence is interrupted, the accumulated damage is kept there!
This isn't fully true though, and it's related to the Bide damage desync glitch that I discovered some time ago. In the event that the Bide sequence doesn't end, one side succesfully manages to load 2 into the address but the other side does not. This is because, for the Bide sequence to be interrupted, the Bide user must faint. When it faints, 2 is loaded in the address, but only in the opponent's side, similarly to what occurred with the Bide desync glitch. This glitch is not present in regular battles, because in this case both sides succesfully load 2 to this address when a Pokemon faints. While it sounds like it would be a desync on link battles, in the end the double strike move user will send the other side its own number of hits value, overriding the opponent's value of 2. In the end, the move will hit as many times as the amount of damage accumulated with Bide before it was interrupted. Note that this only applies to the very next double strike move used by the player who saw his Bide sequence interrupted, as the double strike move itself will set the address to 2 when it ends.
Some other notes:
- If the Pokemon not using Bide faints (e.g. due to Poison), the address gets back to 2 in the Bide user side, meaning that even if Bide is interrupted without accumulating more damage, the next double strike move will hit twice (it's set to 2 during a faint, but not during a send out, so switching doesn't count).
- When any multi hit move is used by the player (Bide user), including 2-5 hit moves, 2 is loaded into the address, also disrupting the glitch.
- The double strike move can't hit more than 255 times this way. If Bide accumulated 260 damage, it will hit 260 - 256 = 4 times. Obviously, the attack will stop when/if the target faints.
- Breaking a Substitute doesn't let some of the move effects finish (see Explosion, Hyper Beam...). This also applies here, as in the event that Bide damage is unleashed breaking a substitute, it will count as if the sequence was interrupted instead, as the address isn't set to 2.
The delays applied during the animation of health bars of above 48 maximum HP are buggy. In a nutshell:
Intended delay during the depletion of a full HP bar (in miliseconds, approximately): 48 * 33 + 48 * Max_HP / 10
Actual delay during the depletion of a full HP bar (in miliseconds, approximately): Max_HP * 33
The HP bar is 48 pixels long. On Pokemon with over 48 maximum HP, a single pixel may represent more than 1 HP. It was intended that, during the HP bar animation, a small delay (adjusted a little depending on the value of the maximum HP) would be introduced whenever the number of pixels changed, but due to an oversight, the small delay occurs on every single 1 HP difference. The game tries to compare the old HP bar length value to the current HP bar length value in order to determine whether to apply the delay or not; however, due to a misplaced instruction, it erroneously compares it to the Pokemon maximum's HP instead (which is not even a value in pixels). Since the compared values never match, the game thinks that the number of pixels changes on every single iteration, and proceeds to animate the HP bar (with no effect if the HP bar length didn't actually change) and to apply the small delay.
To fix it:
- Pokemon Crystal (U): Write 7B C1 D1 E1 starting from address D723
- Pokemon Gold/Silver (U): Write 7B C1 D1 E1 starting from address D729
Also check out my Pokemon TCG Randomizer!
github.com/xCrystal/TCGRandomizer#tcgrandomizer
It is a detailed tutorial of a far more versatile Coin Case arbitrary code execution approach that can be used for multiple purposes, and includes examples and troubleshooting.
Help won't be offered in the comments section of this video, other than to redirect to the video linked above. This is because 90% of your ambitions or troubles with the Coin Case glitch are covered or can be avoided by following the steps explained in that other video. This is, in fact, the reason why I've made that video.
----- Old video description below -----
Coin Case glitch: http://forums.glitchcity.info/index.php/topic,6716.0.html
This trick is based on the Bug Catching Contest feature in Gold and Silver. By setting the contest status flag, we can trick the game into believing that the player is currently participating in the contest. The address of the species of the Pokemon "caught" in the contest can be edited during the trick so that the player receives whichever Pokemon he wants.
The species is read from the fifth party Pokemon's current HP stat (the lowest byte). A Pokemon's current HP is probably the easiest RAM address to manipulate even though it's not exactly easy.
Here's the suggested ASM/Hex code and corresponding item list for this trick: http://pastebin.com/fCRime06. Note that the Quagsire must be holding Protein (as well as Sleep Talk as the first move). None of the required items is especially difficult to obtain, though you may need to start a new game if you have lost access to some of the TMs required. Note as well that the trick assumes the player beaten the rockets in Mahogany, as the contest status flag shares its RAM address with the rocket event flag, and the value being written into that address during the trick clears the latter.
The obtained Pokemon will retain the data of the Pokemon you last caught in the bug catching contest, including known moves (not future learned moves), DVs, stats and the like. If you level up your Pokemon or deposit it in the daycare, their stats will get back to normal. Note that if the growth rate doesn't match it's possible that the Pokemon grows a rare number of levels after gaining experience in battle. If you had never participated in the contest before, all the data will be 0's (like myself in the video). You can't send this Pokemon into battle but you can still deposit it in the daycare to get a level 1 Pokemon back.
I you happen to have the "coin case as a memory editor" (youtube.com/watch?v=ffZjCabeNr4) setup working, you can use it for this trick as well. Otherwise the item list specifically suggested for this version is easier to make. Anyway, if you go with the memory editor setup, it requires two iterations for each Pokemon in the following order (note that in this case, the species byte is not read from the fifth Pokemon HP, so it's not needed):
(Address) Byte:
(DCE7) Hexadecimal species identifier of wanted Pokemon
(D572) 04
No matter the method you use, you can perform the trick as many times as you want. While setting up the party and items can be more time consuming than doing the famous Celebi (egg) glitch to obtain any Pokemon, the advantage of doing it via coin case ACE this way is that after you've set everything up the first time you can repeat it as many times as you want in just a few minutes to obtain another Pokemon.
REQUIREMENTS
- A Quagsire holding Protein with Sleep Talk as the first move. Put it the fourth position of your party.
- An untrained, low level Pokemon. Put it the third position of your party. The Pidgeys or Rattatas in Route 29 are some of the best ones. Make sure that the Pokemon's Special stat is not 8 and that it's HP stat is not 16. Make sure the Pokemon is female as well to further increase the chances of succeding. A Pokemon that meets these three requirements will work around two thirds of the times. If it didn't work (the game froze, the level of the first party Pokemon did not change), catch another Pokemon and try again.
- In the fifth position, a Pokemon with an HP stat matching the species id of the Pokemon you want to get. For example, 151 HP if you want a Mew. This is not necessary if you use the "coin case as a memory editor" method.
- List of items in the PC: http://pastebin.com/fCRime06
STEPS:
- Arrange the Pokemon in your party and the items in your PC as explained before.
- Enter Prof. Elm's Lab or Cherrygrove Mart.
- Leave the building and move exactly four steps to the right
- Open the Pokedex and open Machop's page (so that you hear its cry). Bellsprout, Machoke and Omanyte should work too.
- Exit the Pokedex and open the bag.
- Switch the pockets in the bag at least once. Then use the Coin Case.
- [Specific for this trick] Exit the items menu and the start menu and wait for the beep. Selecting the "QUIT" option also works.
As we all know, there are 15 trash cans inside the Vermillion gym. To open the electric door that lets you reach Lt. Surge you have to find two switches inside the trash cans. Every time you pick one trash can wrong, the position of the switches gets randomized.
The first switch will be in either of the 15 trash cans, at random. Then, it was intended that the second switch would be in one of the adjacent trash cans. Adjacent trash cans include the ones above, below, to the left, or to the right, but not diagonally. This means that depending on the position of the first trash can, the second switch could be in 2, 3, or 4 different trash cans, with 4, 8, and 3 cases respectively.
Here's the layout of the trash can map identified by their harcoded hexadecimal id's:
0 | 3 | 6 | 9 | C
1 | 4 | 7 | A | D
2 | 5 | 8 | B | E
As a result of the routine that handles the switch positions being buggy, here's what happens after the position of the first switch is known:
- For the cans that have two adjacent cans, the adjacent can with the lowest id will never contain the second switch.
- For the cans that have four adjacent cans, the adjacent cans with the first, second, and third lowest id's will never contain the second switch. For example if the first switch is in 7, the second switch will never be in 4, 6 or 8. This leaves A as the seemingly only option but...
- In addition to this, can 0 (top left) always has a chance to contain the second switch, regardless of where the first switch was. If the first switch had two or four adjacent cans, there is a 50% chance that the second switch is in can 0. If the first switch had three adjacent cans, there is a 25% chance that the second switch is in can 0. The remaining probability is split between the other possible cans (if these also include can 0, the probabilities of the second switch being in can 0 add up).
What does this mean?
If switch one is in 4, 7, or A, switch two will be in 7, A, D respectively (50%), or in 0 (50%).
If switch one is in 0, 2, C, or E, switch two will be in 3, 5, D, D respectively (50%), or in 0 (50%).
If switch one is in any of the other positions, their three adjacent cans will have a 25% each, and can 0 will have the other 25%.
The first bug of not all adjacent cans being possible is because the number of adjacent cans is used as a mask and ANDed with a random number. ANDing with 3 (%0011) leaves all options of 0, 1, 2, 3 possible, but ANDing with 2 (%0010) only leaves 0 or 2, while ANDing with 4 (%0100) only leaves 0 or 4.
To sum up the cause of the second bug, it is as a result of the number obtained above being decremented (by 1) in order to point to the right value in the trash can data structure. If the result was 0, it gives 255 when decremented causing the function to grab the second switch position from a location in ROM where there's no data (just 0's). If this happens, a 0 will be read and treated as switch 0.
If it's succesful in this scenario, it will deal damage to the player equal to twice the damage Counter or Mirror Coat would've dealt if they had no additional effect (like a move such as Tackle or Water Gun). In other words, since both Counter and Mirror Coat have a hardcoded base power of 1, they would "strike back" damage equivalent to a 1-base power fighting-type move or a 1-base power psychic-type move respectively.
The minimum damage in the battle formula is 2 for neutral moves, becoming 3 with STAB. Since the base power used during the calculation is merely 1, Counter or Mirror Coat will usually deal twice the value of the minimum possible damage, but they could do more if the attack/defense ratio is high enough.
This occurs because Counter and Mirror Coat also call the generic damage calculation function despite ignoring the result under normal circumstances. The result is still written to wCurDamage and stays there until it gets overwritten or cleared. This oversight doesn't occur in a wild battle, because in this case the wCurDamage address is cleared before Counter or Mirror Coat are used.
Since Lorelei's Dewgong's only Psychic-type move is Rest (while the other moves are Ice or Normal-type), she will always pick it against Fighting or Poison-type Pokemon (unless they are also weak to Ice-type moves) or against some other type combination like Rock/Water. While enemy Pokemon do have PP structures in RBY just like the player Pokemon, they aren't functional, meaning that PP is never decremented when a trainer's Pokemon uses a move and that the enemies have no limit on how many times they can use any given move.
Another example is Sabrina's Alakazam. It has three Psychic-type moves and Recover, which is a Normal-type attack. If you send a Psychic-type Pokemon, Alakazam will keep using Recover.
And here's where the move Rage comes in. When Rage is used, the user gets stuck using it and is unable to switch Pokemon, use an item, or select another move, as the battle menu is skipped. In addition, Rage only consumes PP on its first use. If the Rage user is not powerful enough to defeat Lorelei's Dewgong with 3 consecutive Rages, Dewgong will keep using Rest and healing itself while the player has no other option but to keep using Rage, forever. Since the Rage user isn't taking damage, its Attack doesn't increase either. The only way to get away is turning off the game.


