SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
HOT.cpp
Go to the documentation of this file.
1#include <vtfpp/HOT.h>
2
3#include <BufferStream.h>
4
5using namespace sourcepp;
6using namespace vtfpp;
7
9 : opened(true) {}
10
11HOT::HOT(std::span<const std::byte> hotData) {
12 BufferStreamReadOnly stream{hotData.data(), hotData.size()};
13
14 stream >> this->version >> this->flags;
15 if (this->version != 1) {
16 return;
17 }
18
19 this->rects.resize(stream.read<uint16_t>());
20 for (auto& rect : this->rects) {
21 stream >> rect.flags >> rect.x1 >> rect.y1 >> rect.x2 >> rect.y2;
22 }
23
24 this->opened = true;
25}
26
27HOT::HOT(const std::string& hotPath)
28 : HOT(fs::readFileBuffer(hotPath)) {}
29
30HOT::operator bool() const {
31 return this->opened;
32}
33
34uint8_t HOT::getVersion() const {
35 return this->version;
36}
37
38void HOT::setVersion(uint8_t v) {
39 if (v != 1) {
40 return;
41 }
42 this->version = v;
43}
44
45uint8_t HOT::getFlags() const {
46 return this->flags;
47}
48
49void HOT::setFlags(uint8_t f) {
50 this->flags = f;
51}
52
53const std::vector<HOT::Rect>& HOT::getRects() const {
54 return this->rects;
55}
56
57std::vector<HOT::Rect>& HOT::getRects() {
58 return this->rects;
59}
60
61std::vector<std::byte> HOT::bake() const {
62 if (!this->opened) {
63 return {};
64 }
65
66 std::vector<std::byte> hotspotData;
67 BufferStream stream{hotspotData};
68
69 stream << this->version << this->flags;
70 stream.write<uint16_t>(this->rects.size());
71
72 for (const auto& rect : this->rects) {
73 stream << rect.flags << rect.x1 << rect.y1 << rect.x2 << rect.y2;
74 }
75
76 hotspotData.resize(stream.tell());
77 return hotspotData;
78}
79
80bool HOT::bake(const std::string& hotPath) const {
81 return fs::writeFileBuffer(hotPath, this->bake());
82}
Definition: HOT.h:13
std::vector< std::byte > bake() const
Definition: HOT.cpp:61
void setVersion(uint8_t v)
Definition: HOT.cpp:38
HOT()
Definition: HOT.cpp:8
std::vector< Rect > rects
Definition: HOT.h:57
const std::vector< Rect > & getRects() const
Definition: HOT.cpp:53
uint8_t getFlags() const
Definition: HOT.cpp:45
void setFlags(uint8_t f)
Definition: HOT.cpp:49
bool opened
Definition: HOT.h:53
uint8_t flags
Definition: HOT.h:56
uint8_t version
Definition: HOT.h:55
uint8_t getVersion() const
Definition: HOT.cpp:34
bool writeFileBuffer(const std::string &filepath, std::span< const std::byte > buffer)
Definition: FS.cpp:27
Definition: LZMA.h:11
Definition: HOT.h:11