Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 60 additions & 33 deletions THIRDPARTY_LEGAL_NOTICES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,39 +74,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


--------------- Crypto++ ---------------

BSD 3-Clause "New" or "Revised" License

Copyright (c) 2018, The Authors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* 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.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------- emscripten ---------------

MIT License
Expand Down Expand Up @@ -266,6 +233,66 @@ AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


--------------- libtomcrypt ---------------

The Unlicense

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org>


--------------- libtommath ---------------

The Unlicense

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org>


--------------- libwebp ---------------

BSD 3-Clause "New" or "Revised" License
Expand Down
34 changes: 10 additions & 24 deletions cmake/AddRemoteLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include_guard(GLOBAL)
include(FetchContent)

function(add_sourcepp_remote_library NAME REPOSITORY TAG)
cmake_parse_arguments(PARSE_ARGV 3 OPTIONS "ALLOW_NOT_PINNED;EXCLUDE_FROM_ALL;DO_NOT_USE_CMAKELISTS" "" "")
cmake_parse_arguments(PARSE_ARGV 3 OPTIONS "ALLOW_NOT_PINNED;DO_NOT_USE_CMAKELISTS;EXCLUDE_FROM_ALL;OVERRIDE_FIND_PACKAGE" "" "")
if(NOT OPTIONS_ALLOW_NOT_PINNED)
string(LENGTH "${TAG}" TAG_SIZE)
if(NOT TAG_SIZE EQUAL 40)
Expand All @@ -13,31 +13,17 @@ function(add_sourcepp_remote_library NAME REPOSITORY TAG)
if(NOT TARGET NAME)
message(STATUS "Fetching ${NAME} ${REPOSITORY} ${TAG}")
string(REPLACE ":" "_" NAME_CLEAN "${NAME}")
set(FETCHCONTENT_DECLARE_ARGUMENTS "${NAME_CLEAN}" "GIT_REPOSITORY" "${REPOSITORY}.git" "GIT_TAG" "${TAG}")
if(OPTIONS_DO_NOT_USE_CMAKELISTS)
list(APPEND FETCHCONTENT_DECLARE_ARGUMENTS "SOURCE_SUBDIR" "THIS_DIRECTORY_DOES_NOT_EXIST")
endif()
if(OPTIONS_EXCLUDE_FROM_ALL)
if(OPTIONS_DO_NOT_USE_CMAKELISTS)
FetchContent_Declare(${NAME_CLEAN}
GIT_REPOSITORY "${REPOSITORY}.git"
GIT_TAG "${TAG}"
SOURCE_SUBDIR "THIS_DIRECTORY_DOES_NOT_EXIST"
EXCLUDE_FROM_ALL)
else()
FetchContent_Declare(${NAME_CLEAN}
GIT_REPOSITORY "${REPOSITORY}.git"
GIT_TAG "${TAG}"
EXCLUDE_FROM_ALL)
endif()
else()
if(OPTIONS_DO_NOT_USE_CMAKELISTS)
FetchContent_Declare(${NAME_CLEAN}
GIT_REPOSITORY "${REPOSITORY}.git"
GIT_TAG "${TAG}"
SOURCE_SUBDIR "THIS_DIRECTORY_DOES_NOT_EXIST")
else()
FetchContent_Declare(${NAME_CLEAN}
GIT_REPOSITORY "${REPOSITORY}.git"
GIT_TAG "${TAG}")
endif()
list(APPEND FETCHCONTENT_DECLARE_ARGUMENTS "EXCLUDE_FROM_ALL")
endif()
if(OPTIONS_OVERRIDE_FIND_PACKAGE)
list(APPEND FETCHCONTENT_DECLARE_ARGUMENTS "OVERRIDE_FIND_PACKAGE")
endif()
FetchContent_Declare(${FETCHCONTENT_DECLARE_ARGUMENTS})
FetchContent_MakeAvailable(${NAME_CLEAN})
endif()
return(PROPAGATE "${NAME_CLEAN}_POPULATED" "${NAME_CLEAN}_SOURCE_DIR" "${NAME_CLEAN}_BINARY_DIR")
Expand Down
114 changes: 63 additions & 51 deletions ext/_ext.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Threads
if(SOURCEPP_BUILD_WITH_THREADS)
set(CMAKE_THREAD_PREFER_PTHREAD ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
if(NOT Threads_FOUND)
set(SOURCEPP_BUILD_WITH_THREADS OFF CACHE INTERNAL "" FORCE)
endif()
endif()

function(sourcepp_add_threads TARGET)
if(SOURCEPP_BUILD_WITH_THREADS)
target_compile_definitions(${TARGET} PUBLIC SOURCEPP_BUILD_WITH_THREADS)
target_link_libraries(${TARGET} PRIVATE Threads::Threads)
endif()
endfunction()


# bcdec
if(SOURCEPP_USE_VTFPP)
add_sourcepp_remote_library(bcdec https://github.com/craftablescience/bcdec 59441e17ba36b7d7eef336aeedc62e01d0cdcd5a)
Expand All @@ -14,19 +32,6 @@ if(SOURCEPP_USE_VTFPP AND SOURCEPP_VTFPP_BUILD_WITH_COMPRESSONATOR)
endif()


# cryptopp
if(NOT TARGET cryptopp::cryptopp)
set(CRYPTOPP_BUILD_TESTING OFF CACHE INTERNAL "" FORCE)
set(CRYPTOPP_INSTALL OFF CACHE INTERNAL "" FORCE)
add_sourcepp_remote_library(cryptopp-cmake https://github.com/abdes/cryptopp-cmake 866aceb8b13b6427a3c4541288ff412ad54f11ea)

# hack: clang on windows (NOT clang-cl) needs these to compile cryptopp
if(WIN32 AND NOT MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(cryptopp PRIVATE -mcrc32 -mssse3)
endif()
endif()


# half
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/half")

Expand All @@ -43,6 +48,51 @@ if(SOURCEPP_USE_VCRYPTPP)
endif()


# libtommath
if(NOT TARGET libtommath)
add_sourcepp_remote_library(libtommath https://github.com/libtom/libtommath ae40a87a920099a7d9d00979570e0c8d917a1fd7 OVERRIDE_FIND_PACKAGE)

# hack: always compile with optimizations on MSVC because this library stinks
if(WIN32 AND MSVC)
get_target_property(libtommath_CURRENT_FLAGS libtommath COMPILE_FLAGS)
if(libtommath_CURRENT_FLAGS)
list(REMOVE_ITEM libtommath_CURRENT_OPTIONS "/RTC1")
list(APPEND libtommath_CURRENT_OPTIONS "/O2")
set_target_properties(libtommath PROPERTIES COMPILE_FLAGS "${libtommath_CURRENT_FLAGS}")
endif()
endif()
endif()


# libtomcrypt
if(NOT TARGET libtomcrypt)
if(SOURCEPP_BUILD_WITH_THREADS AND CMAKE_USE_PTHREADS_INIT)
set(WITH_PTHREAD ON CACHE INTERNAL "" FORCE)
endif()
add_sourcepp_remote_library(libtomcrypt https://github.com/libtom/libtomcrypt c80285ba04f87ee5359baf689ccc7ce8a31116dc)
endif()


# libwebp
if(SOURCEPP_USE_VTFPP AND SOURCEPP_VTFPP_SUPPORT_WEBP)
set(WEBP_BUILD_ANIM_UTILS OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_CWEBP OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_DWEBP OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_GIF2WEBP OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_IMG2WEBP OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_VWEBP OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_WEBPINFO OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_LIBWEBPMUX OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_WEBPMUX OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_EXTRAS OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_WEBP_JS OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_FUZZTEST OFF CACHE INTERNAL "" FORCE)
set(WEBP_USE_THREAD ${SOURCEPP_BUILD_WITH_THREADS} CACHE INTERNAL "" FORCE)
set(WEBP_NEAR_LOSSLESS ON CACHE INTERNAL "" FORCE)
add_sourcepp_remote_library(libwebp https://github.com/webmproject/libwebp 5003e5609eedc5680b8d838a962cbb9a6e9709ce EXCLUDE_FROM_ALL)
endif()


# miniz
if(SOURCEPP_USE_VPKPP OR SOURCEPP_USE_VTFPP)
add_sourcepp_remote_library(miniz https://github.com/richgel999/miniz 5cf1e56a9c968c11fdd1a6414f3a95f84314c437)
Expand Down Expand Up @@ -116,41 +166,3 @@ function(sourcepp_add_tbb TARGET)
endif()
endif()
endfunction()


# Threads
if(SOURCEPP_BUILD_WITH_THREADS)
set(CMAKE_THREAD_PREFER_PTHREAD ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
if(NOT Threads_FOUND)
set(SOURCEPP_BUILD_WITH_THREADS OFF CACHE INTERNAL "" FORCE)
endif()
endif()

function(sourcepp_add_threads TARGET)
if(SOURCEPP_BUILD_WITH_THREADS)
target_compile_definitions(${TARGET} PUBLIC SOURCEPP_BUILD_WITH_THREADS)
target_link_libraries(${TARGET} PRIVATE Threads::Threads)
endif()
endfunction()


# webp
if(SOURCEPP_USE_VTFPP AND SOURCEPP_VTFPP_SUPPORT_WEBP)
set(WEBP_BUILD_ANIM_UTILS OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_CWEBP OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_DWEBP OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_GIF2WEBP OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_IMG2WEBP OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_VWEBP OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_WEBPINFO OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_LIBWEBPMUX OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_WEBPMUX OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_EXTRAS OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_WEBP_JS OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_FUZZTEST OFF CACHE INTERNAL "" FORCE)
set(WEBP_USE_THREAD ${SOURCEPP_BUILD_WITH_THREADS} CACHE INTERNAL "" FORCE)
set(WEBP_NEAR_LOSSLESS ON CACHE INTERNAL "" FORCE)
add_sourcepp_remote_library(webp https://github.com/webmproject/libwebp 5003e5609eedc5680b8d838a962cbb9a6e9709ce EXCLUDE_FROM_ALL)
endif()
6 changes: 6 additions & 0 deletions include/sourcepp/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <charconv>
#include <concepts>
#include <cstddef>
#include <span>
#include <string>
#include <string_view>
#include <vector>
Expand Down Expand Up @@ -92,4 +94,8 @@ std::from_chars_result toFloat(std::string_view number, std::floating_point auto
#endif
}

[[nodiscard]] std::vector<std::byte> decodeHex(std::string_view hex);

[[nodiscard]] std::string encodeHex(std::span<const std::byte> hex);

} // namespace sourcepp::string
17 changes: 17 additions & 0 deletions include/sourcepp/crypto/AES.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <cstddef>
#include <span>
#include <vector>

#include <sourcepp/Math.h>

namespace sourcepp::crypto {

extern const std::array<std::byte, 16> NULL_IV;

bool decryptAES_CFB(std::span<std::byte> buffer, std::span<const std::byte> key, std::span<const std::byte> iv = NULL_IV);

bool encryptAES_CFB(std::span<std::byte> buffer, std::span<const std::byte> key, std::span<const std::byte> iv = NULL_IV);

} // namespace sourcepp::crypto
11 changes: 11 additions & 0 deletions include/sourcepp/crypto/Globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

namespace sourcepp::crypto {

extern const bool LTM_MATH;

extern const int AES_INDEX;
extern const int SHA256_INDEX;
extern const int YARROW_INDEX;

} // namespace sourcepp::crypto
12 changes: 12 additions & 0 deletions include/sourcepp/crypto/SHA256.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <cstddef>
#include <span>

#include <sourcepp/Math.h>

namespace sourcepp::crypto {

std::array<std::byte, 32> computeSHA256(std::span<const std::byte> buffer);

} // namespace sourcepp::crypto
15 changes: 0 additions & 15 deletions include/sourcepp/crypto/String.h

This file was deleted.

4 changes: 2 additions & 2 deletions include/vpkpp/format/GCF.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ class GCF : public PackFileReadOnly {

[[nodiscard]] CompressionType getCompressionType() const {
static constexpr std::array compressionTypeLUT = {
CompressionType::UNCOMPRESSED,
CompressionType::COMPRESSED,
CompressionType::COMPRESSED_AND_ENCRYPTED,
CompressionType::UNCOMPRESSED,
CompressionType::ENCRYPTED,
};
const auto idx = (static_cast<std::uint8_t>(flags) & 7) - 1;
if (idx <= 3) {
if (const uint16_t idx = this->flags & 0x111; idx < compressionTypeLUT.size()) {
return compressionTypeLUT[idx];
}
return CompressionType::UNCOMPRESSED;
Expand Down
Loading
Loading