Skeetendo

’Cause all games were better on the GBC

You are not logged in.

#1 2010-12-19 19:42:57

EvilOttoJr
Member
Registered: 2010-12-05
Post 17/86

Shiny Pokemon in Gold

What in the ROM governs the odds of this, and can it be changed?

I know there's a 1 in approximately 8000 chance of running into Pokemon this way. I want to change it so that there's more like a 1 in 100 chance of it, because I'm redoing most of the sprite palettes so Shinies look better (e.g. the Charizard shiny looks the same way it does in the later Pokemon (haha Jokemon) games). I still want them to be rare, just not impossible to get a hold of.

Also, is there a way to put it into Pokemon events such as like the Red Gyarados has? I was thinking of making some of the legendary scripts in the hack have permanent Shiny Pokemon (such as the Mew or Celebi script).

Offline

#2 2010-12-19 20:53:10

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 345/3,578

Re: Shiny Pokemon in Gold

I don't know how to change it so they are more common in the wild, but for event pokemon it's easy to make them be shiny like the red gyrados. When you put the byte in the their script for which type of fight it is, one of them is for a shiny battle. It's detailed in the compendium when you go to "application example" (or somethign like that) when you are looking at the load pokemon data and starting a battle commands.

Offline

#3 2010-12-19 22:37:15

68/703

Re: Shiny Pokemon in Gold

The odds of a Pokémon being shiny are exactly 1⁄8192. Shiny Pokémon have Defense, Speed, and Special IVs of 0xA and an attack IV where bit 1 is set. (In other words, the Attack IV can be any of 2, 3, 6, 7, 10, 11, 14 or 15.)

Event Pokémon are easy to make shiny by reusing the Red Gyarados configuration, but these battles are also impossible to run away from. This is probably not a bad thing, just something to be aware of. The Red Gyarados has an attack IV of 14.

To determine if a Pokémon is shiny, the game calls 02:5052 and checks the carry flag.

CheckShininess: ; 02:5052
; given a pointer to Attack/Defense DV in bc, determine if monster is shiny or not
; if shiny, set carry
    ld l,c
    ld h,b
    ld a,[hl]
    and a,%00100000 ; is attack DV xx1x?
    jr z,.NotShiny\@
    ld a,[hli]
    and a,$F
    cp $A ; is defense DV 1010?
    jr nz,.NotShiny\@
    ld a,[hl]
    and a,$F0
    cp $A0 ; is speed DV 1010?
    jr nz,.NotShiny\@
    ld a,[hl]
    and a,$F
    cp $A ; is special DV 1010?
    jr nz,.NotShiny\@
    scf
    ret
.NotShiny
    and a ; clear carry flag
    ret

This code is pretty straightforward to edit if you want to make shinies more common.

#4 2010-12-20 03:26:54

EvilOttoJr
Member
Registered: 2010-12-05
Post 18/86

Re: Shiny Pokemon in Gold

Damn... I REALLY need to learn ASM, it's required even for really simple stuff it seems.

Thanks for the help though, I can refer to this if I can learn ASM.

Last edited by EvilOttoJr (2010-12-20 03:27:27)

Offline

#5 2010-12-20 04:30:35

71/703

Re: Shiny Pokemon in Gold

This is a good block of ASM to learn from, as it's very simple. It's at offset 0x9052 in the ROM, and looks like this with the hex equivalents:

ld l,c ; 69
    ld h,b ; 60
    ld a,[hl] ; 7E
    and a,$20 ; E6 20
    jr z,+$17 ; 28 17
    ld a,[hli] ; 2A
    and a,$F ; E6 0F
    cp $A ; FE 0A
    jr nz,+$10 ; 20 10
    ld a,[hl] ; 7E
    and a,$F0 ; E6 F0
    cp $A0 ; FE A0
    jr nz,+$9 ; 20 09
    ld a,[hl] ; 7E
    and a,$F ; E6 0F
    cp $A ; FE 0A
    jr nz,+$2 ; 20 02
    scf ; 37
    ret ; C9
    and a ; A7
    ret ; C9

Let's take this a step at a time. You have registers that can each contain a value from $00 to $FF: a, b, c, d, h, l. You can pair up bc and hl to effectively have values from $0000 to $FFFF.

ld l,c ; 69
ld h,b ; 60

This copies bc to hl. Since bc had a pointer to the Pokémon's DVs, now hl has the pointer as well.

ld a,[hl] ; 7E

Take the value referenced by a pointer in hl, and store in the register a. Now a contains the Attack/Defense DV. (If you don't know what a DV is: it's a random value, from 0 to 15, that affects the stats of a Pokémon. Higher DVs mean better stats. So $FEDC means an Attack DV of 15, a Defense DV of 14, a Speed DV of 13, and a Special Attack/Special Defense DV of 12.)

and a,$20 ; E6 20

Convert a and $20 to binary, then perform a logical "and" of the two values, then store the result back into a. $20 in binary is %00100000. If both input bits are 1, the resulting bit is 1; otherwise, the resulting bit is 0. So if a contains $FF (%11111111):

11111111
00100000
00100000

The result is %00100000, or $20. But if a contains $12 (%00010010):

00010010
00100000
00000000

The result is %00000000 because none of the bits match.

jr z,+$17 ; 28 17

If the result of the last instruction was 0, jump forward $17 bytes. Otherwise, keep going.

This is here because if the last and resulted in zero, the Attack DV had a pattern of xx0x instead of xx1x. That means it can't be a shiny Pokémon, so we jump to the "not shiny" code.

ld a,[hli] ; 2A

Since we overwrote a with the result of the last and, this reloads a with the Attack/Defense DV again. The "i" means that hl is incremented afterwards, so after this it points to the Speed/Special DV instead of the Attack/Defense DV.

and a,$F ; E6 0F

We know what this does: it does a logical "and" between a and the number $F (%00001111). This makes the upper four bits zero, so the next instruction will only need to worry about the Defense DV.

cp $A ; FE 0A

Cp stands for "compare." It subtracts $A from the value in a and throws away the result. It does this for the next conditional instruction:

jr nz,+$10 ; 20 10

If the result of the last instruction was not zero, then move forward $10 bytes. Just like last time, this means that if the Defense DV isn't 10 ($A), it's not a shiny Pokémon, so we jump to the "not shiny" code.

ld a,[hl] ; 7E

Since we incremented hl last time, this loads a with the Speed/Special DV.

and a,$F0 ; E6 F0

Restrict ourselves to the Speed DV.

cp $A0 ; FE A0
jr nz,+$9 ; 20 09

Does the Speed DV equal $A? If not, jump to the "not shiny" code.

ld a,[hl] ; 7E
and a,$F ; E6 0F

Reload a with the Speed/Special DV, and cut out the Speed part so we only have the Special DV.

cp $A ; FE 0A
jr nz,+$2 ; 20 02

I think you know what this does by now.

scf ; 37
ret ; C9

If the code has made it this far without jumping elsewhere, we know it has to be shiny because its DVs follow the right pattern. So we turn on the carry flag and end the function.

and a ; A7
ret ; C9

This is the "not shiny" code. It so happens that the "and" instruction always turns off the carry flag, so that's what the "and a" is for.


That's how this function works. Anytime a different block of code needs to know if a monster is shiny, it loads bc with the pointer to the DVs, calls this function, and checks the carry flag. If the carry is 1, it's shiny! If the carry is 0, it's not.

To make shiny Pokémon easier to find, we can change the compares. For instance, here is a revised function that reduces the odds to 1⁄256 (any Pokémon with Attack/Defense IVs of 15/15 is shiny):

ld l,c
ld h,b
ld a,[hl]
cp $FF
jr nz,.NotShiny\@
scf
ret
.NotShiny
and a
ret

Here is code that makes all Pokémon shiny:

scf
ret

Here is code that makes shinies rarer (1⁄65536 odds: DVs have to be 10/10/10/10).

ld l,c
    ld h,b
    ld a,[hl]
    cp $AA
    jr nz,.NotShiny\@
    ld a,[hli]
    cp $AA
    jr nz,.NotShiny\@
    scf
    ret
.NotShiny
    and a ; clear carry flag
    ret

Last edited by IIMarckus (2011-09-18 03:42:14)

#6 2010-12-21 18:39:33

EvilOttoJr
Member
Registered: 2010-12-05
Post 19/86

Re: Shiny Pokemon in Gold

Wow, that is INCREDIBLY helpful! :) That's actually not too difficult to understand... hmm, this may be easier than I thought. Thanks!

EDIT: WAIT!!! If I were to change it to like the 1/256 script, would it change like the Red Gyarados script or anything so it might not be shiny? Or does the CallShinyBattle script still work even if I change the ShinyCheck script?

Last edited by EvilOttoJr (2010-12-21 19:13:17)

Offline

#7 2010-12-21 19:25:00

75/703

Re: Shiny Pokemon in Gold

EvilOttoJr wrote:

Wow, that is INCREDIBLY helpful! :) That's actually not too difficult to understand... hmm, this may be easier than I thought. Thanks!

EDIT: WAIT!!! If I were to change it to like the 1/256 script, would it change like the Red Gyarados script or anything so it might not be shiny? Or does the CallShinyBattle script still work even if I change the ShinyCheck script?

The Red Gyarados script doesn't force shininess, it forces DVs of 14/10/10/10. If this pattern matches your new shiny restrictions, the Pokémon obtained through the event will be shiny.

The 1⁄256 code I wrote won't make 14/10/10/10 shiny, but it can be trivially changed to do so and still keep the same odds. Just replace the compare to $FF (15/15) with a compare to $EA (14/10).

#8 2010-12-24 20:03:05

EvilOttoJr
Member
Registered: 2010-12-05
Post 24/86

Re: Shiny Pokemon in Gold

At what offset can I find the force DV script, and what do I need to change to make it match the code you wrote? Is it similar in structure to this code? I want to change it so it will go with your current code, because presently, Shiny Pokemon can never have DVs of 15 and thus never max stats, whereas the 1/256 code you wrote allows for it.

Offline

#9 2010-12-24 23:31:45

81/703

Re: Shiny Pokemon in Gold

EvilOttoJr wrote:

At what offset can I find the force DV script, and what do I need to change to make it match the code you wrote? Is it similar in structure to this code? I want to change it so it will go with your current code, because presently, Shiny Pokemon can never have DVs of 15 and thus never max stats, whereas the 1/256 code you wrote allows for it.

I oversimplified a bit. The Red Gyarados script actually sets the "battle type" (memory address D119; see "Application Example" for 5E in Tauwasser's doc) to 07. Then when a Pokémon appears (or is sent out), the game checks if the battle type is 07:

; 0F:67EE
; if battle type is 07, make shiny
cp a,$07
jr nz,.next\@
ld b,$EA
ld c,$AA
jr .SetDVs\@
…
; 0F:6800
; set DVs of active enemy Pokémon
.SetDVs
ld hl,$D0F5 ; address of active enemy Pokémon's Attack/Defense DV
ld a,b
ld [hli],a
ld [hl],c

Change the values here to change the DVs of the Red Gyarados.

#10 2010-12-25 00:05:39

EvilOttoJr
Member
Registered: 2010-12-05
Post 27/86

Re: Shiny Pokemon in Gold

Okay, sorry, I got lost again. I'm not getting the ASM notation.

Last edited by EvilOttoJr (2010-12-25 00:06:14)

Offline

#11 2010-12-25 00:29:04

82/703

Re: Shiny Pokemon in Gold

The code stats at offset 0x3E7EE. At this point, a contains the battle type, while b and c contain randomly-generated DVs for the Pokémon.

cp a,$07 ; FE 07
jr nz,+6 ; 20 06

Subtract 7 from a. If the result is not zero, skip the next 6 bytes.

ld b,$EA ; 06 EA
ld c,$AA ; 0E AA

If this code is being run, this is the Red Gyarados event, so replace the DVs in b and c with $EAAA.

jr +8 ; 18 08

Skip the portion of the code that's for non-shiny Pokémon, and pick up eight bytes later.

ld hl,$D0F5 ; 21 F5 D0

Load hl with the pointer to the Pokémon's DVs.

ld a,b
ld [hli],a

Copy the Attack/Defense DV to a, store it at the pointer, and increment the pointer (so now hl points to the Speed/Special DV).

ld [hl],c

Load the Speed/Special DV.

#12 2010-12-26 20:16:09

EvilOttoJr
Member
Registered: 2010-12-05
Post 28/86

Re: Shiny Pokemon in Gold

Oh, I get it! And so if I wanted to change it so Red Gyarados or whatever's using the script had max DVs in line with the 1/256 shiny script you wrote, I could just change the EA AA with like FF AA or even FF FF for completely max stats? I think I'll do that, it'd be cool to have Red Gyarados/any standing shiny to have completely max DVs. Thanks, I think I might be starting to get this a bit better now.

Offline

#13 2010-12-30 00:04:10

EvilOttoJr
Member
Registered: 2010-12-05
Post 31/86

Re: Shiny Pokemon in Gold

Okay, I tested myself a bit, but I need graded before I attempt to put this into my game.
I converted the 1/256 shiny script into hex. Is this right?

ld l,c - 69
ld h,b - 60
ld a,[hl] - 7e
cp $FF - FE FF
jr nz,.NotShiny\@ - 28 17
scf - 37
ret - C9
.NotShiny - 17
and a - A7
ret - C9

Offline

#14 2010-12-30 00:34:11

93/703

Re: Shiny Pokemon in Gold

For reference, here is a list of opcodes and their ASM equivalents.

jr nz is 20, not 28.

Your understanding of jr is wrong. The argument is a number of bytes to skip (technically, a two’s complement, which means it can be negative). .NotShiny is not an assembler opcode, just a label—one that doesn’t actually exist in the ROM. It’s there as notation so we don’t have to count bytes all the time.

The correct code looks like this:

ld l,c ; 69
ld h,b ; 60
ld a,[hl] ; 7E
cp $FF ; FE FF
jr nz,+2 ; 20 02
scf ; 37
ret ; C9
and a ; A7
ret ; C9

#15 2010-12-30 00:57:54

EvilOttoJr
Member
Registered: 2010-12-05
Post 32/86

Re: Shiny Pokemon in Gold

Ok, thank you! That opcode list is really going to help me out. Are there other docs that will add to my understanding? I've got that now, and Tauwasser's Scripting Compendium.

EDIT: I put the code in the game, it works. Ran around south of Goldenrod City, used VBA with Speed, got into over 150 Pokemon battles in 3 minutes and caught a Shiny Drowzee. Red Gyarados stopped being red, so I changed the Red Gyarados script to force DVs of 15/15/15/15 and he's shiny now. Thank you for all you help, and maybe soon I won't have to ask everyone "how the heck do I do this?"

Last edited by EvilOttoJr (2010-12-30 01:17:34)

Offline

#17 2012-04-15 11:50:01

ReadCutting-T
Member
Registered: 2012-04-12
Post 18/20

Re: Shiny Pokemon in Gold

Thanks for this, although its over a year old now, these kind of examples really help with me learning asm

Offline

#18 2012-07-28 11:25:52

Akwa
Member
Registered: 2012-06-14
Post 26/140

Re: Shiny Pokemon in Gold

I began learning ASM and thanks to IIMarckus explanation, I am actually starting to understand a bit.

I want to change the chance of Pokemon being shiny so every DV must be at least 12 - (1/4)^4 = 1/256 chance

$CC = %11001100
So this is my script:

ld l,c ; 69
    ld h,b ; 60
    ld a,[hli] ; 2A
    and a,$CC ; E6 CC
    cp $CC ; FE CC
    jr nz,+$09 ; 20 09
    ld a,[hl] ; 7E
    and a,$CC ; E6 CC
    cp $CC ; FE CC
    jr nz,+$02 ; 20 02
    scf ; 37
    ret ; C9
    and a ; A7
    ret ; C9

I suppose everything is good here?

Last edited by Akwa (2012-07-28 11:47:58)

Offline

#19 2012-07-28 14:50:15

494/703

Re: Shiny Pokemon in Gold

Akwa wrote:

I began learning ASM and thanks to IIMarckus explanation, I am actually starting to understand a bit.

I want to change the chance of Pokemon being shiny so every DV must be at least 12 - (1/4)^4 = 1/256 chance

So some example shiny DVs would be:

  • $CCCC

  • $CCDD

  • $FFFF

and some non‐shiny DVs would be:

  • $CC00

  • $0000

Did I interpret that correctly?

Akwa wrote:

$CC = %11001100
So this is my script:

and a,$CC ; E6 CC
cp $CC ; FE CC
jr nz,+$09 ; 20 09
ld a,[hl] ; 7E
and a,$CC ; E6 CC
cp $CC ; FE CC
jr nz,+$02 ; 20 02
scf ; 37
ret ; C9
and a ; A7
ret ; C9

I suppose everything is good here?

This looks okay to me. Good job.

#20 2012-07-29 10:16:10

Akwa
Member
Registered: 2012-06-14
Post 27/140

Re: Shiny Pokemon in Gold

Yes, you got it right.

There's a small issue now - the pkmn Trainer Cal's (from Viridan battle club) pokemon all are shiny. I guess all of his pokemon DVs are $FFFF (it also proves my asm script is working well).

How to change that? I guess some ASM script changes DV values in RAM depending on trainer type.

Offline

#21 2012-08-10 15:54:29

PixelEye
Member
From: Philippines
Registered: 2012-08-02
Post 30/162
Website

Re: Shiny Pokemon in Gold

Mates, can you make a patch for this, i'm making a simple hack so i cant make this one..maybe in the future i'll try to understand this. ASM is hard to understand. Givi'n me headaches.
Thanks in advance.

Cheers.


LIKE US on Facebook!
---
Berries Inc.,Corp. Graphical Resource
---
I'M BACK, BUT MY WORKS BEEN ACCIDENTALLY DELETED ON MY PHONE(INCLUDING MY HACK THAT I'M DOING AND GEN 5 SPRITES AND TILESETS). SO THE SOLUTION WILL BE REVISING MY WORKS FROM 0 TO 456.

CHEERS.

Offline

#22 2012-11-04 01:28:06

comet
Member
Registered: 2012-04-09
Post 24/679

Re: Shiny Pokemon in Gold

and a, $ff is pointless since a is already 8 bits. You also need to increment hl and load the next dv.

kkj1116 wrote:

I also want to make shininess impossible, but there is no "reset carry flag" instruction

and a (ands a by itself which resets the carry flag) is already in your function. A lengthier solution is to complement carry (ccf) after setting it with scf (this leaves the z flag unaffected unlike with and a).

To make shininess impossible, just replace the function with

and a
ret

Last edited by comet (2012-11-04 01:29:27)

Offline

#23 2012-11-04 03:24:11

546/703

Re: Shiny Pokemon in Gold

kkj1116 wrote:

What program(s) do you use to paste your code onto here? Or do you type them out by hand?

Some people use RGBDS syntax (this is usable in the disassemblies we’ve been working on). Some people use BGB syntax.

#24 2012-11-25 18:24:45

Crystal_
Member
From: Spain
Registered: 2012-09-16
Post 22/450
Website

Re: Shiny Pokemon in Gold

If I wanted to do so that for a pokemon to be shiny it has to have atk and def IVs of 13 and an odd spc IV, will this work well?

ld l,c ; 69
    ld h,b ; 60
    ld a,[hl] ; 7E
    and a,$F0 ; E6 F0
    cp $D0 ; FE D0
    jr nz,+$E ; 20 0E
    ld a,[hli] ; 2A
    and a,$F ; E6 0F
    cp $D ; FE 0D
    jr nz,+$7 ; 20 07
    ld a,[hl] ; 7E
    and a,$1 ; E6 01
    jr z,+$2 ; 28 02
    scf ; 37
    ret ; C9
    and a ; A7
    ret ; C9

then fill the remaining bytes with 00s

I really only care about the hex numbers tbh, as I'm just going to modify it with a hex editor right away.

EDIT: nvm it works.

Last edited by Crystal_ (2012-11-30 13:57:55)

Offline

#25 2012-12-31 02:21:48

emaj30
Member
From: Indigo Plateau
Registered: 2012-12-29
Post 15/463
Website

Re: Shiny Pokemon in Gold

w0w!this thread nearly blew my head just by reading it!its very useful for exploiting shiny thingy of the game,though having an average DV wouldnt be that great i think?am i right?i think setting a pokemon event with maxed out DV's would be more interesting?like adding mewtwo event or setting for ho-oh or lugia?

Offline

Board footer

Powered by FluxBB