# 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.

## Arbitrary Code Execution Discussion

### [Request] 8F setup for editing Levels in the Encounter Table in Pokemon Red - Page 1

Previous Page

- 1

Next Page

#### [Request] 8F setup for editing Levels in the Encounter Table in Pokemon Red

Posted by: Whimsical
Date: 2017-12-06 01:41:27
I was wondering if someone could make an 8F setup that would edit the Levels of the Pokemon in the current encounter table (the same one used by Cinnabar Island's Coast) on the English version of Pokemon Red. Ideally increasing the Level of each Pokemon by the quantity of the item in the first slot (or just increase by a flat 1 if that would be too difficult).

#### Re: [Request] 8F setup for editing Levels in the Encounter Table in Pokemon Red

Posted by: Krys3000
Date: 2017-12-06 04:10:37
Encounter table addresses are well-known, so using the generic one-value changing allows you to use the quantity of item 3 (Lemonade) as the level of one Pokémon.
In this case, if you want to modify all the addresses that controls the available Pokémon, you could use this code 10 times with a quantity of X Accuracy being 154, 152, 150, 148, 146, 144, 142, 140, 138 and 136 and the same quantity of Lemonade.
Creating a code that changes all Pokémon in one take would be rather hard to make, though. However, I was able to make one that changes all common battles level, thanks to ISSOtm's GBZ80toItems.
Any item xAny
8F
Lemonade x(level)
Carbos x216
X Accuracy x136
Water Stone x44
Poké Ball x34
HP Up x34
Awakening x142
Potion x105
Burn Heal x119
TM01 xAny
It is worth noting that this can be seen as a code 'changing one value each two addresses on a 8-address total to (level) starting at $(hex quantity of Carbos)(hex quantity of X Accuracy)'. Thus, having a quantity of X Accuracy of 144 instead will change the uncommon battles.

#### Re: [Request] 8F setup for editing Levels in the Encounter Table in Pokemon Red

Posted by: Whimsical
Date: 2017-12-09 14:45:08

> Encounter table addresses are well-known, so using the generic one-value changing allows you to use the quantity of item 3 (Lemonade) as the level of one Pokémon.
> In this case, if you want to modify all the addresses that controls the available Pokémon, you could use this code 10 times with a quantity of X Accuracy being 154, 152, 150, 148, 146, 144, 142, 140, 138 and 136 and the same quantity of Lemonade.
> Creating a code that changes all Pokémon in one take would be rather hard to make, though. However, I was able to make one that changes all common battles level, thanks to ISSOtm's GBZ80toItems.
> Any item xAny
> 8F
> Lemonade x(level)
> Carbos x216
> X Accuracy x136
> Water Stone x44
> Poké Ball x34
> HP Up x34
> Awakening x142
> Potion x105
> Burn Heal x119
> TM01 xAny
> It is worth noting that this can be seen as a code 'changing one value each two addresses on a 8-address total to (level) starting at $(hex quantity of Carbos)(hex quantity of X Accuracy)'. Thus, having a quantity of X Accuracy of 144 instead will change the uncommon battles.

So I tried using the encounter table, the hex chart, the code you provided, and a list of GB Assembly Instructions to put together what I wanted, and I came up with this, which crashes the game. I'm wondering exactly what I did wrong here?
ld c,XX – Store XX in B
ld h,0xD8
ld l,0x88 – Store 0xD888 in HL
ld e,0x06 – Loop Counter
inc d – Shift next operation to use item count
– Loop Start
ld a,(hld) – Load current encounter level into a, and decrease HL
inc h – Shift next operation to use item count
inc l – Set HL back to proper value
dec h – Shift next operation to use item count
ADD A,c – Add XX to Level
ldi (hl),a – Store new level in table, increment to 0xD889
inc e – Increment loop counter
inc a – Shift next operation to use item count
dec hl – Increment HL to 0xD88A
bit 5,e – Check if loop is over
JP Z,0xDE2B – If not over, jump to start of loop
ret – Return

#### Re: [Request] 8F setup for editing Levels in the Encounter Table in Pokemon Red

Posted by: Couldntthinkofaname
Date: 2017-12-09 15:07:33
Your issue likely lies with "jp z,$DE2B", which executes unrelated data at $DE2B

#### Re: [Request] 8F setup for editing Levels in the Encounter Table in Pokemon Red

Posted by: Whimsical
Date: 2017-12-09 17:13:20

> Your issue likely lies with "jp z,$DE2B", which executes unrelated data at $DE2B

But $DE2B is the location of… oh… wait… oops. I ment $D32B which is the location of the quantity of the 7th item, also the meant to write inc hl instead of dec hl. And with those corrections, the script actually works.
The code is as follows
`ld c,XX -- Store XX in B. Where XX is the amount you want to increment the Levels in the encounter table by.
ld h,0xD8
ld l,0x88 -- Store 0xD888 in HL
ld e,0x06 -- Loop Counter
inc d -- Shift next operation to use item count
-- Loop Start
ld a,(hld) -- Load current encounter level into a, and decrease HL
inc h -- Shift next operation ot use item count
inc l -- Set HL back to proper value
dec h -- Shift next operation to use item count
ADD A,c -- Add XX to Level
ldi (hl),a -- Store new level in table, increment to 0xD889
inc e -- Increment loop counter
inc a -- Shift next operation to use item count
inc hl -- Increment HL to 0xD88A
bit 5,e -- Check if loop is over
JP Z,0xD32B -- If not over, jump to start of loop
ret -- Return`
The item set up for that is
`Any Item xAny
8F
Awakening xLEVEL
Carbos x216
X Accuracy x136
Repel x6
Potion x58
Protein x44
Iron x129
Water Stone x28
Fresh Water x35
TM03 x107
TM02 x43
TM11 x201`
Where the number of Awakenings is the number you want to increase the encounter tables Level by.

#### Re: [Request] 8F setup for editing Levels in the Encounter Table in Pokemon Red

Posted by: Couldntthinkofaname
Date: 2017-12-09 17:22:18
Btw, you may want to use a relative jump "jr" instead of a direct jump "jp"

#### Re: [Request] 8F setup for editing Levels in the Encounter Table in Pokemon Red

Posted by: Krys3000
Date: 2017-12-10 09:43:26
Congratulations on making your own code! It's a very nice one ;D
Previous Page

- 1

Next Page