Why PS1 Harry Potter?

This week, while teaching a cybersecurity course over the summer, I found myself inspired to dive into a personal project that blended my hacking and retro gaming: reverse-engineering a PS1 game.

Months ago my girlfriend and I played through the Harry Potter games on the PS1, enjoying the mix of nostalgic gameplay and the unique charm of the PlayStation 1 era jank. Back then I was intrigued by the idea of modding these games but between exams and other university commitments I never got the chance to try. This week seemed like the perfect opportunity to finally try.

An in-game screenshot of the Philosopher’s Stone PS1 game

Introducing Hagrid, A Game Archive Extractor And Repacker

The culmination of my efforts is a tool called ‘hagrid’, which you can find here. Hagrid is designed to extract and repack the archive files used by these games—specifically, the POTTER.DAT and POTTER.DIR files.

Its usage can be seen below: Extracting and repacking game files using hagrid

Extracting The Data From .bin & .cue Files And Repacking It

Before starting to describe the formats I feel it is important to explain how to extract and repack PS1 games correctly, as the public information on it is very lacking, and it might help future PS1 modders and reverse-engineers.

PS1 discs can be extracted and repacked using the tool mkpsxiso, which takes xml descriptions of game files to reassemble the .bin/.cue combination needed by emulators and disc burning software to run the game.

Extracting

To extract and dump the .bin/.cue files of the game, use the following command:

dumpsxiso  potter01.bin -x potter01_extracted -s potter01_repack.xml

Or execute ‘dumpiso.sh’ in the hagrid repo

Repacking

To repack the game using the XML file generated by dumpsxiso run:

mkpsxiso potter01_repack.xml

Or run ‘buildiso.sh’ from the hagrid repo

POTTER.DAT And POTTER.DIR

The games data files (maps, textures, models etc.) are all stored in a large archive, called POTTER.DIR.

To look up and open these files POTTER.DIR must be referenced which lists the offsets and information within POTTER.DIR to extract the files.

The .DAT Format

The .DAT format is really simple as it relies on the indexing of the .DIR format for resolving the files. Each file is simply inserted into the file directly, joined back to back, but with zero padding for each file to make their size a multiple of 2kb. The files are inserted in the order specified in the .DIR file (largely alphabetical, and can be repacked as such, but the base game is slightly non-alphabetical in ordering for some reason).

The .DIR Format

The .DIR format specifies what files are in the .DAT file, and their lengths and offsets. The format is as follows:

  • All data is encoded as little-endian
  • It starts with a 4 byte header, which is the number of files inside the archive (202 in the base game for the Philosopher’s Stone)
  • Then the file is just a repeated structure as follows:
    • A 12 byte long filename, without a null terminator but 0x00 padded to 12 bytes always
    • A 4 byte (uint32_t) filesize, in bytes, of the file in the .DAT file
    • A 4 byte offset into the .DAT file, dictating where the file starts

As such extraction of files is as simple as reading these repeated entries and copying the data out to files, terminating the name and making it the filename

Future Developments

There is a lot of room for future developments to be made with the game files, particularly in the creation of GUI programs such as level editors:

  • .WAD Files: The game stores collections of files in .WAD format. By breaking down these chunks, we can gain further access to the game files, enabling features like custom levels
  • .IMG Format: Textures are stored in the .IMG format, which, while known and extractable, can be cumbersome to work with. Adding functionality to Hagrid to convert these to and from .bmp could be greatly useful
  • Map Editors: Editing tools could be developed to load and modify the map files (especially since the developers conveniently left a .WAD with a template test level in the game files)
  • PC Port: Ultimately, with enough effort in reversing formats and re-implementing gameplay, a full PC port could be created, but this is largely outside of my plans due to the lengthy time needed for its creation