Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump sourcepp #12

Merged
merged 2 commits into from
Aug 20, 2024
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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.24)

project( verifier
DESCRIPTION "A tool used to verify a game's install."
VERSION 0.3.2
VERSION 0.3.3
)
set( CMAKE_CXX_STANDARD 20 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
Expand Down Expand Up @@ -44,7 +44,7 @@ target_compile_definitions( ${PROJECT_NAME} PRIVATE $<$<CONFIG:Debug>:DEBUG> "VE

# Link to CLI dependencies
include( "${CMAKE_CURRENT_SOURCE_DIR}/src/thirdparty/CMakeLists.txt" )
target_link_libraries( ${PROJECT_NAME} PRIVATE Argumentum::argumentum cryptopp::cryptopp fmt::fmt kvpp vpkpp)
target_link_libraries( ${PROJECT_NAME} PRIVATE Argumentum::argumentum cryptopp::cryptopp fmt::fmt sourcepp::kvpp sourcepp::vpkpp)

# Create GUI executable
if( VERIFIER_BUILD_GUI )
Expand Down
63 changes: 30 additions & 33 deletions src/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
#include <cryptopp/hex.h>
#include <cryptopp/sha.h>
#include <kvpp/kvpp.h>
#include <sourcepp/fs/FS.h>
#include <sourcepp/string/String.h>
#include <sourcepp/FS.h>
#include <vpkpp/format/VPK.h>

#include "log.hpp"
Expand Down Expand Up @@ -242,46 +241,44 @@ auto createFromSteamDepotConfigs( const std::string& configPath, const std::vect
static auto enterVPK( std::ofstream& writer, std::string_view vpkPath, std::string_view vpkPathRel, const std::vector<std::regex>& excludes, const std::vector<std::regex>& includes, unsigned int& count ) -> bool {
using namespace vpkpp;

auto vpk = VPK::open( std::string{ vpkPath } );
const auto vpk = VPK::open( std::string{ vpkPath } );
if (! vpk ) {
return false;
}

for ( const auto& [ entryDirectory, entries ] : vpk->getBakedEntries() ) {
for ( const auto& entry : entries ) {
if ( !excludes.empty() && matchPath( entry.path, excludes) ) {
continue;
}
vpk->runForAllEntries( [ &writer, &vpkPath, &vpkPathRel, &excludes, &includes, &count, &vpk ]( const std::string& path, const Entry& entry ) {
if ( !excludes.empty() && matchPath( path, excludes) ) {
return;
}

if ( !includes.empty() && !matchPath( entry.path, includes ) ) {
continue;
}
if ( !includes.empty() && !matchPath( path, includes ) ) {
return;
}

auto entryData{ vpk->readEntry( entry ) };
if (! entryData ) {
Log_Error( "Failed to open file: `{}/{}`", vpkPath, entry.path );
continue;
}
auto entryData{ vpk->readEntry( path ) };
if (! entryData ) {
Log_Error( "Failed to open file: `{}/{}`", vpkPath, path );
return;
}

// sha1 (crc32 is already computed)
CryptoPP::SHA1 sha1er{};
sha1er.Update( reinterpret_cast<const CryptoPP::byte*>( entryData->data() ), entryData->size() );
std::array<CryptoPP::byte, CryptoPP::SHA1::DIGESTSIZE> sha1Hash{};
sha1er.Final( sha1Hash.data() );

std::string sha1HashStr;
std::string crc32HashStr;
{
CryptoPP::StringSource sha1HashStrSink{ sha1Hash.data(), sha1Hash.size(), true, new CryptoPP::HexEncoder{ new CryptoPP::StringSink{ sha1HashStr } } };
CryptoPP::StringSource crc32HashStrSink{ reinterpret_cast<const CryptoPP::byte*>( &entry.crc32 ), sizeof( entry.crc32 ), true, new CryptoPP::HexEncoder{ new CryptoPP::StringSink{ crc32HashStr } } };
}
// sha1 (crc32 is already computed)
CryptoPP::SHA1 sha1er{};
sha1er.Update( reinterpret_cast<const CryptoPP::byte*>( entryData->data() ), entryData->size() );
std::array<CryptoPP::byte, CryptoPP::SHA1::DIGESTSIZE> sha1Hash{};
sha1er.Final( sha1Hash.data() );

// write out entry
writer << fmt::format( "{}\xFF{}\xFF{}\xFF{}\xFF{}\xFF\xFD", vpkPathRel, entry.path, entryData->size(), sha1HashStr, crc32HashStr );
Log_Info( "Processed file `{}/{}`", vpkPath, entry.path );
count += 1;
std::string sha1HashStr;
std::string crc32HashStr;
{
CryptoPP::StringSource sha1HashStrSink{ sha1Hash.data(), sha1Hash.size(), true, new CryptoPP::HexEncoder{ new CryptoPP::StringSink{ sha1HashStr } } };
CryptoPP::StringSource crc32HashStrSink{ reinterpret_cast<const CryptoPP::byte*>( &entry.crc32 ), sizeof( entry.crc32 ), true, new CryptoPP::HexEncoder{ new CryptoPP::StringSink{ crc32HashStr } } };
}
}

// write out entry
writer << fmt::format( "{}\xFF{}\xFF{}\xFF{}\xFF{}\xFF\xFD", vpkPathRel, path, entryData->size(), sha1HashStr, crc32HashStr );
Log_Info( "Processed file `{}/{}`", vpkPath, path );
count += 1;
} );

return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_subdirectory( "${CMAKE_CURRENT_LIST_DIR}/fmt" SYSTEM )
set( SOURCEPP_USE_BSPPP OFF CACHE INTERNAL "" )
set( SOURCEPP_USE_DMXPP OFF CACHE INTERNAL "" )
set( SOURCEPP_USE_FGDPP OFF CACHE INTERNAL "" )
set( SOURCEPP_USE_GAMEPP OFF CACHE INTERNAL "" )
set( SOURCEPP_USE_MDLPP OFF CACHE INTERNAL "" )
set( SOURCEPP_USE_STEAMPP OFF CACHE INTERNAL "" )
set( SOURCEPP_USE_VICEPP OFF CACHE INTERNAL "" )
Expand Down
2 changes: 1 addition & 1 deletion src/thirdparty/sourcepp
Submodule sourcepp updated 106 files
13 changes: 6 additions & 7 deletions src/verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
#include <cryptopp/filters.h>
#include <cryptopp/hex.h>
#include <cryptopp/sha.h>
#include <sourcepp/crypto/String.h>
#include <vpkpp/format/VPK.h>

#include "log.hpp"

static auto verifyArchivedFile( const std::string& archivePath, const std::string& entryPath, std::uint64_t expectedSize, std::string_view expectedSha1, std::string_view expectedCrc32, unsigned int& entries, unsigned int& errors ) -> void;
static auto verifyArchivedFile( const std::string& archivePath, const std::string& archiveRel, const std::string& entryPath, std::uint64_t expectedSize, std::string_view expectedSha1, std::string_view expectedCrc32, unsigned int& entries, unsigned int& errors ) -> void;

static auto splitString( const std::string& string, const std::string& delim ) -> std::vector<std::string>;

Expand Down Expand Up @@ -73,7 +72,7 @@ auto verify( std::string_view root_, std::string_view indexLocation ) -> int {
}

if ( insideArchive ) {
verifyArchivedFile( path.string(), pathRel, expectedSize, expectedSha1, expectedCrc32, entries, errors );
verifyArchivedFile( path.string(), archive, pathRel, expectedSize, expectedSha1, expectedCrc32, entries, errors );
continue;
}

Expand Down Expand Up @@ -146,19 +145,19 @@ auto verify( std::string_view root_, std::string_view indexLocation ) -> int {
return 0;
}

static auto verifyArchivedFile( const std::string& archivePath, const std::string& entryPath, std::uint64_t expectedSize, std::string_view expectedSha1, std::string_view expectedCrc32, unsigned int& entries, unsigned int& errors ) -> void {
static auto verifyArchivedFile( const std::string& archivePath, const std::string& archiveRel, const std::string& entryPath, std::uint64_t expectedSize, std::string_view expectedSha1, std::string_view expectedCrc32, unsigned int& entries, unsigned int& errors ) -> void {
using namespace vpkpp;

static std::unordered_map<std::string, std::unique_ptr<PackFile>> loadedVPKs{};
if (! loadedVPKs.contains( archivePath ) ) {
loadedVPKs[ archivePath ] = VPK::open( archivePath );
}
if (! loadedVPKs[ archivePath ]) {
Log_Error( "Failed to open VPK at `{}` (containing file at `{}`)", archivePath, entryPath );
Log_Error( "Failed to open VPK at `{}` (containing file at `{}`)", archiveRel, entryPath );
return;
}

const auto fullPath{ archivePath + '/' + entryPath };
const auto fullPath{ archiveRel + '/' + entryPath };

auto entry{ loadedVPKs[ archivePath ]->findEntry( entryPath ) };
if (! entry ) {
Expand All @@ -167,7 +166,7 @@ static auto verifyArchivedFile( const std::string& archivePath, const std::strin
return;
}

auto entryData{ loadedVPKs[ archivePath ]->readEntry( *entry ) };
auto entryData{ loadedVPKs[ archivePath ]->readEntry( entryPath ) };
if (! entryData ) {
Log_Error( "Failed to open file: `{}`", fullPath );
return;
Expand Down