ROM Hack Extracting models and textures from 3DS games

YoshiInAVoid

Banned!
OP
Banned
Joined
Jan 10, 2011
Messages
560
Trophies
1
Website
google.com
XP
465
Country
UPDATE: This thread is slightly outdated, there is an easier method which is to use the tool Every File Explorer.

The purpose of this thread is to collect all of the information from this thread which is difficult to find due to there being so many pages and to provide my own additional findings of how to extract models and textures from the decrypted file system.

For this example, I will be extracting the "Barrel" model of Super Mario 3D Land.

Here's what the final result will be:

Barrel.png

For a bonus, here's the model extracted from AssistItem.szs, and the model extracted from FireFlower.szs:

assist.png

flower.png

First, you need to extract the ROMFS (ROM File System) partition of the 3DS ROM. Do NOT use 3DSExplorer, there is a bug with this software which causes it to the extract from the wrong offset, so you won't be able to decrypt correctly. Use this tool:

http://gbatemp.net/threads/release-3ds_ctr_decryptor-void.370684/page-5#post-5085243

Click and drag your ROM into getromfs.exe and it will extract the encrypted romfs for the rom as EncryptedRomFS.bin. Don't close the cmd window. It will close on its own when it's done. It will take a couple minutes.

You should now have EncryptedRomFS.bin in the same directory. The next step is to decrypt the ROMFS. Use this tool to generate an XOR pad (instructions are in the thread):

http://gbatemp.net/threads/release-3ds_ctr_decryptor-void.370684/

Note: There is a bug which means that the XOR pad is not the same size as the ROMFS file! Most XOR tools support decryption with a differently sized XOR pad, however if not, you will need to delete the end of the XOR pad until it is the same size as the EncryptedRomFS.bin file.

Now that you have your XOR pad, you can decrypt the EncryptedRomFS.bin into DecryptedRomFS.bin. For this tutorial, we will use 3DSExplorer which you can download here:

http://3dsexplorer.googlecode.com/files/3dsexplorer_v1.5.3.zip

Go to Tools->XOR Tool

First File: CTR-P-AREP0.romfs.xorpad
Second File: EncryptedRomFS.bin

Then hit Save, and chose the name of the decrypted file.

Now you have your DecryptedRomFS.bin!

To extract files from it, we will need the 3DSHax fork of ctrtool available here:

https://github.com/3dshax/ctr/tree/master/ctrtool

If you don't want to compile it from source, there is a compiled version available here:

https://dl.dropboxusercontent.com/u/35197530/zip/ctrtool.zip

Once extracted, use this command line to extract files from the DecryptedRomFS.bin:

Code:
ctrtool.exe -t romfs --romfsdir=Mario DecryptedRomFS.bin

This will make a new directory called "Mario" where you should see more directories such as "StageData" which contains several .SZS files.

In this tutorial, I will be decompressing the file "Mario\ObjectData\Barrel.szs" but this should work for other SZS files as well.

Thankfully, 3DS SZS files are the same format as SZS files found in Wii games, and are compatible with Wii hacking tools! So, download and install this tool:

http://szs.wiimm.de/wszst/

Once installed, you can use this command line:

Code:
wszst DECOMPRESS Barrel.szs

Which will produce a file named Barrel.bin.

Barrel.bin is actually a .narc file, so just rename it to Barrel.narc.

To extract files from a .narc file, you can use several DS hacking tools. The one which I managed to get working is Mario Kart DS Course Modifier, download here:

http://gbatemp.net/threads/mkds-course-modifier.299444/

Open Mario Kart DS Course modifier, and then open Barrel.narc. Select the files from the treeview and click extract.

We now have these files:

- ActorHitByReactionCtrl.byml
- Barrel.bcmdl
- InitActor.byml
- InitClipping.byml
- InitLight.byml
- InitSensor.byml
- InitShadow.byml

The one which contains the model and textures is Barrel.bcmdl. This is a CGFX file.

To extract models and textures from a CGFX file we use Smealum's tool cgfx2obj.py which you can download here:

https://gist.github.com/smealum/8807124

In addition to this, you also need Python installed (I tested with version 2.7):

https://www.python.org/downloads/

PIL which can be downloaded here:

http://www.pythonware.com/products/pil/

and "etc.exe". If you want to build etc.exe from source, you will need these files:

https://gist.github.com/smealum/8897237
https://code.google.com/p/rg-etc1/source/browse/#svn/trunk

And you can compile it with the following Makefile which I wrote:

Code:
etc.exe: main.c rg_etc1.cpp
    g++ main.c rg_etc1.cpp -o etc.exe -Wall

If you don't want to compile etc.exe yourself, here is my compiled etc.exe file (all credit to Smealum, I just compiled it):

http://filetrip.net/3ds-downloads/development-tools/download-etc-exe-1-0-f32920.html

Now you may be trying this command:

Code:
cgfx2obj.py Barrel.bcmdl

And notice that it writes the obj to stdout, we need to redirect stdout to a file, the correct command is this:

Code:
cgfx2obj.py Barrel.bcmdl > Barrel.obj

Congratulations! You now have these files:

- Barrel.obj,
- tex_0x9a00.png,
- tex_0xc480.png,

Once again, here's what the finished result looks like:

Barrel.png
 
D

Deleted-346555

Guest
Pretty cool thread! However it works only w/ "lite" roms for now since our decryptor got a problem, still trying to fix it...
 

robotortoise

Well-Known Member
Member
Joined
Jan 12, 2012
Messages
100
Trophies
0
Location
Arizona
XP
190
Country
United States
Wow, this is really awesome!

Now, if someone could only make a program to do all of this in one....

It's a bit of a pain to do this for EVERY SINGLE model, and I don't really know how to code. :P
 

Gericom

Well-Known Member
Member
Joined
Jun 30, 2011
Messages
1,381
Trophies
2
Age
25
XP
4,688
Country
Netherlands
Awesome! Looking forward to it.

Will you also implement animations and alternate textures? (Blinking eyes, ect.)
And will I still have to extract all the stuff from the zar, or will it be an all-in-one app?

It's an all in one app. It is called every file explorer, and will replace mkds course modifier. It will have a plugin for 3ds
 

bobmcjr

Well-Known Member
Member
Joined
Apr 26, 2013
Messages
1,156
Trophies
1
XP
3,212
Country
United States
Tried cgfx2obj on a different game, and I can't seem to get valid objects. This is the header of one: http://i.imgur.com/xLv48NP.png
Textures extract almost ok, and for some of the .bin files it produces objects (which seem can't be opened in anything).
In cygwin with python-2.7 and PIL, cgfx2obj seems to always segfault.
Code:
# SOBJ 0x301c
# SOBJ 0x30a4
# SOBJ 0x312c
# SOBJ 0x3c04
# vertex format 0x5f
g SOBJ_0x3c04
<points here>
# SOBJ 0x406c
# vertex format 0x12
g SOBJ_0x406c
<more points here>
# SOBJ 0x42b0
# vertex format 0xb
g SOBJ_0x42b0
<more points here>
# SOBJ 0x4648
# vertex format 0x0
g SOBJ_0x4648
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    The Real Jdbye @ The Real Jdbye: i like the dlc tbh, i'd like a new game more