diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/common/zbic_compression.cpp | 46 | ||||
| -rw-r--r-- | src/common/zbic_compression.h | 15 |
3 files changed, 67 insertions, 0 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 0517f0b9e1..5d1b30a549 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -137,6 +137,8 @@ add_library( uuid.cpp uuid.h vector_math.h + zbic_compression.cpp + zbic_compression.h zstd_compression.cpp zstd_compression.h fs/ryujinx_compat.h fs/ryujinx_compat.cpp @@ -147,6 +149,10 @@ add_library( net/net.h net/net.cpp container/unordered_map.h container/unordered_set.h) +set_source_files_properties(zbic_compression.cpp PROPERTIES + INCLUDE_DIRECTORIES "${ZBIC_INCLUDE_DIR}" + COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:Clang,GNU>:-Wno-unused-function;-Wno-missing-declarations;-Wno-shadow>") + if(WIN32) target_sources(common PRIVATE windows/timer_resolution.cpp windows/timer_resolution.h) diff --git a/src/common/zbic_compression.cpp b/src/common/zbic_compression.cpp new file mode 100644 index 0000000000..5e0e4d947b --- /dev/null +++ b/src/common/zbic_compression.cpp @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#include <cstring> + +#include "common/zbic_compression.h" + +#define ZSTD_ZBIC_SUPPORT 1 +#define ZSTDLIB_VISIBLE static +#define ZSTDLIB_HIDDEN static +#define ZSTDERRORLIB_VISIBLE static +#define ZSTDERRORLIB_HIDDEN static +#undef ZSTD_MULTITHREAD + +#if defined(__ANDROID__) +#undef _GNU_SOURCE +#endif + +#include "zstd.h" +#define g_ZSTD_threading_useless_symbol g_ZSTD_zbic_threading_useless_symbol +#include "zstd.c" +#undef g_ZSTD_threading_useless_symbol + +namespace Common::Compression { + +bool IsZBIC(std::span<const u8> src) { + if (src.size() < sizeof(u32)) { + return false; + } + u32 magic = 0; + std::memcpy(&magic, src.data(), sizeof(u32)); + return magic == ZSTD_MAGICNUMBER; // 0x4349425A ("ZBIC") +} + +int DecompressDataZBIC(std::span<u8> dst, std::span<const u8> src) { + if (dst.empty() || src.empty()) { + return -1; + } + const size_t res = ZSTD_decompress(dst.data(), dst.size(), src.data(), src.size()); + if (ZSTD_isError(res)) { + return -1; + } + return static_cast<int>(res); +} + +} // namespace Common::Compression diff --git a/src/common/zbic_compression.h b/src/common/zbic_compression.h new file mode 100644 index 0000000000..c36a559388 --- /dev/null +++ b/src/common/zbic_compression.h @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include <span> +#include "common/common_types.h" + +namespace Common::Compression { + +[[nodiscard]] bool IsZBIC(std::span<const u8> src); + +[[nodiscard]] int DecompressDataZBIC(std::span<u8> dst, std::span<const u8> src); + +} // namespace Common::Compression |
