libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Ship::OtrArchive Class Referencefinal

Archive implementation backed by an MPQ file (Blizzard's MoPaQ format). More...

#include <OtrArchive.h>

Inheritance diagram for Ship::OtrArchive:
[legend]
Collaboration diagram for Ship::OtrArchive:
[legend]

Public Member Functions

 OtrArchive (const std::string &archivePath, std::shared_ptr< ResourceManager > resourceManager=nullptr, std::shared_ptr< Keystore > keystore=nullptr)
 Constructs an OtrArchive for the given MPQ file path.
 
 ~OtrArchive ()
 
bool Open ()
 Opens the underlying MPQ file via StormLib.
 
bool Close ()
 Closes the MPQ file handle and releases StormLib resources.
 
bool WriteFile (const std::string &filename, const std::vector< uint8_t > &data)
 Writes raw data to a file entry inside the MPQ archive.
 
std::shared_ptr< FileLoadFile (const std::string &filePath)
 Loads a file from the archive by its virtual path.
 
std::shared_ptr< FileLoadFile (uint64_t hash)
 Loads a file from the archive by its 64-bit hash.
 
- Public Member Functions inherited from Ship::Archive
 Archive (const std::string &path, std::shared_ptr< ResourceManager > resourceManager=nullptr, std::shared_ptr< Keystore > keystore=nullptr)
 Constructs an Archive for the given filesystem path.
 
 ~Archive ()
 
bool operator== (const Archive &rhs) const
 Two archives are equal when they refer to the same underlying path.
 
void Load ()
 Opens and indexes the archive, making its contents available for loading.
 
void Unload ()
 Closes the archive and releases all associated resources.
 
std::shared_ptr< std::unordered_map< uint64_t, std::string > > ListFiles ()
 Returns a map of all files indexed in this archive (hash → path).
 
std::shared_ptr< std::unordered_map< uint64_t, std::string > > ListFiles (const std::string &filter)
 Returns only the files whose paths match the given filter string.
 
bool HasFile (const std::string &filePath)
 Checks whether the archive contains a file at the given path.
 
bool HasFile (uint64_t hash)
 Checks whether the archive contains a file with the given hash.
 
bool HasGameVersion ()
 Returns true if a game version value was found in the manifest.
 
uint32_t GetGameVersion ()
 Returns the game version encoded in the archive manifest.
 
const ArchiveManifestGetManifest ()
 Returns the parsed archive manifest.
 
bool IsSigned ()
 Returns true if the archive carries a digital signature in its manifest.
 
bool IsChecksumValid ()
 Returns true if the archive's checksum field matches the computed checksum.
 
const std::string & GetPath ()
 Returns the filesystem path this archive was opened from.
 
bool IsInitialized ()
 Returns true if the archive has been successfully initialized/opened.
 

Additional Inherited Members

- Protected Member Functions inherited from Ship::Archive
void SetInitialized (bool isInitialized)
 Sets the initialized state flag. Called by Load() / Unload().
 
void SetGameVersion (uint32_t gameVersion)
 Stores the game version parsed from the manifest.
 
void IndexFile (const std::string &filePath)
 Adds a file to the internal hash→path index.
 
void Validate ()
 Validates the manifest checksum and signature, setting mIsSigned / mIsChecksumValid.
 
- Protected Attributes inherited from Ship::Archive
std::shared_ptr< ResourceManagermResourceManager
 
std::shared_ptr< KeystoremKeystore
 

Detailed Description

Archive implementation backed by an MPQ file (Blizzard's MoPaQ format).

OtrArchive wraps StormLib to expose a Ship::Archive over an ".otr" file, which is structurally an MPQ archive. This class is only compiled when the project is built with MPQ support enabled (-DINCLUDE_MPQ_SUPPORT).

All file I/O operations are thread-safe via the StormLib handle.

Deprecated:
OtrArchive and the ".otr" format are deprecated in favour of the ".o2r" format backed by Ship::O2rArchive. MPQ support is disabled by default; opt in with -DINCLUDE_MPQ_SUPPORT=ON only for projects that still need to load legacy ".otr" archives. New projects should use the ".o2r" format exclusively.

Constructor & Destructor Documentation

◆ OtrArchive()

Ship::OtrArchive::OtrArchive ( const std::string &  archivePath,
std::shared_ptr< ResourceManager resourceManager = nullptr,
std::shared_ptr< Keystore keystore = nullptr 
)

Constructs an OtrArchive for the given MPQ file path.

Parameters
archivePathAbsolute or relative filesystem path to the ".otr" file.

◆ ~OtrArchive()

Ship::OtrArchive::~OtrArchive ( )

Member Function Documentation

◆ Close()

bool Ship::OtrArchive::Close ( )
virtual

Closes the MPQ file handle and releases StormLib resources.

Returns
true on success.

Implements Ship::Archive.

◆ LoadFile() [1/2]

std::shared_ptr< File > Ship::OtrArchive::LoadFile ( const std::string &  filePath)
virtual

Loads a file from the archive by its virtual path.

Parameters
filePathVirtual path of the file within the MPQ.
Returns
Loaded File with a populated buffer, or nullptr if not found.

Implements Ship::Archive.

◆ LoadFile() [2/2]

std::shared_ptr< File > Ship::OtrArchive::LoadFile ( uint64_t  hash)
virtual

Loads a file from the archive by its 64-bit hash.

Parameters
hashCRC/hash of the file path.
Returns
Loaded File with a populated buffer, or nullptr if not found.

Implements Ship::Archive.

◆ Open()

bool Ship::OtrArchive::Open ( )
virtual

Opens the underlying MPQ file via StormLib.

Returns
true if the file was opened successfully.

Implements Ship::Archive.

◆ WriteFile()

bool Ship::OtrArchive::WriteFile ( const std::string &  filename,
const std::vector< uint8_t > &  data 
)
virtual

Writes raw data to a file entry inside the MPQ archive.

Parameters
filenameTarget path within the archive.
dataRaw bytes to write.
Returns
true on success.

Implements Ship::Archive.


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