From aa5665e255079365f9e360e28cc62993697139f0 Mon Sep 17 00:00:00 2001 From: craftablescience Date: Sat, 24 Oct 2026 16:25:10 -0700 Subject: [PATCH] all: enable warnings, treat warnings as errors --- cmake/AddPrettyParser.cmake | 12 ++ include/sourcepp/Math.h | 2 +- include/vpkpp/PackFile.h | 19 ++++ lang/c/include/vtfppc/SHT.h | 2 +- lang/c/src/sourceppc/String.cpp | 2 +- src/bsppp/BSP.cpp | 16 ++- src/bsppp/EntityLump.cpp | 16 +-- src/fspp/fspp.cpp | 15 ++- src/kvpp/DMX.cpp | 44 ++++---- src/kvpp/KV1Binary.cpp | 14 +-- src/mdlpp/mdlpp.cpp | 10 +- src/mdlpp/structs/VVD.cpp | 2 +- src/toolpp/CmdSeq.cpp | 4 +- src/vpkpp/PackFile.cpp | 2 +- src/vpkpp/format/APK.cpp | 4 +- src/vpkpp/format/FGP.cpp | 4 +- src/vpkpp/format/FPX.cpp | 4 +- src/vpkpp/format/GCF.cpp | 14 +-- src/vpkpp/format/GMA.cpp | 2 +- src/vpkpp/format/GRP.cpp | 2 +- src/vpkpp/format/REZ.cpp | 3 +- src/vpkpp/format/TAB.cpp | 7 +- src/vpkpp/format/VPK.cpp | 8 +- src/vpkpp/format/VPK_VTMB.cpp | 9 +- src/vpkpp/format/WAD3.cpp | 4 +- src/vpkpp/format/ZIP.cpp | 2 +- src/vtfpp/DistanceMapping.cpp | 18 +-- src/vtfpp/ImageConversion.cpp | 27 +++-- src/vtfpp/VBF.cpp | 2 +- src/vtfpp/VTF.cpp | 192 ++++++++++++++++---------------- 30 files changed, 255 insertions(+), 207 deletions(-) diff --git a/cmake/AddPrettyParser.cmake b/cmake/AddPrettyParser.cmake index a48ecc0ec..49b20add6 100644 --- a/cmake/AddPrettyParser.cmake +++ b/cmake/AddPrettyParser.cmake @@ -29,6 +29,18 @@ function(add_pretty_parser TARGET) target_link_libraries(${TARGET} PUBLIC ${PROJECT_NAME} ${OPTIONS_DEPS_PUBLIC}) target_link_libraries(${TARGET} INTERFACE ${OPTIONS_DEPS_INTERFACE}) + # Enable warnings, warnings are errors + if(PROJECT_IS_TOP_LEVEL) + if(MSVC) + target_compile_options(${TARGET} PRIVATE /W4 /WX) + else() + target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Wpedantic) + endif() + set_target_properties(${TARGET} PROPERTIES + COMPILE_WARNING_AS_ERROR ON + LINK_WARNING_AS_ERROR ON) + endif() + # Define DEBUG macro target_compile_definitions(${TARGET} PRIVATE "$<$:DEBUG>") diff --git a/include/sourcepp/Math.h b/include/sourcepp/Math.h index c91a208c1..502528aad 100644 --- a/include/sourcepp/Math.h +++ b/include/sourcepp/Math.h @@ -63,7 +63,7 @@ template [[nodiscard]] constexpr uint16_t paddingForAlignment(uint16_t alignment, uint64_t n) { if (const auto rest = n % alignment; rest > 0) { - return alignment - rest; + return static_cast(alignment - rest); } return 0; } diff --git a/include/vpkpp/PackFile.h b/include/vpkpp/PackFile.h index 7ed03c22a..b04efc505 100644 --- a/include/vpkpp/PackFile.h +++ b/include/vpkpp/PackFile.h @@ -10,8 +10,18 @@ #include #include + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif + #include +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + #include "Attribute.h" #include "Entry.h" #include "Options.h" @@ -226,10 +236,19 @@ class PackFile { static std::unordered_map>& getOpenExtensionRegistry(); +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdangling-reference" +#endif + static const OpenFactoryFunction& registerOpenExtensionForTypeFactory(std::string_view extension, const OpenFactoryFunctionBasic& factory); static const OpenFactoryFunction& registerOpenExtensionForTypeFactory(std::string_view extension, const OpenFactoryFunction& factory); +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + std::string fullFilePath; EntryTrie entries; EntryTrie unbakedEntries; diff --git a/lang/c/include/vtfppc/SHT.h b/lang/c/include/vtfppc/SHT.h index daee55370..a37a186ca 100644 --- a/lang/c/include/vtfppc/SHT.h +++ b/lang/c/include/vtfppc/SHT.h @@ -16,7 +16,7 @@ VTFPP_EXTERN typedef struct { vtfpp_sht_sequence_frame_bounds_t bounds[4]; } vtfpp_sht_sequence_frame_t; -#define VTFPP_SHT_SEQUENCE_FRAME_INVALID (SOURCEPP_CAST_CTOR(vtfpp_sht_sequence_frame_t) {.duration = 0.f}) +#define VTFPP_SHT_SEQUENCE_FRAME_INVALID (SOURCEPP_CAST_CTOR(vtfpp_sht_sequence_frame_t) {.duration = 0.f, .bounds = {{0.f, 0.f, 0.f, 0.f}, {0.f, 0.f, 0.f, 0.f}, {0.f, 0.f, 0.f, 0.f}, {0.f, 0.f, 0.f, 0.f}}}) VTFPP_EXTERN typedef struct { uint32_t id; diff --git a/lang/c/src/sourceppc/String.cpp b/lang/c/src/sourceppc/String.cpp index 73b8df837..73b4601fc 100644 --- a/lang/c/src/sourceppc/String.cpp +++ b/lang/c/src/sourceppc/String.cpp @@ -37,7 +37,7 @@ SOURCEPP_API sourcepp_string_array_t sourcepp_string_array_new(size_t size) { SOURCEPP_API void sourcepp_string_array_free(sourcepp_string_array_t* array) { if (array->data) { - for (size_t i = 0; i < array->size; i++) { + for (int64_t i = 0; i < array->size; i++) { if (char* str = array->data[i]) { std::free(str); array->data[i] = nullptr; diff --git a/src/bsppp/BSP.cpp b/src/bsppp/BSP.cpp index 60930a363..f88030e50 100644 --- a/src/bsppp/BSP.cpp +++ b/src/bsppp/BSP.cpp @@ -195,11 +195,17 @@ bool BSP::setLump(BSPLump lumpIndex, uint32_t version, std::spanstagedLumps[lump] = std::make_pair>({ - .version = version, .uncompressedLength = static_cast(data.size()), + .offset = 0, + .length = 0, + .version = version, + .uncompressedLength = static_cast(data.size()), }, {compressedData->begin(), compressedData->end()}); } else { this->stagedLumps[lump] = std::make_pair>({ - .version = version, .uncompressedLength = 0, + .offset = 0, + .length = 0, + .version = version, + .uncompressedLength = 0, }, {data.begin(), data.end()}); } return true; @@ -258,6 +264,7 @@ bool BSP::setGameLump(BSPGameLump::Signature signature, uint16_t version, std::s .version = version, .offset = 0, .uncompressedLength = static_cast(data.size()), + .data = {}, }; if (compressLevel) { @@ -286,8 +293,7 @@ void BSP::resetLump(BSPLump lumpIndex) { this->stagedGameLumps = this->parseGameLumps(false); return; } - const auto lump = static_cast>(lumpIndex); - if (this->stagedLumps.contains(lump)) { + if (const auto lump = static_cast>(lumpIndex); this->stagedLumps.contains(lump)) { this->stagedLumps.erase(lump); } } @@ -378,7 +384,7 @@ bool BSP::bake(std::string_view outputPath) { } const auto lumpsHeaderOffset = stream.tell(); - for (int i = 0; i < sizeof(Header::lumps); i++) { + for (size_t i = 0; i < sizeof(Header::lumps); i++) { stream.write(0); } diff --git a/src/bsppp/EntityLump.cpp b/src/bsppp/EntityLump.cpp index 9c82d8445..513463132 100644 --- a/src/bsppp/EntityLump.cpp +++ b/src/bsppp/EntityLump.cpp @@ -35,7 +35,7 @@ uint64_t BSPEntityKeyValues::getKeyValuesCount() const { uint64_t BSPEntityKeyValues::getKeyValuesCount(std::string_view childKey) const { uint64_t count = 0; for (const auto& element : this->keyvalues) { - if (sourcepp::string::iequals(element.getKey(), childKey)) { + if (string::iequals(element.getKey(), childKey)) { ++count; } } @@ -64,7 +64,7 @@ BSPEntityKeyValues::Element& BSPEntityKeyValues::operator[](std::string_view chi const BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_view childKey) const { for (const auto& element : this->keyvalues) { - if (sourcepp::string::iequals(element.getKey(), childKey)) { + if (string::iequals(element.getKey(), childKey)) { return element; } } @@ -73,7 +73,7 @@ const BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_vi BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_view childKey) { for (auto& element : this->keyvalues) { - if (sourcepp::string::iequals(element.getKey(), childKey)) { + if (string::iequals(element.getKey(), childKey)) { return element; } } @@ -83,7 +83,7 @@ BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_view chi const BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_view childKey, unsigned int n) const { unsigned int count = 0; for (const auto& element : this->keyvalues) { - if (sourcepp::string::iequals(element.getKey(), childKey)) { + if (string::iequals(element.getKey(), childKey)) { if (count == n) { return element; } @@ -96,7 +96,7 @@ const BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_vi BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_view childKey, unsigned int n) { unsigned int count = 0; for (auto& element: this->keyvalues) { - if (sourcepp::string::iequals(element.getKey(), childKey)) { + if (string::iequals(element.getKey(), childKey)) { if (count == n) { return element; } @@ -107,9 +107,9 @@ BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_view chi } void BSPEntityKeyValues::removeKeyValue(std::string_view childKey, int n) { - unsigned int count = 0; + int count = 0; for (auto element = this->keyvalues.begin(); element != this->keyvalues.end(); ++element) { - if (sourcepp::string::iequals(element->getKey(), childKey)) { + if (string::iequals(element->getKey(), childKey)) { if (n < 0 || count == n) { element = this->keyvalues.erase(element); if (count == n) { @@ -130,6 +130,6 @@ std::string BSPEntityKeyValues::bake(bool useEscapes) const { out += parser::text::convertSpecialCharsToEscapes(elem.getValue(), parser::text::getDefaultEscapeSequencesOrNone(useEscapes)); out += "\"\n"; } - out += "}"; + out += '}'; return out; } diff --git a/src/fspp/fspp.cpp b/src/fspp/fspp.cpp index 16349626a..8c0578417 100644 --- a/src/fspp/fspp.cpp +++ b/src/fspp/fspp.cpp @@ -55,7 +55,7 @@ FileSystem::FileSystem(std::string_view gamePath, const FileSystemOptions& optio if (searchPathKVs.isInvalid()) { return; } - for (int i = 0; i < searchPathKVs.getChildCount(); i++) { + for (uint64_t i = 0; i < searchPathKVs.getChildCount(); i++) { auto searches = string::split(string::toLower(searchPathKVs[i].getKey()), '+'); auto path = std::string{string::toLower(searchPathKVs[i].getValue())}; @@ -67,7 +67,7 @@ FileSystem::FileSystem(std::string_view gamePath, const FileSystemOptions& optio } else if (path.starts_with(GAMEINFO_PATH)) { path = gameID + '/' + path.substr(GAMEINFO_PATH.length()); } - if (path.ends_with(".") && !path.ends_with("..")) { + if (path.ends_with('.') && !path.ends_with("..")) { path.pop_back(); } string::normalizeSlashes(path); @@ -89,8 +89,7 @@ FileSystem::FileSystem(std::string_view gamePath, const FileSystemOptions& optio if (!this->searchPathVPKs.contains(search)) { this->searchPathVPKs[search] = std::vector>{}; } - auto packFile = PackFile::open(fullPath); - if (packFile) { + if (auto packFile = PackFile::open(fullPath)) { this->searchPathVPKs[search].push_back(std::move(packFile)); } } @@ -102,7 +101,7 @@ FileSystem::FileSystem(std::string_view gamePath, const FileSystemOptions& optio if (path.ends_with("/*")) { // Add the glob dir searchpath if (const auto globParentPath = this->rootPath + '/' + path.substr(0, path.length() - 2); std::filesystem::exists(globParentPath) && std::filesystem::is_directory(globParentPath)) { - for (const auto directoryIterator : std::filesystem::directory_iterator{globParentPath, std::filesystem::directory_options::skip_permission_denied}) { + for (const auto& directoryIterator : std::filesystem::directory_iterator{globParentPath, std::filesystem::directory_options::skip_permission_denied}) { auto globChildPath = std::filesystem::relative(directoryIterator.path(), this->rootPath).string(); string::normalizeSlashes(globChildPath); this->searchPathDirs[search].push_back(globChildPath); @@ -143,8 +142,8 @@ FileSystem::FileSystem(std::string_view gamePath, const FileSystemOptions& optio } else { this->searchPathDirs["executable_path"] = {}; } - this->searchPathDirs["executable_path"].push_back("bin"); - this->searchPathDirs["executable_path"].push_back(""); + this->searchPathDirs["executable_path"].emplace_back("bin"); + this->searchPathDirs["executable_path"].emplace_back(""); } // Add PLATFORM if it doesn't exist, point it at "platform" @@ -161,7 +160,7 @@ FileSystem::FileSystem(std::string_view gamePath, const FileSystemOptions& optio } } if (!foundPlatform) { - this->searchPathDirs["game"].push_back("platform"); + this->searchPathDirs["game"].emplace_back("platform"); } } diff --git a/src/kvpp/DMX.cpp b/src/kvpp/DMX.cpp index 39f370cd4..286e3f1cf 100644 --- a/src/kvpp/DMX.cpp +++ b/src/kvpp/DMX.cpp @@ -163,7 +163,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_ELEMENT: { const auto elements = this->getValue>(); std::string out = "["; - for (int i = 0; i < elements.size(); i++) { + for (size_t i = 0; i < elements.size(); i++) { if (elements[i].index == -2) { out += std::format("{}GUID: {}{}", i == 0 ? "" : " ", elements[i].externalGUID, i == elements.size() - 1 ? "" : ","); } else { @@ -175,7 +175,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_INT32: { const auto ints = this->getValue>(); std::string out = "["; - for (int i = 0; i < ints.size(); i++) { + for (size_t i = 0; i < ints.size(); i++) { out += std::format("{}{}{}", i == 0 ? "" : " ", ints[i], i == ints.size() - 1 ? "" : ","); } return out + ']'; @@ -183,7 +183,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_FLOAT: { const auto floats = this->getValue>(); std::string out = "["; - for (int i = 0; i < floats.size(); i++) { + for (size_t i = 0; i < floats.size(); i++) { out += std::format("{}{}{}", i == 0 ? "" : " ", floats[i], i == floats.size() - 1 ? "" : ","); } return out + ']'; @@ -191,7 +191,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_BOOL: { const auto bools = this->getValue>(); std::string out = "["; - for (int i = 0; i < bools.size(); i++) { + for (size_t i = 0; i < bools.size(); i++) { // ReSharper disable once CppRedundantCastExpression out += std::format("{}{}{}", i == 0 ? "" : " ", static_cast(bools[i]), i == bools.size() - 1 ? "" : ","); } @@ -200,7 +200,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_STRING: { const auto strings = this->getValue>(); std::string out = "["; - for (int i = 0; i < strings.size(); i++) { + for (size_t i = 0; i < strings.size(); i++) { out += std::format("{}{}{}", i == 0 ? "" : " ", strings[i], i == strings.size() - 1 ? "" : ",\n"); } return out + ']'; @@ -208,7 +208,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_BYTEARRAY: { const auto bytearrays = this->getValue>(); std::string out = "["; - for (int i = 0; i < bytearrays.size(); i++) { + for (size_t i = 0; i < bytearrays.size(); i++) { std::stringstream hex; hex << std::hex << std::setfill('0'); for (auto byte : bytearrays[i]) { @@ -221,7 +221,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_UUID: { const auto uuids = this->getValue>(); std::string out = "["; - for (int i = 0; i < uuids.size(); i++) { + for (size_t i = 0; i < uuids.size(); i++) { std::stringstream hex; hex << std::hex << std::setfill('0'); for (auto byte : uuids[i]) { @@ -234,7 +234,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_TIME: { const auto times = this->getValue>(); std::string out = "["; - for (int i = 0; i < times.size(); i++) { + for (size_t i = 0; i < times.size(); i++) { out += std::format("{}{}{}", i == 0 ? "" : " ", times[i].seconds, i == times.size() - 1 ? "" : ","); } return out + ']'; @@ -242,7 +242,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_COLOR: { const auto colors = this->getValue>(); std::string out = "["; - for (int i = 0; i < colors.size(); i++) { + for (size_t i = 0; i < colors.size(); i++) { out += std::format("{}rgba({}, {}, {}, {}){}", i == 0 ? "" : " ", colors[i].r, colors[i].g, colors[i].b, colors[i].a, i == colors.size() - 1 ? "" : ",\n"); } return out + ']'; @@ -250,7 +250,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_VECTOR2: { const auto vecs = this->getValue>(); std::string out = "["; - for (int i = 0; i < vecs.size(); i++) { + for (size_t i = 0; i < vecs.size(); i++) { out += std::format("{}[{}, {}]{}", i == 0 ? "" : " ", vecs[i][0], vecs[i][1], i == vecs.size() - 1 ? "" : ",\n"); } return out + ']'; @@ -258,7 +258,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_VECTOR3: { const auto vecs = this->getValue>(); std::string out = "["; - for (int i = 0; i < vecs.size(); i++) { + for (size_t i = 0; i < vecs.size(); i++) { out += std::format("{}[{}, {}, {}]{}", i == 0 ? "" : " ", vecs[i][0], vecs[i][1], vecs[i][2], i == vecs.size() - 1 ? "" : ",\n"); } return out + ']'; @@ -266,7 +266,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_VECTOR4: { const auto vecs = this->getValue>(); std::string out = "["; - for (int i = 0; i < vecs.size(); i++) { + for (size_t i = 0; i < vecs.size(); i++) { out += std::format("{}[{}, {}, {}, {}]{}", i == 0 ? "" : " ", vecs[i][0], vecs[i][1], vecs[i][2], vecs[i][3], i == vecs.size() - 1 ? "" : ",\n"); } return out + ']'; @@ -274,7 +274,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_EULER_ANGLES: { const auto angles = this->getValue>(); std::string out = "["; - for (int i = 0; i < angles.size(); i++) { + for (size_t i = 0; i < angles.size(); i++) { out += std::format("{}[{}, {}, {}]{}", i == 0 ? "" : " ", angles[i][0], angles[i][1], angles[i][2], i == angles.size() - 1 ? "" : ",\n"); } return out + ']'; @@ -282,7 +282,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_QUATERNION: { const auto quats = this->getValue>(); std::string out = "["; - for (int i = 0; i < quats.size(); i++) { + for (size_t i = 0; i < quats.size(); i++) { out += std::format("{}[{}, {}, {}, {}]{}", i == 0 ? "" : " ", quats[i][0], quats[i][1], quats[i][2], quats[i][3], i == quats.size() - 1 ? "" : ",\n"); } return out + ']'; @@ -290,7 +290,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_MATRIX_4X4: { const auto matrices = this->getValue>(); std::string out = "["; - for (int m = 0; m < matrices.size(); m++) { + for (size_t m = 0; m < matrices.size(); m++) { out += m == 0 ? "[" : " ["; for (int i = 0; i < 4; i++) { out += i == 0 ? "" : " "; @@ -307,7 +307,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_UINT64: { const auto ints = this->getValue>(); std::string out = "["; - for (int i = 0; i < ints.size(); i++) { + for (size_t i = 0; i < ints.size(); i++) { out += std::format("{}{}{}", i == 0 ? "" : " ", ints[i], i == ints.size() - 1 ? "" : ","); } return out + ']'; @@ -315,7 +315,7 @@ std::string DMXAttribute::getValueString() const { case ARRAY_UINT8: { const auto ints = this->getValue>(); std::string out = "["; - for (int i = 0; i < ints.size(); i++) { + for (size_t i = 0; i < ints.size(); i++) { out += std::format("{}{}{}", i == 0 ? "" : " ", ints[i], i == ints.size() - 1 ? "" : ","); } return out + ']'; @@ -466,7 +466,7 @@ void DMXElement::removeAttribute(unsigned int n) { } void DMXElement::removeAttribute(std::string_view attributeKey, int n) { - unsigned int count = 0; + int count = 0; for (auto attribute = this->attributes.begin(); attribute != this->attributes.end(); ++attribute) { if (string::iequals(attribute->getKey(), attributeKey)) { if (n < 0 || count == n) { @@ -623,7 +623,7 @@ DMX::DMX(std::span dmxData) { std::vector out; auto size = stream.read(); out.reserve(size); - for (int i = 0; i < size; i++) { + for (uint32_t i = 0; i < size; i++) { // String arrays are always inline out.push_back(std::get(readValue(DMXValue::arrayIDToInnerID(type_), false))); } @@ -779,7 +779,7 @@ DMX::DMX(std::span dmxData) { stringCount = stream.read(); } stringList.reserve(stringCount); - for (int i = 0; i < stringCount; i++) { + for (uint32_t i = 0; i < stringCount; i++) { stringList.push_back(stream.read_string()); } } @@ -1014,7 +1014,7 @@ void DMX::removeElement(unsigned int n) { for (auto& attribute : element.attributes) { if (const auto attributeType = attribute.getValueType(); attributeType == DMXValue::ID::ELEMENT) { auto elementRef = attribute.getValue(); - if (elementRef.index > n) { + if (static_cast(elementRef.index) > n) { elementRef.index--; } attribute.setValue(elementRef); @@ -1022,7 +1022,7 @@ void DMX::removeElement(unsigned int n) { auto elementsRef = attribute.getValue>(); bool shouldSet = false; for (auto& [index, externalGUID] : elementsRef) { - if (index > n) { + if (static_cast(index) > n) { index--; shouldSet = true; } diff --git a/src/kvpp/KV1Binary.cpp b/src/kvpp/KV1Binary.cpp index 08ecec8c6..372f64494 100644 --- a/src/kvpp/KV1Binary.cpp +++ b/src/kvpp/KV1Binary.cpp @@ -141,7 +141,7 @@ void KV1BinaryElement::removeChild(unsigned int n) { } void KV1BinaryElement::removeChild(std::string_view childKey, int n) { - unsigned int count = 0; + int count = 0; for (auto element = this->children.begin(); element != this->children.end(); ++element) { if (string::iequals(element->getKey(), childKey)) { if (n < 0 || count == n) { @@ -198,9 +198,8 @@ KV1Binary::KV1Binary(std::span kv1Data, bool use64BitPointers) case FLOAT: element.setValue(stream.read()); break; - case POINTER: { - const auto data32 = stream.read(); - if (use64BitPointers && data32 == KV1BinaryPointer::MAGIC_64_BIT) { + case POINTER: + if (const auto data32 = stream.read(); use64BitPointers && data32 == KV1BinaryPointer::MAGIC_64_BIT) { const auto data64 = stream.read(); element.setValue(KV1BinaryPointer{ .v64 = data64, @@ -213,7 +212,6 @@ KV1Binary::KV1Binary(std::span kv1Data, bool use64BitPointers) }); } break; - } case WSTRING: { const auto len = stream.read(); std::wstring value; @@ -271,9 +269,8 @@ std::vector KV1Binary::bake() const { case FLOAT: stream.write(*element.getValue()); break; - case POINTER: { - const auto pointer = *element.getValue(); - if (pointer.is64Bit) { + case POINTER: + if (const auto pointer = *element.getValue(); pointer.is64Bit) { stream .write(KV1BinaryPointer::MAGIC_64_BIT) .write(pointer.v64); @@ -281,7 +278,6 @@ std::vector KV1Binary::bake() const { stream.write(pointer.v32); } break; - } case WSTRING: { const auto val = *element.getValue(); stream diff --git a/src/mdlpp/mdlpp.cpp b/src/mdlpp/mdlpp.cpp index a28dd7c49..af2673601 100644 --- a/src/mdlpp/mdlpp.cpp +++ b/src/mdlpp/mdlpp.cpp @@ -61,11 +61,11 @@ BakedModel StudioModel::processModelData(int currentLOD) const { } } - for (int bodyPartIndex = 0; bodyPartIndex < this->mdl.bodyParts.size(); bodyPartIndex++) { + for (size_t bodyPartIndex = 0; bodyPartIndex < this->mdl.bodyParts.size(); bodyPartIndex++) { auto& mdlBodyPart = this->mdl.bodyParts.at(bodyPartIndex); const auto& [vtxModels] = this->vtx.bodyParts.at(bodyPartIndex); - for (int modelIndex = 0; modelIndex < mdlBodyPart.models.size(); modelIndex++) { + for (size_t modelIndex = 0; modelIndex < mdlBodyPart.models.size(); modelIndex++) { auto& mdlModel = mdlBodyPart.models.at(modelIndex); const auto& [vtxModelLODs] = vtxModels.at(modelIndex); @@ -73,7 +73,7 @@ BakedModel StudioModel::processModelData(int currentLOD) const { continue; } - for (int meshIndex = 0; meshIndex < mdlModel.meshes.size(); meshIndex++) { + for (size_t meshIndex = 0; meshIndex < mdlModel.meshes.size(); meshIndex++) { auto& mdlMesh = mdlModel.meshes.at(meshIndex); const auto& [vtxStripGroups, vtxMeshFlags] = vtxModelLODs.at(currentLOD).meshes.at(meshIndex); @@ -86,13 +86,13 @@ BakedModel StudioModel::processModelData(int currentLOD) const { // Remember to flip the winding order if (strip.flags & VTX::Strip::FLAG_IS_TRILIST) { - for (int i = 0; i < strip.indices.size(); i += 3) { + for (size_t i = 0; i < strip.indices.size(); i += 3) { addIndex(strip.indices[i+0]); addIndex(strip.indices[i+2]); addIndex(strip.indices[i+1]); } } else /* if (strip.flags & VTX::Strip::FLAG_IS_TRISTRIP) */ { - for (int i = 0; i < strip.indices.size() - 2; i++) { + for (size_t i = 0; i < strip.indices.size() - 2; i++) { if (i & 1) { addIndex(strip.indices[i+0]); addIndex(strip.indices[i+2]); diff --git a/src/mdlpp/structs/VVD.cpp b/src/mdlpp/structs/VVD.cpp index f475b752f..18d9d4df2 100644 --- a/src/mdlpp/structs/VVD.cpp +++ b/src/mdlpp/structs/VVD.cpp @@ -47,7 +47,7 @@ bool VVD::open(const std::byte* data, std::size_t size, const MDL::MDL& mdl) { } stream.seek(tangentsOffset); - for (std::size_t i = 0; i < this->numVerticesInLOD[0]; i++) { + for (int32_t i = 0; i < this->numVerticesInLOD[0]; i++) { this->vertices.at(i).tangent = stream.read(); } diff --git a/src/toolpp/CmdSeq.cpp b/src/toolpp/CmdSeq.cpp index ebf834492..56f2b87f1 100644 --- a/src/toolpp/CmdSeq.cpp +++ b/src/toolpp/CmdSeq.cpp @@ -264,7 +264,7 @@ std::vector CmdSeq::bakeKeyValuesHPP() const { auto& kvFile = kv.addChild("Command Sequences"); for (const auto& [seqName, seqCommands] : this->getSequences()) { auto& kvSequence = kvFile.addChild(seqName); - for (int i = 1; i <= seqCommands.size(); i++) { + for (size_t i = 1; i <= seqCommands.size(); i++) { const auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] = seqCommands[i - 1]; auto& kvCommand = kvSequence.addChild(std::format("{}", i)); kvCommand["enable"] = enabled; @@ -286,7 +286,7 @@ std::vector CmdSeq::bakeKeyValuesStrata() const { auto& kvFile = kv.addChild("Command Sequences"); for (const auto& [seqName, seqCommands] : this->getSequences()) { auto& kvSequence = kvFile.addChild(seqName); - for (int i = 1; i <= seqCommands.size(); i++) { + for (size_t i = 1; i <= seqCommands.size(); i++) { const auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] = seqCommands[i - 1]; auto& kvCommand = kvSequence.addChild(std::format("{}", i)); kvCommand["enabled"] = enabled; diff --git a/src/vpkpp/PackFile.cpp b/src/vpkpp/PackFile.cpp index faded709d..8a4d7af22 100644 --- a/src/vpkpp/PackFile.cpp +++ b/src/vpkpp/PackFile.cpp @@ -29,7 +29,7 @@ std::string joinPath(const std::vector& list) { return ""; } std::string result = list.front(); - for (int i = 1; i < list.size(); ++i) { + for (size_t i = 1; i < list.size(); ++i) { result += '/' + list[i]; } return result; diff --git a/src/vpkpp/format/APK.cpp b/src/vpkpp/format/APK.cpp index 8c4198fea..2a0ae966e 100644 --- a/src/vpkpp/format/APK.cpp +++ b/src/vpkpp/format/APK.cpp @@ -88,14 +88,14 @@ std::optional> APK::readEntry(const std::string& path_) c return stream.read_bytes(entry->length); } -void APK::addEntryInternal(Entry& entry, const std::string& path, std::vector& buffer, EntryOptions options) { +void APK::addEntryInternal(Entry& entry, const std::string&, std::vector& buffer, EntryOptions) { entry.length = buffer.size(); // Offset will be reset when it's baked entry.offset = 0; } -bool APK::bake(const std::string& outputDir_, BakeOptions options, const EntryCallback& callback) { +bool APK::bake(const std::string& outputDir_, BakeOptions, const EntryCallback& callback) { // Get the proper file output folder const std::string outputDir = this->getBakeOutputDir(outputDir_); const std::string outputPath = outputDir + '/' + this->getFilename(); diff --git a/src/vpkpp/format/FGP.cpp b/src/vpkpp/format/FGP.cpp index 41e7a7d20..263ffa7d2 100644 --- a/src/vpkpp/format/FGP.cpp +++ b/src/vpkpp/format/FGP.cpp @@ -70,7 +70,7 @@ std::unique_ptr FGP::open(const std::string& path, const EntryCallback reader.seek_in_u(reader.seek_in(sizeof(uint64_t) * 2, std::ios::end).read()); if (reader.read() == FGP_SOURCEPP_FILENAMES_SIGNATURE && reader.read() == 1) { const auto filepathCount = reader.read(); - for (int i = 0; i < filepathCount; i++) { + for (uint32_t i = 0; i < filepathCount; i++) { const auto hash = reader.read(); crackedHashes[hash] = fgp->cleanEntryPath(reader.read_string(reader.read())); } @@ -182,7 +182,7 @@ std::size_t FGP::removeDirectory(const std::string& dirName) { return false; } -void FGP::addEntryInternal(Entry& entry, const std::string& path, std::vector& buffer, EntryOptions options) { +void FGP::addEntryInternal(Entry& entry, const std::string& path, std::vector& buffer, EntryOptions) { // note: NOT a CRC32! check FGP::hashFilePath entry.crc32 = FGP::hashFilePath(this->cleanEntryPath(path)); entry.length = buffer.size(); diff --git a/src/vpkpp/format/FPX.cpp b/src/vpkpp/format/FPX.cpp index bff7adcd4..95e39fbcb 100644 --- a/src/vpkpp/format/FPX.cpp +++ b/src/vpkpp/format/FPX.cpp @@ -118,8 +118,8 @@ std::unique_ptr FPX::openInternal(const std::string& path, const Entry entry.length += preloadedDataSize; } - if (entry.archiveIndex != VPK_DIR_INDEX && entry.archiveIndex > fpx->numArchives) { - fpx->numArchives = entry.archiveIndex; + if (entry.archiveIndex != VPK_DIR_INDEX && entry.archiveIndex > static_cast(fpx->numArchives)) { + fpx->numArchives = static_cast(entry.archiveIndex); } fpx->entries.emplace(entryPath, entry); diff --git a/src/vpkpp/format/GCF.cpp b/src/vpkpp/format/GCF.cpp index 22e77cd60..85ed7a2a3 100644 --- a/src/vpkpp/format/GCF.cpp +++ b/src/vpkpp/format/GCF.cpp @@ -64,7 +64,7 @@ std::unique_ptr GCF::open(const std::string& path, const EntryCallback // block headers!!!!!! bool requestKey = false; - for (int i = 0; i < gcf->header.blockcount; i++) { + for (uint32_t i = 0; i < gcf->header.blockcount; i++) { Block& block = gcf->blockdata.emplace_back(); reader.read(block); if (block.isEncrypted()) { @@ -102,7 +102,7 @@ std::unique_ptr GCF::open(const std::string& path, const EntryCallback // Fragmentation Map (list of dwords) - for (int i = 0; i < blkcount; i++) { + for (uint32_t i = 0; i < blkcount; i++) { gcf->fragmap.push_back(reader.read()); } @@ -116,7 +116,7 @@ std::unique_ptr GCF::open(const std::string& path, const EntryCallback std::vector direntries{}; - for (int i = 0; i < gcf->dirheader.itemcount; i++) { + for (uint32_t i = 0; i < gcf->dirheader.itemcount; i++) { DirectoryEntry2& entry = direntries.emplace_back(); reader.read(entry.entry_real); auto currentoffset = reader.tell_in(); @@ -160,7 +160,7 @@ std::unique_ptr GCF::open(const std::string& path, const EntryCallback reader.skip_in(); // Directory Map entries - for (int i = 0; i < gcf->dirheader.itemcount; i++) { + for (uint32_t i = 0; i < gcf->dirheader.itemcount; i++) { DirectoryMapEntry& entry = gcf->dirmap_entries.emplace_back(); reader.read(entry); } @@ -182,12 +182,12 @@ std::unique_ptr GCF::open(const std::string& path, const EntryCallback //printf("%lu %lu\n", chksummapheader.checksum_count, chksummapheader.item_count); - for (int i = 0; i < chksummapheader.item_count; i++) { + for (uint32_t i = 0; i < chksummapheader.item_count; i++) { auto& cur_entry = gcf->chksum_map.emplace_back(); reader.read(cur_entry); } - for (int i = 0; i < chksummapheader.checksum_count; i++) { + for (uint32_t i = 0; i < chksummapheader.checksum_count; i++) { auto& currentChecksum = gcf->checksums.emplace_back(); reader.read(currentChecksum); } @@ -211,7 +211,7 @@ std::vector GCF::verifyEntryChecksums() const { uint32_t idx = entry.crc32; uint32_t count = this->chksum_map[idx].count; uint32_t checksumstart = this->chksum_map[idx].firstindex; - for (int i = 0; i < count; i++) { + for (uint32_t i = 0; i < count; i++) { uint32_t csum = this->checksums[checksumstart + i]; std::size_t toread = std::min(static_cast(0x8000), tocheck); const auto* data = bytes->data() + (i * 0x8000); diff --git a/src/vpkpp/format/GMA.cpp b/src/vpkpp/format/GMA.cpp index f32d4f76f..5288b5272 100644 --- a/src/vpkpp/format/GMA.cpp +++ b/src/vpkpp/format/GMA.cpp @@ -105,7 +105,7 @@ std::optional> GMA::readEntry(const std::string& path_) c return stream.read_bytes(entry->length); } -void GMA::addEntryInternal(Entry& entry, const std::string& path, std::vector& buffer, EntryOptions options) { +void GMA::addEntryInternal(Entry& entry, const std::string&, std::vector& buffer, EntryOptions) { entry.length = buffer.size(); entry.crc32 = crypto::computeCRC32(buffer); diff --git a/src/vpkpp/format/GRP.cpp b/src/vpkpp/format/GRP.cpp index 22b90b8d4..0c11e2ba3 100644 --- a/src/vpkpp/format/GRP.cpp +++ b/src/vpkpp/format/GRP.cpp @@ -40,7 +40,7 @@ std::unique_ptr GRP::open(const std::string& path, const EntryCallback const auto dirSize = (GRP_FILENAME_MAX_SIZE + sizeof(uint32_t)) * (entryCount + 1); uint32_t currentOffset = dirSize; - for (int i = 0; i < entryCount; i++) { + for (uint32_t i = 0; i < entryCount; i++) { Entry entry = createNewEntry(); auto entryPath = grp->cleanEntryPath(reader.read_string(GRP_FILENAME_MAX_SIZE)); diff --git a/src/vpkpp/format/REZ.cpp b/src/vpkpp/format/REZ.cpp index 98e245bf1..692e2b4a4 100644 --- a/src/vpkpp/format/REZ.cpp +++ b/src/vpkpp/format/REZ.cpp @@ -60,7 +60,8 @@ std::unique_ptr REZ::open(const std::string& path, const EntryCallback if (rez->version != 1) { return nullptr; } - break; + // todo: v2 support + return nullptr; default: return nullptr; } diff --git a/src/vpkpp/format/TAB.cpp b/src/vpkpp/format/TAB.cpp index d7d6ca90b..5cf88daf4 100644 --- a/src/vpkpp/format/TAB.cpp +++ b/src/vpkpp/format/TAB.cpp @@ -1,4 +1,5 @@ // ReSharper disable CppParameterMayBeConst +// ReSharper disable CppRedundantParentheses // ReSharper disable CppRedundantQualifier #include @@ -105,7 +106,7 @@ std::unique_ptr TAB::open(const std::string& path, const EntryCallback entry.length = reader.read(); entry.archiveIndex = 0; - for (int j = 0; j < tab->numArchives; j++) { + for (uint32_t j = 0; j < tab->numArchives; j++) { if (entry.offset < archiveAlignments[j]) { entry.archiveIndex = j; break; @@ -146,7 +147,7 @@ std::optional> TAB::readEntry(const std::string& path_) c return stream.read_bytes(entry->length); } -void TAB::addEntryInternal(Entry& entry, const std::string& path, std::vector& buffer, EntryOptions options) { +void TAB::addEntryInternal(Entry& entry, const std::string& path, std::vector& buffer, EntryOptions) { // note: NOT a CRC32! check TAB::hashFilePath entry.crc32 = TAB::hashFilePath(path); entry.length = buffer.size(); @@ -156,7 +157,7 @@ void TAB::addEntryInternal(Entry& entry, const std::string& path, std::vectorgetBakeOutputDir(outputDir_); const std::string outputPath = outputDir + '/' + this->getFilename(); diff --git a/src/vpkpp/format/VPK.cpp b/src/vpkpp/format/VPK.cpp index 5ae6278ee..b467bbb78 100644 --- a/src/vpkpp/format/VPK.cpp +++ b/src/vpkpp/format/VPK.cpp @@ -412,8 +412,8 @@ void VPK::addEntryInternal(Entry& entry, const std::string&, std::vectornumArchives; if (!options.vpk_saveToDirectory && !this->freedChunks.empty() && !this->hasCompression()) { int64_t bestChunkIndex = -1; - std::size_t currentChunkGap = SIZE_MAX; - for (int64_t i = 0; i < this->freedChunks.size(); i++) { + size_t currentChunkGap = SIZE_MAX; + for (int64_t i = 0; i < static_cast(this->freedChunks.size()); i++) { if ( (bestChunkIndex < 0 && this->freedChunks[i].length >= entry.length) || (bestChunkIndex >= 0 && this->freedChunks[i].length >= entry.length && this->freedChunks[i].length - entry.length < currentChunkGap) @@ -569,7 +569,7 @@ bool VPK::bake(const std::string& outputDir_, BakeOptions options, const EntryCa // Copy external binary blobs to the new dir if (!outputDir_.empty()) { - for (uint32_t archiveIndex = 0; archiveIndex < this->numArchives; archiveIndex++) { + for (int32_t archiveIndex = 0; archiveIndex < this->numArchives; archiveIndex++) { std::string from = getArchiveFilename(this->getTruncatedFilepath(), archiveIndex); if (!std::filesystem::exists(from)) { continue; @@ -885,7 +885,7 @@ bool VPK::sign(const std::vector& privateKey, const std::vectorheader2.signatureSectionSize) { return false; } - for (int i = 0; i < this->header2.signatureSectionSize; i++) { + for (uint32_t i = 0; i < this->header2.signatureSectionSize; i++) { dirFileBuffer.pop_back(); } this->footer2.publicKey = publicKey; diff --git a/src/vpkpp/format/VPK_VTMB.cpp b/src/vpkpp/format/VPK_VTMB.cpp index a40e5c97a..e895efa04 100644 --- a/src/vpkpp/format/VPK_VTMB.cpp +++ b/src/vpkpp/format/VPK_VTMB.cpp @@ -51,7 +51,7 @@ std::unique_ptr VPK_VTMB::open(const std::string& path, const EntryCal } if (vpkVTMB->knownArchives.empty()) { - uint32_t archiveIndex; + uint32_t archiveIndex = 0; string::toInt(stem.substr(4), archiveIndex); vpkVTMB->openNumbered(archiveIndex, path, callback); } @@ -68,8 +68,7 @@ void VPK_VTMB::openNumbered(uint32_t archiveIndex, const std::string& path, cons const auto dirOffset = reader.read(); // Make 100% sure - const auto version = reader.read(); - if (version != 0) { + if (const auto version = reader.read(); version != 0) { return; } @@ -116,7 +115,7 @@ std::optional> VPK_VTMB::readEntry(const std::string& pat return stream.read_bytes(entry->length); } -void VPK_VTMB::addEntryInternal(Entry& entry, const std::string& path, std::vector& buffer, EntryOptions options) { +void VPK_VTMB::addEntryInternal(Entry& entry, const std::string&, std::vector& buffer, EntryOptions) { entry.archiveIndex = this->currentArchive; entry.length = buffer.size(); @@ -124,7 +123,7 @@ void VPK_VTMB::addEntryInternal(Entry& entry, const std::string& path, std::vect entry.offset = 0; } -bool VPK_VTMB::bake(const std::string& outputDir_, BakeOptions options, const EntryCallback& callback) { +bool VPK_VTMB::bake(const std::string& outputDir_, BakeOptions, const EntryCallback& callback) { if (this->knownArchives.empty()) { return false; } diff --git a/src/vpkpp/format/WAD3.cpp b/src/vpkpp/format/WAD3.cpp index 2e4797dcf..9ed6fb84b 100644 --- a/src/vpkpp/format/WAD3.cpp +++ b/src/vpkpp/format/WAD3.cpp @@ -136,14 +136,14 @@ std::optional> WAD3::readEntry(const std::string& path_) return stream.read_bytes(entry->length); } -void WAD3::addEntryInternal(Entry& entry, const std::string& path, std::vector& buffer, EntryOptions options) { +void WAD3::addEntryInternal(Entry& entry, const std::string&, std::vector& buffer, EntryOptions) { entry.length = buffer.size(); // Offset will be reset when it's baked entry.offset = 0; } -bool WAD3::bake(const std::string& outputDir_, BakeOptions options, const EntryCallback& callback) { +bool WAD3::bake(const std::string& outputDir_, BakeOptions, const EntryCallback& callback) { // Get the proper file output folder std::string outputDir = this->getBakeOutputDir(outputDir_); std::string outputPath = outputDir + '/' + this->getFilename(); diff --git a/src/vpkpp/format/ZIP.cpp b/src/vpkpp/format/ZIP.cpp index 39bc49ccb..9cfa81dde 100644 --- a/src/vpkpp/format/ZIP.cpp +++ b/src/vpkpp/format/ZIP.cpp @@ -121,7 +121,7 @@ bool ZIP::isReadOnly() const noexcept { return xzpVersion == 2 || xzpVersion == 3; } -void ZIP::addEntryInternal(Entry& entry, const std::string& path, std::vector& buffer, EntryOptions options) { +void ZIP::addEntryInternal(Entry& entry, const std::string&, std::vector& buffer, EntryOptions options) { entry.flags = (static_cast(options.zip_compressionType == EntryCompressionType::NO_OVERRIDE ? EntryCompressionType::NO_COMPRESS : options.zip_compressionType) << 16) | options.zip_compressionStrength; entry.length = buffer.size(); entry.compressedLength = 0; diff --git a/src/vtfpp/DistanceMapping.cpp b/src/vtfpp/DistanceMapping.cpp index 04a0a1f89..6a2968c7a 100644 --- a/src/vtfpp/DistanceMapping.cpp +++ b/src/vtfpp/DistanceMapping.cpp @@ -80,18 +80,18 @@ class SampleParam { ImageConversion::ResizeEdge edge ) : srcImg(srcImg) - , pxLen(pxLen) - , alphaOffs(alphaOffs) - , imgWidth(inWidth) + , alphaThreshold(alphaThreshold) , imgHeight(inHeight) - , reduceX(reduceX) - , reduceY(reduceY) + , imgWidth(inWidth) , searchRadius(ftoabsu16(2.0f * std::max(reduceX, reduceY) * distanceSpread)) // the second power of two after search radius , granularity(uint16_t{4} << ftoabsu16(ceil(log2(static_cast(this->searchRadius))))) , offsX(sampleCentered ? reduceX / 2 : 0) , offsY(sampleCentered ? reduceY / 2 : 0) - , alphaThreshold(alphaThreshold) + , reduceX(reduceX) + , reduceY(reduceY) + , pxLen(pxLen) + , alphaOffs(alphaOffs) , indexFn(indexBy(edge)) {} @@ -185,13 +185,13 @@ class RasterCursor { public: RasterCursor(const QuadTree *tree, uint16_t imgWidth, uint16_t imgHeight, uint16_t reduceX = 1, uint16_t reduceY = 1, uint16_t offsX = 0, uint16_t offsY = 0) : tree(tree) + , curX(offsX) + , curY(offsY) , imgWidth(imgWidth) , imgHeight(imgHeight) , reduceX(reduceX) , reduceY(reduceY) , offsX(offsX) - , curX(offsX) - , curY(offsY) { this->curShade = this->reorient(); } @@ -291,6 +291,7 @@ void paintMap( switch (srcShade) { case OUT: fillDistance = 0.0f; + [[fallthrough]]; case IN: for (uint16_t i = 0; i < dstW; i++, iOut += dstPxLen) { dstImg[iOut] = fillDistance; @@ -390,7 +391,6 @@ void paintMap( RasterCursor diffCursor(&tree, dstWidth, dstHeight); uint32_t diffOut = dstAlphaOffs; Leaf diffShade = FIGUREITOUT; - const uint32_t dstBufLen = dstWidth * dstHeight * dstPxLen; uint16_t diffY = 0, diffX = 0, diffW = 0; uint32_t iGradR = 0; diff --git a/src/vtfpp/ImageConversion.cpp b/src/vtfpp/ImageConversion.cpp index 4ee57eb77..6e638dc1f 100644 --- a/src/vtfpp/ImageConversion.cpp +++ b/src/vtfpp/ImageConversion.cpp @@ -49,6 +49,13 @@ #include #include +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-value" +#endif + #define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_STATIC #define STBI_NO_FAILURE_STRINGS @@ -64,6 +71,10 @@ #define STBI_WRITE_NO_STDIO #include +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + #ifdef VTFPP_SUPPORT_EXR #include #endif @@ -589,7 +600,7 @@ namespace { VTFPP_CASE_CONVERT(BGRX5551, {VTFPP_REMAP_FROM_8(pixel.b(), 5), VTFPP_REMAP_FROM_8(pixel.g(), 5), VTFPP_REMAP_FROM_8(pixel.r(), 5), 1}); VTFPP_CASE_CONVERT(BGRA4444, {VTFPP_REMAP_FROM_8(pixel.b(), 4), VTFPP_REMAP_FROM_8(pixel.g(), 4), VTFPP_REMAP_FROM_8(pixel.r(), 4), VTFPP_REMAP_FROM_8(pixel.a(), 4)}); VTFPP_CASE_CONVERT(UV88, {pixel.r(), pixel.g()}); - VTFPP_CASE_CONVERT(UVLX8888, {pixel.r(), pixel.g(), pixel.b()}); + VTFPP_CASE_CONVERT(UVLX8888, {pixel.r(), pixel.g(), pixel.b(), 0xff}); VTFPP_CASE_CONVERT(RGBX8888, {pixel.r(), pixel.g(), pixel.b(), 0xff}); VTFPP_CASE_CONVERT(CONSOLE_BGRX8888_LINEAR, {pixel.b(), pixel.g(), pixel.r(), 0xff}); VTFPP_CASE_CONVERT(CONSOLE_RGBA8888_LINEAR, {pixel.r(), pixel.g(), pixel.b(), pixel.a()}); @@ -1509,7 +1520,8 @@ std::vector ImageConversion::convertImageDataToFile(std::span imageDataConverted; switch (ImageFormatDetails::containerFormat(format)) { @@ -1655,7 +1667,8 @@ std::vector ImageConversion::convertFileToImageData(std::span out; - JxlPixelFormat pixelFormat{ .endianness = JXL_LITTLE_ENDIAN }; + JxlPixelFormat pixelFormat{}; + pixelFormat.endianness = JXL_LITTLE_ENDIAN; bool infoHasBeenSet = false; while (true) { switch (JxlDecoderProcessInput(decoder.get())) { @@ -1842,7 +1855,7 @@ std::vector ImageConversion::convertFileToImageData(std::span(image.tiles[t].offset_y) * header.tile_size_y + j; const auto idx = ii + jj * image.width; - if (ii >= image.width || jj >= image.height) { + if (ii >= static_cast(image.width) || jj >= static_cast(image.height)) { continue; } @@ -1860,7 +1873,7 @@ std::vector ImageConversion::convertFileToImageData(std::span(image.images); - for (uint64_t i = 0; i < width * height; i++) { + for (uint64_t i = 0; i < static_cast(width) * height; i++) { if (r >= 0) out[i * channelCount + 0] = src[r][i]; else if (hasRed) out[i * channelCount + 0] = 0.f; if (g >= 0) out[i * channelCount + 1] = src[g][i]; @@ -2040,7 +2053,7 @@ std::vector ImageConversion::convertFileToImageData(std::span(width) && frame.height == static_cast(height) && frame.x_offset == 0 && frame.y_offset == 0 && frame.blend_op == STBI_APNG_blend_op_source) { std::memcpy(out.data() + dstFrameOffset, stbImage.get() + srcFrameOffset, fullFrameSize); } else { // Check the blend op @@ -2436,7 +2449,7 @@ void ImageConversion::gammaCorrectImageData(std::span imageData, Imag static constexpr auto calculateGammaLUT = [](float gamma_, uint8_t channelSize) -> std::array { const auto maxSize = static_cast((1 << channelSize) - 1); std::array gammaLUT{}; - for (int i = 0; i < gammaLUT.size(); i++) { + for (size_t i = 0; i < gammaLUT.size(); i++) { gammaLUT[i] = static_cast(std::clamp(std::pow((static_cast(i) + 0.5f) / maxSize, gamma_) * maxSize - 0.5f, 0.f, maxSize)); } return gammaLUT; diff --git a/src/vtfpp/VBF.cpp b/src/vtfpp/VBF.cpp index 73fd40b41..d69871d69 100644 --- a/src/vtfpp/VBF.cpp +++ b/src/vtfpp/VBF.cpp @@ -36,7 +36,7 @@ VBF::VBF(std::span vbfData) { stream >> size[0] >> size[1]; stream >> abcSpacing[0] >> abcSpacing[1] >> abcSpacing[2]; } - for (int i = 0; i < this->glyphs.size(); i++) { + for (size_t i = 0; i < this->glyphs.size(); i++) { if (const auto glyphIndex = glyphLUT[i]; glyphIndex < glyphCount) { this->glyphs[i] = glyphList[glyphIndex]; } diff --git a/src/vtfpp/VTF.cpp b/src/vtfpp/VTF.cpp index f91ad79e6..845c20c2d 100644 --- a/src/vtfpp/VTF.cpp +++ b/src/vtfpp/VTF.cpp @@ -166,7 +166,7 @@ void swizzleUncompressedImageDataXBOX(std::span inputData, std::span< for (uint16_t y = 0; y < height; y++) { for (uint16_t x = 0; x < width; x++) { const auto codedIndex = zIndex(x, y, z); - for (uint32_t b = 0; b < stride; b++) { + for (int b = 0; b < stride; b++) { if constexpr (ExistingDataIsSwizzled) { outputData[linearIndex * stride + b] = inputData[codedIndex * stride + b]; } else { @@ -469,7 +469,7 @@ VTF::VTF(std::vector&& vtfData, bool parseHeaderOnly, bool hdr) const auto readResources = [this, &stream](uint32_t resourceCount) { // Read resource header info this->resources.reserve(resourceCount); - for (int i = 0; i < resourceCount; i++) { + for (uint32_t i = 0; i < resourceCount; i++) { auto& [type, flags_, data_] = this->resources.emplace_back(); auto typeAndFlags = stream.read(); @@ -685,115 +685,113 @@ VTF::VTF(std::vector&& vtfData, bool parseHeaderOnly, bool hdr) return; } case PLATFORM_XBOX: { - if (this->platform == PLATFORM_XBOX) { - uint16_t preloadSize = 0, imageOffset = 0; - stream - .read(this->flags) - .read(this->width) - .read(this->height) - .read(this->depth) - .read(this->frameCount) - .read(preloadSize) - .read(imageOffset) - .read(this->reflectivity[0]) - .read(this->reflectivity[1]) - .read(this->reflectivity[2]) - .read(this->bumpMapScale) - .read(this->format) - .read(this->thumbnailWidth) - .read(this->thumbnailHeight) - .read(this->fallbackWidth) - .read(this->fallbackHeight) - .read(this->consoleMipScale) - .skip(); // padding - - const bool headerSizeIsAccurate = stream.tell() == headerSize; - - this->mipCount = (this->flags & FLAG_V0_NO_MIP) ? 1 : ImageDimensions::getMaximumMipCount(this->width, this->height, this->depth); - this->fallbackMipCount = (this->flags & FLAG_V0_NO_MIP) ? 1 : ImageDimensions::getMaximumMipCount(this->fallbackWidth, this->fallbackHeight); - - postHeaderReadTransform(); - - // Can't use VTF::getFaceCount yet because there's no image data - const auto faceCount = (this->flags & FLAG_V0_ENVMAP) ? 6 : 1; - - if (this->thumbnailWidth == 0 || this->thumbnailHeight == 0) { - this->thumbnailFormat = ImageFormat::EMPTY; + uint16_t preloadSize = 0, imageOffset = 0; + stream + .read(this->flags) + .read(this->width) + .read(this->height) + .read(this->depth) + .read(this->frameCount) + .read(preloadSize) + .read(imageOffset) + .read(this->reflectivity[0]) + .read(this->reflectivity[1]) + .read(this->reflectivity[2]) + .read(this->bumpMapScale) + .read(this->format) + .read(this->thumbnailWidth) + .read(this->thumbnailHeight) + .read(this->fallbackWidth) + .read(this->fallbackHeight) + .read(this->consoleMipScale) + .skip(); // padding + + const bool headerSizeIsAccurate = stream.tell() == headerSize; + + this->mipCount = (this->flags & FLAG_V0_NO_MIP) ? 1 : ImageDimensions::getMaximumMipCount(this->width, this->height, this->depth); + this->fallbackMipCount = (this->flags & FLAG_V0_NO_MIP) ? 1 : ImageDimensions::getMaximumMipCount(this->fallbackWidth, this->fallbackHeight); + + postHeaderReadTransform(); + + // Can't use VTF::getFaceCount yet because there's no image data + const auto faceCount = (this->flags & FLAG_V0_ENVMAP) ? 6 : 1; + + if (this->thumbnailWidth == 0 || this->thumbnailHeight == 0) { + this->thumbnailFormat = ImageFormat::EMPTY; + } else { + this->thumbnailFormat = ImageFormat::RGB888; + const auto thumbnailSize = ImageFormatDetails::getDataLength(this->thumbnailFormat, this->thumbnailWidth, this->thumbnailHeight); + if (!parseHeaderOnly) { + this->resources.push_back({ + .type = Resource::TYPE_THUMBNAIL_DATA, + .flags = Resource::FLAG_NONE, + .data = stream.read_span(thumbnailSize), + }); } else { - this->thumbnailFormat = ImageFormat::RGB888; - const auto thumbnailSize = ImageFormatDetails::getDataLength(this->thumbnailFormat, this->thumbnailWidth, this->thumbnailHeight); - if (!parseHeaderOnly) { - this->resources.push_back({ - .type = Resource::TYPE_THUMBNAIL_DATA, - .flags = Resource::FLAG_NONE, - .data = stream.read_span(thumbnailSize), - }); - } else { - stream.skip(thumbnailSize); - } + stream.skip(thumbnailSize); } + } - if (this->format == ImageFormat::P8) { - const auto paletteSize = 256 * sizeof(ImagePixel::BGRA8888) * this->frameCount; - if (!parseHeaderOnly) { - this->resources.push_back({ - .type = Resource::TYPE_PALETTE_DATA, - .flags = Resource::FLAG_NONE, - .data = stream.read_span(paletteSize), - }); - } else { - stream.skip_u(paletteSize); - } + if (this->format == ImageFormat::P8) { + const auto paletteSize = 256 * sizeof(ImagePixel::BGRA8888) * this->frameCount; + if (!parseHeaderOnly) { + this->resources.push_back({ + .type = Resource::TYPE_PALETTE_DATA, + .flags = Resource::FLAG_NONE, + .data = stream.read_span(paletteSize), + }); + } else { + stream.skip_u(paletteSize); } + } - bool ok; - auto fallbackSize = ImageFormatDetails::getDataLengthXBOX(false, this->format, this->fallbackMipCount, this->frameCount, faceCount, this->fallbackWidth, this->fallbackHeight); - std::vector reorderedFallbackData; - if (this->hasFallbackData()) { + bool ok; + auto fallbackSize = ImageFormatDetails::getDataLengthXBOX(false, this->format, this->fallbackMipCount, this->frameCount, faceCount, this->fallbackWidth, this->fallbackHeight); + std::vector reorderedFallbackData; + if (this->hasFallbackData()) { + if (stream.tell() + fallbackSize != preloadSize) { + // A couple XTFs that shipped with HL2 are missing the NO_MIP flag. We can detect them by checking the size of the fallback + fallbackSize = ImageFormatDetails::getDataLengthXBOX(false, this->format, 1, this->frameCount, faceCount, this->fallbackWidth, this->fallbackHeight); if (stream.tell() + fallbackSize != preloadSize) { - // A couple XTFs that shipped with HL2 are missing the NO_MIP flag. We can detect them by checking the size of the fallback - fallbackSize = ImageFormatDetails::getDataLengthXBOX(false, this->format, 1, this->frameCount, faceCount, this->fallbackWidth, this->fallbackHeight); - if (stream.tell() + fallbackSize != preloadSize) { - this->opened = false; - return; - } - this->fallbackMipCount = 1; - this->mipCount = 1; - this->flags |= FLAG_V0_NO_MIP; - } - reorderedFallbackData = ::convertBetweenDDSAndVTFMipOrderForXBOX(false, stream.read_span(fallbackSize), this->format, this->fallbackMipCount, this->frameCount, faceCount, this->fallbackWidth, this->fallbackHeight, 1, ok); - if (!ok) { this->opened = false; return; } - ::swapImageDataEndianForConsole(reorderedFallbackData, this->format, this->fallbackMipCount, this->frameCount, faceCount, this->fallbackWidth, this->fallbackHeight, 1, this->platform); + this->fallbackMipCount = 1; + this->mipCount = 1; + this->flags |= FLAG_V0_NO_MIP; } - - this->opened = headerSizeIsAccurate; - if (parseHeaderOnly) { + reorderedFallbackData = ::convertBetweenDDSAndVTFMipOrderForXBOX(false, stream.read_span(fallbackSize), this->format, this->fallbackMipCount, this->frameCount, faceCount, this->fallbackWidth, this->fallbackHeight, 1, ok); + if (!ok) { + this->opened = false; return; } + ::swapImageDataEndianForConsole(reorderedFallbackData, this->format, this->fallbackMipCount, this->frameCount, faceCount, this->fallbackWidth, this->fallbackHeight, 1, this->platform); + } - const auto imageSize = ImageFormatDetails::getDataLengthXBOX(true, this->format, this->mipCount, this->frameCount, faceCount, this->width, this->height, this->depth); - std::vector reorderedImageData; - if (this->hasImageData()) { - reorderedImageData = ::convertBetweenDDSAndVTFMipOrderForXBOX(true, stream.seek(imageOffset).read_span(imageSize), this->format, this->mipCount, this->frameCount, faceCount, this->width, this->height, this->depth, ok); - if (!ok) { - this->opened = false; - return; - } - ::swapImageDataEndianForConsole(reorderedImageData, this->format, this->mipCount, this->frameCount, faceCount, this->width, this->height, this->depth, this->platform); - } + this->opened = headerSizeIsAccurate; + if (parseHeaderOnly) { + return; + } - // By this point we cannot use spans over data, it will change here - if (this->hasFallbackData()) { - this->setResourceInternal(Resource::TYPE_FALLBACK_DATA, reorderedFallbackData); - } - if (this->hasImageData()) { - this->setResourceInternal(Resource::TYPE_IMAGE_DATA, reorderedImageData); + const auto imageSize = ImageFormatDetails::getDataLengthXBOX(true, this->format, this->mipCount, this->frameCount, faceCount, this->width, this->height, this->depth); + std::vector reorderedImageData; + if (this->hasImageData()) { + reorderedImageData = ::convertBetweenDDSAndVTFMipOrderForXBOX(true, stream.seek(imageOffset).read_span(imageSize), this->format, this->mipCount, this->frameCount, faceCount, this->width, this->height, this->depth, ok); + if (!ok) { + this->opened = false; + return; } - return; + ::swapImageDataEndianForConsole(reorderedImageData, this->format, this->mipCount, this->frameCount, faceCount, this->width, this->height, this->depth, this->platform); } + + // By this point we cannot use spans over data, it will change here + if (this->hasFallbackData()) { + this->setResourceInternal(Resource::TYPE_FALLBACK_DATA, reorderedFallbackData); + } + if (this->hasImageData()) { + this->setResourceInternal(Resource::TYPE_IMAGE_DATA, reorderedImageData); + } + return; } case PLATFORM_X360: case PLATFORM_PS3_ORANGEBOX: @@ -2366,6 +2364,7 @@ uint64_t VTF::estimateBakeSize(bool& isExact) const { vtfSize += sizeof(uint64_t); // AXC header size vtfSize += sizeof(uint32_t) * (2 + this->mipCount * this->frameCount * this->getFaceCount()); // AXC resource size } + [[fallthrough]]; case 5: case 4: case 3: @@ -2375,8 +2374,10 @@ uint64_t VTF::estimateBakeSize(bool& isExact) const { vtfSize += resourceData.size(); // resource size } } + [[fallthrough]]; case 2: vtfSize += sizeof(uint16_t); // depth header field + [[fallthrough]]; case 1: case 0: vtfSize += sizeof(uint32_t) * 9 + sizeof(float) * 4 + sizeof(uint16_t) * 4 + sizeof(uint8_t) * 3; // header fields @@ -2424,6 +2425,7 @@ uint64_t VTF::estimateBakeSize(bool& isExact) const { break; case PLATFORM_PS3_PORTAL2: vtfSize += sizeof(uint32_t); // align to 16 bytes + [[fallthrough]]; case PLATFORM_X360: case PLATFORM_PS3_ORANGEBOX: vtfSize += sizeof(uint32_t) * 7 + sizeof(float) * 4 + sizeof(uint16_t) * 5 + sizeof(uint8_t) * 6; // header fields