Skip to content

Commit

Permalink
fix(vtfpp): use sourcepp makeFourCC helper for signature
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed Aug 21, 2024
1 parent a4078b4 commit 6b99bda
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
5 changes: 1 addition & 4 deletions include/sourcepp/parser/Binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ namespace sourcepp::parser::binary {
* @param fourCC The human-readable FourCC.
* @return The FourCC identifier.
*/
consteval uint32_t makeFourCC(std::string_view fourCC) {
if (fourCC.length() != 4) {
return 0;
}
consteval uint32_t makeFourCC(const char fourCC[4]) {
return fourCC[0] | (fourCC[1] << 8) | (fourCC[2] << 16) | (fourCC[3] << 24);
}

Expand Down
15 changes: 8 additions & 7 deletions include/vtfpp/vtfpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
#include <vector>

#include <sourcepp/math/Vector.h>
#include <sourcepp/parser/Binary.h>

#include "ImageFormats.h"

namespace vtfpp {

constexpr int32_t VTF_SIGNATURE = 'V' + ('T' << 8) + ('F' << 16);
constexpr uint32_t VTF_SIGNATURE = sourcepp::parser::binary::makeFourCC("VTF\0");

struct Resource {
enum Type : uint8_t {
Expand All @@ -41,11 +42,11 @@ struct Resource {
std::span<std::byte> data;

using ConvertedData = std::variant<
std::monostate, // Anything that would be equivalent to just returning data directly, or used as an error
uint32_t, // CRC, TSO
std::pair<uint8_t, uint8_t>, // LOD
std::string, // KVD
std::span<uint32_t> // AXC
std::monostate, // Anything that would be equivalent to just returning data directly, or used as an error
uint32_t, // CRC, TSO
std::pair<uint8_t, uint8_t>, // LOD
std::string, // KVD
std::span<uint32_t> // AXC
>;
[[nodiscard]] ConvertedData convertData() const;

Expand Down Expand Up @@ -182,7 +183,7 @@ class VTF {

std::vector<std::byte> data;

//int32_t signature;
//uint32_t signature;
uint32_t majorVersion{};
uint32_t minorVersion{};

Expand Down
2 changes: 1 addition & 1 deletion src/vtfpp/vtfpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ VTF::VTF(std::vector<std::byte>&& vtfData, bool parseHeaderOnly)
: data(std::move(vtfData)) {
BufferStreamReadOnly stream{this->data};

if (stream.read<int32_t>() != VTF_SIGNATURE) {
if (stream.read<uint32_t>() != VTF_SIGNATURE) {
return;
}

Expand Down

0 comments on commit 6b99bda

Please sign in to comment.