Re: Third map tutorial: How to edit tiles of any acre

Discuss anything related to hacking ROMs of the Telefang games here.
Blaziken257
Posts: 983
Joined: Fri Dec 22, 2006 11:52 am

Re: Third map tutorial: How to edit tiles of any acre

Post by Blaziken257 »

This is my third map tutorial, and probably the most fun one to do. In order to do this, it REALLY helps if you know how to edit the game's maps themselves (in other words, telling the game which acre the game should load in each part of the map). If you don't know how, then you should read this tutorial first.

This tutorial tells you how to edit the acres themselves. You know, the layout. You can make it completely look different! This will not focus on any sprites on the map, as that's coded separately (and honestly, I haven't figured out how that works yet).

Oh yeah, and to figure this out, you also need to know how hex works, and how to multiply and add using hex.

So first, you want to know what acre you want to edit. To know this, you first need to know which location it is in (example: the overworld map, Toronko Village Water Station, etc.) There is a starting offset depending on which location the acre is in (I had to figure this all out by trial and error):

* 18C000 -> Ion Island Cave
* 190000 -> Marts & Houses, Burion Relic: Floors 7-9, Human World
* 194000 -> Burion Relic: Floors 1-6
* 198000 -> Kakotos Relic
* 1A0000 -> Overworld Map (Top-left, top-right, and bottom-left quadrants), Antenna trees (same quadrants)
* 1A4000 -> Overworld Map (Bottom-right quadrant), Antenna trees (Bottom-right quadrant), Toronko Village Water Station, Kurinon Village Cave, Paparuna Lake Laboratory, Panses Village Cave
* 1A8000 -> Toripa Antenna Tree Cave, Peperi Mountain

You'll notice that a couple of locations are in different banks. For example, the bottom-right quadrant of the overworld is in a different place, and Burion Relic is also broken up too. You'll also notice that 19C000 has no starting offset. This is because this is where the game's maps and warps are stored, among other things.

Keep this starting offset in mind, as you'll need it later.

Second, you need to find the hex value of the acre you want to modify. You can do this with two ways:

1. Go to the acre, then use the Memory Viewer to look up address 0xC903. This is the simpler method, but it may be more time consuming because it may take a while to get there.
2. Locate the position that the acre is on the map. Find the coordinate of it. Then, look in the ROM and find the map of the acre you want to modify. For offsets, click here. Once you find the offset for this, then locate the coordinate of it in the ROM (it goes from left to right, then from top to bottom, it's always 8x8). You'll get your hex value here.
3. Here is where you need to do some math. It REALLY helps if you have a calculator that can do hexadecimal. The Windows calculator can calculate in Hex in scientific mode. Now take this value that you just obtained, multiply it by hex 50 (this is 80 in decimal), then add this to the starting offset you find a while ago.
4. This is where the data for the acre you're modifying starts. Conveniently, the format is completely uncompressed (unlike games like Super Mario Bros., where it uses an annoying compressed format). This means that each byte is a 16x16-pixel tile. The data goes from left to right, then top to bottom. There are 10 16x16-pixel tiles in a row, and 8 in a column, resulting in 80 bytes for each acre. (Remember, the status bar takes up 16 rows of pixels, resulting in a smaller screen). And because of this, the offset where the acre data ends is hex 4F (79 in decimal) bytes after it starts.
5. Each map uses a different tileset. In these images I made, it goes from left to right, then top to bottom. Here are tilesets for all the maps (note that for most of them, many of them are just glitch tiles, and lots are unused):

Overworld
Antenna Trees
Toronko Village Water Station & Kurinon Village Cave
Houses & Marts
Paparuna Lake Laboratory, Panses Village Cave, and Ion Island Cave
Toripa Antenna Tree Cave
Peperi Mountain
Kakotos Relic
Burion Relic
Human World - Main Area
Human World - Antenna Tree
Human World - Unused Buildings

So just play around with it, and see what you can come up with!

One thing you'll notice is that in almost every map, there are a couple or so tiles that look graphically identical to each other (for example, tiles 11 and 86 in the overworld). Even though they LOOK the same, they're functionally different. Often, the first one of its kind is NOT warpable, while the second one (which is usually way after the first one) IS warpable. However, I have no idea why sometimes there are identical-looking doors.

Confused? Well, I'll do one example. Let's do the very first place in the overworld:

Image

First, you have to find the starting offset. Looking at the list way above, you'll see that the bottom-left quadrant of the overworld starts at 1A0000. You'll need this for later.

You need to identify where this is on the map. I've said this many times, but the overworld map is really four smaller maps joined together. So we're only worried about the bottom-left part. Now looking at it, you'll see that this is in the 5th column in the 3rd row:

Image

Now we have to find the map data. Using the link on DataCrystal, you'll see that the data for the bottom-left quadrant of the overworld is found from 19C50E-19C54D. That's the data we want:

80 81 82 83 84 85 86 87
88 89 8A 8B 8C 8D 8E 8F
90 91 92 93 94 95 96 97
98 99 9A 9B 9C 9D 9E 9F
A0 A1 A2 A3 A4 A5 A6 A7
A8 A9 AA AB AC AD AE AF
B0 B1 B2 B3 B4 B5 B6 B7
B8 B9 BA BB BC BD BE BF


Now look at the data, and find the 5th column in the 3rd row. You'll see that it's 94. This is the hex value of the acre that we need.

Now that we have it, we need to use this to find the offset of the acre. First, multiply hex 94 by hex 50, and you'll get 2E40. Add this to the starting offset that you obtained before (1A0000) and you get 1A2E40. Bingo! This is where the data for the starting acre starts. It ends at this offset plus hex 4F, which is 1A2E8F. So the data is from 1A2E40-1A2E8F.

Time for the fun part. Here is the data for the acre:

04 03 04 17 92 92 17 03 04 03
15 11 11 11 11 11 11 11 11 01
15 11 11 11 11 11 11 11 11 03
18 0F 19 11 11 11 11 01 02 01
0E 91 0E 11 11 11 11 03 04 03
11 11 11 11 11 11 17 87 9A 01
11 11 11 11 11 11 11 88 11 03
02 01 02 01 02 01 02 01 02 01


If you look at it carefully, doesn't it look like the acre itself? Yes it does! Let's compare it again:

Image

How convenient!! That means one byte equals one 16x16 tile. For reference, don't forget that this is the tileset for the overworld:

http://img98.imageshack.us/my.php?image=tiles04bb7.gif

While playing around, I changed it to this (of course, you can do whatever you want):

04 03 04 17 92 92 17 03 04 03
15 15 15 11 11 11 15 15 15 01
15 11 11 11 11 11 11 11 15 03
18 0F 19 11 39 5E 1C 5E 5F 2D
0E 91 0E 11 39 0A 1C 0A 0A 2F
15 11 11 11 39 0A 1C 87 9A 01
15 15 15 11 39 0A 1C 88 11 03
02 01 02 01 02 2B 02 01 02 01


And what did I get? This!

Image

Totally awesome. I was kinda limited to what I can do, though. I had to keep the house where it was, or else it would have caused problems when starting the game (because the characters walk in a set path, which I don't know how to change). And I had to keep the treasure chest in the same spot, because if you move it somewhere else, you have to edit the treasure chest data, which is separate (and this will be my next tutorial). If you don't edit the treasure chest data, then the chest will be empty. And I had to keep the doors there, or else editing the warp data would have been quite a lot of work (though still doable).

Just try it out though -- it's really fun! (Hopefully you can do better than what I did...)

Oh, and I'd like to end this post with a proof-of-concept patch. This patch modifies the layout of Toronko Village Water Station -- every room looks at least somewhat different. Unfortunately, my lack of knowledge of editing sprites (both their position, and their set paths after talking to them, like the guy who rams into the locked door then runs off) limited me to what I can do, so it's not COMPLETELY different. But at least this patch can show you what can be done with it. And I figured out how to move the chest with the key in a different place without any problems, which I've been meaning to figure out for ages!
User avatar
andwhyisit
Site Admin
Posts: 1197
Joined: Fri Dec 14, 2007 9:24 pm

Re: Third map tutorial: How to edit tiles of any acre

Post by andwhyisit »

You are a romhacking genius I swear. Less than a month from now you would probably be editing sprite positions. :blink:

I sense the makings of a map editor. :D
Blaziken257
Posts: 983
Joined: Fri Dec 22, 2006 11:52 am

Re: Third map tutorial: How to edit tiles of any acre

Post by Blaziken257 »

Thanks. :) Though this is the only game where I have gone this much in depth, however. Mainly because nobody plays it, so SOMEONE has to do it. It takes tons of patience to find this stuff out -- I didn't figure it out overnight. With other games, all I can mostly do is edit color palettes (except Telefang 2 where I can edit text instead), which is kinda boring. Now if I can only figure out how to decompress tiles... but unfortunately that won't happen anytime soon...

And yeah, maybe I will figure out sprite positions. That would be cool, because I could do so much more with the game. It seems complicated, because sprites have lots of different properties:

- Whether you can battle them or not (and you can, which Denjuu they use)
- Their position
- The sprite itself
- What makes it appear/disappear (there are TONS of examples of this throughout the game)
- The direction it's facing (this has an added effect: I found that if you hack your way to a spot you're not supposed to be and you talk to certain people/Denjuu from a certain spot, they won't talk to you; for example, you can only talk to Nejiro from the left)
- Any and all dialogue

Of course, there's also another thing I need to figure out as well: There are certain events that trigger when walking in a specific place. For example, when you walk on land in the Palm Sea antenna tree, the cutscene where Kai appears triggers. Or when you first get to Toripa Village and stand in front of the tree, you get asked whether you want to enter the antenna tree or not. That will be complicated, because those are widely variable...

So much stuff...
User avatar
andwhyisit
Site Admin
Posts: 1197
Joined: Fri Dec 14, 2007 9:24 pm

Re: Third map tutorial: How to edit tiles of any acre

Post by andwhyisit »

Blaziken257 wrote: Thanks. :) Though this is the only game where I have gone this much in depth, however. Mainly because nobody plays it, so SOMEONE has to do it. It takes tons of patience to find this stuff out -- I didn't figure it out overnight. With other games, all I can mostly do is edit color palettes (except Telefang 2 where I can edit text instead), which is kinda boring. Now if I can only figure out how to decompress tiles... but unfortunately that won't happen anytime soon...

And yeah, maybe I will figure out sprite positions. That would be cool, because I could do so much more with the game. It seems complicated, because sprites have lots of different properties:

- Whether you can battle them or not (and you can, which Denjuu they use)
- Their position
- The sprite itself
- What makes it appear/disappear (there are TONS of examples of this throughout the game)
- The direction it's facing (this has an added effect: I found that if you hack your way to a spot you're not supposed to be and you talk to certain people/Denjuu from a certain spot, they won't talk to you; for example, you can only talk to Nejiro from the left)
- Any and all dialogue

Of course, there's also another thing I need to figure out as well: There are certain events that trigger when walking in a specific place. For example, when you walk on land in the Palm Sea antenna tree, the cutscene where Kai appears triggers. Or when you first get to Toripa Village and stand in front of the tree, you get asked whether you want to enter the antenna tree or not. That will be complicated, because those are widely variable...

So much stuff...
How about:

- Initial Position
- Movement Behaviour
- Sprite hex value
- Direction

and either
- Event that is called by player interaction.
or
- Id referenced by event.

and maybe
- Player interaction that triggers event?

Though I think that would be within the event itself.

Events such as calling dialogue, the appear/disappear stuff, and battles would not be kept within the sprite data. They would be stored where every other event used by the game is most likely stored. Events can be called by the map and would be either difficult or space consuming (wasted space I might add) to assign to the sprite data anyway.

You are looking at probably 6 or 7 bytes of information per sprite on the map.

...unless the sprites are placed by events? Hmm... nah!
Blaziken257
Posts: 983
Joined: Fri Dec 22, 2006 11:52 am

Re: Third map tutorial: How to edit tiles of any acre

Post by Blaziken257 »

That's really complicated... but I really don't feel like figuring this stuff out now. These tutorials always take me a long time to write, so I'm going to take a short break for now.

Oh, and I also forgot to mention that I have no idea how to create hacking utilities. So unless someone (like swampert22) does, we're all stuck with using a hex editor for this. Oh well.
User avatar
Sanqui
Posts: 736
Joined: Sun Dec 16, 2007 12:25 am

Re: Third map tutorial: How to edit tiles of any acre

Post by Sanqui »

Good job! I edited the map like this in memory before (haha my WTW), but hey this is awesome. Definitly may try someday. Also someone totally needs to make an editor.

EDIT: ImageEPIC WIN! Thanks!
User avatar
andwhyisit
Site Admin
Posts: 1197
Joined: Fri Dec 14, 2007 9:24 pm

Re: Third map tutorial: How to edit tiles of any acre

Post by andwhyisit »

Blaziken257 wrote: Oh, and I also forgot to mention that I have no idea how to create hacking utilities. So unless someone (like swampert22) does, we're all stuck with using a hex editor for this. Oh well.
I was thinking more along the lines of Milnivri actually.
Blaziken257
Posts: 983
Joined: Fri Dec 22, 2006 11:52 am

Re: Third map tutorial: How to edit tiles of any acre

Post by Blaziken257 »

Sanky wrote:Good job! I edited the map like this in memory before (haha my WTW), but hey this is awesome. Definitly may try someday. Also someone totally needs to make an editor.

EDIT: ImageEPIC WIN! Thanks!
Where is that?

Oh and you're welcome!
andwhyisit wrote:
Blaziken257 wrote: Oh, and I also forgot to mention that I have no idea how to create hacking utilities. So unless someone (like swampert22) does, we're all stuck with using a hex editor for this. Oh well.
I was thinking more along the lines of Milnivri actually.
Oh yeah, he did say that he was going to do something like this once...

That reminds me, I still gotta try out his Denjuu editor...
User avatar
Sanqui
Posts: 736
Joined: Sun Dec 16, 2007 12:25 am

Re: Third map tutorial: How to edit tiles of any acre

Post by Sanqui »

Ha ha!
It's the screen right to the left of Musa's house, in Toronko XD

I tried out your patch, it's great!
Milnivri(imported)
Posts: 351
Joined: Wed Dec 27, 2006 10:14 pm

Re: Third map tutorial: How to edit tiles of any acre

Post by Milnivri(imported) »

Heh, yes I did say I wanted to make one.. but it seems much harder than it looks. Considering the complexity of the ROM it's gonna be hard..

Oh and yeah this tutorial is great!

EDIT: Oh and I totally forgot to go back to working on the Denjuu editor, wanted to implement new features.. gonna release next version soon I hope. XD
Post Reply