Compare commits

...

16 commits

Author SHA1 Message Date
Syping c74b4a415f libragephoto 0.5.1 release
- ragephoto_open: fix memory leak when instance can't be allocated
- ragephoto_loadfile: fix file handle leak when data heap can't be
allocated
- ragephotodata_load: fix printf print types
- RagePhoto.cpp: remove std namespace from C functions
2023-10-25 16:33:01 +02:00
Syping 6fdc075741 libragephoto 0.5.0 release
- CMakeLists.txt: add missing RagePhotoA for C API builds
- updated README.md
2023-06-11 23:07:41 +02:00
Syping 12507be85d libragephoto: add RagePhotoB for best implementation
CMakeLists.txt: add RagePhotoB class, improve settings clarification
doc/build.doc: add RAGEPHOTO_C_LIBRARY flag
doc/index.doc: correct RagePhoto.h header
doc/usage.doc: fix minor documentation issue, clarify class differences
ragephoto-gtkviewer: use RagePhotoB class
ragephoto-qtviewer: use RagePhotoB class
RagePhoto-Extract.cpp: use RagePhotoB class
RagePhoto.cpp: LIBRAGEPHOTO_C_API -> LIBRAGEPHOTO_CXX_C
RagePhotoA.hpp: simplify brief
RagePhotoB.hpp: add best implementation detection
RagePhotoLibrary.h: fix WASM C API inclusion by default
README.md: add RAGEPHOTO_C_LIBRARY flag
2023-06-11 05:41:32 +02:00
Syping d7943e552d GitHub Actions: fix WebAssembly C build 2023-06-09 05:05:42 +02:00
Syping b838c505a4 libragephoto: C++ headers have now .hpp extension
RagePhoto.h -> RagePhoto.hpp
RagePhotoA.h -> RagePhotoA.hpp
RagePhotoC.h -> RagePhoto.h

unicode.cmake: exclude codecvt for C builds
GitHub Actions: separate C and CXX builds
2023-06-07 06:57:23 +02:00
Syping 6acf7b7338 RagePhoto.c: fix potential memory issue 2023-06-07 06:12:24 +02:00
Syping 24e0d9c03e RagePhoto.c: fix potential memory issue 2023-06-07 06:09:37 +02:00
Syping 6066d92ee9 RagePhoto.c: fix potential memory issue, fix debug code 2023-06-06 21:05:55 +02:00
Syping c3e838cecf RagePhoto.c: fix iconv code 2023-06-06 20:27:51 +02:00
Syping 8a29d8aebe GitHub Actions: use C library for WebAssembly build
RagePhoto.c: fix header includes
2023-06-06 20:22:20 +02:00
Syping 3046cbd077 libragephoto: introduce C library port
CMakeLists.txt: fixes for MSVC and C library support
RagePhoto: non C++11 support
RagePhotoC: clarify C instance support in comment
RagePhotoTypedefs: add typedefs for C library
2023-06-06 19:39:22 +02:00
Syping af3580dff4 libragephoto 0.4.1 release
RagePhotoA: fix setData() pointer passthrough
2023-05-25 23:30:26 +02:00
Syping 4aedd8b869 libragephoto 0.4.0 release
- CMakeLists.txt: bump version to 0.4.0
- RagePhoto(A): add headerSum2 for RDR 2
- RagePhotoC: add ragephoto_setphotoheader2() for RDR 2
- RagePhotoTypedefs: remove unnamedSum1, rename unnamedSum2 ->
headerSum2
- RagePhotoTypedefs: remove ragephoto_bool_t for bool
2023-05-14 11:44:59 +02:00
Syping 3d9d632d7b libragephoto: add RDR 2 SignInitial 2023-05-09 23:28:38 +02:00
Syping f1485be7a7 libragephoto: add defines for C API
RagePhotoTypedefs.h: add defines for C API
RagePhoto-Extract.c: take advantage of C API defines
2023-04-26 01:09:22 +02:00
Syping d8c0d7d470 libragephoto: rename BINDING to PUBLIC, some other changes
- doc/Doxyfile.in: rename BINDING to PUBLIC
- doc/usage.doc: fix a usage example
- CMakeLists.txt: include CPack only when libragephoto is Top Level
- RagePhoto.h: rename BINDING TO PUBLIC
- RagePhotoC.h: rename BINDING TO PUBLIC
- RagePhotoLibrary.h: rename BINDING to PUBLIC, add new checks
2023-04-09 21:22:13 +02:00
30 changed files with 2236 additions and 762 deletions

29
.github/workflows/ubuntu-c.yml vendored Normal file
View file

@ -0,0 +1,29 @@
name: Ubuntu C
on: push
jobs:
Release:
runs-on: ubuntu-latest
env:
BUILD_TYPE: Release
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Install packages
run: |
sudo apt-get update -qq
sudo apt-get install cmake gcc g++ ninja-build -qq
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRAGEPHOTO_C_LIBRARY=ON -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Install
run: cmake --install ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --prefix ${{github.workspace}}/install/usr/local
- name: Upload
uses: actions/upload-artifact@v2
with:
name: Ubuntu
path: |
${{github.workspace}}/install/

View file

@ -1,4 +1,4 @@
name: Ubuntu
name: Ubuntu CXX
on: push

30
.github/workflows/webassembly-c.yml vendored Normal file
View file

@ -0,0 +1,30 @@
name: WebAssembly C
on: push
jobs:
Release:
runs-on: ubuntu-latest
env:
BUILD_TYPE: Release
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v11
- name: Install packages
run: |
sudo apt-get update -qq
sudo apt-get install cmake ninja-build -qq
- name: Configure CMake
run: emcmake cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRAGEPHOTO_C_LIBRARY=ON -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Upload
uses: actions/upload-artifact@v2
with:
name: WebAssembly
path: |
${{github.workspace}}/build/libragephoto.js
${{github.workspace}}/build/libragephoto.wasm

View file

@ -1,4 +1,4 @@
name: WebAssembly
name: WebAssembly CXX
on: push

34
.github/workflows/windows-c.yml vendored Normal file
View file

@ -0,0 +1,34 @@
name: Windows C
on: push
jobs:
Release:
runs-on: windows-latest
env:
BUILD_TYPE: Release
strategy:
matrix:
arch:
- amd64
- amd64_x86
- amd64_arm64
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{matrix.arch}}
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRAGEPHOTO_C_LIBRARY=ON -DRAGEPHOTO_UNICODE=wincvt -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Install
run: cmake --install ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --prefix ${{github.workspace}}/install
- name: Upload
uses: actions/upload-artifact@v2
with:
name: Windows MSVC ${{matrix.arch}}
path: |
${{github.workspace}}/install/

View file

@ -1,4 +1,4 @@
name: Windows
name: Windows CXX
on: push

View file

@ -17,7 +17,7 @@
****************************************************************************]]
cmake_minimum_required(VERSION 3.8)
project(ragephoto VERSION 0.3.0 LANGUAGES CXX)
project(ragephoto VERSION 0.5.1 LANGUAGES C CXX)
include(GNUInstallDirs)
# RagePhoto CMake includes
@ -32,14 +32,33 @@ else()
endif()
# RagePhoto Source files
set(RAGEPHOTO_HEADERS
src/RagePhoto.h
src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.cpp
)
option(RAGEPHOTO_C_LIBRARY "Build libragephoto as C library" OFF)
if (RAGEPHOTO_C_LIBRARY)
set(RAGEPHOTO_HEADERS
src/RagePhoto.h
src/RagePhotoA
src/RagePhotoA.hpp
src/RagePhotoB
src/RagePhotoB.hpp
src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.c
)
else()
set(RAGEPHOTO_HEADERS
src/RagePhoto
src/RagePhoto.hpp
src/RagePhotoB
src/RagePhotoB.hpp
src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.cpp
)
endif()
# RagePhoto Library Type
option(RAGEPHOTO_STATIC "Build libragephoto as static library" OFF)
@ -52,7 +71,7 @@ else()
endif()
# RagePhoto Benchmark
option(RAGEPHOTO_BENCHMARK "Build with libragephoto benchmark" OFF)
option(RAGEPHOTO_BENCHMARK "Build with libragephoto benchmark (C++ only)" OFF)
if (RAGEPHOTO_BENCHMARK)
list(APPEND LIBRAGEPHOTO_DEFINES
RAGEPHOTO_BENCHMARK
@ -60,14 +79,19 @@ if (RAGEPHOTO_BENCHMARK)
endif()
# RagePhoto C API
if (RAGEPHOTO_C_API)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_API)
list(APPEND RAGEPHOTO_HEADERS
src/RagePhotoA.h
src/RagePhotoC.h
)
if (RAGEPHOTO_C_LIBRARY)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_ONLY)
else()
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_NOAPI)
if (RAGEPHOTO_C_API)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_CXX_C)
list(APPEND RAGEPHOTO_HEADERS
src/RagePhoto.h
src/RagePhotoA
src/RagePhotoA.hpp
)
else()
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_CXX_ONLY)
endif()
endif()
# RagePhoto Win32 Shared Resources
@ -99,7 +123,7 @@ target_compile_definitions(ragephoto PRIVATE
LIBRAGEPHOTO_LIBRARY
${LIBRAGEPHOTO_DEFINES}
)
if (MSVC)
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914 AND NOT RAGEPHOTO_C_LIBRARY)
target_compile_options(ragephoto PRIVATE "/Zc:__cplusplus")
endif()
target_include_directories(ragephoto PUBLIC
@ -143,7 +167,6 @@ option(RAGEPHOTO_EXTRACT "Build libragephoto with ragephoto-extract" ${RPTL_ON})
if (RAGEPHOTO_EXTRACT)
# RagePhoto-Extract Source files
if (RAGEPHOTO_C_API)
enable_language(C)
set(EXTRACT_SOURCES src/RagePhoto-Extract.c)
else()
set(EXTRACT_SOURCES src/RagePhoto-Extract.cpp)
@ -161,7 +184,7 @@ if (RAGEPHOTO_EXTRACT)
set_target_properties(ragephoto-extract PROPERTIES
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
)
if (MSVC AND NOT RAGEPHOTO_C_API)
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914 AND NOT RAGEPHOTO_C_API)
target_compile_options(ragephoto-extract PRIVATE "/Zc:__cplusplus")
endif()
target_link_libraries(ragephoto-extract PRIVATE ragephoto)
@ -169,12 +192,14 @@ if (RAGEPHOTO_EXTRACT)
endif()
# CPack Package Generation
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_DESCRIPTION "Open Source RAGE Photo Parser for GTA V and RDR 2")
set(CPACK_PACKAGE_NAME "libragephoto")
set(CPACK_PACKAGE_VENDOR "Syping")
set(CPACK_PACKAGE_VERSION_MAJOR "${ragephoto_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${ragephoto_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${ragephoto_VERSION_PATCH}")
set(CPACK_STRIP_FILES ON)
include(CPack)
if (RPTL_ON)
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_DESCRIPTION "Open Source RAGE Photo Parser for GTA V and RDR 2")
set(CPACK_PACKAGE_NAME "libragephoto")
set(CPACK_PACKAGE_VENDOR "Syping")
set(CPACK_PACKAGE_VERSION_MAJOR "${ragephoto_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${ragephoto_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${ragephoto_VERSION_PATCH}")
set(CPACK_STRIP_FILES ON)
include(CPack)
endif()

View file

@ -19,6 +19,7 @@ sudo cmake --install libragephoto-build
`-DCMAKE_CXX_STANDARD=17`
`-DRAGEPHOTO_BENCHMARK=ON`
`-DRAGEPHOTO_C_API=OFF`
`-DRAGEPHOTO_C_LIBRARY=ON`
`-DRAGEPHOTO_DOC=ON`
`-DRAGEPHOTO_EXAMPLE_GTKVIEWER=ON`
`-DRAGEPHOTO_EXAMPLE_QTVIEWER=ON`
@ -27,7 +28,7 @@ sudo cmake --install libragephoto-build
#### RagePhoto API
[RagePhoto C API](https://libragephoto.syping.de/doc/RagePhotoC_8h.html)
[RagePhoto C API](https://libragephoto.syping.de/doc/RagePhoto_8h.html)
[RagePhoto C++ API](https://libragephoto.syping.de/doc/classRagePhoto.html)
#### libragephoto Documentation

View file

@ -60,7 +60,7 @@ else()
"UNICODE_WINCVT"
)
message("-- UnicodeCvt - wincvt")
elseif (CODECVT_COMPAT)
elseif (CODECVT_COMPAT AND NOT RAGEPHOTO_C_LIBRARY)
list(APPEND LIBRAGEPHOTO_DEFINES
"UNICODE_CODECVT"
)
@ -70,5 +70,7 @@ else()
"UNICODE_ICONV"
)
message("-- UnicodeCvt - iconv")
else()
message("-- UnicodeCvt - none")
endif()
endif()

View file

@ -33,6 +33,7 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
"SHELL:-s MODULARIZE=1"
"SHELL:-s WASM=1"
"SHELL:-s WASM_BIGINT=1"
"SHELL:-s EXPORT_NAME=libragephotoModule"
"SHELL:-s EXPORTED_FUNCTIONS=_free,_malloc"
"SHELL:-s EXPORTED_RUNTIME_METHODS=ccall,cwrap"

View file

@ -12,5 +12,5 @@ EXPAND_ONLY_PREDEF = YES
PREDEFINED = "__cplusplus=201703L" \
"RAGEPHOTO_CXX_STD=17" \
"@LIBRAGEPHOTO_API@" \
"LIBRAGEPHOTO_C_BINDING=" \
"LIBRAGEPHOTO_CXX_BINDING="
"LIBRAGEPHOTO_C_PUBLIC=" \
"LIBRAGEPHOTO_CXX_PUBLIC="

View file

@ -20,6 +20,7 @@ To customise your libragephoto build, the following <a href="#flags">Optional CM
-DCMAKE_CXX_STANDARD=17
-DRAGEPHOTO_BENCHMARK=ON
-DRAGEPHOTO_C_API=OFF
-DRAGEPHOTO_C_LIBRARY=ON
-DRAGEPHOTO_DOC=ON
-DRAGEPHOTO_EXAMPLE_GTKVIEWER=ON
-DRAGEPHOTO_EXAMPLE_QTVIEWER=ON

View file

@ -14,7 +14,7 @@
<b>Reference</b>
RagePhoto (C++ API)
RagePhotoA (C++ API based on C API)
RagePhotoC.h (C API)
RagePhoto.h (C API)
RagePhotoData (Data Object Struct)
RagePhotoFormatParser (Custom Format Parser Struct)

View file

@ -4,10 +4,10 @@
<h4 id="cxx_include_usage">Including and using RagePhoto</h4>
Include RagePhoto.h or RagePhotoA.h
Include RagePhoto (C++ native), RagePhotoA (C API wrapper) or \link RagePhotoB.hpp RagePhotoB \endlink (best implementation)
\code{.cpp}
#include <RagePhoto.h>
#include <RagePhoto>
\endcode
Create a RagePhoto object
@ -96,7 +96,7 @@ bool saveJpeg(RagePhoto* ragePhoto, const std::string& filename) {
}
// Using the saveJpeg function
const char* filename = "PGTA5123456789";
const char* filename = "PGTA5123456789.jpg";
const bool saved = saveJpeg(&ragePhoto, filename);
\endcode
@ -128,7 +128,7 @@ const bool loaded = image.loadFromData(QByteArray::fromRawData(ragePhoto.jpegDat
Using the JSON in Boost.JSON
\code{.cpp}
std::error_code ec;
boost::json::error_code ec;
const boost::json::value jv = boost::json::parse(ragePhoto.json(), ec);
if (ec)
return;
@ -137,8 +137,7 @@ if (ec)
Using the JSON in Qt
\code{.cpp}
const QByteArray json = ragePhoto.json();
const QJsonDocument jd = QJsonDocument::fromJson(json);
const QJsonDocument jd = QJsonDocument::fromJson(ragePhoto.json());
if (jd.isNull())
return;
\endcode

View file

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include <RagePhoto.h>
#include <RagePhotoB>
#include <gtkmm/application.h>
#include <gtkmm/box.h>
#include <gtkmm/button.h>
@ -36,11 +36,11 @@ bool readPhotoFile(const std::string &filename, Gtk::Window *win, Gtk::Image *im
if (ifs.is_open()) {
std::string data(std::istreambuf_iterator<char>{ifs}, {});
ifs.close();
RagePhoto ragePhoto;
RagePhotoB ragePhoto;
const bool loaded = ragePhoto.load(data);
if (!loaded) {
const int32_t error = ragePhoto.error();
if (error <= RagePhoto::PhotoReadError) {
if (error <= RagePhotoB::PhotoReadError) {
Gtk::MessageDialog msg(*win, "Failed to read photo: " + filename, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true);
msg.set_title("Open Photo");
msg.run();

View file

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include <RagePhoto.h>
#include <RagePhotoB>
#include <QApplication>
#include <QHBoxLayout>
#include <QVBoxLayout>
@ -35,11 +35,11 @@ bool readPhotoFile(const QString &filename, QMainWindow *mainWindow, QLabel *pho
if (file.open(QIODevice::ReadOnly)) {
const QByteArray fileData = file.readAll();
file.close();
RagePhoto ragePhoto;
RagePhotoB ragePhoto;
const bool loaded = ragePhoto.load(fileData.data(), static_cast<size_t>(fileData.size()));
if (!loaded) {
const int32_t error = ragePhoto.error();
if (error <= RagePhoto::PhotoReadError) {
if (error <= RagePhotoB::PhotoReadError) {
QMessageBox::warning(mainWindow, "Open Photo", "Failed to read photo: " + filename);
return false;
}

1
src/RagePhoto Normal file
View file

@ -0,0 +1 @@
#include "RagePhoto.hpp"

View file

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include "RagePhotoC.h"
#include "RagePhoto.h"
#include <stdio.h>
int main(int argc, char *argv[])
@ -33,12 +33,13 @@ int main(int argc, char *argv[])
const int loaded = ragephoto_loadfile(ragephoto_in, argv[1]);
if (loaded != 1) {
if (ragephoto_error(ragephoto_in) == 0) {
const int32_t error = ragephoto_error(ragephoto_in);
if (error == RAGEPHOTO_ERROR_UNINITIALISED) {
printf("Failed to open file: %s\n", argv[1]);
ragephoto_close(ragephoto_in);
return 1;
}
else if (ragephoto_getphotosize(ragephoto_in) <= 0) {
else if (error <= RAGEPHOTO_ERROR_PHOTOREADERROR) {
printf("Failed to load photo\n");
ragephoto_close(ragephoto_in);
return 1;
@ -68,9 +69,9 @@ int main(int argc, char *argv[])
}
const uint32_t photoFormat = ragephoto_getphotoformat(ragephoto_in);
if (photoFormat == ragephoto_format_gta5())
if (photoFormat == RAGEPHOTO_FORMAT_GTA5)
printf("GTA V Photo successfully exported\n");
else if (photoFormat == ragephoto_format_rdr2())
else if (photoFormat == RAGEPHOTO_FORMAT_RDR2)
printf("RDR 2 Photo successfully exported\n");
else
printf("Photo successfully exported\n");

View file

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include "RagePhoto.h"
#include <RagePhotoB>
#include <fstream>
int main(int argc, char *argv[])
@ -27,18 +27,18 @@ int main(int argc, char *argv[])
}
// Initialise RagePhoto
RagePhoto ragePhoto;
RagePhotoB ragePhoto;
// Load Photo
const bool loaded = ragePhoto.loadFile(argv[1]);
if (!loaded) {
const int32_t error = ragePhoto.error();
if (error == RagePhoto::Uninitialised) {
if (error == RagePhotoB::Uninitialised) {
std::cout << "Failed to open file: " << argv[1] << std::endl;
return 1;
}
else if (error <= RagePhoto::PhotoReadError) {
else if (error <= RagePhotoB::PhotoReadError) {
std::cout << "Failed to load photo" << std::endl;
return 1;
}
@ -60,9 +60,9 @@ int main(int argc, char *argv[])
}
const uint32_t photoFormat = ragePhoto.format();
if (photoFormat == RagePhoto::GTA5)
if (photoFormat == RagePhotoB::GTA5)
std::cout << "GTA V Photo successfully exported" << std::endl;
else if (photoFormat == RagePhoto::RDR2)
else if (photoFormat == RagePhotoB::RDR2)
std::cout << "RDR 2 Photo successfully exported" << std::endl;
else
std::cout << "Photo successfully exported" << std::endl;

1230
src/RagePhoto.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -16,9 +16,9 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include "RagePhoto.hpp"
#ifdef LIBRAGEPHOTO_CXX_C
#include "RagePhoto.h"
#ifdef LIBRAGEPHOTO_C_API
#include "RagePhotoC.h"
#endif
#include <cstdlib>
@ -54,7 +54,7 @@ inline size_t readBuffer(const char *input, void *output, size_t *pos, size_t ou
readLen = inputLen - *pos;
if (readLen > outputLen)
readLen = outputLen;
std::memcpy(output, &input[*pos], readLen);
memcpy(output, &input[*pos], readLen);
*pos = *pos + readLen;
return readLen;
}
@ -67,7 +67,7 @@ inline size_t writeBuffer(const void *input, char *output, size_t *pos, size_t o
return 0;
if (inputLen > maxLen)
writeLen = maxLen;
std::memcpy(&output[*pos], input, writeLen);
memcpy(&output[*pos], input, writeLen);
*pos = *pos + writeLen;
return writeLen;
}
@ -78,33 +78,33 @@ inline bool writeDataChar(const char *input, char **output)
if (*output) {
const size_t dst_s = strlen(*output) + 1;
if (dst_s > src_s) {
char *t_output = static_cast<char*>(std::realloc(*output, src_s));
char *t_output = static_cast<char*>(realloc(*output, src_s));
if (!t_output) {
return false;
}
*output = t_output;
std::memcpy(*output, input, src_s);
memcpy(*output, input, src_s);
}
else if (dst_s < src_s) {
char *t_output = static_cast<char*>(std::malloc(src_s));
char *t_output = static_cast<char*>(malloc(src_s));
if (!t_output) {
return false;
}
std::free(*output);
free(*output);
*output = t_output;
std::memcpy(*output, input, src_s);
memcpy(*output, input, src_s);
}
else {
std::memcpy(*output, input, src_s);
memcpy(*output, input, src_s);
}
}
else {
char *t_output = static_cast<char*>(std::malloc(src_s));
char *t_output = static_cast<char*>(malloc(src_s));
if (!t_output) {
return false;
}
*output = t_output;
std::memcpy(*output, input, src_s);
memcpy(*output, input, src_s);
}
return true;
}
@ -143,53 +143,53 @@ inline uint32_t joaatFromInitial(const char *data, size_t size, uint32_t init_va
/* BEGIN OF RAGEPHOTO CLASS */
RagePhoto::RagePhoto()
{
m_data = static_cast<RagePhotoData*>(std::malloc(sizeof(RagePhotoData)));
m_data = static_cast<RagePhotoData*>(malloc(sizeof(RagePhotoData)));
if (!m_data)
throw std::runtime_error("RagePhotoData data struct can't be allocated");
std::memset(m_data, 0, sizeof(RagePhotoData));
m_parser = static_cast<RagePhotoFormatParser*>(std::malloc(sizeof(RagePhotoFormatParser)));
memset(m_data, 0, sizeof(RagePhotoData));
m_parser = static_cast<RagePhotoFormatParser*>(malloc(sizeof(RagePhotoFormatParser)));
if (!m_parser)
throw std::runtime_error("RagePhotoFormatParser parser struct can't be allocated");
std::memset(m_parser, 0, sizeof(RagePhotoFormatParser));
memset(m_parser, 0, sizeof(RagePhotoFormatParser));
setBufferDefault(m_data);
}
RagePhoto::~RagePhoto()
{
std::free(m_data->jpeg);
std::free(m_data->description);
std::free(m_data->json);
std::free(m_data->header);
std::free(m_data->title);
std::free(m_data);
std::free(m_parser);
free(m_data->jpeg);
free(m_data->description);
free(m_data->json);
free(m_data->header);
free(m_data->title);
free(m_data);
free(m_parser);
}
void RagePhoto::addParser(RagePhotoFormatParser *rp_parser)
{
if (rp_parser) {
RagePhotoFormatParser n_parser[1]{};
if (!std::memcmp(&n_parser[0], rp_parser, sizeof(RagePhotoFormatParser)))
if (!memcmp(&n_parser[0], rp_parser, sizeof(RagePhotoFormatParser)))
return;
size_t length;
for (length = 0; std::memcmp(&n_parser[0], &m_parser[length], sizeof(RagePhotoFormatParser)); length++);
RagePhotoFormatParser *t_parser = static_cast<RagePhotoFormatParser*>(std::realloc(m_parser, (length + 2 * sizeof(RagePhotoFormatParser))));
for (length = 0; memcmp(&n_parser[0], &m_parser[length], sizeof(RagePhotoFormatParser)); length++);
RagePhotoFormatParser *t_parser = static_cast<RagePhotoFormatParser*>(realloc(m_parser, (length + 2 * sizeof(RagePhotoFormatParser))));
if (!t_parser)
throw std::runtime_error("RagePhotoFormatParser array can't be expanded");
m_parser = t_parser;
std::memcpy(&m_parser[length], rp_parser, sizeof(RagePhotoFormatParser));
std::memset(&m_parser[length+1], 0, sizeof(RagePhotoFormatParser));
memcpy(&m_parser[length], rp_parser, sizeof(RagePhotoFormatParser));
memset(&m_parser[length+1], 0, sizeof(RagePhotoFormatParser));
}
}
void RagePhoto::clear(RagePhotoData *rp_data)
{
std::free(rp_data->jpeg);
std::free(rp_data->description);
std::free(rp_data->json);
std::free(rp_data->header);
std::free(rp_data->title);
std::memset(rp_data, 0, sizeof(RagePhotoData));
free(rp_data->jpeg);
free(rp_data->description);
free(rp_data->json);
free(rp_data->header);
free(rp_data->title);
memset(rp_data, 0, sizeof(RagePhotoData));
setBufferDefault(rp_data);
}
@ -221,7 +221,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->photoFormat, uInt32Buffer, 4);
memcpy(&rp_data->photoFormat, uInt32Buffer, 4);
#else
rp_data->photoFormat = charToUInt32LE(uInt32Buffer);
#endif
@ -242,19 +242,19 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
const size_t photoHeader_size = photoHeader_string.size() + 1;
rp_data->header = static_cast<char*>(std::malloc(photoHeader_size));
rp_data->header = static_cast<char*>(malloc(photoHeader_size));
if (!rp_data->header) {
rp_data->error = Error::HeaderMallocError; // 4
return false;
}
std::memcpy(rp_data->header, photoHeader_string.c_str(), photoHeader_size);
memcpy(rp_data->header, photoHeader_string.c_str(), photoHeader_size);
#elif defined UNICODE_ICONV
iconv_t iconv_in = iconv_open("UTF-8", "UTF-16LE");
if (iconv_in == (iconv_t)-1) {
rp_data->error = Error::UnicodeInitError; // 4
return false;
}
rp_data->header = static_cast<char*>(std::malloc(256));
rp_data->header = static_cast<char*>(malloc(256));
if (!rp_data->header) {
rp_data->error = Error::HeaderMallocError; // 4
iconv_close(iconv_in);
@ -271,14 +271,14 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#elif defined UNICODE_WINCVT
rp_data->header = static_cast<char*>(std::malloc(256));
rp_data->header = static_cast<char*>(malloc(256));
if (!rp_data->header) {
rp_data->error = Error::HeaderMallocError; // 4
return false;
}
const int converted = WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<wchar_t*>(photoHeader), -1, rp_data->header, 256, NULL, NULL);
if (converted == 0) {
std::free(rp_data->header);
free(rp_data->header);
rp_data->header = nullptr;
rp_data->error = Error::UnicodeHeaderError; // 6
return false;
@ -291,22 +291,23 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->headerSum, uInt32Buffer, 4);
memcpy(&rp_data->headerSum, uInt32Buffer, 4);
#else
rp_data->headerSum = charToUInt32LE(uInt32Buffer);
#endif
if (rp_data->photoFormat == PhotoFormat::RDR2) {
size = readBuffer(data, uInt32Buffer, &pos, 4, length);
char formatCheckBuffer[4];
size = readBuffer(data, formatCheckBuffer, &pos, 4, length);
if (size != 4) {
rp_data->error = Error::IncompleteChecksum; // 7
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->unnamedSum1, uInt32Buffer, 4);
#else
rp_data->unnamedSum1 = charToUInt32LE(uInt32Buffer);
#endif
char n_formatCheckBuffer[4]{};
if (memcmp(formatCheckBuffer, n_formatCheckBuffer, 4)) {
rp_data->error = Error::IncompatibleFormat; // 2
return false;
}
size = readBuffer(data, uInt32Buffer, &pos, 4, length);
if (size != 4) {
@ -314,9 +315,9 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->unnamedSum2, uInt32Buffer, 4);
memcpy(&rp_data->headerSum2, uInt32Buffer, 4);
#else
rp_data->unnamedSum2 = charToUInt32LE(uInt32Buffer);
rp_data->headerSum2 = charToUInt32LE(uInt32Buffer);
#endif
}
const size_t headerSize = pos;
@ -327,7 +328,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->endOfFile, uInt32Buffer, 4);
memcpy(&rp_data->endOfFile, uInt32Buffer, 4);
#else
rp_data->endOfFile = charToUInt32LE(uInt32Buffer);
#endif
@ -338,7 +339,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->jsonOffset, uInt32Buffer, 4);
memcpy(&rp_data->jsonOffset, uInt32Buffer, 4);
#else
rp_data->jsonOffset = charToUInt32LE(uInt32Buffer);
#endif
@ -348,7 +349,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->titlOffset, uInt32Buffer, 4);
memcpy(&rp_data->titlOffset, uInt32Buffer, 4);
#else
rp_data->titlOffset = charToUInt32LE(uInt32Buffer);
#endif
@ -359,7 +360,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->descOffset, uInt32Buffer, 4);
memcpy(&rp_data->descOffset, uInt32Buffer, 4);
#else
rp_data->descOffset = charToUInt32LE(uInt32Buffer);
#endif
@ -370,7 +371,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
rp_data->error = Error::IncompleteJpegMarker; // 12
return false;
}
if (std::memcmp(markerBuffer, "JPEG", 4) != 0) {
if (memcmp(markerBuffer, "JPEG", 4)) {
rp_data->error = Error::IncorrectJpegMarker; // 13
return false;
}
@ -381,7 +382,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->jpegBuffer, uInt32Buffer, 4);
memcpy(&rp_data->jpegBuffer, uInt32Buffer, 4);
#else
rp_data->jpegBuffer = charToUInt32LE(uInt32Buffer);
#endif
@ -392,19 +393,19 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->jpegSize, uInt32Buffer, 4);
memcpy(&rp_data->jpegSize, uInt32Buffer, 4);
#else
rp_data->jpegSize = charToUInt32LE(uInt32Buffer);
#endif
rp_data->jpeg = static_cast<char*>(std::malloc(rp_data->jpegSize));
rp_data->jpeg = static_cast<char*>(malloc(rp_data->jpegSize));
if (!rp_data->jpeg) {
rp_data->error = Error::PhotoMallocError; // 16
return false;
}
size = readBuffer(data, rp_data->jpeg, &pos, rp_data->jpegSize, length);
if (size != rp_data->jpegSize) {
std::free(rp_data->jpeg);
free(rp_data->jpeg);
rp_data->jpeg = nullptr;
rp_data->error = Error::PhotoReadError; // 17
return false;
@ -416,7 +417,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
rp_data->error = Error::IncompleteJsonMarker; // 18
return false;
}
if (std::memcmp(markerBuffer, "JSON", 4) != 0) {
if (memcmp(markerBuffer, "JSON", 4)) {
rp_data->error = Error::IncorrectJsonMarker; // 19
return false;
}
@ -427,19 +428,19 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->jsonBuffer, uInt32Buffer, 4);
memcpy(&rp_data->jsonBuffer, uInt32Buffer, 4);
#else
rp_data->jsonBuffer = charToUInt32LE(uInt32Buffer);
#endif
rp_data->json = static_cast<char*>(std::malloc(rp_data->jsonBuffer));
rp_data->json = static_cast<char*>(malloc(rp_data->jsonBuffer));
if (!rp_data->json) {
rp_data->error = Error::JsonMallocError; // 21
return false;
}
size = readBuffer(data, rp_data->json, &pos, rp_data->jsonBuffer, length);
if (size != rp_data->jsonBuffer) {
std::free(rp_data->json);
free(rp_data->json);
rp_data->json = nullptr;
rp_data->error = Error::JsonReadError; // 22
return false;
@ -451,7 +452,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
rp_data->error = Error::IncompleteTitleMarker; // 23
return false;
}
if (std::memcmp(markerBuffer, "TITL", 4) != 0) {
if (memcmp(markerBuffer, "TITL", 4)) {
rp_data->error = Error::IncorrectTitleMarker; // 24
return false;
}
@ -462,19 +463,19 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->titlBuffer, uInt32Buffer, 4);
memcpy(&rp_data->titlBuffer, uInt32Buffer, 4);
#else
rp_data->titlBuffer = charToUInt32LE(uInt32Buffer);
#endif
rp_data->title = static_cast<char*>(std::malloc(rp_data->titlBuffer));
rp_data->title = static_cast<char*>(malloc(rp_data->titlBuffer));
if (!rp_data->title) {
rp_data->error = Error::TitleMallocError; // 26
return false;
}
size = readBuffer(data, rp_data->title, &pos, rp_data->titlBuffer, length);
if (size != rp_data->titlBuffer) {
std::free(rp_data->title);
free(rp_data->title);
rp_data->title = nullptr;
rp_data->error = Error::TitleReadError; // 27
return false;
@ -486,7 +487,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
rp_data->error = Error::IncompleteDescMarker; // 28
return false;
}
if (std::memcmp(markerBuffer, "DESC", 4) != 0) {
if (memcmp(markerBuffer, "DESC", 4)) {
rp_data->error = Error::IncorrectDescMarker; // 29
return false;
}
@ -497,19 +498,19 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->descBuffer, uInt32Buffer, 4);
memcpy(&rp_data->descBuffer, uInt32Buffer, 4);
#else
rp_data->descBuffer = charToUInt32LE(uInt32Buffer);
#endif
rp_data->description = static_cast<char*>(std::malloc(rp_data->descBuffer));
rp_data->description = static_cast<char*>(malloc(rp_data->descBuffer));
if (!rp_data->description) {
rp_data->error = Error::DescMallocError; // 31
return false;
}
size = readBuffer(data, rp_data->description, &pos, rp_data->descBuffer, length);
if (size != rp_data->descBuffer) {
std::free(rp_data->description);
free(rp_data->description);
rp_data->description = nullptr;
rp_data->error = Error::DescReadError; // 32
return false;
@ -521,7 +522,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
rp_data->error = Error::IncompleteJendMarker; // 33
return false;
}
if (std::memcmp(markerBuffer, "JEND", 4) != 0) {
if (memcmp(markerBuffer, "JEND", 4)) {
rp_data->error = Error::IncorrectJendMarker; // 34
return false;
}
@ -535,8 +536,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
#ifdef RAGEPHOTO_DEBUG
std::cout << "header: " << rp_data->header << std::endl;
std::cout << "headerSum: " << rp_data->headerSum << std::endl;
std::cout << "unnamedSum1: " << rp_data->unnamedSum1 << std::endl;
std::cout << "unnamedSum2: " << rp_data->unnamedSum2 << std::endl;
std::cout << "headerSum2: " << rp_data->headerSum2 << std::endl;
std::cout << "photoBuffer: " << rp_data->jpegBuffer << std::endl;
std::cout << "descBuffer: " << rp_data->descBuffer << std::endl;
std::cout << "descOffset: " << rp_data->descOffset << std::endl;
@ -569,7 +569,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
}
else if (rp_parser) {
RagePhotoFormatParser n_parser[1]{};
for (size_t i = 0; std::memcmp(&n_parser[0], &rp_parser[i], sizeof(RagePhotoFormatParser)); i++) {
for (size_t i = 0; memcmp(&n_parser[0], &rp_parser[i], sizeof(RagePhotoFormatParser)); i++) {
if (rp_data->photoFormat == rp_parser[i].photoFormat)
if (rp_parser[i].funcLoad)
return (rp_parser[i].funcLoad)(rp_data, data, length);
@ -644,6 +644,8 @@ uint64_t RagePhoto::jpegSign(uint32_t photoFormat, RagePhotoData *rp_data)
{
if (photoFormat == PhotoFormat::GTA5)
return (0x100000000000000ULL | joaatFromInitial(rp_data->jpeg, rp_data->jpegSize, SignInitials::SIGTA5));
else if (photoFormat == PhotoFormat::RDR2)
return (0x100000000000000ULL | joaatFromInitial(rp_data->jpeg, rp_data->jpegSize, SignInitials::SIRDR2));
else
return 0;
}
@ -769,7 +771,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
char uInt32Buffer[4];
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &photoFormat, 4);
memcpy(uInt32Buffer, &photoFormat, 4);
#else
uInt32ToCharLE(static_cast<uint32_t>(photoFormat), uInt32Buffer);
#endif
@ -781,52 +783,48 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->headerSum, 4);
memcpy(uInt32Buffer, &rp_data->headerSum, 4);
#else
uInt32ToCharLE(rp_data->headerSum, uInt32Buffer);
#endif
writeBuffer(uInt32Buffer, data, &pos, length, 4);
if (photoFormat == PhotoFormat::RDR2) {
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->unnamedSum1, 4);
#else
uInt32ToCharLE(rp_data->unnamedSum1, uInt32Buffer);
#endif
writeBuffer(uInt32Buffer, data, &pos, length, 4);
char n_formatCheckBuffer[4]{};
writeBuffer(n_formatCheckBuffer, data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->unnamedSum2, 4);
memcpy(uInt32Buffer, &rp_data->headerSum2, 4);
#else
uInt32ToCharLE(rp_data->unnamedSum2, uInt32Buffer);
uInt32ToCharLE(rp_data->headerSum2, uInt32Buffer);
#endif
writeBuffer(uInt32Buffer, data, &pos, length, 4);
}
const size_t headerSize = pos;
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->endOfFile, 4);
memcpy(uInt32Buffer, &rp_data->endOfFile, 4);
#else
uInt32ToCharLE(rp_data->endOfFile, uInt32Buffer);
#endif
writeBuffer(uInt32Buffer, data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->jsonOffset, 4);
memcpy(uInt32Buffer, &rp_data->jsonOffset, 4);
#else
uInt32ToCharLE(rp_data->jsonOffset, uInt32Buffer);
#endif
writeBuffer(uInt32Buffer, data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->titlOffset, 4);
memcpy(uInt32Buffer, &rp_data->titlOffset, 4);
#else
uInt32ToCharLE(rp_data->titlOffset, uInt32Buffer);
#endif
writeBuffer(uInt32Buffer, data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->descOffset, 4);
memcpy(uInt32Buffer, &rp_data->descOffset, 4);
#else
uInt32ToCharLE(rp_data->descOffset, uInt32Buffer);
#endif
@ -835,14 +833,14 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
writeBuffer("JPEG", data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->jpegBuffer, 4);
memcpy(uInt32Buffer, &rp_data->jpegBuffer, 4);
#else
uInt32ToCharLE(rp_data->jpegBuffer, uInt32Buffer);
#endif
writeBuffer(uInt32Buffer, data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->jpegSize, 4);
memcpy(uInt32Buffer, &rp_data->jpegSize, 4);
#else
uInt32ToCharLE(rp_data->jpegSize, uInt32Buffer);
#endif
@ -857,7 +855,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
writeBuffer("JSON", data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->jsonBuffer, 4);
memcpy(uInt32Buffer, &rp_data->jsonBuffer, 4);
#else
uInt32ToCharLE(rp_data->jsonBuffer, uInt32Buffer);
#endif
@ -872,7 +870,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
writeBuffer("TITL", data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->titlBuffer, 4);
memcpy(uInt32Buffer, &rp_data->titlBuffer, 4);
#else
uInt32ToCharLE(rp_data->titlBuffer, uInt32Buffer);
#endif
@ -887,7 +885,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
writeBuffer("DESC", data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->descBuffer, 4);
memcpy(uInt32Buffer, &rp_data->descBuffer, 4);
#else
uInt32ToCharLE(rp_data->descBuffer, uInt32Buffer);
#endif
@ -911,7 +909,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
}
else if (rp_parser) {
RagePhotoFormatParser n_parser[1]{};
for (size_t i = 0; std::memcmp(&n_parser[0], &rp_parser[i], sizeof(RagePhotoFormatParser)); i++) {
for (size_t i = 0; memcmp(&n_parser[0], &rp_parser[i], sizeof(RagePhotoFormatParser)); i++) {
if (photoFormat == rp_parser[i].photoFormat)
if (rp_parser[i].funcSave)
return (rp_parser[i].funcSave)(rp_data, data, photoFormat);
@ -972,7 +970,11 @@ bool RagePhoto::saveFile(const std::string &filename, uint32_t photoFormat)
m_data->error = Error::Uninitialised; // 0
return false;
}
#if (RAGEPHOTO_CXX_STD >= 11) && (__cplusplus >= 201103L)
ofs << sdata;
#else
ofs.write(sdata.data(), sdata.size());
#endif
ok = ofs.good();
ofs.close();
return ok;
@ -994,7 +996,7 @@ size_t RagePhoto::saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePho
return (rp_data->jpegBuffer + rp_data->jsonBuffer + rp_data->titlBuffer + rp_data->descBuffer + RDR2_HEADERSIZE + 56UL);
else if (rp_parser) {
RagePhotoFormatParser n_parser[1]{};
for (size_t i = 0; std::memcmp(&n_parser[0], &rp_parser[i], sizeof(RagePhotoFormatParser)); i++) {
for (size_t i = 0; memcmp(&n_parser[0], &rp_parser[i], sizeof(RagePhotoFormatParser)); i++) {
if (photoFormat == rp_parser[i].photoFormat)
if (rp_parser[i].funcSaveSz)
return (rp_parser[i].funcSaveSz)(rp_data, photoFormat);
@ -1055,60 +1057,59 @@ bool RagePhoto::setData(RagePhotoData *rp_data, bool takeCopy)
if (rp_data->header) {
const size_t headerSize = strlen(rp_data->header) + 1;
m_data->header = static_cast<char*>(std::malloc(headerSize));
m_data->header = static_cast<char*>(malloc(headerSize));
if (!m_data->header)
return false;
std::memcpy(m_data->header, rp_data->header, headerSize);
memcpy(m_data->header, rp_data->header, headerSize);
m_data->headerSum = rp_data->headerSum;
m_data->headerSum2 = rp_data->headerSum2;
}
if (rp_data->jpeg) {
m_data->jpeg = static_cast<char*>(std::malloc(rp_data->jpegSize));
m_data->jpeg = static_cast<char*>(malloc(rp_data->jpegSize));
if (!m_data->jpeg)
return false;
std::memcpy(m_data->jpeg, rp_data->jpeg, rp_data->jpegSize);
memcpy(m_data->jpeg, rp_data->jpeg, rp_data->jpegSize);
m_data->jpegSize = rp_data->jpegSize;
m_data->jpegBuffer = rp_data->jpegBuffer;
}
if (rp_data->json) {
const size_t jsonSize = strlen(rp_data->json) + 1;
m_data->json = static_cast<char*>(std::malloc(jsonSize));
m_data->json = static_cast<char*>(malloc(jsonSize));
if (!m_data->json)
return false;
std::memcpy(m_data->json, rp_data->json, jsonSize);
memcpy(m_data->json, rp_data->json, jsonSize);
m_data->jsonBuffer = rp_data->jsonBuffer;
}
if (rp_data->title) {
const size_t titleSize = strlen(rp_data->title) + 1;
m_data->title = static_cast<char*>(std::malloc(titleSize));
m_data->title = static_cast<char*>(malloc(titleSize));
if (!m_data->title)
return false;
std::memcpy(m_data->title, rp_data->title, titleSize);
memcpy(m_data->title, rp_data->title, titleSize);
m_data->titlBuffer = rp_data->titlBuffer;
}
if (rp_data->description) {
const size_t descriptionSize = strlen(rp_data->description) + 1;
m_data->description = static_cast<char*>(std::malloc(descriptionSize));
m_data->description = static_cast<char*>(malloc(descriptionSize));
if (!m_data->description)
return false;
std::memcpy(m_data->description, rp_data->description, descriptionSize);
memcpy(m_data->description, rp_data->description, descriptionSize);
m_data->descBuffer = rp_data->descBuffer;
}
m_data->unnamedSum1 = rp_data->unnamedSum1;
m_data->unnamedSum2 = rp_data->unnamedSum2;
setBufferOffsets(m_data);
}
else {
std::free(m_data->jpeg);
std::free(m_data->description);
std::free(m_data->json);
std::free(m_data->header);
std::free(m_data->title);
std::free(m_data);
free(m_data->jpeg);
free(m_data->description);
free(m_data->json);
free(m_data->header);
free(m_data->title);
free(m_data);
m_data = rp_data;
}
@ -1138,36 +1139,36 @@ bool RagePhoto::setJpeg(const char *data, uint32_t size, uint32_t bufferSize)
{
if (m_data->jpeg) {
if (m_data->jpegSize > size) {
char *t_photoData = static_cast<char*>(std::realloc(m_data->jpeg, size));
char *t_photoData = static_cast<char*>(realloc(m_data->jpeg, size));
if (!t_photoData) {
m_data->error = Error::PhotoMallocError; // 16
return false;
}
m_data->jpeg = t_photoData;
std::memcpy(m_data->jpeg, data, size);
memcpy(m_data->jpeg, data, size);
m_data->jpegSize = size;
}
else if (m_data->jpegSize < size) {
std::free(m_data->jpeg);
m_data->jpeg = static_cast<char*>(std::malloc(size));
free(m_data->jpeg);
m_data->jpeg = static_cast<char*>(malloc(size));
if (!m_data->jpeg) {
m_data->error = Error::PhotoMallocError; // 16
return false;
}
std::memcpy(m_data->jpeg, data, size);
memcpy(m_data->jpeg, data, size);
m_data->jpegSize = size;
}
else {
std::memcpy(m_data->jpeg, data, size);
memcpy(m_data->jpeg, data, size);
}
}
else {
m_data->jpeg = static_cast<char*>(std::malloc(size));
m_data->jpeg = static_cast<char*>(malloc(size));
if (!m_data->jpeg) {
m_data->error = Error::PhotoMallocError; // 16
return false;
}
std::memcpy(m_data->jpeg, data, size);
memcpy(m_data->jpeg, data, size);
m_data->jpegSize = size;
}
@ -1198,13 +1199,14 @@ void RagePhoto::setJson(const char *json, uint32_t bufferSize)
m_data->error = Error::NoError; // 255
}
void RagePhoto::setHeader(const char *header, uint32_t headerSum)
void RagePhoto::setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2)
{
if (!writeDataChar(header, &m_data->header)) {
m_data->error = Error::HeaderMallocError; // 4
return;
}
m_data->headerSum = headerSum;
m_data->headerSum2 = headerSum2;
m_data->error = Error::NoError; // 255
}
@ -1221,7 +1223,7 @@ void RagePhoto::setTitle(const char *title, uint32_t bufferSize)
m_data->error = Error::NoError; // 255
}
#ifdef LIBRAGEPHOTO_C_API
#ifdef LIBRAGEPHOTO_CXX_C
ragephoto_t ragephoto_open()
{
return static_cast<ragephoto_t>(new RagePhoto);
@ -1244,18 +1246,18 @@ void ragephotodata_clear(RagePhotoData *rp_data)
RagePhoto::clear(rp_data);
}
ragephoto_bool_t ragephoto_load(ragephoto_t instance, const char *data, size_t size)
bool ragephoto_load(ragephoto_t instance, const char *data, size_t size)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->load(data, size);
}
ragephoto_bool_t ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t size)
bool ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t size)
{
return RagePhoto::load(data, size, rp_data, rp_parser);
}
ragephoto_bool_t ragephoto_loadfile(ragephoto_t instance, const char *filename)
bool ragephoto_loadfile(ragephoto_t instance, const char *filename)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->loadFile(filename);
@ -1379,35 +1381,35 @@ size_t ragephotodata_getsavesizef(RagePhotoData *rp_data, RagePhotoFormatParser
return RagePhoto::saveSize(photoFormat, rp_data, rp_parser);
}
ragephoto_bool_t ragephoto_save(ragephoto_t instance, char *data)
bool ragephoto_save(ragephoto_t instance, char *data)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->save(data);
}
ragephoto_bool_t ragephotodata_save(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data)
bool ragephotodata_save(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data)
{
return RagePhoto::save(data, rp_data->photoFormat, rp_data, rp_parser);
}
ragephoto_bool_t ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat)
bool ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->save(data, photoFormat);
}
ragephoto_bool_t ragephotodata_savef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data, uint32_t photoFormat)
bool ragephotodata_savef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data, uint32_t photoFormat)
{
return RagePhoto::save(data, photoFormat, rp_data, rp_parser);
}
ragephoto_bool_t ragephoto_savefile(ragephoto_t instance, const char *filename)
bool ragephoto_savefile(ragephoto_t instance, const char *filename)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->saveFile(filename);
}
ragephoto_bool_t ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat)
bool ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->saveFile(filename, photoFormat);
@ -1435,13 +1437,13 @@ void ragephotodata_setbufferoffsets(RagePhotoData *rp_data)
RagePhoto::setBufferOffsets(rp_data);
}
ragephoto_bool_t ragephoto_setphotodata(ragephoto_t instance, RagePhotoData *rp_data)
bool ragephoto_setphotodata(ragephoto_t instance, RagePhotoData *rp_data)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->setData(rp_data, false);
}
ragephoto_bool_t ragephoto_setphotodatac(ragephoto_t instance, RagePhotoData *rp_data)
bool ragephoto_setphotodatac(ragephoto_t instance, RagePhotoData *rp_data)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->setData(rp_data, true);
@ -1459,7 +1461,7 @@ void ragephoto_setphotoformat(ragephoto_t instance, uint32_t photoFormat)
ragePhoto->setFormat(photoFormat);
}
ragephoto_bool_t ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize)
bool ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->setJpeg(data, size, bufferSize);
@ -1477,6 +1479,12 @@ void ragephoto_setphotoheader(ragephoto_t instance, const char *header, uint32_t
ragePhoto->setHeader(header, headerSum);
}
void ragephoto_setphotoheader2(ragephoto_t instance, const char *header, uint32_t headerSum, uint32_t headerSum2)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
ragePhoto->setHeader(header, headerSum, headerSum2);
}
void ragephoto_setphototitle(ragephoto_t instance, const char *title, uint32_t bufferSize)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);

View file

@ -19,174 +19,297 @@
#ifndef RAGEPHOTO_H
#define RAGEPHOTO_H
#ifdef __cplusplus
#include "RagePhotoLibrary.h"
#include "RagePhotoTypedefs.h"
#include <iostream>
#include <cstdlib>
#include <cstdint>
#include <cstdio>
#include <stddef.h>
#include <stdint.h>
/**
* \brief GTA V and RDR 2 Photo Parser.
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/** C API for RagePhoto.
* \file RagePhoto.h
*/
class LIBRAGEPHOTO_CXX_BINDING RagePhoto
{
public:
/** 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 */
};
/** Parsing and set errors */
enum Error : int32_t {
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 */
IncompatibleFormat = 2, /**< Format is incompatible */
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 */
IncompleteHeader = 3, /**< Header is incomplete */
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 */
NoError = 255, /**< Finished without errors */
NoFormatIdentifier = 1, /**< No format detected, empty file */
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 */
Uninitialised = 0, /**< Uninitialised, file access failed */
};
/** Photo Formats */
enum PhotoFormat : uint32_t {
GTA5 = 0x01000000UL, /**< GTA V Photo Format */
RDR2 = 0x04000000UL, /**< RDR 2 Photo Format */
};
/** Sign Initials */
enum SignInitials : uint32_t {
SIGTA5 = 0xE47AB81CUL, /**< GTA V Sign Initial */
};
RagePhoto();
~RagePhoto();
void addParser(RagePhotoFormatParser *rp_parser); /**< Add a custom defined RagePhotoFormatParser. */
static void clear(RagePhotoData *rp_data); /**< Resets the RagePhotoData object to default values. */
void clear(); /**< Resets the RagePhotoData object to default values. */
RagePhotoData* data(); /**< Returns the internal RagePhotoData object. */
static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Loads a Photo from a const char*. */
/** 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);
/** Loads a Photo from a file.
* \param filename File to load
*/
bool loadFile(const std::string &filename);
int32_t error() const; /**< Returns the last error occurred. */
uint32_t format() const; /**< Returns the Photo Format (GTA V or RDR 2). */
const std::string jpeg() const; /**< Returns the Photo JPEG data. */
#if (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L)
const std::string_view jpeg_view() const; /**< Returns the Photo JPEG data. */
#endif
const char* jpegData() const; /**< Returns the Photo JPEG data. */
static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data); /**< Returns the Photo JPEG sign. */
static uint64_t jpegSign(RagePhotoData *rp_data); /**< Returns the Photo JPEG sign. */
uint64_t jpegSign(uint32_t photoFormat) const; /**< Returns the Photo JPEG sign. */
uint64_t jpegSign() const; /**< Returns the Photo JPEG sign. */
uint32_t jpegSize() const; /**< Returns the Photo JPEG data size. */
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. */
static const char* version(); /**< Returns the library version. */
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*. */
/** Saves a Photo to a char*.
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
bool save(char *data, uint32_t photoFormat);
/** 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
*/
const std::string save(uint32_t photoFormat, bool *ok = nullptr);
/** Saves a Photo to a std::string.
* \param ok \p true when saved successfully
*/
const std::string save(bool *ok = nullptr);
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. */
static size_t saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Returns the Photo save file size. */
static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Returns the Photo save file size. */
size_t saveSize(uint32_t photoFormat); /**< Returns the Photo save file size. */
size_t saveSize(); /**< Returns the Photo save file size. */
static void setBufferDefault(RagePhotoData *rp_data); /**< Sets all cross-format Buffer to default size. */
void setBufferDefault(); /**< Sets all cross-format Buffer to default size. */
static void setBufferOffsets(RagePhotoData *rp_data); /**< Moves all Buffer offsets to correct position. */
void setBufferOffsets(); /**< Moves all Buffer offsets to correct position. */
bool setData(RagePhotoData *rp_data, bool takeCopy = true); /**< Sets the internal RagePhotoData object. */
void setDescription(const char *description, uint32_t bufferSize = 0); /**< Sets the Photo description. */
void setFormat(uint32_t photoFormat); /**< Sets the Photo Format (GTA V or RDR 2). */
/** Sets the Photo JPEG data.
* \param data JPEG data
* \param size JPEG data size
* \param bufferSize JPEG buffer size
*/
bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize = 0);
/** Sets the Photo JPEG data.
* \param data JPEG data
* \param bufferSize JPEG buffer size
*/
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) */
void setTitle(const char *title, uint32_t bufferSize = 0); /**< Sets the Photo title. */
private:
RagePhotoData *m_data;
RagePhotoFormatParser *m_parser;
};
#else
#include "RagePhotoC.h"
/** RagePhoto C instance/C++ class typedef. */
typedef void* ragephoto_t;
/** Opens a \p ragephoto_t instance. */
LIBRAGEPHOTO_C_PUBLIC ragephoto_t ragephoto_open();
/** Add a custom defined RagePhotoFormatParser.
* \param instance \p ragephoto_t instance
* \param rp_parser RagePhotoFormatParser parser to add
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_addparser(ragephoto_t instance, RagePhotoFormatParser *rp_parser);
/** Resets the RagePhotoData object to default values.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_clear(ragephoto_t instance);
/** Resets the RagePhotoData object to default values.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_PUBLIC void ragephotodata_clear(RagePhotoData *rp_data);
/** Loads a Photo from a const char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param size Photo data size
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_load(ragephoto_t instance, const char *data, size_t size);
/** Loads a Photo from a const char*.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
* \param data Photo data
* \param size Photo data size
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t size);
/** Loads a Photo from a file.
* \param instance \p ragephoto_t instance
* \param filename File to load
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_loadfile(ragephoto_t instance, const char *filename);
/** Returns the last error occurred.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC int32_t ragephoto_error(ragephoto_t instance);
/** Returns the GTA V default Photo Buffer Size. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_defpbuf_gta5();
/** Returns the RDR 2 default Photo Buffer Size. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_defpbuf_rdr2();
/** Returns the GTA V Photo Format. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_format_gta5();
/** Returns the RDR 2 Photo Format. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_format_rdr2();
/** Returns the internal RagePhotoData object.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC RagePhotoData* ragephoto_getphotodata(ragephoto_t instance);
/** Returns the Photo description.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotodesc(ragephoto_t instance);
/** Returns the Photo Format (GTA V or RDR 2).
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_getphotoformat(ragephoto_t instance);
/** Returns the Photo JPEG data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotojpeg(ragephoto_t instance);
/** Returns the Photo JSON data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotojson(ragephoto_t instance);
/** Returns the Photo header.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotoheader(ragephoto_t instance);
/** Returns the Photo JPEG sign.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephoto_getphotosign(ragephoto_t instance);
/** Returns the Photo JPEG sign.
* \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephoto_getphotosignf(ragephoto_t instance, uint32_t photoFormat);
/** Returns the Photo JPEG sign.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephotodata_getphotosign(RagePhotoData *rp_data);
/** Returns the Photo JPEG sign.
* \param rp_data RagePhotoData object
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephotodata_getphotosignf(RagePhotoData *rp_data, uint32_t photoFormat);
/** Returns the Photo JPEG data size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_getphotosize(ragephoto_t instance);
/** Returns the Photo title.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphototitle(ragephoto_t instance);
/** Returns the Photo save file size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC size_t ragephoto_getsavesize(ragephoto_t instance);
/** Returns the Photo save file size.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
*/
LIBRAGEPHOTO_C_PUBLIC size_t ragephotodata_getsavesize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
/** Returns the Photo save file size.
* \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC size_t ragephoto_getsavesizef(ragephoto_t instance, uint32_t photoFormat);
/** Returns the Photo save file size.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC size_t ragephotodata_getsavesizef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, uint32_t photoFormat);
/** Saves a Photo to a char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_save(ragephoto_t instance, char *data);
/** Saves a Photo to a char*.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
* \param data Photo data
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephotodata_save(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data);
/** Saves a Photo to a char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat);
/** Saves a Photo to a char*.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephotodata_savef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data, uint32_t photoFormat);
/** Saves a Photo to a file.
* \param instance \p ragephoto_t instance
* \param filename File to save
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savefile(ragephoto_t instance, const char *filename);
/** Saves a Photo to a file.
* \param instance \p ragephoto_t instance
* \param filename File to save
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat);
/** Sets all cross-format Buffer to default size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setbufferdefault(ragephoto_t instance);
/** Sets all cross-format Buffer to default size.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_PUBLIC void ragephotodata_setbufferdefault(RagePhotoData *rp_data);
/** Moves all Buffer offsets to correct position.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setbufferoffsets(ragephoto_t instance);
/** Moves all Buffer offsets to correct position.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_PUBLIC void ragephotodata_setbufferoffsets(RagePhotoData *rp_data);
/** Sets the internal RagePhotoData object.
* \param instance \p ragephoto_t instance
* \param rp_data RagePhotoData object being set
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotodata(ragephoto_t instance, RagePhotoData *rp_data);
/** Copies RagePhotoData object to internal RagePhotoData object.
* \param instance \p ragephoto_t instance
* \param rp_data RagePhotoData object being copied
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotodatac(ragephoto_t instance, RagePhotoData *rp_data);
/** Sets the Photo description.
* \param instance \p ragephoto_t instance
* \param description Description
* \param bufferSize Description buffer size
*
* Default bufferSize: 256UL
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotodesc(ragephoto_t instance, const char *description, uint32_t bufferSize);
/** Sets the Photo Format (GTA V or RDR 2).
* \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoformat(ragephoto_t instance, uint32_t photoFormat);
/** Sets the Photo JPEG data.
* \param instance \p ragephoto_t instance
* \param data JPEG data
* \param size JPEG data size
* \param bufferSize JPEG buffer size
*
* Default bufferSize: ragephoto_defpbuf_gta5() or ragephoto_defpbuf_rdr2()
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize);
/** Sets the Photo JSON data.
* \param instance \p ragephoto_t instance
* \param json JSON data
* \param bufferSize JSON data buffer size
*
* Default bufferSize: 3072UL
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotojson(ragephoto_t instance, const char *json, uint32_t bufferSize);
/** Sets the Photo header. */
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoheader(ragephoto_t instance, const char *header, uint32_t headerSum);
/** Sets the Photo header. (RDR 2) */
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoheader2(ragephoto_t instance, const char *header, uint32_t headerSum, uint32_t headerSum2);
/** Sets the Photo title.
* \param instance \p ragephoto_t instance
* \param title Title
* \param bufferSize Title buffer size
*
* Default bufferSize: 256UL
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphototitle(ragephoto_t instance, const char *title, uint32_t bufferSize);
/** Closes a \p ragephoto_t instance.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_close(ragephoto_t instance);
/** Returns the library version. */
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_version();
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // RAGEPHOTO_H

191
src/RagePhoto.hpp Normal file
View file

@ -0,0 +1,191 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021-2023 Syping
*
* 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_HPP
#define RAGEPHOTO_HPP
#ifdef __cplusplus
#include "RagePhotoLibrary.h"
#include "RagePhotoTypedefs.h"
#include <iostream>
#include <cstdlib>
#include <cstdint>
#include <cstdio>
/**
* \brief GTA V and RDR 2 Photo Parser.
*/
class LIBRAGEPHOTO_CXX_PUBLIC RagePhoto
{
public:
/** 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 */
};
/** Parsing and set errors */
enum Error : int32_t {
DescBufferTight = 39L, /**< Description Buffer is too tight */
DescMallocError = 31L, /**< Description Buffer can't be allocated */
DescReadError = 32L, /**< Description can't be read successfully */
HeaderBufferTight = 35L, /**< Header Buffer is too tight */
HeaderMallocError = 4L, /**< Header Buffer can't be allocated */
IncompatibleFormat = 2L, /**< Format is incompatible */
IncompleteChecksum = 7L, /**< Header checksum is incomplete */
IncompleteDescBuffer = 30L, /**< Description Buffer Size is incomplete */
IncompleteDescMarker = 28L, /**< Description Marker is incomplete */
IncompleteDescOffset = 11L, /**< Description Offset is incomplete */
IncompleteEOF = 8L, /**< End Of File Offset is incomplete */
IncompleteHeader = 3L, /**< Header is incomplete */
IncompleteJendMarker = 33L, /**< JEND Marker is incomplete */
IncompleteJpegMarker = 12L, /**< JPEG Marker is incomplete */
IncompleteJsonBuffer = 20L, /**< JSON Buffer Size is incomplete */
IncompleteJsonMarker = 18L, /**< JSON Marker incomplete */
IncompleteJsonOffset = 9L, /**< JSON Offset incomplete */
IncompletePhotoBuffer = 14L, /**< Photo Buffer Size is incomplete */
IncompletePhotoSize = 15L, /**< Photo Size is incomplete */
IncompleteTitleBuffer = 25L, /**< Title Buffer Size is incomplete */
IncompleteTitleMarker = 23L, /**< Title Marker is incomplete */
IncompleteTitleOffset = 10L, /**< Title Offset is incomplete */
IncorrectDescMarker = 29L, /**< Description Marker is incorrect */
IncorrectJendMarker = 34L, /**< JEND Marker is incorrect */
IncorrectJpegMarker = 13L, /**< JPEG Marker is incorrect */
IncorrectJsonMarker = 19L, /**< JSON Marker is incorrect */
IncorrectTitleMarker = 24L, /**< Title Marker is incorrect */
JsonBufferTight = 37L, /**< JSON Buffer is too tight */
JsonMallocError = 21L, /**< JSON Buffer can't be allocated */
JsonReadError = 22L, /**< JSON can't be read successfully */
NoError = 255L, /**< Finished without errors */
NoFormatIdentifier = 1L, /**< No format detected, empty file */
PhotoBufferTight = 36L, /**< Photo Buffer is too tight */
PhotoMallocError = 16L, /**< Photo Buffer can't be allocated */
PhotoReadError = 17L, /**< Photo can't be read */
TitleBufferTight = 38L, /**< Title Buffer is too tight */
TitleMallocError = 26L, /**< Title Buffer can't be allocated */
TitleReadError = 27L, /**< Title can't be read */
UnicodeInitError = 5L, /**< Failed to initialise Unicode decoder */
UnicodeHeaderError = 6L, /**< Header can't be encoded/decoded successfully */
Uninitialised = 0L, /**< Uninitialised, file access failed */
};
/** Photo Formats */
enum PhotoFormat : uint32_t {
GTA5 = 0x01000000UL, /**< GTA V Photo Format */
RDR2 = 0x04000000UL, /**< RDR 2 Photo Format */
};
/** Sign Initials */
enum SignInitials : uint32_t {
SIGTA5 = 0xE47AB81CUL, /**< GTA V Sign Initial */
SIRDR2 = 0x00FEEB1EUL, /**< RDR 2 Sign Initial */
};
RagePhoto();
~RagePhoto();
void addParser(RagePhotoFormatParser *rp_parser); /**< Add a custom defined RagePhotoFormatParser. */
static void clear(RagePhotoData *rp_data); /**< Resets the RagePhotoData object to default values. */
void clear(); /**< Resets the RagePhotoData object to default values. */
RagePhotoData* data(); /**< Returns the internal RagePhotoData object. */
static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Loads a Photo from a const char*. */
/** 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);
/** Loads a Photo from a file.
* \param filename File to load
*/
bool loadFile(const std::string &filename);
int32_t error() const; /**< Returns the last error occurred. */
uint32_t format() const; /**< Returns the Photo Format (GTA V or RDR 2). */
const std::string jpeg() const; /**< Returns the Photo JPEG data. */
#if (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L)
const std::string_view jpeg_view() const; /**< Returns the Photo JPEG data. */
#endif
const char* jpegData() const; /**< Returns the Photo JPEG data. */
static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data); /**< Returns the Photo JPEG sign. */
static uint64_t jpegSign(RagePhotoData *rp_data); /**< Returns the Photo JPEG sign. */
uint64_t jpegSign(uint32_t photoFormat) const; /**< Returns the Photo JPEG sign. */
uint64_t jpegSign() const; /**< Returns the Photo JPEG sign. */
uint32_t jpegSize() const; /**< Returns the Photo JPEG data size. */
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. */
static const char* version(); /**< Returns the library version. */
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*. */
/** Saves a Photo to a char*.
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
bool save(char *data, uint32_t photoFormat);
/** 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
*/
const std::string save(uint32_t photoFormat, bool *ok = nullptr);
/** Saves a Photo to a std::string.
* \param ok \p true when saved successfully
*/
const std::string save(bool *ok = nullptr);
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. */
static size_t saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Returns the Photo save file size. */
static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Returns the Photo save file size. */
size_t saveSize(uint32_t photoFormat); /**< Returns the Photo save file size. */
size_t saveSize(); /**< Returns the Photo save file size. */
static void setBufferDefault(RagePhotoData *rp_data); /**< Sets all cross-format Buffer to default size. */
void setBufferDefault(); /**< Sets all cross-format Buffer to default size. */
static void setBufferOffsets(RagePhotoData *rp_data); /**< Moves all Buffer offsets to correct position. */
void setBufferOffsets(); /**< Moves all Buffer offsets to correct position. */
bool setData(RagePhotoData *rp_data, bool takeCopy = true); /**< Sets the internal RagePhotoData object. */
void setDescription(const char *description, uint32_t bufferSize = 0); /**< Sets the Photo description. */
void setFormat(uint32_t photoFormat); /**< Sets the Photo Format (GTA V or RDR 2). */
/** Sets the Photo JPEG data.
* \param data JPEG data
* \param size JPEG data size
* \param bufferSize JPEG buffer size
*/
bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize = 0);
/** Sets the Photo JPEG data.
* \param data JPEG data
* \param bufferSize JPEG buffer size
*/
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, uint32_t headerSum2 = 0); /**< Sets the Photo header. */
void setTitle(const char *title, uint32_t bufferSize = 0); /**< Sets the Photo title. */
private:
RagePhotoData *m_data;
RagePhotoFormatParser *m_parser;
};
#endif // __cplusplus
#endif // RAGEPHOTO_HPP

1
src/RagePhotoA Normal file
View file

@ -0,0 +1 @@
#include "RagePhotoA.hpp"

View file

@ -16,19 +16,16 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#ifndef RAGEPHOTOA_H
#define RAGEPHOTOA_H
#ifndef RAGEPHOTOA_HPP
#define RAGEPHOTOA_HPP
#ifdef __cplusplus
#include "RagePhotoC.h"
#include "RagePhoto.h"
#include <cstdlib>
#include <iostream>
/**
* \brief ABI Stable Wrapper for RagePhoto.
*
* Using RagePhotoA instead of RagePhoto allows your library or application to survive more changes in the RagePhoto class,
* disadvantages include that it doesn't always include the newest features, performance is about the same.
* \brief GTA V and RDR 2 Photo Parser (C API wrapper).
*/
class RagePhotoA
{
@ -45,47 +42,47 @@ public:
};
/** Parsing and set errors */
enum Error : int32_t {
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 */
IncompatibleFormat = 2, /**< Format is incompatible */
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 */
IncompleteHeader = 3, /**< Header is incomplete */
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 */
NoError = 255, /**< Finished without errors */
NoFormatIdentifier = 1, /**< No format detected, empty file */
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 */
Uninitialised = 0, /**< Uninitialised, file access failed */
DescBufferTight = 39L, /**< Description Buffer is too tight */
DescMallocError = 31L, /**< Description Buffer can't be allocated */
DescReadError = 32L, /**< Description can't be read successfully */
HeaderBufferTight = 35L, /**< Header Buffer is too tight */
HeaderMallocError = 4L, /**< Header Buffer can't be allocated */
IncompatibleFormat = 2L, /**< Format is incompatible */
IncompleteChecksum = 7L, /**< Header checksum is incomplete */
IncompleteDescBuffer = 30L, /**< Description Buffer Size is incomplete */
IncompleteDescMarker = 28L, /**< Description Marker is incomplete */
IncompleteDescOffset = 11L, /**< Description Offset is incomplete */
IncompleteEOF = 8L, /**< End Of File Offset is incomplete */
IncompleteHeader = 3L, /**< Header is incomplete */
IncompleteJendMarker = 33L, /**< JEND Marker is incomplete */
IncompleteJpegMarker = 12L, /**< JPEG Marker is incomplete */
IncompleteJsonBuffer = 20L, /**< JSON Buffer Size is incomplete */
IncompleteJsonMarker = 18L, /**< JSON Marker incomplete */
IncompleteJsonOffset = 9L, /**< JSON Offset incomplete */
IncompletePhotoBuffer = 14L, /**< Photo Buffer Size is incomplete */
IncompletePhotoSize = 15L, /**< Photo Size is incomplete */
IncompleteTitleBuffer = 25L, /**< Title Buffer Size is incomplete */
IncompleteTitleMarker = 23L, /**< Title Marker is incomplete */
IncompleteTitleOffset = 10L, /**< Title Offset is incomplete */
IncorrectDescMarker = 29L, /**< Description Marker is incorrect */
IncorrectJendMarker = 34L, /**< JEND Marker is incorrect */
IncorrectJpegMarker = 13L, /**< JPEG Marker is incorrect */
IncorrectJsonMarker = 19L, /**< JSON Marker is incorrect */
IncorrectTitleMarker = 24L, /**< Title Marker is incorrect */
JsonBufferTight = 37L, /**< JSON Buffer is too tight */
JsonMallocError = 21L, /**< JSON Buffer can't be allocated */
JsonReadError = 22L, /**< JSON can't be read successfully */
NoError = 255L, /**< Finished without errors */
NoFormatIdentifier = 1L, /**< No format detected, empty file */
PhotoBufferTight = 36L, /**< Photo Buffer is too tight */
PhotoMallocError = 16L, /**< Photo Buffer can't be allocated */
PhotoReadError = 17L, /**< Photo can't be read */
TitleBufferTight = 38L, /**< Title Buffer is too tight */
TitleMallocError = 26L, /**< Title Buffer can't be allocated */
TitleReadError = 27L, /**< Title can't be read */
UnicodeInitError = 5L, /**< Failed to initialise Unicode decoder */
UnicodeHeaderError = 6L, /**< Header can't be encoded/decoded successfully */
Uninitialised = 0L, /**< Uninitialised, file access failed */
};
/** Photo Formats */
enum PhotoFormat : uint32_t {
@ -95,6 +92,7 @@ public:
/** Sign Initials */
enum SignInitials : uint32_t {
SIGTA5 = 0xE47AB81CUL, /**< GTA V Sign Initial */
SIRDR2 = 0x00FEEB1EUL, /**< RDR 2 Sign Initial */
};
RagePhotoA() {
instance = ragephoto_open();
@ -301,7 +299,7 @@ public:
if (takeCopy)
return ragephoto_setphotodatac(instance, ragePhotoData);
else
return ragephoto_setphotodata(&instance, ragePhotoData);
return ragephoto_setphotodata(instance, ragePhotoData);
}
/** Sets the Photo description. */
void setDescription(const char *description, uint32_t bufferSize = 0) {
@ -330,9 +328,9 @@ public:
void setJson(const char *json, uint32_t bufferSize = 0) {
ragephoto_setphotojson(instance, json, bufferSize);
}
/** Sets the Photo header. (EXPERT ONLY) */
void setHeader(const char *header, uint32_t headerSum) {
ragephoto_setphotoheader(instance, header, headerSum);
/** Sets the Photo header. */
void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0) {
ragephoto_setphotoheader2(instance, header, headerSum, headerSum2);
}
/** Sets the Photo title. */
void setTitle(const char *title, uint32_t bufferSize = 0) {
@ -342,8 +340,6 @@ public:
private:
ragephoto_t instance;
};
#else
#include "RagePhotoC.h"
#endif // __cplusplus
#endif // RAGEPHOTOA_H
#endif // RAGEPHOTOA_HPP

1
src/RagePhotoB Normal file
View file

@ -0,0 +1 @@
#include "RagePhotoB.hpp"

43
src/RagePhotoB.hpp Normal file
View file

@ -0,0 +1,43 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2023 Syping
*
* 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 RAGEPHOTOB_HPP
#define RAGEPHOTOB_HPP
#ifdef __cplusplus
#include "RagePhotoLibrary.h"
#ifdef LIBRAGEPHOTO_CXX_ONLY
#include "RagePhoto.hpp"
typedef RagePhoto RagePhotoB;
#elif defined LIBRAGEPHOTO_CXX_C
#ifdef LIBRAGEPHOTO_STATIC
#include "RagePhoto.hpp"
typedef RagePhoto RagePhotoB;
#else
#include "RagePhotoA.hpp"
typedef RagePhotoA RagePhotoB;
#endif // LIBRAGEPHOTO_STATIC
#elif defined LIBRAGEPHOTO_C_ONLY
#include "RagePhotoA.hpp"
typedef RagePhotoA RagePhotoB;
#else
#error "Could not determine best RagePhoto implementation, libragephoto installation might be corrupt!"
#endif // LIBRAGEPHOTO_CXX_ONLY
#endif // __cplusplus
#endif // RAGEPHOTOB_HPP

View file

@ -1,316 +0,0 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021-2023 Syping
*
* 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 RAGEPHOTOC_H
#define RAGEPHOTOC_H
#include "RagePhotoLibrary.h"
#include "RagePhotoTypedefs.h"
#include <stddef.h>
#include <stdint.h>
#ifdef LIBRAGEPHOTO_C_NOAPI
#error "libragephoto was built without C API"
#endif // LIBRAGEPHOTO_C_NOAPI
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/** C API for RagePhoto.
* \file RagePhotoC.h
*/
/** RagePhoto C++ class typedef for C API. */
typedef void* ragephoto_t;
/** Opens a \p ragephoto_t instance. */
LIBRAGEPHOTO_C_BINDING ragephoto_t ragephoto_open();
/** Add a custom defined RagePhotoFormatParser.
* \param instance \p ragephoto_t instance
* \param rp_parser RagePhotoFormatParser parser to add
*/
LIBRAGEPHOTO_C_BINDING void ragephoto_addparser(ragephoto_t instance, RagePhotoFormatParser *rp_parser);
/** Resets the RagePhotoData object to default values.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING void ragephoto_clear(ragephoto_t instance);
/** Resets the RagePhotoData object to default values.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_BINDING void ragephotodata_clear(RagePhotoData *rp_data);
/** Loads a Photo from a const char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param size Photo data size
*/
LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_load(ragephoto_t instance, const char *data, size_t size);
/** Loads a Photo from a const char*.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
* \param data Photo data
* \param size Photo data size
*/
LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t size);
/** Loads a Photo from a file.
* \param instance \p ragephoto_t instance
* \param filename File to load
*/
LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_loadfile(ragephoto_t instance, const char *filename);
/** Returns the last error occurred.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING int32_t ragephoto_error(ragephoto_t instance);
/** Returns the GTA V default Photo Buffer Size. */
LIBRAGEPHOTO_C_BINDING uint32_t ragephoto_defpbuf_gta5();
/** Returns the RDR 2 default Photo Buffer Size. */
LIBRAGEPHOTO_C_BINDING uint32_t ragephoto_defpbuf_rdr2();
/** Returns the GTA V Photo Format. */
LIBRAGEPHOTO_C_BINDING uint32_t ragephoto_format_gta5();
/** Returns the RDR 2 Photo Format. */
LIBRAGEPHOTO_C_BINDING uint32_t ragephoto_format_rdr2();
/** Returns the internal RagePhotoData object.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING RagePhotoData* ragephoto_getphotodata(ragephoto_t instance);
/** Returns the Photo description.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING const char* ragephoto_getphotodesc(ragephoto_t instance);
/** Returns the Photo Format (GTA V or RDR 2).
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING uint32_t ragephoto_getphotoformat(ragephoto_t instance);
/** Returns the Photo JPEG data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING const char* ragephoto_getphotojpeg(ragephoto_t instance);
/** Returns the Photo JSON data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING const char* ragephoto_getphotojson(ragephoto_t instance);
/** Returns the Photo header.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING const char* ragephoto_getphotoheader(ragephoto_t instance);
/** Returns the Photo JPEG sign.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING uint64_t ragephoto_getphotosign(ragephoto_t instance);
/** Returns the Photo JPEG sign.
* \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_BINDING uint64_t ragephoto_getphotosignf(ragephoto_t instance, uint32_t photoFormat);
/** Returns the Photo JPEG sign.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_BINDING uint64_t ragephotodata_getphotosign(RagePhotoData *rp_data);
/** Returns the Photo JPEG sign.
* \param rp_data RagePhotoData object
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_BINDING uint64_t ragephotodata_getphotosignf(RagePhotoData *rp_data, uint32_t photoFormat);
/** Returns the Photo JPEG data size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING uint32_t ragephoto_getphotosize(ragephoto_t instance);
/** Returns the Photo title.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING const char* ragephoto_getphototitle(ragephoto_t instance);
/** Returns the Photo save file size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING size_t ragephoto_getsavesize(ragephoto_t instance);
/** Returns the Photo save file size.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
*/
LIBRAGEPHOTO_C_BINDING size_t ragephotodata_getsavesize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
/** Returns the Photo save file size.
* \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_BINDING size_t ragephoto_getsavesizef(ragephoto_t instance, uint32_t photoFormat);
/** Returns the Photo save file size.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_BINDING size_t ragephotodata_getsavesizef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, uint32_t photoFormat);
/** Saves a Photo to a char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
*/
LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_save(ragephoto_t instance, char *data);
/** Saves a Photo to a char*.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
* \param data Photo data
*/
LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephotodata_save(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data);
/** Saves a Photo to a char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat);
/** Saves a Photo to a char*.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephotodata_savef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data, uint32_t photoFormat);
/** Saves a Photo to a file.
* \param instance \p ragephoto_t instance
* \param filename File to save
*/
LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_savefile(ragephoto_t instance, const char *filename);
/** Saves a Photo to a file.
* \param instance \p ragephoto_t instance
* \param filename File to save
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat);
/** Sets all cross-format Buffer to default size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING void ragephoto_setbufferdefault(ragephoto_t instance);
/** Sets all cross-format Buffer to default size.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_BINDING void ragephotodata_setbufferdefault(RagePhotoData *rp_data);
/** Moves all Buffer offsets to correct position.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING void ragephoto_setbufferoffsets(ragephoto_t instance);
/** Moves all Buffer offsets to correct position.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_BINDING void ragephotodata_setbufferoffsets(RagePhotoData *rp_data);
/** Sets the internal RagePhotoData object.
* \param instance \p ragephoto_t instance
* \param rp_data RagePhotoData object being set
*/
LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_setphotodata(ragephoto_t instance, RagePhotoData *rp_data);
/** Copies RagePhotoData object to internal RagePhotoData object.
* \param instance \p ragephoto_t instance
* \param rp_data RagePhotoData object being copied
*/
LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_setphotodatac(ragephoto_t instance, RagePhotoData *rp_data);
/** Sets the Photo description.
* \param instance \p ragephoto_t instance
* \param description Description
* \param bufferSize Description buffer size
*
* Default bufferSize: 256UL
*/
LIBRAGEPHOTO_C_BINDING void ragephoto_setphotodesc(ragephoto_t instance, const char *description, uint32_t bufferSize);
/** Sets the Photo Format (GTA V or RDR 2).
* \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_BINDING void ragephoto_setphotoformat(ragephoto_t instance, uint32_t photoFormat);
/** Sets the Photo JPEG data.
* \param instance \p ragephoto_t instance
* \param data JPEG data
* \param size JPEG data size
* \param bufferSize JPEG buffer size
*
* Default bufferSize: ragephoto_defpbuf_gta5() or ragephoto_defpbuf_rdr2()
*/
LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize);
/** Sets the Photo JSON data.
* \param instance \p ragephoto_t instance
* \param json JSON data
* \param bufferSize JSON data buffer size
*
* Default bufferSize: 3072UL
*/
LIBRAGEPHOTO_C_BINDING void ragephoto_setphotojson(ragephoto_t instance, const char *json, uint32_t bufferSize);
/** Sets the Photo header. (EXPERT ONLY) */
LIBRAGEPHOTO_C_BINDING void ragephoto_setphotoheader(ragephoto_t instance, const char *header, uint32_t headerSum);
/** Sets the Photo title.
* \param instance \p ragephoto_t instance
* \param title Title
* \param bufferSize Title buffer size
*
* Default bufferSize: 256UL
*/
LIBRAGEPHOTO_C_BINDING void ragephoto_setphototitle(ragephoto_t instance, const char *title, uint32_t bufferSize);
/** Closes a \p ragephoto_t instance.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING void ragephoto_close(ragephoto_t instance);
/** Returns the library version. */
LIBRAGEPHOTO_C_BINDING const char* ragephoto_version();
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // RAGEPHOTOC_H

View file

@ -25,35 +25,45 @@
#ifdef _WIN32
#ifndef LIBRAGEPHOTO_STATIC
#ifdef LIBRAGEPHOTO_LIBRARY
#define LIBRAGEPHOTO_C_BINDING __declspec(dllexport)
#define LIBRAGEPHOTO_CXX_BINDING __declspec(dllexport)
#define LIBRAGEPHOTO_C_PUBLIC __declspec(dllexport)
#define LIBRAGEPHOTO_CXX_PUBLIC __declspec(dllexport)
#else
#define LIBRAGEPHOTO_C_BINDING __declspec(dllimport)
#define LIBRAGEPHOTO_CXX_BINDING __declspec(dllimport)
#define LIBRAGEPHOTO_C_PUBLIC __declspec(dllimport)
#define LIBRAGEPHOTO_CXX_PUBLIC __declspec(dllimport)
#endif // LIBRAGEPHOTO_LIBRARY
#else
#define LIBRAGEPHOTO_C_BINDING
#define LIBRAGEPHOTO_CXX_BINDING
#define LIBRAGEPHOTO_C_PUBLIC
#define LIBRAGEPHOTO_CXX_PUBLIC
#endif // LIBRAGEPHOTO_STATIC
#else
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#define LIBRAGEPHOTO_C_BINDING EMSCRIPTEN_KEEPALIVE
#define LIBRAGEPHOTO_CXX_BINDING
#define LIBRAGEPHOTO_C_PUBLIC EMSCRIPTEN_KEEPALIVE
#define LIBRAGEPHOTO_CXX_PUBLIC
#else
#define LIBRAGEPHOTO_C_BINDING
#define LIBRAGEPHOTO_CXX_BINDING
#ifdef __GNUC__
#ifndef LIBRAGEPHOTO_STATIC
#define LIBRAGEPHOTO_C_PUBLIC __attribute__((visibility("default")))
#define LIBRAGEPHOTO_CXX_PUBLIC __attribute__((visibility("default")))
#else
#define LIBRAGEPHOTO_C_PUBLIC
#define LIBRAGEPHOTO_CXX_PUBLIC
#endif // LIBRAGEPHOTO_STATIC
#else
#define LIBRAGEPHOTO_C_PUBLIC
#define LIBRAGEPHOTO_CXX_PUBLIC
#endif // __GNUC__
#endif // __EMSCRIPTEN__
#endif // _WIN32
/* RAGEPHOTO LIBRARY BINDING END */
/* ENABLE C API FOR RAGEPHOTO WASM LIBRARY BEGIN */
/* ENABLE C API FOR LIBRAGEPHOTO WASM LIBRARY BEGIN */
#ifdef LIBRAGEPHOTO_WASM
#ifdef RAGEPHOTO_C_NOAPI
#undef RAGEPHOTO_C_NOAPI
#define RAGEPHOTO_C_API
#endif // RAGEPHOTO_C_NOAPI
#ifdef LIBRAGEPHOTO_CXX_ONLY
#undef LIBRAGEPHOTO_CXX_ONLY
#define LIBRAGEPHOTO_CXX_C
#endif // LIBRAGEPHOTO_CXX_ONLY
#endif // LIBRAGEPHOTO_WASM
/* ENABLE C API FOR RAGEPHOTO WASM LIBRARY END */
/* ENABLE C API FOR LIBRAGEPHOTO WASM LIBRARY END */
#endif // RAGEPHOTOLIBRARY_H

View file

@ -19,6 +19,7 @@
#ifndef RAGEPHOTOTYPEDEFS_H
#define RAGEPHOTOTYPEDEFS_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@ -34,32 +35,28 @@ typedef struct RagePhotoData {
char* header; /**< Pointer for internal Header buffer */
char* title; /**< Pointer for internal Title buffer */
int32_t error; /**< RagePhoto error code */
uint32_t descBuffer; /**< Photo Description buffer length */
uint32_t descOffset; /**< Photo Description buffer offset */
uint32_t endOfFile; /**< Photo End Of File offset */
uint32_t headerSum; /**< Photo Checksum of the header */
uint32_t jpegBuffer; /**< Photo JPEG buffer length */
uint32_t descBuffer; /**< Description buffer length */
uint32_t descOffset; /**< Description buffer offset */
uint32_t endOfFile; /**< End Of File offset */
uint32_t headerSum; /**< Checksum of the header 1 */
uint32_t headerSum2; /**< Checksum of the header 2 (RDR 2 only) */
uint32_t jpegBuffer; /**< JPEG buffer length */
uint32_t jpegSize; /**< Internal JPEG buffer length and size of JPEG */
uint32_t jsonBuffer; /**< Photo JSON buffer length */
uint32_t jsonOffset; /**< Photo JSON buffer offset */
uint32_t jsonBuffer; /**< JSON buffer length */
uint32_t jsonOffset; /**< JSON buffer offset */
uint32_t photoFormat; /**< Photo file format magic */
uint32_t titlBuffer; /**< Photo Title buffer length */
uint32_t titlOffset; /**< Photo Title buffer offset */
uint32_t unnamedSum1; /**< 1st unnamed checksum for Red Dead Redemption 2 */
uint32_t unnamedSum2; /**< 2nd unnamed checksum for Red Dead Redemption 2 */
uint32_t titlBuffer; /**< Title buffer length */
uint32_t titlOffset; /**< Title buffer offset */
} RagePhotoData;
/** RagePhoto bool typedef. */
typedef int32_t ragephoto_bool_t;
/** RagePhoto load function typedef. */
typedef ragephoto_bool_t (*ragephoto_loadfunc_t)(RagePhotoData*, const char*, size_t);
typedef bool (*ragephoto_loadfunc_t)(RagePhotoData*, const char*, size_t);
/** RagePhoto save function typedef (char* allocated by caller). */
typedef ragephoto_bool_t (*ragephoto_savefunc_t)(RagePhotoData*, char*, uint32_t);
typedef bool (*ragephoto_savefunc_t)(RagePhotoData*, char*, uint32_t);
/** RagePhoto save function typedef (char* allocated by function). */
typedef ragephoto_bool_t (*ragephoto_savepfunc_t)(RagePhotoData*, char**, uint32_t);
typedef bool (*ragephoto_savepfunc_t)(RagePhotoData*, char**, uint32_t);
/** RagePhoto saveSize function typedef. */
typedef size_t (*ragephoto_saveszfunc_t)(RagePhotoData*, uint32_t);
@ -73,6 +70,72 @@ typedef struct RagePhotoFormatParser {
ragephoto_saveszfunc_t funcSaveSz; /**< Pointer to saveSize function */
} RagePhotoFormatParser;
/** RagePhoto instance struct for storing data and format parser pointer. */
typedef struct RagePhotoInstance {
RagePhotoData *data; /**< Pointer for data */
RagePhotoFormatParser *parser; /**< Pointer for format parser */
} RagePhotoInstance;
/* RagePhoto default sizes */
#define RAGEPHOTO_DEFAULT_GTA5_PHOTOBUFFER 524288UL /**< GTA V default Photo Buffer Size */
#define RAGEPHOTO_DEFAULT_RDR2_PHOTOBUFFER 1048576UL /**< RDR 2 default Photo Buffer Size */
#define RAGEPHOTO_DEFAULT_DESCBUFFER 256UL /**< Default Description Buffer Size */
#define RAGEPHOTO_DEFAULT_JSONBUFFER 3072UL /**< Default JSON Buffer Size */
#define RAGEPHOTO_DEFAULT_TITLBUFFER 256UL /**< Default Title Buffer Size */
#define RAGEPHOTO_GTA5_HEADERSIZE 264UL /**< GTA V Header Size */
#define RAGEPHOTO_RDR2_HEADERSIZE 272UL /**< RDR 2 Header Size */
/* RagePhoto error codes */
#define RAGEPHOTO_ERROR_DESCBUFFERTIGHT 39L /**< Description Buffer is too tight */
#define RAGEPHOTO_ERROR_DESCMALLOCERROR 31L /**< Description Buffer can't be allocated */
#define RAGEPHOTO_ERROR_DESCREADERROR 32L /**< Description can't be read successfully */
#define RAGEPHOTO_ERROR_HEADERBUFFERTIGHT 35L /**< Header Buffer is too tight */
#define RAGEPHOTO_ERROR_HEADERMALLOCERROR 4L /**< Header Buffer can't be allocated */
#define RAGEPHOTO_ERROR_INCOMPATIBLEFORMAT 2L /**< Format is incompatible */
#define RAGEPHOTO_ERROR_INCOMPLETECHECKSUM 7L /**< Header checksum is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEDESCBUFFER 30L /**< Description Buffer Size is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEDESCMARKER 28L /**< Description Marker is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEDESCOFFSET 11L /**< Description Offset is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEEOF 8L /**< End Of File Offset is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEHEADER 3L /**< Header is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEJENDMARKER 33L /**< JEND Marker is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEJPEGMARKER 12L /**< JPEG Marker is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEJSONBUFFER 20L /**< JSON Buffer Size is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEJSONMARKER 18L /**< JSON Marker incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEJSONOFFSET 9L /**< JSON Offset incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEPHOTOBUFFER 14L /**< Photo Buffer Size is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEPHOTOSIZE 15L /**< Photo Size is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETETITLEBUFFER 25L /**< Title Buffer Size is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETETITLEMARKER 23L /**< Title Marker is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETETITLEOFFSET 10L /**< Title Offset is incomplete */
#define RAGEPHOTO_ERROR_INCORRECTDESCMARKER 29L /**< Description Marker is incorrect */
#define RAGEPHOTO_ERROR_INCORRECTJENDMARKER 34L /**< JEND Marker is incorrect */
#define RAGEPHOTO_ERROR_INCORRECTJPEGMARKER 13L /**< JPEG Marker is incorrect */
#define RAGEPHOTO_ERROR_INCORRECTJSONMARKER 19L /**< JSON Marker is incorrect */
#define RAGEPHOTO_ERROR_INCORRECTTITLEMARKER 24L /**< Title Marker is incorrect */
#define RAGEPHOTO_ERROR_JSONBUFFERTIGHT 37L /**< JSON Buffer is too tight */
#define RAGEPHOTO_ERROR_JSONMALLOCERROR 21L /**< JSON Buffer can't be allocated */
#define RAGEPHOTO_ERROR_JSONREADERROR 22L /**< JSON can't be read successfully */
#define RAGEPHOTO_ERROR_NOERROR 255L /**< Finished without errors */
#define RAGEPHOTO_ERROR_NOFORMATIDENTIFIER 1L /**< No format detected, empty file */
#define RAGEPHOTO_ERROR_PHOTOBUFFERTIGHT 36L /**< Photo Buffer is too tight */
#define RAGEPHOTO_ERROR_PHOTOMALLOCERROR 16L /**< Photo Buffer can't be allocated */
#define RAGEPHOTO_ERROR_PHOTOREADERROR 17L /**< Photo can't be read */
#define RAGEPHOTO_ERROR_TITLEBUFFERTIGHT 38L /**< Title Buffer is too tight */
#define RAGEPHOTO_ERROR_TITLEMALLOCERROR 26L /**< Title Buffer can't be allocated */
#define RAGEPHOTO_ERROR_TITLEREADERROR 27L /**< Title can't be read */
#define RAGEPHOTO_ERROR_UNICODEINITERROR 5L /**< Failed to initialise Unicode decoder */
#define RAGEPHOTO_ERROR_UNICODEHEADERERROR 6L /**< Header can't be encoded/decoded successfully */
#define RAGEPHOTO_ERROR_UNINITIALISED 0L /**< Uninitialised, file access failed */
/* RagePhoto formats */
#define RAGEPHOTO_FORMAT_GTA5 0x01000000UL /**< GTA V Photo Format */
#define RAGEPHOTO_FORMAT_RDR2 0x04000000UL /**< RDR 2 Photo Format */
/* RagePhoto sign initials */
#define RAGEPHOTO_SIGNINITIAL_GTA5 0xE47AB81CUL /**< GTA V Sign Initial */
#define RAGEPHOTO_SIGNINITIAL_RDR2 0x00FEEB1EUL /**< RDR 2 Sign Initial */
#ifdef __cplusplus
}
#endif // __cplusplus