Edit Hex

Required:

Files:

  • Windhex
  • Super Mario Bros (Nes) rom

One of the basics when it comes to romhacking, is of course to actually edit hexadecimal code in a rom. Although it may seem easy at glance (it actually is quite simple), there could be some misunderstandings, especially for those who doesn't have any knowledge in hex (if you skipped the first chapter, I'd suggest you read it first)

Since we won't produce our own fully fledged hack in this chapter, we're going to use Super Mario Bros (Nes) as our example. This rom has already been hacked throughly by many others, and several programs exists that allows you to change text, graphics and level layout without knowing a single bit about romhacking.

But since the purpose of this chapter isn't to hack SMB as much as teaching you to edit hex, we're going to use ut anyway. Therefore, in order to follow along with our examples, you'll need a copy of the Super Mario Bros rom (US version). Make sure that you download the right versions, in order to avoid differences in the code between your rom and the rom found in the examples.

Apart from a SMB rom, a hexeditor is also needed to alter the code. We'll use Windhex in this case, so you can either download it from our hexeditors page or via this link.

And finally, you need an emulator to play your rom on. As long as it can play Super Mario Bros without any bugs, it doesn't really matters which one you choose (although this tutorial uses NESten).

Now then, what we're going to do, is simply to change the starting level in the game by replacing some hex values in the rom, that stores the information about which level to load. Don't worry if you've never used Windhex before. This tutorial will be as descriptive as it possibly can.

First, copy your rom into a separate romhacking folder. Since we're altering the code, chances are that the rom will stop functioning. And you don't want to mess up your only copy of the game, do you? When you have a copy to work with, open it up in an emulator and start a new game. If you're playing the right game, it should look something like this:

This isn't really related to hex editing at all, but at least you know how it looks before we apply the changes.

Now open up Windhex, go to the menu in the upper left and click "File > Open File for Editing (Ctrl+O)".

Browse untill you find your rom and open it. Upon doing this, you'll see the code in Windhex, divided into three columns.

The first column (starting from the left) is simply the offset for the hexadecimal (middle column)to the far left on every line.

In other words, it's the adress of every hexadecimal in the rom, "00000000" for the first, "00000001" for the next one, all the way to the second line that starts with "00000010" and so on. Note that there's 16 hexadecimals on every line.

The middle column contains the actual code, written in hexadecimal. Windhex automatically alternates color between every pair, making it easier to distinguish them.

To the right is the same code as in the middle column, but this time it is typed out using a specified table. By default, a standard ASCII-table is being used (this is a function in Windhex and not the rom). How to use tablefiles will be covered later on. Hexadecimals that doesn't have any ASCII equivalents are simply represented by a ".", no matter which hexadecimal. If you move the cursor using Up/Down and Left/Right, you'll see that it affects both the middle and right column (because they display the same code).

But for now, we'll focus on the middle column. Before we can edit the level data, we first have to find it. This on the other hand, isn't anything you'll find on this page. For that reason, I'll simply give you the adress of the data, so that we can proceed.

But before we continue, the level data findings should be credited to Dahrk Daiz and his excellent documentation on Super Mario Bros. It is avilable here on romhacking.net.

The adress for the first levels data is 0x1CCC, which would be the 13:th spot (C=12, plus one since the first number is 0) from 00001CC0 in the left column. To get there as fast as possible, we'll use Windhex Go To-feature. Simply click "Search > Go To Offset (Ctrl+G)" in the menu, and you'll see a new window telling you to insert the offset.

Insert "1CCC" in the top field and click "Done". Since we're typing in the adress/offset in hex, we'll leave "Hex-decimal" checked. This way, you'll automaticly jump to your designated offset, rather then having to scroll down to it by hand (not an option when you're working with roms of larger size).

If you used the right rom, and did everything right up until now, you should be on a line of code looking like this:

If the hex values doesn't correspond, despite you being on 00001CC0, chances are that you're using a different (or an altered) rom. Feel free to try other roms, otherwise you could just continue reading.

To be precise, the hexadecimal "25" you see on this line, is the value that decides which level data that should be loaded when level 1-1 starts. By changing this value, we can specify other levels instead.

First of all, Windhex has two modes of editing, Hex and Text (ASCII). We want to edit directly in Hex, so make sure that "Hex / Edit Mode" is NOT checked in the Edit menu.

Now we're ready to do some changes. In this case, we will change the hexadecimal "25" to "35" instead.

With "25" selected in the middle column, press "3". As you'll notice, nothing happens with "25". This is because Hexadecimals always are typed out in pairs, thus any changes won't show up until you have typed in an entire 1-byte number. Upon pressing "5", the number 25 changes to 35.

Now that we have changed this hexadecimal, we must first save the file before any changes take effect. To do so, simply click "File > Save File (Crtl+S)" in the menu.

When the file is saved, open up your rom in an emulator agin to see the changes take effect. This is how the first level looks now:

You'll notice how the background on the titlescreen has changed, that's because the game uses the first level for background as well. Also note that even though the level itself has been changed, other data like respawning points still remain the same. Before the game will be playable, data like this also has to change, but we won't cover that here.

Now you have successfully edited a hexadecimal. If you want to do some more changes, take a look at the "29" to the right of "25".

This is the data that decides what to load when level 1-1 has been cleared. Try changing it from 29 to 2A, and see what happens when you finish 1-1.

Unfortunately, this site won't cover the subject any further then this. If you're looking to produce your own hacks of this kind, some guidelines are to first learn more about localisation of level data.

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.