resonance 1.0.1
Loading...
Searching...
No Matches
openarkobject.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include "os/hxstr.h"
6
8constexpr int kArkHeaderSize = 0x100;
9
11constexpr int kArkVersion = 2;
12
14constexpr int kArkMountPointSize = 0x80;
15
17constexpr int kArkSectorCacheRows = 8;
18
20constexpr int kArkDevicePathSize = 0x100;
21
23constexpr char kArkDiscRoot[] = "cdrom0:\\ARK";
24
26constexpr char kArkHostRoot[] = "host0:";
27
29constexpr char kArkRunComponent[] = "run";
30
32constexpr int kArkPathBufferSize = 0x80;
33
35constexpr int kArkNameBufferSize = 0x80;
36
38constexpr int kArkRelPathBufferSize = 0x100;
39
45constexpr int kArkIndexAny = 100;
46
57 unsigned short mNameHash;
58 unsigned short mFlags;
61 unsigned short mSectorOffset;
62 int mSector;
63 int mLength;
64 int mSize;
65};
66
74struct ArkRelPath {
75 unsigned short mPathHash;
76 unsigned short mFlags;
78};
79
91short HashArkString(const char *pszName);
92
93class OpenArkObject;
94
116
137public:
146 static int Open(const char *pszPath);
147
155
168 static int Close(const char *pszPath);
169
179
198 static ArkFileEntry *
199 FindFileEntryByPath(const char *pszPath, char *pszName, char *pszRelPath, int *pnArk);
200
212
221 void PrintHeader() const;
222
231 void PrintRelPaths() const;
232
241 void PrintFiles() const;
242
251 void DumpStrings() const;
252
261 void PrintAll() const;
262
263private:
282 static int MapPathToArkIndex(const char *pszPath, char *pszName, char *pszRelPath);
283
299 ArkFileEntry *FindFileEntry(short nNameHash,
300 short nRelPathHash,
301 const char *pszName,
302 const char *pszRelPath) const;
303
305 friend int SeekArkStream(int nStream, int nOffset, int nOrigin);
306 friend int ArkfileGetBaseSector(int nFile);
307 friend int ArkfileLogicalToPhysicalSector(int nFile, int nSector);
308
309 HxStr mPath;
310 int mFile;
311 char mSig[4];
312 int mVersion;
313 int mDirOffset;
314 int mNumFiles;
315 int mRelPathOffset;
316 int mNumPaths;
317 int mStringTabOffset;
318 int mNumStrings;
319 int mSizeHdrAndDir;
320 int mSectorSize;
321 int mOptimized;
322 int mOptimizedOffset;
323 int mOptimizedCount;
324 int mHeaderReserved40; // +0x040 zero in every shipped archive, and never read
325 int mHeaderReserved44; // +0x044 zero in every shipped archive, and never read
326 int mHeaderReserved48; // +0x048 zero in every shipped archive, and never read
327 char mHeaderPath[kArkHeaderSize - 0x40];
328 void *mTables;
329 ArkFileEntry *mFiles;
330 ArkRelPath *mRelPaths;
331 char *mStrings;
332 int mDiscLsn;
333 void *mOptimizedTable;
334 int mOptimizedCursor;
335 char mMountPoint[kArkMountPointSize];
336};
337
346int EraseArkStream(int nHandle);
347
360
374
384int OpenFileInArk(const char *pszPath);
385
396int GetArkFileLengthByPath(const char *pszPath);
397
414int ReadArkStreamThroughCache(int nHandle, void *pBuffer, unsigned nBytes);
415
428int IoctlFile(int nFile, int nRequest, void *pArg);
429
440void WaitForFileIdle(int nFile);
441
450int GetArkfileIdFromFileFd(int nHandle);
451
463int ArkfileGetBaseSector(int nFile);
464
488int ArkfileLogicalToPhysicalSector(int nFile, int nSector);
489
501
514
516constexpr int kSessionArkCount = 3;
517
525extern const char *const g_apSessionArkPaths[kSessionArkCount];
526
533extern std::vector<OpenArkObject *> g_apMountedArks;
534
541extern std::vector<ArkStream> gOpenArkFileTable;
542
549extern int gOpenFileIndex;
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
Mounted ark archive.
Definition openarkobject.h:136
friend int ArkfileLogicalToPhysicalSector(int nFile, int nSector)
Map a chunk of an archive to the chunk position the disc stores it at.
OpenArkObject()
Construct an unmounted archive.
void PrintHeader() const
Write every field of the copied archive header to standard output.
friend int ArkfileGetBaseSector(int nFile)
Report the disc sector a mounted archive starts at.
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.
int OpenStream(ArkFileEntry *pEntry)
Open a stream on one file of this archive.
friend int SeekArkStream(int nStream, int nOffset, int nOrigin)
Move an ark stream's read position.
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.
~OpenArkObject()
Release the tables the mount allocated.
void PrintAll() const
Write the header, the file table, the relative path table, and the strings, in that order.
static int Open(const char *pszPath)
Mount an ark archive by path.
constexpr int kArkRelPathBufferSize
Bytes every caller of OpenArkObject::FindFileEntryByPath() reserves for the relative path.
Definition openarkobject.h:38
short HashArkString(const char *pszName)
Hash a file name or a relative path for the table searches.
int ReadArkStreamThroughCache(int nHandle, void *pBuffer, unsigned nBytes)
Read from an ark stream through the sector cache.
int ArkfileLogicalToPhysicalSector(int nFile, int nSector)
Map a chunk of an archive to the chunk position the disc stores it at.
int CloseArk()
Unmount the archives InitArk() mounted.
constexpr int kArkMountPointSize
The number of bytes the mount point occupies, which is the rest of the record.
Definition openarkobject.h:14
constexpr char kArkRunComponent[]
Path component of the archive header that fixes the mount point.
Definition openarkobject.h:29
int ArkfileGetBaseSector(int nFile)
Report the disc sector a mounted archive starts at.
int IoctlFile(int nFile, int nRequest, void *pArg)
Forward a control request to sceIoctl().
constexpr char kArkDiscRoot[]
Directory the archives live in on the disc.
Definition openarkobject.h:23
constexpr int kArkNameBufferSize
Bytes every caller of OpenArkObject::FindFileEntryByPath() reserves for the file name.
Definition openarkobject.h:35
ArkFileEntry * FindOpenFileInArk(int nHandle)
Report the file entry a stream reads.
void WaitForFileIdle(int nFile)
Wait until no asynchronous operation is running on a file.
int OpenFileInArk(const char *pszPath)
Open a stream on a file inside a mounted archive.
constexpr int kArkSectorCacheRows
Rows the sector cache is asked for on the first mount.
Definition openarkobject.h:17
const char *const g_apSessionArkPaths[kSessionArkCount]
The archives InitArk() mounts for the session and CloseArk() unmounts: ark/root.ark,...
int GetArkfileIdFromFileFd(int nHandle)
Report the archive a stream reads from.
constexpr int kArkDevicePathSize
The number of bytes of the device path Open() builds on its stack.
Definition openarkobject.h:20
constexpr int kArkIndexAny
Archive index that asks OpenArkObject::FindFileEntryByPath() to search every mounted archive.
Definition openarkobject.h:45
std::vector< ArkStream > gOpenArkFileTable
Every stream open on a mounted archive.
constexpr char kArkHostRoot[]
Prefix that reads an archive over the host link instead.
Definition openarkobject.h:26
constexpr int kArkHeaderSize
The number of bytes of the archive header the mount copies into the record.
Definition openarkobject.h:8
constexpr int kArkVersion
The archive header version the mount accepts.
Definition openarkobject.h:11
ArkStream * LookupOpenFile(int nHandle)
Find the record of an open stream.
std::vector< OpenArkObject * > g_apMountedArks
Every archive mounted right now.
int InitArk()
Mount the archives the game needs for the whole session.
int EraseArkStream(int nHandle)
Erase a stream record by handle.
constexpr int kSessionArkCount
The number of archives in g_apSessionArkPaths.
Definition openarkobject.h:516
constexpr int kArkPathBufferSize
Bytes of the lowercased path copy OpenArkObject::FindFileEntryByPath() builds on its stack.
Definition openarkobject.h:32
int gOpenFileIndex
Handle OpenArkObject::OpenStream() gives the next stream, incremented after every open.
int GetArkFileLengthByPath(const char *pszPath)
Report the stored length of a file inside a mounted archive.
One entry of the archive's file table.
Definition openarkobject.h:56
int mSize
Definition openarkobject.h:64
unsigned short mNameHash
Definition openarkobject.h:57
unsigned short mSectorOffset
Definition openarkobject.h:61
short mRelPathIndex
Definition openarkobject.h:60
unsigned short mFlags
Definition openarkobject.h:58
int mLength
Definition openarkobject.h:63
int mNameOffset
Definition openarkobject.h:59
int mSector
Definition openarkobject.h:62
One entry of the archive's relative path table, which lists the directories the files are in.
Definition openarkobject.h:74
unsigned short mFlags
Definition openarkobject.h:76
int mPathOffset
Definition openarkobject.h:77
unsigned short mPathHash
Definition openarkobject.h:75
One open stream on a mounted archive.
Definition openarkobject.h:100
int mArkPosition
Definition openarkobject.h:110
int mPosition
Definition openarkobject.h:111
int mHandle
Definition openarkobject.h:113
OpenArkObject * FindArk() const
Find the mounted archive this stream reads from.
ArkFileEntry * mEntry
Definition openarkobject.h:114
int mFile
Definition openarkobject.h:112