3DS Data Tools: Difference between revisions

From GameBrew
(Created page with "{{Infobox 3DS homebrew | title = 3DS Data Tools | image = https://dlhb.gamebrew.org/3dshomebrew/3DSDataTools.jpg|250px | type = PC Utilities | version = | licence = Mixed | au...")
 
m (Text replacement - "Category:PC utilities for 3DS homebrew" to "")
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Infobox 3DS homebrew
{{Infobox 3DS Homebrews
| title = 3DS Data Tools
|title=3DS Data Tools
| image = https://dlhb.gamebrew.org/3dshomebrew/3DSDataTools.jpg|250px
|image=3dspc.png
| type = PC Utilities
|description=Tools for extracting and packing resources found in 3DS games.
| version =
|author=ObsidianB
| licence = Mixed
|lastupdated=2016/04/25
| author = ObsidianB
|type=File Operation
| website = https://gbatemp.net/threads/release-various-3ds-editing-tools.424118/
|version=2016
| download = https://dlhb.gamebrew.org/3dshomebrew/3DSDataTools.rar
|license=Mixed
| source = https://dlhb.gamebrew.org/3dshomebrew/3DSDataTools.rar
|download=https://dlhb.gamebrew.org/3dshomebrews/3dstoolsobs.7z
|website=https://gbatemp.net/threads/release-various-3ds-editing-tools.424118/
|source=https://github.com/ObsidianX/3dstools
}}
}}
<youtube>Oa9ICwEm4Ks</youtube>
This is a set of tools for extracting and packing resources found in 3DS games, aims to be cross-platform compatible and they are all written in Python.


Hey folks,
==User guide==
===bffnt.py===
BFFNT extract/create tool. Creates a PNG file from the texture atlases in a BFFNT as well as a JSON manifest.


A while back I started translating Rhythm Tengoku The Best+ (before Nintendo announced the US release -_-) and couldn't find tools that were cross-platform and worked with the specific (newer?) NintendoWare formats found in RTG, so I decided to write my own [[File:styles/default/xenforo/clear.png|class=mceSmilieSprite mceSmilie48|:)]]
'''Command line:'''
usage: bffnt [-h] [-v] [-d] [-y] [-l | -b] (-c | -x) -f bffnt
BFFNT Converter Tool
optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose        print more data when working
  -d, --debug          print debug information
  -y, --yes            answer yes to any questions (overwriting files)
  -a, --ensure-ascii    turn off ensure_ascii option when dump json file
  -l, --little-endian  Use little endian encoding in the created BFFNT file
                        (default)
  -b, --big-endian      Use big endian encoding in the created BFFNT file
  -c, --create          create BFFNT file from extracted files
  -x, --extract        extract BFFNT into PNG/JSON files
  -f bffnt, --file bffnt
                        BFFNT file


'''https://github.com/ObsidianX/3dstools'''
'''Examples:'''
[Extract a BFFNT to PNG/JSON...]
bffnt.py -xf Sample.bffnt
[...Results]
Sample_manifest.json
Sample_sheet0.png
[Create a BFFNT from PNG/JSON]
bffnt.py -cf Sample.bffnt


These tools are all written in Python and should be cross-platform compatible, though I wrote them all in Linux and haven't tested them in Windows so patches/bug reports are welcome.
'''Note:''' Sample_manifest.json and Sample_sheet0.png must be in the current directory to build Sample.bffnt.


'''<span style="font-size: 22px">bffnt.py</span>'''
===bflim.py===
BFLIM converter to and from PNG files. This tool is still in development (supports conversion of all texture formats but cannot create ETC1 bflim files).


Extract, edit, and re-create fonts in the bffnt format.�It outputs a PNG of each texture sheet found in the source bffnt (usually just one) and a JSON manifest that describes each glyph.
'''Command line:'''
usage: bflim [-h] [-v] [-d] [-y] [-l | -b] [-s {0,8,4}] (-c png | -x | -i)
              bflim_file
BFLIM Converter
positional arguments:
  bflim_file            FLIM file
optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose        print more data when working
  -d, --debug          print debug information
  -y, --yes            answer yes to any questions (overwriting files)
  -l, --little-endian  use Little Endian when reading/writing (default)
  -b, --big-endian      use Big Endian when reading/writing
  -s {0,8,4}, --swizzle {0,8,4}
                        set the swizzle type of the output BFLIM (default: 0)
                        0 - none; 4 - rotate 90deg; 8 - transpose
  -c png, --create png  create BFLIM file from PNG
  -x, --extract        convert BFLIM to PNG
  -i, --info            just list debug info and quit


'''<span style="font-size: 22px">bflim.py</span>'''
'''Examples:'''
[Convert BFLIM to PNG]
bflim.py -x image.bflim
[Convert PNG to BFLIM]
bflim.py -c image.png image.bflim
[Convert PNG to BFLIM, setting swizzle to 90 degree rotation]
bflim.py -s 4 -c image.png image.bflim


Convert bflim images to and from PNG format for editing.�Supports conversion of all texture formats but cannot create ETC1 bflim files because I didn't need it at the time and ETC1 compression is a bit more involved than just re-encoding pixels [[File:styles/default/xenforo/clear.png|class=mceSmilieSprite mceSmilie2|;)]]
'''Note:''' Swizzling is only applied if OpenCV is available.


'''<span style="font-size: 22px">msbt.py</span>'''
===msbt.py===
String resource extractor for MSBT "MsgStdBn" files. Converts between MSBT and JSON files for translation or string modification.  


Converts the binary &quot;message&quot; text files to a JSON object for editing and re-packing.�Has minimal support for the color format found in RTG and a couple other games I'd found that use colored text.�Fair forewarning: the JSON format is horrible in order to maintain the original binary structure in the event that it matters to the game.�I never tested whether I could modify the structure since this worked well enough.
Has minimal support for the color format found in RTG and a couple other games found that use colored text.


'''<span style="font-size: 22px">sarc.py</span>'''
'''Command line:'''
usage: msbt.py [-h] [-v] [-d] [-c] (-x | -p) [-y] -j JSON msbt_file
MsgStdBn Parser
positional arguments:
  msbt_file            MSBT file to parse
optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose        print more data when working
  -d, --debug          print debug information
  -c, --colors          decode colors in strings
  -x, --extract        extract MSBT to plain text
  -p, --pack            pack plain text into an MSBT file
  -y, --yes            answer "Yes" to any questions (overwriting files)
  -j JSON, --json JSON  JSON document to read from or write to


Extracts and creates SARC archives with zlib compression support.�In RTG all SARC files are zlib-compressed with the size of the original file prepended to the beginning of the file.�This feature may not be needed outside of RTG but it's there [[File:styles/default/xenforo/clear.png|class=mceSmilieSprite mceSmilie48|:)]]�The SARC archives were the main thing keeping the game from accepting my modified files until I had figured out the big thing that differentiates them from the other *ARC formats: sorted entires.�The files are sorted within the archive based on the hash associated with each file entry.�Once that part was figured out the game would boot and everything was spiffy.
'''Examples:'''
[Convert an MSBT to JSON for editing]
msbt.py -x -j Sample.json Sample.msbt
[Convert from JSON back to MSBT]
msbt.py -p -j Sample.json Sample.msbt
[If strings contain color codes (which are invalid UTF-16 bytes) then use the --colors flag to parse them]
msbt.py -x -c -j Sample.json Sample.msbt
[Make sure you mirror the --colors flag when repacking]
msbt.py -p -c -j Sample.json Sample.msbt


'''Colors:'''


'''<span style="font-size: 18px">Dependencies</span>'''
In at least one game, colors are prefixed with two bytes, \u0003\u0004 followed by a 32-bit color code. The --colors flag will ensure that the 4 bytes following the color prefix are not parsed as UTF-16. The resulting output string will look like:
"\u0003\u0004[#ff112233]Color"


bffnt and bflim depend on PyPng:
When packing the MSBT with the --colors flag, the parser will look for those color markers and write them as 4-byte integers just as they were read out originally. Example (little endian):
30 00 40 00 33 22 11 ff 43 6f 6c 6f 72
 
===sarc.py===
SARC (Sorted ARChive?) tool that can extract and pack both uncompressed and ZLIB compressed archives. In RTG all SARC files are zlib-compressed with the size of the original file prepended to the beginning of the file. This feature may not be needed outside of RTG but it's there. Uses TAR-like command line syntax.


'''Command line:'''
usage: sarc.py [-h] [-v] [-d] [-y] [-z] [--compression-level LEVEL]
                (-x | -c | -t) [-l | -b] -f archive
                [file [file ...]]
SARC Archive Tool
positional arguments:
  file                  files to add to an archive
optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose        print more data when working
  -d, --debug          print debug information
  -y, --yes            answer "yes" to questions (overwriting files)
  -z, --zlib            use ZLIB to compress or decompress the archive
  --compression-level LEVEL
                        ZLIB compression level (default: 6)
  -x, --extract        extract the SARC
  -c, --create          create a SARC
  -t, --list            list contents
  -l, --little-endian  use little endian encoding when creating an archive
                        (default)
  -b, --big-endian      use big endian encoding when creating an archive
  -f archive, --archive archive
                        the SARC filename
'''Examples:'''
[Extract an uncompressed SARC]
sarc.py -xf Sample.sarc
[Create a compressed SARC]
sarc.py -czf Sample.zlib file1.txt file2.txt subdir/
[List contents of a compressed SARC]
sarc.py -tzf Sample.zlib
subdir/file3.txt
subdir/file4.txt
file1.txt
file2.txt


===Dependencies===
bffnt and bflim depend on PyPng:
* pypng - https://github.com/drj11/pypng
* pypng - https://github.com/drj11/pypng


 
bflim will utilize OpenCV, if available, for swizzle support (rotate/flip operations on the image):
bflim will utilize OpenCV, if available, for swizzle support (rotate/flip operations on the image)
 
 
* OpenCV
* OpenCV
** Windows - http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
** Windows - http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
** Linux - use your favorite package manager
** Linux - Use your favorite package manager.
** OS X - total pain in the ass with brew/macports, sorry [[File:styles/default/xenforo/clear.png|class=mceSmilieSprite mceSmilie29|:(]]
 
 
If you don't install OpenCV you can perform the de-swizzling yourself with your favorite image editor, but ensure that you re-swizzle images to the orientation they were in before repacking and set the right flag.�In RTG at least, the swizzle still needed to be applied, perhaps because of the Layout remembering or something.
 
'''<span style="font-size: 18px">Special Thanks/References</span>'''
 
Most of the RE work for these file formats were done by other wonderful homebrew developers with only a little extra work needed for the different format versions and missing pieces (The hardest being BFFNT).�None of my work is based off of any proprietary NintendoWare code or tools.
 


* MSBT - http://mk8.tockdom.com/wiki/MSBT_(File_Format)
If you don't install OpenCV you can perform the de-swizzling yourself with your favorite image editor, but ensure that you re-swizzle images to the orientation they were in before repacking and set the right flag. In RTG at least, the swizzle still needed to be applied, perhaps because of the Layout remembering or something.
* BFLIM
** http://mk8.tockdom.com/wiki/BFLIM_(File_Format)
* BFFNT - http://3dbrew.org/wiki/BCFNT (v4 data added by me)
** v4 info gleaned from https://github.com/dnasdw/3dsfont
* SARC - http://mk8.tockdom.com/wiki/SARC_(File_Format)
* Texture format and ETC1 decompression sanity checking thanks to EveryFileExplorer
** https://github.com/Gericom/EveryFileExplorer/blob/master/3DS/GPU/Textures.cs


<div class="messageTextEndMarker">
==Credits==
Most of the RE work for these file formats were done by other wonderful homebrew developers with only a little extra work needed for the different format versions and missing pieces (The hardest being BFFNT). None of these tools are based off of any proprietary NintendoWare code or tools.


Special thanks/References:
* [http://mk8.tockdom.com/wiki/MSBT_(File_Format) MSBT].
* [http://mk8.tockdom.com/wiki/BFLIM_(File_Format) BFLIM].
* [http://3dbrew.org/wiki/BCFNT BFFNT] (v4 data added by ObsidianB, info gleaned from [https://github.com/dnasdw/3dsfont here].
* [http://mk8.tockdom.com/wiki/SARC_(File_Format) SARC].
* [https://github.com/Gericom/EveryFileExplorer/blob/master/3DS/GPU/Textures.cs Texture format and ETC1 decompression sanity checking] thanks to EveryFileExplorer.


</div>
==External links==
* GitHub - https://github.com/ObsidianX/3dstools
* GBAtemp - https://gbatemp.net/threads/release-various-3ds-editing-tools.424118

Latest revision as of 04:25, 6 May 2024

3DS Data Tools
3dspc.png
General
AuthorObsidianB
TypeFile Operation
Version2016
LicenseMixed
Last Updated2016/04/25
Links
Download
Website
Source

This is a set of tools for extracting and packing resources found in 3DS games, aims to be cross-platform compatible and they are all written in Python.

User guide

bffnt.py

BFFNT extract/create tool. Creates a PNG file from the texture atlases in a BFFNT as well as a JSON manifest.

Command line:

usage: bffnt [-h] [-v] [-d] [-y] [-l | -b] (-c | -x) -f bffnt

BFFNT Converter Tool

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         print more data when working
  -d, --debug           print debug information
  -y, --yes             answer yes to any questions (overwriting files)
  -a, --ensure-ascii    turn off ensure_ascii option when dump json file
  -l, --little-endian   Use little endian encoding in the created BFFNT file
                        (default)
  -b, --big-endian      Use big endian encoding in the created BFFNT file
  -c, --create          create BFFNT file from extracted files
  -x, --extract         extract BFFNT into PNG/JSON files
  -f bffnt, --file bffnt
                        BFFNT file

Examples:

[Extract a BFFNT to PNG/JSON...]
bffnt.py -xf Sample.bffnt

[...Results]
Sample_manifest.json
Sample_sheet0.png

[Create a BFFNT from PNG/JSON]
bffnt.py -cf Sample.bffnt

Note: Sample_manifest.json and Sample_sheet0.png must be in the current directory to build Sample.bffnt.

bflim.py

BFLIM converter to and from PNG files. This tool is still in development (supports conversion of all texture formats but cannot create ETC1 bflim files).

Command line:

usage: bflim [-h] [-v] [-d] [-y] [-l | -b] [-s {0,8,4}] (-c png | -x | -i)
             bflim_file

BFLIM Converter 

positional arguments:
  bflim_file            FLIM file 

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         print more data when working
  -d, --debug           print debug information
  -y, --yes             answer yes to any questions (overwriting files)
  -l, --little-endian   use Little Endian when reading/writing (default)
  -b, --big-endian      use Big Endian when reading/writing
  -s {0,8,4}, --swizzle {0,8,4}
                        set the swizzle type of the output BFLIM (default: 0)
                        0 - none; 4 - rotate 90deg; 8 - transpose
  -c png, --create png  create BFLIM file from PNG
  -x, --extract         convert BFLIM to PNG
  -i, --info            just list debug info and quit

Examples:

[Convert BFLIM to PNG]
bflim.py -x image.bflim

[Convert PNG to BFLIM]
bflim.py -c image.png image.bflim

[Convert PNG to BFLIM, setting swizzle to 90 degree rotation]
bflim.py -s 4 -c image.png image.bflim

Note: Swizzling is only applied if OpenCV is available.

msbt.py

String resource extractor for MSBT "MsgStdBn" files. Converts between MSBT and JSON files for translation or string modification.

Has minimal support for the color format found in RTG and a couple other games found that use colored text.

Command line:

usage: msbt.py [-h] [-v] [-d] [-c] (-x | -p) [-y] -j JSON msbt_file

MsgStdBn Parser

positional arguments:
  msbt_file             MSBT file to parse

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         print more data when working
  -d, --debug           print debug information
  -c, --colors          decode colors in strings
  -x, --extract         extract MSBT to plain text
  -p, --pack            pack plain text into an MSBT file
  -y, --yes             answer "Yes" to any questions (overwriting files)
  -j JSON, --json JSON  JSON document to read from or write to

Examples:

[Convert an MSBT to JSON for editing]
msbt.py -x -j Sample.json Sample.msbt

[Convert from JSON back to MSBT]
msbt.py -p -j Sample.json Sample.msbt

[If strings contain color codes (which are invalid UTF-16 bytes) then use the --colors flag to parse them]
msbt.py -x -c -j Sample.json Sample.msbt

[Make sure you mirror the --colors flag when repacking]
msbt.py -p -c -j Sample.json Sample.msbt

Colors:

In at least one game, colors are prefixed with two bytes, \u0003\u0004 followed by a 32-bit color code. The --colors flag will ensure that the 4 bytes following the color prefix are not parsed as UTF-16. The resulting output string will look like:

"\u0003\u0004[#ff112233]Color"

When packing the MSBT with the --colors flag, the parser will look for those color markers and write them as 4-byte integers just as they were read out originally. Example (little endian):

30 00 40 00 33 22 11 ff 43 6f 6c 6f 72

sarc.py

SARC (Sorted ARChive?) tool that can extract and pack both uncompressed and ZLIB compressed archives. In RTG all SARC files are zlib-compressed with the size of the original file prepended to the beginning of the file. This feature may not be needed outside of RTG but it's there. Uses TAR-like command line syntax.

Command line:

usage: sarc.py [-h] [-v] [-d] [-y] [-z] [--compression-level LEVEL]
               (-x | -c | -t) [-l | -b] -f archive
               [file [file ...]]

SARC Archive Tool 

positional arguments:
  file                  files to add to an archive

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         print more data when working
  -d, --debug           print debug information
  -y, --yes             answer "yes" to questions (overwriting files)
  -z, --zlib            use ZLIB to compress or decompress the archive
  --compression-level LEVEL
                        ZLIB compression level (default: 6)
  -x, --extract         extract the SARC
  -c, --create          create a SARC
  -t, --list            list contents
  -l, --little-endian   use little endian encoding when creating an archive
                        (default)
  -b, --big-endian      use big endian encoding when creating an archive
  -f archive, --archive archive
                        the SARC filename

Examples:

[Extract an uncompressed SARC]
sarc.py -xf Sample.sarc

[Create a compressed SARC]
sarc.py -czf Sample.zlib file1.txt file2.txt subdir/

[List contents of a compressed SARC]
sarc.py -tzf Sample.zlib

subdir/file3.txt
subdir/file4.txt
file1.txt
file2.txt

Dependencies

bffnt and bflim depend on PyPng:

bflim will utilize OpenCV, if available, for swizzle support (rotate/flip operations on the image):

If you don't install OpenCV you can perform the de-swizzling yourself with your favorite image editor, but ensure that you re-swizzle images to the orientation they were in before repacking and set the right flag. In RTG at least, the swizzle still needed to be applied, perhaps because of the Layout remembering or something.

Credits

Most of the RE work for these file formats were done by other wonderful homebrew developers with only a little extra work needed for the different format versions and missing pieces (The hardest being BFFNT). None of these tools are based off of any proprietary NintendoWare code or tools.

Special thanks/References:

External links

Advertising: