SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
PAK.h
Go to the documentation of this file.
1// ReSharper disable CppRedundantQualifier
2
3#pragma once
4
6
7#include "../PackFile.h"
8
9namespace vpkpp {
10
11constexpr uint8_t PAK_FILENAME_MAX_SIZE = 56;
13
14constexpr uint8_t PAK_SIN_FILENAME_MAX_SIZE = 120;
16
18
19constexpr uint8_t PAK_HROT_FILENAME_MAX_SIZE = 120;
21
22constexpr std::string_view PAK_EXTENSION = ".pak";
23constexpr std::string_view SIN_EXTENSION = ".sin";
24
25class PAK : public PackFile {
26public:
27 enum class Type {
29 SIN,
30 SIN_RELOADED,
31 HROT,
32 };
33
35 static std::unique_ptr<PackFile> create(const std::string& path, Type type = Type::PAK);
36
38 [[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);
39
40 [[nodiscard]] std::optional<std::vector<std::byte>> readEntry(const std::string& path_) const override;
41
42 bool bake(const std::string& outputDir_ /*= ""*/, BakeOptions options /*= {}*/, const EntryCallback& callback /*= nullptr*/) override;
43
44 [[nodiscard]] Attribute getSupportedEntryAttributes() const override;
45
46 [[nodiscard]] Type getType() const;
47
48 void setType(Type type_);
49
50protected:
52
53 void addEntryInternal(Entry& entry, const std::string& path, std::vector<std::byte>& buffer, EntryOptions options) override;
54
55 [[nodiscard]] uint32_t getSignature() const;
56
57 [[nodiscard]] uint8_t getFilenameLength() const;
58
60
61private:
62 VPKPP_REGISTER_PACKFILE_OPEN(PAK_EXTENSION, &PAK::open);
63 VPKPP_REGISTER_PACKFILE_OPEN(SIN_EXTENSION, &PAK::open);
64};
65
66} // namespace vpkpp
This class represents the metadata that a file has inside a PackFile.
Definition Entry.h:14
static std::unique_ptr< PackFile > create(const std::string &path, Type type=Type::PAK)
Create a PAK file.
Definition PAK.cpp:12
static std::unique_ptr< PackFile > open(const std::string &path, const EntryCallback &callback=nullptr)
Open a PAK file.
Definition PAK.cpp:36
std::optional< std::vector< std::byte > > readEntry(const std::string &path_) const override
Try to read the entry's data to a bytebuffer.
Definition PAK.cpp:118
Type getType() const
Definition PAK.cpp:258
Attribute getSupportedEntryAttributes() const override
Returns a list of supported entry attributes Mostly for GUI programs that show entries and their meta...
Definition PAK.cpp:253
uint8_t getFilenameLength() const
Definition PAK.cpp:280
uint32_t getSignature() const
Definition PAK.cpp:266
Type type
Definition PAK.h:59
void addEntryInternal(Entry &entry, const std::string &path, std::vector< std::byte > &buffer, EntryOptions options) override
Definition PAK.cpp:137
void setType(Type type_)
Definition PAK.cpp:262
PackFile(const PackFile &other)=delete
EntryCallbackBase< void > EntryCallback
Definition PackFile.h:40
bool bake()
If output folder is an empty string, it will overwrite the original.
Definition PackFile.cpp:369
PackFile(const PackFile &other)=delete
consteval uint32_t makeFourCC(const char fourCC[4])
Creates a FourCC identifier from a string of 4 characters.
Definition Binary.h:20
constexpr auto PAK_SIN_RELOADED_SIGNATURE
Definition PAK.h:17
constexpr auto PAK_HROT_SIGNATURE
Definition PAK.h:20
constexpr auto PAK_SIN_SIGNATURE
Definition PAK.h:15
constexpr auto PAK_SIGNATURE
Definition PAK.h:12
Attribute
Definition Attribute.h:7
constexpr std::string_view SIN_EXTENSION
Definition PAK.h:23
constexpr uint8_t PAK_SIN_FILENAME_MAX_SIZE
Definition PAK.h:14
constexpr uint8_t PAK_HROT_FILENAME_MAX_SIZE
Definition PAK.h:19
constexpr uint8_t PAK_FILENAME_MAX_SIZE
Definition PAK.h:11
constexpr std::string_view PAK_EXTENSION
Definition PAK.h:22