[Research/HOW-TO] Modding on iPad

Discuss and distribute tools and methods for modding. Moderator - Grognak
drakulix
Posts: 9
Joined: Sun Apr 20, 2014 5:13 pm

[Research/HOW-TO] Modding on iPad

Post by drakulix »

Hey there,
I am Drakulix and I am totally new to this community, however I am enjoying the various nice mods for FTL already quite a while. Now the iPad is out and I tried my best to reverse engineer the iPad version and got some interesting details, I wanted to tell you all. I tried the last days to create some tools to make editing the iPad Version a lot easier, however I was running into some serious issues, I am not totally sure how to solve them. For that reason I decided to drop working on this and just share, what I found out, so some smarter people may be able to do that.

What to expect (short table of contents):
- extracting and modifing iPad game assets.
- differences to modding the Win/Mac/Linux version - most mods don't work out-of-the-box on the iPad
- a lot technical stuff, that is not very deeply explained. If you have no clue, what I am talking about, wait until some more skilled people have build nice interfaces around this stuff.

For clarification:
When I talk about bad performance on the iPad, it does usually not mean, that your game will lag. On an iPad 2, that might actually happen, but on my iPad Air I did not notice any lags so far. It actually depends on your device and is not very likely (FTL is not a very demanding game). However it will always drain your battery faster (not necessary noticeable on modern iPads), when I am referring to "bad performance".

So lets start:
1. All game assets are stored in a file called ftl.dat on the iPad
So your first question probably is, how to get that file. You don't need to grab it for modding as you will see later.
But okay, if you are interested anyway, I recommend using iFunBox. Jailbreakers will probably have other preferred ways.

2. The format is not the same as on PC.
Figuring out the format took me most of the time on my research, I was quite lucky, that I found some references to a library called SIL, though IDA Pro. ( http://achurch.org/SIL/ )

So download that library, go into the tools folder and run "make".
Windows people will probably need cygwin to do that, I will not provide a tutorial for that here (and please don't pm me about that subject), there are enought tutorials on the internet.
Mac Users need XCode installed.
You probably need to install some dependencies, the log will tell you. You do not need to build everything, just make sure that these tools are build probably: extract-pkg, build-pkg and pngtotex.

You can now extract the ftl.dat using extract-pkg. and upon writing a control file (see comments in the build-pkg.c file) also generate new ftl.dat files.

3.
The folder structure of the ftl.dat is the same as for data.dat and resource.dat. It contains fonts, data, audio and img, but also atlas, which brings us to the next point:

4.
The images are saved in a different format. Instead of .png, .tex is used.
Those .tex files are not any really known format (like dds or similar texture formats), but a custom format of SIL. You can generate your own texture files out of png files with pngtotex.

Some notes: Most textures on the iPad are saved with the -bgra flag of pngtotex. However that does not seem to make a huge performance difference, you do not need to set that flag, when converting textures. Some however are saved in PVR(TC), which is a lossy mobile format. It is mostly used for huge background textures and makes a significant performance difference. However PVR(TC) textures do not look very good (no clear edges and stuff), so you do not wanna use that for everything else then backgrounds.

After converting you can just replace the .tex files of the ftl.dat contents, before repacking and you will see your new image in-game.

5. the atlas folder contains even more wired textures.
It contains so called sprite sheets (google it) of some textures, also to save performance. You can however just delete a sprite sheet and place the images, that were contained in the sprite sheet, separately in the img folder at the normal paths. The iPad will fallback to the old paths, when no sprite sheets are found, which brings me to point 6:

6. There is no need to grab the original ftl.dat, if you got the game on your pc/mac.
You can just convert all .png textures (better create a small bash script for that) and pack the whole thing as ftl.dat and it will work! You will have a worse performance, then with the original files, because you are not using sprite sheets and probably also no PVR textures, but it works and is nice for testing.

7. To get your ftl.dat on the device simply use iFunBox. (or whatever you prefer)

Sounds like modding on the iPad is very easy, just patch all textures and repack everything, right? No its not:

1. Recreating the atlas files most be done manually by re-creating the sprite sheets out of the original textures. That means, if you just want to modify one file in the whole sprite sheet you need to rebuild the entire thing (actually that means you are distributing original game assets, when uploading your modified sprite sheet somewhere). And you should be interested in rebuilding the sprite sheets for peoples battery and those iPad 2 and mini owners, who might have lags otherwise.

2. Mods may very easily crash the game. Already modifing the main_base2.tex file in the img/ipad/main_menus folder might crash the main menu, if the format is not 4:3.
Some other image files also cause the game to crash upon loading. It seems that mostly backgrounds in 16:9/16:10 format are causing this, and need to have 4:3 counterparts in the ipad subfolder of the img folder.
But although I have already patched all backgrounds I still cannot get the captains edition mod to work, neither I could get better backgrounds to work. Somebody needs to test that file by file to figure out, what the iPad version accepts and all incompatible mods need to be patched to work correctly.
But some ship modifications are working nicely out of the box.

I have not the time and motivation to figure out, why the iPad version is still not loading the captains edition correctly, but I wanted to provide you guys the tools, so somebody else may figure out all that stuff.

Now feel free to discuss and try everything out. I will try to help everybody, as good as I can, but do not expect me to set up your modding environment. ;)

- Drakulix
0l1v3rof
Posts: 1
Joined: Sun Apr 20, 2014 8:24 pm

Re: [Research/HOW-TO] Modding on iPad

Post by 0l1v3rof »

Well done Drakulix! :D

I hope the android version (when released) will not need as much effort as the method used with the iPad. But I reckon some smart guy/girl will release a tool for one or both of the platforms.

I would test some mods on my family's iPad but I have been give strict instructions not to hack or mod it in anyway. :)

p.s. My first post :)
drakulix
Posts: 9
Joined: Sun Apr 20, 2014 5:13 pm

Re: [Research/HOW-TO] Modding on iPad

Post by drakulix »

0l1v3rof wrote:Well done Drakulix! :D

I hope the android version (when released) will not need as much effort as the method used with the iPad. But I reckon some smart guy/girl will release a tool for one or both of the platforms.

I would test some mods on my family's iPad but I have been give strict instructions not to hack or mod it in anyway. :)

p.s. My first post :)
They will likely use the same engine for android, because SIL is android compatible an also offers the same perfomance improvements for android it provided for the ipad. That would mean the android and ipad files will be interchangeable at least.
Hael
Posts: 5
Joined: Sun May 04, 2014 8:32 pm

Re: [Research/HOW-TO] Modding on iPad

Post by Hael »

Hello, I have successfully created extract-pkg and build-pkg.exe, however I am stuck on the writing a control file part since I don't understand the format or the comments in the build-pkg.c file. I am using cygwin on windows, and both c++ and linux are very unfamiliar to me so its a bit of a struggle.

do you have to include each data file line by line, can we not just copy the entire directory?

so the file would read something like

atlas
audio
data
fonts
img

since these are the only directories in my working directory
drakulix
Posts: 9
Joined: Sun Apr 20, 2014 5:13 pm

Re: [Research/HOW-TO] Modding on iPad

Post by drakulix »

Hael wrote:Hello, I have successfully created extract-pkg and build-pkg.exe, however I am stuck on the writing a control file part since I don't understand the format or the comments in the build-pkg.c file. I am using cygwin on windows, and both c++ and linux are very unfamiliar to me so its a bit of a struggle.

do you have to include each data file line by line, can we not just copy the entire directory?

so the file would read something like

atlas
audio
data
fonts
img

since these are the only directories in my working directory
You only have to include each folder (including subfolders!) in the control file, if you use the % for the filename (it only works for filenames, not folders). And do not forget to add the deflate prefix.

Your final control file should look somewhat like this:

Code: Select all

deflate:"atlas/%"
deflate:"audio/%"
deflate:"audio/waves/%"
deflate:"audio/..."
...
(you get the idea)
Hael
Posts: 5
Joined: Sun May 04, 2014 8:32 pm

Re: [Research/HOW-TO] Modding on iPad

Post by Hael »

thanks, i was in the process of doing something like that.. It seems to be giving me some strange packing errors, but at least im on the right track.. wip
drakulix
Posts: 9
Joined: Sun Apr 20, 2014 5:13 pm

Re: [Research/HOW-TO] Modding on iPad

Post by drakulix »

Hael wrote:thanks, i was in the process of doing something like that.. It seems to be giving me some strange packing errors, but at least im on the right track.. wip
If you need any help, just post your errors. I am glad to help.
Hael
Posts: 5
Joined: Sun May 04, 2014 8:32 pm

Re: [Research/HOW-TO] Modding on iPad

Post by Hael »

so im getting the following error using for simplicity (once i get this working ill make the full one) the following control-file.txt
deflate:"atlas/%"
deflate:"atlas/people/%"

so after the following line is executed
$ ./build-pkg.exe control-file.txt ftl.dat
we get
Failed to read from atlas/people while writing package: Unexpected EOF

then when i unpack to a clean directory i get a bunch of decompression errors"
like
atlas/planet_bigblue.tex: Decompression error -3
atlas/people/boarder_ion.tex: Decompression error -3

im wondering if build-pkg.exe somehow didn't build properly.... im pretty sure extract-pkg.exe works fine
drakulix
Posts: 9
Joined: Sun Apr 20, 2014 5:13 pm

Re: [Research/HOW-TO] Modding on iPad

Post by drakulix »

Hael wrote:so im getting the following error using for simplicity (once i get this working ill make the full one) the following control-file.txt
deflate:"atlas/%"
deflate:"atlas/people/%"

so after the following line is executed
$ ./build-pkg.exe control-file.txt ftl.dat
we get
Failed to read from atlas/people while writing package: Unexpected EOF

then when i unpack to a clean directory i get a bunch of decompression errors"
like
atlas/planet_bigblue.tex: Decompression error -3
atlas/people/boarder_ion.tex: Decompression error -3

im wondering if build-pkg.exe somehow didn't build properly.... im pretty sure extract-pkg.exe works fine

did you change the directory before calling build-pkg?
you need to use "cd" to navigate inside the folder, where your to-be-compressed-files are. so the parent folder of yous atlas folder.
Hael
Posts: 5
Joined: Sun May 04, 2014 8:32 pm

Re: [Research/HOW-TO] Modding on iPad

Post by Hael »

Heya, thanks I really appreciate the help. I'm being an idiot it seems.

so ive tested things with a bunch of different control files and think ive spotted the problem.
everytime i pack things in a directory that doesn't contain a subdirectory, the program works fine.. however if there is a subdirectory in there, it reads the directory like a string?? and mucks up (which then messes up everything else)

eg
deflate:"data/%"
deflate:"fonts/%"
deflate:"atlas/people/%"

works and packs correctly, however
deflate:"atlas/%"

gives the following error
Failed to read from atlas/people while writing package: Unexpected EOF

everything is in my home directory:
eg
build-pkg.exe
control-file.txt
extract-pkg.exe
ftl.dat (when its built)
and the directories
atlas, audio, data, fonts, img
Post Reply