GBAFE Map Hacking Suite

This is a gbafe map hacking suite which can:
*Create and Insert a map tileset. 75 colors supported.
*Insert a map. Flipping when mapping by Tiled supported. Flipping Support Patch needed.
*Insert map changes.

An example of a flipped tile:

Download

It comes with an example and its source. There is also a patch for testing in it.

A tutorial on how to use it:

Preparations

1.Install Tiled 0.16.2.
2.Install a lua running environment.

Create the tileset

1.The whole tileset should be a 512x512 png. Divide it into no more than 5 parts from top to the bottom.


buildings, water, forest, mountains and land. Each part can only have 15 colors (because the 1st color is transparent).
2.Split it into 5 images:
(1) 0.png

its palette:

(2) 1.png

its palette:

(3) 2.png

its palette:

(4) 3.png

its palette:

(5) 4.png

its palette:

3.Check if the 5 images can really make up of a whole 512x512 image. Of course you can also split it into 4 images or 3 images or 2 images or even one image (itself), but confirm that their width is 512px and their total height is also 512 px.

Edit the terrain info

1.Import the tileset.png into Tiled.

Notice each tile is 16x16.
2.Edit the terrain info of the tileset with terrain tool of Tiled.


If you don’t know how to use it, read its user manual.
Notice that the name of each terrain is not important at all. Name it to sth which can help you to recognize it like plains, forest, sea and so on.
3.Add a property called “ID” to each terrain. Refer to “terrain list.txt” and set its value correctly. This is how the game recognizes the terrain type.

Create the map

1.Create a map with your own tileset.

Notice that X/Y is the hotkey for flipping in Tiled.
2.Name its layer to “Main”.

Create the map changes

1.Create a map change in a new layer.
(1)seize the gate:


(2)destroy the village:

(3)close the village:

2.Add properties to each mapchange layor:
-ID:
Tells the ID of the map change.
-X:
Tells X coordinate of the left edge of the map change.
Required for map changes.
-Y::
Tells Y coordinate of the top edge of the map change.
Required for map changes.
-Width:
Tells the width of the map change.
-Height:
Tells the height of the map change.
-Offset:
Tells where you plan to insert the map change data.
Notice that you can insert them to anywhere of the rom and don’t give all the map changes data the same offset.

(1)destroy the village:

(2)seize the gate:

(3)close the village:

Save

Export it as .lua

File->Export As… or Ctrl+Shift+E
Name it to map.lua
Notice the .tmx is useless now.

Run the tool suite

1.Move 0.png, 1.png, 2.png, 3.png, 4.png and map.lua into its folder.
2.Edit the runme.bat.
Change:
grit 0.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp0 -mR4 -mRtf -pn16 -ftb
grit 1.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp1 -mR4 -mRtf -pn16 -ftb -ma129
grit 2.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp2 -mR4 -mRtf -pn16 -ftb -ma350
grit 3.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp3 -mR4 -mRtf -pn16 -ftb -ma446
grit 4.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp4 -mR4 -mRtf -pn16 -ftb -ma662

To:
grit 0.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp0 -mR4 -mRtf -pn16 -ftb
grit 1.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp1 -mR4 -mRtf -pn16 -ftb
grit 2.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp2 -mR4 -mRtf -pn16 -ftb
grit 3.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp3 -mR4 -mRtf -pn16 -ftb
grit 4.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp4 -mR4 -mRtf -pn16 -ftb

Save
3.Run runme.bat.
4.Open 0.h and record the number here:

so X0=129
5. Record X1,X2,X3,X4 from 1.h,2.h,3.h,4.h
X1=221
X2=96
X3=216
X4=210
6.Calculate X0+X1+X2+X3+X4=?
129+221+96+216+210=872
Check if it < 1024
872<1024, then OK.
If not, adjust your tileset(by removing some tiles), run runme.bat again until the requirement is satisfied.
7.Calculate:
Y1=X0=129
Y2=Y1+X1=129+221=350
Y3=Y2+X2=350+96=446
Y4=Y3+X3=446+216=662
8.Edit the runme.bat
Change:
grit 0.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp0 -mR4 -mRtf -pn16 -ftb
grit 1.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp1 -mR4 -mRtf -pn16 -ftb
grit 2.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp2 -mR4 -mRtf -pn16 -ftb
grit 3.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp3 -mR4 -mRtf -pn16 -ftb
grit 4.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp4 -mR4 -mRtf -pn16 -ftb

To:
grit 0.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp0 -mR4 -mRtf -pn16 -ftb
grit 1.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp1 -mR4 -mRtf -pn16 -ftb -maY1
grit 2.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp2 -mR4 -mRtf -pn16 -ftb -maY2
grit 3.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp3 -mR4 -mRtf -pn16 -ftb -maY3
grit 4.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp4 -mR4 -mRtf -pn16 -ftb -maY4

In this instance:
grit 0.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp0 -mR4 -mRtf -pn16 -ftb
grit 1.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp1 -mR4 -mRtf -pn16 -ftb -ma129
grit 2.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp2 -mR4 -mRtf -pn16 -ftb -ma350
grit 3.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp3 -mR4 -mRtf -pn16 -ftb -ma446
grit 4.png -gB4 -mLf -gT000000 -m -mB16:p4vhi10 -mp4 -mR4 -mRtf -pn16 -ftb -ma662

Save.
9.Run runme.bat
And you will get tileset.pal.dmp, tileset.img.dmp, tileset.conf.dmp, map.dmp, mapChange.conf.dmp and mapChangeX(offset).dmp(X= the id of the map change, Offset= where you need to insert it).
In this instance:

Insert and repoint

1.Apply the Flipping Support Patch to your rom.
2.Open your rom by a hex editor and paste them to any free space.
But paste mapChangeX(offset).dmp to the offset it tells you(You set them in the Tiled).
tileset.pal.dmp->the palette of the tileset
tileset.img.dmp->the raw data of the tileset(you need to compress it by a lz77 compressor before inserting)
tileset.conf.dmp->the config of the tileset(you need to compress it by a lz77 compressor before inserting)
map.dmp->the map data(you need to compress it by a lz77 compressor before inserting)
mapChange.conf.dmp-> the map change data
I think you can use the extended EA to help you. I just use a hex editor here ><.
3.Repoint them in the event table by Nightmare.
4.Set the chapter data correctly by Nightmare. Be sure to set the tile animation id to 0.
In the Chapter Data Editor:
Object Set -> the index of the tileset.img.dmp in the event table
Palette -> the index of the tileset.pal.dmp in the event table
Tile Configuration -> the index of the tileset.conf.dmp in the event table
Map -> the index of the map.dmp in the event table
Triggerable Map Changes -> the index of the mapChange.conf.dmp in the event table
Tile Animations -> 0

For testing, I inserted them:
9000170 Object Set
9005ec0 Palette
9005f60 Tile Configuration
90075a0 Map
90077f0 Map Changes
Then edit the prologue chapter data:

0xC9A200
Object Set1 0x1
Object Set2 0x0
Palette 0x02
Tile Configuration 0x03
Map 0x04
Tile Animation 0x05 -> 0x0
Map Changes 0x0 -> 0x5

Then edit the event table:

Finally test it:

Everything works perfectly (including the flipped tiles).

Discuss on the tile animation

I didn’t add the tile animation support to it. Here is the reason:

1.How does it work in Tiled?

It works by changing the tile id repeatedly.
2.How does it work in GBAFE?
It works by overwriting the pixel data of some certain tiles in the VRAM.
the format of the tile animation data in the rom:
(half word 1) (half word 2) pointer
(half word 1) (half word 2) pointer
……
(half word 1) (half word 2) pointer
00000000 00000000
(half word 1) (half word 2) pointer
(half word 1) (half word 2) pointer
……
(half word 1) (half word 2) pointer
00000000 00000000
(half word 1) (half word 2) pointer
(half word 1) (half word 2) pointer
……
(half word 1) (half word 2) pointer
00000000 00000000
……

(half word 1) is sth related to the frame counts/durations?
(half word 2) is the length of the data pointed by the pointer followed.
pointer is the real pixel data of the anmated tiles like this:


The game uses CPUFastSet(swi 0Ch) to copy the pixel data of the animated tiles into VRAM
In FE7J:
0x80C0550 swi 0Ch;CpuFastSet
0x80C0552 bx r14
r0=pointer, r1=600a000h, r2=(half word 2)>>2
so the tiles which supports animation must be at the same offset in the tileset image data. The game does a partial recycle for the tileset image data.

To conclude, It is impossible to convert the animation made by Tiled into the animation data which gbafe likes.

16 Likes