ndspy.fnt
: Filename Tables¶
ROM files (ndspy.rom
) and NARC archives (ndspy.narc
) both
use the same format for filename tables. ndspy.fnt
provides a consistent
interface for these.
Warning
Some games (such as New Super Mario Bros.) load files by hardcoded file IDs rather than by their filenames. Thus, when editing filename tables, you should avoid changing existing file IDs unless you’re sure that the game loads files by their filenames.
A filename table is represented as a Folder
. This class does not
contain any file data; it merely defines the folder hierarchy, and names of
folders and files. As such, this particular page of documentation page will use
the terms “filename” and “file” rather interchangeably.
Filenames and file IDs¶
It’s important to understand how file IDs relate to filenames. Here’s an example directory structure showing both filenames and file IDs:
(root)/ 87
barrier-skip.mp4 (87)
sm64-upwarp.zip (88)
books/ 89
hyrule-historia.pdf (89)
ndspy-documentation.pdf (90)
lord-of-the-rings/ 91
book1.pdf (91)
book2.pdf (92)
book3.pdf (93)
songs/ 94
smb3-athletic.mp3 (94)
zeldas-lullaby.mp3 (95)
Folders have a “first ID” attribute (Folder.firstID
) that specifies
the ID of the first file within the folder; these are shown above as numbers
without parentheses. The files within the folder then implicitly have ascending
file IDs starting with that value; these are shown above as parenthesized
numbers.
Files in a folder’s subfolders have IDs greater than those of the files directly in the folder. Files and folders are usually sorted in ASCIIbetical order, though that probably does not have to be the case.
File IDs referenced by a filename table do not always start at 0. ROMs, for instance, usually include overlays as unnamed files starting at ID 0, causing the filename table to begin at some higher file ID.
- ndspy.fnt.save(root)¶
Generate a
bytes
object representing this root folder as a filename table. This is the inverse ofload()
.
- class ndspy.fnt.Folder([folders[, files[, firstID]]])¶
A single folder within a filename table, or an entire filename table – ndspy does not make a distinction between these. It can contain subfolders (
folders
) and files (files
).All files within a folder implicitly have consecutive IDs. This is done by only specifying the ID of the first file in the folder (
firstID
). The second file in the folder then has file ID “firstID
+ 1”, the third has “firstID
+ 2”, etc. See the introduction to this page for a more thorough explanation.- Parameters:
Note
For convenience,
Folder
supports indexing syntax (folder[key]
):If the key is a
int
, indexing is equivalent to callingfilenameOf()
.If the key is a
str
, indexing is equivalent to first callingidOf()
, and then callingsubfolder()
if that returnsNone
.
Thus, you can index by file ID to retrieve a filename, index by filename to get a file ID, and index by subfolder name to get a
Folder
instance.Warning
Unless you know exactly what the filename table you’re parsing contains, it’s a good idea to explicitly use
idOf()
andsubfolder()
instead of indexing syntax for retrieving file IDs. Indexing syntax is the same for accessing both files and subfolders, so you may run into confusing problems if a subfolder with the same name as the file you’re looking for exists, or vice versa.- files¶
The files within this folder. The first one implicitly has file ID
firstID
, the second has file ID “firstID
+ 1”, and so on.
- firstID¶
The file ID of the first file within this folder (that is, the file ID of “
files
[0]”).- Type:
- Default:
0
- folders¶
The folders contained within this folder.
This is presented as a list of name-value pairs because
collections.OrderedDict
– the best choice for an order-preserving dictionary type – does not provide an easy way to adjust the order of its elements.See also
ndspy.indexInNamedList()
,ndspy.findInNamedList()
,ndspy.setInNamedList()
– helper functions you can use to find and replace values in this list.
- idOf(path)¶
Find the file ID for the given filename, or for the given file path (using
/
as the separator) relative to this folder.See also
subfolder()
The equivalent function for finding folders instead of files.
- filenameOf(id)¶
Find the filename of the file with the given ID. If it exists in a subfolder, the filename will be returned as a path separated by forward slashes (
/
).