resonance 1.0.1
Loading...
Searching...
No Matches
openarkobject.h File Reference
#include <vector>
#include "os/hxstr.h"
Include dependency graph for openarkobject.h:

Go to the source code of this file.

Classes

struct  ArkFileEntry
 One entry of the archive's file table. More...
struct  ArkRelPath
 One entry of the archive's relative path table, which lists the directories the files are in. More...
struct  ArkStream
 One open stream on a mounted archive. More...
class  OpenArkObject
 Mounted ark archive. More...

Functions

short HashArkString (const char *pszName)
 Hash a file name or a relative path for the table searches.
int EraseArkStream (int nHandle)
 Erase a stream record by handle.
ArkStream * LookupOpenFile (int nHandle)
 Find the record of an open stream.
ArkFileEntry * FindOpenFileInArk (int nHandle)
 Report the file entry a stream reads.
int OpenFileInArk (const char *pszPath)
 Open a stream on a file inside a mounted archive.
int GetArkFileLengthByPath (const char *pszPath)
 Report the stored length of a file inside a mounted archive.
int ReadArkStreamThroughCache (int nHandle, void *pBuffer, unsigned nBytes)
 Read from an ark stream through the sector cache.
int IoctlFile (int nFile, int nRequest, void *pArg)
 Forward a control request to sceIoctl().
void WaitForFileIdle (int nFile)
 Wait until no asynchronous operation is running on a file.
int GetArkfileIdFromFileFd (int nHandle)
 Report the archive a stream reads from.
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.
int InitArk ()
 Mount the archives the game needs for the whole session.
int CloseArk ()
 Unmount the archives InitArk() mounted.

Variables

constexpr int kArkHeaderSize = 0x100
 The number of bytes of the archive header the mount copies into the record.
constexpr int kArkVersion = 2
 The archive header version the mount accepts.
constexpr int kArkMountPointSize = 0x80
 The number of bytes the mount point occupies, which is the rest of the record.
constexpr int kArkSectorCacheRows = 8
 Rows the sector cache is asked for on the first mount.
constexpr int kArkDevicePathSize = 0x100
 The number of bytes of the device path Open() builds on its stack.
constexpr char kArkDiscRoot [] = "cdrom0:\\ARK"
 Directory the archives live in on the disc.
constexpr char kArkHostRoot [] = "host0:"
 Prefix that reads an archive over the host link instead.
constexpr char kArkRunComponent [] = "run"
 Path component of the archive header that fixes the mount point.
constexpr int kArkPathBufferSize = 0x80
 Bytes of the lowercased path copy OpenArkObject::FindFileEntryByPath() builds on its stack.
constexpr int kArkNameBufferSize = 0x80
 Bytes every caller of OpenArkObject::FindFileEntryByPath() reserves for the file name.
constexpr int kArkRelPathBufferSize = 0x100
 Bytes every caller of OpenArkObject::FindFileEntryByPath() reserves for the relative path.
constexpr int kArkIndexAny = 100
 Archive index that asks OpenArkObject::FindFileEntryByPath() to search every mounted archive.
constexpr int kSessionArkCount = 3
 The number of archives in g_apSessionArkPaths.
const char *const g_apSessionArkPaths [kSessionArkCount]
 The archives InitArk() mounts for the session and CloseArk() unmounts: ark/root.ark, ark/levels.ark, and ark/arenas.ark.
std::vector< OpenArkObject * > g_apMountedArks
 Every archive mounted right now.
std::vector< ArkStream > gOpenArkFileTable
 Every stream open on a mounted archive.
int gOpenFileIndex
 Handle OpenArkObject::OpenStream() gives the next stream, incremented after every open.

Function Documentation

◆ HashArkString()

short HashArkString ( const char * pszName)

Hash a file name or a relative path for the table searches.

Each character is shifted left by one more place than the character before it, the shift wrapping from 7 back to 0, and combined into a 16-bit accumulator with exclusive or.

Parameters
pszNameThe string to hash.
Returns
The hash.
Ghidra address:
NTSC-U/C: 0x0055c340
Ghidra address:
PAL: 0x0059d560

◆ EraseArkStream()

int EraseArkStream ( int nHandle)

Erase a stream record by handle.

Parameters
nHandleThe stream handle.
Returns
Zero when the record was erased, or -1 when no record has that handle.
Ghidra address:
NTSC-U/C: 0x0055a1a0
Ghidra address:
PAL: 0x0059b3c0

◆ LookupOpenFile()

ArkStream * LookupOpenFile ( int nHandle)

Find the record of an open stream.

kFileHandleArkStream is masked off the handle before the search. A caller may therefore pass the handle with the bit or without it.

Parameters
nHandleThe stream handle.
Returns
The record, or null when no record has that handle.
Ghidra address:
NTSC-U/C: 0x0055c158
Ghidra address:
PAL: 0x0059d378

◆ FindOpenFileInArk()

ArkFileEntry * FindOpenFileInArk ( int nHandle)

Report the file entry a stream reads.

The entry is what gives a caller the stream's stored and inflated sizes without a file table search of its own. The search walks the stream vector here rather than through LookupOpenFile(), and it masks kFileHandleArkStream off the handle in the same way.

Parameters
nHandleThe stream handle, with the bit or without it.
Returns
The entry, or null when no record has that handle.
Ghidra address:
NTSC-U/C: 0x0055be80
Ghidra address:
PAL: 0x0059d0a0

◆ OpenFileInArk()

int OpenFileInArk ( const char * pszPath)

Open a stream on a file inside a mounted archive.

Parameters
pszPathThe path of the file.
Returns
The stream handle, without kFileHandleArkStream, or -1 when no mounted archive lists the file.
Ghidra address:
NTSC-U/C: 0x0055bce8
Ghidra address:
PAL: 0x0059cf08

◆ GetArkFileLengthByPath()

int GetArkFileLengthByPath ( const char * pszPath)

Report the stored length of a file inside a mounted archive.

The shipped program does not call it.

Parameters
pszPathThe path of the file.
Returns
The length in bytes, or -1 when no mounted archive lists the file.
Ghidra address:
NTSC-U/C: 0x0055bee0
Ghidra address:
PAL: 0x0059d100

◆ ReadArkStreamThroughCache()

int ReadArkStreamThroughCache ( int nHandle,
void * pBuffer,
unsigned nBytes )

Read from an ark stream through the sector cache.

The request is clamped to the bytes left in the file. Each 64 KiB chunk the read touches is taken from the cache, and a chunk the cache does not have is read into the least recently used row first, at the position ArkfileLogicalToPhysicalSector() maps it to. A cached chunk the current asynchronous operation is still filling waits for that operation through AsyncCheck().

Parameters
nHandleThe stream handle.
pBufferThe destination.
nBytesThe number of bytes requested.
Returns
The number of bytes read, or -1 when no record has that handle or the stream is at the end of its file.
Ghidra address:
NTSC-U/C: 0x0055a280
Ghidra address:
PAL: 0x0059b4a0

◆ IoctlFile()

int IoctlFile ( int nFile,
int nRequest,
void * pArg )

Forward a control request to sceIoctl().

The shipped program does not call it.

Parameters
nFileThe file descriptor.
nRequestThe request.
pArgThe request argument.
Returns
The sceIoctl() result.
Ghidra address:
NTSC-U/C: 0x0055c3e0
Ghidra address:
PAL: 0x0059d600

◆ WaitForFileIdle()

void WaitForFileIdle ( int nFile)

Wait until no asynchronous operation is running on a file.

The routine polls sceIoctl() with kSceFsExecuting and performs no other work between the polls. A negative descriptor returns at once. The shipped program does not call it.

Parameters
nFileThe file descriptor.
Ghidra address:
NTSC-U/C: 0x0055c458
Ghidra address:
PAL: 0x0059d678

◆ GetArkfileIdFromFileFd()

int GetArkfileIdFromFileFd ( int nHandle)

Report the archive a stream reads from.

Parameters
nHandleThe stream handle.
Returns
The archive's file, or -1 when no record has that handle.
Ghidra address:
NTSC-U/C: 0x0055c000
Ghidra address:
PAL: 0x0059d220

◆ ArkfileGetBaseSector()

int ArkfileGetBaseSector ( int nFile)

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 )

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

◆ InitArk()

int InitArk ( )

Mount the archives the game needs for the whole session.

Performs no work when ark archives are not in use. The first archive that fails to mount is reported on cout, and the archives after it are not tried.

Returns
Non-zero when every archive was mounted.
Ghidra address:
NTSC-U/C: 0x004dfb20
Ghidra address:
PAL: 0x0051e280

◆ CloseArk()

int CloseArk ( )

Unmount the archives InitArk() mounted.

Each archive is closed through OpenArkObject::Close() even when an earlier one was refused. The result counts the unmounts, so it is zero after a successful teardown. It is non-zero only when ark archives are not in use or when none of the three was still mounted.

Returns
Non-zero when no archive was unmounted.
Ghidra address:
NTSC-U/C: 0x004dfbd8
Ghidra address:
PAL: 0x0051e338

Variable Documentation

◆ kArkHeaderSize

int kArkHeaderSize = 0x100
constexpr

The number of bytes of the archive header the mount copies into the record.

◆ kArkVersion

int kArkVersion = 2
constexpr

The archive header version the mount accepts.

◆ kArkMountPointSize

int kArkMountPointSize = 0x80
constexpr

The number of bytes the mount point occupies, which is the rest of the record.

◆ kArkSectorCacheRows

int kArkSectorCacheRows = 8
constexpr

Rows the sector cache is asked for on the first mount.

◆ kArkDevicePathSize

int kArkDevicePathSize = 0x100
constexpr

The number of bytes of the device path Open() builds on its stack.

◆ kArkDiscRoot

char kArkDiscRoot[] = "cdrom0:\\ARK"
constexpr

Directory the archives live in on the disc.

◆ kArkHostRoot

char kArkHostRoot[] = "host0:"
constexpr

Prefix that reads an archive over the host link instead.

◆ kArkRunComponent

char kArkRunComponent[] = "run"
constexpr

Path component of the archive header that fixes the mount point.

◆ kArkPathBufferSize

int kArkPathBufferSize = 0x80
constexpr

Bytes of the lowercased path copy OpenArkObject::FindFileEntryByPath() builds on its stack.

◆ kArkNameBufferSize

int kArkNameBufferSize = 0x80
constexpr

Bytes every caller of OpenArkObject::FindFileEntryByPath() reserves for the file name.

◆ kArkRelPathBufferSize

int kArkRelPathBufferSize = 0x100
constexpr

Bytes every caller of OpenArkObject::FindFileEntryByPath() reserves for the relative path.

◆ kArkIndexAny

int kArkIndexAny = 100
constexpr

Archive index that asks OpenArkObject::FindFileEntryByPath() to search every mounted archive.

OpenArkObject::MapPathToArkIndex() never reports it, and the search is therefore unreachable.

◆ kSessionArkCount

int kSessionArkCount = 3
constexpr

The number of archives in g_apSessionArkPaths.

◆ g_apSessionArkPaths

const char* const g_apSessionArkPaths[kSessionArkCount]
extern

The archives InitArk() mounts for the session and CloseArk() unmounts: ark/root.ark, ark/levels.ark, and ark/arenas.ark.

Ghidra address:
NTSC-U/C: 0x00702650
Ghidra address:
PAL: 0x007460a0

◆ g_apMountedArks

std::vector<OpenArkObject *> g_apMountedArks
extern

Every archive mounted right now.

Ghidra address:
NTSC-U/C: 0x00725e90
Ghidra address:
PAL: 0x00769b30

◆ gOpenArkFileTable

std::vector<ArkStream> gOpenArkFileTable
extern

Every stream open on a mounted archive.

Ghidra address:
NTSC-U/C: 0x00725ea0
Ghidra address:
PAL: 0x00769b40

◆ gOpenFileIndex

int gOpenFileIndex
extern

Handle OpenArkObject::OpenStream() gives the next stream, incremented after every open.

Ghidra address:
NTSC-U/C: 0x00725e88
Ghidra address:
PAL: 0x00769b28