The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > Fan Games > Binary ROM Hacking
Reload this Page Other Script to Read Bytes in a Table

Notices
For all updates, view the main page.

Binary ROM Hacking Need a helping hand or just want to talk about binary ROM hacks? Get comments and answers to any ROM Hacking-related problems, questions or thoughts you have here.

Ad Content
Reply
 
Thread Tools
  #1   Link to this post, but load the entire thread.  
Old April 19th, 2015 (3:09 PM). Edited July 13th, 2015 by azurile13.
azurile13 azurile13 is offline
 
Join Date: Mar 2015
Posts: 417
I'm looking for a scripting command that allows me to use the species of a pokemon as an "input" and get back information from its base stats table such as egg groups, types, or obviously literal base stats (I would assume the command would store the value in Last Result, but I don't care how it is done as long as my script has access to the number). I know the offset of the base stats table in my rom, and I even know the exact location of each byte/word thanks to bulbapedia, but I'm not sure how to get a script to read those bytes and throw it into a script. In fact, even more helpful would be a tutorial (that I can't find) on how to get a script to read and copy off of a table in general. Any pointers appreciated!
Reply With Quote
  #2   Link to this post, but load the entire thread.  
Old April 19th, 2015 (7:35 PM).
Joexv's Avatar
Joexv Joexv is offline
ManMadeOfGouda
joexv.github.io
 
Join Date: Oct 2012
Location: Oregon
Age: 25
Gender: Male
Nature: Sassy
Posts: 1,035
Im pretty sure this would require asm, but from what I've learned so far it wouldn't be too hard.
But I dont think there is any script that would do this.
__________________
New living flesh vessel who dis?
Reply With Quote
  #3   Link to this post, but load the entire thread.  
Old April 19th, 2015 (10:37 PM).
DizzyEgg's Avatar
DizzyEgg DizzyEgg is offline
 
Join Date: Feb 2014
Location: Poland
Age: 25
Gender: Male
Nature: Quiet
Posts: 794
By literal base stats you mean current stats, right? If so, then getting them would require ASM(altough it's not that hard, I could even write a script for that). Reading anything other than stats is much more complicated. If you have no idea what ASM is, check those threads out.
1 - to get a vague idea of ASM
2 - to know how to insert an ASM routine into your rom
3 - to see ASM in action
I also think that there's checktype command in scripting, but I'm not sure on this one.
__________________
Support Pokeemerald!

Pokeemerald starter pack:
Emerald Expansion
Reply With Quote
  #4   Link to this post, but load the entire thread.  
Old April 19th, 2015 (11:36 PM). Edited July 13th, 2015 by azurile13.
azurile13 azurile13 is offline
 
Join Date: Mar 2015
Posts: 417
Quote:
Originally Posted by DizzyEgg View Post
By literal base stats you mean current stats, right? If so, then getting them would require ASM(altough it's not that hard, I could even write a script for that). Reading anything other than stats is much more complicated. If you have no idea what ASM is, check those threads out.
1 - to get a vague idea of ASM
2 - to know how to insert an ASM routine into your rom
3 - to see ASM in action
I also think that there's checktype command in scripting, but I'm not sure on this one.
Mmm no, not current stats. I meant the base stats that every pokemon of a species has, like how every Blissey has base HP 255, or every Groudon has base attack 150. The first six found here: http://bulbapedia.bulbagarden.net/wiki/Pok%C3%A9mon_base_stats_data_structure_in_Generation_III

Regardless, base stats weren't the main thing I was interested in; that was just an example. I was interested in being able to copy bytes from a static table. Any table, simply given the offset of the table, how long each entry happens to be, and how many bytes into each entry I want to read/copy. It was a table that I want to create from scratch, meaning I want to learn how to read a table in general, and not a specific table.

As far as ASM, I know what it is and have an idea of how it works, but I unfortunately can't find a program that let's me assemble. I can insert the hex versions of routines and utilize callasm, but other than that, I'm stuck. I'm on a Mac, and I haven't found anything that works for me. Even most programs that allows Macs to run Windows programs don't work because (I'm guessing) you need Terminal, which uses the actual computer itself, so my Mac terminal tries to work directly with a windows exe, and it simply cannot.
Reply With Quote
  #5   Link to this post, but load the entire thread.  
Old April 20th, 2015 (12:11 AM).
miksy91's Avatar
miksy91 miksy91 is offline
Dark Energy is back in action! ;)
 
Join Date: Oct 2008
Location: Finland
Gender: Male
Posts: 1,480
Quote:
Originally Posted by azurile13 View Post
Mmm no, not current stats. I meant the base stats that every pokemon of a species has, like how every Blissey has base HP 255, or every Groudon has base attack 150. The first six found here: http://bulbapedia.bulbagarden.net/wiki/Pok%C3%A9mon_base_stats_data_structure_in_Generation_III

Regardless, base stats weren't the main thing I was interested in; that was just an example. I was interested in being able to copy bytes from a static table. Any table, simply given the offset of the table, how long each entry happens to be, and how many bytes into each entry I want to read/copy. It was a table that I want to create from scratch, meaning I want to learn how to read a table in general, and not a specific table.

As far as ASM, I know what it is and have an idea of how it works, but I unfortunately can't find a program that let's me assemble. I can insert the hex versions of routines and utilize callasm, but other than that, I'm stuck. I'm on a Mac, and I haven't found anything that works for me. Even most programs that allows Macs to run Windows programs don't work because (I'm guessing) you need Terminal, which uses the actual computer itself, so my Mac terminal tries to work directly with a windows exe, and it simply cannot.
You should write the code with a hex editor then.
Call an asm routine, load data from those rom addresses you like to registers and move that data from registers to ram where you can access it "easier". What comes to this though... can't you point to the whole rom area at any time in GBA engine? In case so, I don't see a reason why you should even move the data anywhere - just access it straight with pointers.


You can point to rom addresses by "forming bytes" from the addresses, rotating the bytes around and then putting a "08" byte at the end of the pointer. If you have resized the rom data to be larger than 16MB and want to point to addresses above the first 8MB, the last byte should be "09" instead of "08".
More info (and actually a better example) here: http://datacrystal.romhacking.net/wiki/Pointer
__________________
Pokémon Dark Energy
Some ROM hacking related stuff
Reply With Quote
  #6   Link to this post, but load the entire thread.  
Old April 20th, 2015 (12:51 AM). Edited July 13th, 2015 by azurile13.
azurile13 azurile13 is offline
 
Join Date: Mar 2015
Posts: 417
Quote:
Originally Posted by miksy91 View Post
You should write the code with a hex editor then.
Call an asm routine, load data from those rom addresses you like to registers and move that data from registers to ram where you can access it "easier". What comes to this though... can't you point to the whole rom area at any time in GBA engine? In case so, I don't see a reason why you should even move the data anywhere - just access it straight with pointers.


You can point to rom addresses by "forming bytes" from the addresses, rotating the bytes around and then putting a "08" byte at the end of the pointer. If you have resized the rom data to be larger than 16MB and want to point to addresses above the first 8MB, the last byte should be "09" instead of "08".
More info (and actually a better example) here: http://datacrystal.romhacking.net/wiki/Pointer
Hmm. Maybe I'm not being clear. I'll be more specific. As an example, in my rom, the base stats table begins at 0x72D8A4. Now let's say I'm trying to look at the egg groups a pokemon is in. So I know that Bulbasaur's table entry begins at 0x72D8C0. I know that egg group 1 for Bulbasaur in specific is at offset 0x78D8D4 and I know that egg group 2 is at 0x72D8D5, and reading the values at both of those offsets, perfect, egg groups Monster and Grass. The problem, of course, is that I don't want a script that reads Bulbasaur's egg groups. I want a script that reads the egg group of an arbitrary pokemon species. I know the offset locations of the six or seven hundred pokemon in my pokedex, but it doesn't sound at all efficient to make 1400 pointers. My question was about a script reading off of a table so I wouldn't need to make those 1400 pointers, but it sounds like there isn't a script solution, so I suppose I'll need to borrow a PC :/
Reply With Quote
  #7   Link to this post, but load the entire thread.  
Old April 20th, 2015 (1:03 PM).
miksy91's Avatar
miksy91 miksy91 is offline
Dark Energy is back in action! ;)
 
Join Date: Oct 2008
Location: Finland
Gender: Male
Posts: 1,480
Quote:
Originally Posted by azurile13 View Post
Hmm. Maybe I'm not being clear. I'll be more specific. As an example, in my rom, the base stats table begins at 0x72D8A4. Now let's say I'm trying to look at the egg groups a pokemon is in. So I know that Bulbasaur's table entry begins at 0x72D8C0. I know that egg group 1 for Bulbasaur in specific is at offset 0x78D8D4 and I know that egg group 2 is at 0x72D8D5, and reading the values at both of those offsets, perfect, egg groups Monster and Grass. The problem, of course, is that I don't want a script that reads Bulbasaur's egg groups. I want a script that reads the egg group of an arbitrary pokemon species. I know the offset locations of the six or seven hundred pokemon in my pokedex, but it doesn't sound at all efficient to make 1400 pointers. My question was about a script reading off of a table so I wouldn't need to make those 1400 pointers, but it sounds like there isn't a script solution, so I suppose I'll need to borrow a PC :/
You'll have to do the following in assembly then;

0x72D8A4 + [Index Nr. of pokemon?] * [Size of one table entry] + 0x14 (= difference between start of the table entry and the first egg group value]

There is probably a simple multiply asm instruction you can use for calculating "Index" * "Size of table". If not, you'll need to build a loop that does the following;
5x4 = 4 + 4 + 4 + 4 + 4

So basically, if multiply instruction doesn't exist in GBA engine (it probably does but it doesn't in GB/C that I'm hacking), you'll have to use multiple "add"s in a row in a loop. But I don't think you'll have to do this really.

So basically, all you have to do is to:
1. Load the index value of the pokemon of which egg group you want to figure out to some register
2. Load the "size of one table entry" to a register
3. Multiply these two together and store the result in a register
4. Add 0x72D8A4 + 0x14 to that result.

After these four steps, the register should hold the value of the first egg group number of the pokemon you wish to know.

Anyway... if you don't have any sort of assembler or asm editor for that matter either that you can use, you could search for byte opcodes for GBA asm instructions and find a way to write the code with a hex editor that way. In case this turns out too unconvenient, ask somebody to assemble it for you. :)
__________________
Pokémon Dark Energy
Some ROM hacking related stuff
Reply With Quote
  #8   Link to this post, but load the entire thread.  
Old April 20th, 2015 (1:05 PM).
Joexv's Avatar
Joexv Joexv is offline
ManMadeOfGouda
joexv.github.io
 
Join Date: Oct 2012
Location: Oregon
Age: 25
Gender: Male
Nature: Sassy
Posts: 1,035
Quote:
Originally Posted by miksy91 View Post
You'll have to do the following in assembly then;

0x72D8A4 + [Index Nr. of pokemon?] * [Size of one table entry] + 0x14 (= difference between start of the table entry and the first egg group value]

There is probably a simple multiply asm instruction you can use for calculating "Index" * "Size of table". If not, you'll need to build a loop that does the following;

5x4 = 4 + 4 + 4 + 4 + 4
So basically, if multiply instruction doesn't exist in GBA engine (it probably does but it doesn't in GB/C that I'm hacking), you'll have to use multiple "add"s in a row in a loop. But I don't think you'll have to do this really.

So basically, all you have to do is to:
1. Load the index value of the pokemon of which egg group you want to figure out to some register
2. Load the "size of one table entry" to a register
3. Multiply these two together and store in a register
4. Add 0x72D8A4 + 0x14 to that result.

After these four steps, the register should hold the value of the first egg group number of the pokemon you wish to know.

Anyway... if you don't have any sort of assembler or asm editor for that matter either that you can use, you could search for byte opcodes for GBA asm instructions and find a way to write the code with a hex editor that way. In case this turns out too unconvenient, ask somebody to assemble it for you. :)
Im actually already working on it myself. But this is my first asm routine so it may be a daynor two. It almost works too.:P
__________________
New living flesh vessel who dis?
Reply With Quote
  #9   Link to this post, but load the entire thread.  
Old April 20th, 2015 (2:39 PM). Edited July 13th, 2015 by azurile13.
azurile13 azurile13 is offline
 
Join Date: Mar 2015
Posts: 417
Quote:
Originally Posted by miksy91 View Post
You'll have to do the following in assembly then;

0x72D8A4 + [Index Nr. of pokemon?] * [Size of one table entry] + 0x14 (= difference between start of the table entry and the first egg group value]

There is probably a simple multiply asm instruction you can use for calculating "Index" * "Size of table". If not, you'll need to build a loop that does the following;
5x4 = 4 + 4 + 4 + 4 + 4

So basically, if multiply instruction doesn't exist in GBA engine (it probably does but it doesn't in GB/C that I'm hacking), you'll have to use multiple "add"s in a row in a loop. But I don't think you'll have to do this really.

So basically, all you have to do is to:
1. Load the index value of the pokemon of which egg group you want to figure out to some register
2. Load the "size of one table entry" to a register
3. Multiply these two together and store the result in a register
4. Add 0x72D8A4 + 0x14 to that result.

After these four steps, the register should hold the value of the first egg group number of the pokemon you wish to know.

Anyway... if you don't have any sort of assembler or asm editor for that matter either that you can use, you could search for byte opcodes for GBA asm instructions and find a way to write the code with a hex editor that way. In case this turns out too unconvenient, ask somebody to assemble it for you. :)
Hmm surprisingly, a lot of this made sense. Although I haven't done any assembly, I've read a few beginner tutorials, just to understand how it works. The setup doesn't seem too different from the very first baby lesson HackMew provided with getting your secret ID, with the obvious difference being the multiplier dependent on index. I quickly looked up the byte opcodes, and could only find the regular gameboy codes, but even those looked mind numbing. I think I'll try to assemble a routine myself then just borrow a friend's PC for a bit.
Quote:
Originally Posted by joexv View Post
Im actually already working on it myself. But this is my first asm routine so it may be a daynor two. It almost works too.:P
Hmm...sharing is caring ^_^ I'll work on it myself first, but if that doesn't work, I'd love to see a code that works. No rush or anything, I have a lot of basic scripts to write before I'll need to use any asm.
Reply With Quote
  #10   Link to this post, but load the entire thread.  
Old April 20th, 2015 (5:27 PM).
Joexv's Avatar
Joexv Joexv is offline
ManMadeOfGouda
joexv.github.io
 
Join Date: Oct 2012
Location: Oregon
Age: 25
Gender: Male
Nature: Sassy
Posts: 1,035
Quote:
Originally Posted by azurile13 View Post
sharing is caring ^_^ I'll work on it myself first, but if that doesn't work, I'd love to see a code that works. No rush or anything, I have a lot of basic scripts to write before I'll need to use any asm.
Lol sharing is definately caring in this community. I've almost got it so you probably won't need to worry about trying if you don't want to(not saying u shouldn't,).
__________________
New living flesh vessel who dis?
Reply With Quote
  #11   Link to this post, but load the entire thread.  
Old April 22nd, 2015 (7:55 AM).
Blah's Avatar
Blah Blah is offline
Free supporter
 
Join Date: Jan 2013
Location: Unknown Island
Gender: Male
Posts: 1,924
Code:
#dyn 0x740000
#org @start
setvar 0x8000 0x[species ID]
setvar 0x8001 0x0
setvar 0x8002 0x0

#org @loop
addvar 0x8001 0x1C
addvar 0x8002 0x1
compare 0x8002 0x8000
if != jump @loop
copybyte 0x20370B8 (0x[pointer to stats] + 0x8001)
end
You can do the above in corsara's script editor iirc :)
Actually his script editor also supports while syntax, so the extra variable 0x8002 I used here becomes obselete. Check it out if you're not familiar with the ASM. Though it should be pointed out that the ASM equivalent of this is much more superior. Keep in mind that script commands are executed once per frame, so looping is expensive.
__________________
...
Reply With Quote
  #12   Link to this post, but load the entire thread.  
Old April 22nd, 2015 (6:11 PM). Edited July 13th, 2015 by azurile13.
azurile13 azurile13 is offline
 
Join Date: Mar 2015
Posts: 417
Quote:
Originally Posted by FBI agent View Post
Keep in mind that script commands are executed once per frame, so looping is expensive.
O_O Soooo asm it is, I suppose? I haven't created extensive loops, so I didn't realize scripts were executed that slowly.
Reply With Quote
Reply

Quick Reply

Join the conversation!

Create an account to post a reply in this thread, participate in other discussions, and more!

Create a PokéCommunity Account
Ad Content

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 9:10 AM.