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.

Emulation & ROM Hacking

Anyone with a knowledge of hex help me out? - Page 1

Anyone with a knowledge of hex help me out?

Posted by: greentyphlosion
Date: 2019-08-14 06:23:02
Apologies if this is in the wrong thread, etc.

I've just got my hands on an Xploder cartridge which I've been using on various games. I have a working shiny code for Pokemon Emerald which is great (especially as I have a Max IV code that works in conjunction with it) but for some reason every Pokemon I catch has a Lonely nature. Unfortunately while I've a little experience with Hex I'm unable to discern what part of the code exactly is fixing the Natures. Can anyone assist?

Codes below:

(m)
928817F0298A
BBC1B6B105C4
B84FBA534945

(Shiny code)
1130CB63CD01
3004FB634D27
118263F709DD
56FC0D142272
D9A856E44D4C

Re: Anyone with a knowledge of hex help me out?

Posted by: greentyphlosion
Date: 2019-08-14 08:48:00
…well, this is interesting.

I've just tried the same code on a different save file. Same result, except that all the Pokemon caught are Relaxed instead of Lonely.

My new theory is that the code is working on each individual file's ID. Presumably, further save files will elicit different results. Will keep researching…

Re: Anyone with a knowledge of hex help me out?

Posted by: Sherkel
Date: 2019-08-14 10:13:20
What you're looking for is someone who knows how the Xploder encrypts its codes. The way all of these devices work is by writing a byte to a specific location in memory, or multiple instances of that in case of a longer code. After the original GameShark, for whatever reason the developers decided to make the mechanism less obvious by throwing an encryption algorithm on top of it. I tried using this, but it needs to know the Xploder version and a "game ID" which I don't know the first thing about.

However, it's not hard to guess how the code works, given how these games decide what's shiny once it's encountered or hatched. It simply takes the PID (4 bytes) of the Pokémon in question, calculates the XOR of the upper and lower 2 bytes, then calculates the XOR of your ID and secret ID (2 bytes each), and if the difference is less than 8 (0 included, so in short a chance of 8/65536 or 1/8192), it's a shiny. It can be traded to other games and stay shiny due to its status as such being permanent, but if it were originally encountered on that other game, it wouldn't be, unless the ID and secret ID were the same or extremely close.

That said, the code probably works in one of two ways:

Store your ID to an unused memory location (i.e. read it)
Store your secret ID to an unused memory location
Upon encountering the next Pokémon, make the PID be identical to that (as a xor a is 0, which is less than 8)


or (which seems more likely, based on what you said):

Load a specific value to the PID of the next encountered Pokémon
Temporarily change your ID to match that, putting it in an out of an unused location before and after the battle


It's a pretty silly method, but "it's just Pokémon", and it gets the job done. What makes it so obviously silly, though, is the fact that a PID includes nature (and in Gen III, can be extrapolated directly to IVs in wild encounters), so those will always be the same if the code temporarily changes your ID to a specific value or something along those lines. It might not be that exactly; I'd have to check the decomp instead of going off what's off the top of my head, but keep in mind that shininess and nature are inherently intertwined.

EDIT:

…well, this is interesting.

I've just tried the same code on a different save file. Same result, except that all the Pokemon caught are Relaxed instead of Lonely.

My new theory is that the code is working on each individual file's ID. Presumably, further save files will elicit different results. Will keep researching…

Okay, so it's more likely to be the first one. With how few lines of machine code it is, it's bound to just be copying your ID and SID to the PID of whatever you encounter, making it always the same, and the most obvious tell of that without using PKHex would be nature.

Re: Anyone with a knowledge of hex help me out?

Posted by: greentyphlosion
Date: 2019-08-14 15:56:36
This is useful to know, thanks. I'll sniff around Reddit and Gamefaqs but these sorts of devices are such old hat I won't hold my breath.

After further testing can definitely confirm that the code is simply using my PID as a base. The characteristics of all the Pokemon encountered appear to be identical; I've caught a bunch of shiny Relaxed Wurmple and every single one of them has evolved into a Cascoon.

That site you linked to is interesting - it doesn't have anything for Emerald, but it does have an entry for FireRed (I assume the basics are the same).

The annoying thing is that with the codes I've currently got I can get a 6IV Pokemon or a shiny Pokemon, but not one that's both (unless, of course, it's Relaxed or Lonely). Might be good for the Battle Palace, I suppose?

Re: Anyone with a knowledge of hex help me out?

Posted by: Torchickens
Date: 2019-08-14 18:14:32
Using cbacrypt with these codes (a program to decrypt and encrypt codebreaker codes unfortunately forgot where you can download it), I get:

(m, decrypted):
928817F0 298A
00006FA7 000A
1006AFA4 0007

(shiny code, decrypted):
83007CE4 3020
83007CE6 0300
53003020 0004
001087E5 1EFF
2FE10000 0000

Looks like something is set to 00032030. As the 3007CE4-6 region is affected by DMA (what the address is is affected by randomization), one of the codes possibly anti-DMA, so that it's always wild Pokémon related.

Unfortunately that's as far as I got right now but my guess is this affects the wild Pokémon's PID. When calculating the Shiny Pokémon, both the player's Trainer ID and Secret ID considered (Bulbapedia explains the calculation).

Hope this helps. Sorry for not knowing anything further.

Re: Anyone with a knowledge of hex help me out?

Posted by: Sherkel
Date: 2019-08-15 23:31:20

The annoying thing is that with the codes I've currently got I can get a 6IV Pokemon or a shiny Pokemon, but not one that's both (unless, of course, it's Relaxed or Lonely). Might be good for the Battle Palace, I suppose?

The Battle Video trick makes it fairly easy to get the flawless IVs without cheat codes, assuming you're using wild encounters only (breeding is more complicated but faster). Getting your ID to make them shiny is a TAS thing, but again only if it's wild encounters.

Play the game however it's most fun to you, though, obviously. You just might be limited with an older external device like that in terms of the results you're looking for.

Re: Anyone with a knowledge of hex help me out?

Posted by: greentyphlosion
Date: 2019-08-16 16:57:04

Using cbacrypt with these codes (a program to decrypt and encrypt codebreaker codes unfortunately forgot where you can download it), I get:

(m, decrypted):
928817F0 298A
00006FA7 000A
1006AFA4 0007

(shiny code, decrypted):
83007CE4 3020
83007CE6 0300
53003020 0004
001087E5 1EFF
2FE10000 0000

Looks like something is set to 00032030. As the 3007CE4-6 region is affected by DMA (what the address is is affected by randomization), one of the codes possibly anti-DMA, so that it's always wild Pokémon related.

Unfortunately that's as far as I got right now but my guess is this affects the wild Pokémon's PID. When calculating the Shiny Pokémon, both the player's Trainer ID and Secret ID considered (Bulbapedia explains the calculation).

Hope this helps. Sorry for not knowing anything further.



No, this is great! Thanks. I've been playing around with codes over the last couple of days and I think I'm a bit more up on how they're put together, so I'm edging ever closer.

Re: Anyone with a knowledge of hex help me out?

Posted by: greentyphlosion
Date: 2019-08-16 16:58:22


The annoying thing is that with the codes I've currently got I can get a 6IV Pokemon or a shiny Pokemon, but not one that's both (unless, of course, it's Relaxed or Lonely). Might be good for the Battle Palace, I suppose?

The Battle Video trick makes it fairly easy to get the flawless IVs without cheat codes, assuming you're using wild encounters only (breeding is more complicated but faster). Getting your ID to make them shiny is a TAS thing, but again only if it's wild encounters.

Play the game however it's most fun to you, though, obviously. You just might be limited with an older external device like that in terms of the results you're looking for.


I… was not aware of this. Holy shit.

Re: Anyone with a knowledge of hex help me out?

Posted by: Torchickens
Date: 2019-08-16 17:00:11

No, this is great! Thanks. I've been playing around with codes over the last couple of days and I think I'm a bit more up on how they're put together, so I'm edging ever closer.


Awesome! ^^ ~ Glad to hear and hope you learn more and more. :)