Pokémon Mystery Dungeon: Red Rescue Team/pksdir0: Difference between revisions

From Data Crystal
Jump to navigation Jump to search
(i reverse engineered some functions relating to the pksdir directory structures, and updated this page with my findings.)
m (some amendmends as i learn a bit more)
Line 3: Line 3:
"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.
"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.
In some instances, 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 a lot more often outside of such a structure with no known purpose. In fact, the game only seems to contain 9 such structures total in contrast to the many times the string occurs in each version.
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.
Modifying or removing these strings might be safe in instances when it is '''not''' part of a directory structure, but care should still be taken as the reason for their presence is still unknown.


The directory structure is laid out as follows:
The directory structure is laid out as follows:
Line 22: Line 22:
04 (0x04)    4    pointer to the actual file data
04 (0x04)    4    pointer to the actual file data
</pre>
</pre>
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 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 [[Pokémon Mystery Dungeon: Red Rescue Team|SIRO Data Header]] (also see this [https://projectpokemon.org/home/docs/mystery-dungeon-nds/sir0siro-format-r46/ 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.
The code reading those directory structures has special handling for files with a [[Pokémon Mystery Dungeon: Red Rescue Team|SIRO Data Header]] (also see this [https://projectpokemon.org/home/docs/mystery-dungeon-nds/sir0siro-format-r46/ 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 [[Pokémon Mystery Dungeon: Blue Rescue Team|Blue Rescue Team]], likely because of the built-in support for files and directories of the DS.
These strings are not present in [[Pokémon Mystery Dungeon: Blue Rescue Team|Blue Rescue Team]].

Revision as of 14:49, 1 August 2021

This is a sub-page of Pokémon Mystery Dungeon: Red Rescue Team.

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

In some instances, 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 a lot more often outside of such a structure with no known purpose. In fact, the game only seems to contain 9 such structures total in contrast to the many times the string occurs in each version. Modifying or removing these strings might be safe in instances when it is not part of a directory structure, but care should still be taken as the reason for their presence is still unknown.

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 are not present in Blue Rescue Team.