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
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ The Python wrappers can be found on PyPI in the [sourcepp](https://pypi.org/proj
</tr>
<tr><!-- empty row to disable GitHub striped bg color --></tr>
<tr>
<td rowspan="33"><code>vpkpp</code></td>
<td rowspan="35"><code>vpkpp</code></td>
<td>007 v1.1, v1.3 (007 - Nightfire)</td>
<td align="center">✅</td>
<td align="center">❌</td>
<td rowspan="33" align="center">C<br>C#<br>Python</td>
<td rowspan="35" align="center">C<br>C#<br>Python</td>
</tr>
<tr><!-- empty row to disable GitHub striped bg color --></tr>
<tr>
Expand Down Expand Up @@ -259,6 +259,12 @@ The Python wrappers can be found on PyPI in the [sourcepp](https://pypi.org/proj
<td align="center">✅</td>
</tr>
<tr><!-- empty row to disable GitHub striped bg color --></tr>
<tr>
<td>TAB v3 (Avalanche Engine)</td>
<td align="center">✅</td>
<td align="center">❌</td>
</tr>
<tr><!-- empty row to disable GitHub striped bg color --></tr>
<tr>
<td>
<a href="https://developer.valvesoftware.com/wiki/VPK" target="_blank" rel="noreferrer">VPK</a> pre-v1, v1-2, v54
Expand Down
7 changes: 6 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ <h2>Supported Formats</h2>
<td>✅</td>
</tr>
<tr class="support-table-no-offset">
<td rowspan="17">
<td rowspan="18">
vpkpp
<ul>
<li>C</li>
Expand Down Expand Up @@ -683,6 +683,11 @@ <h2>Supported Formats</h2>
<td>✅</td>
<td>✅</td>
</tr>
<tr>
<td>TAB v3 (Avalanche Engine)</td>
<td>✅</td>
<td>❌</td>
</tr>
<tr>
<td>
<a href="https://developer.valvesoftware.com/wiki/VPK" target="_blank" rel="noreferrer">VPK</a> pre-v1, v1-2, v54
Expand Down
13 changes: 13 additions & 0 deletions include/sourcepp/crypto/SHA1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <array>
#include <cstddef>
#include <span>

#include <sourcepp/Math.h>

namespace sourcepp::crypto {

std::array<std::byte, 20> computeSHA1(std::span<const std::byte> buffer);

} // namespace sourcepp::crypto
45 changes: 45 additions & 0 deletions include/vpkpp/format/TAB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// ReSharper disable CppRedundantQualifier

#pragma once

#include <sourcepp/parser/Binary.h>

#include "../PackFile.h"

namespace vpkpp {

constexpr std::string_view TAB_EXTENSION = ".tab";

constexpr auto TAB_FILENAME_MAX_SIZE = 128;
constexpr std::string_view TAB_HASHED_FILEPATH_PREFIX = "__hashed__/";

constexpr std::string_view ARC_EXTENSION = ".arc";

/// Chunk size in bytes (1gb)
constexpr uint32_t ARC_CHUNK_SIZE = 1024 * 1024 * 1024;

class TAB : public PackFileReadOnly {
public:
/// Open a TAB file
[[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);

[[nodiscard]] std::optional<std::vector<std::byte>> readEntry(const std::string& path_) const override;

[[nodiscard]] Attribute getSupportedEntryAttributes() const override;

[[nodiscard]] explicit operator std::string() const override;

[[nodiscard]] static uint32_t hashFilePath(const std::string& filepath);

protected:
using PackFileReadOnly::PackFileReadOnly;

uint32_t version = 0;
uint32_t sectorSize = 0;
uint32_t numArchives = 0;

private:
VPKPP_REGISTER_PACKFILE_OPEN(TAB_EXTENSION, &TAB::open);
};

} // namespace vpkpp
1 change: 1 addition & 0 deletions include/vpkpp/vpkpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "format/ORE.h"
#include "format/PAK.h"
#include "format/PCK.h"
#include "format/TAB.h"
#include "format/VPK.h"
#include "format/VPK_VTMB.h"
#include "format/VPP.h"
Expand Down
21 changes: 21 additions & 0 deletions lang/c/include/vpkppc/format/TAB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "../PackFile.h"

VPKPP_EXTERNVAR const char* VPKPP_TAB_EXTENSION;

VPKPP_EXTERNVAR const int VPKPP_TAB_FILENAME_MAX_SIZE;
VPKPP_EXTERNVAR const char* VPKPP_TAB_HASHED_FILEPATH_PREFIX;

VPKPP_EXTERNVAR const char* VPKPP_ARC_EXTENSION;
VPKPP_EXTERNVAR const uint32_t VPKPP_ARC_CHUNK_SIZE;

VPKPP_API vpkpp_pack_file_handle_t vpkpp_tab_open(const char* path, vpkpp_entry_callback_t callback); // REQUIRES MANUAL FREE: vpkpp_close
VPKPP_API uint32_t vpkpp_tab_hash_file_path(const char* filepath);

// C++ conversion routines
#ifdef __cplusplus

#include <vpkpp/format/TAB.h>

#endif
1 change: 1 addition & 0 deletions lang/c/include/vpkppc/vpkpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "format/ORE.h"
#include "format/PAK.h"
#include "format/PCK.h"
#include "format/TAB.h"
#include "format/VPK.h"
#include "format/VPK_VTMB.h"
#include "format/WAD3.h"
Expand Down
2 changes: 2 additions & 0 deletions lang/c/src/vpkppc/_vpkppc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_pretty_parser(vpkpp C
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/ORE.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/PAK.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/PCK.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/TAB.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/VPK.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/VPK_VTMB.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/VPP.h"
Expand All @@ -34,6 +35,7 @@ add_pretty_parser(vpkpp C
"${CMAKE_CURRENT_LIST_DIR}/format/ORE.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/PAK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/PCK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/TAB.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/VPK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/VPK_VTMB.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/VPP.cpp"
Expand Down
30 changes: 30 additions & 0 deletions lang/c/src/vpkppc/format/TAB.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <vpkppc/format/TAB.h>

#include <sourceppc/Helpers.h>

using namespace sourceppc;
using namespace vpkpp;

const char* VPKPP_TAB_EXTENSION = TAB_EXTENSION.data();

const int VPKPP_TAB_FILENAME_MAX_SIZE = TAB_FILENAME_MAX_SIZE;
const char* VPKPP_TAB_HASHED_FILEPATH_PREFIX = TAB_HASHED_FILEPATH_PREFIX.data();

const char* VPKPP_ARC_EXTENSION = ARC_EXTENSION.data();
const uint32_t VPKPP_ARC_CHUNK_SIZE = ARC_CHUNK_SIZE;

VPKPP_API vpkpp_pack_file_handle_t vpkpp_tab_open(const char* path, vpkpp_entry_callback_t callback) {
SOURCEPP_EARLY_RETURN_VAL(path, nullptr);

auto packFile = TAB::open(path, callback ? [callback](const std::string& entryPath, const Entry& entry) {
callback(entryPath.c_str(), const_cast<Entry*>(&entry));
} : static_cast<PackFile::EntryCallback>(nullptr));
if (!packFile) {
return nullptr;
}
return packFile.release();
}

VPKPP_API uint32_t vpkpp_tab_hash_file_path(const char* filepath) {
return TAB::hashFilePath(filepath);
}
10 changes: 8 additions & 2 deletions lang/csharp/src/vpkpp/DLL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,16 @@ internal static partial class DLL

[LibraryImport(Name, StringMarshalling = StringMarshalling.Utf8)]
public static partial nint vpkpp_pck_open(string path, EntryCallbackNative? callback);


[LibraryImport(Name, StringMarshalling = StringMarshalling.Utf8)]
public static partial nint vpkpp_tab_open(string path, EntryCallbackNative? callback);

[LibraryImport(Name, StringMarshalling = StringMarshalling.Utf8)]
public static partial uint vpkpp_tab_hash_file_path(string path);

[LibraryImport(Name, StringMarshalling = StringMarshalling.Utf8)]
public static partial nint vpkpp_vpk_create(string path);

[LibraryImport(Name, StringMarshalling = StringMarshalling.Utf8)]
public static partial nint vpkpp_vpk_create_with_options(string path, uint version);

Expand Down
28 changes: 28 additions & 0 deletions lang/csharp/src/vpkpp/Format/TAB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;

namespace sourcepp.vpkpp.Format;

using OpenPropertyRequest = Func<PackFile, OpenProperty, byte[]>;

using EntryCallback = Action<string, Entry>;

public class TAB : PackFile
{
protected TAB(nint handle, bool managed = true) : base(handle, managed)
{
}

public new static TAB? Open(string path, EntryCallback? callback = null, OpenPropertyRequest? _ = null)
{
var handle = DLL.vpkpp_tab_open(path, callback is not null ? (entryPath, entry) =>
{
callback(entryPath, new Entry(entry, false));
} : null);
return handle == nint.Zero ? null : new TAB(handle);
}

public static uint HashFilepath(string path)
{
return DLL.vpkpp_tab_hash_file_path(path);
}
}
10 changes: 10 additions & 0 deletions lang/python/src/vpkpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@ inline void register_python(py::module_& m) {
.def("get_godot_version", &PCK::getGodotVersion)
.def("set_godot_version", &PCK::setGodotVersion, "major"_a = 0, "minor"_a = 0, "patch"_a = 0);

vpkpp.attr("TAB_EXTENSION") = TAB_EXTENSION;
vpkpp.attr("TAB_FILENAME_MAX_SIZE") = TAB_FILENAME_MAX_SIZE;
vpkpp.attr("TAB_HASHED_FILEPATH_PREFIX") = TAB_HASHED_FILEPATH_PREFIX;
vpkpp.attr("ARC_EXTENSION") = ARC_EXTENSION;
vpkpp.attr("ARC_CHUNK_SIZE") = ARC_CHUNK_SIZE;

py::class_<TAB, PackFileReadOnly>(vpkpp, "TAB")
.def_static("open", &TAB::open, "path"_a, "callback"_a = nullptr)
.def_static("hash_filepath", &FGP::hashFilePath);

vpkpp.attr("VPK_SIGNATURE") = VPK_SIGNATURE;
vpkpp.attr("VPK_DIR_INDEX") = VPK_DIR_INDEX;
vpkpp.attr("VPK_ENTRY_TERM") = VPK_ENTRY_TERM;
Expand Down
12 changes: 6 additions & 6 deletions src/sourcepp/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ std::mt19937& getRandomGenerator() {
using namespace sourcepp;

bool string::contains(std::string_view s, char c) {
return std::find(s.begin(), s.end(), c) != s.end();
return std::ranges::find(s, c) != s.end();
}

bool string::matches(std::string_view in, std::string_view search) {
Expand Down Expand Up @@ -67,7 +67,7 @@ bool string::iequals(std::string_view s1, std::string_view s2) {
// https://stackoverflow.com/a/217605

void string::ltrim(std::string& s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](char c) { return !std::isspace(c); }));
s.erase(s.begin(), std::ranges::find_if(s, [](char c) { return !std::isspace(c); }));
}

std::string_view string::ltrim(std::string_view s) {
Expand Down Expand Up @@ -108,7 +108,7 @@ std::string string::trimInternal(std::string_view s) {
}

void string::ltrim(std::string& s, std::string_view chars) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [chars](char c) {
s.erase(s.begin(), std::ranges::find_if(s, [chars](char c) {
return !contains(chars, c);
}));
}
Expand Down Expand Up @@ -165,7 +165,7 @@ std::vector<std::string> string::split(std::string_view s, char delim) {
}

void string::toLower(std::string& input) {
std::transform(input.begin(), input.end(), input.begin(), [](unsigned char c){ return std::tolower(c); });
std::ranges::transform(input, input.begin(), [](unsigned char c){ return std::tolower(c); });
}

std::string string::toLower(std::string_view input) {
Expand All @@ -175,7 +175,7 @@ std::string string::toLower(std::string_view input) {
}

void string::toUpper(std::string& input) {
std::transform(input.begin(), input.end(), input.begin(), [](unsigned char c){ return std::toupper(c); });
std::ranges::transform(input, input.begin(), [](unsigned char c){ return std::toupper(c); });
}

std::string string::toUpper(std::string_view input) {
Expand Down Expand Up @@ -235,7 +235,7 @@ void string::normalizeSlashes(std::string& path, bool stripSlashPrefix, bool str
}

void string::denormalizeSlashes(std::string& path, bool stripSlashPrefix, bool stripSlashSuffix) {
std::replace(path.begin(), path.end(), '/', '\\');
std::ranges::replace(path, '/', '\\');
if (stripSlashPrefix && path.starts_with('\\')) {
path = path.substr(1);
}
Expand Down
21 changes: 21 additions & 0 deletions src/sourcepp/crypto/SHA1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <sourcepp/crypto/SHA1.h>

#include <tomcrypt.h>

#include <sourcepp/crypto/Globals.h>

using namespace sourcepp;

std::array<std::byte, 20> crypto::computeSHA1(std::span<const std::byte> buffer) {
if (!LTM_MATH || buffer.empty()) {
return {};
}

hash_state sha1;
sha1_init(&sha1);
sha1_process(&sha1, reinterpret_cast<const unsigned char*>(buffer.data()), buffer.size());

std::array<std::byte, 20> final{};
sha1_done(&sha1, reinterpret_cast<unsigned char*>(final.data()));
return final;
}
2 changes: 2 additions & 0 deletions src/sourcepp/crypto/_crypto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ list(APPEND ${PROJECT_NAME}_crypto_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/crypto/Globals.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/crypto/MD5.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/crypto/RSA.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/crypto/SHA1.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/crypto/SHA256.h")

add_library(${PROJECT_NAME}_crypto STATIC
Expand All @@ -15,6 +16,7 @@ add_library(${PROJECT_NAME}_crypto STATIC
"${CMAKE_CURRENT_LIST_DIR}/Globals.cpp"
"${CMAKE_CURRENT_LIST_DIR}/MD5.cpp"
"${CMAKE_CURRENT_LIST_DIR}/RSA.cpp"
"${CMAKE_CURRENT_LIST_DIR}/SHA1.cpp"
"${CMAKE_CURRENT_LIST_DIR}/SHA256.cpp")

target_precompile_headers(${PROJECT_NAME}_crypto PUBLIC ${${PROJECT_NAME}_crypto_HEADERS})
Expand Down
2 changes: 2 additions & 0 deletions src/vpkpp/_vpkpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_pretty_parser(vpkpp
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/ORE.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/PAK.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/PCK.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/TAB.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/VPK.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/VPK_VTMB.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/VPP.h"
Expand All @@ -36,6 +37,7 @@ add_pretty_parser(vpkpp
"${CMAKE_CURRENT_LIST_DIR}/format/ORE.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/PAK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/PCK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/TAB.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/VPK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/VPK_VTMB.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/VPP.cpp"
Expand Down
Loading
Loading