Hex Editing Tutorial (with SimCity 4 Example)
How to change the resolution within your "Simcity4 Deluxe" config file to something widescreen. Along the way you'll learn some basics about hex editing. This article was inspired by Komoto on the forums. There are three things you need to do before starting.
First, you need a Hex editor program. I use a program called EditPad, which gets the job done and is free. I'll be using this editor from here on out.
Second, MAKE A BACKUP OF YOUR CONFIG NOW! I found my config file under My Documents\Simcity 4\.
Third, start up Simcity4 Deluxe and go to the settings menu when the region map loads up. Set the resolution you're playing at to 1600x1200. You have to do this because after some trial and error I discovered it was only possible to change the config file if it had been last saved at 1600x1200.
Now open up your SC4 Deluxe config file in EditPad. Onced opened, change view to hexidecimal (Ctrl-H). You should see a screen like this:
Ignore the first and last columns. We want to focus on the two main columns in the middle with all the numbers/letters grouped in 2's. These are hexidecimal numbers in all their glory! Each 'group' represents a numeric value from 0 to 255. What are those letters doing there? The letters represent numbers greater than 9. 'A' stands for 10, B for 11, C for 12, D for 13, E for 14, and F for 15. Add the numbers symbols (0-9) and letter symbols (A-F) together and we get 16 total symbols used to represent numbers in hexidecimal. Hex- stands for 6, dec- stands for 10, put those words together and you get hexidecimal. Brilliant! You can also probably figure out from this that our "base 10" number system (just using the symbols 0-9 to represent numbers) is called decimal. Brilliant!
Before going on, let me explain some syntax stuff I will use concerning hexidecimal numbers. Ordinary old decimal numbers are written like you've always done, just the numbers themselves. However, when we programmers write hex numbers in code, we precede them with two characters, a 0 and an x. The '0x' is just a marker, nothing more. It's so the computer doesn't get confused as to whether the programmer, when he typed 10, meant decimal 10 or hexidecimal 10 (both have very different values!). Programmers also like hex numbers to be in groups of 2's, 4's, and 8's, even if the leftmost numbers are zeroes which you'd normally drop in the decimal system. This is to make many numbers placed side by side easier to read. So, a 9 in hex is written 0x09. A 10 in hex is written 0x0A, an 11 = 0x0B, and so on. A 10 in hex could also be written 0x000A, or 0x0000000A, and would mean exactly the same thing.
To clarify a bit on hexidecimal numbers, in case you're still a little confused. It is best to think of the letters as just symbols and nothing more. To make this clear with an example, think what happens when we add 1 + 15. In hexidecimal this is 0x01 + 0x0F. The answer is 0x10. Notice the F resets to 0 and the left number goes up by one, just like in decimal when 19 + 1 = 20. Going from here, we see that 0x10 = 16, 0x11 = 17, 0x20 = 32, 0x30 = 48, up to 0xFF which stands for 255. Add one more to 0xFF and we get 0x0100, or 256.
Now that we understand hexidecimal numbers a bit more, let's see what we need to do with this config. What we're going to do is look for the numbers in the file that represent the resolution 1200x1600, and replace them with our custom resolution. Just for sake of this tutorial this custom res is going to be 1680x1050, the size of my monitor.
Converting to Hexidecimal
First things first, we need to convert 1600x1200 to hexidecimal. Do you know these values off the top of your head? Neither do I. So open up your trusty Windows calculator and change the view mode to scientific. Make sure that the radio button labeled 'Dec' is selected. Type 1600 into the calc, and click the Hex radio button (see below).
What you should see is '640', or, correctly written, 0x0640. Convert 1200 to hex and we get 0x04B0. While we're here let's get the decimal equivalent of our custom resolution. This comes out to be 0x0690 (1680) by 0x041A (1050). So, the replacement we're going to be doing in our config is:
0x0640 -> 0x0690
0x04B0 -> 0x041A
To make it clearer as the what this find/replace looks like in EditPad, let me display the numbers in the block sequences of 2's like we see in the editor:
[06] [40] -> [06] [90]
[04] [B0] -> [04] [1A]
All I've done is divide the numbers into groups to make is clearer what the blocks would look like in the editor. So is that it? Can I search and replace now? Well...go ahead, see if you can find either of those sequences in the config file you've loaded up. You won't be successful though, as there's one more thing you need to know about.
Numbers, when stored in a file, are placed in reverse order in groups of 2's. So, when we go searching for the number 0x0640 in EditPad, it's not going to be in the block sequence [06] [40] like we'd expect. The blocks are going to be switched, and so we need to look for the sequence [40] [06] (in that order!).
Putting this all together, than means the replacement will instead look like this:
[40] [06] -> [90] [06]
[B0] [04] -> [1A] [04]
Notice that within the block the digit order has NOT changed, just the order of the blocks themselves.
Finish It
The first screenshot shows what blocks are going to be changed. The second screenshot shows the same blocks, after they have changed.