News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Cross-platform Command-line Tools (Relative Search, NES Tile Editor)  (Read 1447 times)

amihart

  • Newbie
  • *
  • Posts: 2
    • View Profile
Hello, I'm new to this whole ROM Hacking thing. I'm also new to this forum, so if I'm doing something wrong, please be sure to tell me.

As I've been learning new concepts in ROM Hacking, I've also been developing my own custom tools in Java.
Since they are Java, they should all be cross-platform.
 
I have finished several tools and I thought I might as well share them.

These are all command-line tools, and they can all be found here;

The first tool I've written is a Relative Search tool. It lets you search binary files for relative sequences, such as strings of text, and also accepts wildcards.

Spoiler:
You can search for relative sequences using both character sequences or numerical sequences. A numerical sequence would look something like this:

Code: [Select]
java RelativeSearch zelda.nes 8 false 1 3 -1
That will return something like this:

Code: [Select]
0001AC19: D8 D9 DC DB
As you can see, the hex value "D8" increases by 1, then by 3, then down by 1.

The "8" is either 8 or 16 depending on whether the ROM uses 8 bits per character or 16 bits per character.
The "false" is either "true" or "false" depending on if you want the relative calculations to be done using signed or unsigned bytes. I believe this probably should almost always be false, but I left the option in there in case there is an exception somewhere.

A character sequence would look something like this:

Code: [Select]
java RelativeSearch zelda.nes 8 false take?this
This will return something like this:

Code: [Select]
0000407D: 1D 0A 14 0E 24 1D 11 12 1C
Essentially, a character relative sequence calculates the relative change in values between each character using ASCII values, and searches for that. I used a "?" for the space because it's unlikely an actual space will be the same distance from "e" and "t" as it is in ASCII. The "?" is a wildcard that means any byte.

In fact, that "0000407D" is the location of where the guy in the cave tells link "It's dangerous to go alone. Take this.".

The only wildcard in character sequences is the ?. But in numeric sequences, you can also use "+", "-", and "x".

"+" means the value increases. It can be any value, it just must be larger.
"-" means the value decreases. It can be any value, it just must be less.
"x" means the value changes. It can be any value, it just must be different.
"0" can be used if you want to check if the value doesn't change.

For example:

Code: [Select]
java RelativeSearch zo.nes 8 false 20 + + - - -
This returns:

Code: [Select]
000081CF: 1B 2F 6F CF CA 6A 39
1B first changes to 20, then it increases to 6F, then increases to CF, then decreases three times to 39.

Another example:

Code: [Select]
java RelativeSearch zo.nes 8 false 0 0 0 x 0 0 x 0 0 0 x
This returns:

Code: [Select]
000054F8: 00 00 00 00 F7 F7 F7 FF FF FF FF DC
As you can see, the first value, 00, doesn't change three times, then changes to F7. Then, it changes to FF, then doesn't change three times. Then finally it changes to DC.

The next one I've written is a tile editor for NES games.

Spoiler:
The tile editor allows you to import and export tiles, as well as dump all the tiles within a single ROM.

For example, if I were to type:

Code: [Select]
java TileEditor mario.nes -e 2104
I'd get this as an output:

Code: [Select]
▓▓▓▓           
▓▓▓▓▓▓▓▓▓▓     
░░██░░         
░░██░░░░░░     
░░░░██░░░░░░   
░░████████     
░░░░░░░░       
████   

That is the front of Mario's head.
The "-e" means "export", and the "2104" is the tile ID (memory address divided by 16).

If I want, I can dump all the tiles in the entire ROM into a single file using "-d".
The number after "-d" says how many tiles you want per column.

If I were to type:

Code: [Select]
java TileEditor mario.nes -d 5 > dump.txt
That would produce a pretty large text file, which I'll post here.
You can start finding the graphics around #2100.

We exported a single tile just a little while ago, but we can also import custom tiles.

If we export our Mario head to a file like so:

Code: [Select]
java TileEditor mario.nes -e 2104 > head.txt
We can then edit the text file. Let's say we change it to Mario without a mouth:

Code: [Select]
▓▓▓▓           
▓▓▓▓▓▓▓▓▓▓     
░░██░░         
░░██░░░░░░     
░░░░░░░░░░░░   
░░░░░░░░░░     
░░░░░░░░       
████           

We just save that as a text file, then we can import that into the ROM like so:

Code: [Select]
java TileEditor mario.nes -i 2104 < head.txt

The third program is very simple, but rather useful. It allows you to create a map file which you can then use to easily convert strings into their hex values and back again.

Spoiler:
This program lets you convert strings to hex values, and back again, based on a map file.

Here's an example of a map file:
Code: [Select]
48 = A
49 = B
5A = C
10 = a
11 = b
12 = c
01 = wa
02 = ta
03 = shi

You can then use something like:
Code: [Select]
HexMapper custom.map AbC
That will output:
Code: [Select]
48 11 5A
Or another way to use it is:
Code: [Select]
HexMapper custom.map 1 2 48 3
That will return:
Code: [Select]
wata48shi
Note that the hex values must be on the left side on the equals sign and the spaces around the equal sign are required.
(I required it so you can use "=" as an actual character.)

It actually supports any base (you can use decimal instead of hex).
I just mainly use hex.


All this can be found a the Github page I linked to at the top.
I will probably update this with more tools once I develop them.

Again, I'm new to this so I'm still learning, so as I learn new stuff I'll probably make more tools.

tvtoon

  • Sr. Member
  • ****
  • Posts: 371
    • View Profile
Re: Cross-platform Command-line Tools (Relative Search, NES Tile Editor)
« Reply #1 on: June 07, 2016, 10:09:50 pm »
If you are working on JAVA, it is a better solution to use the TileMolester code, as it is ancient stuff or as close to CLI as possible.

amihart

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Cross-platform Command-line Tools (Relative Search, NES Tile Editor)
« Reply #2 on: June 08, 2016, 03:01:15 am »
If you are working on JAVA, it is a better solution to use the TileMolester code, as it is ancient stuff or as close to CLI as possible.
I'm not sure what you mean.

I'm not doing this because it's old. CLI programs are useful in development because you can control them with scripts, unlike GUI programs. For example, I was translating the menu in Famicom Jump and I needed a custom font, so I simply create a folder with all my font files, then I wrote a script that will apply all of them to the ROM in the correct places.

There's 68 font files, I'm too lazy to draw 68 images myself, so they were all generated from another script.

Code: [Select]
i=16901
for f in *.tile
do
if [ "$((i-16901))" -gt "58" ]; then
java TileEditor fj.nes -i $((4+i)) < $f
else
java TileEditor fj.nes -i $i < $f
fi
i=$((i+1))
done

That's an example of writing a script to control the NES tile editor.

And my NES tile editor is complete, as I've uploaded it it works perfectly.