SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
VFONT.cpp
Go to the documentation of this file.
1#include <vcryptpp/VFONT.h>
2
3#include <string_view>
4
5#include <BufferStream.h>
6
7using namespace vcryptpp;
8
9std::vector<std::byte> VFONT::decrypt(std::span<const std::byte> data) {
10 BufferStreamReadOnly reader{data.data(), data.size()};
11
12 if (reader.seek(SIGNATURE.length(), std::ios::end).read_string(SIGNATURE.length()) != SIGNATURE) {
13 return {};
14 }
15 reader.seek(SIGNATURE.length() + sizeof(uint8_t), std::ios::end);
16
17 auto bytes = reader.read<uint8_t>();
18
19 std::vector<std::byte> out;
20 out.resize(reader.size() - SIGNATURE.length() - bytes);
21
22 reader.seek(-static_cast<int>(bytes), std::ios::cur);
23 uint8_t magic = MAGIC;
24 for (int i = 0; i < bytes - 1; i++) {
25 magic ^= reader.read<uint8_t>() + MAGIC;
26 }
27
28 reader.seek(0);
29 for (auto& outByte : out) {
30 auto byte = reader.read<uint8_t>();
31 outByte = static_cast<std::byte>(byte ^ magic);
32 magic = byte + MAGIC;
33 }
34
35 return out;
36}
constexpr uint8_t MAGIC
Definition: VFONT.h:14
constexpr std::string_view SIGNATURE
Definition: VFONT.h:12
std::vector< std::byte > decrypt(std::span< const std::byte > data)
Definition: VFONT.cpp:9
Definition: VFONT.h:10