2021-08-25 00:30:10 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* libragephoto RAGE Photo Parser
|
2023-01-07 20:43:11 +01:00
|
|
|
* Copyright (C) 2021-2023 Syping
|
2021-08-25 00:30:10 +02:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* This software is provided as-is, no warranties are given to you, we are not
|
|
|
|
* responsible for anything with use of the software, you are self responsible.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef RAGEPHOTO_H
|
|
|
|
#define RAGEPHOTO_H
|
|
|
|
|
2021-10-29 11:52:59 +02:00
|
|
|
#ifdef __cplusplus
|
2023-02-07 03:06:22 +01:00
|
|
|
#include "RagePhotoLibrary.h"
|
|
|
|
#include "RagePhotoTypedefs.h"
|
2021-08-25 00:30:10 +02:00
|
|
|
#include <iostream>
|
2021-11-18 17:33:20 +01:00
|
|
|
#include <cstdlib>
|
2021-08-25 00:30:10 +02:00
|
|
|
#include <cstdint>
|
|
|
|
#include <cstdio>
|
|
|
|
|
2021-11-04 13:21:18 +01:00
|
|
|
/**
|
|
|
|
* \brief GTA V and RDR 2 Photo Parser.
|
|
|
|
*/
|
2023-02-07 03:06:22 +01:00
|
|
|
class LIBRAGEPHOTO_CXX_BINDING RagePhoto
|
2021-08-25 00:30:10 +02:00
|
|
|
{
|
|
|
|
public:
|
2021-10-20 04:03:45 +02:00
|
|
|
/** Default sizes */
|
|
|
|
enum DefaultSize : uint32_t {
|
|
|
|
DEFAULT_GTA5_PHOTOBUFFER = 524288UL, /**< GTA V default Photo Buffer Size */
|
|
|
|
DEFAULT_RDR2_PHOTOBUFFER = 1048576UL, /**< RDR 2 default Photo Buffer Size */
|
|
|
|
DEFAULT_DESCBUFFER = 256UL, /**< Default Description Buffer Size */
|
|
|
|
DEFAULT_JSONBUFFER = 3072UL, /**< Default JSON Buffer Size */
|
|
|
|
DEFAULT_TITLBUFFER = 256UL, /**< Default Title Buffer Size */
|
|
|
|
GTA5_HEADERSIZE = 264UL, /**< GTA V Header Size */
|
|
|
|
RDR2_HEADERSIZE = 272UL, /**< RDR 2 Header Size */
|
|
|
|
};
|
2021-09-14 19:35:46 +02:00
|
|
|
/** Parsing and set errors */
|
2023-02-07 03:06:22 +01:00
|
|
|
enum Error : int32_t {
|
2023-01-08 13:35:32 +01:00
|
|
|
DescBufferTight = 39, /**< Description Buffer is too tight */
|
|
|
|
DescMallocError = 31, /**< Description Buffer can't be allocated */
|
|
|
|
DescReadError = 32, /**< Description can't be read successfully */
|
|
|
|
HeaderBufferTight = 35, /**< Header Buffer is too tight */
|
|
|
|
HeaderMallocError = 4, /**< Header Buffer can't be allocated */
|
2021-09-15 16:17:51 +02:00
|
|
|
IncompatibleFormat = 2, /**< Format is incompatible */
|
2023-01-08 13:35:32 +01:00
|
|
|
IncompleteChecksum = 7, /**< Header checksum is incomplete */
|
|
|
|
IncompleteDescBuffer = 30, /**< Description Buffer Size is incomplete */
|
|
|
|
IncompleteDescMarker = 28, /**< Description Marker is incomplete */
|
|
|
|
IncompleteDescOffset = 11, /**< Description Offset is incomplete */
|
|
|
|
IncompleteEOF = 8, /**< End Of File Offset is incomplete */
|
2021-09-15 16:17:51 +02:00
|
|
|
IncompleteHeader = 3, /**< Header is incomplete */
|
2023-01-08 13:35:32 +01:00
|
|
|
IncompleteJendMarker = 33, /**< JEND Marker is incomplete */
|
|
|
|
IncompleteJpegMarker = 12, /**< JPEG Marker is incomplete */
|
|
|
|
IncompleteJsonBuffer = 20, /**< JSON Buffer Size is incomplete */
|
|
|
|
IncompleteJsonMarker = 18, /**< JSON Marker incomplete */
|
|
|
|
IncompleteJsonOffset = 9, /**< JSON Offset incomplete */
|
|
|
|
IncompletePhotoBuffer = 14, /**< Photo Buffer Size is incomplete */
|
|
|
|
IncompletePhotoSize = 15, /**< Photo Size is incomplete */
|
|
|
|
IncompleteTitleBuffer = 25, /**< Title Buffer Size is incomplete */
|
|
|
|
IncompleteTitleMarker = 23, /**< Title Marker is incomplete */
|
|
|
|
IncompleteTitleOffset = 10, /**< Title Offset is incomplete */
|
|
|
|
IncorrectDescMarker = 29, /**< Description Marker is incorrect */
|
|
|
|
IncorrectJendMarker = 34, /**< JEND Marker is incorrect */
|
|
|
|
IncorrectJpegMarker = 13, /**< JPEG Marker is incorrect */
|
|
|
|
IncorrectJsonMarker = 19, /**< JSON Marker is incorrect */
|
|
|
|
IncorrectTitleMarker = 24, /**< Title Marker is incorrect */
|
|
|
|
JsonBufferTight = 37, /**< JSON Buffer is too tight */
|
|
|
|
JsonMallocError = 21, /**< JSON Buffer can't be allocated */
|
|
|
|
JsonReadError = 22, /**< JSON can't be read successfully */
|
2021-09-15 16:17:51 +02:00
|
|
|
NoError = 255, /**< Finished without errors */
|
|
|
|
NoFormatIdentifier = 1, /**< No format detected, empty file */
|
2023-01-08 13:35:32 +01:00
|
|
|
PhotoBufferTight = 36, /**< Photo Buffer is too tight */
|
|
|
|
PhotoMallocError = 16, /**< Photo Buffer can't be allocated */
|
|
|
|
PhotoReadError = 17, /**< Photo can't be read */
|
|
|
|
TitleBufferTight = 38, /**< Title Buffer is too tight */
|
|
|
|
TitleMallocError = 26, /**< Title Buffer can't be allocated */
|
|
|
|
TitleReadError = 27, /**< Title can't be read */
|
|
|
|
UnicodeInitError = 5, /**< Failed to initialise Unicode decoder */
|
|
|
|
UnicodeHeaderError = 6, /**< Header can't be encoded/decoded successfully */
|
2021-11-02 10:16:56 +01:00
|
|
|
Uninitialised = 0, /**< Uninitialised, file access failed */
|
2021-08-26 00:22:11 +02:00
|
|
|
};
|
2021-09-14 19:35:46 +02:00
|
|
|
/** Photo Formats */
|
2021-10-28 03:28:36 +02:00
|
|
|
enum PhotoFormat : uint32_t {
|
|
|
|
GTA5 = 0x01000000UL, /**< GTA V Photo Format */
|
|
|
|
RDR2 = 0x04000000UL, /**< RDR 2 Photo Format */
|
2021-08-25 00:30:10 +02:00
|
|
|
};
|
|
|
|
RagePhoto();
|
|
|
|
~RagePhoto();
|
2023-02-20 11:27:14 +01:00
|
|
|
void addParser(RagePhotoFormatParser *rp_parser); /**< Add a custom defined RagePhotoFormatParser. */
|
2023-02-20 11:56:23 +01:00
|
|
|
static void clear(RagePhotoData *rp_data); /**< Resets the RagePhotoData object to default values. */
|
|
|
|
void clear(); /**< Resets the RagePhotoData object to default values. */
|
2021-12-14 03:15:52 +01:00
|
|
|
RagePhotoData* data(); /**< Returns the internal RagePhotoData object. */
|
2023-02-23 09:17:53 +01:00
|
|
|
static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Loads a Photo from a const char*. */
|
2021-09-16 05:02:08 +02:00
|
|
|
/** Loads a Photo from a const char*.
|
|
|
|
* \param data Photo data
|
|
|
|
* \param size Photo data size
|
|
|
|
*/
|
|
|
|
bool load(const char *data, size_t size);
|
|
|
|
/** Loads a Photo from a std::string.
|
|
|
|
* \param data Photo data
|
|
|
|
*/
|
|
|
|
bool load(const std::string &data);
|
2021-11-02 10:16:56 +01:00
|
|
|
/** Loads a Photo from a file.
|
|
|
|
* \param filename File to load
|
|
|
|
*/
|
|
|
|
bool loadFile(const std::string &filename);
|
2023-02-07 03:06:22 +01:00
|
|
|
int32_t error() const; /**< Returns the last error occurred. */
|
2021-10-30 17:40:58 +02:00
|
|
|
uint32_t format() const; /**< Returns the Photo Format (GTA V or RDR 2). */
|
2023-02-23 09:17:53 +01:00
|
|
|
const std::string jpeg() const; /**< Returns the Photo JPEG data. */
|
2023-02-24 23:51:32 +01:00
|
|
|
const char* jpegData() const; /**< Returns the Photo JPEG data. */
|
2023-02-23 09:17:53 +01:00
|
|
|
uint32_t jpegSize() const; /**< Returns the Photo JPEG data size. */
|
2023-01-07 20:43:11 +01:00
|
|
|
const char* description() const; /**< Returns the Photo description. */
|
|
|
|
const char* json() const; /**< Returns the Photo JSON data. */
|
|
|
|
const char* header() const; /**< Returns the Photo header. */
|
|
|
|
const char* title() const; /**< Returns the Photo title. */
|
2021-11-03 10:54:35 +01:00
|
|
|
static const char* version(); /**< Returns the library version. */
|
2023-02-23 09:17:53 +01:00
|
|
|
static bool save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Saves a Photo to a char*. */
|
|
|
|
static bool save(char *data, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Saves a Photo to a char*. */
|
2021-09-17 07:22:49 +02:00
|
|
|
/** Saves a Photo to a char*.
|
|
|
|
* \param data Photo data
|
|
|
|
* \param photoFormat Photo Format (GTA V or RDR 2)
|
|
|
|
*/
|
2021-10-28 03:28:36 +02:00
|
|
|
bool save(char *data, uint32_t photoFormat);
|
2021-09-17 07:22:49 +02:00
|
|
|
/** Saves a Photo to a char*.
|
|
|
|
* \param data Photo data
|
|
|
|
*/
|
|
|
|
bool save(char *data);
|
|
|
|
/** Saves a Photo to a std::string.
|
|
|
|
* \param photoFormat Photo Format (GTA V or RDR 2)
|
|
|
|
* \param ok \p true when saved successfully
|
|
|
|
*/
|
2021-10-28 03:28:36 +02:00
|
|
|
const std::string save(uint32_t photoFormat, bool *ok = nullptr);
|
2021-09-17 07:22:49 +02:00
|
|
|
/** Saves a Photo to a std::string.
|
|
|
|
* \param ok \p true when saved successfully
|
|
|
|
*/
|
|
|
|
const std::string save(bool *ok = nullptr);
|
2021-11-02 10:16:56 +01:00
|
|
|
bool saveFile(const std::string &filename, uint32_t photoFormat); /**< Saves a Photo to a file. */
|
|
|
|
bool saveFile(const std::string &filename); /**< Saves a Photo to a file. */
|
2023-02-23 09:17:53 +01:00
|
|
|
static size_t saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Returns the Photo save file size. */
|
2023-02-20 11:27:14 +01:00
|
|
|
static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Returns the Photo save file size. */
|
2021-11-02 09:26:56 +01:00
|
|
|
size_t saveSize(uint32_t photoFormat); /**< Returns the Photo save file size. */
|
|
|
|
size_t saveSize(); /**< Returns the Photo save file size. */
|
2023-02-20 11:27:14 +01:00
|
|
|
static void setBufferDefault(RagePhotoData *rp_data); /**< Sets all cross-format Buffer to default size. */
|
2023-02-20 13:37:40 +01:00
|
|
|
void setBufferDefault(); /**< Sets all cross-format Buffer to default size. */
|
2023-02-20 11:27:14 +01:00
|
|
|
static void setBufferOffsets(RagePhotoData *rp_data); /**< Moves all Buffer offsets to correct position. */
|
2023-02-20 13:37:40 +01:00
|
|
|
void setBufferOffsets(); /**< Moves all Buffer offsets to correct position. */
|
2023-02-23 09:17:53 +01:00
|
|
|
bool setData(RagePhotoData *rp_data, bool takeCopy = true); /**< Sets the internal RagePhotoData object. */
|
2023-01-07 20:43:11 +01:00
|
|
|
void setDescription(const char *description, uint32_t bufferSize = 0); /**< Sets the Photo description. */
|
2021-10-28 03:28:36 +02:00
|
|
|
void setFormat(uint32_t photoFormat); /**< Sets the Photo Format (GTA V or RDR 2). */
|
2021-09-14 19:35:46 +02:00
|
|
|
/** Sets the Photo JPEG data.
|
2021-09-16 03:07:11 +02:00
|
|
|
* \param data JPEG data
|
|
|
|
* \param size JPEG data size
|
|
|
|
* \param bufferSize JPEG buffer size
|
2021-09-14 19:35:46 +02:00
|
|
|
*/
|
2023-02-23 09:17:53 +01:00
|
|
|
bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize = 0);
|
2021-09-14 19:35:46 +02:00
|
|
|
/** Sets the Photo JPEG data.
|
2021-09-16 03:07:11 +02:00
|
|
|
* \param data JPEG data
|
|
|
|
* \param bufferSize JPEG buffer size
|
2021-09-14 19:35:46 +02:00
|
|
|
*/
|
2023-02-23 09:17:53 +01:00
|
|
|
bool setJpeg(const std::string &data, uint32_t bufferSize = 0);
|
|
|
|
void setJson(const char *json, uint32_t bufferSize = 0); /**< Sets the Photo JSON data. */
|
|
|
|
void setHeader(const char *header, uint32_t headerSum); /**< Sets the Photo header. (EXPERT ONLY) */
|
2023-01-07 20:43:11 +01:00
|
|
|
void setTitle(const char *title, uint32_t bufferSize = 0); /**< Sets the Photo title. */
|
2021-08-25 00:30:10 +02:00
|
|
|
|
2021-11-18 18:00:09 +01:00
|
|
|
private:
|
2023-01-08 15:21:16 +01:00
|
|
|
RagePhotoData *m_data;
|
2023-02-20 11:27:14 +01:00
|
|
|
RagePhotoFormatParser *m_parser;
|
2021-08-25 00:30:10 +02:00
|
|
|
};
|
2021-11-02 09:26:56 +01:00
|
|
|
#else
|
2021-11-13 04:41:01 +01:00
|
|
|
#include "RagePhotoC.h"
|
|
|
|
#endif // __cplusplus
|
2021-08-25 00:30:10 +02:00
|
|
|
|
|
|
|
#endif // RAGEPHOTO_H
|