resonance 1.0.1
Loading...
Searching...
No Matches
OpenArkObject Class Reference

Mounted ark archive. More...

#include <openarkobject.h>

Public Member Functions

 OpenArkObject ()
 Construct an unmounted archive.
 ~OpenArkObject ()
 Release the tables the mount allocated.
int OpenStream (ArkFileEntry *pEntry)
 Open a stream on one file of this archive.
void PrintHeader () const
 Write every field of the copied archive header to standard output.
void PrintRelPaths () const
 Write every entry of the relative path table to standard output.
void PrintFiles () const
 Write every entry of the file table to standard output.
void DumpStrings () const
 Write every file name and every relative path to standard output.
void PrintAll () const
 Write the header, the file table, the relative path table, and the strings, in that order.

Static Public Member Functions

static int Open (const char *pszPath)
 Mount an ark archive by path.
static int Close (const char *pszPath)
 Unmount a previously mounted archive.
static ArkFileEntry * FindFileEntryByPath (const char *pszPath, char *pszName, char *pszRelPath, int *pnArk)
 Find the entry of a file in whichever mounted archive the path maps to.

Friends

OpenArkObject * ArkStream::FindArk () const
int SeekArkStream (int nStream, int nOffset, int nOrigin)
 Move an ark stream's read position.
int ArkfileGetBaseSector (int nFile)
 Report the disc sector a mounted archive starts at.
int ArkfileLogicalToPhysicalSector (int nFile, int nSector)
 Map a chunk of an archive to the chunk position the disc stores it at.

Detailed Description

Mounted ark archive.

An ark stores the game's data files in one seekable blob, so the streaming layer can read a file without a directory lookup per file. This class is not polymorphic and has no RTTI, so it has no vptr. Its name comes from the debug strings of its dump routines, and its allocations use the ArkFile.cpp tag. The record is 424 bytes and begins with an embedded HxStr. The mount therefore assigns a path through the record pointer itself.

A mount copies the whole 256-byte header into the record, then allocates one block for the file table, the relative path table, and the string table together, and rebases every string offset into that block. The header's own path is lowercased in place and must include a run component, which is what fixes the archive's mount point.

The header member titles come from the labels PrintHeader() writes. The data members are private. The stream and sector routines of this unit (ArkStream::FindArk(), SeekArkStream(), ArkfileGetBaseSector(), and ArkfileLogicalToPhysicalSector()) are free functions that read the file, sector size, base sector, and optimized block members directly, and are friends.

Constructor & Destructor Documentation

◆ OpenArkObject()

OpenArkObject::OpenArkObject ( )

Construct an unmounted archive.

Only the path and the four table pointers are cleared. mFile is deliberately not, which the one unreachable branch of Open() depends on.

◆ ~OpenArkObject()

OpenArkObject::~OpenArkObject ( )

Release the tables the mount allocated.

The destructor is inlined into Close(), which is where its line number comes from.

Ghidra address:
NTSC-U/C: 0x00559f70
Ghidra address:
PAL: 0x0059b180

Member Function Documentation

◆ Open()

int OpenArkObject::Open ( const char * pszPath)
static

Mount an ark archive by path.

Parameters
pszPathThe archive path, relative to the data root.
Returns
Non-zero on success.
Ghidra address:
NTSC-U/C: 0x00559858
Ghidra address:
PAL: 0x0059a9b0

◆ Close()

int OpenArkObject::Close ( const char * pszPath)
static

Unmount a previously mounted archive.

The unmount is refused, and reports zero, when the path is not mounted and when a stream is still open on the archive's file. In the second case the offending stream record is erased first.

Parameters
pszPathThe same path that was passed to Open().
Returns
Non-zero when the archive was unmounted.
Ghidra address:
NTSC-U/C: 0x00559f70
Ghidra address:
PAL: 0x0059b180

◆ FindFileEntryByPath()

ArkFileEntry * OpenArkObject::FindFileEntryByPath ( const char * pszPath,
char * pszName,
char * pszRelPath,
int * pnArk )
static

Find the entry of a file in whichever mounted archive the path maps to.

The path is copied, with every backslash turned into a slash and every capital letter lowercased, before OpenArkObject::MapPathToArkIndex() splits it and selects the archive. The archive's file table is then searched for the name and relative path hashes, and the strings confirm a hash match.

Parameters
pszPathThe path to find.
pszNameReceives the file name, at least kArkNameBufferSize bytes.
pszRelPathReceives the path relative to the archive's mount point, at least kArkRelPathBufferSize bytes.
pnArkReceives the index of the archive in g_apMountedArks, or -1 when the file was not found.
Returns
The file entry, or null when the file was not found.
Ghidra address:
NTSC-U/C: 0x0055a6d0
Ghidra address:
PAL: 0x0059b8f0

◆ OpenStream()

int OpenArkObject::OpenStream ( ArkFileEntry * pEntry)

Open a stream on one file of this archive.

The stream starts at the file's first byte, and its record is appended to gOpenArkFileTable.

Parameters
pEntryThe file to read, one of this archive's file entries.
Returns
The new stream handle, without kFileHandleArkStream.
Ghidra address:
NTSC-U/C: 0x0055c288
Ghidra address:
PAL: 0x0059d4a8

◆ PrintHeader()

void OpenArkObject::PrintHeader ( ) const

Write every field of the copied archive header to standard output.

The shipped program does not call it.

Ghidra address:
NTSC-U/C: 0x0055aa38
Ghidra address:
PAL: 0x0059bc58

◆ PrintRelPaths()

void OpenArkObject::PrintRelPaths ( ) const

Write every entry of the relative path table to standard output.

The shipped program does not call it.

Ghidra address:
NTSC-U/C: 0x0055ac30
Ghidra address:
PAL: 0x0059be50

◆ PrintFiles()

void OpenArkObject::PrintFiles ( ) const

Write every entry of the file table to standard output.

The shipped program does not call it.

Ghidra address:
NTSC-U/C: 0x0055ada0
Ghidra address:
PAL: 0x0059bfc0

◆ DumpStrings()

void OpenArkObject::DumpStrings ( ) const

Write every file name and every relative path to standard output.

The shipped program does not call it.

Ghidra address:
NTSC-U/C: 0x0055afc8
Ghidra address:
PAL: 0x0059c1e8

◆ PrintAll()

void OpenArkObject::PrintAll ( ) const

Write the header, the file table, the relative path table, and the strings, in that order.

The shipped program does not call it.

Ghidra address:
NTSC-U/C: 0x0055c3a0
Ghidra address:
PAL: 0x0059d5c0

◆ ArkStream::FindArk

OpenArkObject * ArkStream::FindArk ( ) const
friend

◆ SeekArkStream

int SeekArkStream ( int nStream,
int nOffset,
int nOrigin )
friend

Move an ark stream's read position.

A resulting position before the start of the stream is clamped back to the start. A stream whose archive is no longer mounted, and an origin outside FileSeekOrigin, both report -1.

Parameters
nStreamThe ark stream handle, kFileHandleArkStream included.
nOffsetThe offset to move by.
nOriginOne of FileSeekOrigin.
Returns
The resulting position, or -1 when no stream record has that handle.
Ghidra address:
NTSC-U/C: 0x0055bd38
Ghidra address:
PAL: 0x0059cf58

◆ ArkfileGetBaseSector

int ArkfileGetBaseSector ( int nFile)
friend

Report the disc sector a mounted archive starts at.

A file that is not a mounted archive is fatal, and the report lists every mounted archive's file before stopping.

Parameters
nFileThe archive's file.
Returns
The archive's start sector.
Ghidra address:
NTSC-U/C: 0x0055a590
Ghidra address:
PAL: 0x0059b7b0

◆ ArkfileLogicalToPhysicalSector

int ArkfileLogicalToPhysicalSector ( int nFile,
int nSector )
friend

Map a chunk of an archive to the chunk position the disc stores it at.

An archive built without the optimized block stores its chunks in order, and the argument is returned unchanged. An optimized archive stores them in the order the game reads them, and its optimized block is an array of two-byte logical chunk indices whose slot number is the position on the disc. The lookup is therefore a search of that array for the logical index, returning the slot it was found in.

OpenArkObject::mOptimizedCursor makes the common case constant time. It records the slot after the one the last lookup resolved. That is the slot a sequential read wants next. A miss on the guess reports through the log, abandons the cursor, and falls back to searching the whole array. A chunk that appears in no slot is fatal.

A file that is not a mounted archive is reported through the log, and the argument is returned unchanged.

Parameters
nFileThe archive's file.
nSectorThe logical chunk index.
Returns
The chunk position on the disc.
Ghidra address:
NTSC-U/C: 0x0055a410
Ghidra address:
PAL: 0x0059b630

The documentation for this class was generated from the following file: