Relative Searching is a technique used by ROM hackers to find out what the hexadecimal code for a character is in a video game.

Relative searching is needed because when hackers open up a ROM in a hex editor such as Thingy, and look at the part of the ROM which contains a block of text, they do not see the text as it is displayed during the game. What they see instead are sets of hex values which signify letters. These are converted to letters and therefore to form words in game. But to change the letters out of game, we need to know what set of hex values signifies what letter. They can find this out by relative searching.

Relative searching is a process which only works when the codes that signify an alphabet are arranged in alphabetical order. For example, if the code for A is $28, the code for B has to be $29 and the code for C must be $2A. Luckily, most games have their letters arranged in this way.

The best way to illustrate how relative searching works is to do one. So let's all pull out our copy of Tile Layer Pro and our copy of Hexpose (you should find them for download at in the relevant utilities section), our copy of Nesticle (from and our copy of the NES ROM for Super Mario Brothers. I can't tell you where to download that, but suffice to say that it was probably one of the most popular NES game ever, so it shouldn't be too much of a struggle to find.No, seriously, go get them, we'll do this together. It'll be like a Disney sing along fun video, but with MORE fun. And less retardedness.

How to Relative Search. Idiot*.

  1. Make a Backup of your ROM. In fact, make more than one. You will almost certainly end up doing something retarded, corrupting your ROM, and with no backup you're screwed until you can find one on the Internet again. And that can take time. So to be safe, make a backup of everything you work on. Unlike many other applications, Hex editors very rarely have an Undo command, so learn to live with it.
  2. So, what we want to do first is confirm that the font is stored in alphabetical order in the game. I already know that it is, and nearly every game is like this, but you are idiots so I'll have to show you how to do it. And it's fun to have a look at the code so let's do it. You Idiot.
  3. Open up the ROM in Tile Layer Pro. If it's all fucked up you probably forgot to unzip it. Idiot.
  4. TLP should be in NES 2bpp mode. If it isn't, it should be. Make sure your ROM has a .nes file extension and it should open with NES settings automatically. If this doesn't happen, you are an idiot.
  5. So, scroll to the bottom of the file, past all the nasty nasty machine code, and you should see some lovely four colour tiles which look vaguely like things out of the game. Well done, Idiot. Past that you should see an alphabet, which, shockingly enough, is in alphabetical order. See, I told you it would be, didn't I? If only you'd just believed me rather than being an Idiot. Idiot.
  6. Now that we know the alphabet is in the right order, we can relative search. You could do it quite easily, but without knowing why you are doing it you would just be being an idiot. So listen up.
  7. No matter what the value for... say... the letter P, the letter R must have a hex value that is 2 more (the alphabet goes P, Q, R, remember, Idiot?). This means that if there is a hex value followed by another which is two larger, these two values could signify PR. But it's incredibly likely that this combination will occur in other places apart from the tet blocks, so we would find too many values.
  8. So let's find a longer string. Try... PRINCESS. This means that the value will go up two between the first and second values, then down 9 to the third value, and so on.
  9. The differences should be plus 2... minus 9.... plus 5.... minus 11.... plus 2.... plus 14.... no difference.
  10. A Relative Search will let us type in a word (in this case, Princess), work out the relative differences that should occur between each value, and then search for that set of differences in whatever ROM you are using. If there is ntohing nasty like compression or DTE, and the word exists in the game, then it should be found.
  11. Still with me, Idiot? Need a lie down?
  12. So, open up Hexposure and load Super Mario Bros ROM.
  13. Ooh nasty scary HEX. Don't run away yet, Idiot...
  14. Press escape and then press right until you see a menu open which has a "Relative..." option. Press enter on that option.
  15. Type in PRINCESS in the box that appears. It's a nice long word, so make sure you type it right. If you mess it up, you'll look like an Idiot. Idiot.
  16. Press Enter.
  17. "Build a Font Table based on search results?" Well, yes, I think it would be quite useful to be able to read the rest of the text. Only an idiot would say no. You're an idiot, but you're a special idiot, so you'll say YES.
  19. You see? The relative search has found the string, and because it guessed that it's the right one, it's worked out what the values would be for each of the other letters.
  20. That's why you can read bits of text like "MARIO" and "LUIGI" in the right hand box. You've found the piece of code which governs the messages which are played once you finish a castle. You know, Thank you Mario! But our Princess is in another castle!. If you wanted the text to say "Thank you Mario! But yo bitch be chillin with some home dog pimp daddies!"... you are out of luck. I knew an Idiot like you would want to do something idiotic like that. Idiot.
  21. The problem is that the game is supposed to take a certain amount of letters at that point and display them. Entering more letters will only leak it into the next message, and quite probably bugger the whole thing up.
  22. But we can change the text, so long as we keep to the original length.
  23. Think of a word the same length as Princess. I know you don't know many words that long, so I'll help you. Try MISTRESS. It's the same length, and it's almost humorous.
  24. Still in Hexposure, you'll want to be editing in Text mode. If your cursor in the right hand window is a white block, that's fine. If not, then press Tab once. It should become a white block.
  25. Position the white block over the P at the start of the word PRINCESS.
  26. Turn on Caps Lock. Sorry, but the game doesn't have a lower case font, so you'll have to live with looking like a shouting old Granny. It all looks fine in the game, I promise. You Idiot.
  27. If the cursor is in the right place, type MISTRESS.
  28. Save the ROM using the File... Save command. Come on, stop crying, it wasn't that difficult.
  29. Open up the ROM in Nesticle.
  30. Now comes the really, really hard bit.
  31. You're going to have to play through the first four levels of Super Mario Brothers. Come on, it's not that hard. Use your initiative, idiot.
  32. Once you get rid of the first Bowser (you have to jump over him and then onto that thing. It makes the bridge fall away, see) you should see a toadstool guy. If you don't, check that you are playing the right game. You may have accidentally picked up a copy of the Great Giana Sisters. This is Wrong.
  33. Hopefully, the Toadstool will say "Thank You Mario! But our Mistress is in another Castle!"
  34. If this doesn't happen, you are an Idiot.
  35. If it does happen, you are still an idiot, but a lucky idiot who has learned how to use Relative Searching to replace text in a ROM file. You lucky thing.

The possibilities of this are almost endless. If you can work out something to say which fits the same space as the original text in any uncompressed game ROM, you now know how to relative search to find the codes, create a Table File (that was done for you, without you even having to try. You lucky thing) and add in some hilarious alternative text. Okay, we still need to work on that last one.

I hope you find this useful. I am planning a whole series of writeups on How to ROMhack here on E2, so if you enjoyed flexing your hexing muscles this time, I bet you can't wait for the next one.

Couldn't get it to work? Comments or questions? /msg me and we'll work it out.

yerricde says "Open the rom in nesticle? Ouch. I'd suggest FCE Ultra instead." - agreed Nesticle can be slow for gameplay, but it does have pattern tables. And we all love them.

Pseudo Intellectual says "re Relative search: engaging style, so long as it's used sparingly 8)"

* - this nice friendly style of gently guiding people through something by calling them Idiots was stolen from Gideon Zhi of Aeon Genesis Translations. He pioneered it in his JUST DO IT IDIOT™ document which introduced me to ROM hacking. Sorry, Gideon, but I stole from the best... And if you don't like the style of my tutorial, be thankful I didn't do it the original way - ALL CAPS. Ouch.

Log in or register to write something here or to contact authors.