SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Toggle main menu visibility
Loading...
Searching...
No Matches
HOG.cpp
Go to the documentation of this file.
1
#include <
vpkpp/format/HOG.h
>
2
3
#include <filesystem>
4
5
#include <FileStream.h>
6
7
using namespace
sourcepp
;
8
using namespace
vpkpp
;
9
10
std::unique_ptr<PackFile>
HOG::open
(
const
std::string& path,
const
EntryCallback
& callback) {
11
if
(!std::filesystem::exists(path)) {
12
// File does not exist
13
return
nullptr
;
14
}
15
16
auto
* hog =
new
HOG
{path};
17
auto
packFile = std::unique_ptr<PackFile>(hog);
18
19
FileStream reader{hog->fullFilePath};
20
reader.seek_in(0);
21
22
// Verify signature
23
if
(
const
auto
signature = reader.read_string(3); signature !=
HOG_SIGNATURE
) {
24
return
nullptr
;
25
}
26
27
// Read file entries
28
while
(
true
) {
29
// Create new entry
30
Entry
entry =
createNewEntry
();
31
32
// Get file path
33
const
auto
entryPath = hog->cleanEntryPath(reader.read_string(13));
34
35
// Check if we're at EOF (must perform the check after reading beyond file bounds)
36
if
(!reader) {
37
break
;
38
}
39
40
// Get file size and offset
41
entry.
length
= reader.read<uint32_t>();
42
entry.
offset
= reader.tell_in();
43
44
// Seek past file data
45
reader.seek_in_u(entry.
offset
+ entry.
length
);
46
47
// Put it in
48
hog->entries.emplace(entryPath, entry);
49
50
if
(callback) {
51
callback(entryPath, entry);
52
}
53
}
54
55
return
packFile;
56
}
57
58
std::optional<std::vector<std::byte>>
HOG::readEntry
(
const
std::string& path_)
const
{
59
auto
path = this->
cleanEntryPath
(path_);
60
auto
entry = this->
findEntry
(path);
61
if
(!entry) {
62
return
std::nullopt;
63
}
64
if
(entry->unbaked) {
65
return
readUnbakedEntry
(*entry);
66
}
67
68
// It's baked into the file on disk
69
FileStream stream{this->
fullFilePath
};
70
if
(!stream) {
71
return
std::nullopt;
72
}
73
stream.seek_in_u(entry->offset);
74
return
stream.read_bytes(entry->length);
75
}
76
77
Attribute
HOG::getSupportedEntryAttributes
()
const
{
78
using
enum
Attribute
;
79
return
LENGTH
;
80
}
HOG.h
vpkpp::Entry
This class represents the metadata that a file has inside a PackFile.
Definition
Entry.h:14
vpkpp::Entry::offset
uint64_t offset
Offset, format-specific meaning - 0 if unused, or if the offset genuinely is 0.
Definition
Entry.h:33
vpkpp::Entry::length
uint64_t length
Length in bytes (in formats with compression, this is the uncompressed length).
Definition
Entry.h:26
vpkpp::HOG
Definition
HOG.h:12
vpkpp::HOG::getSupportedEntryAttributes
Attribute getSupportedEntryAttributes() const override
Returns a list of supported entry attributes Mostly for GUI programs that show entries and their meta...
Definition
HOG.cpp:77
vpkpp::HOG::open
static std::unique_ptr< PackFile > open(const std::string &path, const EntryCallback &callback=nullptr)
Open a HOG file.
Definition
HOG.cpp:10
vpkpp::HOG::readEntry
std::optional< std::vector< std::byte > > readEntry(const std::string &path_) const override
Try to read the entry's data to a bytebuffer.
Definition
HOG.cpp:58
vpkpp::PackFile::EntryCallback
EntryCallbackBase< void > EntryCallback
Definition
PackFile.h:38
vpkpp::PackFile::findEntry
std::optional< Entry > findEntry(const std::string &path_, bool includeUnbaked=true) const
Try to find an entry given the file path.
Definition
PackFile.cpp:172
vpkpp::PackFile::fullFilePath
std::string fullFilePath
Definition
PackFile.h:231
vpkpp::PackFile::cleanEntryPath
std::string cleanEntryPath(const std::string &path) const
Definition
PackFile.cpp:706
vpkpp::PackFile::createNewEntry
static Entry createNewEntry()
Definition
PackFile.cpp:715
vpkpp::PackFile::readUnbakedEntry
static std::optional< std::vector< std::byte > > readUnbakedEntry(const Entry &entry)
Definition
PackFile.cpp:719
sourcepp
Definition
LZMA.h:11
vpkpp
Definition
Attribute.h:5
vpkpp::Attribute
Attribute
Definition
Attribute.h:7
vpkpp::Attribute::LENGTH
@ LENGTH
Definition
Attribute.h:10
vpkpp::HOG_SIGNATURE
constexpr std::string_view HOG_SIGNATURE
Definition
HOG.h:9
src
vpkpp
format
HOG.cpp
Generated on
for SourcePP by
1.17.0