Jump to content

Number of trades on trainer card


Tzitzimpirdas

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.

Link to comment
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
Link to comment
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
Link to comment
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?

Link to comment
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! 

Link to comment
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
Link to comment
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.

Link to comment
Share on other sites

  • 2 weeks later...

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
Link to comment
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
Link to comment
Share on other sites

Hey, using your research I somehow ended up finding some offsets that might be useful for someone else, so here it is:

 

Section 2
- Link Battles:
Total Wins: 0x+2DC (16-bit) (Appear in the Trainer Card)
Total Loses: 0x+2E0 (16-bit) (Appear in the Trainer Card)
Total Draws: 0x+2E4 (16-bit) (Appear only in the Leaderboard)

Trades: 0x+2D4 (16-bit) (You already found this)
Union Trades & Battles: 0x+348 (16-bit) (That's new)
Berry Crush: 0x+34C (16-bit) (That's new too)

Little problem: If someone edit the berry crush information and want a legitimate save file, then we still need to find the offset to modify the Powder Jar quantity and the Berry Crush Leaderboard (Cerulean City Berry old man has a leaderboard in his house) to make everything looks legit. The leaderboard in the second floor of the Pokémon Center in FireRed maybe should be researched too, for anyone who modifies the Battle Link "Win" value.

Edit:

I managed to find the offset for the Powder Jar too. It is located at the end of the section 0 and uses 4 bytes.

Powder Jar: 0x+AF8 (32-bit)

 

I do have a save with the Berry Crush leaderboard with a value of "10.58" times/sec. but I don't how to look for this number in hex, anyone can help me with this?

back_trainercard.png

Edited by Damedayo
Link to comment
Share on other sites

@arjun I am using Visual Studio's binary editor and VBinDiff.

 

@Damedayo Very nice work with the extra 2 stats you found and the powder jar value. I confirmed that they work. Can you pm me the save with the 10.58 value to see if I can find anything?

 

@Kaphotics Thanks to Damedayo's work, we have these 2 extra stats. In PKHeX we can edit the first 50 stats (if I counted correctly). These 2 are right after the 50th (Entered hot springs), Union trades & battles is the 51st and berry crush the 52nd. You could kindly add them in FR/LG versions.

 

Edit: Just found the Link battle records board location in FR/LG. It is Section 0 + 0x0A98 and works exactly like in Emerald as explained some posts above.

Edited by Tzitzimpirdas
Link to comment
Share on other sites

  • 2 weeks later...

You guys are awesome. I have a request that is in line with the work you are doing now. 

 

Would you be able to give us the option in Emerald to edit the Battle Frontier leader boards?

Here are some pics of what i am talking about

http://prntscr.com/mz9f8e

http://prntscr.com/mz9fhe

 

image.png.bfcbab38c3ff4fb20a7ecc329c437cb6.pngimage.png.034f8b9a8540e5de934b89bc435f8dac.png

 

I mixed records with a member on this forum who gave me the Regi dolls which i am grateful for but now i have all of his records jacking up my leader boards that i like to mix records with.

I would realistically like to remove EMERALD from all of my boards if possible.  

Link to comment
Share on other sites

  • 5 years later...

Regarding your issue with finding the number of trades on your trainer card, it sounds like you've already done quite a bit of investigation. Sometimes, these values can be a bit tricky to locate because they might be stored in unexpected ways or use encryption.

I don't have an exact answer, but you might want to try searching for related data that changes when you trade, such as the Pokémon ID or the timestamp of the trade. Also, checking forums or communities dedicated to Pokémon game hacking might provide additional insights or tools that could help.

Edited by Denni
Link to comment
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
×
×
  • Create New...