Extracting models and textures from 3DS games

Discussion in '3DS - ROM Hacking, Translations and Utilities' started by YoshiInAVoid, Aug 30, 2014.

  1. YoshiInAVoid
    OP

    YoshiInAVoid GBAtemp Advanced Fan

    Banned
    560
    336
    Jan 10, 2011
    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:

    Warning: Spoilers inside!

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

    Warning: Spoilers inside!

    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

    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:

    Warning: Spoilers inside!
     


  2. Relys

    Relys Master of Computer Science

    Member
    863
    788
    Jan 5, 2007
    United States
    Great tutorial! This kind of work was exactly what I was hoping for. :)
     
    Margen67, MAXLEMPIRA and YoshiInAVoid like this.
  3. Esppiral

    Esppiral GBAtemp Regular

    Member
    216
    119
    Aug 24, 2014
    Nice! I was looking for this.
     
  4. YoshiInAVoid
    OP

    YoshiInAVoid GBAtemp Advanced Fan

    Banned
    560
    336
    Jan 10, 2011
    Thanks! I wouldn't have been able to do this wouldn't without your tool!
     
    Relys likes this.
  5. IronClouds

    IronClouds GBAtemp's Pok├ębro

    Member
    1,018
    460
    May 8, 2010
    United States
    Liked the first post so hard.
     
  6. intermet

    intermet GBAtemp Regular

    Member
    152
    28
    Jul 19, 2012
    France
    In NSMB2 there is any szs but sarc ( like arc or rarc for wii/gc ).
     
  7. YoshiInAVoid
    OP

    YoshiInAVoid GBAtemp Advanced Fan

    Banned
    560
    336
    Jan 10, 2011
    I've only tried Super Mario 3D Land. I may try other ROMs another day.

    In the mean time, here's AssistItem.SZS:

    [​IMG]

    I'll add this one to the first post.
     
    Margen67 likes this.
  8. intermet

    intermet GBAtemp Regular

    Member
    152
    28
    Jul 19, 2012
    France
    Can you show me the header of .bcmdl ?
    Thx
     
  9. Gericom

    Gericom GBAtemp Advanced Fan

    Member
    851
    898
    Jun 30, 2011
    Netherlands
    Upcoming:
    Bcmdl.PNG
     
  10. GovanifY

    GovanifY Member

    Banned
    42
    45
    Mar 9, 2014
    France
    Pretty cool thread! However it works only w/ "lite" roms for now since our decryptor got a problem, still trying to fix it...
     
  11. robotortoise

    robotortoise Advanced Member

    Newcomer
    99
    23
    Jan 12, 2012
    United States
    Arizona
    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
     
  12. Gericom

    Gericom GBAtemp Advanced Fan

    Member
    851
    898
    Jun 30, 2011
    Netherlands
    That's what I am doing. A viewer for cgfx.
     
    Huntereb likes this.
  13. robotortoise

    robotortoise Advanced Member

    Newcomer
    99
    23
    Jan 12, 2012
    United States
    Arizona
    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?
     
  14. Gericom

    Gericom GBAtemp Advanced Fan

    Member
    851
    898
    Jun 30, 2011
    Netherlands
    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
     
    robotortoise and Huntereb like this.
  15. bobmcjr

    bobmcjr GBAtemp Advanced Fan

    Member
    895
    334
    Apr 26, 2013
    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.
    Warning: Spoilers inside!
     
  16. chrrox

    chrrox Member

    Newcomer
    42
    11
    Sep 24, 2009
    United States

    Attached Files:

    SciresM, windwakr and bobmcjr like this.
  17. the_randomizer

    the_randomizer The Temp's official fox whisperer

    Member
    21,198
    10,076
    Apr 29, 2011
    United States
    Dr. Wahwee's castle
    Man, I wonder if there will eventually be a way to import these into 3DS Max or Maya...
     
    MAXLEMPIRA likes this.
  18. Flurry

    Flurry Member

    Newcomer
    48
    48
    Sep 1, 2013
    United States
    Can't you do that when they are in .obj format?
     
  19. the_randomizer

    the_randomizer The Temp's official fox whisperer

    Member
    21,198
    10,076
    Apr 29, 2011
    United States
    Dr. Wahwee's castle

    Whoops, my mistake, I need to reread the OP, sorry about that :P I hope sites like Models Resource will have these models from 3DS games available one of these days, as I've some ideas on how I could use them.
     
  20. gudenau

    gudenau Never a unique idea

    Member
    3,258
    1,225
    Jul 7, 2010
    United States
    /dev/random
    You should be able to create a OBJ file and import that.