Glitch City Laboratories Archives

Glitch City Laboratories closed on 1 September 2020 (announcement). This is an archived copy of a thread from Glitch City Laboratories Forums.

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

You may also download the archive of this forum in .tar.gz, .sql.gz, or .sqlite.gz formats.

Generation II Glitch Discussion

The newcomer and experienced user's guide to G/S/C Arbitrary Code Execution! - Page 1

The newcomer and experienced user's guide to G/S/C Arbitrary Code Execution!

Posted by: Krys3000
Date: 2017-10-30 14:18:52
UPDATE: Many extra thanks to Epsilon, spamviech, Evie, Crystal_, ISSOtm and luckytyphlosion for helping, reviewing and contributing to this guide

Hello there! Welcome to the world of Pokémon ACE!

Lately, with the release of Gold, Silver and now even Crystal in 3DS's Virtual Console, there has been a lot of people asking questions about Arbitrary Code Execution (mainly Coin Case), and with this came a lot of new ideas to use it as well as to perform it. Very talented people (luckytyphlosion, gifvex, Crystal_, ISSOtm to mention some…) have restarted working on it especially for G/S non-english adaptation and lately for Crystal. All of this resulted in the information being spread in a lot of different threads, videos, talks on Discord, etc.

I felt like it was the time for a collaborative guide that gathers all of the current knowledge on
- What are the different ways to make ACE in my language
- What can I do with ACE
- On the long term, an introduction to opcodes and how to make codes that go beyond basic memory editing (if you want to write this part, please don't hesitate)
In forms of summaries but also by giving the links to the different threads and videos about it.

Please don't hesitate to contribute to this guide, as I don't know everything about it, especially regarding english games!

TABLE OF CONTENT:
I. WHAT ARE THE DIFFERENT ACE TECHNIQUES IN G/S/C
II. COIN CASE VS. WRONG POCKET TM ACE
III. WRONG POCKET TM ACE EXPLAINED
III.1: Obtain a Glitch Pokémon n°000
III.2: Use the Glitch Pokémon n°000 to get Mystery Eggs
III.3: Use Mystery Eggs to get TM17 (G/S) or TM15 (Crystal)
III.4: Prepare the Party setup
IV. BAD CLONE ACE EXPLAINED
IV.1: Get any type of Bad Clone (both setups)
IV.2 (A): Crystal_'s setup for ITEMS OR BOX CODES
IV.2 (B): luckytyphlosion's setup for MAIL CODES
V. GLITCH POKEDEX ACE EXPLAINED
V.1: Obtain a Glitch Pokémon n°000
V.2: Use the Glitch Pokémon n°000 to get Mystery Eggs
V.3: Use Mystery Eggs to get the Expanded Balls Pocket
V.4: Prepare the Party setup
VI. WRITE AND EXECUTE A CODE, REGARDLESS OF THE METHOD
VI.1: GET TM17 IN THE WRONG POCKET (Box, G/S)
VI.2: GET ANY TM/HM x255 CODE (Box, G/S)
VI.3: INCREASE/DECREASE THE QUANTITY OF AN ITEM CODE (Items, G/S/C)
VI.4: GET ANY ITEM CODE (Items, G/S/C)
VI.5: MEMORY EDITOR CODE, A.K.A. GAMESHARK SIMULATOR (Items or Box, G/S/C)
VI.6: CHANGING ID CODE (Items, G/S/C)
VI.7: MAKE THE SIXTH POKEMON IN PARTY SHINY CODE (Items, G/S/C)
VI.8: GOTTA CATCH 'EM ALL CODE (Box, G/S)
VI.9: MORE AND COMPETITIVE CODES (Box)
VI.10: A WORD ON HOW TO WRITE COMPLEX CODES
ANNEX 1: GET TM ACE SETUP THROUGH A FIRST-GENERATION GAME
ANNEX 1.1: Gather the needed items
ANNEX 1.2: Create custom jump Pokémon
ANNEX 1.3: Use Mystery Eggs to get TM25
ANNEX 2: GET MYSTERY EGGS USING THE MACHOP TECHNIQUE
GENERAL CONCLUSION

I. WHAT ARE THE DIFFERENT ACE TECHNIQUES IN G/S/C

Much like in first generation games, arbitrary code execution is about to give you the power to modify the RAM in order to make the game do pretty much everything you want, but also, if you feel like it, change the maps, create scripts, and even program another game inside your game.

A well-known method to perform ACE in G/S is the Coin Case Glitch. This very simple glitch is due a mistake done by the english localization team, who forgot in just one occasion to change the end-of-string terminator that was used in japanese games for the actual terminator of english and european games. This mistake is not a part of the original game, and that's why unfortunately, because the localization team of every other country was more rigorous, this glitch cannot be performed in all other languages. Also, even in english games, the glitch was corrected in Crystal. Lame.

So what are the other options to perform ACE, being either in english games or non-english european games? Well, there is, at least, 5 other ACE methods:

- The best method, by far, is the TM Wrong Pocket ACE. which is about having a certain TM in another Pocket than the TM/HM Pocket of the bag and take advantage of it. This method works in all languages and all three games, but it is relatively hard to setup in non-english G/S, as well as in any language Crystal (for which it would require the use of another ACE method BEFORE using this one).

- There is also the Bad Clone ACE which used the properties of a Bad Clone to execute code from box names, much like Coin Case. However, this method uses code from the Mobile GB Adapter and therefore, is a Crystal-only glitch! Although it has been mainly used only as a speedrunning technique for a long time, Crystal_ and luckytyphlosion have made setups to use it during legit gameplay. Nowadays, this can be considered the best method to start ACE (and setup the Wrong Pocket TM) in Crystal.

- ACE can also be achieved using Glitch Pokédex Mode. This method may be done in G/S but I have no clue how to. However, I recently did a setup to use it in Crystal. This method is quite long to setup and has drawbacks, but it also has huge benefits compared to Bad Clone ACE. As a result, if you play Crystal and don't intend to use Bad Clone ACE to setup Wrong Pocket TM ACE, I recommend to use this method instead.

The two last methods are not considered worth it so I'm not going to explain them in details.

- Move 0x00 ACE (also known as 'Move 00 Type ACE' or 'Type 0xD0 move glitch') is another method found by luckytyphlosion that involves a Ditto traded from R/B in which he has been taught the infamous Cooltrainer move. It can also be performed with a Bad Clone. Originally made for speedrunning, it was adapted for legit gameplay by Torchickens, and seems to be exclusive to english games.
* The method is well explained here.
* You will find more on this glitch in the official thread by Torchickens.

- The 'Withdraw Smash ACE', also known as Stack Corruption, is yet another multi-language G/S ACE technique invented by Crystal_ and ISSOtm which also uses a Bad Clone, this time to extend the number of Pokémon in party, and relies on the withdrawal of many Pokémon to corrupt data.
* Don't hesitate to watch this video if you want to learn it!

II. COIN CASE VS. WRONG POCKET TM ACE

NOTE: These methods can be performed on original cartridge as well as Virtual Console (even if it's a shitty emulator), but if performed on an emulator, you must use one that supports ECHO RAM. VisualBoyAdvance doesn't (although VBA-RR and VBA-M do). BGB does. BGB loves you. Use BGB.

Coin Case Glitch is a ready-to-use ACE technique that has no complicated requirements, and there has been work done to exploit it directly, for example to get Celebi. However, Wrong Pocket TM ACE requires less steps and is easier to handle. Also, it doesn't corrupt the Stack, which is an annoying side-effect of Coin Case Glitch. Thus, it is a more efficient ACE source than Coin Case… as long as you have the good TM in the wrong Pocket, and that is precisely the catch.

Fortunately, it is possible to use Coin Case glitch to get this TM in that Pocket! This to say that nowadays, most people prefer to use Coin Case glitch just once, in order to setup Wrong Pocket TM ACE. Whether what you will be one of them or not is up to you, but if you stick with Coin Case, codes that are designed for Wrong Pocket TM won't work without a prior adaptation step. If you're playing a non-english game and thus don't have access to Coin Case, or if you're playing an english game but for some reason prefer not using Coin Case, you can directly jump to chapter III which explains the Wrong Pocket TM ACE.

This is basically how Coin Case works:

1 ) You need what we call a 'Slide Pokémon' in slot 3 of the party. Unlike Wrong Pocket TM ACE, for which any lvl2 Sentret without 6 in Sp. Def. would work, the 'Slide Pokémon' for Coin Case is less permissive. The perfect Pokémon for this is Rocky, the Onix you can trade for a lvl5 (this is important) Bellsprout in Violet City, or Muscle the Machop traded for a lvl13 Drowzee in Goldenrod Departement Store. If you don't have access to these trades, then you can use a lvl2 female Hoothoot (Route 29) but this has only 60% chance to work and you have no way to figure out if it will before you try. If it doesn't, you need to catch another Hoothoot. In all cases the 'Slide Pokémon' must never be trained of receive an EV-changing item, as well as never receive significant friendship, and must be fully healed (without status) every time you use the glitch.

2 ) You need a Quagsire with some specific requirements in slot 4 of the party. There is two sets of requirements, depending on if you want to write a code from your items, in a similar fashion that what was used in R/B/Y, or from box names. Both methods will be explained in this guide, and codes will be given for both. I actually suggest you prepare two Quagsire so you can use one or the other method at any time.
For item codes, have Quagsire hold a Protein and know SLEEP TALK (TM35, basement of Goldenrod Store, requires Basement Key) as first move.
For box codes, have Quagsire hold TM02 (giveaway at Ilex Forest, or bought at Goldenrod Store) and know RETURN (TM27, giveaway if your first Pokémon is happy at Goldenrod Store) as first move.

NOTE: If you can't or don't want to get these TMs, you can use a glitch called the Bad Clone Trick to get them. However, as this glitch is the entry (and hot) point of using Wrong Pocket TM ACE if you don't use Coin Case, doing it makes the whole Coin Case thing useless because you will now be able to use TM ACE. If you really want to learn about this, continue this guide and you'll find out how when we'll come to the part of preparing these Quagsire for Wrong Pocket TM ACE.

NOTE: Of course, you can setup only one ACE method for now, as you will learn from this guide how to use it to setup the other method.

3 ) Write whatever code you want using the method you chose. You will learn how to do this later in the guide, since it is exactly the same for Coin Case and Wrong Pocket TM ACE.

4 ) Enter Cherrygrove City's Pokémon Mart.

5 ) Exit it and take exactly 4 steps to the right.

6 ) Open Bellsprout or Machop's entry in the Pokédex.

7 ) Open the bag, switch Pocket at least once, then go to the Key Items Pocket.

8 ) Use Coin Case to launch the code.

Now before we explain how TM ACE works and how to make codes you will be able to use with one or the other method, here are some ressources you might want to look at:
* GCL's official page about the Coin Case Glitch which also gives some troubleshooting.
* Technical explanations about this glitch can be found in this thread
* Crystal_ made this video illustrating the glitch and explaining how to setup Wrong TM ACE with it.

III. WRONG POCKET TM ACE EXPLAINED

This technique relies on the fact that a TM or HM that is placed, using some glitch magic, in another Pocket than the TM/HM Pocket will execute code, instead of teaching a move. Unless you use another ACE technique (such as Coin Case ACE in G/S, or Bad Clone ACE in Crystal) to get that TM, you will need to learn how to perform 'Item Shifting Glitch', a glitch allowing to get any item in the Balls Pocket, by following the steps below (official thread here).

Credits for it essentially goes to Paco81, for the initial discovery of the Bad Clone Trick (and all those who worked to make this glitch better), luckytyphlosion and gifvex (for the discovery of the Item Shifting Glitch) and Háčky (for its initial work discovering the Expanded Balls Pocket).

NOTE: If playing G/S, you can use 'ANNEX 1: GET TM ACE SETUP THROUGH A FIRST-GENERATION GAME (G/S only)' instead of this whole part.

You first need to use the Bad Clone Trick in a certain way to get two Mystery Eggs. The most reliable way to do this, that guarantees that it will work, has been invented by luckytyphlosion and gifvex and is described below (original source is this pastebin). However, there is another method which is described in 'ANNEX 2: GET MYSTERY EGGS USING THE MACHOP TECHNIQUE' if you want to use it instead of III.1 and III.2 (then come back to III.3).

This particular Bad Clone Trick requires:
- One PC box which has 15 random Pokémon currently, but never had 20 Pokémon at one point.
- Either the Daycare Man or Lady must not have a Pokémon (Lady is preferred).
- At least $200.
- A Bellsprout cloned 5 times (so you have 6 of them).

III.1: Obtain a Glitch Pokémon n°000

Go to the Daycare, south of Goldenrod, and clone Bellsprout once again. However this time, the cloning must be performed in the 15 Pokémon aforementioned box and you must have reset your game right after saying 'YES' to the question about save replacement. If it worked, the obtained clone will be level 0, won't have a name (or many "?" as name in Crystal), and its Pokédex ID (in the profile) also is 000; this is what we call a Bad Clone. If you got a normal clone, release it and try again.
NOTE: In G/S, any clone without name/level but also without the Pokédex ID 000 won't work (treat it as a normal clone). However, if you get such clone in Crystal, it is worth noting that you can convert it into a Bad Clone that can be used for this method. To do this, store the Bad Clone in another PC Box and store 5 other Pokémon in that same box. Then, use the withdraw option to display that box. Leave it and use the withdraw option again. All Pokémon are now Kingdra. Withdraw the Bad Clone and you can now use it (in case of trouble with getting the Kingdra, please read this).

Make a party of the Bad Clone and 5 Bellsprout clones (leaving 1 in the PC).

Give the Bad Clone to the Daycare lady and immediately take it back. It will now be a Glitch Pokémon with n°000 and LAST in your party.

III.2: Use the Glitch Pokémon n°000 to get Mystery Eggs

Open the PC menu and enter the Move Pkmn W/O Mail menu.

Move the last Bellsprout clone from the PC to the 2nd slot of the Party. Note that the Bellsprout names will change to [blank] or your Trainer Name. This is a side effect of the setup and does not have any negative effects.

Move the first Bellsprout to the third party slot, then move the first Bellsprout in place (Press A when the move cursor is shown).

Move the fourth Bellsprout to the first party slot, then move the first Bellsprout in place (Press A when the move cursor is shown).

Move the first Bellsprout to the fourth party slot, then move the first Bellsprout in place TWICE.

Move the second Bellsprout to the third party slot, then move the first Bellsprout in place TWICE.

Exit the Move Pkmn W/O Mail menu and go to the Deposit Menu. Release the first Bellsprout and exit the PC. The first two Bellsprout in the party now have Mystery Egg attached.

Take them and give the Pokémon Glitch n°000 to the Daycare Lady.

III.3: Use Mystery Eggs to get TM17 (G/S) or TM15 (Crystal)

Move the Mystery Eggs in the Key Items Pocket so that they are the last items in the Pocket (do not swap them together).
NOTE: For this trick to work, the Key Items Pocket must be full. If you don't have enough Key Items, you can keep cloning the Bellsprout to get more Eggs in order to fill the Pocket.

Have Great Ball x1 and Poké Ball x2 in the Balls Pocket (nothing else).

Now, swap the first Mystery Egg with the second Mystery Egg (order is important). A S.S. Ticket will appear.

Move to the Balls Pocket. The Great Ball x1 and Poké Ball x2 should have turned into a Master Ball x5 and Ultra Ball x255 respectively (255 is indicated by a [tile]5).

Toss 47 (G/S) or 49 (Crystal) Ultra Balls from the Ultra Ball x255 stack.

Swap the Master Ball x5 with the Ultra Ball x208 (G/S) or x206 (Crystal).

Deposit the Mystery Egg in the Player's PC.

Withdraw the Mystery Egg from the Player's PC. In the Balls Pocket, the Ultra Ball x208 and Master Ball x5 should now have turned into a TM17 x1 (G/S) or TM15 x1 (Crystal) and Poké Ball x255.

Store 255 (all) from the Poké Ball x255 stack in the Player's PC.

III.4: Prepare the Party setup

Item gathering:
- In G/S, get TM02 (giveaway at Ilex Forest, or bought at Goldenrod Store), TM27 (giveaway if your first Pokémon is happy at Goldenrod Store) and TM35 (basement of Goldenrod Store, requires Basement Key).
NOTE: You can also use the Bad Clone Trick to get these items. If you know how to do that, the corresponding moves you will need are ZAP CANNON (TM02), ENCORE (TM35) and FRUSTRATION (TM27).
- In Crystal, get TM50 (giveaway after the Spearow quest in Route 31), TM27 (giveaway if your first Pokémon is happy at Goldenrod Store), Thick Club (or Miracle Seed) and optionally TM18 (obtained at Slowpoké Well or bought at Celadon Store).

Quagsire preparation:
Similarly to Coin Case ACE, you need a Quagsire.
- In G/S, to execute box codes, get the Quagsire to know RETURN as first move (using TM27), and give it TM02 to hold. To execute item codes, get the Quagsire to know SLEEP TALK as first move (using TM35), and give it a Protein to hold. The Quagsire must be in SECOND position of the party.
- In Crystal, to execute box codes, get the Quagsire to know SAFEGUARD as first move (this can only be done through breeding), and give it Miracle Seed (to execute from character 1) or Thick Club (character 2) to hold. To execute item codes, get the Quagsire to know RETURN as first move (using TM27), and give it TM50 to hold. Finally, to execute mail buffer codes, get the Quagsire to know RAIN DANCE as first move (by leveling up to lvl 47 or using TM18), and make sure it doesn't hold any item. The Quagsire must be in FIRST position of the party.
NOTE: I suggest you actually prepare all the Quagsire, and store the ones you don't use when you don't.

Final jump preparation:
- In G/S, you now need a 'Slide Pokémon' which will be put at FIRST position of the party (fully healed, without status). Catch either a Bellsprout in Violet City that you raise at lvl5 then trade for Rocky the Onix with the NPC in Violet City, or a Drowzee that you raise at lvl13 then trade for Muscle the Machop with the NPC in Goldenrod Departement Store. This Pokémon must then never win any battle, or you won't be able to use it anymore.
NOTE: Instead, you can catch a lvl2 Sentret in Route 29, and make sure it doesn't have a 6 in its SP. DEF. stat (if so, catch another - this stat value appears in 31.25% of lvl2 Sentret). This Pokémon must then never win any battle, or you won't be able to use it anymore.
- In Crystal, you now need to use any other ACE method to execute the following item code (starting from item 1):
PP Up x252
TM42 x18
TM27 x3
TM10 x(any quantity)
Any other items in any quantities can go from here on
Once done, toss 29 PP Up and 1 TM42 and execute again. Then toss 28 PP Up and 1 TM42 and execute a third time.

With all this done, everytime you use the TM from the Wrong Pocket with the Pokémon in right place, code will be executed!

IV. BAD CLONE ACE EXPLAINED

If you're playing Crystal, you will anyway need another ACE method than the one described in section III. to set it up. This method is the most suitable one and can be performed before III. If you're playing G/S, just jump to section 'VI. WRITE AND EXECUTE A CODE, REGARDLESS OF THE METHOD'.

There are two different setups available for this ACE method. Crystal_'s one is quick but only works if executing code from ITEMS or BOX NAMES ; luckytyphlosion's one can be used to execute code from the MAIL BUFFER instead.

IV.1: Get any type of Bad Clone (both setups)

You will need:
- One PC box which has 15 random Pokémon currently, but never had 20 Pokémon at one point.
- A random Pokémon.

Go to the Daycare, south of Goldenrod, and clone the random Pokémon once again. However this time, the cloning must be performed in the 15 Pokémon aforementioned box and you must have reset your game right after saying 'YES' to the question about save replacement. If it worked, the obtained clone will have many "?" as name. Here, the level and Pokémon ID are not important. If you got a normal clone, release it and try again.

Store the Bad Clone in the PC. The best is not having any other Pokémon in the box, so they don't get corrupted.

IV.2 (A): Crystal_'s setup for ITEMS OR BOX CODES



The code execution is then performed this way:



IV.2 (B): luckytyphlosion's setup for MAIL CODES

Here's a pastebin that roughly explains this setup: https://pastebin.com/DaWmYHLF
Please note that you must introduce "4AA" before starting your mail code. Otherwise, s**t will happen.

V. GLITCH POKEDEX ACE EXPLAINED

Only available in Crystal (so far), this method is not perfect, but once it's setup the first time, it's practical. For some reasons, you might not want to setup the Wrong Pocket TM ACE in your Crystal version and if so, I recommend to use this method instead of the Bad Clone ACE, because it allows to execute code from everywhere in the game and not only at a Pokémon Center. If you're playing G/S, just jump to section 'VI. WRITE AND EXECUTE A CODE, REGARDLESS OF THE METHOD'.

As with the Wrong Pocket TM ACE, you first need to use the Bad Clone Trick in a certain way to get Mystery Eggs, but this time, you need three of them. The most reliable way to do this, that guarantees that it will work, has been invented by luckytyphlosion and gifvex and is described below (original source is this pastebin). However, there is another method which is described in 'ANNEX 2: GET MYSTERY EGGS USING THE MACHOP TECHNIQUE' if you want to use it instead of V.1 and V.2 (then come back to V.3).

This particular Bad Clone Trick requires:
- One PC box which has 15 random Pokémon currently, but never had 20 Pokémon at one point.
- Either the Daycare Man or Lady must not have a Pokémon (Lady is preferred).
- At least $200.
- A Bellsprout cloned 5 times (so you have 6 of them).

V.1: Obtain a Glitch Pokémon n°000

Go to the Daycare, south of Goldenrod, and clone Bellsprout once again. However this time, the cloning must be performed in the 15 Pokémon aforementioned box and you must have reset your game right after saying 'YES' to the question about save replacement. If it worked, the obtained clone will be level 0, won't have a name (or many "?" as name in Crystal), and its Pokédex ID (in the profile) also is 000; this is what we call a Bad Clone. If you got a normal clone, release it and try again.
NOTE: In G/S, any clone without name/level but also without the Pokédex ID 000 won't work (treat it as a normal clone). However, if you get such clone in Crystal, it is worth noting that you can convert it into a Bad Clone that can be used for this method. To do this, store the Bad Clone in another PC Box and store 5 other Pokémon in that same box. Then, use the withdraw option to display that box. Leave it and use the withdraw option again. All Pokémon are now Kingdra. Withdraw the Bad Clone and you can now use it (in case of trouble with getting the Kingdra, please read this).

Make a party of the Bad Clone and 5 Bellsprout clones (leaving 1 in the PC).

Give the Bad Clone to the Daycare lady and immediately take it back. It will now be a Glitch Pokémon with n°000 and LAST in your party.

V.2: Use the Glitch Pokémon n°000 to get Mystery Eggs

Open the PC menu and enter the Move Pkmn W/O Mail menu.

Move the last Bellsprout clone from the PC to the 2nd slot of the Party. Note that the Bellsprout names will change to [blank] or your Trainer Name. This is a side effect of the setup and does not have any negative effects.

Move the first Bellsprout to the third party slot, then move the first Bellsprout in place (Press A when the move cursor is shown).

Move the fourth Bellsprout to the first party slot, then move the first Bellsprout in place (Press A when the move cursor is shown).

Move the first Bellsprout to the fourth party slot, then move the first Bellsprout in place TWICE.

Move the second Bellsprout to the third party slot, then move the first Bellsprout in place TWICE.

Exit the Move Pkmn W/O Mail menu and go to the Deposit Menu. Release the first Bellsprout and exit the PC. The first two Bellsprout in the party now have Mystery Egg attached. Clone one of these Bellsprout in order to have three Pokémon with Mystery Egg attached.

Take them and give the Pokémon Glitch n°000 to the Daycare Lady.

V.3: Use Mystery Eggs to get the Expanded Balls Pocket

The idea here is to perform luckytyphlosion's Item Shifting Glitch (official thread here) in a certain way that I coined 'Double Item Shifting Glitch'. The catch here is that you don't want a specific items in your Balls Pocket, but you want this pocket to get 255 items (<i>Expanded Balls Pocket</i>) so you can access your stored items (and many other data) from the Balls Pocket. However, in Crystal, item 00 ("?") freezes the game when you place the cursor on it, so you need to make sure that there won't be an item 00 before stored items in the Expanded Balls Pocket. This is the way it must be performed:


V.4: Prepare the Party setup

Gather the following items and store them in the PC:


Now, similarly to Coin Case ACE or Wrong Pocket TM ACE, you need a Quagsire. To execute box codes, get the Quagsire to know SAFEGUARD as first move (this can only be done through breeding), and give it Miracle Seed (to execute from character 1) or Thick Club (character 2) to hold. To execute item codes, get the Quagsire to know RETURN as first move (using TM27), and give it TM50 to hold. Finally, to execute mail buffer codes, get the Quagsire to know RAIN DANCE as first move (by leveling up to lvl 47 or using TM18), and make sure it doesn't hold any item. The Quagsire must be in SECOND position of the party.
NOTE: I suggest you actually prepare all the Quagsire, and store the ones you don't use when you don't.

Now, similarly to G/S methods, you need a 'Slide Pokémon' which will be put at FIRST position of the party (fully healed, without status). Catch either a Bellsprout in Violet City that you raise at lvl5 then trade for Rocky the Onix with the NPC in Violet City, or an Abra that you raise at lvl13 then trade for Muscle the Machop with the NPC in Goldenrod Departement Store. This Pokémon must then never win any battle, or you won't be able to use it anymore.
NOTE: Instead, you can catch a lvl2 Sentret in Route 29, and make sure it doesn't have a 6 in its SP. DEF. stat (if so, catch another - this stat value appears in 31.25% of lvl2 Sentret). This Pokémon must then never win any battle, or you won't be able to use it anymore.

Finally, open the Balls Pocket and slide down, you will see the PC Items after the CANCEL that follows the last ball (although only the description might show up). Using SELECT, place the x9 item at position 65, the TM19 at position 165, and the TM29 at position 166.

With this done, everytime you use the Pokédex, code gets executed!

VI. WRITE AND EXECUTE A CODE, REGARDLESS OF THE METHOD

At this point, you know how to have your setup ready to execute code and you just need to write it. We will review here some codes, either Item Codes, Box Codes, and possibily Mail Buffer Codes, for use with either Coin Case, Wrong Pocket TM, Bad Clone ACE or Glitch Pokédex, as well as explain how to make some of your own!

Once you have finished this section and arrived to the point where you understand how to ACE and what are the registers, please keep in mind that some of the codes you may create, or created by others, modify the de register. This may be an issue if you execute it using the Bad Clone ACE. To avoid this, before ending your code, please set de to 0134.

NOTE: Unfortunately, there is no way to use most, if not all, box codes in German G/S/C as well as in French Crystal.

VI.1: GET TM17 IN THE WRONG POCKET (Box, G/S)
This code is exclusively for Coin Case ACE.

NOTE: Of course, this code is destined to Coin Case users willing to have TM17 on the Item Pocket to shift on Wrong Pocket TM ACE (the code is from Crystal_'s video linked in chapter II). It would, of course, be useless to do that with TM ACE, and since it contains a way to fix the Stack, doing it will not work.

Make that the first item in your Item Pocket is disposable, as it will be replaced by TM17.

Go to Bill's PC and use the CHANGE BOX option to rename Box 1 to 5 into as follows:
Ap0'déyPk (Pk is an available symbol, not "P followed by k")
'v't'véé'l2h
'd'd2'v9.9't
é?2hhhhh
h'm

Follow step 4 to 8 in chapter II while making sure the 'Slide Pokémon' and Quagsire with RETURN and TM02 are placed in the right spots (3 and 4). TM17 will then appear in your Item Pocket.

VI.2: GET ANY TM/HM x255 CODE (Box, G/S)

Go to Bill's PC and use the CHANGE BOX option to rename Box 1 into Ap09é_'d (english game), Ap09é_ì (italian and spanish game) or Ap09é_n' (french game) while replacing _ by the character corresponding to the TM in the following table:
(space) = TM02
A = TM03
B = TM04
C = TM05
D = TM06
E = TM07
F = TM08
G = TM09
H = TM10
I = TM11
J = TM12
K = TM13
L = TM14
M = TM15
N = TM16
O = TM17
P = TM18
Q = TM19
R = TM20
S = TM21
T = TM22
U = TM23
V = TM24
W = TM25
X = TM26
Y = TM27
Z = TM28
( = TM29
) = TM30
: = TM31
; = TM32
[ = TM33
] = TM34
a = TM35
b = TM36
c = TM37
d = TM38
e = TM39
f = TM40
g = TM41
h = TM42
i = TM43
j = TM44
k = TM45
l = TM46
m = TM47
n = TM48
o = TM49
p = TM50
q = HM01
r = HM02
s = HM03
t = HM04
u = HM05
v = HM06
w = HM07
NOTE: As of now, to my knowledge there is no equivalent to this for german games.

Use TM17 from the Wrong Pocket (or follow step 4 to 8 in chapter II if you use Coin Case) while making sure the 'Slide Pokémon' and Quagsire with RETURN and TM02 are placed in the right spots (1 and 2 for TM ACE, 3 and 4 for Coin Case). The TM/HM x255 will appear in the TM/HM Pocket.

VI.3: INCREASE/DECREASE THE QUANTITY OF AN ITEM CODE (Items, G/S/C)

Use 'VI.2: GET ANY TM/HM x255 CODE' to get TM10 and TM23 (TM26 in Cristal), unless you already have them in the necessary quantities below.
NOTE: TM10 can be bought.

Get (unless you already have), then store the following items in the PC, in that order:
Any Item x(any quantity) (nothing in Crystal)
Any item x(any quantity) (nothing in Crystal)
Fresh Water x44 (x3 in Crystal)
Poké Ball x38
TM23 (TM26 in Cristal) x52 (to increase) or x53 (to decrease)
[ONLY FOR COIN CASE: X Defense x1] (otherwise replace with TM10 x(any quantity))
[ONLY FOR COIN CASE: X Speed + x1] (otherwise replace with Any item x(any quantity))
[ONLY FOR COIN CASE: TM06 x195 (use VI.2 and VI.3 to get them)] (otherwise replace with Any item x(any quantity))
[ONLY FOR COIN CASE: HM03 x18 (use VI.2 and VI.3 to get them)] (otherwise replace with Any item x(any quantity))
[ONLY FOR COIN CASE: TM10 x(any quantity)] (otherwise replace with Any item x(any quantity))
The item that must change x(any quantity)
Any other items in any quantities can go from here on

According to the selected method,
- Use TM17/TM15 from the Wrong Pocket (Wrong Pocket TM)
- Follow step 4 to 8 in chapter II (Coin Case)
- Follow the process in chapter IV.2 (Bad Clone ACE)
- Open the Pokédex (Glitch Pokédex ACE)
While making sure the 'Slide Pokémon'/Spearow/the appropriate Quagsire are placed in the right spots (if needed in your method) and the 11th item will get or lose one unit.
NOTE: Decreasing the quantity is very useful if the item is x1; this way, using the code twice will set the quantity to x255, and then you can toss as many units as you want to reach the quantity you actually need.

VI.4: GET ANY ITEM CODE (Items, G/S/C)

Use 'VI.2: GET ANY TM/HM x255 CODE' to get TM10 and TM23 (TM26 in Cristal), unless you already have them in the necessary quantities below.
NOTE: TM10 can be bought.

Use this list: https://glitchcity.info/wiki/The_Big_HEX_List to find an item that you have or can easily buy/get and is the closest possible (above or below) of the wanted item in the Item column. Get this selected item.

Get (unless you already have), then store the following items in the PC, in that order:
Any Item x(any quantity) (nothing in Crystal)
Any item x(any quantity) (nothing in Crystal)
Fresh Water x43 (x2 in Crystal)
Poké Ball x38
TM23 (TM26 in Cristal) x52 (if the wanted item is below the selected one) or x53 (if the wanted item is above the selected one)
[ONLY FOR COIN CASE: X Defense x1] (otherwise replace with TM10 x(any quantity))
[ONLY FOR COIN CASE: X Speed + x1] (otherwise replace with Any item x(any quantity))
[ONLY FOR COIN CASE: TM06 x195 (use VI.2 and VI.3 to get them)] (otherwise replace with Any item x(any quantity))
[ONLY FOR COIN CASE: HM03 x18 (use VI.2 and VI.3 to get them)] (otherwise replace with Any item x(any quantity))
[ONLY FOR COIN CASE: TM10 x(any quantity)] (otherwise replace with Any item x(any quantity))
The selected item x(any quantity)
Any other items in any quantities can go from here on

According to the selected method,
- Use TM17/TM15 from the Wrong Pocket (Wrong Pocket TM)
- Follow step 4 to 8 in chapter II (Coin Case)
- Follow the process in chapter IV.2 (Bad Clone ACE)
- Open the Pokédex (Glitch Pokédex ACE)
While making sure the 'Slide Pokémon'/Spearow/the appropriate Quagsire are placed in the right spots (if needed in your method) and the 11th item will change.

VI.5: MEMORY EDITOR CODE, A.K.A. GAMESHARK SIMULATOR (Items or Box, G/S/C)

The box version of this code (G/S only) is tricky and described in Crystal_'s videos. First use 'VI.2: GET ANY TM/HM x255 CODE' to get TM09 (unless you already have it) and make Quagsire hold it instead of TM02, then click here for english games (from 10:29) and click here for non-english games (from 9:41). For the items version of the code, do as follows.

If you want to simulate a G/S Gameshark code (which always is 01XXYYZZ):
- Use the Windows Calculator to convert XX into Decimal and note the value.
- Do the same with YY.
- Check in this table http://pastebin.com/raw/arPmsvYu the item that matches ZZ.
If you want to edit a WRAM address value instead:
- Use one of the two following sources to find the $ZZYY memory address that contains the data you want to edit. The first one is more convenient and easier to use, but less exhaustive than the second one.
* Datacrystal's G/S RAM MAP: https://datacrystal.romhacking.net/wiki/Pok%C3%A9mon_Gold_and_Silver:RAM_map
* Pokémon Gold(/Silver) disassembly project: https://github.com/PikalaxALT/pokegold/blob/master/wram.asm
- Determine the XX value you want to put in the address. For example, if the address is the one that controls the quantity of the first item in the Balls Pocket and you want it to be 5, then XX is 5. If the address controls what the first item is and you want it to be a Master Ball, use this table http://pastebin.com/raw/arPmsvYu to see that Master Ball's hex ID is 01. Therefore XX would be 01.
- Use the Windows Calculator to convert XX into Decimal and note the value.
- Do the same with YY.
- Check in the aforementioned table the item that matches ZZ.

Use 'VI.2: GET ANY TM/HM x255 CODE' to get TM10 and TM42, unless you already have them in the necessary quantities below. If ZZ matches a TM and you need it, use it also for this TM.
NOTE: TM10 can be bought.

Use 'VI.4: GET ANY ITEM CODE (Items)' to get PP Up, unless you already have one (or more). If ZZ doesn't match a TM and you need it, use it also for this item.

Get (unless you already have), then store the following items in the PC, in that order:
Any Item x(any quantity) (nothing in Crystal)
Any item x(any quantity) (nothing in Crystal)
PP Up x(decimal conversion of XX)
TM42 x(decimal conversion of YY)
Item that matches ZZ x3
[ONLY FOR COIN CASE: X Defense x1] (otherwise nothing)
[ONLY FOR COIN CASE: X Speed + x1] (otherwise nothing)
[ONLY FOR COIN CASE: TM06 x195 (use VI.2 and VI.3 to get them)] (otherwise nothing)
[ONLY FOR COIN CASE: HM03 x18 (use VI.2 and VI.3 to get them)] (otherwise nothing)
TM10 x(any quantity)
Any other items in any quantities can go from here on

According to the selected method,
- Use TM17/TM15 from the Wrong Pocket (Wrong Pocket TM)
- Follow step 4 to 8 in chapter II (Coin Case)
- Follow the process in chapter IV.2 (Bad Clone ACE)
- Open the Pokédex (Glitch Pokédex ACE)
While making sure the 'Slide Pokémon'/Spearow/the appropriate Quagsire are placed in the right spots (if needed in your method) and the code will get executed.

VI.6: CHANGING ID CODE (Items, G/S/C)
Particular usage of 'VI.5: MEMORY EDITOR CODE, A.K.A. GAMESHARK SIMULATOR (Items or Box)'

Use 'VI.2: GET ANY TM/HM x255 CODE' to get TM10, TM42 and TM18 (TM21 in Crystal), unless you already have them in the necessary quantities below.
NOTE: TM10 and TM18 can be bought.

Use 'VI.4: GET ANY ITEM CODE (Items)' to get PP Up, unless you already have one (or more).

Using the Windows Calculator, convert the ID you want into hexadecimal (example: 13579 translates into 350B). Then, split this hexadecimal ID number in two parts (example: in this case, you get '35' and '0B').

Use this list: http://pastebin.com/raw/arPmsvYu to find the number from the Decimal column corresponding to the SECOND part of the hexadecimal ID number (read in the Hexadecimal column) (example: in this case, 0B corresponds to 11).

Use 'VI.3: INCREASE/DECREASE THE QUANTITY OF AN ITEM CODE (Items)' on PP Up to give them the quantity corresponding to this previously obtained number.

Get (unless you already have), then store the following items in the PC, in that order:
Any Item x(any quantity) (nothing in Cristal)
Any item x(any quantity) (nothing in Cristal)
PP Up x(the obtained number)
TM42 x162 (x124 in Crystal)
TM18 (TM21 in Crystal) x3
[ONLY FOR COIN CASE: X Defense x1] (otherwise nothing)
[ONLY FOR COIN CASE: X Speed + x1] (otherwise nothing)
[ONLY FOR COIN CASE: TM06 x195 (use VI.2 and VI.3 to get them)] (otherwise nothing)
[ONLY FOR COIN CASE: HM03 x18 (use VI.2 and VI.3 to get them)] (otherwise nothing)
TM10 x(any quantity)
Any other items in any quantities can go from here on

According to the selected method,
- Use TM17/TM15 from the Wrong Pocket (Wrong Pocket TM)
- Follow step 4 to 8 in chapter II (Coin Case)
- Follow the process in chapter IV.2 (Bad Clone ACE)
- Open the Pokédex (Glitch Pokédex ACE)
While making sure the 'Slide Pokémon'/Spearow/the appropriate Quagsire are placed in the right spots (if needed in your method).

Use this list: http://pastebin.com/raw/arPmsvYu to find the number from the Decimal column corresponding to the FIRST part of the hexadecimal ID number (read in the Hexadecimal column) (example: in this case, 35 corresponds to 53).

Use 'VI.3: INCREASE/DECREASE THE QUANTITY OF AN ITEM CODE (Items)' on PP Up to give them the quantity corresponding to this previously obtained number.

Toss or withdraw 1 TM42, so you now have TM42 x161 (x123 in Crystal) in the PC.

According to the selected method,
- Use TM17/TM15 from the Wrong Pocket (Wrong Pocket TM)
- Follow step 4 to 8 in chapter II (Coin Case)
- Follow the process in chapter IV.2 (Bad Clone ACE)
- Open the Pokédex (Glitch Pokédex ACE)
While making sure the 'Slide Pokémon'/Spearow/the appropriate Quagsire are placed in the right spots (if needed in your method).

VI.7: MAKE THE SIXTH POKEMON IN PARTY SHINY CODE (Items, G/S/C)

Use 'VI.2: GET ANY TM/HM x255 CODE (Box)' to get TM10 and TM28, unless you already have them in the necessary quantities below.

Use 'VI.4: GET ANY ITEM CODE (Items)' to get Polkadot Bow and Metal Powder.
NOTE: You can also trade respectively Jigglypuff and Ditto from R/B/Y, they will hold these items.

Use 'VI.3: INCREASE/DECREASE THE QUANTITY OF AN ITEM CODE (Items)' on Polkadot Bow and Metal Powder to give them the quantity of x119 (in Crystal, use it also on X Accuracy to give it a quantity of x228).

Get (unless you already have), then store the following items in the PC, in that order:
Any Item x(any quantity) (nothing in Crystal)
Any item x(any quantity) (nothing in Crystal)
X Accuracy x47 (x228 in Crystal)
TM28 x62 (TM29 x62 in Crystal)
Polkadot Bow x119
Metal Powder x119
[ONLY FOR COIN CASE: X Defense x1] (otherwise nothing)
[ONLY FOR COIN CASE: X Speed + x1] (otherwise nothing)
[ONLY FOR COIN CASE: TM06 x195 (use VI.2 and VI.3 to get them)] (otherwise nothing)
[ONLY FOR COIN CASE: HM03 x18 (use VI.2 and VI.3 to get them)] (otherwise nothing)
TM10 x(any quantity)
Any other items in any quantities can go from here on

According to the selected method,
- Use TM17/TM15 from the Wrong Pocket (Wrong Pocket TM)
- Follow step 4 to 8 in chapter II (Coin Case)
- Follow the process in chapter IV.2 (Bad Clone ACE)
- Open the Pokédex (Glitch Pokédex ACE)
While making sure the 'Slide Pokémon'/Spearow/the appropriate Quagsire are placed in the right spots (if needed in your method) and the sixth Pokémon will be Shiny.

VI.8: GOTTA CATCH 'EM ALL CODE (Box, G/S)

The standard version of this code is easy and quick to perform:
- For English games, see this post for that gives it for Wrong Pocket TM ACE and Coin Case ACE (a video is also available here). This code also gives shiny Pokémon.
- For italian and spanish games, do the same as English Wrong Pocket TM but replace 'v with ° and 'd with ì in italian and spanish games. This code also gives shiny Pokémon.
- For french games, see this post.
- There doesn't seem to be a German adaptation to this so far.

NOTE: If you don't like this code, you can also apply another method that is significantly longer but uses one code for all Pokémon. This method is explained in Crystal_'s video here.

VI.9: MORE AND COMPETITIVE CODES (Box)

More G/S codes made by the members of GCLF can be found in this thread. Don't hesitate to read it, but pay attention to what they have been designed for (Coin Case, Wrong Pocket TM, or both).

This thread here by FMK gives more G/S box codes and explain how to convert Coin Case box codes into Wrong Pocket TM box codes. It also gives a slightly different process with TM25 instead.

For some G/S competitive battling codes, check this thread by Torchickens.

VI.10: A WORD ON HOW TO WRITE COMPLEX CODES

As of now, you know how to create your own code to change a single value in the game's RAM. That's very cool, but you might want to do more complex codes that will affect several values at once or create your own scripts. To do that, you'll need to understand how ACE works.

In G/S, using TM17 in the wrong pocket makes the game read code from address $FA47, which is located in what we call Echo RAM. Starting at $E000, this Echo RAM is a duplicate of WRAM, the memory section going from $C000 to $DFFF which stores the game's data. $FA47 thus contains exactly the same value than $DA47, the caught data of your current first Pokémon. Registered inside two consecutive addresses ($DA47 and $DA48 in the case of Pokémon 1), caught data is an unused section of the Pokémon's data, so its value is always 00. If you ever heard about people using TM25 instead, well the concept is the same, but it reads from the Defense EV of the second Pokémon. Finally, using Coin Case is no different, but this time we read data from the third Pokémon!

In all these cases, writing useful code from Pokémon data is almost impossible because it would require specific stats, EV, sometimes even IV… so we need to get the hell out of this place to reach another section of WRAM in which we have more control (either items or box names). Now let's explain the theory with the case of TM17 and let's take a look at the RAM's data for party Pokémon 1 and 2 (you can see all of this using the RAM Map)

Pokémon 1
($DA2A to $DA46 are all the other datas that are not useful here)
$DA47 to $DA48 = Caught Data
$DA49 = Level
$DA4A to $DA4B = Status
$DA4C to $DA4D = HP
$DA4E to $DA4F = Max HP
$DA50 to $DA51 = Attack
$DA52 to $DA53 = Defense
$DA54 to $DA55 = Speed
$DA56 to $DA57 = Special Defense
$DA58 to $DA59 = Special Attack
Pokémon 2
$DA5A = Species
$DA5B = Item Held
$DA5C to $DA5F = Moves

Every address mentioned here has an hexadecimal value corresponding to the data of your Pokémon (for example, if the attack stat of Pokémon 1 is 21, the value of $DA51 is 15). You must now understand that when the game reads code from a point, it interprets the hexadecimal values into instructions called opcodes. In the corresponding list we've provided before for Hex/Dec/Items correspondance, you also have the opcode for each hex, and you can also find here on this more complete table. To take an example, 41 matches the instruction 'ld B,C'.

I don't want (and it's above my knowledge) to explain all opcodes here, but you can actually find a lot of useful ressources on the Internet (I'll link some later in this guide) but we're going to review some basics:
- nop (matching hexadecimal 00) means no operation. The game just continues reading.
- ld means load, in the way that a variable is loaded with ('becomes') a value.
- inc and dec command to increase or decrease the value of a given variable.
- add and sub means that a given value is added or substracted to the variable A (always).
- jp is a jump. It allows you to move to a given part of the WRAM, that can be either directly set by the user or contained in a duo of variable, HL.
- jr is also a jump, but a relative one. It jumps at a given distance of the current reading position.
- ret is mainly used, here, to end your code (in fact, it pops the top of the stack to the program counter).

At first, we want to jump at $D61B (third stored item) or $D8C0 (box 1 name, character two). In the latter case, that translates to "jp D8C0". We will then use the instruction coded by hexadecimal C3, which is a jump at the position given by the two following hexadecimals (reversed - to understand why, read Wikipedia's page about endianness). That means if the game reads C3 C0 D8, then it will jump at box name 1.

We can't easily control the data we have access to in Pokémon 1 when using TM17, but we could use the species (hex:C3 is Quagsire in the list), held item (hex:C0 is TM02) and first move of Pokémon 2 (hex:D8 is RETURN) because that is not a big requirement. Our best shot is then to make sure Pokémon 1's data matches 'unharmful opcodes' that won't jump or will only affect variables we don't care about to so it can 'slide' until Quagsire: this is why the first Pokémon is called 'Slide Pokémon'. The same goes for Pokémon 3 with Coin Case, although it reads more ot its data, so the 'Slide Pokémon' is less permissive. However, in the case of TM25, we can actually affect the EV of the Pokémon by training it until it reaches these values, so it's not mandatory to use a 'Slide Pokémon' (but then, it's longer to setup).

In Crystal, the process for Wrong Pocket TM is quite the same, but TM15 reads from $DA10, an unused part of the RAM. Using another ACE method, we edit this section to introduce C3 DF FC, which commands a jump to party Pokémon 1 species. With Quagsire, we then write C3 F2 (TM50) D8 (RETURN), C3 75 (Miracle Seed) DB (SAFEGUARD) or C3 00 (no item) F0 (RAIN DANCE) and therefore jump in the appropriate place.

Glitch Pokédex ACE method is about changing the Pokédex mode (usually New, Old, A to Z or Zarbi Mode) to glitched mode 09. Pokédex mode is controlled by address $D959 in Crystal, and can be modified to an invalid value (such as 09) using the expanded Balls Pocket obtained through the Double Item Shifting Glitch, because it matches the quantity of item 65. Placing any x9 item at this position will then affect the Pokédex mode. Then, any opening of the Pokédex executes code from $FA20 (a copy of $DA20). This address is linked to game flags, and you can modify it once again by manipulating items 165 and 166. With CT19 x1 and CT29 x1, we write the code D2 01 DD, which translates into 'jp NC,$DD01'. This is a conditionnal jump to the first Pokémon of the party, and in this case, the jump will always occur. There goes the 'Slide Pokémon' and Quagsire as usual.

Let's finish the Crystal digression with Bad Clone ACE. Bad Clones have no terminated name and once you view them in the PC in Crystal, the reading of their name continues on following memory data. That being said, some characters, named control characters, are used by the game not to write things, but sometimes to execute functions. Character with hex ID 15 is one of them and is used for Mobile Adapter GB. But, because of a programmer mistake, if character 15 is followed by any address containing 00, game executes code from $CD52, the buffer for map data. By following the steps indicated in the guide, you modify this buffer and 'write' a ret instruction at $CD74. This ret is not going to stop the code execution, but deviates it (for technical reasons) to whatever address is located right after the 15 00.

Now, $D106 controls the current position of the item pointer. Thus, it always contains the hex ID of the item on which the pointer currently is. $D107 contains the bag position of the item that you currently have selected; which means that by viewing Max Elixer (hex ID 15) but not selecting it, you write 15 00, which is then read as part of the Bad Clone's name, and therefore executes code at $CD52… which jumps back to $D108! This area is yet another buffer, this time containing visualized Pokémon: $D108 is the hex ID of the last viewed Pokémon in the PC, $D10E is the hex ID of the last Pokémon's displayed profile, $D110 its first move, and $D10F the hex ID of the held item of the last Pokémon viewed by either method. Assuming Quagsire has RETURN and TM50, we order C3 XX XX XX XX XX C3 F2 D8. The three last addresses indeed matches 'jp $D8F2' but the first C3 would jump us somewhere else. By viewing Spearow, without opening its profile, we overwrite the first C3 without touching the one at $D10E - and Quagsire's item doesn't matter since it is overwritten by Spearow's TM50.

Let's now focus on G/S and review the gameshark simulation/single-address value changing code (VI.5). Keep in mind what we want to do here is to put BB as the value of address $DDCC. PP Up's hex ID is 3E, TM42 is EA, and TM10 is C9. Remember that after the address of an item comes the address of its quantity, and only then we can proceed with item 2.
$D61B 3E ld A,XX
As mentioned in the table by the small '2' under this opcode, it takes two bytes: XX will be the value of the following address ($D61C, the quantity of item 3 - in our case, "BB"). This instruction thus says 'ld A,BB' and the variable A becomes BB. Therefore, $D61C is not read as an opcode, and we proceed.
$D61D EA ld XXXX,A (3 octets) This instruction takes 3 bytes so we need to consider the two following ones.
$D61E "CC"
$D61F "DD" ld (DDCC),A The parenthesis indicates it's the value of XXXX that changes. Then, the value of $DDCC becomes A which is now BB!
$D620 03 inc BC Increase the duo of variable b and c. It's just a placeholder here, we don't use these variables.

The 4 following items in the code (instructions read from $D621 to $D628) are exclusive to Coin Case. This is because Coin Case has a major drawback compared to Wrong Pocket TM ACE which we mentioned before: it destroys the stack. This set of instructions is meant to fix it, and thus are not used with Wrong Pocket TM ACE. Let's finish this code:
$D629 C9 ret Code reading ends.

Isn't that easy? See this other example with the code that changes Stored Item 11 (VI.4). This item's address is $D62B. You should be able to understand that the code read by the game in this case is 2E 2B 05 26 D6 34 [Coin Case Set] C9.
$D61B 2E ld l,XX (2 bytes)
$D61C 2B ld l,2B Variable l becomes 2B.
$D61D 05 dec b Variable b is decreased. This is still a placeholder.
$D61E 26 ld h,XX (2 bytes)
$D61F D6 ld h,D6 Variable l becomes D6.
$D620 34 inc (hl) Value of address hl ($D62B) is increased. We're done!
$D621 to $D628 Coin Case set.
$D629 C9 ret Code reading ends.


Writing codes with items is easy in theory because you have access to almost all opcodes. However, it can be a bit unpractical when it comes to gathering items. Writing box codes is of course quicker and easier, but you won't have access to all opcodes because the first character, the space, has an hex ID of 7F (followed by A, which has an hex ID of 80). This is why box codes are longer than item codes, since it requires to spam add and sub to workaround the impossibility to use 2-bytes ld. Also, some characters are exclusive to languages, which means codes have to be translated for each language! It is rather easy in italian and spanish, very difficult in french (because of the lack of sub) and almost impossible in german because it doesn't even have 3-bytes ld.

This guide won't get into details for box codes, because it would require more lessons on opcodes and how to use flags. If you're new to this, you can stick to item codes, or ask here for specific help with your codes! We can always go further and ACE can be also used to program something, in the way TheZZAZZGlitch did a Pong game in R/B/Y! Everything cannot be included in this guide, but there is a lot for you to discover. Your very own ACE legend is about to unfold! A world of dreams and adventures with ACE awaits! Let's go!

Useful ressources:
* This website's guide to GB Programming
* A GameBoy opcode summary can be found here for basic understanding of what opcodes do.
* A more detailed guide with syntax is available on this website.

ANNEX 1: GET TM ACE SETUP THROUGH A FIRST-GENERATION GAME (G/S only)

You will need:
- A R/B/Y game in which you can perform code execution using either the 8F item, the wsl'm item, or the 4F item (this is NOT a guide to code execution in first generation games, it assumes you already have one of these items and a proper setup to use it. If you don't know what we're talking about here, please go back to the normal process).
- The following TMs (at least 1 of each): TM01, TM14, TM18, HM03.
- At least 1 of each of the following : Thunderstone, Max Revive, X Accuracy, Lemonade, Water Stone, Soda Pop.
- 34 Ice Heal stored in the PC.
- Some other things that can easily be bought in-game.

ANNEX 1.1: Gather the needed items

Place the following items, in that order, in your pack:
8F (4F or wsl'm in Yellow)
Thunderstone x1
Poké Ball x45
Revive x3
TM01 x(any quantity)
Any other items in any quantities can go from here on

Use the 8F (4F or wsl'm in Yellow) item. You should now have Thunderstone x0 instead of x1. Store them in the PC.

Place the following items, in that order, in your pack:
8F (4F or wsl'm in Yellow)
Max Revive x1
Poké Ball x45
Revive x3
TM01 x(any quantity)
Any other items in any quantities can go from here on

Use the 8F (4F or wsl'm in Yellow) item. You should now have Max Revive x0 instead of x1. Store them in the PC.

Place the following items, in that order, in your pack:
8F (4F or wsl'm in Yellow)
X Accuracy x1
Poké Ball x45
Revive x3
TM01 x(any quantity)
Any other items in any quantities can go from here on

Use the 8F (4F or wsl'm in Yellow) item. You should now have X Accuracy x0 instead of x1. Store them in the PC.

Place the following items, in that order, in your pack:
8F (4F or wsl'm in Yellow)
Lemonade x1
Poké Ball x45
Revive x3
TM01 x(any quantity)
Any other items in any quantities can go from here on

Use the 8F (4F or wsl'm in Yellow) item. You should now have Lemonade x0 instead of x1. Store them in the PC.

Place the following items, in that order, in your pack:
8F (4F or wsl'm in Yellow)
Water Stone x1
Poké Ball x45
Revive x3
TM01 x(any quantity)
Any other items in any quantities can go from here on

Use the 8F (4F or wsl'm in Yellow) item. You should now have Water Stone x0 instead of x1. Store them in the PC.

Place the following items, in that order, in your pack:
8F (4F or wsl'm in Yellow)
Soda Pop x1
Poké Ball x45
Revive x3
TM01 x(any quantity)
Any other items in any quantities can go from here on

Use the 8F (4F or wsl'm in Yellow) item. You should now have Soda Pop x0 instead of x1. Store them in the PC.

Place the following items, in that order, in your pack:
8F (4F or wsl'm in Yellow)
HM03 x1
Poké Ball x45
Revive x3
TM01 x(any quantity)
Any other items in any quantities can go from here on

Use the 8F (4F or wsl'm in Yellow) item. You should now have HM03 x0 instead of x1 (but you won't seen its number). Store them in the PC.

Place the following items, in that order, in your pack:
8F (4F or wsl'm in Yellow)
TM18 (TM17 in Yellow) x1
Poké Ball x45
Revive x3
TM01 x(any quantity)
Any other items in any quantities can go from here on

Use the 8F (4F or wsl'm in Yellow) item. You should now have the TM x0 instead of x1. Store them in the PC.

Place the following items, in that order, in your pack:
8F (4F or wsl'm in Yellow)
TM14 x1
Poké Ball x45
Revive x3
TM01 x(any quantity)
Any other items in any quantities can go from here on

Use the 8F (4F or wsl'm in Yellow) item. You should now have TM14 x0 instead of x1. Store them in the PC.

ANNEX 1.2: Create custom jump Pokémon

Make sure you have at least 2 Pokémon in the active box.
NOTE: If you're playing Yellow, these 2 Pokémon are part of your setup.

Withdrawing items from the x0 stacks in your PC, place the following items, in that order, in your pack:
Any item x(any quantity)
8F (4F or wsl'm in Yellow)
Thunderstone x190 in english R/B (x189 in english Yellow, x195 in non-english R/B, x194 in non-english Yellow)
TM18 x4
Max Revive x69
X Accuracy x205 in english R/B (x204 in english Yellow, x210 in non-english R/B, x209 in non-english Yellow)
Lemonade x195
Water Stone x12
TM14 x3
Ice Heal x34
HM03 x25
Soda Pop x119
TM01 x(any quantity)

Use the 8F (4F or wsl'm in Yellow) item.

Toss 33 Thunderstone.

Toss 33 X Accuracy.

Withdraw 165 TM14 from the PC.

Toss all HM03 and withdraw 188 HM03 from the PC (it takes time!).

Place the following items, in that order, in your pack:
Any item x(any quantity)
8F (4F or wsl'm in Yellow)
Thunderstone x157 in english R/B (x156 in english Yellow, x162 in non-english R/B, x161 in non-english Yellow)
TM18 x4
Max Revive x69
X Accuracy x172 in english R/B (x171 in english Yellow, x177 in non-english R/B, x176 in non-english Yellow)
Lemonade x195
Water Stone x12
TM14 x168
Ice Heal x34
HM03 x188
Soda Pop x119
TM01 x(any quantity)

Use the 8F (4F or wsl'm in Yellow) item.

Withdraw and trade the first two Pokémon in your active box to your G/S game: both will hold a Mystery Egg. They must NEVER win any battle, or you won't be able to use them anymore.

ANNEX 1.3: Use Mystery Eggs to get TM25

Take both Mystery Eggs and place them in the Key Items Pocket so that they are the last items in the Pocket (do not swap them together).
NOTE: For this trick to work, the Key Items Pocket must be full. If you don't have enough Key Items, you can clone one or both Pokémon before taking the Egg, to get more Eggs in order to fill the Pocket.

Now, swap the first Mystery Egg with the second Mystery Egg (order is important). A S.S. Ticket will appear.

Move to the Balls Pocket. The Great Ball x1 and Poké Ball x2 should have turned into a Master Ball x5 and Ultra Ball x255 respectively (255 is indicated by a [tile]5).

Toss 39 Ultra Balls from the Ultra Ball x255 stack.

Swap the Master Ball x5 with the Ultra Ball x216.

Deposit the Mystery Egg in the Player's PC.

Withdraw the Mystery Egg from the Player's PC. In the Balls Pocket, the Ultra Ball x216 and Master Ball x5 should now have turned into a TM25 x1 and Poké Ball x255.

Store 255 (all) from the Poké Ball x255 stack in the Player's PC.

ANNEX 1.4: Prepare the Party setup

Place the Pokémon that was FIRST in the R/B/Y's PC box at slot 2 of your party everytime you need to execute item codes during 'VI. WRITE AND EXECUTE A CODE' (instead of the Quagsire with SLEEP TALK and Protein), and place the Pokémon that was SECOND in the R/B/Y's PC box at slot 2 of your party everytime you need to execute box codes during 'VI. WRITE AND EXECUTE A CODE' (instead of the Quagsire with RETURN and TM02). In both cases, you won't need any 'Slide Pokémon' in slot 1.

Use TM25 from the Balls Pocket everytime you need to execute codes during 'VI. WRITE AND EXECUTE A CODE' (instead of TM17).

ANNEX 2: GET MYSTERY EGGS USING THE MACHOP TECHNIQUE

This method will NOT work if your Trainer ID is superior to 65280 or is equal to 255 modulo 256 (which means 511, 767, 1023, etc.). It requires:
- A Machop with Seismic Toss as first move (stored in the PC).
- 5 clones of a Pokémon obtained by trading with an NPC that has never been trained before. If this is impossible to you, use clones of any caught Pokémon that has never been trained before, but note that there is 3% chance it won't work.
- At least $200.

Go to the Daycare, south of Goldenrod, and clone Bellsprout once again. However this time, the cloning must be performed in the 15 Pokémon aforementioned box and you must have reset your game right after saying 'YES' to the question about save replacement. If it worked, the obtained clone will be level 0, won't have a name (or many "?" as name in Crystal), and its Pokédex ID (in the profile) also is 000; this is what we call a Bad Clone. If you got a normal clone, release it and try again.
NOTE: In G/S, any clone without name/level but also without the Pokédex ID 000 won't work (treat it as a normal clone). However, if you get such clone in Crystal, it is worth noting that you can convert it into a Bad Clone that can be used for this method. To do this, store the Bad Clone in another PC Box and store 5 other Pokémon in that same box. Then, use the withdraw option to display that box. Leave it and use the withdraw option again. All Pokémon are now Kingdra. Withdraw the Bad Clone and you can now use it (in case of trouble with getting the Kingdra, please read this).

Make a party of the Bad Clone and the 5 clones.

Give the Bad Clone to the Daycare lady and immediately take it back. It will now be a Glitch Pokémon with n°000.

Put the glitch Pokémon n°000 in front at the top of your party, and go to Bill's PC.

Choose 'MOVE PKMN W/O MAIL' and it will seem like your party is empty. Thanks to this, you can move the Machop at first slot (therefore you now have 7 Pokémon).

Exit the PC and give the glitch Pokémon n°000 to the Daycare lady again. Don't take it back this time.
NOTE: It is also possible to move it at slot 7 instead, and give it to the lady only after finishing this step.

Go back to Bill's PC and store Machop. It will now have a Mystery Egg attached.

Before taking the Egg from it, clone this Pokémon once (twice if wanting three Eggs), then take the 2 or 3 Mystery Eggs.
NOTE: I recommend you do a backup clone also, in case you need other Eggs.

GENERAL CONCLUSION

Alright, I'mma stop here with this guide for now. If you're kinda lost, remember this:


I know I have to add some colours and more BBCodes, but please mention me any improvement, any mistake, any thread that gives more interesting codes, and don't hesitate to ask questions!

Re: The newcomer and experienced user's guide to G/S Arbitrary Code Execution!

Posted by: Couldntthinkofaname
Date: 2017-10-30 14:21:58
Wow, this is incredibly detailed! Nice work!

Re: The newcomer and experienced user's guide to G/S Arbitrary Code Execution!

Posted by: Krys3000
Date: 2017-10-30 14:33:27
Thanks! :)

Re: The newcomer and experienced user's guide to G/S Arbitrary Code Execution!

Posted by: Couldntthinkofaname
Date: 2017-10-30 14:45:50
Your encounter code seems a little complex, however. It seems to require multiple uses of TM 25. I wrote a wild encounter box name code that only requires one use of of TM 25, and it's only 9 boxes long. It can be found here.

And as a plus, the found Pokemon is shiny.

Re: The newcomer and experienced user's guide to G/S Arbitrary Code Execution!

Posted by: Krys3000
Date: 2017-10-30 15:37:49
Thanks! I'll add this code asap, that's very cool. I also must add this as a more easy-to-handle list http://pastebin.com/raw/arPmsvYu , a way to make guarantee the expanded balls pocket trick and links to code threads from this board.

Re: The newcomer and experienced user's guide to G/S Arbitrary Code Execution!

Posted by: spamviech
Date: 2017-10-31 03:19:47

IV.1: GET TM17 IN THE WRONG POCKET (Box)

NOTE: Of course, this code is destined to Coin Case users willing to have TM17 on the Item Pocket to shift on Wrong Pocket TM ACE (the code is from Crystal_'s video linked in chapter II). But it could also be used with Wrong Pocket TM ACE, just for fun.

Make that the first item in your Item Pocket is disposable, as it will be replaced by TM17.

Go to Bill's PC and use the CHANGE BOX option to rename Box 1 to 5 into as follows:
Ap0'déyPk (Pk is an available symbol, not "P followed by k")
'v't'véé'l2h
'd'd2'v9.9't
é?2hhhhh
h'm


Didn't really check, but doesn't this code contain a part for fixing the stack from Coin Case?
Therefore it will probably crash the game when executed via wrong pocket TM ACE. The same is true vice versa for wrong pocket codes executed via coin case ACE.

Oh and btw. all box name codes probably won't work for german language games since we don't have the é character available as an input character (same for 'v, but you can work around that one).

Anyway, great work on this compilation.  :)


Thanks! I'll add this code asap, that's very cool. I also must add this as a more easy-to-handle list http://pastebin.com/raw/arPmsvYu , a way to make guarantee the expanded balls pocket trick and links to code threads from this board.

You need to add Pk- and Mn-Symbols missing in the list (e1 & e2).

Re: The newcomer and experienced user's guide to G/S Arbitrary Code Execution!

Posted by: Krys3000
Date: 2017-10-31 16:43:18
You're probably right indeed! Thanks I'll change things asap :)

Re: The newcomer and experienced user's guide to G/S Arbitrary Code Execution!

Posted by: Krys3000
Date: 2017-11-03 16:30:56
The guide was a bit modified with all the informations that you all gave to me. Many thanks!

I would like to understand more about adapting Wrong Pocket TM ACE codes to Coin Case variants, so I can add both for each categories.

Of course, I don't want to link all codes from the main thread but I will add links to some code threads to the guide :)

Re: The newcomer and experienced user's guide to G/S Arbitrary Code Execution!

Posted by: Torchickens
Date: 2017-11-03 17:04:27

The guide was a bit modified with all the informations that you all gave to me. Many thanks!

I would like to understand more about adapting Wrong Pocket TM ACE codes to Coin Case variants, so I can add both for each categories.

Of course, I don't want to link all codes from the main thread but I will add links to some code threads to the guide :)


Basically with Coin Case arbitrary code execution you have to fix the stack. The stack can be fixed to a degree with the help of two pop des, followed by an inc sp, followed by pop de (in that order. I think the order you do this matters if I remember rightly), and you also should set FF83 (a zero page address) to 0. Only after you do that, you can terminate the code with "or a" (to ensure the carry flag is not set) and a "ret nc".

To avoid a laggy menu you can also set address D199 (or its Echo RAM equivalent F199) to 00. However you don't need to do this and you can also avoid the lag by setting Menu Account to Off in the options.

FMK's "one-off code" ensures that the last two boxes (box 13 and box 14) have code that will both 'fix' the stack and return control to the game, hence you can make simpler codes followed by 5s (filler code) until box 13 and box 14.

With wrong pocket TM execution (and glitch Pokédex mode ACE) you don't have to fix the stack, so you can terminate with the or a and ret nc as usual. Furthermore they can be used anywhere without having to make any overworld movement or listen to Bellsprout/Machop etc.'s cry.

Re: The newcomer and experienced user's guide to G/S Arbitrary Code Execution!

Posted by: Krys3000
Date: 2017-11-03 17:11:23
Thank you Torchickens! I should be able to provide equivalents for each code now. If you have any other comment to make to this guide, don't hesitate to. It's meant to be the most accurate and user-friendly so it can be visible and a proper introduction to ACE :)

Re: The newcomer and experienced user's guide to G/S Arbitrary Code Execution!

Posted by: Torchickens
Date: 2017-11-03 17:13:18

Thank you Torchickens! I should be able to provide equivalents for each code now. If you have any other comment to make to this guide, don't hesitate to. It's meant to be the most accurate and user-friendly so it can be visible and a proper introduction to ACE :)


Pleasure! ^^

Good luck and have fun and I'll keep that in mind!

Re: The newcomer and experienced user's guide to G/S Arbitrary Code Execution!

Posted by: spamviech
Date: 2017-11-03 17:55:10
It's possible to replace the (not representable by an available character) INC SP with a ADD SP, ff followed by an additional POP DE (as pointed out by ISSOtm here).

It also turns out that you don't have to set ff83 to 0 when setting f199 to 0.

So the only adjustment you have to make from a wrong-pocket TM code to a Coin Case one is replace the final x'd with
péZ.9'l'l'l'lx'd

You have to keep the "péZ", the ".9" and the "x'd" (obviously has to be at the end) together. If you have space problems in my experience it is no problem to space it out in the code (replace some filler 5s).

Re: The newcomer and experienced user's guide to G/S Arbitrary Code Execution!

Posted by: Krys3000
Date: 2017-11-05 06:05:21
Thanks!

I assume the job is the same with items? I'll add the variants for each code.

Re: The newcomer and experienced user's guide to G/S Arbitrary Code Execution!

Posted by: Couldntthinkofaname
Date: 2017-11-05 08:39:32

Thanks!

I assume the job is the same with items? I'll add the variants for each code.


With item codes, most developers simply use:

Inc sp
Ld bc,0134
Push bc
Jp 12f5


What this effectively does is trick the game into reading the end-terminator $50, which fixes the stack on it's own.

Re: The newcomer and experienced user's guide to G/S Arbitrary Code Execution!

Posted by: Krys3000
Date: 2017-11-05 12:34:11
I've added as an option to item codes, before TM10 (ret) a list of items which matches the opcodes you gave me, Couldntthinkofaname:
X Defense x1
X Speed + x1
TM06 x195
HM03 x18

Thanks! This makes easier to understand why everyone should focus on TM ACE imo  :P

Regarding the OAM DMA Hijacking, I'm unsure whether we can replace 2'd with péZ.9'l'l'l'lx'd or péZ.9'l'l'l'l2'd.