Tablefiles

Required:

Files:

  • Windhex
  • Super Mario Bros (Nes) rom

In this tutorial:

Those who attempt to alter a roms text, be it for a translation or a just-for-fun texthack, will sooner or later come across tablefiles, as they are one of the more convenient options when it comes to typing text in hex.

Now, everyone who has read the first part of the Text-chapter knows that when you're typing text into a rom, you do it by inserting the hexadecimals that correspond to the correct letter of whatever alphabet you're using. If you, for example, wanted to type "A", you would do it by inserting the hexadecimal that displays "A" on screen. This can be done by opening your rom in a hexeditor and simply inserting the hexadecimal (let's say that it's "0A" in this case) by hand.

But what if you wanted to type "Communications sattelite" instead ? Obviously, you could do it in the same manner, but let's face it: Typing text in hex really doesn't work out in the long run, unless you have lots and lots of time to spare. However, using tablefiles, this process becomes so much easier.

Using tablefiles, we can assign some (or all) hexadecimals to specific keys on our keyboard. For example, we could set "0A" to the key "A", so that the next time we pressed the"A"-key, the hexeditor would automaticly insert the hexadecimal "0A". This way, we can type on our keyboard using the standard latin alphabet, and the hexeditor would automatically insert the correct hexadecimals for us.

And not only that. The text in our rom would now be easier to view, since the hexadecimals we specified in the tablefile sometimes are displayed as regular text in hex editors (Windhex for example).

All of this may sound wonderful, but there's a catch. There's no way to tell which hexadecimal that stands for which letter simply by reading the text during gameplay. We used "0A" as "A" in our example, but it could have been anything between 00 to FF. The only way to find this out, is by locating the text (or rather, the hexadecimals displaying the text) in our rom (using a hexeditor) and check just which hexadecimals that are being used to output the text.

The problem with THIS on the other hand, is that unless you know which hexadecimals to search for, you won't fimd them at all. And without finding them, you won't find out which ones to search for. You see the predicament we're in, don't you?

This would make it pretty impossible to find anything, but there is one more thing that goes true for many (if not most) roms. In a rom, the letters in the alphabet are usually stored in a certain order. Namely this one:

A B C D E F G H I J K L M N OP Q R S T U V W X Y Z

a b c d e f g h i j k l m n o p q r s t u v w x y z

And since they all have a fixed position, we can utilize something called a...

Relative Search

Given that there's no compression in our rom, and that every letter we're searching for has its own hexadecimal value, we can do a relative search. By doing this, the hexeditor checks each given letter (listed in your search) and compares its relative position to the other letters in the word you're searching for.

Because of this, a relative search can only be done with letters from the upper OR lower part of the alphabet. Do NOT mix upper and lower characters, since chances are that they won't have a relative position compared to eachother.

But what exactly do I mean by a "relative position"?

In the alphabet, every letter has a relative position compared to eachother. For example, the letter "K" is located three steps ahead of "H" (...H I J K...). If you were to compare K:s position with H:s, you could say that K:s position is "+3". On the other hand, if you compared "K" with "P", you'd get "-5" (...K L M N O P...). In other words, no matter how or where the aplhabet and its letters are stored, "K" is always placed 3 steps ahead of "H" and so on.

Suppose we ordered Windhex to do a relative search for the word "MARIO" in our Super Mario Bros rom.

The first letter in this word is "M", and it has the position "0" since there's no letter to compare its position to.

The second letter is "A", and has the relative position (or value) "-12" (minus twelve). This is because the letter "A" comes 12 letters before "M" in the latin alphabet:

The third letter is "R". It has the relative position of "+17" since, you've guessed it, it comes 17 letters ahead of "A".

The fourth letter is "I", therefore it has the position "-9". And last is "O", with a position of "+6".

This means that when we perform a relative search for the word "MARIO", we do in fact search for a string of hexadecimals where:

  • The second Hex is 12 values less then the first
  • The third Hex is 17 values higher then the second
  • The fourth Hex is 9 values less then the third
  • The fifth Hex is 6 values higher then the fourth

M(0) A(-12) R(+17) I(-9) O(+6)

As you can probably guess, there aren't that many strings of hex that follow this exact pattern. Because of that, the only searchresults we'll be getting, are strings of hex that actually says MARIO. Of course, chances are that a string of hex (not text) following this pattern actually could exist in our rom, but since it's so small in size (being a nes rom and all) it's not as likely as when you're search, say, a N64 rom.

Even so, it's important to remember that a relative search only searches for hexadecimal values that follow the pattern you input, not for actual text. Any results you might get this way, can always be other code then text.

In case you're having problem with multiple (non-relevant) hexstrings showing up when you're performing a relative search, simply try searching for a longer pattern. The more specific pattern, the less chance is it that you get a non-relevant hit. And by more specific, I mean longer.

0 +3 -1 = Not very specific.

0 +1 +2 +9 -5 +16 +1 -1 -3 -4 +5 +5 = Specific.

However, not everything can be located with this method. Numbers, punctuation and other code usually aren't stored in a specific order i roms, because of that, you'll have to limit your search to words only. If you need to search for strings of text with non-searchable code in it, some hexeditors allow you to type "*" as a wildcard (can be anything).

Our first Tablefile

Enough with the talking, let's locate the word "MARIO" in our hexeditor (Windhex) and build a tablefile using the information we can get from the results. First of all, open up Windhex and load an unedited copy of your Super Mario Bros rom. Now that you're faced with the usual amount of hexadecimals, start a relative search by clicking "Search > Relative Search" (Ctrl+R).

Now you should see the window where you can input the word you're searching for. Type "MARIO" in the emtpy field, and click "Find".

After that, Windhex will search through the rom for a set of hexadecimals that follows the pattern "0 -12 +17 -9 +6". Since this rom contains the word "MARIO" in more then one place, the results-window will list every offset in the rom that gives a positive match.

For your information, the first result (the one on top of the list) is the same name that we altered in the text-chapter. From here on it doesn't really matters which "MARIO" we pick, but let's stick to the first one just to be safe. Click on the top line to make Windhex jump the right offset, then close the results-window.

Now that we have located a word using a relative search, we can begin constructing our tablefile using the data we find in the word. For example, since we searched for the term "MARIO", the first hexadecimal in our result (i.e where the flashing cursor points right after jumping to the right offset) should be "M". The next one should be "A" and so on. Look at the hexadecimal for "A" (the one next to "M"), and note its value (if you did it right up until now, it should be "0A").

Open up a blank document in notepad (or whatever text editor you prefer) and type:

0A=A

Then press Enter.

Now, this is where your knowledge of hex comes to good use. If "0A" is "A", then "0B" should be "B", right? Exactly. Since every letter in this rom is stored in exactly the same way as in the alphabet, you can easily calculate the remaining letters simply by adding 1 to the hexadecimal for the previous letter. In other words:

0A=A
0B=B
0C=C
0D=D
0E=E
0F=F
10=G
11=H
12=I
13=J
14=K
15=L
16=M
17=N
18=O
19=P
1A=Q
1B=R
1C=S
1D=T
1E=U
1F=V
20=W
21=X
22=Y
23=Z

When you have filled in the values above, click "save as", and save your tablefile as "mario_table.tbl".

please note that the filename MUST end with .tbl

Also remember to select "All files" as format before saving. I.e, make sure you don't save it as .txt.

Without doing anything else in Windhex, click "File > Open Table File > #Table 1".

Browse until you find your tablefile and load it. If you did it right up until now, the right column should now looke like this:

There you have it, some of the text used in Super Mario Bros. If you didn't get it right, you can always copy the values I typed as an example above and paste them into your table file.

Note that Windhex also has its own tablecreator. You can access it by clicking "Tools > Table Editor/Maker" depending on if you want to create a new tablefile or just modify an old one.

As you can see, the text look a bit jumbled with all the .'s and letters that doesn't seem to belong to a specific word. When it comes to the .'s, you already know that Windhex displays unassigned hexadecimals this way.

As for the letters, they are simply hexadecimal code that happens to have the same value as the ones we inserted into our table file. Take the word "TIMEW" for example. The letter "W" isn't really a part of the word "TIME", it just so happens that the hexadecimal "20" is written just after it. And since "20=W" in our table file, Windhex displays every "20" as "W", no matter if that hexadecimal is a part of the text or not.

Just for the record, every letter used in Super Mario Bros is now typed into our table file. But since this game uses some punctuation as well, let's fill those in before we move on actually editing the text. One important thing is the blank space that comes between each word. To find out which hexadecimal that produces a blank space on screen, take a sentance that you know has a blank space written in it.

The most obvious choice given the limited amount of text, is the frase "GAME OVER". Place the cursor on the "." between "E" and "O", and check its hexadecimal value in the middle column. If you did it right, it should be "24".

Now head over to your table file in notepad, and fill in the value

24= 

at the bottom. Though it's not showing, that line actually says "24=[blank space]". Highlight it and see for yourself.

When you have typed that into your tablefile, save it agin, and load it once more in Windhex. This way, some of the frases will show a blank space between each word ("GAME OVER", "TIME UP"; "WELCOME TO WARPZONE").

Two more values you can find by comparing the text in the game with your code, is

28=-
2B=!

Type them into your tablefile and reload it.

Now that you have a tablefile, you can proceed to editing text using tablefiles.

For those of you who can't get your own file to work, here's some do's and don'ts.

  • Always type your values on a single line
  • Never type anything else then the exact value of a hexadecimal. If you type "3A=G [other stuff]", then the hexeditor will display "3A" as "G [other stuff]".
  • If your tablefile won't load at all, itsometimes helps adding a new line at the end of the document with nothing on it.
  • Always save you file as name.tbl
  • Make sure you're using the right file format
  • Never assign the same hexadecimal more than once
  • Never assign hexadecimals to keys that the Hexeditor uses for other functions (for example, Thingy uses "@" to input custom hexadecimals)
  • Sometimes a game uses more then one set of characters. In that case, you might need more than one table to find all the text
  • If a game uses both the upper and lower alphabet, you'll have to locate them both and figure out their hexadecimal values

Table Files with Nesticle

Did you have troubles finding the correct values using a relative search? Well, as long as you're hacking a Nes rom, there's a much simplier way to do this. For that reason, you're going to need the emulator Nesticle.

The basics are still the same. We will attempt to locate the hexadecimals used to display text, but this time we won't have to search for them.

The first step is to open Nesticle and load an un-altered copy of your Super Mario Bros rom. Normally you'd play until you see some of the text (that you want to find the hexadecimals for) on the screen, but since Super Mario Bros has some text on the title screen, we can go at it right away.

Press F2. This will bring up a new window, with some of the graphics being used. To the upper right, you'll see the alphabet. All you have left to do now is to click on a letter, preferably "A". This will open up yet another window, with the actual letter being displayed (in hi-res).

But besides from the letter, there's a hexadecimal typed out above it. And that's about it. The hexadecimal you see is the hexadecimal for "A" in Super Mario Bros, "0A". Now you can either figure out the remaining letters by yourself, or repeat the process with the remaining part of the alphabet and the punctuations (i.e, by clicking on them one by one).

Although this process works the same way regardless of the game you're using, it only works on Nes roms (obviously). When working with other platforms, you'll have to use relative searching.

Back to Top

 

Copyright © 2007 Romhacks.net
Code, Layout and tutorials are Copyright © by Aeris130. Other material, such as programs, are copyright to their respective authors. We do NOT claim copyright regarding the actual information described in the tutorials, as the author didn't play any part in discovering them in the first place.