Pokémon Mystery Dungeon: Red Rescue Team:pksdir0

From Data Crystal
Revision as of 12:17, 23 July 2021 by Rabbit (talk | contribs) (i reverse engineered some functions relating to the pksdir directory structures, and updated this page with my findings.)
Jump to navigation Jump to search

"pksdir0" is a 7-characters string with a null ending character, present several hundreds of times in the ROM, with different amount for different region localization.

It is part of a pseudo-directory structure used by the game to compensate the GBAs lack of built-in file/directory support, but also occurs outside of that structure with no known purpose. Special care should be taken in evaluating its usage context before modifying these strings or any data near them/following them, as the game ensures that the string is present when parsing the directory structure.

The directory structure is laid out as follows:

 offset    length    description
---------  ------   -------------
00 (0x00)     8     null-terminated "pksdir0" string (the game checks for this string, and refuses to load/find files if it is incorrect)
08 (0x08)     4     a four-byte integer holding the number of file entries in this pksdir structure
12 (0x0B)     4     little-endian GBA pointer to the table of file entries

The file entry structure referenced by the last pointer is similarly simple, each entry being 8 bytes in size:

 offset    length    description
---------  ------   -------------
00 (0x00)     4     pointer to a string with the filename
04 (0x04)     4     pointer to the actual file data

The file entries in the file entry table *have* to be in alphabetical order, more specifically in an ascending order according to their ANSI values with shorter names first (the game uses a special search algorithm that takes advantage of this ordering).

The code reading those directory structures has special handling for files with a SIRO Data Header (also see this SIR0/SIRO format decription). Red Rescue Team contains only the "pre-loaded" SIRO headers, and the function that is supposed to take a SIR0 header and load it into memory (becoming a SIRO header in the process) is a stub that simply returns without doing anything.

These strings (and by extension the directory structures) are not present in Blue Rescue Team, likely because of the built-in support for files and directories of the DS.