2017-10-30 23:44:40 +01:00
|
|
|
#ifndef _LIBRW_LOADERIMG_HPP_
|
|
|
|
#define _LIBRW_LOADERIMG_HPP_
|
2013-07-02 08:06:03 +02:00
|
|
|
|
2017-10-30 23:44:40 +01:00
|
|
|
#include <cstddef>
|
2016-09-09 22:13:21 +02:00
|
|
|
#include <cstdint>
|
2017-10-30 23:44:40 +01:00
|
|
|
#include <string>
|
2013-07-02 08:06:03 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2017-11-02 05:01:00 +01:00
|
|
|
#include <rw/filesystem.hpp>
|
|
|
|
|
2013-07-02 08:06:03 +02:00
|
|
|
/// \brief Points to one file within the archive
|
2016-09-09 22:13:21 +02:00
|
|
|
class LoaderIMGFile {
|
2013-07-02 08:06:03 +02:00
|
|
|
public:
|
2016-09-09 22:13:21 +02:00
|
|
|
uint32_t offset;
|
|
|
|
uint32_t size;
|
|
|
|
char name[24];
|
2013-07-02 08:06:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-09-09 22:13:21 +02:00
|
|
|
\class LoaderIMG
|
|
|
|
\brief Parses the structure of GTA .IMG archives and loads the files in it
|
2013-07-02 08:06:03 +02:00
|
|
|
*/
|
2016-09-09 22:13:21 +02:00
|
|
|
class LoaderIMG {
|
2013-07-02 08:06:03 +02:00
|
|
|
public:
|
2016-09-09 22:13:21 +02:00
|
|
|
/// Multiple versions of .IMG files
|
2017-10-30 23:44:40 +01:00
|
|
|
enum Version {
|
2016-09-09 22:13:21 +02:00
|
|
|
GTAIIIVC, ///< GTA III and GTA VC archives -- only this one is
|
|
|
|
///implemented
|
|
|
|
GTASA,
|
|
|
|
GTAIV
|
|
|
|
};
|
2013-07-02 08:06:03 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
/// Construct
|
|
|
|
LoaderIMG();
|
2013-07-02 08:06:03 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
/// Load the structure of the archive
|
|
|
|
/// Omit the extension in filename so both .dir and .img are loaded when
|
|
|
|
/// appropriate
|
2017-11-02 05:01:00 +01:00
|
|
|
bool load(const rwfs::path& filename);
|
2013-07-02 08:06:03 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
/// Load a file from the archive to memory and pass a pointer to it
|
|
|
|
/// Warning: Please delete[] the memory in the end.
|
|
|
|
/// Warning: Returns NULL (0) if by any reason it can't load the file
|
|
|
|
char* loadToMemory(const std::string& assetname);
|
2013-07-02 08:06:03 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
/// Writes the contents of assetname to filename
|
|
|
|
bool saveAsset(const std::string& assetname, const std::string& filename);
|
2013-07-02 08:06:03 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
/// Get the information of an asset in the examining archive
|
|
|
|
bool findAssetInfo(const std::string& assetname, LoaderIMGFile& out);
|
2013-07-02 08:06:03 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
/// Get the information of an asset by its index
|
|
|
|
const LoaderIMGFile& getAssetInfoByIndex(size_t index) const;
|
2013-07-02 08:06:03 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
/// Returns the number of asset files in the archive
|
|
|
|
uint32_t getAssetCount() const;
|
2013-07-02 08:06:03 +02:00
|
|
|
|
2017-10-30 23:44:40 +01:00
|
|
|
Version getVersion() const {
|
|
|
|
return m_version;
|
|
|
|
}
|
|
|
|
|
2013-07-02 08:06:03 +02:00
|
|
|
private:
|
2017-10-30 23:44:40 +01:00
|
|
|
Version m_version; ///< Version of this IMG archive
|
2016-09-09 22:13:21 +02:00
|
|
|
uint32_t m_assetCount; ///< Number of assets in the current archive
|
2017-11-02 05:01:00 +01:00
|
|
|
rwfs::path m_archive; ///< Path to the archive being used (no extension)
|
2013-07-02 08:06:03 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
std::vector<LoaderIMGFile> m_assets; ///< Asset info of the archive
|
2013-07-02 08:06:03 +02:00
|
|
|
};
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
#endif // LoaderIMG_h__
|