Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

3DS Data Tools: Difference between revisions

From GameBrew
m (Text replacement - "image = https://dlhb.gamebrew.org/3dshomebrew/" to "image = ")
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Infobox-3DS-Homebrews
{{Infobox 3DS Homebrews
| title = 3DS Data Tools
|title=3DS Data Tools
| image = 3DSDataTools.jpg|250px
|image=3dspc.png
| type = PC Utilities
|description=Tools for extracting and packing resources found in 3DS games.
| version=2016
|author=ObsidianB
| lastupdated = 2016/04/25
|lastupdated=2023/06/24
| licence = Mixed
|type=File Operation
| author = ObsidianB
|version=2023
| website = https://gbatemp.net/threads/release-various-3ds-editing-tools.424118/
|license=Mixed
| download = https://dlhb.gamebrew.org/3dshomebrew/3DSDataTools.rar
|download=https://dlhb.gamebrew.org/3dshomebrews/3dsdatatools.7z
| source = https://github.com/ObsidianX/3dstools
|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.
'''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


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.
'''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


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


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.
===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).


==bflim.py==
'''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


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|;)]]
'''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


==msbt.py==
'''Note:''' Swizzling is only applied if OpenCV is available.


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.
===msbt.py===
String resource extractor for MSBT "MsgStdBn" files. Converts between MSBT and JSON files for translation or string modification.  


'''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.


==sarc.py==
'''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.
'''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


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.
'''Colors:'''


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.
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"


==Dependencies==
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:
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


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.
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.


==Special Thanks/References==
==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.


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.
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.


* MSBT - http://mk8.tockdom.com/wiki/MSBT_(File_Format)
==External links==
* BFLIM
* GitHub - https://github.com/ObsidianX/3dstools
** http://mk8.tockdom.com/wiki/BFLIM_(File_Format)
* GBAtemp - https://gbatemp.net/threads/release-various-3ds-editing-tools.424118
* 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

Latest revision as of 11:31, 22 Haziran 2024

3DS Data Tools
3dspc.png
General
AuthorObsidianB
TypeFile Operation
Version2023
LicenseMixed
Last Updated2023/06/24
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: