Jump to content
Sign in to follow this  
Tzitzimpirdas

Number of trades on trainer card

Recommended Posts

OK, first of all I'm new here, first post actually, so I'm sorry if I'm posting in a wrong forum.

I want to find and change the number of trades I've done on my FireRed game, which is shown in my trainer card, since I could not find a tool that does this. After reading this article, I managed to familiarize myself a bit with the file format, and managed to locate some data like the Trainer's name, the Security Key, coins, etc. Now on to the problem: I was not able to find the number of trades anywhere. I tried locating it as a string, as a "raw" 4 byte value, xoring with both the lower 2 and the higher 2 bytes of the security key. Everything to no avail. I even dumped my hex editor and tried to find it with Cheat Engine after trading. Again nothing.

I am in desperate need of help. Anyone ever had any success in finding it? Thanks in advance.

P.S. Sorry for my English, not my native language.

Share this post


Link to post
Share on other sites

Thanks for the help, I was actually searching for a 2 byte little endian value and wrote 4 byte by mistake. I am still continuing my search, still nothing. 

Share this post


Link to post
Share on other sites

I finally found it. It is a 2 byte value, that is XORed with the lower 2 bytes of the security key. On the save file I attached, it can be found at 0x192d4.

Side question: does the security key change every time one saves one's game?

If @Kaphotics is interested at adding this to pkhex, I can find the value from all the GEN III games.

test.sav

  • Like 1

Share this post


Link to post
Share on other sites

OK, I have located the value in all of the GBA GEN III games. I have attached a zip with the saves I edited and a text with the locations. I 'll run some more tests and see if I can come up with some code that finds the value and edits it and hopefully release a tool if I find the time. Cheers!

trade test.zip

EDIT: Unless I made a big mistake, on my FireRed save the value is on a section with ID 2, and on LeafGreen it's on a section with ID 0. Is this possible? Anyone with any info on that?

EDIT2: Never mind, I actually did a mistake... 😅

Edited by Tzitzimpirdas

Share this post


Link to post
Share on other sites

Research successful. The process is the same with the amount of coins. In games with a security key (FR/LG/E) the 2 byte value needs to be XORed with the lower 2 bytes of the security key. In all games the value that represents the number of trades is located in Section 2.

The offsets for the games are

  • FR/LG: Section2 + 0x02D4
  • E: Section2 + 0x0670
  • R/S: Section2 + 0x0614

@Kaphotics Any chance this is going to be implemented in PKHeX?

Share this post


Link to post
Share on other sites
58 minutes ago, Tzitzimpirdas said:

Research successful. The process is the same with the amount of coins. In games with a security key (FR/LG/E) the 2 byte value needs to be XORed with the lower 2 bytes of the security key. In all games the value that represents the number of trades is located in Section 2.

The offsets for the games are

  • FR/LG: Section2 + 0x02D4
  • E: Section2 + 0x0670
  • R/S: Section2 + 0x0614

@Kaphotics Any chance this is going to be implemented in PKHeX?

Thanks for doing the research on this! 

Share this post


Link to post
Share on other sites

Needs to have full offset list etc. Here's what's needed for full info:

 

for RS: block 2 @ 0x614 = 0x614+0xF80 within the Large save block, which falls under the gameStats region.

https://github.com/pret/pokeruby/blob/fef1f0c11af596f9a740bbab82836dcef6978bab/include/global.h#L678

0x1540 starts the Trainer Stats, and is thru 0x1607 (total of 50 stats, 4bytes per stat)

 

Some stats (incremented) have a maximum of 0x00FFFFFF (16,777,215):

https://github.com/pret/pokeruby/blob/cbc414c44115550c811d6629c23c2e749d9d7fe3/src/overworld.c#L277-L286

 

Game Stat enumeration:

RS (50): https://github.com/pret/pokeruby/blob/f839afb24aa2c7b70e9c28a5c069aacc46993099/include/constants/game_stat.h

E (64): https://github.com/pret/pokeemerald/blob/3a40f5203baafb29f94dda8abdce6489d81635ae/include/constants/game_stat.h

FRLG (64): https://github.com/pret/pokefirered/blob/8367b0015fbf99070cc5a5244d8213420419d2c8/include/constants/game_stat.h

 

Confirmation that E/FRLG xor the gamestats:

E: https://github.com/pret/pokeemerald/blob/3a88ab831d2fb57e1f3e0908aeb79395700867d4/src/overworld.c#L506-L512

FRLG: https://github.com/pret/pokefirered/blob/8f7400809626c0f72dfe751665126f94181fd7c1/asm/overworld.s#L316-L331

RS (doesn't): https://github.com/pret/pokeruby/blob/fef1f0c11af596f9a740bbab82836dcef6978bab/src/overworld.c#L288-L294

 

===

Outside of that, figuring out how to present the UI without it being a large implementation needs to be done...

  • Like 2

Share this post


Link to post
Share on other sites

Sorry for the late reply, I was travelling. First of all, thank you for your awesome tool. Also thank you for the links, very helpful and informative.

By saying you need the full offset list, you mean in order for us to be able to edit the full range of "game stats"? For the trades we have all the info we need, I think. Right?

Anyway, my idea is to locate just the data that appears on the trainer card (+ the stickers) so that we can create a trainer card editor form within pkhex (could I contribute this on github?) where one is able to change all that data. I will start looking for the other offsets.

Share this post


Link to post
Share on other sites

Good news, I have located the offsets for the game stats in Emerald.

Annotation 2019-02-20 032105.jpg

Here is what appears in the trainer card:

GAMES_STATS			BlockOfs[2] + 0x061C

FIRST_HOF_PLAY_TIME		BlockOfs[2] + 0x0620 ⊕ SecurityKey
LINK_BATTLE_WINS		BlockOfs[2] + 0x0678 ⊕ SecurityKey
LINK_BATTLE_LOSSES		BlockOfs[2] + 0x067C ⊕ SecurityKey
POKEMON_TRADES			BlockOfs[2] + 0x0670 ⊕ SecurityKey
POKEBLOCKS_WITH_FRIENDS		BlockOfs[2] + 0x06A4 ⊕ SecurityKey
WON_LINK_CONTEST		BlockOfs[2] + 0x06A8 ⊕ SecurityKey

BATTLE_POINTS_WON		BlockOfs[0] + 0x0EBA

I also have the offsets for most of the remaining game stats that do not appear(?) in-game.

Except for the BATTLE_POINTS_WON which is a 2 byte value and on a different section, the other are all 4 byte values. However, since the max value of these stats are 9999 (minus the time formatted FIRST_HOF_PLAY_TIME) and they have to be XORed with the security key, only the lower 2 bytes matter/change.

The FIRST_HOF_PLAY_TIME value works like this: The first/higher 2 bytes represent the hours, the next byte the minutes and the last/lower byte the seconds.

I have also found the battle results board location and format.

Annotation 2019-02-20 032449.jpg

It is at BlockOfs[4] + 0x02D0 with a size of 80 bytes. Each of the five trainer entries are made of 16 bytes. The first 8 bytes are the trainer's name. 1-7 characters + the string terminator (0xFF). If the name is shorter than 7 characters, then the remaining bytes after the terminator are valued 0x00. The next 2 bytes are the trainer's ID (TID) and the final 6 bytes are the results. 2 bytes for the number of wins, 2 for losses and 2 for draws. A void trainer entry begins with a string terminator and the remaining 15 bytes valued zero.

Edited by Tzitzimpirdas

Share this post


Link to post
Share on other sites

Awesome work, I compiled it at home and it runs perfectly. Thank you. Perhaps the only thing you might consider improving is that for the average user it might be difficult to figure out how to change the value of the HOF Debut, but this is definitely not important. Thanks again.

Share this post


Link to post
Share on other sites
9 hours ago, Tzitzimpirdas said:

Awesome work, I compiled it at home and it runs perfectly. Thank you. Perhaps the only thing you might consider improving is that for the average user it might be difficult to figure out how to change the value of the HOF Debut, but this is definitely not important. Thanks again.

Done:

https://github.com/kwsch/PKHeX/commit/0156958f1aa330b73d19ca7978829465108eff5a

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×