News: 11 March 2016 - Forum Rules

Author Topic: [GBC] Pokémon TCG (1998) Need help understanding something about Hex/Hexadecimal  (Read 856 times)

OracleRaven

  • Jr. Member
  • **
  • Posts: 4
    • View Profile
Greetings,
I'm relatively new to the world of Romhacks, and would like some help understanding a specific concept.

I'm currently working on a Romhack for the GameBoy Color title Pokémon Trading Card Game released in 1998.

I've been using "WindHex" to edit the .gbc file for the game in order to correct typos, edit card text, and edit deck compositions.

To do so, I managed to find a forum post from 2004 explaining how the game determines what cards are included in a deck.
The information I have is as follows:

Quote
For the CPU Decks, the format is [Amount] [Card]. For example :
===============================================
0x30848-0x3086F : Grandmaster Ronald
===============================================
14 02 04 07 01 3D 02 40 01 5A 01 5F 01 72 01 76
02 B9 04 BC 04 BF 03 C0 02 C1 01 C3 03 C5 01 C9
02 CA 03 D0 03 D5 01 E3


0x14 = 20
0x02 : Fire Energy
=> 20× Fire Energy

The part of this info I need help understanding is the code in red.

Thanks to this post and the info from the Data Crystal notes page about the game (found here), I was able to determine that this is how the deck is constructed:

14 02 = 20x Fire Energy
04 07 = 4x Double Colorless Energy
01 3D = 1x Flareon LV22 (GB)
02 40 = 2x Legendary Moltres LV37
01 5A = 1x Vaporeon LV29 (GB)
01 5F = 1x Legendary Articuno LV37
01 72 = 1x Jolteon LV24 (GB)
01 76 = 1x Legendary Zapdos LV68
02 B9 = 2x Kangaskhan LV40
04 BC = 4x Eevee LV12
04 BF = 4x Dratini LV10
03 C0 = 3x Dragonair LV33
02 C1 = 2x Legendary Dragonite LV41 (GB)
01 C3 = 1x Professor Oak
03 C5 = 3x Bill
01 C9 = 1x Pokémon Trader
02 CA = 2x Pokémon Breeder
03 D0 = 3x Energy Removal
03 D5 = 3x Scoop Up
01 E3 = 1x Gambler

In WindHex, I was able to find the part of the code above in blue with ease:


But I don't understand what the part in red 0x30848-0x3086F means, or how it refers to the line 00030840 where the code starts in WindHex.

Thanks to some info from Bulbapedia, I know for certain that one of the decks I wish to edit has 1 Jynx, 3 Rattata, 2 Raticate, 2 Bill, 2 Potion, 1 Full Heal. Based on this and the info from Data Crystal, I should be able to find the following code string somewhere: 01 9C 03 A7 02 A8 02 C5 02 DD 01 DF

01 9C = 1 Jynx
03 A7 = 3 Rattata
02 A8 = 2 Raticate
02 C5 = 2 Bill
02 DD = 2 Potion
01 DF = 1 Full Heal

But searching through the game's code via WindHex's Hex Search feature, it says the string was not found. (And yes, I checked the boxes for "Ignore Case" and "Search From the Beginning")

As per this example from the forum post:
0x14 = 20
0x02 : Fire Energy
=> 20× Fire Energy
It is my understanding that "0x14" is hex code for 20.
Since the Deck I'm looking for also has 14 Water Energy and 10 Psychic Energy, that would mean:
0x0e should mean 14
0x03 should mean Water Energy
0x0a should mean 10
0x06 should mean Psychic Energy
and since there is no "0x" anywhere in the code string in blue, I tried searching for 0e030a06, but I did not find any results.
and now I kind of got lost there...

Any help on how to go from there and obtain the information I need to find the deck I wish to edit would be greatly appreciated!
Thanks!

December 22, 2021, 02:00:26 am - (Auto Merged - Double Posts are not allowed before 7 days.)
Ok, so from looking around in the code, I managed to find where several other decks are located.

For example:
--------------------------------------------------
Line 00030420 is where the code of the Charmander & Friends Deck starts:
0A 02 08 04 06 05 02 30 01 31 01 32 02 36 01 38
02 39 01 3B 02 60 01 67 02 69 01 6B 01 75 02 79
01 7A 01 7D 01 7E 02 A7 01 A8 01 B1 01 C3 02 C5
01 D2 01 D6 01 D8 02 DD 02 DF

0A 02 = 10 Fire Energy
08 04 = 8 Lightning Energy
06 05 = 6 Fighting Energy
etc.
--------------------------------------------------
Line 00030480 is where the code of the Squirtle & Friends Deck starts:
0B 03 06 05 08 06 02 41 01 42 01 43 02 4B 01 4C
01 55 01 56 01 53 01 54 01 59 02 8E 01 8F 02 94
01 97 01 7D 01 7E 02 80 01 88 02 A7 01 A8 01 B1
01 C3 01 C5 01 D2 01 D4 01 D5 01 DA 01 DD 01 DF

0B 03 = 11 Water Energy
06 05 = 6 Fighting Energy
08 06 = 8 Psychic Energy
etc.

--------------------------------------------------
Line 000304F0 is where the code of the Bulbasaur & Friends Deck starts:
0B 01 03 02 09 03 02 08 01 09 01 0B 02 0C 01 0D
02 14 02 17 01 18 01 2D 01 3E 01 4B 01 4C 02 4F
01 50 02 53 01 54 01 5B 01 AF 01 B1 02 BC 01 B9
01 C3 01 D2 01 D4 02 D8 01 D9 02 DF 01 E0

0B 01 = Grass Energy
03 02 = Fire Energy
09 03 = Water Energy
etc.
--------------------------------------------------
Ghost Deck (Robert, Psychic Club) starts on line 00030AD0
Flower Garden Deck (Kristin, Grass Club) starts on line 00030A70
etc.

Essentially, I realized I have no problem searching for specific decks by looking at their energy card counts.

However, the deck I'm looking for is the one given to you during the tutorial.
It is simply called the "Practice Deck".

According to Bulbapedia, it states:
Due to it being used only in the practice battle against Sam, the cards are dealt the same way each time, and therefore some of the cards listed below may never appear during the duels.
Nevertheless, the whole deck data is found from inside the game data and can therefore be listed here.


It seems like it should be around somewhere the game code, but I simply cannot find it for some reason...
This is rather quite puzzling.
« Last Edit: December 22, 2021, 02:03:17 am by OracleRaven »

OracleRaven

  • Jr. Member
  • **
  • Posts: 4
    • View Profile
How do you keep searching in WindHex with the "Search Hex" function?
« Reply #1 on: December 22, 2021, 02:13:12 am »
Hi,
I'm using WindHex and I was wondering how to keep searching when using the "Search Hex" function?

Fox example, I want to search the code for every instance where the string "019C" comes up.
It comes up several times, but when I search for it, it only shows me the first result found and stops there.
How do I keep searching for the next instance, and the next one, and the next one, etc.?
(or show every single one at once)

It seems like the "Relative Search" function works quite nicely, but only for text, not for hex/code strings.

Any tips or help is appreciated,
Thanks!

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7410
  • *sigh* A changed avatar. Big deal.
    • View Profile
What the 0x30848 means is a hex address.
That means yes, go line $30840 (since each line is 0x10 bytes), and then over 8.

If you cannot find the hex data, it might be because you might have clicked Text Search.
You want to click Hex Search for finding data. (I don't think "Ignore case" should be an option applicable to hex searching.)
"My watch says 30 chickens" Google, 2018

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7410
  • *sigh* A changed avatar. Big deal.
    • View Profile
There should be a toolbar button to Search Next.
I think the hotkey in WindHex to search again was F3 but I can't be certain.
"My watch says 30 chickens" Google, 2018

OracleRaven

  • Jr. Member
  • **
  • Posts: 4
    • View Profile


Hmm... I am using the Hex Search function, but I don't see a toolbar button for "Search Next", and as soon as I hit "Find", the search box disappears.

And yes, F3 is the correct hotkey for "Search Again", but it doesn't do anything.

Vehek

  • Full Member
  • ***
  • Posts: 223
    • View Profile
I don't remember my own research well, but the practice decks are laid out in the fixed order the cards appear, rather than all the copies of cards being placed together.
Look here at a disassembly:
https://github.com/pret/poketcg/blob/master/src/data/decks.asm#L488
(I didn't copy the whole listing)
Code: [Select]
PracticePlayerDeck: ; 30344 (c:4344)
db 2, WATER_ENERGY
db 1, PSYCHIC_ENERGY
db 1, SEAKING
db 1, STARYU
db 1, FULL_HEAL
db 1, GOLDEEN
db 5, WATER_ENERGY
db 1, DROWZEE
db 1, POTION
db 1, SEAKING
db 1, STARMIE
db 1, WATER_ENERGY

But I bet it would be a bad idea to mess with the practice deck without knowing how the tutorial restrictions work.

OracleRaven

  • Jr. Member
  • **
  • Posts: 4
    • View Profile
Thank you so much for that info and for the github link! That is super helpful!

I made Seaking's "Waterfall" ability have the same effect as Pidgeot(Jungle)'s "Hurricane" where the Defending Pokémon and all cards attached to it are returned to the opponent's hand. Since Sam, the tutorial guy, has no other Pokémon on his bench at this point, it ends the tutorial early and skips like 3 minutes or so. Tested it with the default cards and it works just fine!

However, what I'd like to do now is to make the Waterfall ability cost Grass+Water instead of Water+Any(Colorless), for balance purposes.

I replaced the Full Heal you get in your opening hand (Which is never used in the tutorial) with a Grass energy, and so far so good.

I get to evolve Goldeen into Seaking, I get to put the Grass energy on it to use Waterfall, but then when I select the attack, the game checks if I attached a Psychic energy to it to use Waterfall. So even though I have the correct energy cards to use the attack, it can't be used unless a Psychic energy was attached to Seaking on that turn.

Since the hexcode for a Psychic Energy is 06 and the hexcode for a Grass Energy is 01, I assume there's a 06 somewhere that I simply need to change to a 01, and then it should work properly. That's only my guess, though.

Asking just in case, but is there any way I can find where the code for the tutorial restrictions might be stored?

---

Oh, I think I just found it:
https://github.com/pret/poketcg/blob/f516a91f5fa02a741631c77b9097598f466d1328/src/engine/duel/core.asm


2926 | PracticeDuelVerify_Turn2:
2927 | ld a, [wTempCardID_ccc2]
2928 | cp SEAKING
2929 | jp nz, ReturnWrongAction
2930 | ld a, [wSelectedAttack]
2931 | cp 1
2932 | jp nz, ReturnWrongAction
2933 | ld e, PLAY_AREA_ARENA
2934 | call GetPlayAreaCardAttachedEnergies
2935 | ld a, [wAttachedEnergies + PSYCHIC]
2936 | or a
2937 | jr z, ReturnWrongAction
2938 | ret


So, uh... line 2935? How can I find that in WindHex?
« Last Edit: December 22, 2021, 09:27:42 pm by OracleRaven »

FAST6191

  • Hero Member
  • *****
  • Posts: 3525
    • View Profile
A lot of disassemblies will include the base code in hex as well, this one appears not to which is a bit unfortunate but oh well.

You can try assembling a few of the instructions (preferably without hardbaked addresses in them, or if you do then wildcard that part of the results) and seeing if you can find that pattern in code -- with a few exceptions then a run of 5 given instructions is pretty unlikely to come up more than a few times (and 6, 7, 8 , 9... rarer still), while I just dissed hardbaked addresses then you can use those too -- set a breakpoint for something reading those (I don't know if/didn't look to see if there is a definition of said nice human readable addresses somewhere in that, I imagine there is as it is kind of key to a disassembly like that) and get to a point in the game just before the code you want to look at is likely to run (this does not look to be something overly common or terribly random and as such you can presumably contrive a point where it is going to be run, might be further back than you think though) and then either figure out where it is from the emulator addresses or search for the matching hex again (might be harder on later systems with compression but unlikely to be a thing for this).