Just a Summary of How Map Data and Tileset Data Work (Programmatically)
Okay… I’m new to FE/GBA hacking/editing, but I’m working on a project for Uni, and needed a programmatic way to figure out the terrain on each map. It took me a while to get it, and I really wouldn’t be posting this and bumping a 7yr old thread unless I thought it was REALLY necessary (I feel like this thread could be worded a lot better lol). Here’s how to pull map data for FE7 (the prologue is my current example):
– THE MAP ITSELF (Use FEBuilder) - Map data (tile-ID-wise) is stored at 0x36AF00 –
- This data is 0x12C (300 bytes) long, and LZ77 GBA-style compressed
- After pulling and decompressing the data, the first two bytes are the width and height (“0F 0A” for the Prologue, which is (15 x 10))
- After this, every 2 bytes is little-Endian formatted tile IDs (“0A B0 (first tile) 0A B4 (second tile) 0C 9C (third tile), etc.”)
- These tile IDs MATCH the ingrained tile IDs in FEBuilder, if you open Tileset Palette and click on the tiles
- (It’s the ‘No.’, or the ‘Tile Base’, in @StanH’s words)
– APPEARANCE AND TERRAIN - Map data (terrain-ID-wise) is stored (for the Prologue) at 0x35EE10 –
-
This data is 0x2400 (9216 bytes) long, and LZ77 GBA-style compressed
-
After pulling and decompressing the data, the first 0x2000 bytes are the
-
“Upper left, Upper Right, Bottom Left, Bottom Right” little-Endian-formatted addresses (Each tile uses 8 bytes)
-
After this, the last 0x400 bytes are the TERRAIN IDs that the tiles belong to, IN ORDER, one byte per tile
-
Thus, tile 1 belongs to terrain 0x00, tile 2 to 0x20, tile 0x3 to 0x13, etc.
-
Thus, you can figure out the hex address to the terrain ID for a tile by taking the (tile ID / 4), and adding + 0x2000
- Tile 0x0AB0 / 4 = 0x2AC (which also happens to be the GID, if you download the map as a .tmx in FEBuilder)
- 0x2000 + 0x2AC = 0x22AC
- The byte at 0x22AC = 0x11 (which is the Mtn terrain ID, which IS the correct ID for Tile 1 (0x0AB0) of the Prologue)
Hope this helps someone else out! Like I said, I’m new, and it took about 3 days to put all this together, but it’s (relatively) easy if you use FEBuilder and look at the data side-by-side, in HxD.
Edits:
– Some other useful information –
- Remember that not all maps are the same size, so make sure your script doesn’t ONLY decode +0x300 bytes from the given map data address (it’ll throw errors anyway, because of how LZ77 compression blocks work)
- Tileset data IS always the same… every tileset is 0x2400 bytes.
- Tilesets are just a way to simultaneously map terrain data and graphical data to a massive png of 1024 tiles. Lots of tilesets are reused (terrain-data-wise), and it’s just the graphical palette that changes.