Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "ext/minizip-ng"]
path = ext/minizip-ng
url = https://github.com/zlib-ng/minizip-ng
[submodule "ext/hat-trie"]
path = ext/hat-trie
url = https://github.com/Tessil/hat-trie
20 changes: 10 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ endif()


# Add libraries
add_sourcepp_library(bsppp NO_TEST)
add_sourcepp_library(dmxpp)
add_sourcepp_library(fgdpp)
add_sourcepp_library(gamepp)
add_sourcepp_library(kvpp)
add_sourcepp_library(mdlpp)
add_sourcepp_library(steampp C)
add_sourcepp_library(vicepp C CSHARP)
add_sourcepp_library(vpkpp C CSHARP NO_TEST)
add_sourcepp_library(vtfpp)
add_sourcepp_library(bsppp NO_TEST) # sourcepp::bsppp
add_sourcepp_library(dmxpp) # sourcepp::dmxpp
add_sourcepp_library(fgdpp) # sourcepp::fgdpp
add_sourcepp_library(gamepp) # sourcepp::gamepp
add_sourcepp_library(kvpp) # sourcepp::kvpp
add_sourcepp_library(mdlpp) # sourcepp::mdlpp
add_sourcepp_library(steampp C) # sourcepp::steampp
add_sourcepp_library(vicepp C CSHARP) # sourcepp::vicepp
add_sourcepp_library(vpkpp C CSHARP NO_TEST) # sourcepp::vpkpp
add_sourcepp_library(vtfpp) # sourcepp::vtfpp


# Tests, part 2
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ Several modern C++20 libraries for sanely parsing Valve formats, rolled into one
<li>FPX v10 (Tactical Intervention)</li>
<li><a href="https://developer.valvesoftware.com/wiki/GCF_archive">GCF</a> v6</li>
<li>GMA v1-3 (Garry's Mod)</li>
<li>GRP (Build Engine)</li>
<li><a href="https://quakewiki.org/wiki/.pak">PAK</a> (Quake, WON Half-Life)</li>
<li><a href="https://docs.godotengine.org/en/stable/tutorials/export/exporting_pcks.html">PCK</a> v1-2 (Godot Engine)</li>
<li><a href="https://developer.valvesoftware.com/wiki/VPK">VPK</a> v1-2</li>
Expand Down
5 changes: 4 additions & 1 deletion cmake/AddPrettyParser.cmake
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
# Add a new parser library
function(add_pretty_parser TARGET)
cmake_parse_arguments(PARSE_ARGV 1 OPTIONS "C" "" "DEPS;PRECOMPILED_HEADERS;SOURCES")
cmake_parse_arguments(PARSE_ARGV 1 OPTIONS "C" "" "DEPS;DEPS_INTERFACE;PRECOMPILED_HEADERS;SOURCES")

if(OPTIONS_C)
add_library(${TARGET}c SHARED ${${PROJECT_NAME}c_SOURCES} ${OPTIONS_PRECOMPILED_HEADERS} ${OPTIONS_SOURCES})
add_library(sourcepp::${TARGET}c ALIAS ${TARGET}c)
set_target_properties(${TARGET}c PROPERTIES PREFIX "")
target_link_libraries(${TARGET}c PRIVATE ${TARGET})
target_include_directories(${TARGET}c PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include")
set(TARGET "${TARGET}c")
else()
add_library(${TARGET} STATIC ${OPTIONS_PRECOMPILED_HEADERS} ${OPTIONS_SOURCES})
add_library(sourcepp::${TARGET} ALIAS ${TARGET})
endif()
if(NOT ("PRECOMPILED_HEADERS" IN_LIST OPTIONS_UNPARSED_ARGUMENTS))
target_precompile_headers(${TARGET} PUBLIC ${OPTIONS_HEADERS})
endif()
target_link_libraries(${TARGET} PUBLIC ${PROJECT_NAME})
target_link_libraries(${TARGET} PRIVATE ${OPTIONS_DEPS})
target_link_libraries(${TARGET} INTERFACE ${OPTIONS_DEPS_INTERFACE})

# Define DEBUG macro
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:DEBUG>")
Expand Down
6 changes: 6 additions & 0 deletions ext/_ext.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ if(NOT TARGET cryptopp::cryptopp)
endif()


# hat-trie
if(NOT TARGET tsl::hat_trie)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/hat-trie")
endif()


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

Expand Down
1 change: 1 addition & 0 deletions ext/hat-trie
Submodule hat-trie added at 906e6a
2 changes: 1 addition & 1 deletion ext/miniz
39 changes: 39 additions & 0 deletions include/sourcepp/BitwiseEnumClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include <type_traits>

#define SOURCEPP_SETUP_BITWISE_ENUM_CLASS(Enum) \
inline constexpr Enum operator|(Enum lhs, Enum rhs) { \
return static_cast<Enum>( \
static_cast<std::underlying_type_t<Enum>>(lhs) | \
static_cast<std::underlying_type_t<Enum>>(rhs)); \
} \
inline constexpr Enum operator&(Enum lhs, Enum rhs) { \
return static_cast<Enum>( \
static_cast<std::underlying_type_t<Enum>>(lhs) & \
static_cast<std::underlying_type_t<Enum>>(rhs)); \
} \
inline constexpr Enum operator^(Enum lhs, Enum rhs) { \
return static_cast<Enum>( \
static_cast<std::underlying_type_t<Enum>>(lhs) ^ \
static_cast<std::underlying_type_t<Enum>>(rhs)); \
} \
inline constexpr Enum operator~(Enum e) { \
return static_cast<Enum>( \
~static_cast<std::underlying_type_t<Enum>>(e)); \
} \
inline Enum& operator|=(Enum& lhs, Enum rhs) { \
return lhs = static_cast<Enum>( \
static_cast<std::underlying_type_t<Enum>>(lhs) | \
static_cast<std::underlying_type_t<Enum>>(rhs)); \
} \
inline Enum& operator&=(Enum& lhs, Enum rhs) { \
return lhs = static_cast<Enum>( \
static_cast<std::underlying_type_t<Enum>>(lhs) & \
static_cast<std::underlying_type_t<Enum>>(rhs)); \
} \
inline Enum& operator^=(Enum& lhs, Enum rhs) { \
return lhs = static_cast<Enum>( \
static_cast<std::underlying_type_t<Enum>>(lhs) ^ \
static_cast<std::underlying_type_t<Enum>>(rhs)); \
}
2 changes: 1 addition & 1 deletion include/sourcepp/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void toUpper(std::string& input);

[[nodiscard]] std::string generateUUIDv4();

[[nodiscard]] std::string padNumber(int number, int width, char pad = '0');
[[nodiscard]] std::string padNumber(int64_t number, int width, char pad = '0');

void normalizeSlashes(std::string& path, bool stripSlashPrefix = false, bool stripSlashSuffix = true);

Expand Down
18 changes: 10 additions & 8 deletions include/vpkpp/Attribute.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#pragma once

#include <sourcepp/BitwiseEnumClass.h>

namespace vpkpp {

enum class Attribute : int {
//PATH, // Not included because its implied
LENGTH = 0,
VPK_PRELOADED_DATA_LENGTH,
ARCHIVE_INDEX,
CRC32,
PCK_MD5,
ATTRIBUTE_COUNT,
enum class Attribute {
NONE = 0,
ARCHIVE_INDEX = 1 << 0,
LENGTH = 1 << 1,
CRC32 = 1 << 2,
PCK_MD5 = 1 << 3,
VPK_PRELOADED_DATA = 1 << 4,
};
SOURCEPP_SETUP_BITWISE_ENUM_CLASS(Attribute)

} // namespace vpkpp
42 changes: 15 additions & 27 deletions include/vpkpp/Entry.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <array>
#include <cstddef>
#include <string>
#include <variant>
Expand All @@ -16,44 +15,33 @@ class Entry {
friend class PackFile;

public:
/// Path to this entry (e.g. "materials/cable.vmt")
std::string path;
/// Format-specific flags (PCK: File flags, VPK: Internal parser state)
uint32_t flags = 0;

/// Which external archive this entry is in.
/// If this file format does not support external archives, this will always be 0
uint32_t archiveIndex = 0;

/// Length in bytes (in formats with compression, this is the uncompressed length)
uint64_t length = 0;
/// Offset, format-specific meaning - may be unused
uint64_t offset = 0;
/// If the format supports compression, this is the compressed length

/// If the format supports compression, this is the compressed length.
/// If compression is not supported or unused, this will remain 0
uint64_t compressedLength = 0;
/// Which external archive this entry is in
/// If this file format does not support external archives, this will always be 0
uint16_t archiveIndex = 0;

/// Offset, format-specific meaning - 0 if unused, or if the offset genuinely is 0
uint64_t offset = 0;

/// Format-specific (PCK: MD5 hash, VPK: Preloaded data)
std::vector<std::byte> extraData;

/// CRC32 checksum - 0 if unused.
/// Note that for GCF, this is actually an index into a checksum array and NOT a checksum
uint32_t crc32 = 0;

/// Used to check if entry is saved to disk
bool unbaked = false;

/// PCK - Each file has a 16-byte MD5 hash
std::array<std::byte, 16> pck_md5{};

/// VPK - Preloaded data
std::vector<std::byte> vpk_preloadedData;

/// Returns the parent directory's path (e.g. "materials/cable.vmt" -> "materials")
[[nodiscard]] std::string getParentPath() const;

/// Returns the filename (e.g. "materials/cable.vmt" -> "cable.vmt")
[[nodiscard]] std::string getFilename() const;

/// Returns the file stem (e.g. "materials/cable.vmt" -> "cable")
[[nodiscard]] std::string getStem() const;

/// Returns the file extension without a period (e.g. "materials/cable.vmt" -> "vmt")
[[nodiscard]] std::string getExtension() const;

private:
/// The data attached to the unbaked entry, or the path to the file containing the unbaked entry's data
std::variant<std::string, std::vector<std::byte>> unbakedData;
Expand Down
Loading