libragephoto Version: 0.5.0
Loading...
Searching...
No Matches
RagePhoto.hpp
1/*****************************************************************************
2* libragephoto RAGE Photo Parser
3* Copyright (C) 2021-2023 Syping
4*
5* Redistribution and use in source and binary forms, with or without modification,
6* are permitted provided that the following conditions are met:
7*
8* 1. Redistributions of source code must retain the above copyright notice,
9* this list of conditions and the following disclaimer.
10*
11* 2. Redistributions in binary form must reproduce the above copyright notice,
12* this list of conditions and the following disclaimer in the documentation
13* and/or other materials provided with the distribution.
14*
15* This software is provided as-is, no warranties are given to you, we are not
16* responsible for anything with use of the software, you are self responsible.
17*****************************************************************************/
18
19#ifndef RAGEPHOTO_HPP
20#define RAGEPHOTO_HPP
21
22#ifdef __cplusplus
23#include "RagePhotoLibrary.h"
24#include "RagePhotoTypedefs.h"
25#include <iostream>
26#include <cstdlib>
27#include <cstdint>
28#include <cstdio>
29
33class LIBRAGEPHOTO_CXX_PUBLIC RagePhoto
34{
35public:
37 enum DefaultSize : uint32_t {
38 DEFAULT_GTA5_PHOTOBUFFER = 524288UL,
39 DEFAULT_RDR2_PHOTOBUFFER = 1048576UL,
40 DEFAULT_DESCBUFFER = 256UL,
41 DEFAULT_JSONBUFFER = 3072UL,
42 DEFAULT_TITLBUFFER = 256UL,
43 GTA5_HEADERSIZE = 264UL,
44 RDR2_HEADERSIZE = 272UL,
45 };
47 enum Error : int32_t {
48 DescBufferTight = 39L,
49 DescMallocError = 31L,
50 DescReadError = 32L,
51 HeaderBufferTight = 35L,
52 HeaderMallocError = 4L,
53 IncompatibleFormat = 2L,
54 IncompleteChecksum = 7L,
55 IncompleteDescBuffer = 30L,
56 IncompleteDescMarker = 28L,
57 IncompleteDescOffset = 11L,
58 IncompleteEOF = 8L,
59 IncompleteHeader = 3L,
60 IncompleteJendMarker = 33L,
61 IncompleteJpegMarker = 12L,
62 IncompleteJsonBuffer = 20L,
63 IncompleteJsonMarker = 18L,
64 IncompleteJsonOffset = 9L,
65 IncompletePhotoBuffer = 14L,
66 IncompletePhotoSize = 15L,
67 IncompleteTitleBuffer = 25L,
68 IncompleteTitleMarker = 23L,
69 IncompleteTitleOffset = 10L,
70 IncorrectDescMarker = 29L,
71 IncorrectJendMarker = 34L,
72 IncorrectJpegMarker = 13L,
73 IncorrectJsonMarker = 19L,
74 IncorrectTitleMarker = 24L,
75 JsonBufferTight = 37L,
76 JsonMallocError = 21L,
77 JsonReadError = 22L,
78 NoError = 255L,
79 NoFormatIdentifier = 1L,
80 PhotoBufferTight = 36L,
81 PhotoMallocError = 16L,
82 PhotoReadError = 17L,
83 TitleBufferTight = 38L,
84 TitleMallocError = 26L,
85 TitleReadError = 27L,
86 UnicodeInitError = 5L,
87 UnicodeHeaderError = 6L,
88 Uninitialised = 0L,
89 };
91 enum PhotoFormat : uint32_t {
92 GTA5 = 0x01000000UL,
93 RDR2 = 0x04000000UL,
94 };
96 enum SignInitials : uint32_t {
97 SIGTA5 = 0xE47AB81CUL,
98 SIRDR2 = 0x00FEEB1EUL,
99 };
100 RagePhoto();
101 ~RagePhoto();
102 void addParser(RagePhotoFormatParser *rp_parser);
103 static void clear(RagePhotoData *rp_data);
104 void clear();
105 RagePhotoData* data();
106 static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
111 bool load(const char *data, size_t size);
115 bool load(const std::string &data);
119 bool loadFile(const std::string &filename);
120 int32_t error() const;
121 uint32_t format() const;
122 const std::string jpeg() const;
123#if (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L)
124 const std::string_view jpeg_view() const;
125#endif
126 const char* jpegData() const;
127 static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data);
128 static uint64_t jpegSign(RagePhotoData *rp_data);
129 uint64_t jpegSign(uint32_t photoFormat) const;
130 uint64_t jpegSign() const;
131 uint32_t jpegSize() const;
132 const char* description() const;
133 const char* json() const;
134 const char* header() const;
135 const char* title() const;
136 static const char* version();
137 static bool save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
138 static bool save(char *data, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
143 bool save(char *data, uint32_t photoFormat);
147 bool save(char *data);
152 const std::string save(uint32_t photoFormat, bool *ok = nullptr);
156 const std::string save(bool *ok = nullptr);
157 bool saveFile(const std::string &filename, uint32_t photoFormat);
158 bool saveFile(const std::string &filename);
159 static size_t saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
160 static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
161 size_t saveSize(uint32_t photoFormat);
162 size_t saveSize();
163 static void setBufferDefault(RagePhotoData *rp_data);
164 void setBufferDefault();
165 static void setBufferOffsets(RagePhotoData *rp_data);
166 void setBufferOffsets();
167 bool setData(RagePhotoData *rp_data, bool takeCopy = true);
168 void setDescription(const char *description, uint32_t bufferSize = 0);
169 void setFormat(uint32_t photoFormat);
175 bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize = 0);
180 bool setJpeg(const std::string &data, uint32_t bufferSize = 0);
181 void setJson(const char *json, uint32_t bufferSize = 0);
182 void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0);
183 void setTitle(const char *title, uint32_t bufferSize = 0);
185private:
186 RagePhotoData *m_data;
187 RagePhotoFormatParser *m_parser;
188};
189#endif // __cplusplus
190
191#endif // RAGEPHOTO_HPP
GTA V and RDR 2 Photo Parser.
Definition RagePhoto.hpp:34
DefaultSize
Definition RagePhoto.hpp:37
SignInitials
Definition RagePhoto.hpp:96
PhotoFormat
Definition RagePhoto.hpp:91
Error
Definition RagePhoto.hpp:47
Definition RagePhotoTypedefs.h:31
Definition RagePhotoTypedefs.h:65